예제 #1
0
 private void RemoveFromCachedIds(DbFavorite favorite)
 {
     if (this.ContainsFavorite(favorite.Id))
     {
         this.favoriteIds.Remove(favorite.Id);
     }
 }
예제 #2
0
 private void AddToCachedIds(DbFavorite favorite)
 {
     if (!this.ContainsFavorite(favorite.Id))
     {
         this.favoriteIds.Add(favorite.Id);
     }
 }
예제 #3
0
        IFavorite IFavorite.Copy()
        {
            DbFavorite copy = Factory.CreateFavorite(this.groups, this.credentials, this.Details.Dispatcher);

            copy.UpdateFrom(this);
            return(copy);
        }
예제 #4
0
 private void TryLoadImageFromDatabase(DbFavorite favorite)
 {
     using (Database database = DatabaseConnections.CreateInstance())
     {
         byte[] imageData = database.GetFavoriteIcon(favorite.Id);
         this.AssignImageByLoadedData(favorite, imageData);
     }
 }
예제 #5
0
 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);
     }
 }
예제 #6
0
 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);
         }
     }
 }
예제 #7
0
파일: Factory.cs 프로젝트: zoroz/Terminals
        /// <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);
        }
예제 #8
0
 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.");
     }
 }
예제 #9
0
 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.");
     }
 }
예제 #10
0
 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.");
     }
 }
예제 #11
0
        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);
        }
예제 #12
0
        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);
 }
예제 #14
0
 private void AssignImageByLoadedData(DbFavorite favorite, byte[] imageData)
 {
     favorite.ToolBarIconImage = this.favoriteIcons.LoadImage(imageData, favorite);
 }
예제 #15
0
 internal FavoriteDetails(DbFavorite favorite)
 {
     this.favorite = favorite;
 }
예제 #16
0
 internal void AttachFavorite(DbFavorite favorite)
 {
     this.Attach(favorite.Details);
     this.database.Favorites.Attach(favorite);
 }
예제 #17
0
 internal void DetachFavorite(DbFavorite favorite)
 {
     this.Detach(favorite.Details);
     this.Detach(favorite);
 }
예제 #18
0
 internal void MarkFavoriteAsModified(DbFavorite favorite)
 {
     this.MarkAsModified(favorite);
     this.MarkAsModified(favorite.Details);
 }
예제 #19
0
 private bool ShouldSaveIcon(DbFavorite favorite)
 {
     return(favorite.ToolBarIconImage != null &&
            !this.favoriteIcons.IsDefaultProtocolImage(favorite.ToolBarIconImage));
 }
예제 #20
0
 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);
     }
 }