اشتراک‌ها
انتشار Samsung Releases 4th Preview of Visual Studio Tools for Tizen including support for .NET Core 2.0 Preview

Samsung has released the fourth preview of Visual Studio Tools for Tizen. Tizen is a Linux-based open source OS running on over 50 million Samsung devices including TVs, wearables, and mobile phones. Since announcing its collaboration with Microsoft on .NET Core and Xamarin.Forms projects last November, Samsung has steadily released preview versions of.NET support for Tizen with enriched features, such as supporting TV application development and various Visual Studio tools for Tizen.

انتشار Samsung Releases 4th Preview of Visual Studio Tools for Tizen including support for .NET Core 2.0 Preview
مطالب
عدم نمایش Ribbon برای کاربران ناشناس (Anonymous Users) در شیرپوینت
یکی از نیاز‌های مشتریان هنگام استفاده از سایت‌های تحت شیرپوینت ، عدم نمایش نوار مدیریتی بالای صفحه یا همان Ribbon برای کاربران ناشناس است .
شاید بتوان گفت که مزیت این راهکار نسبت به دیگر راه کار‌ها ، تصحیح نمایش Scroll Bar مرورگر است که ممکن است در برخی روش‌ها با مشکل مواجه شود. دلیل این امر هم این است که شیرپوینت برای افزودن Ribbon به بالای صفحه Vertical Scroll Bar را از صفحه حذف می‌کند و سپس Scroll Bar سفارشی خود را به صفحه طوری اضافه می‌کند تا نوار Ribbon همیشه در بالا‌ترین نقطه از صفحه بماند
همچنین در این روش از بارگذاری نوار هنگام بالا آمدن سایت نیز البته برای کاربران ناشناس جلوگیری می‌شود
 و اما روش :
 سایت خود را با SharePoint Designer باز کرده و از Master Page یک کپی تهیه کنید و آن را به عنوان پیش فرض سایت تعیین کنید 

سپس تگ زیر را در صفحه بیابید : 
<div id="s4-ribbonrow">
و تگ زیر را به ابتدای آن (قبل از تگ) اضافه کنید : 
<Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="AddDelPrivateWebParts">
مانند تصویر زیر : 

و تگ پایانی آن : 

نکته مهم در استفاده از این تگ ، ویژگی Permissions آن است که باید با دقت و بسته به نیاز شما تعریف شود :

برخی از این موارد عبارتند از : 

EmptyMask – Has no permissions on the Web site. Not available through the user interface.

ViewListItems – View items in lists, documents in document libraries, and view Web discussion comments.

AddListItems – Add items to lists, add documents to document libraries, and add Web discussion comments.

EditListItems – Edit items in lists, edit documents in document libraries, edit Web discussion comments in documents, and customize Web Part Pages in document libraries.

DeleteListItems – Delete items from a list, documents from a document library, and Web discussion comments in documents.

ApproveItems – Approve a minor version of a list item or document.

OpenItems – View the source of documents with server-side file handlers.

ViewVersions – View past versions of a list item or document.

DeleteVersions – Delete past versions of a list item or document.

CancelCheckout – Discard or check in a document which is checked out to another user.

ManagePersonalViews – Create, change, and delete personal views of lists.

ManageLists – Create and delete lists, add or remove columns in a list, and add or remove public views of a list.

ViewFormPages – View forms, views, and application pages, and enumerate lists.

Open – Allow users to open a Web site, list, or folder to access items inside that container.

ViewPages – View pages in a Web site.

AddAndCustomizePages – Add, change, or delete HTML pages or Web Part Pages, and edit the Web site using a SharePoint Foundation–compatible editor.

ApplyThemeAndBorder – Apply a theme or borders to the entire Web site.

ApplyStyleSheets – Apply a style sheet (.css file) to the Web site.

ViewUsageData – View reports on Web site usage.

CreateSSCSite – Create a Web site using Self-Service Site Creation.

ManageSubwebs – Create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites.

CreateGroups – Create a group of users that can be used anywhere within the site collection.

ManagePermissions – Create and change permission levels on the Web site and assign permissions to users and groups.

BrowseDirectories – Enumerate files and folders in a Web site using Microsoft Office SharePoint Designer 2007 and WebDAV interfaces.

