/// <summary> /// Актуальна ли на данный момент локальная база данных. /// Актуальной она считается, если с момента обновления прошло не более суток /// </summary> public static bool LocalDbIsActual() { DataBaseSwitcher.SetActiveDataBase(ConnectionType.Local); LocalDbActualityInfo = LastTimeModifiedTableInfo.Repository.GetAll().ToList(); DataBaseSwitcher.SetActiveDataBase(ConnectionType.Remote); return(LocalDbActualityInfo.Max(i => i.LastTimeModified) >= DateTime.Now.AddDays(-1).Ticks); }
private void TestNewThing() { var all = Storage.Repository.GetAll(); // var singleById = Storage.Repository1.Get("13ffad3a-7e33-4bb3-920a-4736fcfdf746"); DataBaseSwitcher.SetActiveDataBase(ConnectionType.Remote); }
/// <summary> /// Обработчик события подключения/отключения интернета /// </summary> public static void ConnectionChanged(object sender, NetworkAvailabilityEventArgs e) { DataBaseSwitcher.SetActiveDataBase(e.IsAvailable ? ConnectionType.Remote : ConnectionType.Local); Console.Write(e.IsAvailable ? "Network connected!" : "Network dis connected!"); ConnectionIsAvailable = e.IsAvailable; ConnectionIsNotAvailable = e.IsAvailable; MainWindow.ToLoginScreen(); }
/// <summary> /// Обновить таблицу документов типа Т в локальной базе данных /// </summary> public static void UpdateLocalTable <T>() where T : Entity { var repository = (Repository <T>) typeof(T).GetProperty("Repository")?.GetValue(null, null); DataBaseSwitcher.SetActiveDataBase(ConnectionType.Remote); var documents = repository?.GetAll().ToList(); DataBaseSwitcher.SetActiveDataBase(ConnectionType.Local); repository?.DeleteAll(); repository?.AddAll(documents); }
public static void Run() { DataBaseSwitcher.SetActiveDataBase(ConnectionType.Local); Test.Run(AddEntity); Test.Run(DeleteEntity); Test.Run(DeleteEntityById); DataBaseSwitcher.SetActiveDataBase(ConnectionType.Remote); Test.Run(AddEntity); Test.Run(DeleteEntity); Test.Run(DeleteEntityById); }
public static void InitRepositories() { Console.Write(Box.Repository.ToString()); Console.Write(Storage.Repository.ToString()); Console.Write(User.Repository.ToString()); Console.Write(LastTimeModifiedTableInfo.Repository.ToString()); Console.Write(Contract.Repository.ToString()); DataBaseSwitcher.SetActiveDataBase(ConnectionChecker.ConnectionIsAvailable ? ConnectionType.Remote : ConnectionType.Local); }
public MainWindow() { InitializeComponent(); // WebApiHttpClient.RunQuery(); // return; DataBaseSwitcher.SetActiveDataBase(ConnectionChecker.ConnectionIsAvailable ? ConnectionType.Remote : ConnectionType.Local); localDbSeed.Generate(); NetworkChange.NetworkAvailabilityChanged += ConnectionChanged; Instance = this; RootContent.Content = new Login(); // RootContent.Content = new TestDb(); }
/// <summary> /// Обновление локальной базы данных. /// Обновляет устаревшие таблицы в локальной базе. /// </summary> public static void UpdateLocalDb() { var tablesToUpdate = RemoteDbActualityInfo .Where((t, i) => t.LastTimeModified > LocalDbActualityInfo[i].LastTimeModified) .Select(t => t.Id).ToList(); tablesToUpdate.Add("LastTimeModifiedTableInfo"); var typesToUpdate = tablesToUpdate.Select(s => Type.GetType("WpfApp.Domain." + s)).ToList(); typesToUpdate.ForEach(t => { var updateLocalTableGenericMethod = typeof(DbSynchronizer).GetMethod("UpdateLocalTable")?.MakeGenericMethod(t); updateLocalTableGenericMethod?.Invoke(null, null); }); DataBaseSwitcher.SetActiveDataBase(ConnectionType.Remote); }
public static void Generate() { var values = System.Enum.GetValues(typeof(DocumentType)).Cast <DocumentType>().Select(v => v.ToString()).ToList(); if (LastTimeModifiedTableInfo.Repository.GetAll().Count > 0) { return; } foreach (var value in values) { LastTimeModifiedTableInfo.Repository.Add(new LastTimeModifiedTableInfo { Id = value, LastTimeModified = DateTime.MinValue.ToBinary() }); } // User.Repository.Add(new User // { // Id = "1", // Login = "******", // Name = "1", // PasswordHash = "1", // Role = UserRole.Admin // }); DataBaseSwitcher.SetActiveDataBase(ConnectionType.Local); foreach (var value in values) { LastTimeModifiedTableInfo.Repository.Add(new LastTimeModifiedTableInfo { Id = value, LastTimeModified = DateTime.MinValue.ToBinary() }); } DataBaseSwitcher.SetActiveDataBase(ConnectionType.Remote); }
private void ConnectionChanged(object sender, NetworkAvailabilityEventArgs e) { DataBaseSwitcher.SetActiveDataBase(e.IsAvailable ? ConnectionType.Remote : ConnectionType.Local); Dispatcher.Invoke(() => SetContent(new Login())); }