sozsoft-platform/api/src/Sozsoft.Platform.Domain/Entities/Host/DeveloperKit/DynamicService.cs

168 lines
4.1 KiB
C#
Raw Normal View History

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