Ejemplo n.º 1
0
        private void importCSVWithData(string data)
        {
            UserInteraction();
            data = data.Replace("\r\n", "\n");
            var s = data.Split('\n').ToList();

            s = s.Select(x => x.NoControlAndTrim()).ToList();
            int i;

            try
            {
                i = csvImport(s);
            }
            catch (Exception ex)
            {
                i = 0;
                DialogService.ShowError(ex, AppResources.SettingsViewModel_exportData_Error, AppResources.SettingsViewModel_exportData_OK, null);
            }
            if (i > 0)
            {
                Toasts.Notify(ToastNotificationType.Success, AppResources.SettingsViewModel_importCSVWithData_Import_succeed, string.Format(AppResources.SettingsViewModel_importCSVWithData__0__sheets_have_been_imported_, i), TimeSpan.FromSeconds(3));
            }
            if (i < 1)
            {
                Toasts.Notify(ToastNotificationType.Info, AppResources.SettingsViewModel_importCSVWithData_No_data_imported, AppResources.SettingsViewModel_importCSVWithData_No_data_have_been_imported_, TimeSpan.FromSeconds(3));
            }
        }
Ejemplo n.º 2
0
 protected override void IncomingCommand(string commandName, object context)
 {
     if (commandName == Utils.GlobalMessages.CopyToClipbard.ToString())
     {
         CrossShare.Current.SetClipboardText(Generated, AppResources.GeneratePwViewModel_IncomingCommand_My_Stash_generated_password);
     }
     Toasts.Notify(ToastNotificationType.Success, AppResources.GeneratePwViewModel_GeneratePwViewModel_Copy_to_clipboard, AppResources.GeneratePwViewModel_GeneratePwViewModel_Generated_password_copied_to_the_clipboard, TimeSpan.FromSeconds(2));
 }
Ejemplo n.º 3
0
        private void exportData(bool sql = false)
        {
            UserInteraction();
            if (DataService.GetInfoSheetCount(InfoSheet.CategoryFilter.All, InfoSheet.ProFilter.All).Item1 < 1)
            {
                Toasts.Notify(ToastNotificationType.Warning, AppResources.SettingsViewModel_exportData_No_data, AppResources.SettingsViewModel_exportData_No_data_to_export, TimeSpan.FromSeconds(3));
                return;
            }
            try
            {
                var list = originalData;
                if (EncryptedData)
                {
                    list = (from insh in originalData select insh.ToCryptedSheet()).ToList();
                }

                ExportBase <InfoSheet> exp;
                if (sql)
                {
                    exp = new ExportClipboardSql <InfoSheet>();
                }
                else
                {
                    exp = new ExportClipboardCsv <InfoSheet>()
                    {
                        TitleRow = true
                    }
                };
                exp.Source = list;
                foreach (var fi in exp.FieldsInformation)
                {
                    fi.Value.IsExported = false;
                }
                exp.FieldsInformation["Id"].IsExported                                               =
                    exp.FieldsInformation["Title"].IsExported                                        =
                        exp.FieldsInformation["IsPro"].IsExported                                    =
                            exp.FieldsInformation["Note"].IsExported                                 =
                                exp.FieldsInformation["CreatedOn"].IsExported                        =
                                    exp.FieldsInformation["ModifiedOn"].IsExported                   =
                                        exp.FieldsInformation["UrlOrName"].IsExported                =
                                            exp.FieldsInformation["Login"].IsExported                =
                                                exp.FieldsInformation["Password"].IsExported         =
                                                    exp.FieldsInformation["Category"].IsExported     =
                                                        exp.FieldsInformation["Crypting"].IsExported = true;
                exp.Destination = ShareOnExport ? Destination.Share : Destination.Clipboard;
                exp.Execute();
                Toasts.Notify(ToastNotificationType.Success, (sql ? "SQL" : "CSV") + " " + AppResources.SettingsViewModel_exportData_Export, AppResources.SettingsViewModel_exportData_Data_are_in_the_clipboard, TimeSpan.FromSeconds(2));
            }
            catch (Exception ex)
            {
                DialogService.ShowError(ex, AppResources.SettingsViewModel_exportData_Error, AppResources.SettingsViewModel_exportData_OK, null);
            }
        }
