Ejemplo n.º 1
0
 private bool InsertRenameAction(RenameAction renameAction, SqliteConnection con)
 {
     using (SqliteCommand cmd = con.CreateCommand())
     {
         cmd.CommandText = "INSERT INTO " + Configuration.TBL_ACTION +
                           " ( " + Configuration.COL_CHANGE_IN + "," +
                           Configuration.COL_ACTION_TYPE + "," +
                           Configuration.COL_OLD_RELATIVE_PATH + "," +
                           Configuration.COL_NEW_RELATIVE_PATH + "," +
                           Configuration.COL_OLD_HASH + ") VALUES (@changeIn, @action, @oldPath, @newPath, @oldHash)";
         cmd.Parameters.Add(new SqliteParameter("@changeIn", DbType.String)
         {
             Value = renameAction.SourceID
         });
         cmd.Parameters.Add(new SqliteParameter("@action", DbType.Int32)
         {
             Value = renameAction.ChangeType
         });
         cmd.Parameters.Add(new SqliteParameter("@oldPath", DbType.String)
         {
             Value = renameAction.PreviousRelativeFilePath
         });
         cmd.Parameters.Add(new SqliteParameter("@newPath", DbType.String)
         {
             Value = renameAction.RelativeFilePath
         });
         cmd.Parameters.Add(new SqliteParameter("@oldHash", DbType.String)
         {
             Value = renameAction.FileHash
         });
         cmd.ExecuteNonQuery();
         return(true);
     }
 }
Ejemplo n.º 2
0
        public override IList <SyncAction> Load(string sourceID, SourceOption option)
        {
            string             opt     = (option == SourceOption.SOURCE_ID_NOT_EQUALS) ? " <> " : " = ";
            IList <SyncAction> actions = new List <SyncAction>();

            SQLiteAccess db = new SQLiteAccess(Path.Combine(this.StoragePath, Configuration.DATABASE_NAME), false);

            using (SqliteConnection con = db.NewSQLiteConnection())
            {
                if (con == null)
                {
                    throw new DatabaseException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), Path.Combine(this.StoragePath, Configuration.DATABASE_NAME)));
                }

                string cmdText = "SELECT * FROM " + Configuration.TBL_ACTION +
                                 " WHERE " + Configuration.COL_CHANGE_IN + opt + " @sourceId";

                SqliteParameterCollection paramList = new SqliteParameterCollection();
                paramList.Add(new SqliteParameter("@sourceId", System.Data.DbType.String)
                {
                    Value = sourceID
                });

                db.ExecuteReader(cmdText, paramList, reader =>
                {
                    ChangeType actionType = (ChangeType)reader[Configuration.COL_ACTION_TYPE];

                    if (actionType == ChangeType.DELETED)
                    {
                        DeleteAction delAction = new DeleteAction(
                            (int)reader[Configuration.COL_ACTION_ID],
                            (string)reader[Configuration.COL_CHANGE_IN],
                            (string)reader[Configuration.COL_OLD_RELATIVE_PATH], (string)reader[Configuration.COL_OLD_HASH]);
                        actions.Add(delAction);
                    }
                    else if (actionType == ChangeType.NEWLY_CREATED)
                    {
                        CreateAction createAction = new CreateAction(
                            (int)reader[Configuration.COL_ACTION_ID],
                            (string)reader[Configuration.COL_CHANGE_IN],
                            (string)reader[Configuration.COL_NEW_RELATIVE_PATH], (string)reader[Configuration.COL_NEW_HASH]);
                        actions.Add(createAction);
                    }
                    else if (actionType == ChangeType.RENAMED)
                    {
                        RenameAction renameAction = new RenameAction(
                            (int)reader[Configuration.COL_ACTION_ID],
                            (string)reader[Configuration.COL_CHANGE_IN],
                            (string)reader[Configuration.COL_NEW_RELATIVE_PATH],
                            (string)reader[Configuration.COL_OLD_RELATIVE_PATH],
                            (string)reader[Configuration.COL_OLD_HASH]);
                        actions.Add(renameAction);
                    }
                }
                                 );
            }
            return(actions);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Rename a file in sync source folder and update action table
        /// </summary>
        /// <param name="action"></param>
        /// <param name="profile"></param>
        /// <exception cref="System.ComponentModel.Win32Exception"></exception>
        public static void RenameInSyncFolderAndUpdateActionTable(RenameAction action, SyncJob job)
        {
            if (!Directory.Exists(job.SyncSource.Path))
            {
                throw new SyncSourceException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), job.SyncSource.Path));
            }

            if (!Directory.Exists(job.IntermediaryStorage.Path))
            {
                throw new SyncSourceException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), job.IntermediaryStorage.Path));
            }

            string oldAbsolutePathInSyncSource = job.SyncSource.Path + action.PreviousRelativeFilePath;
            string newAbsolutePathInSyncSource = job.SyncSource.Path + action.RelativeFilePath;

            SQLiteAccess     access = new SQLiteAccess(Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME), true);
            SqliteConnection con    = access.NewSQLiteConnection();

            if (con == null)
            {
                throw new DatabaseException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME)));
            }

            SqliteTransaction transaction = (SqliteTransaction)con.BeginTransaction();

            try
            {
                SyncActionsProvider actProvider = SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path);
                actProvider.Delete(action);

                if (File.Exists(oldAbsolutePathInSyncSource) &&
                    !Files.FileUtils.Move(oldAbsolutePathInSyncSource, newAbsolutePathInSyncSource, true))
                {
                    throw new Exception(String.Format(m_ResourceManager.GetString("err_cannotRenameFile"), oldAbsolutePathInSyncSource));
                }
                transaction.Commit();
            }
            catch (Exception)
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                if (con != null)
                {
                    con.Dispose();
                }
            }
        }
