private async Task ResetAsync()
        {
            if (HIOStaticValues.CheckSyncingData())
            {
                return;
            }
            HIOStaticValues.tmain.AccountManager.SourceItems.Clear();
            await UIService.Execute(async() =>
            {
                if (HIOStaticValues.CheckSyncingData())
                {
                    return;
                }
                if (HIOStaticValues.CONNECTIONBHIO == true)
                {
                    Commands ic = new Commands();
                    if (!ic.EraseAll())
                    {
                        HIOStaticValues.popUp("Something went wrong!");
                    }
                }
                else
                {
                    HIOStaticValues.popUp("HIO is not connect!");
                }
            });

            //Application.Current.Dispatcher.Invoke(new Action(() =>
            //{
            //    AddNewDevice();
            //}));
        }
        public void AddNewDevice()
        {
            if (HIOStaticValues.CheckSyncingData())
            {
                return;
            }
            if (HIOStaticValues.PinInputDashboardVM != null)
            {
                HIOStaticValues.PinInputDashboardVM.PinLockEnd = null;
            }
            if (HIOStaticValues.PinInputExtensionVM != null)
            {
                HIOStaticValues.PinInputExtensionVM.PinLockEnd = null;
            }
            Commands cmd = new Commands();

            if (HIOStaticValues.DirectBluetooth == false && HIOStaticValues.CONNECTIONBHIO == true)
            {
                cmd.ResetSync();
                cmd.UnBond(HIOStaticValues.blea.mac);
            }


            HIOStaticValues.DirectBluetooth = false;



            TAddNewDevice deviceAdd = new TAddNewDevice(Parent.Parent.AccountManager);

            deviceAdd.Show(this);
        }
        public void LoadDatabySort()
        {
            if (HIOStaticValues.CheckSyncingData())
            {
                return;
            }
            #region Sort Data
            List <TAccountItem> items = SourceItems.ToList();
            SourceItems.Clear();
            if (SortByField.IsNullOrEmpty() || "Name".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase))
            {
                items = items.OrderBy(t => t.Name).ToList();
            }
            else if ("Date".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase))
            {
                items = items.OrderByDescending(t => t.Date).ToList();
            }
            else if ("Popularity".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase))
            {
                items = items.OrderByDescending(t => t.Popularity).ToList();
            }
            #endregion
            #region Add Data

            foreach (var item in items)
            {
                SourceItems.Add(item);
            }
            #endregion
            OnPropertyChanged(nameof(Items));
        }
        private void Backup()
        {
            if (HIOStaticValues.CheckSyncingData())
            {
                return;
            }

            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName   = "HIO_Records_" + DateTime.Now.ToString("MM-dd-yyyy HH-mm-ss");
            dlg.DefaultExt = ".text";
            dlg.Filter     = "Text documents (.txt)|*.txt";

            Nullable <bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string   filename = dlg.FileName;
                DataBase db       = new DataBase();

                var users = db.ReadData();
                Task.Run(() =>
                {
                    ExportUsersAsync(users, filename);
                });
            }
        }
 private void AccountEdit(object obj)
 {
     if (HIOStaticValues.CheckSyncingData())
     {
         return;
     }
     (obj as TAccountItem).StartEdit();
 }
 private void AccountDelete(object obj)
 {
     if (HIOStaticValues.CheckSyncingData())
     {
         return;
     }
     (obj as TAccountItem).Delete();
 }
 private void AccountCopyPassword(object obj)
 {
     if (HIOStaticValues.CheckSyncingData())
     {
         return;
     }
     (obj as TAccountItem).CopyPassword();
 }
        public void Import()
        {
            if (!HIOStaticValues.CONNECTIONBHIO)
            {
                TMessageBox.Show("HIO is not connect!");
                return;
            }
            if (HIOStaticValues.CheckSyncingData())
            {
                return;
            }
            TImport importPage = new TImport(null, 0, this);

            importPage.Show();
        }
        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));
            }
        }
 public async Task LoadPage()
 {
     try
     {
         if (HIOStaticValues.CheckSyncingData())
         {
             return;
         }
         await UIService.Execute(async() =>
         {
             if (HIOStaticValues.CONNECTIONBHIO == false)
             {
                 Exapnder = true;
             }
             else
             {
                 Exapnder = false;
             }
             if (HIOStaticValues.CheckSyncingData())
             {
                 return;
             }
             Commands ic   = new Commands();
             Converts conv = new Converts();
             if (HIOStaticValues.CONNECTIONBHIO == true)
             {
                 HIOStaticValues.commandQ.Add(() =>
                 {
                     //Get VersioN
                     ic.GetVersion();
                     //  await Task.Run(() => { ic.GetVersion(); });
                     MyHIOTitle   = Encoding.UTF8.GetString(HIOStaticValues.blea.name).Replace("\0", "");
                     MyHIOVersion = "Version: " + HIOStaticValues.blea.ver;
                     MyHIOMac     = "MAC: " + conv.ByteToChar(HIOStaticValues.blea.mac[0]) + ":" + conv.ByteToChar(HIOStaticValues.blea.mac[1]) + ":" + conv.ByteToChar(HIOStaticValues.blea.mac[2]) + ":" + conv.ByteToChar(HIOStaticValues.blea.mac[3]) + ":" + conv.ByteToChar(HIOStaticValues.blea.mac[4]) + ":" + conv.ByteToChar(HIOStaticValues.blea.mac[5]);
                 });
                 //IsConnecting = true;
             }
         });
     }
     catch (Exception ex)
     {
     }
     finally { }
 }
        private async Task Syncronize()
        {
            if (HIOStaticValues.CheckSyncingData())
            {
                return;
            }
            if (SyncronizingState != SyncronizingStateEnum.Synced)
            {
                SyncronizingState = SyncronizingStateEnum.Syncronizing;
                try
                {
                    ProgressPercent = 0;
                    DispatcherTimer dt = new DispatcherTimer();
                    dt.Interval = TimeSpan.FromSeconds(1);
                    dt.Tick    += Dt_Tick;
                    dt.Start();
                    await Task.Run(() =>

                    {
                        Commands ic       = new Commands();
                        SyncronizingState = SyncronizingStateEnum.Syncronizing;
                        ic.Sync();
                        //   dt.Stop();
                    });

                    //   await LoadingAsync();
                }
                finally
                {
                    // SyncronizingState = SyncronizingStateEnum.Completed;
                }
            }
            else
            {
                await LoadData();
            }
            OnPropertyChanged(nameof(IsAllChecked));
        }
        public async Task LoadingAsync()
        {
            try
            {
                if (HIOStaticValues.CheckSyncingData())
                {
                    SyncronizingState = SyncronizingStateEnum.Syncronizing;
                    Trace.WriteLine("SyncronizingState in dashboard:" + SyncronizingState);
                    Trace.WriteLine("percent in dashboard:" + ProgressPercent);
                    DispatcherTimer dt = new DispatcherTimer();
                    dt.Interval = TimeSpan.FromSeconds(1);
                    dt.Tick    += Dt_Tick;
                    dt.Start();
                    return;
                }
                App.Current.Dispatcher.Invoke(new Action(() =>
                {
                    SourceItems.Clear();
                }));
                Converts conv = new Converts();
                DataBase db   = new DataBase();
                //  HIOStaticValues.commandQ.Add(()=> QBatteryandSignalCheckAsync());
                Commands ic = new Commands();
                HIOStaticValues.commandQ.Add(() =>
                {
                    BatteryValue = ic.GetBatteryStatus();
                });

                HIOStaticValues.commandQ.Add(() =>
                {
                    Commands cmd = new Backend.Commands();
                    cmd.GetRssi();
                    App.Current.Dispatcher.Invoke(new Action(() =>

                    {
                        SignalValue = cmd.GetSignalStatus(HIOStaticValues.blea.rssi);
                    }));
                });
                HIOStaticValues.commandQ.Add(() =>
                {
                    App.Current.Dispatcher.Invoke(new Action(async() =>

                    {
                        SyncronizingState = ic.AmISync();
                        if (SyncronizingState == SyncronizingStateEnum.NotSynced)
                        {
                            await Syncronize();
                        }
                    }));
                });

                App.Current.Dispatcher.Invoke(new Action(async() =>
                {
                    //READ DATA
                    lp = await Task.Run(() =>
                    {
                        return(db.ReadData());
                    });
                    if (lp != null)
                    {
                        ItemCounter = (lp.Count > 1) ? lp.Count + " Items" : lp.Count + " Item";
                    }
                    //Note : lp may be null
                    if (lp != null && lp.Any())
                    {
                        #region Load Data

                        List <TAccountItem> items = new List <TAccountItem>();
                        foreach (var item in lp)
                        {
                            DrawingImage tmpDraw = new DrawingImage();
                            if (item.imageData == null || item.imageData.Length == 0)
                            {
                                tmpDraw = HIOStaticValues.PutTextInImage(item.url.Substring(0, 1));
                            }
                            else
                            {
                                tmpDraw = conv.BitmapImageToDrawingImage(conv.byteArrayToImage(item.imageData));
                            }
                            items.Add(new TAccountItem(this)
                            {
                                UserID     = item.rowid,
                                Name       = item.title,
                                Username   = item.userName,
                                Url        = item.url,
                                ImageData  = tmpDraw,
                                AppID      = item.appID,
                                SubTitle1  = item.userName,
                                SubTitle2  = conv.GetPrettyDate(item.last_used),
                                Popularity = item.popularity,
                                Date       = item.last_used
                            });
                            //  items.Add(new User() { Title = listlp[i].title, Username = listlp[i].userName, rowid = listlp[i].rowid });
                        }
                        #endregion

                        #region Sort Data

                        if (SortByField.IsNullOrEmpty() || "Name".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase))
                        {
                            items = items.OrderBy(t => t.Name).ToList();
                        }
                        else if ("Date".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase))
                        {
                            items = items.OrderByDescending(t => t.Date).ToList();
                        }
                        else if ("Popularity".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase))
                        {
                            items = items.OrderByDescending(t => t.Popularity).ToList();
                        }
                        #endregion
                        #region Add Data
                        foreach (var item in items)
                        {
                            SourceItems.Add(item);
                        }
                        #endregion
                    }
                    OnPropertyChanged(nameof(Items));
                }));
            }
            catch (Exception ex)
            {
            }
            finally
            {
                NotifyItemsChanged();
            }
        }
Пример #13
0
        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;
            }
        }