Ejemplo n.º 4
0
 private bool isSheetOkVerbose()
 {
     try
     {
         if (Sheet == null)
         {
             return(false);
         }
         if (string.IsNullOrWhiteSpace(Sheet.Title))
         {
             Toasts.Notify(ToastNotificationType.Warning, AppResources.EditViewModel_isSheetOkVerbose_Enter_a_title, AppResources.EditViewModel_isSheetOkVerbose_Title_is_mandatory, TimeSpan.FromSeconds(2));
             return(false);
         }
         if (Sheet.Category == InfoSheet.CategoryFilter.All)
         {
             Toasts.Notify(ToastNotificationType.Warning, AppResources.EditViewModel_isSheetOkVerbose_Select_a_category, AppResources.EditViewModel_isSheetOkVerbose_A_category_must_be_selected, TimeSpan.FromSeconds(2));
             return(false);
         }
         if (Sheet.Category == InfoSheet.CategoryFilter.Login)
         {
             if (string.IsNullOrWhiteSpace(Sheet.Login))
             {
                 Toasts.Notify(ToastNotificationType.Warning, AppResources.EditViewModel_isSheetOkVerbose_Login_is_empty, AppResources.EditViewModel_isSheetOkVerbose_Enter_a_Login_name, TimeSpan.FromSeconds(2));
                 return(false);
             }
             // ReSharper disable once InvertIf
             if (string.IsNullOrWhiteSpace(Sheet.Password))
             {
                 Toasts.Notify(ToastNotificationType.Warning, AppResources.EditViewModel_isSheetOkVerbose_Password_is_empty, AppResources.EditViewModel_isSheetOkVerbose_Enter_a_password, TimeSpan.FromSeconds(2));
                 return(false);
             }
             return(true);
         }
         // ReSharper disable once InvertIf
         if (string.IsNullOrWhiteSpace(Sheet.Note))
         {
             Toasts.Notify(ToastNotificationType.Warning, AppResources.EditViewModel_isSheetOkVerbose_Note_is_empty, AppResources.EditViewModel_isSheetOkVerbose_Enter_something_in_Note_field, TimeSpan.FromSeconds(2));
             return(false);
         }
         return(true);
     }
     finally
     {
         // ReSharper disable once ExplicitCallerInfoArgument
         RaisePropertyChanged(nameof(IsSheetOk));
     }
 }
Ejemplo n.º 5
0
 public GeneratePwViewModel()
 {
     GenerateCommand = new Command(() =>
     {
         UserInteraction();
         generate();
     }, () => LettersDown || LettersUp || Numbers || Symbols);
     CopyToClipboardCommand = new Command(() =>
     {
         UserInteraction();
         CrossShare.Current.SetClipboardText(Generated ?? string.Empty);
         Toasts.Notify(ToastNotificationType.Success, AppResources.GeneratePwViewModel_GeneratePwViewModel_Copy_to_clipboard, AppResources.GeneratePwViewModel_GeneratePwViewModel_Generated_password_copied_to_the_clipboard, TimeSpan.FromSeconds(2));
     },
                                          () => !string.IsNullOrWhiteSpace(Generated));
     ModalDismissCommand = new Command(() => Navigation.ModalDismiss());
     leetLevels          = (from ls in LeetMaker.LeetStrengthStr
                            select new Tuple <LeetMaker.LeetStrength, string>(ls.Key, ls.Value)).ToList();
     selectedStrength = leetLevels[2];
 }
