Пример #1
0
        /// <summary>
        /// Update details of a sync source
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public override bool Update(SyncSource source)
        {
            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 = "UPDATE " + Configuration.TBL_DATASOURCE_INFO +
                                 " SET " + Configuration.COL_SOURCE_ABSOLUTE_PATH + " = @path WHERE "
                                 + Configuration.COL_SOURCE_ID + " = @id";

                SqliteParameterCollection paramList = new SqliteParameterCollection
                {
                    new SqliteParameter("@id", DbType.String)
                    {
                        Value = source.ID
                    },
                    new SqliteParameter("@path", DbType.String)
                    {
                        Value = source.Path
                    }
                };

                db.ExecuteNonQuery(cmdText, false);
            }
            return(true);
        }
Пример #2
0
        public static void CreateDataStore(string pathToJobFolder, SyncSource syncSource, IntermediaryStorage metaDataSource)
        {
            if (!Directory.Exists(pathToJobFolder)) Directory.CreateDirectory(pathToJobFolder);
            if (!Directory.Exists(metaDataSource.Path)) Directory.CreateDirectory(metaDataSource.Path);

            SqliteConnection con1 = null;
            SqliteConnection con2 = null;
            SqliteTransaction transaction1 = null;
            SqliteTransaction transaction2 = null;
            try
            {
                SQLiteAccess dbAccess1 = new SQLiteAccess(Path.Combine(pathToJobFolder, Configuration.DATABASE_NAME),true);
                SQLiteAccess dbAccess2 = new SQLiteAccess(Path.Combine (metaDataSource.Path, Configuration.DATABASE_NAME),true);

                con1 = dbAccess1.NewSQLiteConnection();
                con2 = dbAccess2.NewSQLiteConnection();

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

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

                transaction2 = (SqliteTransaction)con2.BeginTransaction();
                transaction1 = (SqliteTransaction)con1.BeginTransaction();

                //Create schema for source info table in job folder
                SQLiteSyncSourceProvider.CreateSchema(con1);

                //Create schema for profile table in job folder
                SQLiteSyncJobManager.CreateSchema(con1);

                //create schema for source info table in intermediate storage folder
                SQLiteSyncSourceProvider.CreateSchema(con2);

                //create schema for metadata table in intermediate storage folder
                SQLiteMetaDataProvider mdProvider = (SQLiteMetaDataProvider)SyncClient.GetMetaDataProvider(metaDataSource.Path, Configuration.DATABASE_NAME);
                mdProvider.CreateSchema(con2);

                //create schema for action table in intermediate storage folder
                SQLiteSyncActionsProvider actionProvider = (SQLiteSyncActionsProvider)SyncClient.GetSyncActionsProvider(metaDataSource.Path);
                actionProvider.CreateSchema(con2);

                transaction2.Commit();
                transaction1.Commit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (transaction2 != null) transaction2.Rollback();
                if (transaction1 != null) transaction1.Rollback();
                throw new DatabaseException(m_ResourceManager.GetString("err_databaseException"));
            }
            finally
            {
                if (con1 != null) con1.Dispose();
                if (con2 != null) con2.Dispose();
            }
        }
Пример #3
0
        public SyncJob(string id, string name, SyncSource syncSource, IntermediaryStorage iStorage)
        {
            this._jobId      = id;
            this.Name        = name;
            this._syncSource = syncSource;
            this._iStorage   = iStorage;

            //this._syncSourceWatcher = new FileSystemWatcher(syncSource.Path);
            //this._syncIntermediateWatcher = new FileSystemWatcher(iStorage.Path);
        }
Пример #4
0
        public SyncJob(string id, string name, SyncSource syncSource, IntermediaryStorage iStorage)
        {
            this._jobId = id;
            this.Name = name;
            this._syncSource = syncSource;
            this._iStorage = iStorage;

            //this._syncSourceWatcher = new FileSystemWatcher(syncSource.Path);
            //this._syncIntermediateWatcher = new FileSystemWatcher(iStorage.Path);
        }
Пример #5
0
 /// <summary>
 /// This method takes in SQLiteConnection object as a parameter
 /// </summary>
 /// <param name="s"></param>
 /// <param name="con"></param>
 /// <returns></returns>
 public static bool Add(SyncSource s, SqliteConnection con)
 {
     using (SqliteCommand cmd = con.CreateCommand())
      {
          cmd.CommandText = "INSERT INTO " + Configuration.TBL_DATASOURCE_INFO +
                          "(" + Configuration.COL_SOURCE_ID + "," + Configuration.COL_SOURCE_ABSOLUTE_PATH +
                          ") VALUES (@id, @path)";
          cmd.Parameters.Add(new SqliteParameter("@id", DbType.String) { Value = s.ID });
          cmd.Parameters.Add(new SqliteParameter("@path", DbType.String) { Value = s.Path });
          cmd.ExecuteNonQuery();
      }
      return true;
 }
Пример #6
0
 /// <summary>
 /// Update details of sync source
 /// Pass SQLiteConnection object to make atomic action
 /// </summary>
 /// <param name="source"></param>
 /// <param name="con"></param>
 /// <returns></returns>
 public static bool Update(SyncSource source, SqliteConnection con )
 {
     using (SqliteCommand cmd = con.CreateCommand())
     {
         cmd.CommandText = "UPDATE " + Configuration.TBL_DATASOURCE_INFO +
                 " SET " + Configuration.COL_SOURCE_ABSOLUTE_PATH + " = @path WHERE "
                 + Configuration.COL_SOURCE_ID + " = @id";
         cmd.Parameters.Add(new SqliteParameter("@id", DbType.String) { Value = source.ID });
         cmd.Parameters.Add(new SqliteParameter("@path", DbType.String) { Value = source.Path });
         cmd.ExecuteNonQuery();
         return true;
     }
 }
Пример #7
0
        public override IList <SyncJob> LoadAllJobs()
        {
            IList <SyncJob> jobs = new List <SyncJob>();

            // Note: The SQL depends on other tables as well which might not be created.
            // So empty SyncJob list should be returned if there is an exception

            try
            {
                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)));
                    }

                    using (SqliteCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = "SELECT * FROM " + SYNCJOB_TABLE +
                                          " p, " + DATASOURCE_INFO_TABLE +
                                          " d WHERE p" + "." + COL_SYNC_SOURCE_ID + " = d" + "." + COL_SOURCE_ID;

                        using (SqliteDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                SyncSource          source   = new SyncSource((string)reader[COL_SYNC_SOURCE_ID], (string)reader[COL_SOURCE_ABS_PATH]);
                                IntermediaryStorage mdSource = new IntermediaryStorage((string)reader[COL_METADATA_SOURCE_LOCATION]);
                                SyncJob             p        = new SyncJob((string)reader[COL_SYNCJOB_ID],
                                                                           (string)reader[COL_SYNCJOB_NAME], source, mdSource);
                                jobs.Add(p);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                // Log error?
            }

            return(jobs);
        }
Пример #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="jobName"></param>
        /// <param name="absoluteSyncPath"></param>
        /// <param name="absoluteIntermediatePath"></param>
        /// <returns></returns>
        /// <exception cref="SyncJobNameExistException">if syncjob name already exists.</exception>
        public override SyncJob CreateSyncJob(string jobName, string absoluteSyncPath, string absoluteIntermediatePath)
        {
            SyncSource          syncSource = new SyncSource(System.Guid.NewGuid().ToString(), absoluteSyncPath);
            IntermediaryStorage iStorage   = new IntermediaryStorage(absoluteIntermediatePath);
            SyncJob             job        = new SyncJob(System.Guid.NewGuid().ToString(),
                                                         jobName, syncSource, iStorage);

            CreateDataStore(this.StoragePath, syncSource, iStorage);

            // Returns job if it is successfully added.
            if (Add(job))
            {
                return(job);
            }
            else
            {
                return(null);
            }
        }
Пример #9
0
 /// <summary>
 /// This method takes in SQLiteConnection object as a parameter
 /// </summary>
 /// <param name="s"></param>
 /// <param name="con"></param>
 /// <returns></returns>
 public static bool Add(SyncSource s, SqliteConnection con)
 {
     using (SqliteCommand cmd = con.CreateCommand())
     {
         cmd.CommandText = "INSERT INTO " + Configuration.TBL_DATASOURCE_INFO +
                           "(" + Configuration.COL_SOURCE_ID + "," + Configuration.COL_SOURCE_ABSOLUTE_PATH +
                           ") VALUES (@id, @path)";
         cmd.Parameters.Add(new SqliteParameter("@id", DbType.String)
         {
             Value = s.ID
         });
         cmd.Parameters.Add(new SqliteParameter("@path", DbType.String)
         {
             Value = s.Path
         });
         cmd.ExecuteNonQuery();
     }
     return(true);
 }
Пример #10
0
 /// <summary>
 /// Update details of sync source
 /// Pass SQLiteConnection object to make atomic action
 /// </summary>
 /// <param name="source"></param>
 /// <param name="con"></param>
 /// <returns></returns>
 public static bool Update(SyncSource source, SqliteConnection con)
 {
     using (SqliteCommand cmd = con.CreateCommand())
     {
         cmd.CommandText = "UPDATE " + Configuration.TBL_DATASOURCE_INFO +
                           " SET " + Configuration.COL_SOURCE_ABSOLUTE_PATH + " = @path WHERE "
                           + Configuration.COL_SOURCE_ID + " = @id";
         cmd.Parameters.Add(new SqliteParameter("@id", DbType.String)
         {
             Value = source.ID
         });
         cmd.Parameters.Add(new SqliteParameter("@path", DbType.String)
         {
             Value = source.Path
         });
         cmd.ExecuteNonQuery();
         return(true);
     }
 }
Пример #11
0
        public override SyncJob Load(string jobName)
        {
            SyncJob p = null;

            SQLiteAccess db = new SQLiteAccess(Path.Combine(this.StoragePath, 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 " + SYNCJOB_TABLE +
                                 " p, " + DATASOURCE_INFO_TABLE +
                                 " d WHERE p" + "." + COL_SYNC_SOURCE_ID + " = d" + "." + COL_SOURCE_ID +
                                 " AND " + COL_SYNCJOB_NAME + " = @pname";


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

                db.ExecuteReader(cmdText, paramList, reader =>
                {
                    // TODO: constructor of Profile takes in more arguments to remove dependency on IntermediaryStorage and SyncSource class.
                    SyncSource source            = new SyncSource((string)reader[COL_SYNC_SOURCE_ID], (string)reader[COL_SOURCE_ABS_PATH]);
                    IntermediaryStorage mdSource = new IntermediaryStorage((string)reader[COL_METADATA_SOURCE_LOCATION]);

                    p = new SyncJob((string)reader[COL_SYNCJOB_ID], (string)reader[COL_SYNCJOB_NAME], source, mdSource);

                    return;
                }
                                 );
            }
            return(p);
        }
Пример #12
0
        /// <summary>
        /// Add sync source to database
        /// no transaction supports
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public override bool Add(SyncSource s)
        {
            if (GetSyncSourceCount() == 2)
            {
                throw new SyncSourcesNumberExceededException(m_ResourceManager.GetString("err_onlyTwoSyncSourceFolders"));
            }

            string insertText = "INSERT INTO " + Configuration.TBL_DATASOURCE_INFO +
                                "(" + Configuration.COL_SOURCE_ID + "," + Configuration.COL_SOURCE_ABSOLUTE_PATH +
                                ") VALUES (@id, @path)";

            SqliteParameterCollection paramList = new SqliteParameterCollection
            {
                new SqliteParameter("@id", DbType.String)
                {
                    Value = s.ID
                },
                new SqliteParameter("@path", DbType.String)
                {
                    Value = s.Path
                }
            };

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

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

                dbAccess.ExecuteNonQuery(insertText, paramList);
            }
            return(true);
        }
Пример #13
0
 /// <summary>
 /// Delete the sync source information in the intermediate storage
 /// </summary>
 /// <returns></returns>
 public abstract bool DeleteSyncSourceInIntermediateStorage(SyncSource source);
Пример #14
0
 /// <summary>
 /// Delets a SyncSource
 /// </summary>
 /// <param name="source">SyncSource to be deleted.</param>
 /// <returns>true if deletion is successful.</returns>
 public abstract bool Delete(SyncSource source);
Пример #15
0
 /// <summary>
 /// Update outdated SyncSource.
 /// </summary>
 /// <param name="source">Updated SyncSource.</param>
 /// <returns>true if update is successful.</returns>
 public abstract bool Update(SyncSource source);
Пример #16
0
 /// <summary>
 /// Adds a SyncSource.
 /// </summary>
 /// <param name="s">SyncSource to be added.</param>
 /// <returns>true if successfully added.</returns>
 public abstract bool Add(SyncSource s);
Пример #17
0
 /// <summary>
 /// Delets a SyncSource
 /// </summary>
 /// <param name="source">SyncSource to be deleted.</param>
 /// <returns>true if deletion is successful.</returns>
 public abstract bool Delete(SyncSource source);
Пример #18
0
        /// <summary>
        /// Add sync source to database
        /// no transaction supports
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public override bool Add(SyncSource s)
        {
            if (GetSyncSourceCount() == 2)
                throw new SyncSourcesNumberExceededException(m_ResourceManager.GetString("err_onlyTwoSyncSourceFolders"));

            string insertText =  "INSERT INTO " + Configuration.TBL_DATASOURCE_INFO +
                                 "(" + Configuration.COL_SOURCE_ID + "," + Configuration.COL_SOURCE_ABSOLUTE_PATH +
                                 ") VALUES (@id, @path)";

            SqliteParameterCollection paramList = new SqliteParameterCollection
                                                      {
                                                          new SqliteParameter("@id", DbType.String) {Value = s.ID},
                                                          new SqliteParameter("@path", DbType.String) {Value = s.Path}
                                                      };

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

                dbAccess.ExecuteNonQuery(insertText, paramList);
            }
            return true;
        }
Пример #19
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jobName"></param>
        /// <param name="absoluteSyncPath"></param>
        /// <param name="absoluteIntermediatePath"></param>
        /// <returns></returns>
        /// <exception cref="SyncJobNameExistException">if syncjob name already exists.</exception>
        public override SyncJob CreateSyncJob(string jobName, string absoluteSyncPath, string absoluteIntermediatePath)
        {
            SyncSource syncSource = new SyncSource(System.Guid.NewGuid().ToString(), absoluteSyncPath);
            IntermediaryStorage iStorage = new IntermediaryStorage(absoluteIntermediatePath);
            SyncJob job = new SyncJob(System.Guid.NewGuid().ToString(),
                jobName, syncSource, iStorage);

            CreateDataStore(this.StoragePath, syncSource, iStorage);

            // Returns job if it is successfully added.
            if (Add(job))
                return job;
            else
                return null;
        }
Пример #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="s">SyncSource associated with Sync Job conflicted name.</param>
 public SyncJobNameExistException(SyncSource s) : base()
 {
     this.s = s;
 }
Пример #21
0
 /// <summary>
 /// Update outdated SyncSource.
 /// </summary>
 /// <param name="source">Updated SyncSource.</param>
 /// <returns>true if update is successful.</returns>
 public abstract bool Update(SyncSource source);
Пример #22
0
 /// <summary>
 /// Delete the sync source information in the intermediate storage
 /// </summary>
 /// <returns></returns>
 public abstract bool DeleteSyncSourceInIntermediateStorage(SyncSource source);
Пример #23
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="s">SyncSource associated with Sync Job conflicted name.</param>
 public SyncJobNameExistException(SyncSource s)
     : base()
 {
     this.s = s;
 }
Пример #24
0
        public static void CreateDataStore(string pathToJobFolder, SyncSource syncSource, IntermediaryStorage metaDataSource)
        {
            if (!Directory.Exists(pathToJobFolder))
            {
                Directory.CreateDirectory(pathToJobFolder);
            }
            if (!Directory.Exists(metaDataSource.Path))
            {
                Directory.CreateDirectory(metaDataSource.Path);
            }

            SqliteConnection  con1         = null;
            SqliteConnection  con2         = null;
            SqliteTransaction transaction1 = null;
            SqliteTransaction transaction2 = null;

            try
            {
                SQLiteAccess dbAccess1 = new SQLiteAccess(Path.Combine(pathToJobFolder, Configuration.DATABASE_NAME), true);
                SQLiteAccess dbAccess2 = new SQLiteAccess(Path.Combine(metaDataSource.Path, Configuration.DATABASE_NAME), true);


                con1 = dbAccess1.NewSQLiteConnection();
                con2 = dbAccess2.NewSQLiteConnection();

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

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


                transaction2 = (SqliteTransaction)con2.BeginTransaction();
                transaction1 = (SqliteTransaction)con1.BeginTransaction();

                //Create schema for source info table in job folder
                SQLiteSyncSourceProvider.CreateSchema(con1);

                //Create schema for profile table in job folder
                SQLiteSyncJobManager.CreateSchema(con1);

                //create schema for source info table in intermediate storage folder
                SQLiteSyncSourceProvider.CreateSchema(con2);

                //create schema for metadata table in intermediate storage folder
                SQLiteMetaDataProvider mdProvider = (SQLiteMetaDataProvider)SyncClient.GetMetaDataProvider(metaDataSource.Path, Configuration.DATABASE_NAME);
                mdProvider.CreateSchema(con2);

                //create schema for action table in intermediate storage folder
                SQLiteSyncActionsProvider actionProvider = (SQLiteSyncActionsProvider)SyncClient.GetSyncActionsProvider(metaDataSource.Path);
                actionProvider.CreateSchema(con2);

                transaction2.Commit();
                transaction1.Commit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (transaction2 != null)
                {
                    transaction2.Rollback();
                }
                if (transaction1 != null)
                {
                    transaction1.Rollback();
                }
                throw new DatabaseException(m_ResourceManager.GetString("err_databaseException"));
            }
            finally
            {
                if (con1 != null)
                {
                    con1.Dispose();
                }
                if (con2 != null)
                {
                    con2.Dispose();
                }
            }
        }
Пример #25
0
        public override bool DeleteSyncSourceInIntermediateStorage(SyncSource source)
        {
            SQLiteAccess      db          = new SQLiteAccess(Path.Combine(this.StoragePath, Configuration.DATABASE_NAME), false);
            SqliteTransaction transaction = null;

            try
            {
                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)));
                    }
                    transaction = (SqliteTransaction)con.BeginTransaction();
                    using (SqliteCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = "DELETE FROM " + Configuration.TBL_METADATA +
                                          " WHERE " + Configuration.COL_SOURCE_ID + " = @id";
                        cmd.Parameters.Add(new SqliteParameter("@id", DbType.String)
                        {
                            Value = source.ID
                        });
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "DELETE FROM " + Configuration.TLB_FOLDERMETADATA +
                                          " WHERE " + Configuration.COL_SOURCE_ID + " = @id";
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add(new SqliteParameter("@id", DbType.String)
                        {
                            Value = source.ID
                        });
                        cmd.ExecuteNonQuery();

                        cmd.CommandText = "DELETE FROM " + Configuration.TBL_DATASOURCE_INFO +
                                          " WHERE " + Configuration.COL_SOURCE_ID + " = @id";
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add(new SqliteParameter("@id", DbType.String)
                        {
                            Value = source.ID
                        });
                        cmd.ExecuteNonQuery();

                        cmd.CommandText = "DELETE FROM " + Configuration.TBL_ACTION +
                                          " WHERE " + Configuration.COL_CHANGE_IN + " = @id";
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add(new SqliteParameter("@id", DbType.String)
                        {
                            Value = source.ID
                        });
                        cmd.ExecuteNonQuery();

                        transaction.Commit();
                    }
                }
            }
            catch (Exception)
            {
                if (transaction != null && transaction.Connection.State == ConnectionState.Open)
                {
                    transaction.Rollback();
                }
                throw;
            }
            return(true);
        }
Пример #26
0
 public SyncJob(string name , SyncSource syncSource, IntermediaryStorage iStorage)
     : this(System.Guid.NewGuid().ToString(), name, syncSource, iStorage)
 {
 }
Пример #27
0
 public SyncJob(string name, SyncSource syncSource, IntermediaryStorage iStorage)
     : this(System.Guid.NewGuid().ToString(), name, syncSource, iStorage)
 {
 }
Пример #28
0
 /// <summary>
 /// Adds a SyncSource.
 /// </summary>
 /// <param name="s">SyncSource to be added.</param>
 /// <returns>true if successfully added.</returns>
 public abstract bool Add(SyncSource s);
Пример #29
0
        public override SyncJob Load(string jobName)
        {
            SyncJob p = null;

            SQLiteAccess db = new SQLiteAccess(Path.Combine(this.StoragePath, 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 " + SYNCJOB_TABLE +
                                 " p, " + DATASOURCE_INFO_TABLE +
                                 " d WHERE p" + "." + COL_SYNC_SOURCE_ID + " = d" + "." + COL_SOURCE_ID +
                                 " AND " + COL_SYNCJOB_NAME + " = @pname";

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

                db.ExecuteReader(cmdText, paramList, reader =>
                {
                    // TODO: constructor of Profile takes in more arguments to remove dependency on IntermediaryStorage and SyncSource class.
                    SyncSource source = new SyncSource((string)reader[COL_SYNC_SOURCE_ID], (string)reader[COL_SOURCE_ABS_PATH]);
                    IntermediaryStorage mdSource = new IntermediaryStorage((string)reader[COL_METADATA_SOURCE_LOCATION]);

                    p = new SyncJob((string)reader[COL_SYNCJOB_ID], (string)reader[COL_SYNCJOB_NAME], source, mdSource);

                    return;
                }
                );

            }
            return p;
        }
Пример #30
0
        /// <summary>
        /// Update details of a sync source
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public override bool Update(SyncSource source)
        {
            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 = "UPDATE " + Configuration.TBL_DATASOURCE_INFO +
                        " SET " + Configuration.COL_SOURCE_ABSOLUTE_PATH + " = @path WHERE "
                        + Configuration.COL_SOURCE_ID + " = @id";

                SqliteParameterCollection paramList = new SqliteParameterCollection
                                                          {
                                                              new SqliteParameter("@id", DbType.String)
                                                                  {Value = source.ID},
                                                              new SqliteParameter("@path", DbType.String)
                                                                  {Value = source.Path}
                                                          };

                db.ExecuteNonQuery(cmdText, false);
            }
            return true;
        }
Пример #31
0
        public override IList<SyncJob> LoadAllJobs()
        {
            IList<SyncJob> jobs = new List<SyncJob>();

            // Note: The SQL depends on other tables as well which might not be created.
            // So empty SyncJob list should be returned if there is an exception

            try
            {
                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)));

                    using (SqliteCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = "SELECT * FROM " + SYNCJOB_TABLE +
                                     " p, " + DATASOURCE_INFO_TABLE +
                                     " d WHERE p" + "." + COL_SYNC_SOURCE_ID + " = d" + "." + COL_SOURCE_ID;

                        using (SqliteDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                SyncSource source = new SyncSource((string)reader[COL_SYNC_SOURCE_ID], (string)reader[COL_SOURCE_ABS_PATH]);
                                IntermediaryStorage mdSource = new IntermediaryStorage((string)reader[COL_METADATA_SOURCE_LOCATION]);
                                SyncJob p = new SyncJob((string)reader[COL_SYNCJOB_ID],
                                                        (string)reader[COL_SYNCJOB_NAME], source, mdSource);
                                jobs.Add(p);
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                // Log error?
            }

            return jobs;
        }
Пример #32
0
        public override bool DeleteSyncSourceInIntermediateStorage(SyncSource source)
        {
            SQLiteAccess db = new SQLiteAccess(Path.Combine(this.StoragePath, Configuration.DATABASE_NAME),false);
            SqliteTransaction transaction = null ;
            try
            {
                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)));
                    transaction = (SqliteTransaction)con.BeginTransaction();
                    using (SqliteCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = "DELETE FROM " + Configuration.TBL_METADATA +
                                            " WHERE " + Configuration.COL_SOURCE_ID + " = @id";
                        cmd.Parameters.Add(new SqliteParameter("@id", DbType.String) { Value = source.ID });
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "DELETE FROM " + Configuration.TLB_FOLDERMETADATA +
                                            " WHERE " + Configuration.COL_SOURCE_ID + " = @id";
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add(new SqliteParameter("@id", DbType.String) { Value = source.ID });
                        cmd.ExecuteNonQuery();

                        cmd.CommandText = "DELETE FROM " + Configuration.TBL_DATASOURCE_INFO +
                                            " WHERE " + Configuration.COL_SOURCE_ID + " = @id";
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add(new SqliteParameter("@id", DbType.String) { Value = source.ID });
                        cmd.ExecuteNonQuery();

                        cmd.CommandText = "DELETE FROM " + Configuration.TBL_ACTION +
                                            " WHERE " + Configuration.COL_CHANGE_IN + " = @id";
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add(new SqliteParameter("@id", DbType.String) { Value = source.ID });
                        cmd.ExecuteNonQuery();

                        transaction.Commit();
                    }
                }
            }
            catch (Exception)
            {
                if ( transaction != null && transaction.Connection.State == ConnectionState.Open)  transaction.Rollback();
                throw;
            }
            return true;
        }