reeeeeee
reeeeeee
CC#
Created by reeeeeee on 3/14/2025 in #help
SQLite proper disposal when shutting down the app
mm, how do you mean in good state?
12 replies
CC#
Created by reeeeeee on 3/14/2025 in #help
SQLite proper disposal when shutting down the app
I dont know what would be the best way
12 replies
CC#
Created by reeeeeee on 3/14/2025 in #help
SQLite proper disposal when shutting down the app
yeah, i understand that
12 replies
CC#
Created by reeeeeee on 3/14/2025 in #help
SQLite proper disposal when shutting down the app
i would like to implement some kind of mechanism to always have the most latest data in main DB file - so if a client has a problem, they can simply send only .db file and dont worry about some cached infos
12 replies
CC#
Created by reeeeeee on 3/14/2025 in #help
SQLite proper disposal when shutting down the app
I dont know about that, but it does clear all the files (shm, wal) after you stop it any way
12 replies
CC#
Created by reeeeeee on 2/12/2025 in #help
SQLite weird state managing / caching
So I assume I am missing something when closing the connection.. but idk what, since I am not manually handling the connection
17 replies
CC#
Created by reeeeeee on 2/12/2025 in #help
SQLite weird state managing / caching
*When opening an SQLite database, it creates some kind of "cache" files (.WAL and .SHM). Any change of data is written in those files, which are later on (on connection close or after specific number of new data) merged into original .db file
17 replies
CC#
Created by reeeeeee on 2/12/2025 in #help
SQLite weird state managing / caching
okay yeah, this was one part of the problem.. But I should still fix the part where stopping is not deleting/mergin cache files into original database file
17 replies
CC#
Created by reeeeeee on 2/12/2025 in #help
SQLite weird state managing / caching
and it actually might only be this
17 replies
CC#
Created by reeeeeee on 2/12/2025 in #help
SQLite weird state managing / caching
thought i changed path at some point...looks like not anymore
17 replies
CC#
Created by reeeeeee on 2/12/2025 in #help
SQLite weird state managing / caching
:harold:
17 replies
CC#
Created by reeeeeee on 2/12/2025 in #help
SQLite weird state managing / caching
oh wait
17 replies
CC#
Created by reeeeeee on 2/12/2025 in #help
SQLite weird state managing / caching
//Database connection
var dataSource = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "my-database.db");
services.AddDbContext<MyDbContext>(options => options.UseSqlite($"Data Source={dataSource};"));
//Database connection
var dataSource = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "my-database.db");
services.AddDbContext<MyDbContext>(options => options.UseSqlite($"Data Source={dataSource};"));
public class MyDbContext: DbContext
{
public DbSet<Testing> Testings{ get; set; }
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
public class MyDbContext: DbContext
{
public DbSet<Testing> Testings{ get; set; }
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
services.AddScoped<ITestingServiceRepository, TestingServiceRepository>();
services.AddScoped<ITestingServiceRepository, TestingServiceRepository>();
private readonly MyDbContext _dbContext;

public TaskRepository(MyDbContext dbContext)
{
_dbContext = dbContext;
}

public async Task<Testing> GetAll() => await _dbContext.Testings.AsNoTracking().ToListAsync();
private readonly MyDbContext _dbContext;

public TaskRepository(MyDbContext dbContext)
{
_dbContext = dbContext;
}

public async Task<Testing> GetAll() => await _dbContext.Testings.AsNoTracking().ToListAsync();
17 replies
CC#
Created by reeeeeee on 10/19/2024 in #help
Saving Draggable objects location wpf
So.. what do you think about this? 😅
18 replies
CC#
Created by reeeeeee on 10/19/2024 in #help
Saving Draggable objects location wpf
I would be a lot less messy if I could have only type of objects (but I will need more of them because I need some additional formatting before saving value to object - for exampe: string can only include numbers) Yeah, I know that reflection is usually better to be avoided, but this is currently the best idea I got, haha
18 replies
CC#
Created by reeeeeee on 10/19/2024 in #help
Saving Draggable objects location wpf
and loading is like this:
public async Task GetSettings() {
var fileContent = await File.ReadAllTextAsync("config.json");
var fds = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(fileContent);
foreach (var property in this.GetType().GetProperties().Where(x => typeof(CanvasPosition).IsAssignableFrom(x.PropertyType) && x.CanWrite))
{
if (fds.ContainsKey(property.Name) && typeof(CanvasPosition).IsAssignableFrom(property.PropertyType))
{
var jsonValue = fds[property.Name];
var value = JsonSerializer.Deserialize(jsonValue.GetRawText(), property.PropertyType);
property.SetValue(this, value);
}
}
}
public async Task GetSettings() {
var fileContent = await File.ReadAllTextAsync("config.json");
var fds = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(fileContent);
foreach (var property in this.GetType().GetProperties().Where(x => typeof(CanvasPosition).IsAssignableFrom(x.PropertyType) && x.CanWrite))
{
if (fds.ContainsKey(property.Name) && typeof(CanvasPosition).IsAssignableFrom(property.PropertyType))
{
var jsonValue = fds[property.Name];
var value = JsonSerializer.Deserialize(jsonValue.GetRawText(), property.PropertyType);
property.SetValue(this, value);
}
}
}
18 replies
CC#
Created by reeeeeee on 10/19/2024 in #help
Saving Draggable objects location wpf
Okay, so I managed to do some "improvements", which include less hardcoding stuff. I have two models, CanvasPosition and StringCanvasPosition (this one inherits canvas position - some elements requires string, some int, so I just separated them.
public class CanvasPosition
{
public double? CanvasLeft { get; set; }

public double? CanvasTop { get; set; }
public string BindableName { get; set; }
}


public class StringCanvasPosition : CanvasPosition
{
public string TextValue { get; set; }
}
public class CanvasPosition
{
public double? CanvasLeft { get; set; }

public double? CanvasTop { get; set; }
public string BindableName { get; set; }
}


public class StringCanvasPosition : CanvasPosition
{
public string TextValue { get; set; }
}
Then I have bindable properties like this:
private StringCanvasPosition _receivedRequestsWrapper { get; set; }
public StringCanvasPosition ReceivedRequestsWrapper ....getter, setter...
private StringCanvasPosition _receivedRequestsWrapper { get; set; }
public StringCanvasPosition ReceivedRequestsWrapper ....getter, setter...
For the serialization and deserialization I used reflection. I am saving it to File and the code looks like this: Saving:
Dictionary<string, object> dict = new Dictionary<string, object>();
foreach (var property in this.GetType().GetProperties().Where(x => typeof(CanvasPosition).IsAssignableFrom(x.PropertyType)))
{
dict[property.Name] = property.GetValue(this);
}
var options = new JsonSerializerOptions
{
WriteIndented = true
};
var jsonString = JsonSerializer.Serialize(dict,options); ;
File.WriteAllText(file, jsonString);
Dictionary<string, object> dict = new Dictionary<string, object>();
foreach (var property in this.GetType().GetProperties().Where(x => typeof(CanvasPosition).IsAssignableFrom(x.PropertyType)))
{
dict[property.Name] = property.GetValue(this);
}
var options = new JsonSerializerOptions
{
WriteIndented = true
};
var jsonString = JsonSerializer.Serialize(dict,options); ;
File.WriteAllText(file, jsonString);
18 replies
CC#
Created by reeeeeee on 10/19/2024 in #help
Saving Draggable objects location wpf
oh, when I was typing, this thought occured me,actually it might even work, will test it tommorow morning. If you are OK with that, can I ask you some questions if they will be needed?
18 replies
CC#
Created by reeeeeee on 10/19/2024 in #help
Saving Draggable objects location wpf
Ahh, just when I thought I already have a solution.. looks like I don't. One more question and then I'll let you go..
18 replies
CC#
Created by reeeeeee on 10/19/2024 in #help
Saving Draggable objects location wpf
Okay yeah, I had started with something similar and managed to make it work, which is nice. Thank you! (I should look into stuff like "sealed record", "abstract", "immutableDictionary") Haha ye, every new way of storing data ends totally ugly... well, the above way with hardcoding every property kinda works, maybe some better idea will pop in my mind anytime soon.. It technically works, except some properties have margin set in XAML and on fresh set of X and Y form file, their margin stays there and its location is actually wrong. An easy "fix" would be get rid of margins, but yea 😅
18 replies