Skip to content

Commit 6f90e9f

Browse files
committed
add LocalSnippet
1 parent 106b120 commit 6f90e9f

23 files changed

+541
-42
lines changed

CodeHubDesktop/App.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodeHubDesktop.Views;
1+
using CodeHubDesktop.ViewModels;
2+
using CodeHubDesktop.Views;
23
using HandyControl.Data;
34
using HandyControl.Tools;
45
using ModernWpf;
@@ -35,6 +36,8 @@ protected override Window CreateShell()
3536

3637
protected override void RegisterTypes(IContainerRegistry containerRegistry)
3738
{
39+
containerRegistry.RegisterDialog<DialogService, DialogServiceViewModel>();
40+
3841
containerRegistry.RegisterForNavigation<About>();
3942
containerRegistry.RegisterForNavigation<CheckUpdate>();
4043
containerRegistry.RegisterForNavigation<Settings>();

CodeHubDesktop/CodeHubDesktop.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
22
<PropertyGroup>
33
<OutputType>WinExe</OutputType>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<UseWPF>true</UseWPF>
66
<AssemblyName>CodeHubDesktop</AssemblyName>
77
<RootNamespace>CodeHubDesktop</RootNamespace>
@@ -12,6 +12,8 @@
1212
<AssemblyVersion>1.0.0.0</AssemblyVersion>
1313
<LangVersion>latest</LangVersion>
1414
<SatelliteResourceLanguages>en;fa;en-US;fa-IR</SatelliteResourceLanguages>
15+
<ApplicationIcon>gitbanner_6jm_icon.ico</ApplicationIcon>
16+
<Authors>Mahdi Hosseini</Authors>
1517
</PropertyGroup>
1618
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
1719
<DefineConstants>TRACE;Core</DefineConstants>
@@ -28,6 +30,7 @@
2830
<ItemGroup>
2931
<PackageReference Include="AvalonEdit" Version="6.0.1" />
3032
<PackageReference Include="HandyControls" Version="2.4.9.2" />
33+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.3" />
3134
<PackageReference Include="ModernWpfUI.MahApps" Version="0.8.2-preview.1" />
3235
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
3336
<PackageReference Include="Prism.DryIoc" Version="7.2.0.1422" />

CodeHubDesktop/Controls/MyHamburgerMenu.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ private void ApplyPaneFontFamily()
3434
FontFamily paneFontFamily = PaneFontFamily;
3535
if (paneFontFamily != null)
3636
{
37-
PaneGrid.Resources[SystemFonts.MessageFontFamilyKey] = paneFontFamily;
37+
PaneGrid.Resources[SystemFonts.MenuFontFamilyKey] = paneFontFamily;
3838
PaneGrid.Resources["ContentControlThemeFontFamily"] = paneFontFamily;
3939
}
4040
else
4141
{
42-
PaneGrid.Resources.Remove(SystemFonts.MessageFontFamilyKey);
42+
PaneGrid.Resources.Remove(SystemFonts.MenuFontFamilyKey);
4343
PaneGrid.Resources.Remove("ContentControlThemeFontFamily");
4444
}
4545
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using CodeHubDesktop.Models;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.ChangeTracking;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
9+
namespace CodeHubDesktop.Data.Services
10+
{
11+
public class GenericDataService<T> : IDataService<T> where T : DomainObject
12+
{
13+
public async Task<T> CreateSnippet(T entity)
14+
{
15+
using (SimpleDbContext db = new SimpleDbContext())
16+
{
17+
EntityEntry<T> createdResult = await db.Set<T>().AddAsync(entity);
18+
await db.SaveChangesAsync();
19+
return createdResult.Entity;
20+
}
21+
}
22+
23+
public async Task<bool> DeleteSnippet(int id)
24+
{
25+
using (SimpleDbContext db = new SimpleDbContext())
26+
{
27+
T entity = await db.Set<T>().FirstOrDefaultAsync((e) => e.Id == id);
28+
db.Set<T>().Remove(entity);
29+
await db.SaveChangesAsync();
30+
return true;
31+
}
32+
}
33+
34+
public async Task<IEnumerable<T>> GetAllSnippets()
35+
{
36+
using (SimpleDbContext db = new SimpleDbContext())
37+
{
38+
IEnumerable<T> entities = await db.Set<T>().ToListAsync();
39+
return entities;
40+
}
41+
}
42+
43+
public async Task<IEnumerable<T>> GetSnippet(string filter)
44+
{
45+
using (SimpleDbContext db = new SimpleDbContext())
46+
{
47+
IEnumerable<T> entities = await db.Set<T>().Where(x => x.Title.Contains(filter)).ToListAsync();
48+
return entities;
49+
}
50+
}
51+
52+
public async Task<T> UpdateSnippet(int id, T entity)
53+
{
54+
using (SimpleDbContext db = new SimpleDbContext())
55+
{
56+
entity.Id = id;
57+
58+
db.Set<T>().Update(entity);
59+
await db.SaveChangesAsync();
60+
return entity;
61+
}
62+
}
63+
}
64+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
4+
namespace CodeHubDesktop.Data.Services
5+
{
6+
public interface IDataService<T>
7+
{
8+
Task<IEnumerable<T>> GetAllSnippets();
9+
Task<IEnumerable<T>> GetSnippet(string filter);
10+
Task<T> CreateSnippet(T entity);
11+
Task<T> UpdateSnippet(int id, T entity);
12+
Task<bool> DeleteSnippet(int id);
13+
}
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using CodeHubDesktop.Models;
2+
using Microsoft.EntityFrameworkCore;
3+
4+
namespace CodeHubDesktop.Data
5+
{
6+
public class SimpleDbContext : DbContext
7+
{
8+
public DbSet<SnippetsModel> SnippetsModel { get; set; }
9+
10+
public SimpleDbContext()
11+
{
12+
Database.EnsureCreated();
13+
}
14+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
15+
{
16+
base.OnConfiguring(optionsBuilder);
17+
optionsBuilder.UseSqlite(@"Data Source=localSnippets.db");
18+
}
19+
}
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.ComponentModel.DataAnnotations.Schema;
3+
4+
namespace CodeHubDesktop.Models
5+
{
6+
public class DomainObject
7+
{
8+
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
9+
public int Id { get; set; }
10+
public string Title { get; set; }
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace CodeHubDesktop.Models
2+
{
3+
public class SnippetsModel : DomainObject
4+
{
5+
public string SId { get; set; }
6+
public string Detail { get; set; }
7+
public string Script { get; set; }
8+
public string Language { get; set; }
9+
public string PubDate { get; set; }
10+
public string Link { get; set; }
11+
}
12+
}

CodeHubDesktop/MultiLanguage/Language/Lang.Designer.cs

Lines changed: 91 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)