private void RemoveFromCachedIds(DbFavorite favorite) { if (this.ContainsFavorite(favorite.Id)) { this.favoriteIds.Remove(favorite.Id); } }
private void AddToCachedIds(DbFavorite favorite) { if (!this.ContainsFavorite(favorite.Id)) { this.favoriteIds.Add(favorite.Id); } }
IFavorite IFavorite.Copy() { DbFavorite copy = Factory.CreateFavorite(this.groups, this.credentials, this.Details.Dispatcher); copy.UpdateFrom(this); return(copy); }
private void TryLoadImageFromDatabase(DbFavorite favorite) { using (Database database = DatabaseConnections.CreateInstance()) { byte[] imageData = database.GetFavoriteIcon(favorite.Id); this.AssignImageByLoadedData(favorite, imageData); } }
private static void TryAddToDatabase(DbFavorite historyTarget) { using (var database = DatabaseConnections.CreateInstance()) { var userSid = WindowsUserIdentifiers.GetCurrentUserSid(); // store holds dates in UTC database.InsertHistory(historyTarget.Id, Moment.Now, userSid); } }
private void TryUpdateImageInDatabase(DbFavorite favorite, Database database) { if (this.ShouldSaveIcon(favorite)) { byte[] imageData = this.favoriteIcons.ImageToBinary(favorite.ToolBarIconImage); if (imageData.Length > 0) { database.SetFavoriteIcon(favorite.Id, imageData); } } }
/// <summary> /// Does not set the protocol options. /// </summary> internal static DbFavorite CreateFavorite(Groups groups, StoredCredentials credentials, DataDispatcher dispatcher) { var favorite = new DbFavorite(); favorite.Display = new DbDisplayOptions(); favorite.Security = new DbSecurityOptions(); favorite.ExecuteBeforeConnect = new DbBeforeConnectExecute(); favorite.AssignStores(groups, credentials, dispatcher); favorite.MarkAsNewlyCreated(); return(favorite); }
private void AddToDatabase(DbFavorite historyTarget) { try { TryAddToDatabase(historyTarget); // don't report, if it wasn't successfully added this.FireOnHistoryRecorded(historyTarget); } catch (EntityException exception) { this.dispatcher.ReportActionError(this.AddToDatabase, historyTarget, this, exception, "Unable to save connection history.\r\nDatabase connection lost."); } }
internal void UpdateImageInDatabase(DbFavorite favorite, Database database) { try { this.TryUpdateImageInDatabase(favorite, database); } catch (DbUpdateException) { // recovery will be done by next update Logging.Error("Unable to update favorite image in database because of concurrency exception"); } catch (EntityException exception) { this.dispatcher.ReportActionError(db => this.UpdateImageInDatabase(favorite, db), database, favorite, exception, "Unable to Save favorite icon to database.\r\nDatabase connection lost."); } }
internal void LoadImageFromDatabase(DbFavorite favorite) { try { this.TryLoadImageFromDatabase(favorite); } catch (DbUpdateException) { // assign default image and let fix by next refresh this.AssignImageByLoadedData(favorite, new byte[0]); } catch (EntityException exception) { this.dispatcher.ReportActionError(() => this.LoadImageFromDatabase(favorite), favorite, exception, "Unable to load favorite icon from database.\r\nDatabase connection lost."); } }
private void UpdateFrom(DbFavorite source) { // force load first to fill the content, otherwise we don't have to able to copy this.Details.Load(); source.Details.Load(); // force the protocol to be loaded, in case the source wasnt accessed yet. source.Details.LoadProtocolProperties(); this.DesktopShare = source.DesktopShare; // we cant copy the fields, because they are also dependent on the favorite Id this.Details.UpdateFrom(source.Details); this.Name = source.Name; this.NewWindow = source.NewWindow; this.Notes = source.Notes; this.Port = source.Port; this.ServerName = source.ServerName; this.ToolBarIconImage = source.ToolBarIconImage; // protocolProperties don't have a favorite Id reference, so we can overwrite complete content ProtocolOptions sourceProperties = source.protocolProperties.Copy(); this.ChangeProtocol(source.Protocol, sourceProperties); this.AssignStores(source.groups, source.credentials, source.Details.Dispatcher); }
public void DbFavoriteValidationTest() { // created dbfavorite is not compleate, only necessary to make validable using IFavorite var favorite = new DbFavorite(); favorite.ExecuteBeforeConnect = new DbBeforeConnectExecute(); favorite.Security = new DbSecurityOptions(); favorite.Details.LoadFieldsFromReferences(); favorite.Protocol = longText.Substring(0, 11); favorite.ServerName = longText; favorite.Name = longText; favorite.Notes = longText; favorite.ExecuteBeforeConnect.Command = longText; favorite.ExecuteBeforeConnect.CommandArguments = longText; favorite.ExecuteBeforeConnect.InitialDirectory = longText; var results = Validations.Validate(favorite); Assert.AreEqual(9, results.Count(), "Some properties arent validated properly for DbFavorite"); var serverNameErrors = results.Count(result => result.PropertyName == "ServerName"); Assert.AreEqual(2, serverNameErrors, "DbFavorite ServerName wasnt validated properly"); var protocolErrors = results.Count(result => result.PropertyName == "Protocol"); Assert.AreEqual(2, protocolErrors, "DbFavorite protocol wasnt validated properly"); }
private void UpdateFavorite(DbFavorite toUpdate, IFavorites targetPersistence) { toUpdate.Name += " Changed"; targetPersistence.Update(toUpdate); }
private void AssignImageByLoadedData(DbFavorite favorite, byte[] imageData) { favorite.ToolBarIconImage = this.favoriteIcons.LoadImage(imageData, favorite); }
internal FavoriteDetails(DbFavorite favorite) { this.favorite = favorite; }
internal void AttachFavorite(DbFavorite favorite) { this.Attach(favorite.Details); this.database.Favorites.Attach(favorite); }
internal void DetachFavorite(DbFavorite favorite) { this.Detach(favorite.Details); this.Detach(favorite); }
internal void MarkFavoriteAsModified(DbFavorite favorite) { this.MarkAsModified(favorite); this.MarkAsModified(favorite.Details); }
private bool ShouldSaveIcon(DbFavorite favorite) { return(favorite.ToolBarIconImage != null && !this.favoriteIcons.IsDefaultProtocolImage(favorite.ToolBarIconImage)); }
public void AssingNewIcon(DbFavorite favorite, string imageFilePath) { favorite.ToolBarIconImage = this.favoriteIcons.LoadImage(imageFilePath, favorite); }
private void AddToDatabase(DbFavorite historyTarget) { try { TryAddToDatabase(historyTarget); // don't report, if it wasn't successfully added this.FireOnHistoryRecorded(historyTarget); } catch (EntityException exception) { this.dispatcher.ReportActionError(AddToDatabase, historyTarget, this, exception, "Unable to save connection history.\r\nDatabase connection lost."); } }
private static void TryAddToDatabase(DbFavorite historyTarget) { using (Database database = DatabaseConnections.CreateInstance()) { string userSid = WindowsUserIdentifiers.GetCurrentUserSid(); // store holds dates in UTC database.InsertHistory(historyTarget.Id, Moment.Now, userSid); } }