Skip to content

Commit

Permalink
Refactored core
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianMorozov committed Feb 11, 2025
1 parent d045bc7 commit 88db89e
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Core/TgInfrastructure/Contracts/ITgDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace TgInfrastructure.Contracts;
{
#region Public and private fields, properties, constructor

bool IsLoad { get; set; }
public bool IsLoad { get; set; }
public Guid Uid { get; set; }
public bool IsExistsAtStorage { get; set; }

#endregion

Expand Down
14 changes: 11 additions & 3 deletions Core/TgStorage/Common/TgCommonEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public sealed class TgCommonEntity
[DefaultValue("00000000-0000-0000-0000-000000000000")]
public Guid UidValue { get; set; }

[Timestamp]
[Column(TgEfConstants.ColumnRowVersion)]
public byte[]? RowVersion { get; set; }

[DefaultValue(true)]
public bool BoolValue { get; set; }

Expand Down Expand Up @@ -41,14 +45,18 @@ public sealed class TgCommonEntity
[DefaultValue("2001-02-03 11:22:33")]
public DateTime DtValue { get; set; }

/// <summary>
/// Default constructor.
/// </summary>
/// <summary> Default constructor </summary>
public TgCommonEntity()
{
Default();
}

#endregion

#region Public and private methods

public string ToDebugString() => $"{Uid}";

private void Default()
{
UidValue = this.GetDefaultPropertyGuid(nameof(UidValue));
Expand Down
15 changes: 14 additions & 1 deletion Core/TgStorage/Common/TgDtoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,33 @@ namespace TgStorage.Common;

/// <summary> Base class for TgMvvmModel </summary>
[DebuggerDisplay("{ToDebugString()}")]
public abstract partial class TgDtoBase : ObservableRecipient
public partial class TgDtoBase : ObservableRecipient
{
#region Public and private fields, properties, constructor

[ObservableProperty]
public partial bool IsLoad { get; set; }
[ObservableProperty]
public partial Guid Uid { get; set; }
[ObservableProperty]
public partial bool IsExistsAtStorage { get; set; }

#endregion

#region Public and private methods

public override string ToString() => ToDebugString();

public string ToDebugString() => TgObjectUtils.ToDebugString(this);

public TgDtoBase Fill(TgDtoBase dto, bool isUidCopy)
{
IsLoad = dto.IsLoad;
if (isUidCopy)
Uid = dto.Uid;
IsExistsAtStorage = dto.IsExistsAtStorage;
return this;
}

#endregion
}
3 changes: 1 addition & 2 deletions Core/TgStorage/Domain/Apps/TgEfAppDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public string ApiHashString

public TgEfAppDto Fill(TgEfAppDto dto, bool isUidCopy)
{
if (isUidCopy)
Uid = dto.Uid;
base.Fill(dto, isUidCopy);
ApiHash = dto.ApiHash;
ApiId = dto.ApiId;
FirstName = dto.FirstName;
Expand Down
1 change: 0 additions & 1 deletion Core/TgStorage/Domain/Apps/TgEfAppEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public void Default()
ApiHash = this.GetDefaultPropertyGuid(nameof(ApiHash));
ApiId = this.GetDefaultPropertyInt(nameof(ApiId));
PhoneNumber = this.GetDefaultPropertyString(nameof(PhoneNumber));
//ProxyUid = this.GetDefaultPropertyGuid(nameof(ProxyUid));
ProxyUid = null;
FirstName = this.GetDefaultPropertyString(nameof(FirstName));
LastName = this.GetDefaultPropertyString(nameof(LastName));
Expand Down
3 changes: 1 addition & 2 deletions Core/TgStorage/Domain/Contacts/TgEfContactDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public sealed partial class TgEfContactDto : TgDtoBase, ITgDto<TgEfContactDto, T

public TgEfContactDto Fill(TgEfContactDto dto, bool isUidCopy)
{
if (isUidCopy)
Uid = dto.Uid;
base.Fill(dto, isUidCopy);
DtChanged = dto.DtChanged;
Id = dto.Id;
AccessHash = dto.AccessHash;
Expand Down
3 changes: 1 addition & 2 deletions Core/TgStorage/Domain/Filters/TgEfFilterDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public sealed partial class TgEfFilterDto : TgDtoBase, ITgDto<TgEfFilterDto, TgE

public TgEfFilterDto Fill(TgEfFilterDto dto, bool isUidCopy)
{
if (isUidCopy)
Uid = dto.Uid;
base.Fill(dto, isUidCopy);
IsEnabled = dto.IsEnabled;
FilterType = dto.FilterType;
Name = dto.Name;
Expand Down
3 changes: 1 addition & 2 deletions Core/TgStorage/Domain/Messages/TgEfMessageDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public sealed partial class TgEfMessageDto : TgDtoBase, ITgDto<TgEfMessageDto, T

public TgEfMessageDto Fill(TgEfMessageDto dto, bool isUidCopy)
{
if (isUidCopy)
Uid = dto.Uid;
base.Fill(dto, isUidCopy);
DtCreated = dto.DtCreated;
SourceId = dto.SourceId;
Id = dto.Id;
Expand Down
3 changes: 1 addition & 2 deletions Core/TgStorage/Domain/Proxies/TgEfProxyDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public sealed partial class TgEfProxyDto : TgDtoBase, ITgDto<TgEfProxyDto, TgEfP

public TgEfProxyDto Fill(TgEfProxyDto dto, bool isUidCopy)
{
if (isUidCopy)
Uid = dto.Uid;
base.Fill(dto, isUidCopy);
Type = dto.Type;
HostName = dto.HostName;
Port = dto.Port;
Expand Down
3 changes: 1 addition & 2 deletions Core/TgStorage/Domain/Sources/TgEfSourceDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public sealed partial class TgEfSourceDto : TgDtoBase, ITgDto<TgEfSourceDto, TgE

public TgEfSourceDto Fill(TgEfSourceDto dto, bool isUidCopy)
{
if (isUidCopy)
Uid = dto.Uid;
base.Fill(dto, isUidCopy);
DtChanged = dto.DtChanged;
Id = dto.Id;
AccessHash = dto.AccessHash;
Expand Down
4 changes: 2 additions & 2 deletions Core/TgStorage/Domain/Sources/TgEfSourceEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public sealed class TgEfSourceEntity : ITgDbEntity, ITgDbFillEntity<TgEfSourceEn
[Column(TgEfConstants.ColumnIsActive, TypeName = "BIT")]
public bool IsActive { get; set; }

[DefaultValue("UserName")]
[DefaultValue("")]
[ConcurrencyCheck]
[MaxLength(128)]
[Column(TgEfConstants.ColumnUserName, TypeName = "NVARCHAR(128)")]
public string? UserName { get; set; }

[DefaultValue("Title")]
[DefaultValue("")]
[ConcurrencyCheck]
[MaxLength(256)]
[Column(TgEfConstants.ColumnTitle, TypeName = "NVARCHAR(256)")]
Expand Down
3 changes: 1 addition & 2 deletions Core/TgStorage/Domain/Sources/TgEfSourceLiteDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public sealed partial class TgEfSourceLiteDto : TgDtoBase, ITgDto<TgEfSourceLite

public TgEfSourceLiteDto Fill(TgEfSourceLiteDto dto, bool isUidCopy)
{
if (isUidCopy)
Uid = dto.Uid;
base.Fill(dto, isUidCopy);
DtChangedString = dto.DtChangedString;
Id = dto.Id;
UserName = dto.UserName;
Expand Down
3 changes: 1 addition & 2 deletions Core/TgStorage/Domain/Stories/TgEfStoryDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public sealed partial class TgEfStoryDto : TgDtoBase, ITgDto<TgEfStoryDto, TgEfS

public TgEfStoryDto Fill(TgEfStoryDto dto, bool isUidCopy)
{
if (isUidCopy)
Uid = dto.Uid;
base.Fill(dto, isUidCopy);
DtChanged = dto.DtChanged;
Id = dto.Id;
FromId = dto.FromId;
Expand Down
1 change: 1 addition & 0 deletions Core/TgStorage/Domain/TgEfContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<TgEfStoryEntity>().Property(x => x.RowVersion).IsRowVersion();
modelBuilder.Entity<TgEfVersionEntity>().Property(x => x.RowVersion).IsRowVersion();
// Ignore
modelBuilder.Entity<TgCommonEntity>().Ignore(TgEfConstants.ColumnRowVersion);
modelBuilder.Entity<TgEfAppEntity>().Ignore(TgEfConstants.ColumnRowVersion);
modelBuilder.Entity<TgEfContactEntity>().Ignore(TgEfConstants.ColumnRowVersion);
modelBuilder.Entity<TgEfDocumentEntity>().Ignore(TgEfConstants.ColumnRowVersion);
Expand Down
3 changes: 1 addition & 2 deletions Core/TgStorage/Domain/Versions/TgEfVersionDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public sealed partial class TgEfVersionDto : TgDtoBase, ITgDto<TgEfVersionDto, T

public TgEfVersionDto Fill(TgEfVersionDto dto, bool isUidCopy)
{
if (isUidCopy)
Uid = dto.Uid;
base.Fill(dto, isUidCopy);
Version = dto.Version;
Description = dto.Description;
return this;
Expand Down
2 changes: 1 addition & 1 deletion Core/TgStorage/Migrations/TgEfContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ partial class TgEfContextModelSnapshot : ModelSnapshot
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.0");
modelBuilder.HasAnnotation("ProductVersion", "9.0.1");

modelBuilder.Entity("TgStorage.Domain.Apps.TgEfAppEntity", b =>
{
Expand Down
1 change: 1 addition & 0 deletions Core/TgStorage/Using.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
global using TgInfrastructure.Helpers;
global using TgInfrastructure.Models;
global using TgStorage.Common;
global using TgStorage.Common;
global using TgStorage.Contracts;
global using TgStorage.Domain.Apps;
global using TgStorage.Domain.Contacts;
Expand Down
8 changes: 8 additions & 0 deletions Core/TgStorage/Utils/TgDataFormatUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ public static string TrimStringEnd(string value, int len = 30) =>
public static string GetFormatString(string? value, int len = 30) =>
string.IsNullOrEmpty(value) ? string.Empty : value.PadRight(len)[..len];

public static string GetFormatStringWithStrongLength(string? value, int len = 30)
{
if (string.IsNullOrEmpty(value))
return new string('.', len);
var result = value.Length > len ? value[..len] : $"{value}{new string('.', len - value.Length)}";
return result;
}

public static string GetDtFormat(DateTime dt) => $"{dt:yyyy-MM-dd HH:mm:ss}";

public static string GetDateFormat(DateTime dt) => $"{dt:yyyy-MM-dd}";
Expand Down

0 comments on commit 88db89e

Please sign in to comment.