Beispiel #1
0
        public SyncTracker(RemoteFileCacher remote_cacher, LocalFileCacher local_cacher, string remote_path, string local_path)
        {
            if (remote_cacher == null)
            {
                throw new ArgumentNullException("remote_cacher");
            }
            if (local_cacher == null)
            {
                throw new ArgumentNullException("local_cacher");
            }
            if (string.IsNullOrEmpty(remote_path))
            {
                throw new ArgumentNullException("remote_path");
            }
            if (string.IsNullOrEmpty(local_path))
            {
                throw new ArgumentNullException("local_path");
            }

            if (!File.Exists(local_path) && !Directory.Exists(local_path))
            {
                throw new ArgumentException("local path does not exists, check your path!");
            }

            _remote_cacher = remote_cacher;
            _local_cacher  = local_cacher;
            _remote_path   = remote_path;
            _local_path    = local_path;

            var hidden_path = Path.Combine(_local_path, _HIDDEN_TRACKER_DIR_NAME);
            var dir_info    = new DirectoryInfo(hidden_path);

            if (!dir_info.Exists)
            {
                dir_info.Create();
                dir_info.Attributes |= FileAttributes.Hidden;
            }
            var sql_path = Path.Combine(hidden_path, _HIDDEN_TRACKER_FILE_NAME);

            if (!File.Exists(sql_path))
            {
                File.Create(sql_path).Dispose();
            }

            _sql_lck = new object();
            _initialize_sql_tables();
        }
Beispiel #2
0
        public UploaderPool(RemoteFileCacher remote_cacher, LocalFileCacher local_cacher, int account_id, bool overwrite_file = false, GlobalUtil.KeyManager key_manager = null, bool encrypt_file = false)
        {
            if (remote_cacher == null)
            {
                throw new ArgumentNullException("remote_cacher");
            }
            if (local_cacher == null)
            {
                throw new ArgumentNullException("local_cacher");
            }
            _remote_cacher   = remote_cacher;
            _local_cacher    = local_cacher;
            _queue_data      = new Dictionary <int, Uploader>();
            _external_lock   = new object();
            _pool_size       = _DEFAULT_POOL_SIZE;
            _max_thread      = Uploader.DEFAULT_MAX_THREAD;
            _auto_start      = false;
            _allocated_index = 0;
            _enable_encrypt  = encrypt_file;
            _key_manager     = key_manager;

            _account_id = account_id;
            _overwrite  = overwrite_file;
        }
Beispiel #3
0
        public Uploader(LocalFileCacher local_cacher, RemoteFileCacher remote_cacher, string local_path, string remote_path, int account_id, bool overwriting_exist_file = false, int max_thread = DEFAULT_MAX_THREAD, int speed_limit = 0, KeyManager key_manager = null, bool enable_encryption = false)
        {
            if (local_cacher == null)
            {
                throw new ArgumentNullException("local_cacher");
            }
            if (remote_cacher == null)
            {
                throw new ArgumentNullException("remote_cacher");
            }
            if (string.IsNullOrEmpty(local_path))
            {
                throw new ArgumentNullException("local_path");
            }
            if (string.IsNullOrEmpty(remote_path))
            {
                throw new ArgumentNullException("remote_path");
            }
            if (remote_path.EndsWith("/"))
            {
                throw new ArgumentException("remote_path非法:/不能在路径结束");
            }
            if (speed_limit < 0)
            {
                throw new ArgumentOutOfRangeException("speed_limit");
            }
            _overwrite         = overwriting_exist_file;
            _local_cacher      = local_cacher;
            _remote_cacher     = remote_cacher;
            _local_path        = local_path;
            _remote_path       = remote_path;
            _speed_limit       = speed_limit;
            _key_manager       = key_manager;
            _enable_encryption = enable_encryption;

            var file_info = new FileInfo(_local_path);

            if (!file_info.Exists)
            {
                throw new ArgumentException("file not exists");
            }
            //file monitor
            _file_watcher                     = new FileSystemWatcher(file_info.Directory.FullName, file_info.Name);
            _file_watcher.Changed            += _on_file_changed;
            _file_watcher.Deleted            += _on_file_deleted;
            _file_watcher.EnableRaisingEvents = true;

            _external_lock    = new object();
            _thread_flag_lock = new object();
            _thread_data_lock = new object();

            _file_size    = file_info.Length;
            _max_thread   = max_thread;
            _slice_count  = (int)Math.Ceiling(_file_size * 1.0 / BaiduPCS.UPLOAD_SLICE_SIZE);
            _slice_seq    = new ConcurrentQueue <int>();
            _slice_result = new ConcurrentDictionary <int, string>();

            _selected_account_id = account_id;
            _upload_size_5s      = new LinkedList <long>();
            for (int i = 0; i < 6; i++)
            {
                _upload_size_5s.AddLast(0);
            }
            _monitor_thread_created = new ManualResetEventSlim();
            _file_io_response       = new ManualResetEventSlim();
            _monitor_thread_exited  = new ManualResetEventSlim();

            _local_cacher.LocalFileIOFinish += _on_file_io_completed;
            _local_cacher.LocalFileIOUpdate += _on_file_io_updated;
            _local_cacher.LocalFileIOAbort  += _on_file_io_aborted;

            _upload_thread_flag = _UPLOAD_THREAD_FLAG_READY;
        }