Example #1
0
        /// <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);
        }
Example #2
0
        private void TestNewThing()
        {
            var all = Storage.Repository.GetAll();

//			var singleById = Storage.Repository1.Get("13ffad3a-7e33-4bb3-920a-4736fcfdf746");

            DataBaseSwitcher.SetActiveDataBase(ConnectionType.Remote);
        }
Example #3
0
        /// <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();
        }
Example #4
0
        /// <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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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();
        }
Example #8
0
        /// <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);
        }
Example #9
0
        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);
        }
Example #10
0
 private void ConnectionChanged(object sender, NetworkAvailabilityEventArgs e)
 {
     DataBaseSwitcher.SetActiveDataBase(e.IsAvailable ? ConnectionType.Remote : ConnectionType.Local);
     Dispatcher.Invoke(() => SetContent(new Login()));
 }