Skip to content

Commit

Permalink
sharplier
Browse files Browse the repository at this point in the history
  • Loading branch information
manuc66 committed Dec 3, 2024
1 parent 0ef1b00 commit 6d1eaa8
Show file tree
Hide file tree
Showing 49 changed files with 563 additions and 589 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
root = true
[*]
# Most of the standard properties are supported
indent_size=2
indent_size=4
max_line_length=180

# Most frequently used .NET-coding-convention properties are supported
Expand Down
2 changes: 2 additions & 0 deletions ImgTagFanOut.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Other", "Other", "{666977CA
.github\workflows\build.yml = .github\workflows\build.yml
.github\dependabot.yml = .github\dependabot.yml
_config.yml = _config.yml
global.json = global.json
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
Expand Down
7 changes: 2 additions & 5 deletions ImgTagFanOut/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
desktop.MainWindow = new MainWindow { DataContext = new MainWindowViewModel() };
}

base.OnFrameworkInitializationCompleted();
}
}
}
9 changes: 5 additions & 4 deletions ImgTagFanOut/Behaviors/EnterKeyBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace ImgTagFanOut.Behaviors;

public class EnterKeyBehavior : Behavior<TextBox>
{
public static readonly StyledProperty<ICommand> CommandProperty =
AvaloniaProperty.Register<EnterKeyBehavior, ICommand>(nameof(Command));
public static readonly StyledProperty<ICommand> CommandProperty = AvaloniaProperty.Register<EnterKeyBehavior, ICommand>(nameof(Command));

public ICommand Command
{
Expand All @@ -20,13 +19,15 @@ public ICommand Command
protected override void OnAttached()
{
base.OnAttached();
if (AssociatedObject != null) AssociatedObject.KeyDown += OnKeyDown;
if (AssociatedObject != null)
AssociatedObject.KeyDown += OnKeyDown;
}

protected override void OnDetaching()
{
base.OnDetaching();
if (AssociatedObject != null) AssociatedObject.KeyDown -= OnKeyDown;
if (AssociatedObject != null)
AssociatedObject.KeyDown -= OnKeyDown;
}

private void OnKeyDown(object? sender, KeyEventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions ImgTagFanOut/Dao/Entities/ItemDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ItemDao
{
[Key]
public int ItemId { get; set; }

public string Name { get; set; }
public string? Hash { get; set; }
public bool Done { get; set; }
Expand All @@ -21,4 +21,4 @@ public ItemDao(string name)
{
Name = name;
}
}
}
2 changes: 1 addition & 1 deletion ImgTagFanOut/Dao/Entities/ItemTagDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public class ItemTagDao
public int OrderIndex { get; set; }
public ItemDao Item { get; set; } = null!;
public TagDao Tag { get; set; } = null!;
}
}
5 changes: 3 additions & 2 deletions ImgTagFanOut/Dao/Entities/ParameterDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ namespace ImgTagFanOut.Dao;
[DebuggerDisplay("{Name}-{Value}-{ParameterId}")]
public class ParameterDao
{
[Key] public int ParameterId { get; set; }
[Key]
public int ParameterId { get; set; }

public string Name { get; set; } = null!;
public string? Value { get; set; }
}
}
4 changes: 2 additions & 2 deletions ImgTagFanOut/Dao/Entities/TagDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class TagDao
[Key]
public int TagId { get; set; }
public string Name { get; set; }

public TagDao(string name)
{
Name = name;
}

public List<ItemTagDao> ItemTags { get; } = new();
public List<ItemDao> Items { get; } = new();
}
}
2 changes: 1 addition & 1 deletion ImgTagFanOut/Dao/IImgTagFanOutDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public interface IImgTagFanOutDbContext
DbSet<ItemDao> Items { get; }
DbSet<ItemTagDao> ItemTags { get; }
DbSet<ParameterDao> Parameters { get; }
}
}
2 changes: 1 addition & 1 deletion ImgTagFanOut/Dao/IParameterRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public interface IParameterRepository
void Update(string name, string? value);
T? Get<T>(string name, Func<string?, T?> convert);
void Update<T>(string name, T? value, Func<T?, string?> convert);
}
}
2 changes: 1 addition & 1 deletion ImgTagFanOut/Dao/ITagCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public interface ITagCache
{
Tag GetOrCreate(TagDao tagDao);
void Remove(Tag tag);
}
}
2 changes: 1 addition & 1 deletion ImgTagFanOut/Dao/ITagRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public interface ITagRepository
void DeleteTag(Tag tag);
ImmutableList<string> GetItemsWithTag(Tag tag);
ImmutableList<Tag> GetAllTagForHash(string hash);
}
}
2 changes: 1 addition & 1 deletion ImgTagFanOut/Dao/IUnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public interface IUnitOfWork : IAsyncDisposable, IDisposable
public IParameterRepository ParameterRepository { get; }
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
int SaveChanges();
}
}
60 changes: 19 additions & 41 deletions ImgTagFanOut/Dao/ImgTagFanOutDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ public class ImgTagFanOutDbContext : DbContext, IImgTagFanOutDbContext, IUnitOfW
public ITagRepository TagRepository { get; }
public IParameterRepository ParameterRepository { get; }