Ejemplo n.º 6
0
        public EditViewModel()
        {
            CancelCommand = new Command(async() =>
            {
                UserInteraction();
                Sheet = originalSheet;
                /*await Toasts.Notify(ToastNotificationType.Info, AppResources.EditViewModel_EditViewModel_Action_canceled, AppResources.EditViewModel_EditViewModel_Data_have_not_been_modified, TimeSpan.FromSeconds(2));*/
                await Navigation.ModalDismiss();
            });
            ValidateCommand = new Command(async() =>
            {
                UserInteraction();
                if (Sheet == null)
                {
                    return;
                }
                if (!isSheetOkVerbose())
                {
                    return;
                }
                try
                {
                    DataService.SaveInfoSheet(Sheet);
                    originalSheet = Sheet;
                    MessengerInstance.Send(new NotificationMessage(
                                               InCreationMode ? Utils.GlobalMessages.DataInserted.ToString() : Utils.GlobalMessages.DataModified.ToString()));
                    await Navigation.ModalDismiss();
                    /*await Toasts.Notify(ToastNotificationType.Success, AppResources.EditViewModel_EditViewModel_Data_saved, AppResources.EditViewModel_EditViewModel_Data_has_been_saved, TimeSpan.FromSeconds(1));*/
                }
                catch (Exception ex)
                {
                    await Toasts.Notify(ToastNotificationType.Error, AppResources.EditViewModel_EditViewModel_Can_t_save_data, AppResources.EditViewModel_EditViewModel_Data_have_NOT_been_saved_,
                                        TimeSpan.FromSeconds(4));
                    await DialogService.ShowError(ex, AppResources.EditViewModel_EditViewModel_Data_error, AppResources.DialogService_ShowMessage_Ok, null);
                }
            }, () => IsModified);
            DeleteCommand = new Command(async() =>
            {
                UserInteraction();
                if (Sheet == null || Sheet.Id < 0)
                {
                    return;
                }
                await DialogService.ShowMessage(AppResources.EditViewModel_EditViewModel_Delete_data__Are_you_sure__,
                                                AppResources.EditViewModel_EditViewModel_Confirmation, AppResources.DialogService_ShowMessage_Ok, AppResources.DialogService_ShowMessage_Cancel,
                                                async b =>
                {
                    if (!b)
                    {
                        return;
                    }
                    try
                    {
                        DataService.DeleteinfoSheet(Sheet);
                        MessengerInstance.Send(new NotificationMessage(Utils.GlobalMessages.DataDeleted.ToString()));

                        /*await
                         *  Toasts.Notify(ToastNotificationType.Success, AppResources.EditViewModel_EditViewModel_Data_deleted, AppResources.EditViewModel_EditViewModel_Data_has_been_deleted,
                         *      TimeSpan.FromSeconds(2));*/
                        await Navigation.ModalDismiss();
                        Sheet         = null;
                        originalSheet = null;
                    }
                    catch (Exception ex)
                    {
                        await
                        Toasts.Notify(ToastNotificationType.Error, AppResources.EditViewModel_EditViewModel_Can_t_delete_data,
                                      AppResources.EditViewModel_EditViewModel_Data_have_NOT_been_deleted_,
                                      TimeSpan.FromSeconds(4));
                        await DialogService.ShowError(ex, AppResources.EditViewModel_EditViewModel_Data_error, AppResources.DialogService_ShowMessage_Ok, null);
                    }
                });
            }, () => InEditMode);
            MoreTimeCommand = new Command(() =>
            {
                UserInteraction();
                App.Locator.LoginSwitch.ResetTimeout();
                Toasts.Notify(ToastNotificationType.Success, AppResources.DetailViewModel_DetailViewModel_More_time,
                              string.Format(AppResources.DetailViewModel_DetailViewModel_You_ve_got__0__seconds_more_,
                                            App.Locator.AppSettings.TimeOutSeconds), TimeSpan.FromSeconds(4));
            }, () => IsMoreTimeAvalaible);

            LoginCategoryCommand = new Command(() =>
            {
                UserInteraction();
                Sheet.Category = InfoSheet.CategoryFilter.Login;
                // ReSharper disable ExplicitCallerInfoArgument
                RaisePropertyChanged(nameof(IsLoginCategory));
                RaisePropertyChanged(nameof(IsMiscCategory));
                RaisePropertyChanged(nameof(IsNoteCategory));
                // ReSharper restore ExplicitCallerInfoArgument
            });
            NoteCategoryCommand = new Command(() =>
            {
                UserInteraction();
                Sheet.Category = InfoSheet.CategoryFilter.Note;
                // ReSharper disable ExplicitCallerInfoArgument
                RaisePropertyChanged(nameof(IsLoginCategory));
                RaisePropertyChanged(nameof(IsMiscCategory));
                RaisePropertyChanged(nameof(IsNoteCategory));
                // ReSharper restore ExplicitCallerInfoArgument
            });
            MiscCategoryCommand = new Command(() =>
            {
                UserInteraction();
                Sheet.Category = InfoSheet.CategoryFilter.Misc;
                // ReSharper disable ExplicitCallerInfoArgument
                RaisePropertyChanged(nameof(IsLoginCategory));
                RaisePropertyChanged(nameof(IsMiscCategory));
                RaisePropertyChanged(nameof(IsNoteCategory));
                // ReSharper restore ExplicitCallerInfoArgument
            });
            ProCommand = new Command(() =>
            {
                UserInteraction();
                Sheet.IsPro = true;
                // ReSharper disable ExplicitCallerInfoArgument
                RaisePropertyChanged(nameof(IsProfessional));
                RaisePropertyChanged(nameof(IsPersonal));
                // ReSharper restore ExplicitCallerInfoArgument
            });

            PersoCommand = new Command(() =>
            {
                UserInteraction();
                Sheet.IsPro = false;
                // ReSharper disable ExplicitCallerInfoArgument
                RaisePropertyChanged(nameof(IsProfessional));
                RaisePropertyChanged(nameof(IsPersonal));
                // ReSharper restore ExplicitCallerInfoArgument
            });

            CheckPasswordCommand = new Command(() =>
            {
                UserInteraction();
                Navigation.ModalNavigateTo(PageName.CheckPw.ToString(), Sheet?.Password);
            },
                                               () => !string.IsNullOrWhiteSpace(Sheet?.Password));
            GeneratePasswordCommand = new Command(() =>
            {
                UserInteraction();
                Navigation.ModalNavigateTo(PageName.GeneratePw.ToString(), true);
            });
        }