Ejemplo n.º 4
0
        private bool InsertRenameAction(RenameAction renameAction)
        {
            SQLiteAccess db = new SQLiteAccess(Path.Combine(this.StoragePath, Configuration.DATABASE_NAME), false);

            using (SqliteConnection con = db.NewSQLiteConnection())
            {
                if (con == null)
                {
                    throw new DatabaseException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), Path.Combine(this.StoragePath, Configuration.DATABASE_NAME)));
                }

                string cmdText = "INSERT INTO " + Configuration.TBL_ACTION +
                                 " ( " + Configuration.COL_CHANGE_IN + "," +
                                 Configuration.COL_ACTION_TYPE + "," +
                                 Configuration.COL_OLD_RELATIVE_PATH + "," +
                                 Configuration.COL_NEW_RELATIVE_PATH + "," +
                                 Configuration.COL_OLD_HASH + ") VALUES (@changeIn, @action, @oldPath, @newPath, @oldHash)";

                SqliteParameterCollection paramList = new SqliteParameterCollection();
                paramList.Add(new SqliteParameter("@changeIn", DbType.String)
                {
                    Value = renameAction.SourceID
                });
                paramList.Add(new SqliteParameter("@action", DbType.Int32)
                {
                    Value = renameAction.ChangeType
                });
                paramList.Add(new SqliteParameter("@oldPath", DbType.String)
                {
                    Value = renameAction.PreviousRelativeFilePath
                });
                paramList.Add(new SqliteParameter("@newPath", DbType.String)
                {
                    Value = renameAction.RelativeFilePath
                });
                paramList.Add(new SqliteParameter("@oldHash", DbType.String)
                {
                    Value = renameAction.FileHash
                });

                db.ExecuteNonQuery(cmdText, paramList);
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Renames conflicted file so that RenameAction can be executed
        /// </summary>
        /// <param name="renameAction">Rename action that cannot be executed due to conflict.</param>
        public static void ConflictRenameAndUpdateActionTable(RenameAction action, SyncJob job, bool keepConflictedFile)
        {
            if (!Directory.Exists(job.SyncSource.Path))
                throw new SyncSourceException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), job.SyncSource.Path));

            if (!Directory.Exists(job.IntermediaryStorage.Path))
                throw new SyncSourceException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), job.IntermediaryStorage.Path));

            string absPathInIStorage = job.IntermediaryStorage.DirtyFolderPath + action.RelativeFilePath;
            string absPathInSyncSource = job.SyncSource.Path + action.RelativeFilePath;
            string absOldPathInSyncSource = job.SyncSource.Path + action.PreviousRelativeFilePath;

            SQLiteAccess access = new SQLiteAccess(Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME), true);
            SqliteConnection con = access.NewSQLiteConnection();

            if (con == null)
                throw new DatabaseException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME)));

            SqliteTransaction trasaction = (SqliteTransaction)con.BeginTransaction();
            try
            {
                SQLiteSyncActionsProvider actProvider = (SQLiteSyncActionsProvider)SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path);
                actProvider.Delete(action, con);

                if (!keepConflictedFile)
                    Files.FileUtils.Delete(absPathInSyncSource, true);
                else
                    Files.FileUtils.DuplicateRename(absPathInSyncSource, absPathInSyncSource);

                if (!Files.FileUtils.Move(absOldPathInSyncSource, absPathInSyncSource, true))
                    throw new Exception(String.Format(m_ResourceManager.GetString("err_cannotRenameFile"), absPathInIStorage));

                trasaction.Commit();
                Files.FileUtils.DeleteFileAndFolderIfEmpty(job.IntermediaryStorage.DirtyFolderPath, absPathInIStorage, true);
            }
            catch (Exception)
            {
                trasaction.Rollback();
                throw;
            }
            finally
            {
                if (con != null) con.Dispose();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Rename a file in sync source folder and update action table
        /// </summary>
        /// <param name="action"></param>
        /// <param name="profile"></param>
        /// <exception cref="System.ComponentModel.Win32Exception"></exception>
        public static void RenameInSyncFolderAndUpdateActionTable(RenameAction action, SyncJob job)
        {
            if (!Directory.Exists(job.SyncSource.Path))
                throw new SyncSourceException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), job.SyncSource.Path));

            if (!Directory.Exists(job.IntermediaryStorage.Path))
                throw new SyncSourceException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), job.IntermediaryStorage.Path));

            string oldAbsolutePathInSyncSource = job.SyncSource.Path + action.PreviousRelativeFilePath;
            string newAbsolutePathInSyncSource = job.SyncSource.Path + action.RelativeFilePath;

            SQLiteAccess access = new SQLiteAccess(Path.Combine (job.IntermediaryStorage.Path, Configuration.DATABASE_NAME),true);
            SqliteConnection con = access.NewSQLiteConnection();

            if (con == null)
                throw new DatabaseException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME)));

            SqliteTransaction transaction = (SqliteTransaction)con.BeginTransaction();

            try
            {
                SyncActionsProvider actProvider = SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path);
                actProvider.Delete(action);

                if (File.Exists(oldAbsolutePathInSyncSource) &&
                    !Files.FileUtils.Move(oldAbsolutePathInSyncSource, newAbsolutePathInSyncSource, true))
                    throw new Exception(String.Format(m_ResourceManager.GetString("err_cannotRenameFile"), oldAbsolutePathInSyncSource));
                transaction.Commit();
            }
            catch (Exception)
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                if (con != null) con.Dispose();
            }
        }
