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.
<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 را مانند زیر به آن اضافه کرد .
و تمام :
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.
معرفی کتابخانه 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
- طول عکس خروجی نهایی 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
Rider 2024.2.6 منتشر شد
CI / CD ساده با GitHub در دات نت
گیتهاب برای راه اندازی CI/CD از GitHub Actions استفاده میکند که میتوانید مستندات آن را در اینجا مشاهده کنید و به صورت کامل با آن آشنا شوید. در اینجا با یک مثال با مراحل راهاندازی CI/CD به وسیله GitHub آشنا میشویم.
نمونه کد این مطلب با روند انجامش رو میتونید از اینجا بگیرید .
رایگان شدن مخازن خصوصی github
- 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