Ejemplo n.º 7
0
 public DetailViewModel()
 {
     CheckPasswordCommand = new Command(async() => await Navigation.ModalNavigateTo(PageName.CheckPw.ToString(), sheet.Password), () => IsCheckPasswordVisible);
     CopyLoginCommand     = new Command(async() =>
     {
         UserInteraction();
         await CrossShare.Current.SetClipboardText(Login);
         await Toasts.Notify(ToastNotificationType.Success, AppResources.DetailViewModel_DetailViewModel_Login_copied_to_clipboard, AppResources.DetailViewModel_DetailViewModel_The_login_has_been_copied_to_the_clipboard, TimeSpan.FromSeconds(2));
     }, () => !string.IsNullOrWhiteSpace(Login));
     CopyPasswordCommand = new Command(async() =>
     {
         UserInteraction();
         await CrossShare.Current.SetClipboardText(Password);
         await Toasts.Notify(ToastNotificationType.Success, AppResources.DetailViewModel_DetailViewModel_Password_copied_to_clipboard, AppResources.DetailViewModel_DetailViewModel_The_password_has_been_copied_to_the_clipboard, TimeSpan.FromSeconds(2));
     }, () => !string.IsNullOrWhiteSpace(Password));
     CopyNoteCommand = new Command(() =>
     {
         UserInteraction();
         CrossShare.Current.SetClipboardText(Note);
         Toasts.Notify(ToastNotificationType.Success, AppResources.DetailViewModel_DetailViewModel_Note_copied_to_clipboard, AppResources.DetailViewModel_DetailViewModel_The_note_has_been_copied_to_the_clipboard, TimeSpan.FromSeconds(2));
     }, () => !string.IsNullOrWhiteSpace(Note));
     GoToWebCommand = new Command(async() =>
     {
         UserInteraction();
         try
         {
             Device.OpenUri(new Uri(UrlOrName, UriKind.RelativeOrAbsolute));
         }
         catch
         {
             await Toasts.Notify(ToastNotificationType.Error, AppResources.DetailViewModel_DetailViewModel_Invalid_URL,
                                 AppResources.DetailViewModel_DetailViewModel_Perhaps_are_you_missing_the_protocol_name___http_____for_example___, TimeSpan.FromSeconds(3));
         }
     }, () =>
     {
         try
         {
             Uri.IsWellFormedUriString(UrlOrName,
                                       UriKind.RelativeOrAbsolute);
             return(true);
         }
         catch
         {
             return(false);
         }
     });
     MoreTimeCommand = new Command(async() =>
     {
         UserInteraction();
         App.Locator.LoginSwitch.ResetTimeout();
         await Toasts.Notify(ToastNotificationType.Success, AppResources.DetailViewModel_DetailViewModel_More_time,
                             string.Format(AppResources.DetailViewModel_DetailViewModel_You_ve_got__0__seconds_more_, App.Locator.AppSettings.TimeOutSeconds), TimeSpan.FromSeconds(4));
     }, () => IsMoreTimeAvalaible);
     EditCommand = new Command(async() =>
     {
         UserInteraction();
         await Navigation.ModalNavigateTo(PageName.EditPage.ToString(), sheet);
     });
     MessengerInstance.Register <NotificationMessage>(this, async n =>
     {
         UserInteraction();
         if (n.Notification == Utils.GlobalMessages.DataModified.ToString())
         {
             var s = DataService.GetInfoSheet(sheet.Id);
             IncomingParameter(s);
             return;
         }
         if (n.Notification == Utils.GlobalMessages.DataDeleted.ToString())
         {
             await Navigation.GoBack();
             return;
         }
     });
 }