Ejemplo n.º 7
0
 private bool InsertRenameAction(RenameAction renameAction, SqliteConnection con)
 {
     using (SqliteCommand cmd = con.CreateCommand())
     {
         cmd.CommandText = "INSERT INTO " + Configuration.TBL_ACTION +
                         " ( " + Configuration.COL_CHANGE_IN + "," +
                         Configuration.COL_ACTION_TYPE + "," +
                         Configuration.COL_OLD_RELATIVE_PATH + "," +
                         Configuration.COL_NEW_RELATIVE_PATH + "," +
                         Configuration.COL_OLD_HASH + ") VALUES (@changeIn, @action, @oldPath, @newPath, @oldHash)";
         cmd.Parameters.Add(new SqliteParameter("@changeIn", DbType.String) { Value = renameAction.SourceID });
         cmd.Parameters.Add(new SqliteParameter("@action", DbType.Int32) { Value = renameAction.ChangeType });
         cmd.Parameters.Add(new SqliteParameter("@oldPath", DbType.String) { Value = renameAction.PreviousRelativeFilePath });
         cmd.Parameters.Add(new SqliteParameter("@newPath", DbType.String) { Value = renameAction.RelativeFilePath });
         cmd.Parameters.Add(new SqliteParameter("@oldHash", DbType.String) { Value = renameAction.FileHash });
         cmd.ExecuteNonQuery();
         return true;
     }
 }
Ejemplo n.º 8
0
        private bool InsertRenameAction(RenameAction renameAction)
        {
            SQLiteAccess db = new SQLiteAccess(Path.Combine(this.StoragePath, Configuration.DATABASE_NAME),false);
            using (SqliteConnection con = db.NewSQLiteConnection ())
            {
                if (con == null)
                    throw new DatabaseException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), Path.Combine(this.StoragePath, Configuration.DATABASE_NAME)));

                string cmdText = "INSERT INTO " + Configuration.TBL_ACTION +
                                " ( " + Configuration.COL_CHANGE_IN + "," +
                                Configuration.COL_ACTION_TYPE + "," +
                                Configuration.COL_OLD_RELATIVE_PATH + "," +
                                Configuration.COL_NEW_RELATIVE_PATH + "," +
                                Configuration.COL_OLD_HASH + ") VALUES (@changeIn, @action, @oldPath, @newPath, @oldHash)";

                SqliteParameterCollection paramList = new SqliteParameterCollection();
                paramList.Add(new SqliteParameter("@changeIn", DbType.String) { Value = renameAction.SourceID });
                paramList.Add(new SqliteParameter("@action", DbType.Int32) { Value = renameAction.ChangeType });
                paramList.Add(new SqliteParameter("@oldPath", DbType.String) { Value = renameAction.PreviousRelativeFilePath });
                paramList.Add(new SqliteParameter("@newPath", DbType.String) { Value = renameAction.RelativeFilePath });
                paramList.Add(new SqliteParameter("@oldHash", DbType.String) { Value = renameAction.FileHash });

                db.ExecuteNonQuery(cmdText, paramList);
            }

            return true;
        }
