SayehBanTools 2.1.0
dotnet add package SayehBanTools --version 2.1.0
NuGet\Install-Package SayehBanTools -Version 2.1.0
<PackageReference Include="SayehBanTools" Version="2.1.0" />
<PackageVersion Include="SayehBanTools" Version="2.1.0" />
<PackageReference Include="SayehBanTools" />
paket add SayehBanTools --version 2.1.0
#r "nuget: SayehBanTools, 2.1.0"
#:package SayehBanTools@2.1.0
#addin nuget:?package=SayehBanTools&version=2.1.0
#tool nuget:?package=SayehBanTools&version=2.1.0
SayehBanTools - راهنمای استفاده
یک کتابخانه چندمنظوره برای توسعهدهندگان داتنت با قابلیتهای متنوع
فهرست مطالب
نصب
برای نصب کتابخانه از NuGet استفاده کنید:
dotnet add package SayehBanTools
یا در Visual Studio از طریق Package Manager Console:
Install-Package SayehBanTools
کلاسها و قابلیتها
IPAccess
بررسی محدوده IP:
bool isInRange = IPAccess.IsInRange("192.168.1.5", "192.168.1.1", "192.168.1.10");
// true اگر IP در محدوده باشد
Calculator
انجام محاسبات ریاضی:
// جمع
double sum = Calculator.Add(5, 10, 15); // 30
// ضرب
double product = Calculator.Multiply(2, 3, 4); // 24
// تخفیف
decimal discounted = Calculator.Discount(1000, 20); // 800
// مالیات
decimal taxed = Calculator.Taxation(1000, 9); // 1090
RabbitMQ
پیکربندی سرویسها:
services.AddTransient<RabbitMQConnection, RabbitMQConnection>();
services.AddTransient<ISendMessages, RabbitMQMessageBus>();
ارسال پیام:
var message = new BaseMessage();
await _messageBus.SendMessageAsync(message, "exchange_name", "queue_name");
مدیریت فایلها
var fileManager = new ManageFiles();
// آپلود فایل
string uploadedPath = await fileManager.UploadFileAsync("/uploads", file);
// حذف فایل
fileManager.DeleteFileServer("/uploads/file.txt");
تبدیل اعداد
// عدد به حروف
string words = ConvertNumToString.convert("123456789");
// "صد و بیست و سه میلیون و چهارصد و پنجاه و شش هزار و هفتصد و هشتاد و نه"
// عدد به رشته فارسی
string persianNumber = "123456".En2Fa(); // "۱۲۳۴۵۶"
مدیریت رشتهها
// تبدیل اعداد انگلیسی به فارسی
string persianNum = "123".En2Fa(); // "۱۲۳"
// تبدیل اعداد فارسی به انگلیسی
string englishNum = "۱۲۳".Fa2En(); // "123"
// حذف تگهای HTML
string cleanHtml = "<div>Test</div>".HtmlTags(); // "Test"
رمزنگاری
// رمزنگاری
string encrypted = await StringEncryptor.EncryptAsync("text", "initVector", "passPhrase");
// رمزگشایی
string decrypted = await StringEncryptor.DecryptAsync(encrypted, "initVector", "passPhrase");
⚠️ هشدار:
StringEncryptorرمزنگاری متقارن (Symmetric) است؛ یعنیinitVectorوpassPhraseهر دو در سمت مصرفکننده لازم هستند و متن رمزشده بدون آنها قابل بازیابی است. این روش برای امنسازی در برابر نگاه ساده (مثلاً رشته اتصال در Config) مناسب است، اما نه برای ذخیره رمز عبور کاربر — برای آن از Hashing (مثل BCrypt) استفاده کنید. تازگی Salt/IV در هر دو پکیج یکسان است؛ رشته رمزشدهای که با یک نسخه ساخته شده فقط با همان نسخه رمزگشایی میشود.
تولید مقادیر
// کد ملی معتبر
string nationalCode = NationalCode.GenerateRandom();
// کد تصادفی 16 رقمی
string randomValue = GenerateValues.Generate16ValueRandome();
ارسال پیامک
// ارسال پیامک پترن
var data = new Dictionary<string, object> { { "code", "12345" } };
var result = await SMS_System.SendPatternAsync(apiLink, apiKey, data, "pattern_code", "sender", "09123456789", null);
// بررسی اعتبار
var credit = await SMS_System.GetCreditAsync(apiLink, apiKey);
مدیریت تاریخ
// تبدیل میلادی به شمسی
string shamsiDate = ConvertDateTime.MiladiToShamsi(DateTime.Now);
// تبدیل شمسی به میلادی
DateTime miladiDate = ConvertDateTime.ShamsiToMiladi("1402/05/15");
ترجمه
var translator = new TranslateTexts(new HttpClient());
var request = new TranslationRequest
{
OriginalText = "Hello",
InputLanguage = "en",
OutputLanguage = "fa"
};
var response = await translator.TranslateTextAsync(request);
// response.Translations[0] = "سلام"
مثالهای کد
مثال کامل RabbitMQ
// Startup.cs
services.Configure<RabbitMqConnectionSettings>(Configuration.GetSection("RabbitMQ"));
services.AddTransient<RabbitMQConnection>();
services.AddTransient<ISendMessages, RabbitMQMessageBus>();
// Controller
public class MessageController : Controller
{
private readonly ISendMessages _messageBus;
public MessageController(ISendMessages messageBus)
{
_messageBus = messageBus;
}
[HttpPost]
public async Task<IActionResult> Send([FromBody] MessageDto message)
{
var baseMessage = new BaseMessage();
await _messageBus.SendMessageAsync(baseMessage, "notifications", "emails");
return Ok();
}
}
مثال مدیریت فایل
[HttpPost]
public async Task<IActionResult> Upload(IFormFile file)
{
var fileManager = new ManageFiles();
string path = await fileManager.UploadFileAsync("wwwroot/uploads", file);
return Ok(new { Path = path });
}
کارتخوان PC-POS
اتصال به کارتخوانهای PC-POS بانکی (پروتکل CPML) از طریق پورت سریال یا شبکه. پورتشده از پروژه PC-POS Aramestan.
using SayehBanTools.PCPOS;
// تنظیمات اتصال
var settings = new PosConnectionSettings
{
Brand = PosBrand.SayanKart, // برند دستگاه
ConnectionType = PosConnectionType.SerialPort,
SerialPort = "COM3",
BaudRate = 38400,
SerialTimeout = 30
// یا حالت شبکه:
// ConnectionType = PosConnectionType.Lan,
// LanIp = "192.168.1.100",
// LanPort = 16028, // پورت پیشفرض CPML
// LanTimeout = 60
};
// راه اول: از طریق Singleton
var pos = PosCommander.Instance;
if (pos.Init(settings))
{
Response result = pos.Purchase("فاکتور ۱۲۳", "50000", print: true);
if (result.Success && result.TransactionInfo != null)
Console.WriteLine($"خرید موفق - RRN: {result.TransactionInfo.RRN}، مبلغ: {result.TransactionInfo.Amount}");
}
else
{
Console.WriteLine("اتصال به کارتخوان برقرار نشد");
}
// راه دوم: از طریق Factory (بدون Singleton) - مناسب تزریق وابستگی
IPosProtocol protocol = PosProtocolFactory.Create(PosBrand.SayanKart, settings);
Response info = protocol.GetPosInfo();
Console.WriteLine($"ترمینال: {info.PosInformation.TerminalId}");
سایر عملیات: BalanceInquiry، BillPayment، LastTransaction، LastPcPosTransaction، PrintText، PrintBarcode.
کدهای خطای Response.ErrorCode: 201 عدم اتصال، 202 خطای ارسال، 203 پاسخ خالی، 204 پاسخ نامعتبر.
مشارکت
مشارکتهای شما استقبال میشود! برای مشارکت:
- ریپوی را Fork کنید
- شاخه جدید ایجاد کنید (
git checkout -b feature/AmazingFeature) - تغییرات را Commit کنید (
git commit -m 'Add some AmazingFeature') - Push به شاخه (
git push origin feature/AmazingFeature) - Pull Request باز کنید
مجوز
این پروژه تحت مجوز MIT منتشر شده است. برای اطلاعات بیشتر فایل LICENSE را مطالعه کنید.
📧 برای ارتباط: sdvp1991david@gmail.com
🌍 وبسایت: https://sayehban.ir
💻 مخزن کد: https://github.com/SayyehBan/SayehBanTools
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Dapper (>= 2.1.100)
- Elastic.Clients.Elasticsearch (>= 9.5.3)
- LibVLCSharp (>= 3.10.2)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.14)
- Microsoft.AspNetCore.WebUtilities (>= 11.0.0)
- Microsoft.EntityFrameworkCore (>= 11.0.0)
- Microsoft.Extensions.DependencyInjection (>= 11.0.0)
- Microsoft.Extensions.Features (>= 11.0.0)
- Microsoft.NET.Test.Sdk (>= 18.12.0)
- Newtonsoft.Json (>= 13.0.4)
- OllamaSharp (>= 5.5.2)
- RabbitMQ.Client (>= 7.3.0)
- RestSharp (>= 114.1.0)
- SixLabors.ImageSharp (>= 4.1.3)
- StackExchange.Redis (>= 3.4.35)
- System.IO.Abstractions (>= 23.1.0)
- System.IO.Ports (>= 11.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.0 | 59 | 11/23/2026 |
| 2.0.9 | 58 | 11/23/2026 |
| 2.0.8 | 95 | 11/18/2026 |
| 2.0.7 | 138 | 9/18/2026 |
| 2.0.6 | 196 | 12/20/2025 |
| 2.0.5 | 273 | 12/19/2025 |
| 2.0.4 | 317 | 12/16/2025 |
| 2.0.3 | 319 | 12/16/2025 |
| 2.0.2 | 302 | 12/15/2025 |
| 2.0.1 | 227 | 11/27/2025 |
| 2.0.0 | 203 | 11/23/2025 |
| 1.8.9 | 208 | 11/23/2025 |
| 1.8.8 | 447 | 11/19/2025 |
| 1.8.7 | 283 | 11/16/2025 |
| 1.8.6 | 329 | 11/12/2025 |
| 1.8.5 | 318 | 11/12/2025 |
| 1.8.4 | 334 | 11/11/2025 |
| 1.8.3 | 198 | 11/8/2025 |
| 1.8.2 | 245 | 11/4/2025 |
| 1.8.1 | 241 | 11/3/2025 |