示例#1
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();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Generate patches
        /// </summary>
        private void GeneratePatch()
        {
            // Delete previously saved actions
            actProvider.Delete(_job.SyncSource.ID, SourceOption.SOURCE_ID_EQUALS);

            // Generate new actions
            IList <SyncAction> newActions = GenerateActions();

            if (newActions.Count == 0)
            {
                OnProgressChanged(new SyncProgressChangedEventArgs(1, 1));
                return;
            }

            // Clear log
            log.Clear();
            DateTime startTime = DateTime.Now;

            /*
             * try
             * {
             *  FileMetaData mdDirtyFolder =
             *      MetaDataProvider.GenerateFileMetadata(_job.IntermediaryStorage.DirtyFolderPath, "", false, false);
             *  DeleteRedundantDirtyFiles(newActions, mdDirtyFolder.MetaDataItems, _job.IntermediaryStorage.DirtyFolderPath);
             * }
             * catch (Exception){}
             */

            try
            {
                SaveActionsAndDirtyFiles(newActions);
            }
            catch (OutOfDiskSpaceException)
            {
                throw;
            }
            finally
            {
                WriteLog(startTime, Log.To);
            }
            //catch (OutOfDiskSpaceException) { throw; }
        }
示例#3
0
        public static void DeleteFromActionTable(SyncAction action, SyncJob job)
        {
            SyncActionsProvider actProvider = SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path);

            actProvider.Delete(action);
        }