BrowseUserInfo – View information about users of the Web site.

AddDelPrivateWebParts – Add or remove personal Web Parts on a Web Part Page.

UpdatePersonalWebParts – Update Web Parts to display personalized information.

ManageWeb – Grant the ability to perform all administration tasks for the Web site as well as manage content. Activate, deactivate, or edit properties of Web site scoped Features through the object model or through the user interface (UI). When granted on the root Web site of a site collection, activate, deactivate, or edit properties of site collection scoped Features through the object model. To browse to the Site Collection Features page and activate or deactivate site collection scoped Features through the UI, you must be a site collection administrator.

UseClientIntegration – Use features that launch client applications; otherwise, users must work on documents locally and upload changes.

UseRemoteAPIs – Use SOAP, WebDAV, or Microsoft Office SharePoint Designer 2007 interfaces to access the Web site.

ManageAlerts – Manage alerts for all users of the Web site.

CreateAlerts – Create e-mail alerts.

EditMyUserInfo – Allows a user to change his or her user information, such as adding a picture.

EnumeratePermissions – Enumerate permissions on the Web site, list, folder, document, or list item.

FullMask – Has all permissions on the Web site. Not available through the user interface.

حال خارج از تگ‌های SPSecurityTrimmedControl در ابتدا یا انتها ، باید تگ login را مانند زیر به آن اضافه کرد . 

و تمام : 

موفق باشید 

اشتراک‌ها
امکان استفاده از کامپوننت‌های Blazor در برنامه‌های SPA مانند React و Angular در دات نت 6

Once created, these custom elements -- a custom counter, for example -- can also be used in other single-page application (SPA) web frameworks such as React and Angular. A sample project, aptly titled Blazor Custom Elements, shows how to do just that, providing examples about how to work with those frameworks and the client-side Blazor WebAssembly component as well as Blazor Server.  

امکان استفاده از کامپوننت‌های Blazor در برنامه‌های SPA مانند React و Angular در دات نت 6
اشتراک‌ها
معرفی کتابخانه InfiniteEnumFlags

Enum‌های دات نت با [Flags] attribute, ویژگی قدرتمندی است که امکان ذخیره و ترکیب چندین گزینه یا Feature را تنها به صورت یک مقدار ثابت فراهم میکند که از طریق Bitwise operator‌ها میتوانیم به ترکیب چندین Enum بپردازیم و یا از طریق این مقدار ثابت به تک تک اعضای تشکیل دهنده آن برسیم. ولی مشکل بزرگی این این ویژگی دارد محدودیت آن است که برای Enum هایی از نوع int تنها 32 آیتم و از نوع long تنها 64 مورد را پشتیبانی میکند. این مشکل سبب میشود در اکثر سناریو‌ها به سراغ این ویژگی نرویم, 

به طور مثال برای تعریف دسترسی‌های یک نرم افزار به صورت Strongly Type به احتمال زیاد با بزرگ‌تر شدن برنامه در آینده به مشکل برخورد میکنیم.

InfiniteEnumFlags کتابخانه کوچکی است که تمام امکانات [Flags] را در اختیار ما میگذارد و میتواند حدود 2.1 میلیارد آیتم را پشتیبانی کند. 

public class Permission : InfiniteEnum<Permission>
{
    public static readonly Flag<Permission> None = new(-1);
    public static readonly Flag<Permission> ViewRoles = new(0);
    public static readonly Flag<Permission> ManageRoles = new(1);
    public static readonly Flag<Permission> ViewUsers = new(2);
    public static readonly Flag<Permission> ManageUsers = new(3);
    public static readonly Flag<Permission> ConfigureAccessControl = new(4);
    public static readonly Flag<Permission> Counter = new(5);
    public static readonly Flag<Permission> Forecast = new(6);
    public static readonly Flag<Permission> ViewAccessControl = new(7);

    // We can support up to 2,147,483,647 items

}


مثال استفاده از آن برای تعریف سطح دسترسی‌ها در برنامه‌های Asp.net core  در فولدر Example این مخزن میتوانید پیدا کنید.

 git clone --recurse-submodules https://github.com/alirezanet/InfiniteEnumFlags.git


