/// <summary> /// Get a users profile /// </summary> /// <param name="iUser">The user of the profile to get</param> /// <returns>The users profile if found, otherwise null</returns> public Profile GetUserProfile(User iUser) { Boolean pBlnCreatedTable = ProfilesTable.CreateIfNotExists(); if (pBlnCreatedTable) { String pStrProfile = File.ReadAllText(FunctionAssetsPath + "ProfileDefaults.json"); Profile pProProfile = Profile.FromJSON(pStrProfile); return(pProProfile); } else { TableOperation pTOnRetrieve = TableOperation.Retrieve <DynamicTableEntity>(iUser.PartitionKey, iUser.RowKey); TableResult pTRtResult = ProfilesTable.Execute(pTOnRetrieve); switch (pTRtResult.HttpStatusCode) { case 200: { Profile pProProfile = Profile.FromDynamicTableEntity((DynamicTableEntity)pTRtResult.Result); return(pProProfile); } } } return(null); }
/// <summary> /// Replaces a profile in storage with the provided profile /// </summary> /// <param name="iUser">The user to accociate the profile with</param> /// <param name="iProfile">The profile instance to replace the existing one with</param> /// <returns>True if successful</returns> public Boolean ReplaceProfile(User iUser, Profile iProfile) { Boolean pBlnCreatedTable = ProfilesTable.CreateIfNotExists(); DynamicTableEntity pDTEProfile = iProfile.ToDynamicTableEntity(iUser.PartitionKey, iUser.RowKey); pDTEProfile.ETag = "*"; TableOperation pTOnReplace = TableOperation.Replace(pDTEProfile); TableResult pTRtResult; try { pTRtResult = ProfilesTable.Execute(pTOnReplace); switch (pTRtResult.HttpStatusCode) { case 200: case 204: { return(true); } default: { return(false); } } } catch { return(false); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { var database = new SystemDatabase(); if (!database.CreateDatabaseIfNeed()) { AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToCreate, "system database")); this.Close(); } this._model = new ObservableCollection <ProfileModel>(); using (var table = new ProfilesTable()) { table.OpenDatabase(); table.SelectAll(); while (table.Read()) { this._model.Add(new ProfileModel { Id = table.Id, FilePath = table.FilePath, DisplayName = table.DisplayName, RowOrder = table.RowOrder }); } } this.cProfileList.DataContext = this._model; }
internal ProfileModel(ProfilesTable table) { this.Id = table.Id; this.FilePath = table.FilePath; this.DisplayName = table.DisplayName; this.RowOrder = table.RowOrder; }
private void Delete_Click(object sender, RoutedEventArgs e) { var model = ((Button)sender).Tag as ProfileModel; var dialog = new ProfileDeleteConfirm(this, model); if (true != dialog.ShowDialog()) { dialog.Close(); return; } using (var table = new ProfilesTable()) { if (table.DeleteById(model.Id) < 0) { AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToDelete, "profile")); } if (true == dialog.DeleteFile) { new FileOperator(model.FilePath).Delete(); } } dialog.Close(); this._model.Remove(model); this._deleteModels.Add(model); }
private void Edit_Click(object sender, RoutedEventArgs e) { var model = ((Button)sender).Tag as ProfileModel; var dialog = new EditProfileName(this, model); if (true != dialog.ShowDialog()) { dialog.Close(); return; } if (dialog.IsChanged) { using (var table = new ProfilesTable()) { if (0 == table.UpdateDisplayNameById(model)) { AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToUpdate, "display name")); } } if (null != this.CurrentModel && model.Id == this.CurrentModel.Id) { this.CurrentModel.DisplayName = model.DisplayName; } } dialog.Close(); }
/// <summary> /// check whether profile is already registered. /// </summary> /// <param name="profile">file</param> /// <returns>true:registered, false:otherwise</returns> private bool IsRegisterProfile(string profile) { bool result = false; var table = new ProfilesTable(); if (0 < table.SelectCountByFilePath(profile)) { AppCommon.ShowErrorMsg(ErrorMsg.ProfileIsRegistered); result = true; } return(result); }
/// <summary> /// window loaded /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MySimpleLauncherMain_Loaded(object sender, RoutedEventArgs e) { this.cCategoryList.DataContext = this._categoryList; this.cItemList.DataContext = this._itemList; this.cDisplayMenuShowStatusBar.IsChecked = this._settings.ShowStatusBar; this.cFileStatus.Visibility = this._settings.ShowStatusBar ? Visibility.Visible : Visibility.Collapsed; this.cCategoryList.ContextMenu = this._categoryMenu; this.cItemList.ContextMenu = this._itemMenu; if (this._settings.CurrentProfileId < 0) { this.ClearScreen(); } else { using (var table = new ProfilesTable()) { table.SelectById(this._settings.CurrentProfileId); if (table.Read()) { this._currentProfile = new ProfileModel(table); if (System.IO.File.Exists(table.FilePath)) { this.cProfileList.Content = this._currentProfile.DisplayName; this._profileDatabase = new ProfileDatabase(table.FilePath); this.ShowCategoryList(); this.cCategoryList.SelectedIndex = this._settings.CategoryListSelectedIndex; } else { AppCommon.ShowErrorMsg(string.Format(ErrorMsg.ProfileNotFound, table.FilePath)); this.ClearScreen(); } } else { this.ClearScreen(); } } } this.SetWindowsState(true); }
/// <summary> /// insert profile data and add list if success. /// </summary> /// <param name="profile">profile information</param> /// <returns>true:success, false:otherwise</returns> private bool InsertProfile(FileOperator profile) { var model = new ProfileModel { FilePath = profile.FilePath, DisplayName = profile.NameWithoutExtension }; var table = new ProfilesTable(); var result = false; var id = table.Insert(model); if (id < 0) { AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToInsert, "profile data")); } else { // model.Id = table.SelectIdByFilePath(model.FilePath); model.Id = id; result = true; this._model.Add(model); } return(result); }