Exemple #1
0
        public async void Delete()
        {
            Commands cmd = new Backend.Commands();

            if (TMessageBox.Show("Are you sure you want to delete this account?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                while (true)
                {
                    var res = cmd.AmISync();
                    if (res == SyncronizingStateEnum.Synced)
                    {
                        break;
                    }
                    else
                    {
                        HIOStaticValues.SyncOpration();
                    }
                }

                await UIService.Execute(async() =>
                {
                    Commands ic = new Commands();
                    ic.Delete(UserID);
                    await Parent.LoadData();
                });

                Parent?.OnPropertyChanged(nameof(TAccountManagerViewModel.IsAllChecked));
            }
        }
        private async void Delete()
        {
            if (HIOStaticValues.CheckSyncingData())
            {
                return;
            }

            if (TMessageBox.Show("Are you sure you want to delete these accounts?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                Commands cmd = new Backend.Commands();
                while (true)
                {
                    var res = cmd.AmISync();
                    if (res == SyncronizingStateEnum.Synced)
                    {
                        break;
                    }
                    else
                    {
                        HIOStaticValues.SyncOpration();
                    }
                }


                await UIService.Execute(async() =>
                {
                    DataBase db = new DataBase();
                    foreach (var item in SourceItems.Where(t => t.IsChecked).ToArray())
                    {
                        Commands ic = new Commands();
                        if (ic.Delete(item.UserID))
                        {
                            App.Current.Dispatcher.BeginInvoke((Action)(() =>
                            {
                                SourceItems.Remove(SourceItems.FirstOrDefault(i => i.UserID == item.UserID));
                                OnPropertyChanged(nameof(Items));
                            }));
                        }
                    }
                    await LoadData();
                });

                OnPropertyChanged(nameof(IsAllChecked));
            }
        }
        private async void StartImportingAsync()
        {
            if (HIOStaticValues.CheckSyncingData())
            {
                return;
            }

            List <LoginFieldS> listUser = new List <LoginFieldS>();

            try
            {
                if (HIOStaticValues.CONNECTIONBHIO == true)
                {
                    Commands cmd          = new Backend.Commands();
                    int      userImported = 0;
                    DataBase dbLocal      = new DataBase();
LabelImport:
                    if (cmd.AmISync() == SyncronizingStateEnum.Synced)
                    {
                        IsImporting = true;

                        await Task.Run(() =>
                        {
                            Backup bk       = new Backup();
                            Chrome chrome   = new Chrome();
                            Firefox firefox = new Firefox();
                            Edge edge       = new Edge();
                            double progress = ImportProgressPercent;
                            //  var itemList = Items.Where(t => t.IsChecked);

                            foreach (var item in Items.Where(t => t.IsChecked))
                            {
                                if (item.Title == "Load Backup")
                                {
                                    listUser.AddRange(bk.LoadBackup());
                                }
                                if (item.Title == "Google Chrome")
                                {
                                    listUser.AddRange(chrome.getDataFromChrome());
                                }
                                if (item.Title == "Mozilla Firefox")
                                {
                                    listUser.AddRange(firefox.FetchPassword());
                                }
                                if (item.Title == "Edge")
                                {
                                    listUser.AddRange(edge.ReadPasswords());
                                }
                            }
                            listUser = listUser.Distinct(new loginFieldsCompare()).ToList();
                            int rows = listUser.Count;
                            // ImportVisible = true;

                            try
                            {
                                HIOStaticValues.IMPORT_ON = true;
                                if (rows == 0)
                                {
                                    MessageErr = "No account exist in your browsers";
                                    return;
                                }
                                for (int i = 0; i < rows; i++)
                                {
                                    ImportProgressPercent = (progress == 0) ? (i * 100) / (rows) : progress + ((i * 100) / (rows)) / 2;
                                    int res = HIOStaticValues.BaS.InsertToSwitch(new LoginFieldS {
                                        password = listUser[i].password, userName = listUser[i].userName, title = listUser[i].title, url = listUser[i].url
                                    });

                                    if (res <= 0)
                                    {
                                        if (res == -2)
                                        {
                                            throw new Exception($"Time out.\n {i}  accounts are imported successfully from {rows} accounts");
                                        }
                                        if (res == -3)
                                        {
                                            throw new Exception($"No space is available.\n {userImported} accounts are imported successfully");
                                        }

                                        break;
                                    }
                                    userImported++;
                                    dbLocal.insertToDatabase(res.ToString(), listUser[i].url, (string)listUser[i].userName, "", listUser[i].title);
                                }
                            }
                            catch (SQLiteException ex) when(ex.ErrorCode == 5)
                            {
                                MessageErr = $"HIO needs to close all browsers!{Environment.NewLine}Please save or close your Tabs if your are using any browsers.";
                                return;
                            }
                            catch (Exception ex)
                            {
                                MessageErr = ex.Message;
                                return;
                            }

                            HIOStaticValues.IMPORT_ON = false;
                            System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                IsImporting           = false;
                                ImportVisible         = false;
                                ImportProgressPercent = 0;
                                IsComplete            = true;
                                //  if (db_way2 != "")
                                //    System.IO.File.Delete(db_way2);
                            }));
                        });



                        if (Items.Any(t => t.IsChecked))
                        {
                            MoveNextPage();
                        }
                    }
                    else
                    {
                        HIOStaticValues.popUp("You are not sync!\nPlease wait,We are syncing data...");
                        IsImporting = true;
                        DispatcherTimer dt = new DispatcherTimer();
                        dt.Interval = TimeSpan.FromSeconds(1);
                        dt.Tick    += Dt_Tick;
                        dt.Start();
                        int res = await Task.Run(() =>
                        {
                            DataBase db       = new DataBase();
                            Commands resetCmd = new Backend.Commands();
                            resetCmd.ResetSync();
                            return(resetCmd.Sync());
                        });

                        dt.Stop();

                        if (res == 1)
                        {
                            goto LabelImport;
                        }
                    }
                }
                else
                {
                    TMessageBox.Show("HIO is not connect!");
                }
            }
            finally
            {
                IsImporting = false;

                HIOStaticValues.IMPORT_ON = false;
            }
        }