/// <summary> /// Copy a file from sync folder and update action table /// </summary> /// <param name="action"></param> /// <param name="profile"></param> public static void CopyToSyncFolderAndUpdateActionTable(SyncAction 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)); } // TODO: atomic.... string absolutePathInIntermediateStorage = job.IntermediaryStorage.DirtyFolderPath + action.RelativeFilePath; string absolutePathInSyncSource = job.SyncSource.Path + action.RelativeFilePath; SQLiteAccess dbAccess = new SQLiteAccess(Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME), true); SqliteConnection con = dbAccess.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 (!Files.FileUtils.Copy(absolutePathInIntermediateStorage, absolutePathInSyncSource, true)) { throw new Exception(String.Format(m_ResourceManager.GetString("err_cannotCopyFile"), absolutePathInIntermediateStorage)); } trasaction.Commit(); Files.FileUtils.DeleteFileAndFolderIfEmpty(job.IntermediaryStorage.DirtyFolderPath, absolutePathInIntermediateStorage, true); } catch (OutOfDiskSpaceException) { trasaction.Rollback(); throw; } catch (Exception) { trasaction.Rollback(); throw; } finally { if (con != null) { con.Dispose(); } } }
private void CreateRenameActions(SyncAction x, SyncAction y, IList <SyncAction> actions) { // remove create and delete actions from global action list // and replace it with rename action actions.Remove(x); actions.Remove(y); // Identify which actions is create/delete SyncAction createAction = (x.ChangeType == ChangeType.NEWLY_CREATED) ? x : y; SyncAction deleteAction = (x.ChangeType == ChangeType.DELETED) ? x : y; actions.Add(new RenameAction(0, x.SourceID, createAction.RelativeFilePath, deleteAction.RelativeFilePath, x.FileHash)); }
public bool Delete(SyncAction action, SqliteConnection con) { using (SqliteCommand cmd = con.CreateCommand()) { cmd.CommandText = "DELETE FROM " + Configuration.TBL_ACTION + " WHERE " + Configuration.COL_ACTION_ID + " = @id"; cmd.Parameters.Add(new SqliteParameter("@id", DbType.Int32) { Value = action.ActionId }); cmd.ExecuteNonQuery(); return(true); } }
public bool Add(SyncAction action, SqliteConnection con) { switch (action.ChangeType) { case ChangeType.DELETED: return InsertDeleteAction((DeleteAction)action); case ChangeType.NEWLY_CREATED: return InsertCreateAction((CreateAction)action, con); case ChangeType.RENAMED: return InsertRenameAction((RenameAction)action); default: // Log error? Throw ex? return false; } }
public static void CopyToDirtyFolderAndUpdateActionTable(SyncAction 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)); if (!Directory.Exists(job.IntermediaryStorage.DirtyFolderPath)) Directory.CreateDirectory(job.IntermediaryStorage.DirtyFolderPath); // TODO: make it atomic?? string absolutePathInSyncSource = job.SyncSource.Path + action.RelativeFilePath; string absolutePathInImediateStorage = job.IntermediaryStorage.DirtyFolderPath + action.RelativeFilePath; var db = new SQLiteAccess(Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME),true); var con = db.NewSQLiteConnection(); if (con == null) throw new DatabaseException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME))); var transaction = (SqliteTransaction)con.BeginTransaction(); try { var actProvider = (SQLiteSyncActionsProvider)SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path); actProvider.Add(action, con); if (!FileUtils.Copy(absolutePathInSyncSource, absolutePathInImediateStorage, true)) throw new Exception(String.Format(m_ResourceManager.GetString("err_cannotCopyFile"), absolutePathInSyncSource)); transaction.Commit(); } catch (OutOfDiskSpaceException) { transaction.Rollback(); throw; } catch (Exception) { transaction.Rollback(); throw; } finally { if (con != null) con.Dispose(); } }
public override bool Add(SyncAction action) { switch (action.ChangeType) { case ChangeType.DELETED: return(InsertDeleteAction((DeleteAction)action)); case ChangeType.NEWLY_CREATED: return(InsertCreateAction((CreateAction)action)); case ChangeType.RENAMED: return(InsertRenameAction((RenameAction)action)); default: // Log error? Throw ex? return(false); } }
public override bool Delete(SyncAction action) { 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 = "DELETE FROM " + Configuration.TBL_ACTION + " WHERE " + Configuration.COL_ACTION_ID + " = @id"; SqliteParameterCollection paramList = new SqliteParameterCollection(); paramList.Add(new SqliteParameter("@id", DbType.Int32) { Value = action.ActionId }); db.ExecuteNonQuery(cmdText, paramList); } return(true); }
public static void UpdateTableAction(SyncAction action, SyncJob job) { var actProvider = (SQLiteSyncActionsProvider)SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path); actProvider.Add(action); }
public static void DuplicateRenameInSyncFolderAndUpdateActionTable(SyncAction 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 absolutePathInIntermediateStorage = job.IntermediaryStorage.DirtyFolderPath + action.RelativeFilePath; string absolutePathInSyncSource = 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 trasaction = (SqliteTransaction)con.BeginTransaction(); try { SQLiteSyncActionsProvider actProvider = (SQLiteSyncActionsProvider)SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path); actProvider.Delete(action, con); if (!Files.FileUtils.DuplicateRename(absolutePathInSyncSource, absolutePathInSyncSource) || !Files.FileUtils.Copy(absolutePathInIntermediateStorage, absolutePathInSyncSource, true)) throw new Exception(String.Format(m_ResourceManager.GetString("err_cannotCopyFile"), absolutePathInIntermediateStorage)); trasaction.Commit(); Files.FileUtils.DeleteFileAndFolderIfEmpty(job.IntermediaryStorage.DirtyFolderPath, absolutePathInIntermediateStorage, true); } catch (OutOfDiskSpaceException) { trasaction.Rollback(); throw; } catch (Exception) { trasaction.Rollback(); throw; } finally { if (con != null) con.Dispose(); } }
public static void UpdateTableAction(SyncAction action, SyncJob job) { var actProvider = (SQLiteSyncActionsProvider)SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path); actProvider.Add(action); }
/// <summary> /// Adds a SyncAction. /// </summary> /// <param name="action">SyncAction to be added</param> /// <returns>true if successfully added.</returns> public abstract bool Add(SyncAction action);
/// <summary> /// Adds a SyncAction. /// </summary> /// <param name="action">SyncAction to be added</param> /// <returns>true if successfully added.</returns> public abstract bool Add(SyncAction action);
private void CreateRenameActions(SyncAction x, SyncAction y, IList<SyncAction> actions) { // remove create and delete actions from global action list // and replace it with rename action actions.Remove(x); actions.Remove(y); // Identify which actions is create/delete SyncAction createAction = (x.ChangeType == ChangeType.NEWLY_CREATED) ? x : y; SyncAction deleteAction = (x.ChangeType == ChangeType.DELETED) ? x : y; actions.Add(new RenameAction(0, x.SourceID, createAction.RelativeFilePath, deleteAction.RelativeFilePath, x.FileHash)); }
public bool Delete(SyncAction action, SqliteConnection con) { using (SqliteCommand cmd = con.CreateCommand()) { cmd.CommandText = "DELETE FROM " + Configuration.TBL_ACTION + " WHERE " + Configuration.COL_ACTION_ID + " = @id"; cmd.Parameters.Add(new SqliteParameter("@id", DbType.Int32) { Value = action.ActionId }); cmd.ExecuteNonQuery(); return true; } }
public override bool Delete(SyncAction action) { 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 = "DELETE FROM " + Configuration.TBL_ACTION + " WHERE " + Configuration.COL_ACTION_ID + " = @id"; SqliteParameterCollection paramList = new SqliteParameterCollection(); paramList.Add(new SqliteParameter("@id", DbType.Int32) { Value = action.ActionId }); db.ExecuteNonQuery(cmdText, paramList); } return true; }
/// <summary> /// Delete saved actions with the same ActionID as action argument. /// </summary> /// <param name="action">Saved actions which has the same ActionID as this action will be deleted.</param> /// <returns>true if successfully deleted.</returns> public abstract bool Delete(SyncAction action);
public static void DeleteFromActionTable(SyncAction action, SyncJob job) { SyncActionsProvider actProvider = SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path); actProvider.Delete(action); }
/// <summary> /// Delete saved actions with the same ActionID as action argument. /// </summary> /// <param name="action">Saved actions which has the same ActionID as this action will be deleted.</param> /// <returns>true if successfully deleted.</returns> public abstract bool Delete(SyncAction action);
public static void DeleteFromActionTable(SyncAction action, SyncJob job) { SyncActionsProvider actProvider = SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path); actProvider.Delete(action); }