Пример #1
0
        internal Upload(FileLaserUploaderService main, string filePath)
        {
            _errors = new Dictionary<string, string>()
            {
                {"disklimit", "Over storage limit"},
                {"oversized", "File is too big"},
                {"saveerror", "Couldn't save file"},
            };

            _uploadId = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());

            InitialWait = 3;
            MinBufferSize = 1024 * 5; //5kb
            MaxBufferSize = 1024 * 1024 * 20; //20mb
            BufferSize = 1024 * 25; //25kb
            DesiredInterval = 2;
            IntervalMargin = 0.5; //%
            AverageOver = 5;
            ResizeBufferAfter = 5; //must be equal to or greater than AverageOver

            _service = main;

            FullPath = filePath;
            FileName = Path.GetFileName(FullPath);

            _fs = File.OpenRead(FullPath);

            Debug.WriteLine("{0}: Uploading {1} ({2:f2} kb)", _uploadId, FileName, Size / 1024);
            Debug.WriteLine("{0}: Initial buffer size = {1} bytes", _uploadId, BufferSize);
            Debug.WriteLine("{0}: Initial wait before speed is tracked is {1} seconds", _uploadId, InitialWait);
            Debug.WriteLine("{0}: After initial wait, buffer size will be reevaluated every {1} writes", _uploadId, ResizeBufferAfter);
            Debug.WriteLine("{0}: If writes are not occuring approx every {1} (margin of {2:P0}) seconds, the buffer will be resized to suit", _uploadId, DesiredInterval, IntervalMargin);

            lock (_service)
            {
                if (_service.Status != UploaderStatus.Authenticated)
                {
                    _service.StatusChanged += new EventHandler<UploaderStatusEventArgs>(UploaderStatusChanged);
                    return;
                }

            }

            StartUpload();
        }
        public UploaderViewModel()
        {
            Dispatcher = Dispatcher.CurrentDispatcher;

            Active = new ObservableCollection<UploadViewModel>();
            Complete = new ObservableCollection<UploadViewModel>();

            RegistryKey registry = Registry.CurrentUser.CreateSubKey(@"Software\Kwerty FileLaser Uploader");
            string username;
            byte[] passwordEnc;
            string proxy;

            using (registry)
            {
                FirstTime = (int)registry.GetValue("notfirsttime", 0) != 1 ? true : false;

                username = (string)registry.GetValue("username");
                passwordEnc = (byte[])registry.GetValue("password");
                proxy = (string)registry.GetValue("proxy");
            }

            string password = null;

            if (username != null && passwordEnc != null)
                password = UTF8Encoding.UTF8.GetString(ProtectedData.Unprotect(passwordEnc, null, DataProtectionScope.CurrentUser));

            UploaderService = new FileLaserUploaderService();
            UploaderService.StatusChanged += new EventHandler<UploaderStatusEventArgs>(UploaderStatusUpdated);
            UploaderService.UploadCreated += new EventHandler<UploadEventArgs>(UploadCreated);

            if (username != null)
            {
                SetProxy(proxy);
                SetUser(username, password);
                Authenticate();
            }
        }