This commit is contained in:
2026-02-08 12:26:02 +03:30
commit 3732b9c0b8
51 changed files with 2503 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Mf.Core.Interfaces
{
public interface ICommand
{
}
public interface ICreateCommand<TEntity>: ICommand
{
}
public interface IUpdateCommand<TEntity> : ICommand
{
}
public interface IDeleteCommand<TEntity> : ICommand
{
}
}
+20
View File
@@ -0,0 +1,20 @@
using Mf.Core.SubEntities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mf.Core.Interfaces
{
public interface IContextCore
{
public IGenericService<TEntity> GetService<TEntity>() where TEntity : class, IEntity;
public object GetService(Type type);
public void Dispose();
public void Migrate();
}
}
+23
View File
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Mf.Core.Interfaces
{
public interface IEmailSender
{
string SendEmail(string subject, string address, string body);
string SendDataBaseEmail(string subject, string address, string body, string filePath);
}
public class EmailConfig
{
public string FromAddress { get; set; }
public string Password { get; set; }
public int Port { get; set; }
public string SmtAddress { get; set; }
}
}
+33
View File
@@ -0,0 +1,33 @@
using Mf.Core.SubEntities;
using Mf.Core.SubEntities.QueryModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mf.Core.Interfaces
{
public interface IGenericService<out TEntity> where TEntity : class, IEntity
{
public IEnumerable<TEntity> GetAll();
public IEnumerable<TEntity> GetList(QueryRequest? query = null);
#region Async MotimatDatabaseCore
public Task<IEntity> GetByIdAsync(CancellationToken cancellationToken, params object[] ids);
public Task<IEnumerable<IEntity>> AddRangeAsync(IEnumerable<IEntity> entities, CancellationToken cancellationToken, bool saveNow = true);
public Task<IEntity> UpdateAsync(object entity, CancellationToken cancellationToken, bool saveNow = true);
public Task<IEntity> DeleteAsync(object entity, CancellationToken cancellationToken, bool saveNow = true);
public Task<IEntity> AddAsync(object entity, CancellationToken cancellationToken, bool saveNow = true);
#endregion
}
}
+9
View File
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,50 @@
namespace Mf.Core.OperationSystem
{
public static class OperationSystemService
{
public static OperationSystemType OS
{
get
{
PlatformID platform = Environment.OSVersion.Platform;
// Check if the operating system is Windows
if (platform == PlatformID.Win32NT || platform == PlatformID.Win32Windows)
{
Version version = Environment.OSVersion.Version;
return OperationSystemType.Windows;
// Retrieve and display the Windows version
}
else if (platform == PlatformID.Unix)
{
// Retrieve and display the Linux/Unix version
//string versionInfo = ExecuteCommand("uname -a");
//Console.WriteLine($"Version: {versionInfo}");
return OperationSystemType.Linux;
}
else
{
return OperationSystemType.Unknown;
}
}
}
public static string OperationSystemVersion
{
get
{
return System.Runtime.InteropServices.RuntimeInformation.OSDescription;
}
}
}
public enum OperationSystemType
{
Windows,
Linux,
Unknown
}
}
+151
View File
@@ -0,0 +1,151 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mf.Core.Services
{
public static class DateService
{
public static DateTime GetStartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
{
int diff = (7 + (dt.DayOfWeek - startOfWeek)) % 7;
return dt.AddDays(-1 * diff).Date;
}
public static string ToShamsi(this DateTime DateTime1)
{
try
{
PersianCalendar PersianCalendar1 = new PersianCalendar();
return string.Format(@"{0}/{1}/{2} {3}:{4}:{5}",
PersianCalendar1.GetYear(DateTime1),
PersianCalendar1.GetMonth(DateTime1).ToString("00"),
PersianCalendar1.GetDayOfMonth(DateTime1).ToString("00"),
PersianCalendar1.GetHour(DateTime1).ToString("00"),
PersianCalendar1.GetMinute(DateTime1).ToString("00"),
PersianCalendar1.GetSecond(DateTime1).ToString("00")
);
}
catch (Exception ex)
{
return "Error";
}
}
public static string ToShamsiDate(this DateTime DateTime1)
{
PersianCalendar PersianCalendar1 = new PersianCalendar();
return string.Format(@"{0}/{1}/{2}",
PersianCalendar1.GetYear(DateTime1),
PersianCalendar1.GetMonth(DateTime1).ToString("00"),
PersianCalendar1.GetDayOfMonth(DateTime1).ToString("00"));
}
public static string ToShamsiClock(this DateTime dateTime)
{
PersianCalendar PersianCalendar1 = new PersianCalendar();
return string.Format(@"{0}:{1}",
PersianCalendar1.GetHour(dateTime).ToString("00"),
PersianCalendar1.GetMinute(dateTime).ToString("00"));
}
public static DateTime StringToDateTime(this string value)
{
string[] dateTmp = value.Split(' ');
string[] date = dateTmp[0].Split('/');
string[] time;
if (dateTmp.Length == 2)
{
time = dateTmp[1].Split(':');
}
else
time = new string[2] { "0", "0" };
//date = value.Split('/');
PersianCalendar persianCal = new PersianCalendar();
return persianCal.ToDateTime(Convert.ToInt16(date[0]), Convert.ToInt16(date[1]), Convert.ToInt16(date[2]), int.Parse(time[0]), int.Parse(time[1]), int.Parse(time[2]), 0);
return new DateTime(Convert.ToInt16(date[0]), Convert.ToInt16(date[1]), Convert.ToInt16(date[2]));
// return new JalaliDate(Convert.ToInt16(date[0]), Convert.ToByte(date[1]), Convert.ToByte(date[2])).ToDateTime().AddHours(double.Parse(time[0])).AddMinutes(double.Parse(time[1]));
}
public static DateTime StringDateToDateTime(this string value)
{
string[] dateTmp = value.Split(' ');
string[] date = dateTmp[0].Split('/');
string[] time;
if (dateTmp.Length == 2)
{
time = dateTmp[1].Split(':');
}
else
time = new string[2] { "0", "0" };
//date = value.Split('/');
PersianCalendar persianCal = new PersianCalendar();
return persianCal.ToDateTime(Convert.ToInt16(date[0]), Convert.ToInt16(date[1]), Convert.ToInt16(date[2]), int.Parse(time[0]), int.Parse(time[1]), 0, 0);
return new DateTime(Convert.ToInt16(date[0]), Convert.ToInt16(date[1]), Convert.ToInt16(date[2]));
// return new JalaliDate(Convert.ToInt16(date[0]), Convert.ToByte(date[1]), Convert.ToByte(date[2])).ToDateTime().AddHours(double.Parse(time[0])).AddMinutes(double.Parse(time[1]));
}
public static TimeSpan StringToTimeSpan(this string value)
{
try
{
var split = value.Split(":");
return new TimeSpan(int.Parse(split[0]), int.Parse(split[1]), int.Parse(split[2]));
}
catch (Exception ex)
{
//Console.WriteLine(ex);
return new TimeSpan();
}
}
public static string DayOfWeekShamsi(this DayOfWeek day)
{
switch (day)
{
case (DayOfWeek.Saturday):
return "شنبه";
break;
case (DayOfWeek.Sunday):
return "یک شنبه";
break;
case (DayOfWeek.Monday):
return "دو شنبه";
case (DayOfWeek.Tuesday):
return "سه شنبه";
case (DayOfWeek.Wednesday):
return "چهار شنبه";
case (DayOfWeek.Thursday):
return "پنج شنبه";
case (DayOfWeek.Friday):
return "جمعه";
default:
return "";
}
}
}
//public static class DateConvertor
//{
// public static string ToShamsi(this DateTime date)
// {
// PersianCalendar persian = new PersianCalendar();
// return persian.GetYear(date) + "/" + persian.GetMonth(date).ToString("00") + "/" + persian.GetDayOfMonth(date).ToString("00");
// }
//}
}
+72
View File
@@ -0,0 +1,72 @@
using Mf.Core.Interfaces;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace Mf.Core.Services
{
public class EmailSender : IEmailSender
{
public EmailConfig _config;
public EmailSender(EmailConfig config)
{
_config = config;
}
public string SendEmail(string subject, string address, string body)
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new NetworkCredential(_config.FromAddress, _config.Password);
MailAddress from = new MailAddress(_config.FromAddress);
MailAddress to = new MailAddress(address);
MailMessage message = new MailMessage(from, to);
message.Body = body;
message.BodyEncoding = Encoding.UTF8;
message.Subject = subject;
message.SubjectEncoding = Encoding.UTF8;
client.Send(message);
message.Dispose();
return "Success";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
public string SendDataBaseEmail(string subject, string address, string body, string filePath)
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new NetworkCredential(_config.FromAddress, _config.Password);
MailAddress from = new MailAddress(_config.FromAddress);
MailAddress to = new MailAddress(address);
MailMessage message = new MailMessage(from, to);
message.Body = body;
message.BodyEncoding = Encoding.UTF8;
message.Subject = subject;
message.SubjectEncoding = Encoding.UTF8;
if (File.Exists(filePath))
{
Attachment attachment = new Attachment(filePath);
message.Attachments.Add(attachment);
}
client.Send(message);
message.Dispose();
return "Success";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
}
}
+77
View File
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Mf.Core.SubEntities
{
public abstract class BaseEntity<T> : IEntity
{
[Key]
[Display(Name = "شماره")]
public T Id { get; set; }
}
public abstract class BaseEntity : BaseEntity<long>
{
}
public static class BaseEntityService
{
public static IEnumerable<Type> GetModelsByAttribute(Type attribute)
{
Assembly assembly = Assembly.GetExecutingAssembly();
// همه‌ی تایپ‌های موجود در Assembly را دریافت می‌کنیم
Type[] types = assembly.GetTypes();
// لیستی برای نگهداری تایپ‌هایی که دارای Custom Attribute مورد نظر هستند
List<Type> typesWithCustomAttribute = new List<Type>();
var typess = from assemblyy in AppDomain.CurrentDomain.GetAssemblies()
from type in assemblyy.GetTypes()
where type.IsDefined(attribute)
select type;
// بررسی Custom Attribute هر تایپ
foreach (Type type in typess)
{
// بررسی Custom Attribute هر تایپ
var attributes = type.GetCustomAttributes(attribute, false);
if (attributes.Length > 0)
{
// این تایپ دارای Custom Attribute مورد نظر است
typesWithCustomAttribute.Add(type);
}
}
// چاپ نتیجه‌ی تایپ‌های دارای Custom Attribute مورد نظر
//-----------------------------------------------------------------------
//var types = from assembly in AppDomain.CurrentDomain.GetAssemblies()
// from type in assembly.GetTypes()
// where type.IsDefined(typeof(TableAttribute))
// select type;
return typesWithCustomAttribute;
var ass = typeof(BaseEntity).Assembly;
var all = ass.GetExportedTypes().Where(c => typeof(BaseEntity).IsAssignableFrom(c));
var aa = ass.GetExportedTypes().Where(c => c.IsClass && c.IsPublic && !c.IsAbstract && typeof(BaseEntity).IsAssignableFrom(c));
return aa;
// Assembly فعلی را دریافت می‌کنیم
}
}
}
+12
View File
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mf.Core.SubEntities
{
public interface IEntity
{
}
}
+9
View File
@@ -0,0 +1,9 @@
namespace Mf.Core.SubEntities.QueryModel
{
public class Filter
{
public string Field { get; set; }
public string Operator { get; set; }
public string Value { get; set; }
}
}
@@ -0,0 +1,19 @@
namespace Mf.Core.SubEntities.QueryModel
{
public class QueryRequest
{
public string? ObjectType { get; set; }
public List<Filter> Filters { get; set; } = new();
public List<string> Includes { get; set; } = new();
public int? Skip { get; set; }
public int? Take { get; set; }
}
public class AlterRequest
{
public string? ObjectType { get; set; }
public object? Model { get; set; }
}
}