SQL Server 2019 CTP 3.0 منتشر شد
SQL Server 2019 CTP 2.4 منتشر شد
انتشار SQL Server 2017 CTP 2.0
تغییر مجوز استفادهی از Redis
Redis, the popular in-memory data store, is switching away from the open source three-clause BSD license. Instead, in a move that is clearly aimed to prevent the large cloud providers from offering free alternatives to Redis’ own hosted services, Redis will now be dual-licensed under the Redis Source Available License (RSALv2) and Server Side Public License (SSPLv1). Under this new license, cloud service providers hosting Redis will need to enter into a commercial agreement with Redis. The first company to do so is Microsoft.
معرفی ویژگی جدید StringSyntax
با استفاده از ویژگی StringSyntax جدید میتوان مقدار مورد انتظار از رشتهی درخواستی را معنادار کرد. برای مثال، Visual Studio سالهاست که راهنمایی را در حین تعریف عبارات باقاعده ظاهر میکند. اما این راهنما صرفا مختص به ویژوال استودیو است و تا پیش از این راهی وجود نداشت تا عنوان کنیم که برای مثال این رشته قرار است تنها یک عبارت باقاعده باشد. اکنون در دات نت 7 با معرفی ویژگی جدید StringSyntax میتوان یک چنین intellisense ای را در سایر IDEها نیز شاهد بود.
برای نمونه مثال زیر را درنظر بگیرید:
using System.Diagnostics.CodeAnalysis; namespace CS11Tests; public class StringSyntaxAttributeTests { public static void Test() { RegexTest(""); DateTest(""); } private static void RegexTest([StringSyntax(StringSyntaxAttribute.Regex)] string regex) { } private static void DateTest([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string dateTime) { } }
راهنمای ظاهر شده جهت تعریف سادهتر عبارات باقاعده:
و راهنمای ظاهر شده جهت تعریف سادهتر یک DateTime:
امکان استفاده از StringSyntax در دات نتهای پیش از نگارش 7
هرچند StringSyntax در دات نت 7 تعریف شدهاست؛ اما اگر تعریف کلاس زیر را به همراه فضای نام دقیق آن به پروژههای قدیمیتر هم اضافه کنیم ... برای دات نتهای پیش از نگارش 7 هم کار میکند:
#if !NET7_0_OR_GREATER namespace System.Diagnostics.CodeAnalysis { /// <summary>Specifies the syntax used in a string.</summary> [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] public sealed class StringSyntaxAttribute : Attribute { /// <summary>The syntax identifier for strings containing composite formats for string formatting.</summary> public const string CompositeFormat = "CompositeFormat"; /// <summary>The syntax identifier for strings containing date format specifiers.</summary> public const string DateOnlyFormat = "DateOnlyFormat"; /// <summary>The syntax identifier for strings containing date and time format specifiers.</summary> public const string DateTimeFormat = "DateTimeFormat"; /// <summary>The syntax identifier for strings containing <see cref="T:System.Enum" /> format specifiers.</summary> public const string EnumFormat = "EnumFormat"; /// <summary>The syntax identifier for strings containing <see cref="T:System.Guid" /> format specifiers.</summary> public const string GuidFormat = "GuidFormat"; /// <summary>The syntax identifier for strings containing JavaScript Object Notation (JSON).</summary> public const string Json = "Json"; /// <summary>The syntax identifier for strings containing numeric format specifiers.</summary> public const string NumericFormat = "NumericFormat"; /// <summary>The syntax identifier for strings containing regular expressions.</summary> public const string Regex = "Regex"; /// <summary>The syntax identifier for strings containing time format specifiers.</summary> public const string TimeOnlyFormat = "TimeOnlyFormat"; /// <summary>The syntax identifier for strings containing <see cref="T:System.TimeSpan" /> format specifiers.</summary> public const string TimeSpanFormat = "TimeSpanFormat"; /// <summary>The syntax identifier for strings containing URIs.</summary> public const string Uri = "Uri"; /// <summary>The syntax identifier for strings containing XML.</summary> public const string Xml = "Xml"; /// <summary>Initializes the <see cref="T:System.Diagnostics.CodeAnalysis.StringSyntaxAttribute" /> with the identifier of the syntax used.</summary> /// <param name="syntax">The syntax identifier.</param> public StringSyntaxAttribute(string syntax) { this.Syntax = syntax; this.Arguments = Array.Empty<object>(); } /// <summary>Initializes the <see cref="T:System.Diagnostics.CodeAnalysis.StringSyntaxAttribute" /> with the identifier of the syntax used.</summary> /// <param name="syntax">The syntax identifier.</param> /// <param name="arguments">Optional arguments associated with the specific syntax employed.</param> public StringSyntaxAttribute(string syntax, params object?[] arguments) { this.Syntax = syntax; this.Arguments = arguments; } /// <summary>Gets the identifier of the syntax used.</summary> public string Syntax { get; } /// <summary>Gets the optional arguments associated with the specific syntax employed.</summary> public object?[] Arguments { get; } } } #endif
نحوه ساخت Pipe سفارشی
علاوه بر استفاده از Pipeهای از پیش ساخته شده Angular، شما میتوانید Pipeهای سفارشی خود را نیز تعریف و استفاده کنید. به عنوان مثال میخواهیم Pipe ای را با نام perNumber تعریف کنیم، تا تمامی اعداد موجود در عبارت ورودی Pipe را به صورت اعداد فارسی نمایش دهد. یعنی با اعمال این Pipe به عدد 123456 خروجی ۱۲۳۴۵۶ مورد انتظار است. برای ایجاد Pipe سفارشی مراحل زیر را انجام دهید.
قدم اول - ساخت یک فایل با نام دلخواه
طبق Style Guide در Angular.io نام این فایل را per-number.pipe.ts انتخاب میکنیم.
قدم دوم – افزودن ماژولهای مورد نیاز
داخل فایل ایجاد شده ماژولهای Pipe و PipeTransform را با استفاده از دستور import از angular/core@ اضافه میکنیم.
import { Pipe, PipeTransform } from '@angular/core';
قدم سوم – ساخت کلاس و مزین کردن آن به Pipe@
یک کلاس با نام دلخواه را مثلا به نام PerNumberPipe ایجاد میکنیم. این کلاس علاوه بر اینکه PipeTransform را پیاده سازی خواهد کرد، مزین به متادیتای Pipe@ نیز میباشد. متادیتای Pipe@ هنگام تزئین کلاس، یک نام را دریافت میکند. این نام قرار است به عنوان نام نهایی Pipe برای اعمال بر روی Template expressions مورد استفاده قرار بگیرد.
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'perNumber'}) export class PerNumberPipe implements PipeTransform { }
قدم چهارم – پیاده سازی متد transform
به واسطه اعمال اینترفیس PipeTransform، این کلاس باید متد transform را پیاده سازی کند. این متد در پارامتر اول خود، عبارت ورودی را که قرار است Pipe بر روی آن اعمال شود، دریافت میکند و در ادامه تعداد دلخواهی پارامتر ورودی Pipe را که میخواهد، میتواند دریافت کند.
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'perNumber'}) export class PerNumberPipe implements PipeTransform { transform(value: any, ...args: any[]): any { } }
نکته ۱: نام انتخابی برای Pipe در آذینگر Pipe@ بایستی یک شناسه معتبر در JavaScript باشد.
نکته ۲: متد transform برای Pipe اجباری است و حتما بایستی پیاده سازی شود. اینترفیس PipeTransform این متد را برای کلاس اجباری میکند؛ هرچند استفاده از این اینترفیس برای کلاس Pipe کاملا اختیاری است.
قدم آخر – نوشتن کد تبدیل اعداد
Pipe مورد نظر ما قرار است یک رشته عددی را از ورودی دریافت کند و تمامی اعداد لاتین آن را به فارسی تبدیل کند. همچنین این Pipe هیچگونه پارامتری را دریافت نمیکند. کد زیر نحوه پیاده سازی متد transform را نمایش میدهد.
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'perNumber'}) export class PerNumberPipe implements PipeTransform { transform(input: string): string{ if (input == undefined) return ''; var str = input.toString().trim(); if (str === "") return ""; str = str.replace(/0/g, '۰'); str = str.replace(/1/g, '۱'); str = str.replace(/2/g, '۲'); str = str.replace(/3/g, '۳'); str = str.replace(/4/g, '۴'); str = str.replace(/5/g, '۵'); str = str.replace(/6/g, '۶'); str = str.replace(/7/g, '۷'); str = str.replace(/8/g, '۸'); str = str.replace(/9/g, '۹'); return str; } }
نحوه معرفی Pipe سفارشی به برنامه
حالا جهت استفاده از Pipe سفارشی در کامپوننتهای خود کافی است آنرا یکبار در قسمت declarations در AppModule خود تعریف کنید.
import { PerNumberPipe } from './pipes/per-number.pipe.ts' ... declarations: [PerNumberPipe]
نحوه استفاده از Pipeهای سفارشی
نحوه استفاده از Pipeهای سفارشی، دقیقا مشابه Pipeهای از قبل ساخته شده Angular میباشد.
<h3>{{'12345679' | perNumber}}</h3>
یکسری از Pipeهای مربوط به زبان فارسی در گیتهاب بنده پیاده سازی شده است که نیازمند همکاری دوستان است. لطفا جهت همکاری برای ساخت یک ابزار جامع برای زبان فارسی در Angular به این لینک مراجعه کنید.
Pipeها و تشخیص تغییرات
Angular برای اعمال Pipe بر روی Template expressions بایستی تمامی رخدادهای برنامه را تحت نظر قرار داده و با مشاهده هر تغییری بر روی عبارت ورودی Pipe، فراخوانی Pipe را آغاز کند. از جمله این رخدادها میتوان به رخداد mouse move، timer tick، server response و فشرده شدن کلیدهای ماوس و یا کیبورد اشاره کرد. واضح است که بررسی تغییرات عبارت در این همه رخداد میتواند مخرب باشد و بر روی کارآئی (Performance) تاثیر منفی خواهد گذاشت. اما Angular برای حل این مشکل و همچنین هنگام مشاهده سریع تغییرات هنگام استفاده از Pipeها، الگوریتمهای سریع و سادهای در نظر گرفته است.
در قسمت بعد با انواع Pipeها در Angular و همچنین نحوه پیاده سازی آنها، آشنا خواهیم شد.
show how easy it is to add real-time functionality to your web applications using ASP.NET Core SignalR. They discuss topics such as targeting with clients, SignalR transports, and options for running your SignalR application in the cloud.
Now, you can even leverage the Hub protocol spec is the available on GitHub if you're interested in creating your own SignalR client.