Ejemplo n.º 8
0
        private int csvImport(IEnumerable <string> data)
        {
            UserInteraction();
            data = data.Where(s => !string.IsNullOrWhiteSpace(s.Trim())).ToList();
            // parse
            var lines   = new List <string[]>();
            var curline = 0;

            foreach (var s in data)
            {
                curline++;
                var k = csvSplit(';', '"', s);
                if (k.Count < 1)
                {
                    Toasts.Notify(ToastNotificationType.Error, AppResources.SettingsViewModel_csvImport_Import_failed, string.Format(AppResources.SettingsViewModel_csvImport_Import_aborted_bad_data_line__0_, curline + 1), TimeSpan.FromSeconds(3));
                    return(0);
                }
                lines.Add(k.ToArray());
            }
            // test 1st line
            var fieldPositions = new List <fieldInfo>();
            var pos            = 0;
            var lineZero       = lines[0];

            foreach (var item in lineZero)
            {
                var p = fieldNames.FirstOrDefault(fn => string.Compare(fn.Name, item, StringComparison.OrdinalIgnoreCase) == 0);
                if (p.OriginalPos < 0)
                {
                    Toasts.Notify(ToastNotificationType.Error, AppResources.SettingsViewModel_exportData_Error, string.Format(AppResources.SettingsViewModel_csvImport_field__0__can_t_be_found, item), TimeSpan.FromSeconds(3));
                    return(0);
                }
                p.Pos = pos++;
                fieldPositions.Add(p);
            }
            fieldPositions = fieldPositions.OrderBy(fp => fp.Pos).ToList();
            if (fieldPositions.Any(fp => fp.Pos != fp.OriginalPos) || fieldPositions.Count != fieldNames.Count)
            {
                Toasts.Notify(ToastNotificationType.Error, AppResources.SettingsViewModel_exportData_Error, AppResources.SettingsViewModel_csvImport_Corrupted_data__1st_line_missing_, TimeSpan.FromSeconds(3));
                return(0);
            }
            // make a list of sheets
            var list = new List <InfoSheet>(lines.Count);

            lines.RemoveAt(0); // titles are no more useful
            foreach (var line in lines)
            {
                var fcInt = new Func <string, int>(s =>
                {
                    int i;
                    var b = int.TryParse(s, out i);
                    if (!b)
                    {
                        throw new Exception(string.Format(AppResources.SettingsViewModel_csvImport___0___is_not_a_valid_ID, s));
                    }
                    return(i);
                });
                var fcBool = new Func <string, bool>(s =>
                {
                    bool i;
                    var b = bool.TryParse(s, out i);
                    if (!b)
                    {
                        throw new Exception(string.Format(AppResources.SettingsViewModel_csvImport___0___is_not_a_valid_boolean, s));
                    }
                    return(i);
                });
                var fcDateTime = new Func <string, DateTime>(s =>
                {
                    if (string.IsNullOrEmpty(s))
                    {
                        return(DateTime.Now);
                    }
                    DateTime i;
                    var b = DateTime.TryParse(s, out i);
                    if (!b)
                    {
                        throw new Exception(string.Format(AppResources.SettingsViewModel_csvImport___0___is_not_a_valid_date_time, s));
                    }
                    return(i);
                });
                var fcCat = new Func <string, InfoSheet.CategoryFilter>(s =>
                {
                    try
                    {
                        return(s.ToEnum(InfoSheet.CategoryFilter.Misc));
                    }
                    catch
                    {
                        throw new Exception(string.Format(AppResources.SettingsViewModel_csvImport___0___is_not_a_valid_Category, s));
                    }
                });
                var fcAlgo = new Func <string, SheetCrypting>(s =>
                {
                    if (string.IsNullOrEmpty(s))
                    {
                        return(SheetCrypting.None);
                    }
                    try
                    {
                        return(s.ToEnum(SheetCrypting.None));
                    }
                    catch
                    {
                        throw new Exception(
                            string.Format(AppResources.SettingsViewModel_csvImport___0___is_not_a_valid_algorithm_data_could_be_unreadable, s));
                    }
                });

                var sheet    = new InfoSheet();
                var modified = DateTime.Now;
                foreach (var p in fieldPositions)
                {
                    var str = line[p.Pos];
                    switch (p.OriginalPos)
                    {
                    case 0:
                        sheet.Id = fcInt(str);
                        break;

                    case 1:
                        sheet.Title = str;
                        break;

                    case 2:
                        sheet.IsPro = fcBool(str);
                        break;

                    case 3:
                        sheet.Note = str;
                        break;

                    case 4:
                        sheet.CreatedOn = fcDateTime(str);
                        break;

                    case 5:
                        modified = fcDateTime(str);
                        break;

                    case 6:
                        sheet.UrlOrName = str;
                        break;

                    case 7:
                        sheet.Login = str;
                        break;

                    case 8:
                        sheet.Password = str;
                        break;

                    case 9:
                        sheet.Category = fcCat(str);
                        break;

                    case 10:
                        sheet.Crypting = fcAlgo(str);
                        break;

                    default:
                        throw new Exception(string.Format(AppResources.SettingsViewModel_csvImport___0___is_not_a_valid_field_position_, p.OriginalPos));
                    }
                }
                sheet.ModifiedOn = modified;
                sheet.IsModified = false;
                sheet            = sheet.ToUnencryptedSheet(); // will be uncrypted by save method
                list.Add(sheet);
            }

            // import data

            try
            {
                var t = DataService.ImportData(list, SkipExistingId, SkipExistingTitle, ClearDbBeforeImport);
                if (t.Item2 > 0 || t.Item3 > 0)
                {
                    Toasts.Notify(ToastNotificationType.Info, AppResources.SettingsViewModel_csvImport_Ignored_data,
                                  string.Format(AppResources.SettingsViewModel_csvImport__0__sheets_imported___1__ID_skipped___2__Title_skipped_, t.Item1, t.Item2, t.Item3), TimeSpan.FromSeconds(5));
                }
                MessengerInstance.Send(new NotificationMessage(Utils.GlobalMessages.DataInserted.ToString()));
                return(t.Item1);
            }
            catch (Exception ex)
            {
                DialogService.ShowError(ex, AppResources.SettingsViewModel_exportData_Error, AppResources.SettingsViewModel_exportData_OK, null);
                return(-1);
            }
        }
Ejemplo n.º 9
0
 private void importSql()
 {
     UserInteraction();
     Toasts.Notify(ToastNotificationType.Info, AppResources.SettingsViewModel_importSql_Not_implemented, AppResources.SettingsViewModel_importSql_No_SQL_import_in_this_version, TimeSpan.FromSeconds(3));
 }