// Constructor public FileSyncAgent(SyncJob job) { this._job = job; // Instantiates providers actProvider = SyncClient.GetSyncActionsProvider(this._job.IntermediaryStorage.Path); mdProvider = SyncClient.GetMetaDataProvider(_job.IntermediaryStorage.Path, _job.SyncSource.ID); }
/// <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(); } } }
public static void DeleteFromActionTable(SyncAction action, SyncJob job) { SyncActionsProvider actProvider = SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path); actProvider.Delete(action); }