DECLARE @char CHAR = ''
DECLARE @charI INT = 0
DECLARE @password VARCHAR(100) = ''
DECLARE @len INT = 12 -- Length of Password
WHILE @len > 0
BEGIN
SET @charI = ROUND(RAND()*100,0)
SET @char = CHAR(@charI)
IF @charI > 48 AND @charI < 122
BEGIN
SET @password += @char
SET @len = @len - 1
END
END
SELECT @password [PassWord]
نظرات مطالب
انواع روشهای خلاقانه تولید رشتههای تصادفی
- خیر. بازگشت دادن اعداد تکراری جزو خواص تولید کنندههای این اعداد است؛ در جهت ارائهی یک پوشش آماری مناسب.
- برای اینکار بهتر است از Guid استفاده کنید:
- و یک بحث مفصل در مورد تولید اعداد تکراری منحصربفرد
- برای اینکار بهتر است از Guid استفاده کنید:
//This code generates numbers between 1 - 100 and then takes 10 of them. var result = Enumerable.Range(1,101).OrderBy(g => Guid.NewGuid()).Take(10).ToArray();
اشتراکها
۳۰ روز با TDD
نظرات مطالب
نوشتن افزونه برای مرورگرها: قسمت اول : کروم
عدم پشتیبانی افزودن افزونهها در نوار address bar
نظرات مطالب
ویدیوهای رایگان آموزش jQuery
برای تمام ویدیوها فوق mirror تهیه کردهام:
https://www.dntips.ir/2008/12/mirror.html
و mirror برای ویدیوهای جدید این مجموعه:
Day 14: Implementing Your First Plugin
http://rapidshare.com/files/181363327/v3bg115310.flv
Day 15: Building a jQuery Style-Switcher: Part 1
http://rapidshare.com/files/181363189/n62ldrzuyo.flv
Day 15: Building a jQuery Style-Switcher: Part 2
http://rapidshare.com/files/181363345/qkrwv8jzsf.flv
https://www.dntips.ir/2008/12/mirror.html
و mirror برای ویدیوهای جدید این مجموعه:
Day 14: Implementing Your First Plugin
http://rapidshare.com/files/181363327/v3bg115310.flv
Day 15: Building a jQuery Style-Switcher: Part 1
http://rapidshare.com/files/181363189/n62ldrzuyo.flv
Day 15: Building a jQuery Style-Switcher: Part 2
http://rapidshare.com/files/181363345/qkrwv8jzsf.flv
اشتراکها
Vue.js 3.0 منتشر شد
Today we are proud to announce the official release of Vue.js 3.0 "One Piece". This new major version of the framework provides improved performance, smaller bundle sizes, better TypeScript integration, new APIs for tackling large scale use cases, and a solid foundation for long-term future iterations of the framework.
I just finished teaching the first week of a 9-week, super-intensive, hands-on boot camp that focuses on TypeScript/ASP.NET Web API/AngularJS. I decided to write a series of blog posts that describes each week of the camp. Who makes it. The challenges the students encounter. And, the material that we cover
ASP.NET MVC از روش بکارگیری binding providerها برای تدارک زیرساخت model binding استفاده میکند که در این روش، دادههای پارامترهای یک action method از طریق هدرها، کوئری استرینگها، بدنهی درخواست و غیره تهیه میشوند. در حالت پیشفرض اگر این پارامترها از نوعهای سادهای مانند اعداد و یا DateTime تشکیل شده باشند و یا به همراه یک TypeConverter باشند که امکان تبدیل این رشته را به آن نوع خاص بدهد، به صورت خودکار bind خواهند شد و هر نوع دیگری، به صورت یک نوع پیچیده درنظر گرفته میشود. نوع پیچیده یعنی bind برای مثال اطلاعات بدنهی درخواست به تک تک خواص آن نوع. برای نمونه در کنترلر زیر:
که از دو مدل زیر استفاده میکند:
میتوان خواص پارامتر days را از طریق کوئری استرینگهای HttpGet، برای مثال با ارائهی آدرس WeatherForecast/GetForecast2?from=1&to=3 به صورت خودکار تامین کرد. زمانیکه اطلاعات رسیده چنین شکلی را داشته باشند، کار پردازش و bind آنها در حالت HttpGet، خودکار است.
روش دیگر پردازش اطلاعات رشتهای رسیده و تشکیل یک Model Binder سفارشی در ASP.NET Core 7x
اکنون فرض کنید بجای آدرس WeatherForecast/GetForecast2?from=1&to=3 که اطلاعات را از طریق کوئری استرینگ مشخص و استانداردی دریافت میکند، میخواهیم اطلاعات آنرا از طریق یک قالب سفارشی و غیراستاندارد مانند WeatherForecast/GetForecast3/1-3 دریافت کنیم:
یکی از راههای انجام اینکار، نوشتن model binderهای سفارشی مخصوص است و یا اکنون در ASP.NET Core 7x میتوان با پیاده سازی اینترفیس IParsable به صورت خودکار و با روشی دیگر به این مقصود رسید:
- برای پیاده سازی این اینترفیس باید دو متد TryParse و Parse آنرا به صورت فوق پیاده سازی کرد و توسط آن، روش تبدیل رشتهی دریافتی از کاربر را به شیء مدنظر، مشخص کرد.
- همینقدر که مدلی IParsable را پیاده سازی کرده باشد، از امکانات آن به صورت خودکار استفاده خواهد شد و نیازی به معرفی و یا تنظیمات خاص دیگری ندارد.
- البته این قابلیت جدید نیست و پشتیبانی از IParsable، پیشتر در Minimal API دات نت 6 ارائه شده بود؛ اما در دات نت 7 توسط ASP.NET Core MVC نیز قابل استفاده شدهاست.
[Route("[controller]")] public class WeatherForecastController : ControllerBase { private static readonly string[] Summaries = { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching", }; // /WeatherForecast/GetForecast2?from=1&to=3 [HttpGet("[action]")] public IEnumerable<WeatherForecast> GetForecast2(Duration days) { return Enumerable.Range(days.From, days.To) .Select(index => new WeatherForecast { Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), TemperatureC = Random.Shared.Next(-20, 55), Summary = Summaries[Random.Shared.Next(Summaries.Length)], }) .ToArray(); } }
public class Duration { public int From { get; set; } public int To { get; set; } } public class WeatherForecast { public DateOnly Date { get; set; } public int TemperatureC { get; set; } public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); public string? Summary { get; set; } }
روش دیگر پردازش اطلاعات رشتهای رسیده و تشکیل یک Model Binder سفارشی در ASP.NET Core 7x
اکنون فرض کنید بجای آدرس WeatherForecast/GetForecast2?from=1&to=3 که اطلاعات را از طریق کوئری استرینگ مشخص و استانداردی دریافت میکند، میخواهیم اطلاعات آنرا از طریق یک قالب سفارشی و غیراستاندارد مانند WeatherForecast/GetForecast3/1-3 دریافت کنیم:
// /WeatherForecast/GetForecast3/1-3 [HttpGet("[action]/{days}")] public IEnumerable<WeatherForecast> GetForecast3(Days days) { return Enumerable.Range(days.From, days.To) .Select(index => new WeatherForecast { Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), TemperatureC = Random.Shared.Next(-20, 55), Summary = Summaries[Random.Shared.Next(Summaries.Length)], }) .ToArray(); }
using System.Diagnostics.CodeAnalysis; using System.Globalization; namespace NET7Mvc.Models; public class Days : IParsable<Days> { public Days(int from, int to) { From = from; To = to; } public int From { get; } public int To { get; } public static bool TryParse([NotNullWhen(true)] string? value, IFormatProvider? provider, [MaybeNullWhen(false)] out Days result) { var items = value?.Split('-', StringSplitOptions.RemoveEmptyEntries); if (items is { Length: 2 }) { if (int.TryParse(items[0], NumberStyles.None, provider, out var from) && int.TryParse(items[1], NumberStyles.None, provider, out var to)) { result = new Days(from, to); return true; } } result = default; return false; } public static Days Parse(string value, IFormatProvider? provider) { if (!TryParse(value, provider, out var result)) { throw new ArgumentException("Could not parse the given value.", nameof(value)); } return result; } }
- همینقدر که مدلی IParsable را پیاده سازی کرده باشد، از امکانات آن به صورت خودکار استفاده خواهد شد و نیازی به معرفی و یا تنظیمات خاص دیگری ندارد.
- البته این قابلیت جدید نیست و پشتیبانی از IParsable، پیشتر در Minimal API دات نت 6 ارائه شده بود؛ اما در دات نت 7 توسط ASP.NET Core MVC نیز قابل استفاده شدهاست.