SayehBanTools 2.1.0

dotnet add package SayehBanTools --version 2.1.0
                    
NuGet\Install-Package SayehBanTools -Version 2.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SayehBanTools" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SayehBanTools" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SayehBanTools" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SayehBanTools --version 2.1.0
                    
#r "nuget: SayehBanTools, 2.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SayehBanTools@2.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SayehBanTools&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SayehBanTools&version=2.1.0
                    
Install as a Cake Tool

SayehBanTools - راهنمای استفاده

NuGet Downloads

SayehBanTools Logo

یک کتابخانه چندمنظوره برای توسعه‌دهندگان دات‌نت با قابلیت‌های متنوع

فهرست مطالب

نصب

برای نصب کتابخانه از 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 پاسخ نامعتبر.

مشارکت

مشارکت‌های شما استقبال می‌شود! برای مشارکت:

  1. ریپوی را Fork کنید
  2. شاخه جدید ایجاد کنید (git checkout -b feature/AmazingFeature)
  3. تغییرات را Commit کنید (git commit -m 'Add some AmazingFeature')
  4. Push به شاخه (git push origin feature/AmazingFeature)
  5. Pull Request باز کنید

مجوز

این پروژه تحت مجوز MIT منتشر شده است. برای اطلاعات بیشتر فایل LICENSE را مطالعه کنید.


📧 برای ارتباط: sdvp1991david@gmail.com
🌍 وبسایت: https://sayehban.ir
💻 مخزن کد: https://github.com/SayyehBan/SayehBanTools

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed