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); }
private bool InsertDeleteAction(DeleteAction deleteAction) { 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_OLD_HASH + ") VALUES (@changeIn, @action, @oldPath, @oldHash)"; SqliteParameterCollection paramList = new SqliteParameterCollection();; paramList.Add(new SqliteParameter("@changeIn", DbType.String) { Value = deleteAction.SourceID }); paramList.Add(new SqliteParameter("@action", DbType.Int32) { Value = (int)deleteAction.ChangeType }); paramList.Add(new SqliteParameter("@oldPath", DbType.String) { Value = deleteAction.RelativeFilePath }); paramList.Add(new SqliteParameter("@oldHash", DbType.String) { Value = deleteAction.FileHash }); db.ExecuteNonQuery(cmdText, paramList); } return(true); }
/// <summary> /// Generates list of sync actions that will synchronize current PC /// and other PC based on the metadata. /// </summary> /// <returns>List of sync actions</returns> public IList <SyncAction> Generate(string sourceId, IList <FileMetaDataItem> leftOnly, IList <FileMetaDataItem> rightOnly, IList <FileMetaDataItem> both) { IList <SyncAction> actions = new List <SyncAction>(); /* Keep track of create and delete actions to detect rename */ var createActions = new List <SyncAction>(); var deleteActions = new List <SyncAction>(); //Get newly created items by comparing relative paths foreach (FileMetaDataItem item in leftOnly) { var createAction = new CreateAction(0, item.SourceId, item.RelativePath, item.HashCode); actions.Add(createAction); createActions.Add(createAction); } foreach (FileMetaDataItem item in rightOnly) { //the source id of this action must be source id of the folder where the item is deleted var deleteAction = new DeleteAction(0, sourceId, item.RelativePath, item.HashCode); actions.Add(deleteAction); deleteActions.Add(deleteAction); } foreach (FileMetaDataItem item in both) { var createAction = new CreateAction(0, item.SourceId, item.RelativePath, item.HashCode); actions.Add(createAction); } DetectRenameActions(actions, createActions, deleteActions); return(actions); }
/// <summary> /// Generates list of sync actions that will synchronize current PC /// and other PC based on the metadata. /// </summary> /// <returns>List of sync actions</returns> public IList<SyncAction> Generate(string sourceId, IList<FileMetaDataItem> leftOnly, IList<FileMetaDataItem> rightOnly, IList<FileMetaDataItem> both) { IList<SyncAction> actions = new List<SyncAction>(); /* Keep track of create and delete actions to detect rename */ var createActions = new List<SyncAction>(); var deleteActions = new List<SyncAction>(); //Get newly created items by comparing relative paths foreach (FileMetaDataItem item in leftOnly) { var createAction = new CreateAction(0, item.SourceId, item.RelativePath, item.HashCode); actions.Add(createAction); createActions.Add(createAction); } foreach (FileMetaDataItem item in rightOnly) { //the source id of this action must be source id of the folder where the item is deleted var deleteAction = new DeleteAction(0, sourceId, item.RelativePath, item.HashCode); actions.Add(deleteAction); deleteActions.Add(deleteAction); } foreach (FileMetaDataItem item in both) { var createAction = new CreateAction(0, item.SourceId, item.RelativePath, item.HashCode); actions.Add(createAction); } DetectRenameActions(actions, createActions, deleteActions); return actions; }
private bool InsertDeleteAction(DeleteAction deleteAction) { 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_OLD_HASH + ") VALUES (@changeIn, @action, @oldPath, @oldHash)"; SqliteParameterCollection paramList = new SqliteParameterCollection();; paramList.Add(new SqliteParameter("@changeIn", DbType.String) { Value = deleteAction.SourceID }); paramList.Add(new SqliteParameter("@action", DbType.Int32) { Value = (int)deleteAction.ChangeType }); paramList.Add(new SqliteParameter("@oldPath", DbType.String) { Value = deleteAction.RelativeFilePath }); paramList.Add(new SqliteParameter("@oldHash", DbType.String) { Value = deleteAction.FileHash }); db.ExecuteNonQuery(cmdText, paramList); } return true; }
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; }