معرفی کتابخانه  InfiniteEnumFlags
مطالب
ایجاد بارکد به همراه یک متن
در این مقاله یک بارکد را به همراه یک متن در پایین آن، مشابه تصویر زیر ایجاد میکنیم. سورس کامل این مطلب در این آدرس قرار دارد. جهت تست بارکد از این آدرس استفاده کنید.

- طول عکس خروجی نهایی 250 پیکسل است.

- فونت متن 10 پیکسل هست و عرض هر خط 17 پیکسل.

- حداکثر تعداد خطِ نمایش متن، 3 خط است و اگر متن برای نمایش، به 3 خط بیشتر نیاز داشت، اضافه‌ی متن را به صورت 3 نقطه نمایش میدهیم (مثل عکس بالا).

- عرض بارکد 50 پیکسل است.

- فاصله بین بارکد و متن 5 پیکسل است.

public static class BarcodeHelper
{
    public static string GenerateBarcodeWithText(string input, string textBelow)
    {
        // barcode: 50 pixels
        // margin: top 5 pixels
        // height of each text line is 17 pixels
        // text: maximum 3 lines
        // each 30 letters is: 1 line

        var eachLineHeight = 17;

        var eachLineLetters = 30;

        var maximumLines = 3;

        var maximumTextHeight = eachLineHeight * maximumLines;

        var resultWidth = 250;

        var barcodeHeight = 50;

        var textY = barcodeHeight + 5;

        // each 30 letters is: 1 line for example input length is 150 letters and for show 100 letters we need (150 / 30) 5 lines
        // each line is 17 pixels and text height will be (17 * 5) 102 pixels
        var textHeight = (textBelow.Length / eachLineLetters) * eachLineHeight;

        // if height of text be greater than (eachLineHeight * maximumLines) we use maximum text height (eachLineHeight * maximumLines)
        textHeight = textHeight > maximumTextHeight ? maximumTextHeight : textHeight;

        // if text height be less than 1 line we set 1 line height (17 pixels) to the text height
        // text height minimum is equal 1 linle (17 pixels)
        textHeight = textHeight < eachLineHeight ? eachLineHeight : textHeight;

        var resultHeight = textY + textHeight;
    }
}


چون ما از Bitmap و Image استفاده میکنیم، پس به پکیچ System.Drawing.Common نیاز داریم:

<ItemGroup>
    <PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>

اولین کاری که انجام میدهیم، یک Bitmap را ایجاد میکنیم و بعد یک مستطیل را به اندازه‌ی خود Bitmap ایجاد میکنیم و با کلاس Graphics، به نارنجی، رنگش میکنیم و داخل Bitmap میریزیم و در نهایت عکس ایجاد شده را در حافظه‌ی رم ذخیره میکنیم.

- Bitmap فضایی را در اختیار ما قرار میدهد که داخلش هر چیزی را ترسیم کنیم.

- Graphics به ما کمک میکند که عملیات گرافیکی را نظیر رنگ آمیزی، ترسیم عکس و ... روی یک شیء انجام دهیم.

- MemoryStream برای ذخیره سازی موقت در حافظه‌ی رم به کار میاد؛ عکس ایجاد شده‌ی تا این لحظه را که یک مستطیل نارنجی رنگ هست، در داخل رم ذخیره میکنیم.

#region MainBitmap

var mainBitmap = new Bitmap(resultWidth, resultHeight);
using var rectangleGraphics = Graphics.FromImage(mainBitmap);
{
    var rectangle = new Rectangle(0, 0, resultWidth, resultHeight);
    rectangleGraphics.FillRectangle(Brushes.OrangeRed, rectangle);
}

using var rectangleStream = new MemoryStream();
{
    mainBitmap.Save(rectangleStream, ImageFormat.Png);
}

#endregion

خروجی تا این لحظه:

حالا باید بارکد را ایجاد کنیم و عکس خروجی بارکد را داخل این مستطیل بریزیم؛ برای اینکار از کتابخانه BarcodeLib استفاده میکنیم:

