using System; using System.ComponentModel.DataAnnotations; using Volo.Abp; using Volo.Abp.Domain.Entities.Auditing; namespace Sozsoft.Platform.Entities; /// /// Tenant bazında dinamik olarak tanımlanmış AppService'lerin kod ve meta verilerini saklar /// public class DynamicService : FullAuditedEntity { /// /// AppService'in benzersiz adı (örn: "DynamicCustomerService") /// [Required] [StringLength(256)] public string Name { get; set; } /// /// AppService'in kullanıcı dostu başlığı /// [StringLength(512)] public string? DisplayName { get; set; } /// /// AppService açıklaması /// [StringLength(2000)] public string? Description { get; set; } /// /// Tam C# sınıf kodu (using'ler ve namespace dahil) /// [Required] public string Code { get; set; } /// /// AppService aktif mi? /// public bool IsActive { get; set; } /// /// Son derleme durumu /// public CompilationStatus CompilationStatus { get; set; } /// /// Son derleme hatası (varsa) /// public string? LastCompilationError { get; set; } /// /// Son başarılı derleme zamanı /// public DateTime? LastSuccessfulCompilation { get; set; } /// /// Kod versiyonu (her güncelleme ile artan numara) /// public int Version { get; set; } /// /// Kod hash'i (değişiklik kontrolü için) /// [StringLength(64)] public string? CodeHash { get; set; } /// /// AppService'in kullandığı ana entity türü (opsiyonel) /// [StringLength(256)] public string? PrimaryEntityType { get; set; } /// /// Swagger'da görünecek controller adı /// [StringLength(256)] public string? ControllerName { get; set; } protected DynamicService() { // EF Core constructor } public DynamicService( Guid id, string name, string code) : base(id) { Name = Check.NotNullOrWhiteSpace(name, nameof(name), maxLength: 256); Code = Check.NotNullOrWhiteSpace(code, nameof(code)); IsActive = true; CompilationStatus = CompilationStatus.Pending; Version = 1; } /// /// Kodu günceller ve versiyonu artırır /// public void UpdateCode(string newCode) { Check.NotNullOrWhiteSpace(newCode, nameof(newCode)); if (Code != newCode) { Code = newCode; Version++; CompilationStatus = CompilationStatus.Pending; LastCompilationError = null; CodeHash = GenerateCodeHash(newCode); } } /// /// Derleme başarısını işaretler /// public void MarkCompilationSuccess() { CompilationStatus = CompilationStatus.Success; LastCompilationError = null; LastSuccessfulCompilation = DateTime.Now; } /// /// Derleme hatasını işaretler /// public void MarkCompilationError(string error) { CompilationStatus = CompilationStatus.Failed; LastCompilationError = error; } private string GenerateCodeHash(string code) { using var sha256 = System.Security.Cryptography.SHA256.Create(); var hash = sha256.ComputeHash(System.Text.Encoding.UTF8.GetBytes(code)); return Convert.ToHexString(hash); } } /// /// Derleme durumu enum'u /// public enum CompilationStatus { /// /// Henüz derlenmedi /// Pending = 0, /// /// Derleme başarılı /// Success = 1, /// /// Derleme başarısız /// Failed = 2, /// /// Derleme işlemi devam ediyor /// InProgress = 3 }