示例#1
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();
            }
        }
示例#2
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);
        }
示例#3
0
文件: SyncJob.cs 项目: nydehi/onesync
        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 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);
        }
示例#5
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);
            }
        }
示例#6
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);
        }
示例#7
0
 public SyncJob(string name, SyncSource syncSource, IntermediaryStorage iStorage)
     : this(System.Guid.NewGuid().ToString(), name, syncSource, iStorage)
 {
 }
示例#8
0
文件: SyncJob.cs 项目: nydehi/onesync
 public SyncJob(string name , SyncSource syncSource, IntermediaryStorage iStorage)
     : this(System.Guid.NewGuid().ToString(), name, syncSource, iStorage)
 {
 }
示例#9
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;
        }
示例#10
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;
        }
示例#11
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;
        }
示例#12
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();
                }
            }
        }