Ejemplo n.º 1
0
 private SortableList <IFavorite> TryLodFromDatabase(string historyDateKey)
 {
     using (var database = DatabaseConnections.CreateInstance())
     {
         var interval = HistoryIntervals.GetIntervalByName(historyDateKey);
         // store holds dates in UTC
         var favoriteIds       = database.GetFavoritesHistoryByDate(interval.From, interval.To).ToList();
         var intervalFavorites =
             this.favorites.Cast <DbFavorite>().Where(favorite => favoriteIds.Contains(favorite.Id));
         return(Data.Favorites.OrderByDefaultSorting(intervalFavorites));
     }
 }
Ejemplo n.º 2
0
 private void TryAdd(List <IFavorite> favorites)
 {
     using (Database database = DatabaseConnections.CreateInstance())
     {
         List <DbFavorite> toAdd = favorites.Cast <DbFavorite>().ToList();
         database.AddAll(toAdd);
         this.UpdateIconInDatabase(database, toAdd);
         database.SaveImmediatelyIfRequested();
         database.Cache.DetachAll(toAdd);
         this.cache.Add(toAdd);
         this.dispatcher.ReportFavoritesAdded(favorites);
     }
 }
Ejemplo n.º 3
0
 private void TryApplyCredentials(List <IFavorite> selectedFavorites, ICredentialSet credential)
 {
     using (Database database = DatabaseConnections.CreateInstance())
     {
         var dbFavorites = selectedFavorites.Cast <DbFavorite>().ToList();
         Data.Favorites.ApplyCredentialsToFavorites(selectedFavorites, credential);
         database.Cache.AttachAll(dbFavorites);
         // here we have to mark it modified, because caching detail properties
         // sets proper credential set reference
         database.Cache.MarkAsModified(dbFavorites);
         this.batchActions.SaveAndReportFavoritesUpdated(database, dbFavorites, selectedFavorites);
     }
 }
Ejemplo n.º 4
0
        internal static TestConnectionResult UpdateMastrerPassord(string connectionString, string oldPassword, string newPassword)
        {
            TestConnectionResult oldPasswordCheck = DatabaseConnections.TestConnection(connectionString, oldPassword);

            if (!oldPasswordCheck.Successful)
            {
                return(oldPasswordCheck);
            }

            var update = new DatabasePasswordUpdate();

            return(update.Run(connectionString, oldPassword, newPassword));
        }
Ejemplo n.º 5
0
 internal bool UpdateDatabaseKey(string connectionString, string databasePassword)
 {
     try
     {
         string databaseStoredKey = DatabaseConnections.TryGetMasterPasswordHash(connectionString);
         this.persistenceKeyMaterial = PasswordFunctions2.CalculateMasterPasswordKey(databasePassword, databaseStoredKey);
         return(true);
     }
     catch
     {
         Logging.Error("Unable to obtain database key from database");
         return(false);
     }
 }
Ejemplo n.º 6
0
 private void TryDelete(List <IFavorite> favorites)
 {
     using (Database database = DatabaseConnections.CreateInstance())
     {
         List <DbFavorite>       favoritesToDelete       = favorites.Cast <DbFavorite>().ToList();
         List <DbCredentialBase> redundantCredentialBase = SelectRedundantCredentialBase(favoritesToDelete);
         this.DeleteFavoritesFromDatabase(database, favoritesToDelete);
         database.SaveImmediatelyIfRequested();
         database.RemoveRedundantCredentialBase(redundantCredentialBase);
         database.SaveImmediatelyIfRequested();
         this.groups.RefreshCache();
         this.FinishRemove(favorites, favoritesToDelete);
     }
 }
Ejemplo n.º 7
0
 private void TryDelete(IGroup group)
 {
     using (var database = DatabaseConnections.CreateInstance())
     {
         var toDelete         = group as DbGroup;
         var changedFavorites = group.Favorites;
         this.SetChildsToRoot(database, toDelete);
         database.Groups.Attach(toDelete);
         database.Groups.Remove(toDelete);
         database.SaveImmediatelyIfRequested();
         this.FinishGroupRemove(group);
         this.dispatcher.ReportFavoritesUpdated(changedFavorites);
     }
 }
Ejemplo n.º 8
0
 private void TryAdd(IGroup group)
 {
     using (var database = DatabaseConnections.CreateInstance())
     {
         var toAdd = group as DbGroup;
         database.AddToGroups(toAdd);
         database.SaveImmediatelyIfRequested();
         database.Cache.DetachGoup(toAdd);
         this.cache.Add(toAdd);
         this.dispatcher.ReportGroupsAdded(new List <IGroup> {
             toAdd
         });
     }
 }
Ejemplo n.º 9
0
 private List <DbFavorite> TryLoadFromDatabase()
 {
     string[] knownProtocols = this.connectionManager.GetAvailableProtocols();
     using (Database database = DatabaseConnections.CreateInstance())
     {
         // to list because Linq to entities allows only cast to primitive types.
         // cant use connectionManager.IsKnownProtocol because it cant be translated to serverside query.
         List <DbFavorite> favorites = database.Favorites
                                       .Where(f => knownProtocols.Contains(f.Protocol))
                                       .ToList();
         database.Cache.DetachAll(favorites);
         favorites.ForEach(this.PrepareFavorite);
         return(favorites);
     }
 }
Ejemplo n.º 10
0
        private bool TryInitializeDatabase()
        {
            if (DatabaseConnections.TestConnection())
            {
                bool updatedKey = this.security.UpdateDatabaseKey();

                if (updatedKey)
                {
                    // UpgradeDatabaseVersion();
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 11
0
        private static List <DbGroup> TryLoadFromDatabase(List <DbGroup> toRefresh)
        {
            using (var database = DatabaseConnections.CreateInstance())
            {
                if (toRefresh != null)
                {
                    database.Cache.AttachAll(toRefresh);
                }

                ((IObjectContextAdapter)database).ObjectContext.Refresh(RefreshMode.StoreWins, database.Groups);
                var groups = database.Groups.Include("ParentGroup").ToList();
                database.Cache.DetachAll(groups);
                return(groups);
            }
        }
Ejemplo n.º 12
0
        private void TryUpdateFavorite(IFavorite favorite, List <IGroup> newGroups)
        {
            using (Database database = DatabaseConnections.CreateInstance())
            {
                var toUpdate = favorite as DbFavorite;
                database.Cache.AttachFavorite(toUpdate);
                List <IGroup> addedGroups = database.AddToDatabase(newGroups);
                // commit newly created groups, otherwise we cant add into them
                database.SaveImmediatelyIfRequested();
                UpdateGroupsMembership(favorite, newGroups);
                database.SaveImmediatelyIfRequested();

                this.dispatcher.ReportGroupsAdded(addedGroups);
                this.TrySaveAndReportFavoriteUpdate(toUpdate, database);
            }
        }