Ejemplo n.º 9
0
        public override IList<SyncAction> Load(string sourceID, SourceOption option)
        {
            string opt = (option == SourceOption.SOURCE_ID_NOT_EQUALS) ? " <> " : " = ";
            IList<SyncAction> actions = new List<SyncAction>();

            SQLiteAccess db = new SQLiteAccess(Path.Combine(this.StoragePath, Configuration.DATABASE_NAME),false);
            using (SqliteConnection con = db.NewSQLiteConnection ())
            {
                if (con == null)
                    throw new DatabaseException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), Path.Combine(this.StoragePath, Configuration.DATABASE_NAME)));

                string cmdText = "SELECT * FROM " + Configuration.TBL_ACTION +
                                 " WHERE " + Configuration.COL_CHANGE_IN + opt + " @sourceId";

                SqliteParameterCollection paramList = new SqliteParameterCollection();
                paramList.Add(new SqliteParameter("@sourceId", System.Data.DbType.String) { Value = sourceID });

                db.ExecuteReader(cmdText, paramList, reader =>
                    {
                        ChangeType actionType = (ChangeType)reader[Configuration.COL_ACTION_TYPE];

                        if (actionType == ChangeType.DELETED)
                        {
                            DeleteAction delAction = new DeleteAction(
                                    (int)reader[Configuration.COL_ACTION_ID],
                                    (string)reader[Configuration.COL_CHANGE_IN],
                                    (string)reader[Configuration.COL_OLD_RELATIVE_PATH], (string)reader[Configuration.COL_OLD_HASH]);
                            actions.Add(delAction);
                        }
                        else if (actionType == ChangeType.NEWLY_CREATED)
                        {
                            CreateAction createAction = new CreateAction(
                                (int)reader[Configuration.COL_ACTION_ID],
                                (string)reader[Configuration.COL_CHANGE_IN],
                                (string)reader[Configuration.COL_NEW_RELATIVE_PATH], (string)reader[Configuration.COL_NEW_HASH]);
                            actions.Add(createAction);
                        }
                        else if (actionType == ChangeType.RENAMED)
                        {
                            RenameAction renameAction = new RenameAction(
                                (int)reader[Configuration.COL_ACTION_ID],
                                (string)reader[Configuration.COL_CHANGE_IN],
                                (string)reader[Configuration.COL_NEW_RELATIVE_PATH],
                                (string)reader[Configuration.COL_OLD_RELATIVE_PATH],
                                (string)reader[Configuration.COL_OLD_HASH]);
                            actions.Add(renameAction);
                        }
                    }
                );

            }
            return actions;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Renames conflicted file so that RenameAction can be executed
        /// </summary>
        /// <param name="renameAction">Rename action that cannot be executed due to conflict.</param>
        public static void ConflictRenameAndUpdateActionTable(RenameAction action, SyncJob job, bool keepConflictedFile)
        {
            if (!Directory.Exists(job.SyncSource.Path))
            {
                throw new SyncSourceException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), job.SyncSource.Path));
            }

            if (!Directory.Exists(job.IntermediaryStorage.Path))
            {
                throw new SyncSourceException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), job.IntermediaryStorage.Path));
            }

            string absPathInIStorage      = job.IntermediaryStorage.DirtyFolderPath + action.RelativeFilePath;
            string absPathInSyncSource    = job.SyncSource.Path + action.RelativeFilePath;
            string absOldPathInSyncSource = job.SyncSource.Path + action.PreviousRelativeFilePath;

            SQLiteAccess     access = new SQLiteAccess(Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME), true);
            SqliteConnection con    = access.NewSQLiteConnection();

            if (con == null)
            {
                throw new DatabaseException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME)));
            }

            SqliteTransaction trasaction = (SqliteTransaction)con.BeginTransaction();

            try
            {
                SQLiteSyncActionsProvider actProvider = (SQLiteSyncActionsProvider)SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path);
                actProvider.Delete(action, con);

                if (!keepConflictedFile)
                {
                    Files.FileUtils.Delete(absPathInSyncSource, true);
                }
                else
                {
                    Files.FileUtils.DuplicateRename(absPathInSyncSource, absPathInSyncSource);
                }

                if (!Files.FileUtils.Move(absOldPathInSyncSource, absPathInSyncSource, true))
                {
                    throw new Exception(String.Format(m_ResourceManager.GetString("err_cannotRenameFile"), absPathInIStorage));
                }

                trasaction.Commit();
                Files.FileUtils.DeleteFileAndFolderIfEmpty(job.IntermediaryStorage.DirtyFolderPath, absPathInIStorage, true);
            }
            catch (Exception)
            {
                trasaction.Rollback();
                throw;
            }
            finally
            {
                if (con != null)
                {
                    con.Dispose();
                }
            }
        }