private void SetDataContext() { try { Shortcuts shortcuts = null; if (IsFirstTimeRun()) { // This is the first time the application is runing. shortcuts = NewData.NewShortcuts(); SaveData.SaveShortcuts(shortcuts, true); } else { // This is not the first time the application is runing. // Get the shortcuts data shortcuts = ShortcutsData.GetShortcuts(); // If shortcuts is null then perhaps the sortcut data file is corrupted. if (shortcuts == null) { MessageBoxResult messageBoxResult = MessageBox.Show("For some reason shortcuts are corrupted.\nReseting shortcuts.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); shortcuts = NewData.NewShortcuts(); SaveData.SaveShortcuts(shortcuts, true); } } DataContext = ContextHelper.ShortcutsToVM(shortcuts); } catch (Exception ex) { Error.ShowDialog(ex); } }
public static ShortcutsVM ShortcutsToVM(Shortcuts shortcuts) { ShortcutsVM shortcutsVM = new ShortcutsVM(shortcuts.Version); shortcutsVM.WindowItemVMs = WindowItemsToVMs(shortcuts.WindowItems); return(shortcutsVM); }
public static Shortcuts VMToShortcuts(ShortcutsVM shortcutsVM) { Shortcuts shortcuts = new Shortcuts(shortcutsVM.Version); shortcuts.WindowItems = VMsToWindowItems(shortcutsVM.WindowItemVMs); return(shortcuts); }
public static void SaveShortcuts(string serializedShortcuts, bool saveNow) { if(saveNow) { // If saveNow = true then just save now. // Save to file SaveShortcutsToFile(serializedShortcuts); // This is not used anymore. We use files to store the shortcuts data. // Save to settings // SaveShortcutsToSettings(serializedShortcuts); } else { // If saveNow = false then wait for the save request frequency interval to come before saving // Save every Constants.SAVE_REQUEST_FREQUENCY times ShortcutsVM shortcutsVM = ((App)Application.Current).DataContext; shortcutsVM.SaveRequestCounter += 1; if ((shortcutsVM.SaveRequestCounter % Constants.SAVE_REQUEST_FREQUENCY) == 0) { // Save to file SaveShortcutsToFile(serializedShortcuts); // This is not used anymore. We use files to store the shortcuts data. // Save to settings // SaveShortcutsToSettings(serializedShortcuts); } } // TODO //MessageBox.Show("SaveShortcuts"); }
public RestoreWindow() { InitializeComponent(); try { ShortcutsVM shortcutsVM = ((App)Application.Current).DataContext; ListViewBackup.ItemsSource = shortcutsVM.BackupVMs; } catch (Exception ex) { Error.ShowDialog(ex); } }
public bool Insert(ShortcutsVM entity) { SHORTCUTS bt = new SHORTCUTS { UID = entity.UID, KEY_TYPE = entity.KEY_TYPE, ORDER_ID = entity.ORDER_ID, AddedBy = entity.AddedBy, AddedOn = entity.AddedOn, UpdatedBy = entity.UpdatedBy, updatedOn = entity.updatedOn }; shortCutRepo.Add(bt); return(true); }
public Task <bool> InsertAsync(ShortcutsVM entity) { return(Task.Run <bool>(() => { SHORTCUTS bt = new SHORTCUTS { UID = entity.UID, KEY_TYPE = entity.KEY_TYPE, ORDER_ID = entity.ORDER_ID, AddedBy = entity.AddedBy, AddedOn = entity.AddedOn, UpdatedBy = entity.UpdatedBy, updatedOn = entity.updatedOn }; shortCutRepo.Add(bt); return true; })); }
public bool Delete(ShortcutsVM entity) { SHORTCUTS bt = new SHORTCUTS { UID = entity.UID, KEY_TYPE = entity.KEY_TYPE, ORDER_ID = entity.ORDER_ID, AddedBy = entity.AddedBy, AddedOn = entity.AddedOn, UpdatedBy = entity.UpdatedBy, updatedOn = entity.updatedOn }; object[] Keys = new object[2] { entity.UID, entity.KEY_TYPE }; shortCutRepo.DeleteComposite(bt, Keys); return(true); }
private static void RestoreBackup() { // Before doing restore, close all windows ShortcutsVM shortcutsVM = ((App)Application.Current).DataContext; // Loop through all windows and close them foreach (WindowItemVM windowItemVM in shortcutsVM.WindowItemVMs) { // Loop through all the window clones and close them foreach (WindowItemVM windowItemVMClone in windowItemVM.WindowItemVMClones) { Window windowClone = Helper.GetWindowFromWindowItemVM(windowItemVMClone); windowClone.Close(); } Window window = Helper.GetWindowFromWindowItemVM(windowItemVM); window.Close(); } ((App)Application.Current).StartLife(); }
public static ObservableCollection <WindowItemVM> GetWindowItemVMClones(WindowItemVM windowItemVMToClose) { // Get the application context ShortcutsVM shortcutsVM = ((App)Application.Current).DataContext; foreach (WindowItemVM windowItemVM in shortcutsVM.WindowItemVMs) { if (windowItemVM.WindowItemVMClones != null) { foreach (WindowItemVM windowItemVMClone in windowItemVM.WindowItemVMClones) { if (windowItemVMClone == windowItemVMToClose) { return(windowItemVM.WindowItemVMClones); } } } } return(null); }
public static void DeleteSpecificBackup(string fileName) { // Get the application context ShortcutsVM shortcutsVM = ((App)Application.Current).DataContext; // Remove the backupVM from BackupVMs foreach (BackupVM backupVM in shortcutsVM.BackupVMs) { if (backupVM.FileName.Equals(fileName, StringComparison.InvariantCultureIgnoreCase)) { shortcutsVM.BackupVMs.Remove(backupVM); break; } } // Remove the physical backup file string shortcutsBackupPath = Helper.GetShortcutsBackupPath(); string backupFilePath = Path.Combine(shortcutsBackupPath, fileName); FileIO.DeleteFile(backupFilePath); }
public Task <bool> DeleteAsync(ShortcutsVM entity) { return(Task.Run <bool>(() => { SHORTCUTS bt = new SHORTCUTS { UID = entity.UID, KEY_TYPE = entity.KEY_TYPE, ORDER_ID = entity.ORDER_ID, AddedBy = entity.AddedBy, AddedOn = entity.AddedOn, UpdatedBy = entity.UpdatedBy, updatedOn = entity.updatedOn }; object[] Keys = new object[2] { entity.UID, entity.KEY_TYPE }; shortCutRepo.DeleteComposite(bt, Keys); return true; })); }
/// <summary> /// Create a backup of the current windows & shortcuts. /// </summary> /// <returns></returns> public static string BackupShortcuts() { // Get the application context ShortcutsVM shortcutsVM = ((App)Application.Current).DataContext; Shortcuts shortcuts = ContextHelper.VMToShortcuts(shortcutsVM); string shortcutsSerialized = JsonConvert.SerializeObject(shortcuts); string shortcutsBackupPath = Helper.GetShortcutsBackupPath(); DateTime dateTime = DateTime.Now; string backupFileName = dateTime.ToString("yyyyMMdd_HHmmss_fff", CultureInfo.InvariantCulture); string backupFilePath = Path.Combine(shortcutsBackupPath, backupFileName); FileIO.WriteFile(backupFilePath, shortcutsSerialized, false); FileInfo fileInfo = new FileInfo(backupFilePath); string fileSize = fileInfo.Length.ToString() + " bytes"; // Update the shortcutsVM BackupVM backupVM = new BackupVM(backupFileName, fileSize); shortcutsVM.BackupVMs.Add(backupVM); shortcutsVM.BackupVMs.Sort((a, b) => { return(b.FileName.CompareTo(a.FileName)); }); return(backupFileName); }
public async Task <IHttpActionResult> delete([FromBody] ShortcutsVM entity) { return(Ok(await shortCutService.DeleteAsync(entity))); }
public async Task <IHttpActionResult> add([FromBody] ShortcutsVM entity) { return(Ok(await shortCutService.InsertAsync(entity))); }
public static void SaveShortcuts(bool saveNow) { ShortcutsVM shortcutsVM = ((App)Application.Current).DataContext; Shortcuts shortcuts = ContextHelper.VMToShortcuts(shortcutsVM); SaveShortcuts(shortcuts, saveNow); }