Ejemplo n.º 1
0
 public FileUploader(SyncSetting syncSetting, ManualResetEvent doneEvent, SyncProgressPage syncProgressPage, int taskId)
 {
     this.syncSetting      = syncSetting;
     this.doneEvent        = doneEvent;
     this.syncProgressPage = syncProgressPage;
     this.taskId           = taskId;
     this.localHashDB      = syncProgressPage.LocalHashDB();
     this.syncLogDB        = syncProgressPage.SyncLogDB();
 }
Ejemplo n.º 2
0
 public FileUploader(SyncSetting syncSetting, ManualResetEvent doneEvent, SyncProgressPage syncProgressPage, int taskId)
 {
     this.syncSetting = syncSetting;
     this.doneEvent = doneEvent;
     this.syncProgressPage = syncProgressPage;
     this.taskId = taskId;
     this.localHashDB = syncProgressPage.LocalHashDB();
     this.syncLogDB = syncProgressPage.SyncLogDB();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// load sync settings, this method is called before the page loaded method
        /// </summary>
        /// <param name="syncSetting"></param>
        public void LoadSyncSetting(SyncSetting syncSetting)
        {
            if(syncSetting==null)
            {
                isLoadedFromRecord = false;
                this.syncSetting = new SyncSetting();
            }
            else
            {
                isLoadedFromRecord = true;
                this.syncSetting = syncSetting;
            }

            this.bucketManager = null;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// load sync settings from the database by job id
        /// </summary>
        /// <param name="syncId">job id</param>
        /// <returns>
        /// return null if not exist
        /// </returns>
        public static SyncSetting LoadSyncSettingByJobId(string syncId)
        {
            SyncSetting setting   = null;
            string      myDocPath = Environment.CurrentDirectory;
            string      jobsDb    = System.IO.Path.Combine(myDocPath, "qsunsync", "jobs.db");

            if (File.Exists(jobsDb))
            {
                string conStr = new SQLiteConnectionStringBuilder {
                    DataSource = jobsDb
                }.ToString();
                string query = "SELECT * FROM [sync_jobs]  WHERE [sync_id]=@sync_id";
                using (SQLiteConnection sqlCon = new SQLiteConnection(conStr))
                {
                    sqlCon.Open();
                    using (SQLiteCommand sqlCmd = new SQLiteCommand(sqlCon))
                    {
                        sqlCmd.CommandText = query;
                        sqlCmd.Parameters.Add("@sync_id", System.Data.DbType.String);
                        sqlCmd.Parameters["@sync_id"].Value = syncId;
                        using (SQLiteDataReader dr = sqlCmd.ExecuteReader())
                        {
                            if (dr.Read())
                            {
                                setting = new SyncSetting();
                                setting.SyncLocalDir         = Convert.ToString(dr["sync_local_dir"]);
                                setting.SyncTargetBucket     = Convert.ToString(dr["sync_target_bucket"]);
                                setting.FileType             = Convert.ToInt32(dr["file_type"]);
                                setting.CheckRemoteDuplicate = Convert.ToBoolean(dr["check_remote_duplicate"]);
                                setting.SyncPrefix           = Convert.ToString(dr["sync_prefix"]);
                                setting.CheckNewFiles        = Convert.ToBoolean(dr["check_new_files"]);
                                setting.IgnoreDir            = Convert.ToBoolean(dr["ignore_dir"]);
                                setting.SkipPrefixes         = Convert.ToString(dr["skip_prefixes"]);
                                setting.SkipSuffixes         = Convert.ToString(dr["skip_suffixes"]);
                                setting.SkipDir              = Convert.ToString(dr["skip_dir"]);
                                setting.OverwriteFile        = Convert.ToBoolean(dr["overwrite_file"]);
                                setting.DefaultChunkSize     = Convert.ToInt32(dr["default_chunk_size"]);
                                setting.ChunkUploadThreshold = Convert.ToInt32(dr["chunk_upload_threshold"]);
                                setting.SyncThreadCount      = Convert.ToInt32(dr["sync_thread_count"]);
                                setting.UploadEntryDomain    = Convert.ToInt32(dr["upload_entry_domain"]);
                            }
                        }
                    }
                }
            }
            return(setting);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// load sync settings from the database by job id
        /// </summary>
        /// <param name="jobId">job id</param>
        /// <returns>
        /// return null if not exist
        /// </returns>
        public static SyncSetting LoadSyncSettingByJobId(string jobId)
        {
            SyncSetting setting   = null;
            string      myDocPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string      jobsDb    = System.IO.Path.Combine(myDocPath, "qsunsync", "sync_jobs_v1.db");

            if (File.Exists(jobsDb))
            {
                string conStr = new SQLiteConnectionStringBuilder {
                    DataSource = jobsDb
                }.ToString();
                string query = "SELECT * FROM [sync_jobs]  WHERE [job_id]=@job_id";
                using (SQLiteConnection sqlCon = new SQLiteConnection(conStr))
                {
                    sqlCon.Open();
                    using (SQLiteCommand sqlCmd = new SQLiteCommand(sqlCon))
                    {
                        sqlCmd.CommandText = query;
                        sqlCmd.Parameters.Add("@job_id", System.Data.DbType.String);
                        sqlCmd.Parameters["@job_id"].Value = jobId;
                        using (SQLiteDataReader dr = sqlCmd.ExecuteReader())
                        {
                            if (dr.Read())
                            {
                                setting = new SyncSetting();
                                setting.LocalDirectory       = Convert.ToString(dr["local_directory"]);
                                setting.TargetBucket         = Convert.ToString(dr["target_bucket"]);
                                setting.TargetZoneID         = Convert.ToInt32(dr["target_zone_id"]);
                                setting.SyncPrefix           = Convert.ToString(dr["sync_prefix"]);
                                setting.SkipPrefixes         = Convert.ToString(dr["skip_prefixes"]);
                                setting.SkipSuffixes         = Convert.ToString(dr["skip_suffixes"]);
                                setting.CheckNewFiles        = Convert.ToBoolean(dr["check_new_files"]);
                                setting.FilenameKind         = Convert.ToInt32(dr["file_name_kind"]);
                                setting.OverwriteDuplicate   = Convert.ToBoolean(dr["overwrite_duplicate"]);
                                setting.DefaultChunkSize     = Convert.ToInt32(dr["default_chunk_size"]);
                                setting.ChunkUploadThreshold = Convert.ToInt32(dr["chunk_upload_threshold"]);
                                setting.SyncThreadCount      = Convert.ToInt32(dr["sync_thread_count"]);
                                setting.UploadFromCDN        = Convert.ToBoolean(dr["upload_from_cdn"]);
                            }
                        }
                    }
                }
            }
            return(setting);
        }
Ejemplo n.º 6
0
        public static void InsertRecord(string jobId, DateTime dateTime, SyncSetting syncSetting, string jobsDbPath)
        {
            string conStr = new SQLiteConnectionStringBuilder { DataSource = jobsDbPath }.ToString();
            string queryDelete = "DELETE FROM [sync_jobs] WHERE [job_id]=@job_id";
            string queryInsert = new StringBuilder().Append("INSERT INTO [sync_jobs] ([job_id], [date_time], [local_directory], [target_bucket], [target_zone_id],")
                .Append("[sync_prefix], [skip_prefixes], [skip_suffixes], [check_new_files], [use_short_filename], [overwrite_duplicate],")
                .Append("[default_chunk_size], [chunk_upload_threshold], [sync_thread_count], [upload_from_cdn])")
                .Append(" VALUES ( @job_id, @date_time, @local_directory, @target_bucket, @target_zone_id, @sync_prefix, ")
                .Append("@skip_prefixes, @skip_suffixes, @check_new_files, @use_short_filename, @overwrite_duplicate, ")
                .Append("@default_chunk_size, @chunk_upload_threshold, @sync_thread_count, @upload_from_cdn )").ToString();
            using (SQLiteConnection sqlCon = new SQLiteConnection(conStr))
            {
                sqlCon.Open();
                using (SQLiteTransaction sqlTrans = sqlCon.BeginTransaction())
                {
                    using (SQLiteCommand sqlCmd = new SQLiteCommand(sqlCon))
                    {
                        //do delete if exists
                        sqlCmd.CommandText = queryDelete;
                        sqlCmd.Parameters.Add("@job_id", System.Data.DbType.String);

                        sqlCmd.Parameters["@job_id"].Value = jobId;
                        sqlCmd.ExecuteNonQuery();

                        //do insert
                        sqlCmd.CommandText = queryInsert;
                        sqlCmd.Parameters.Add("@job_id", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@date_time", System.Data.DbType.DateTime);
                        sqlCmd.Parameters.Add("@local_directory", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@target_bucket", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@target_zone_id", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@sync_prefix", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@skip_prefixes", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@skip_suffixes", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@check_new_files",System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@use_short_filename", System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@overwrite_duplicate", System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@default_chunk_size", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@chunk_upload_threshold", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@sync_thread_count", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@upload_from_cdn", System.Data.DbType.Boolean);

                        sqlCmd.Parameters["@job_id"].Value = jobId;
                        sqlCmd.Parameters["@date_time"].Value = dateTime;
                        sqlCmd.Parameters["@local_directory"].Value = syncSetting.LocalDirectory;
                        sqlCmd.Parameters["@target_bucket"].Value = syncSetting.TargetBucket;
                        sqlCmd.Parameters["@target_zone_id"].Value = syncSetting.TargetZoneID;
                        sqlCmd.Parameters["@sync_prefix"].Value = syncSetting.SyncPrefix;
                        sqlCmd.Parameters["@skip_prefixes"].Value = syncSetting.SkipPrefixes;
                        sqlCmd.Parameters["@skip_suffixes"].Value = syncSetting.SkipSuffixes;
                        sqlCmd.Parameters["@check_new_files"].Value = syncSetting.CheckNewFiles;
                        sqlCmd.Parameters["@use_short_filename"].Value = syncSetting.UseShortFilename;
                        sqlCmd.Parameters["@overwrite_duplicate"].Value = syncSetting.OverwriteDuplicate;
                        sqlCmd.Parameters["@default_chunk_size"].Value = syncSetting.DefaultChunkSize;
                        sqlCmd.Parameters["@chunk_upload_threshold"].Value = syncSetting.ChunkUploadThreshold;
                        sqlCmd.Parameters["@sync_thread_count"].Value = syncSetting.SyncThreadCount;
                        sqlCmd.Parameters["@upload_from_cdn"].Value = syncSetting.UploadFromCDN;

                        sqlCmd.ExecuteNonQuery();
                    }

                    //commit
                    sqlTrans.Commit();
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// load sync settings from the database by job id
        /// </summary>
        /// <param name="jobId">job id</param>
        /// <returns>
        /// return null if not exist
        /// </returns>
        public static SyncSetting LoadSyncSettingByJobId(string jobId)
        {
            SyncSetting setting = null;
            string myDocPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string jobsDb = System.IO.Path.Combine(myDocPath, "qsunsync", "sync_jobs.db");

            if (File.Exists(jobsDb))
            {
                string conStr = new SQLiteConnectionStringBuilder { DataSource = jobsDb }.ToString();
                string query = "SELECT * FROM [sync_jobs]  WHERE [job_id]=@job_id";
                using (SQLiteConnection sqlCon = new SQLiteConnection(conStr))
                {
                    sqlCon.Open();
                    using (SQLiteCommand sqlCmd = new SQLiteCommand(sqlCon))
                    {
                        sqlCmd.CommandText = query;
                        sqlCmd.Parameters.Add("@job_id", System.Data.DbType.String);
                        sqlCmd.Parameters["@job_id"].Value = jobId;
                        using (SQLiteDataReader dr = sqlCmd.ExecuteReader())
                        {
                            if (dr.Read())
                            {
                                setting = new SyncSetting();
                                setting.LocalDirectory = Convert.ToString(dr["local_directory"]);
                                setting.TargetBucket = Convert.ToString(dr["target_bucket"]);
                                setting.TargetZoneID = Convert.ToInt32(dr["target_zone_id"]);
                                setting.SyncPrefix = Convert.ToString(dr["sync_prefix"]);
                                setting.SkipPrefixes = Convert.ToString(dr["skip_prefixes"]);
                                setting.SkipSuffixes = Convert.ToString(dr["skip_suffixes"]);
                                setting.CheckNewFiles = Convert.ToBoolean(dr["check_new_files"]);
                                setting.UseShortFilename = Convert.ToBoolean(dr["use_short_filename"]);
                                setting.OverwriteDuplicate = Convert.ToBoolean(dr["overwrite_duplicate"]);
                                setting.DefaultChunkSize = Convert.ToInt32(dr["default_chunk_size"]);
                                setting.ChunkUploadThreshold = Convert.ToInt32(dr["chunk_upload_threshold"]);
                                setting.SyncThreadCount = Convert.ToInt32(dr["sync_thread_count"]);
                                setting.UploadFromCDN = Convert.ToBoolean(dr["upload_from_cdn"]);
                            }
                        }
                    }
                }
            }
            return setting;
        }
Ejemplo n.º 8
0
        public static void RecordSyncJob(string syncId, DateTime syncDateTime, SyncSetting syncSetting, string jobsDbPath)
        {
            string conStr = new SQLiteConnectionStringBuilder {
                DataSource = jobsDbPath
            }.ToString();
            string queryDelete = "DELETE FROM [sync_jobs] WHERE [sync_id]=@sync_id";
            string queryInsert = new StringBuilder().Append("INSERT INTO [sync_jobs] ([sync_id], [sync_local_dir], [sync_target_bucket], [check_remote_duplicate], ")
                                 .Append("[sync_prefix], [check_new_files], [ignore_dir], [skip_prefixes], [skip_suffixes], [overwrite_file], [default_chunk_size], [chunk_upload_threshold], [sync_thread_count], ")
                                 .Append("[upload_entry_domain], [sync_date_time]) VALUES ( @sync_id, @sync_local_dir, @sync_target_bucket, @check_remote_duplicate, @sync_prefix, @check_new_files, @ignore_dir, ")
                                 .Append("@skip_prefixes, @skip_suffixes, @overwrite_file, @default_chunk_size, @chunk_upload_threshold, @sync_thread_count, @upload_entry_domain, @sync_date_time)").ToString();

            using (SQLiteConnection sqlCon = new SQLiteConnection(conStr))
            {
                sqlCon.Open();
                using (SQLiteTransaction sqlTrans = sqlCon.BeginTransaction())
                {
                    using (SQLiteCommand sqlCmd = new SQLiteCommand(sqlCon))
                    {
                        //do delete if exists
                        sqlCmd.CommandText = queryDelete;
                        sqlCmd.Parameters.Add("@sync_id", System.Data.DbType.String);

                        sqlCmd.Parameters["@sync_id"].Value = syncId;
                        sqlCmd.ExecuteNonQuery();

                        //do insert
                        sqlCmd.CommandText = queryInsert;
                        sqlCmd.Parameters.Add("@sync_id", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@sync_local_dir", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@sync_target_bucket", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@check_remote_duplicate", System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@sync_prefix", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@check_new_files", System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@ignore_dir", System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@skip_prefixes", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@skip_suffixes", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@overwrite_file", System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@default_chunk_size", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@chunk_upload_threshold", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@sync_thread_count", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@upload_entry_domain", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@sync_date_time", System.Data.DbType.DateTime);

                        sqlCmd.Parameters["@sync_id"].Value                = syncId;
                        sqlCmd.Parameters["@sync_local_dir"].Value         = syncSetting.SyncLocalDir;
                        sqlCmd.Parameters["@sync_target_bucket"].Value     = syncSetting.SyncTargetBucket;
                        sqlCmd.Parameters["@check_remote_duplicate"].Value = syncSetting.CheckRemoteDuplicate;
                        sqlCmd.Parameters["@sync_prefix"].Value            = syncSetting.SyncPrefix;
                        sqlCmd.Parameters["@check_new_files"].Value        = syncSetting.CheckNewFiles;
                        sqlCmd.Parameters["@ignore_dir"].Value             = syncSetting.IgnoreDir;
                        sqlCmd.Parameters["@skip_prefixes"].Value          = syncSetting.SkipPrefixes;
                        sqlCmd.Parameters["@skip_suffixes"].Value          = syncSetting.SkipSuffixes;
                        sqlCmd.Parameters["@overwrite_file"].Value         = syncSetting.OverwriteFile;
                        sqlCmd.Parameters["@default_chunk_size"].Value     = syncSetting.DefaultChunkSize;
                        sqlCmd.Parameters["@chunk_upload_threshold"].Value = syncSetting.ChunkUploadThreshold;
                        sqlCmd.Parameters["@sync_thread_count"].Value      = syncSetting.SyncThreadCount;
                        sqlCmd.Parameters["@upload_entry_domain"].Value    = syncSetting.UploadEntryDomain;
                        sqlCmd.Parameters["@sync_date_time"].Value         = syncDateTime;

                        sqlCmd.ExecuteNonQuery();
                    }

                    //commit
                    sqlTrans.Commit();
                }
            }
        }
Ejemplo n.º 9
0
 //go to sync progress page
 internal void GotoSyncProgress(SyncSetting syncSetting)
 {
     this.MainHostFrame.Content = this.syncProgressPage;
     this.syncProgressPage.LoadSyncSetting(syncSetting);
 }
Ejemplo n.º 10
0
        //this is called before page loaded
        internal void LoadSyncSetting(SyncSetting syncSetting)
        {
            this.syncSetting = syncSetting;

            string jobName = string.Join("\t", new string[] { syncSetting.LocalDirectory, syncSetting.TargetBucket });
            this.jobId = Tools.md5Hash(jobName);

            string myDocPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            this.jobsDbPath = System.IO.Path.Combine(myDocPath, "qsunsync", "sync_jobs.db");
            this.jobLogDir = System.IO.Path.Combine(myDocPath, "qsunsync", "logs", jobId);

            string localHashDBDir = System.IO.Path.Combine(myDocPath, "qsunsync", "hashdb");
            if(!Directory.Exists(localHashDBDir))
            {
                Directory.CreateDirectory(localHashDBDir);
            }
            string bucketId = Tools.md5Hash(syncSetting.TargetBucket);
            this.localHashDBPath = System.IO.Path.Combine(localHashDBDir, bucketId + ".db");
            this.cacheDir = System.IO.Path.Combine(myDocPath, "qsunsync", "dircache");
            this.syncLogDir = System.IO.Path.Combine(myDocPath, "qsunsync", "synclog");
            this.syncLogDBPath = System.IO.Path.Combine(this.syncLogDir, jobId + ".log.db");

            string cacheId = jobId;
            this.cacheFilePathDone = System.IO.Path.Combine(cacheDir, cacheId + ".done");
            this.cacheFilePathTemp = System.IO.Path.Combine(cacheDir, cacheId + ".temp");
        }
Ejemplo n.º 11
0
        public static void InsertRecord(string jobId, DateTime dateTime, SyncSetting syncSetting, string jobsDbPath)
        {
            string conStr = new SQLiteConnectionStringBuilder {
                DataSource = jobsDbPath
            }.ToString();
            string queryDelete = "DELETE FROM [sync_jobs] WHERE [job_id]=@job_id";
            string queryInsert = new StringBuilder().Append("INSERT INTO [sync_jobs] ([job_id], [date_time], [local_directory], [target_bucket], [target_zone_id],")
                                 .Append("[sync_prefix], [skip_prefixes], [skip_suffixes], [check_new_files], [file_name_kind], [overwrite_duplicate],")
                                 .Append("[default_chunk_size], [chunk_upload_threshold], [sync_thread_count], [upload_from_cdn])")
                                 .Append(" VALUES ( @job_id, @date_time, @local_directory, @target_bucket, @target_zone_id, @sync_prefix, ")
                                 .Append("@skip_prefixes, @skip_suffixes, @check_new_files, @file_name_kind, @overwrite_duplicate, ")
                                 .Append("@default_chunk_size, @chunk_upload_threshold, @sync_thread_count, @upload_from_cdn )").ToString();

            using (SQLiteConnection sqlCon = new SQLiteConnection(conStr))
            {
                sqlCon.Open();
                using (SQLiteTransaction sqlTrans = sqlCon.BeginTransaction())
                {
                    using (SQLiteCommand sqlCmd = new SQLiteCommand(sqlCon))
                    {
                        //do delete if exists
                        sqlCmd.CommandText = queryDelete;
                        sqlCmd.Parameters.Add("@job_id", System.Data.DbType.String);

                        sqlCmd.Parameters["@job_id"].Value = jobId;
                        sqlCmd.ExecuteNonQuery();

                        //do insert
                        sqlCmd.CommandText = queryInsert;
                        sqlCmd.Parameters.Add("@job_id", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@date_time", System.Data.DbType.DateTime);
                        sqlCmd.Parameters.Add("@local_directory", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@target_bucket", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@target_zone_id", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@sync_prefix", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@skip_prefixes", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@skip_suffixes", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@check_new_files", System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@file_name_kind", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@overwrite_duplicate", System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@default_chunk_size", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@chunk_upload_threshold", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@sync_thread_count", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@upload_from_cdn", System.Data.DbType.Boolean);

                        sqlCmd.Parameters["@job_id"].Value                 = jobId;
                        sqlCmd.Parameters["@date_time"].Value              = dateTime;
                        sqlCmd.Parameters["@local_directory"].Value        = syncSetting.LocalDirectory;
                        sqlCmd.Parameters["@target_bucket"].Value          = syncSetting.TargetBucket;
                        sqlCmd.Parameters["@target_zone_id"].Value         = syncSetting.TargetZoneID;
                        sqlCmd.Parameters["@sync_prefix"].Value            = syncSetting.SyncPrefix;
                        sqlCmd.Parameters["@skip_prefixes"].Value          = syncSetting.SkipPrefixes;
                        sqlCmd.Parameters["@skip_suffixes"].Value          = syncSetting.SkipSuffixes;
                        sqlCmd.Parameters["@check_new_files"].Value        = syncSetting.CheckNewFiles;
                        sqlCmd.Parameters["@file_name_kind"].Value         = syncSetting.FilenameKind;
                        sqlCmd.Parameters["@overwrite_duplicate"].Value    = syncSetting.OverwriteDuplicate;
                        sqlCmd.Parameters["@default_chunk_size"].Value     = syncSetting.DefaultChunkSize;
                        sqlCmd.Parameters["@chunk_upload_threshold"].Value = syncSetting.ChunkUploadThreshold;
                        sqlCmd.Parameters["@sync_thread_count"].Value      = syncSetting.SyncThreadCount;
                        sqlCmd.Parameters["@upload_from_cdn"].Value        = syncSetting.UploadFromCDN;

                        sqlCmd.ExecuteNonQuery();
                    }

                    //commit
                    sqlTrans.Commit();
                }
            }
        }
Ejemplo n.º 12
0
        public static void RecordSyncJob(string syncId, DateTime syncDateTime, SyncSetting syncSetting, string jobsDbPath)
        {
            string conStr = new SQLiteConnectionStringBuilder { DataSource = jobsDbPath }.ToString();
            string queryDelete = "DELETE FROM [sync_jobs] WHERE [sync_id]=@sync_id";
            string queryInsert = new StringBuilder().Append("INSERT INTO [sync_jobs] ([sync_id], [sync_local_dir], [sync_target_bucket], [check_remote_duplicate], ")
                .Append("[sync_prefix], [check_new_files], [ignore_dir], [skip_prefixes], [skip_suffixes], [overwrite_file], [default_chunk_size], [chunk_upload_threshold], [sync_thread_count], ")
                .Append("[upload_entry_domain], [sync_date_time]) VALUES ( @sync_id, @sync_local_dir, @sync_target_bucket, @check_remote_duplicate, @sync_prefix, @check_new_files, @ignore_dir, ")
                .Append("@skip_prefixes, @skip_suffixes, @overwrite_file, @default_chunk_size, @chunk_upload_threshold, @sync_thread_count, @upload_entry_domain, @sync_date_time)").ToString();
            using (SQLiteConnection sqlCon = new SQLiteConnection(conStr))
            {
                sqlCon.Open();
                using (SQLiteTransaction sqlTrans = sqlCon.BeginTransaction())
                {
                    using (SQLiteCommand sqlCmd = new SQLiteCommand(sqlCon))
                    {
                        //do delete if exists
                        sqlCmd.CommandText = queryDelete;
                        sqlCmd.Parameters.Add("@sync_id", System.Data.DbType.String);

                        sqlCmd.Parameters["@sync_id"].Value = syncId;
                        sqlCmd.ExecuteNonQuery();

                        //do insert
                        sqlCmd.CommandText = queryInsert;
                        sqlCmd.Parameters.Add("@sync_id", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@sync_local_dir", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@sync_target_bucket", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@check_remote_duplicate",System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@sync_prefix", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@check_new_files",System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@ignore_dir", System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@skip_prefixes",System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@skip_suffixes", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@overwrite_file", System.Data.DbType.Boolean);
                        sqlCmd.Parameters.Add("@default_chunk_size", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@chunk_upload_threshold", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@sync_thread_count", System.Data.DbType.Int32);
                        sqlCmd.Parameters.Add("@upload_entry_domain", System.Data.DbType.String);
                        sqlCmd.Parameters.Add("@sync_date_time", System.Data.DbType.DateTime);

                        sqlCmd.Parameters["@sync_id"].Value = syncId;
                        sqlCmd.Parameters["@sync_local_dir"].Value = syncSetting.SyncLocalDir;
                        sqlCmd.Parameters["@sync_target_bucket"].Value = syncSetting.SyncTargetBucket;
                        sqlCmd.Parameters["@check_remote_duplicate"].Value = syncSetting.CheckRemoteDuplicate;
                        sqlCmd.Parameters["@sync_prefix"].Value = syncSetting.SyncPrefix;
                        sqlCmd.Parameters["@check_new_files"].Value = syncSetting.CheckNewFiles;
                        sqlCmd.Parameters["@ignore_dir"].Value = syncSetting.IgnoreDir;
                        sqlCmd.Parameters["@skip_prefixes"].Value = syncSetting.SkipPrefixes;
                        sqlCmd.Parameters["@skip_suffixes"].Value = syncSetting.SkipSuffixes;
                        sqlCmd.Parameters["@overwrite_file"].Value = syncSetting.OverwriteFile;
                        sqlCmd.Parameters["@default_chunk_size"].Value = syncSetting.DefaultChunkSize;
                        sqlCmd.Parameters["@chunk_upload_threshold"].Value = syncSetting.ChunkUploadThreshold;
                        sqlCmd.Parameters["@sync_thread_count"].Value = syncSetting.SyncThreadCount;
                        sqlCmd.Parameters["@upload_entry_domain"].Value = syncSetting.UploadEntryDomain;
                        sqlCmd.Parameters["@sync_date_time"].Value = syncDateTime;

                        sqlCmd.ExecuteNonQuery();
                    }

                    //commit
                    sqlTrans.Commit();
                }
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// load sync settings, this method is called before the page loaded method
 /// </summary>
 /// <param name="syncSetting"></param>
 public void LoadSyncSetting(SyncSetting syncSetting)
 {
     this.syncSetting = syncSetting;
     this.bucketManager = null;
 }
Ejemplo n.º 14
0
        private void StartSyncButton_EventHandler(object sender, RoutedEventArgs e)
        {
            this.SyncSettingTabControl.SelectedIndex = 0;
            //check ak & sk
            if (string.IsNullOrEmpty(this.account.AccessKey)
                || string.IsNullOrEmpty(this.account.SecretKey))
            {
                this.SettingsErrorTextBlock.Text = "请返回设置 AK & SK";
                return;
            }

            //save config to job record
            if (this.SyncLocalFolderTextBox.Text.Trim().Length == 0)
            {
                this.SettingsErrorTextBlock.Text = "请选择本地待同步目录";
                return;
            }

            if (this.SyncTargetBucketsComboBox.SelectedIndex == -1)
            {
                this.SettingsErrorTextBlock.Text = "请选择同步的目标空间";
                return;
            }

            string syncLocalDir = this.SyncLocalFolderTextBox.Text.Trim();
            if (!Directory.Exists(syncLocalDir))
            {
                //directory not found
                this.SyncSettingTabControl.SelectedIndex = 0;
                this.SettingsErrorTextBlock.Text = "本地待同步目录不存在";
                return;
            }

            string syncTargetBucket = this.SyncTargetBucketsComboBox.SelectedItem.ToString();
            StatResult statResult = this.bucketManager.stat(syncTargetBucket, "NONE_EXIST_KEY");
            if (statResult.ResponseInfo.isNetworkBroken())
            {
                this.SettingsErrorTextBlock.Text = "网络故障";
                return;
            }

            if (statResult.ResponseInfo.StatusCode == 401)
            {
                //ak & sk not right
                this.SettingsErrorTextBlock.Text = "AK 或 SK 不正确";
                return;
            }
            else if (statResult.ResponseInfo.StatusCode == 631)
            {
                //bucket not exist
                this.SettingsErrorTextBlock.Text = "指定空间不存在";
                return;
            }
            else if (statResult.ResponseInfo.StatusCode == 612
                || statResult.ResponseInfo.StatusCode == 200)
            {
                //file exists or not
                //ignore
            }
            else if (statResult.ResponseInfo.StatusCode == 400)
            {
                if (statResult.ResponseInfo.Error.Equals("incorrect zone"))
                {
                    this.SettingsErrorTextBlock.Text = "请选择正确的上传入口机房";
                }
                else
                {
                    this.SettingsErrorTextBlock.Text = statResult.ResponseInfo.Error;
                }
                return;
            }
            else
            {
                this.SettingsErrorTextBlock.Text = "未知错误,请联系七牛";
                Log.Error(string.Format("get buckets unknown error, {0}:{1}:{2}:{3}", statResult.ResponseInfo.StatusCode,
                       statResult.ResponseInfo.Error, statResult.ResponseInfo.ReqId, statResult.Response));
                return;
            }

            //set progress ak & sk
            SystemConfig.ACCESS_KEY = this.account.AccessKey;
            SystemConfig.SECRET_KEY = this.account.SecretKey;

            //optional settings
            SyncSetting syncSetting = new SyncSetting();
            syncSetting.SyncLocalDir = syncLocalDir;
            syncSetting.SyncTargetBucket = syncTargetBucket;
            syncSetting.CheckRemoteDuplicate = this.CheckRemoteDuplicateCheckBox.IsChecked.Value;
            syncSetting.SyncPrefix = this.PrefixTextBox.Text.Trim();
            syncSetting.CheckNewFiles = this.CheckNewFilesCheckBox.IsChecked.Value;
            syncSetting.IgnoreDir = this.IgnoreDirCheckBox.IsChecked.Value;
            syncSetting.SkipPrefixes = this.SkipPrefixesTextBox.Text.Trim();
            syncSetting.SkipSuffixes = this.SkipSuffixesTextBox.Text.Trim();
            syncSetting.OverwriteFile = this.OverwriteFileCheckBox.IsChecked.Value;
            syncSetting.SyncThreadCount = (int)this.ThreadCountSlider.Value;
            syncSetting.ChunkUploadThreshold = (int)this.ChunkUploadThresholdSlider.Value * 1024 * 1024;
            syncSetting.DefaultChunkSize = this.defaultChunkSize;
            syncSetting.UploadEntryDomain = this.uploadEntryDomain;

            this.mainWindow.GotoSyncProgress(syncSetting);
        }