private static Bitmap GenerateBarcodeImage(string input, int width, int height)
{
    var barcodeInstance = new Barcode();
    var barcodeImage = barcodeInstance.Encode(BarcodeLib.TYPE.CODE39, input, Color.Black,
        Color.OrangeRed, width, height);
    using var barcodeStream = new MemoryStream();
    {
        barcodeImage.Save(barcodeStream, ImageFormat.Png);
    }
    return (Bitmap)Image.FromStream(barcodeStream);
}

و الان این عکس بارکد را داخل مستطیل اصلی میریزیم و هر دو را Merge میکنیم:

#region Barcode

var barcodeImage = GenerateBarcodeImage(input, resultWidth, barcodeHeight);

#endregion

#region MergedRectangleAndBarcode

var newMainBitmap = (Bitmap)Image.FromStream(rectangleStream);
var newBarcodeBitmap = barcodeImage;
using var newRectangleGraphics = Graphics.FromImage(newMainBitmap);
{
    newRectangleGraphics.DrawImage(newBarcodeBitmap, 0, 0);
}

using var mergedRectangleAndBarcodeStream = new MemoryStream();
{
    newMainBitmap.Save(mergedRectangleAndBarcodeStream, ImageFormat.Png);
}

#endregion

خروجی تا این لحظه :

حالا باید 5 پیکسل از پایین بارکد فاصله بگیریم و متن را بنویسیم.

برای اینکار از یک مستطیل کمک میگیریم. یعنی یک مستطیل بدون هیچ رنگ و Border ـی را پایین این بارکد ایجاد میکنیم، چرا؟ دلیل این است که میخواهیم متن‌مان را به صورت وسط چین، از راست و چپ، و وسط از بالا و پایین قرار بدیم و برای اینکار میگیم این نسبت وسط چین بودن از راست و چپ، وسط بودن از بالا و پایین را از مستطیل پایین بارکد کمک بگیر، خلاصه‌اش می‌شود اینکه از مستطیلِ پایینِ بارکد برای وسط چین بودن متن از راست و چپ و وسط بودن از بالا و پایین استفاده میکنیم.

#region WriteText

var barcodeBitmap = (Bitmap)Image.FromStream(mergedRectangleAndBarcodeStream);
using var graphics = Graphics.FromImage(barcodeBitmap);
{
    using var font = new Font("Tahoma", 10);
    {
        var rect = new Rectangle(0, textY, resultWidth, textHeight);
        var sf = new StringFormat();
        sf.Alignment = StringAlignment.Center;
        sf.Trimming = StringTrimming.EllipsisCharacter;
        sf.FormatFlags = StringFormatFlags.DirectionRightToLeft;
        sf.LineAlignment = StringAlignment.Center;
        graphics.DrawString(textBelow, font, Brushes.Black, rect, sf);
        //graphics.DrawRectangle(Pens.Green, rect);
    }
}

using var finalStream = new MemoryStream();
{
    barcodeBitmap.Save(finalStream, ImageFormat.Png);
}

#endregion

graphics.DrawString می‌گوید textBelow را با font تاهوما و با رنگ سیاه، داخل rect (مستطیل) و با این تنظیماتِ متن بریز.

Alignment متن را وسط چین می‌کند (این وسط چین شدن نسبت به مستطیل پایین بارکد است که هیچ رنگ و Border ـی ندارد) .

LineAlignment متن را از بالا و پایین میارد وسط (این وسط شدن نسبت به مستطیل پایین بارکد است که هیچ رنگ و Border ـی ندارد).

EllipsisCharacter اگر متن طولانی باشد، اضافه متن را به صورت سه نقطه نمایش می‌دهد.

DirectionRightToLeft متن را RTL می‌کند.

خروجی نهایی:

عکس نهایی به صورت Stream ذخیره شده‌است، آن‌را به فرمت Base64 تبدیل میکنیم و برگشت میزنیم.

return Convert.ToBase64String(finalStream.ToArray());

برای نمایش یک آرایه بایتی که به فرمت Base64 تبدیل شده، به این روش عمل میکنیم:

<img src="data:image/png;base64, @BarcodeHelper.GenerateBarcodeWithText("barcode text", "below text")" />