public ImgTagFanOutDbContext() : this(new(), ".")
{
}
public ImgTagFanOutDbContext()
: this(new(), ".") { }

public ImgTagFanOutDbContext(TagCache tagCache, string folder)
{
Expand All @@ -25,70 +24,49 @@ public ImgTagFanOutDbContext(TagCache tagCache, string folder)
ParameterRepository = new ParameterRepository(this);
}

protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}")
protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlite($"Data Source={DbPath}")
// .LogTo(Console.WriteLine)
;

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Items
modelBuilder.Entity<ItemDao>()
.ToTable("items");
modelBuilder.Entity<ItemDao>().ToTable("items");

modelBuilder.Entity<ItemDao>()
.HasIndex(b => new { b.Name })
.IsUnique()
.IsDescending();
modelBuilder.Entity<ItemDao>().HasIndex(b => new { b.Name }).IsUnique().IsDescending();

modelBuilder.Entity<ItemDao>()
.HasIndex(b => new { b.Hash });
modelBuilder.Entity<ItemDao>().HasIndex(b => new { b.Hash });

modelBuilder.Entity<ItemDao>().HasKey(x => x.ItemId);
modelBuilder.Entity<ItemDao>().Property(x => x.ItemId)
.IsRequired()
.ValueGeneratedOnAdd();
modelBuilder.Entity<ItemDao>().Property(x => x.ItemId).IsRequired().ValueGeneratedOnAdd();

// Tags
modelBuilder.Entity<TagDao>()
.ToTable("tags");
modelBuilder.Entity<TagDao>().ToTable("tags");

modelBuilder.Entity<TagDao>()
.HasIndex(b => new { b.Name })
.IsUnique()
.IsDescending();
modelBuilder.Entity<TagDao>().HasIndex(b => new { b.Name }).IsUnique().IsDescending();

modelBuilder.Entity<TagDao>().HasKey(x => x.TagId);
modelBuilder.Entity<TagDao>().Property(x => x.TagId)
.IsRequired()
.ValueGeneratedOnAdd();
modelBuilder.Entity<TagDao>().Property(x => x.TagId).IsRequired().ValueGeneratedOnAdd();

// ItemTags
modelBuilder.Entity<ItemTagDao>()
.ToTable("item_tags");
modelBuilder.Entity<ItemTagDao>().ToTable("item_tags");

modelBuilder.Entity<ItemTagDao>()
.HasIndex(b => new { b.OrderIndex })
.IsDescending();
modelBuilder.Entity<ItemTagDao>().HasIndex(b => new { b.OrderIndex }).IsDescending();

modelBuilder.Entity<ItemDao>()
modelBuilder
.Entity<ItemDao>()
.HasMany(e => e.Tags)
.WithMany(e => e.Items)
.UsingEntity<ItemTagDao>(
l => l.HasOne<TagDao>(e => e.Tag).WithMany(e => e.ItemTags).HasForeignKey(e => e.TagForeignKey),
r => r.HasOne<ItemDao>(e => e.Item).WithMany(e => e.ItemTags).HasForeignKey(e => e.ItemForeignKey));
r => r.HasOne<ItemDao>(e => e.Item).WithMany(e => e.ItemTags).HasForeignKey(e => e.ItemForeignKey)
);

// Parameters
modelBuilder.Entity<ParameterDao>()
.ToTable("parameters");
modelBuilder.Entity<ParameterDao>().ToTable("parameters");

modelBuilder.Entity<ParameterDao>()
.HasIndex(b => new { b.Name })
.IsUnique()
.IsDescending();
modelBuilder.Entity<ParameterDao>().HasIndex(b => new { b.Name }).IsUnique().IsDescending();
modelBuilder.Entity<ParameterDao>().HasKey(x => x.ParameterId);
modelBuilder.Entity<ParameterDao>().Property(x => x.ParameterId)
.IsRequired()
.ValueGeneratedOnAdd();
modelBuilder.Entity<ParameterDao>().Property(x => x.ParameterId).IsRequired().ValueGeneratedOnAdd();
}
}
8 changes: 3 additions & 5 deletions ImgTagFanOut/Dao/InMemoryTagRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ public ImmutableList<Tag> GetAllTag()
return _tags.ToImmutableList();
}

public void AddOrUpdateItem(CanHaveTag tagAssignation)
{

}
public void AddOrUpdateItem(CanHaveTag tagAssignation) { }

public void AddTagToItem(Tag tag, CanHaveTag tagAssignation)
{
Expand Down Expand Up @@ -68,6 +65,7 @@ public void MarkDone(CanHaveTag tagAssignation)
{
tagAssignation.Done = true;
}

public void MarkUnDone(CanHaveTag tagAssignation)
{
tagAssignation.Done = false;
Expand All @@ -90,4 +88,4 @@ public ImmutableList<Tag> GetAllTagForHash(string hash)
{
return new List<Tag>().ToImmutableList();
}
}
}
2 changes: 1 addition & 1 deletion ImgTagFanOut/Dao/ParameterRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ public void Update<T>(string name, T? value, Func<T?, string?> convert)

Update(name, rawValue);
}
}
}
Loading

0 comments on commit 6d1eaa8

Please sign in to comment.