چون برای ایجاد بارکد از تایپ 39 استفاده کرده‌ایم و تایپ 39 فقط حروف بزرگ انگلیسی را پشتیبانی میکند، پس برای اینکه دچار خطا نشویم، میتوانیم ابتدای متدمان، از این کد استفاده کنیم:

// Type 39 doesn't support lower case letters, for prevent exception, we convert all input letters to upper case
// more details: https://www.dntips.ir/newsarchive/details/18019
input = input.ToUpperInvariant();

همچنین جهت تشخیص خودکار راست به چک بودن متن پایین بارکد، میتوان از متد ContainsFarsi در پکیج DNTPersianUtils.Core استفاده کرد:

if (textBelow.ContainsFarsi())
    sf.FormatFlags = StringFormatFlags.DirectionRightToLeft;
اشتراک‌ها
دریافت C# 9 Cheat Sheet

C# 9 Cheat Sheet with code example and pros and cons.

  • Records
  • Init only setters
  • Top-level statements
  • Pattern matching enhancements
  • Native sized integers
  • Function pointers
  • Suppress emitting localsinit flag
  • Target-typed new expressions
  • static anonymous functions
  • Target-typed conditional expressions
  • Covariant return types
  • Extension GetEnumerator support for foreach loops
  • Lambda discard parameters
  • Attributes on local functions
  • Module initializers
  • New features for partial methods 
دریافت C# 9 Cheat Sheet
اشتراک‌ها
Rider 2024.2.6 منتشر شد
Rider 2024.2.6 is out and introduces highly requested support for the .slnx format for solution files. This build also has several important fixes. The Show Diff Preview on Single Click option is available in the Commit dialog again, and there is no longer an issue with copying and pasting text from Rider when CWM is enabled.
Rider 2024.2.6 منتشر شد
اشتراک‌ها
CI / CD ساده با GitHub در دات نت

گیتهاب برای راه اندازی CI/CD از GitHub Actions استفاده می‌کند که می‌توانید مستندات آن را در اینجا مشاهده کنید و به صورت کامل با آن آشنا شوید. در اینجا با یک مثال با مراحل راه‌اندازی CI/CD به وسیله GitHub آشنا می‌شویم. 

نمونه کد این مطلب با روند انجامش رو می‌تونید از اینجا بگیرید . 

CI / CD ساده با GitHub در دات نت
اشتراک‌ها
رایگان شدن مخازن خصوصی github

سرویس github مخازن خصوصی خود رو رایگان کرد. از این پس می‌توان بصورت نامحدود repository‌های private ایجاد کرد. البته نسخه رایگان شامل محدودیت هایی خواهد بود:

- عدم اضافه کردن wiki

- محدودیت تعداد مشارکت کننده‌ها به 3 نفر

- عدم ساخت github page

رایگان شدن مخازن خصوصی github
نظرات مطالب
PowerShell 7.x - قسمت دوازدهم - آشنایی با GitHub Actions و بررسی یک مثال
یک نکته‌ی تکمیلی: شبیه سازی mikeal/publish-to-github-action@master با کدنویسی مستقیم
این اکشن که جهت به روز رسانی مخزن کد، با تغییرات جدید است، بر اساس سرورهای لینوکسی کار می‌کند و اگر از سرور ویندوزی استفاده شود، خطا خواهد داد که می‌شود آن‌را با معادل زیر، جایگزین کرد:
      - name: Push changes to repo          
        run: |      
          git config http.sslVerify false
          git config user.name "${{ github.actor }}"
          git config user.email "${{ github.actor }}@users.noreply.github.com"
          git remote add publisher "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
          git show-ref
          git branch --verbose
          git lfs install
          git checkout main
          git add -A
          git commit -m "Automated publish"
          git pull --rebase publisher main
          git push publisher main
نکته‌ی مهم! اگر این قطعه کد را به انتهای فایل yml اکشن خود اضافه کنید، با خطای «نداشتن دسترسی»، خاتمه پیدا می‌کند. برای رفع این مشکل، مسیر «Settings > Actions > General» را در مخزن کد جاری، طی کرده و در انتهای صفحه، گزینه‌ی «Read and write permissions» را انتخاب کنید. حالت پیش‌فرض آن «Read repository contents permission» است که برای اعمال تغییرات کافی نیست.