Exemple #1
0
        private void uploader_ProgressChanged(ProgressManager progress)
        {
            if (progress != null)
            {
                Info.Progress = progress;

                if (threadWorker != null)
                {
                    threadWorker.InvokeAsync(OnUploadProgressChanged);
                }
                else
                {
                    OnUploadProgressChanged();
                }
            }
        }
Exemple #2
0
 protected void OnProgressChanged(ProgressManager progress)
 {
     if (ProgressChanged != null)
     {
         ProgressChanged(progress);
     }
 }
Exemple #3
0
        protected bool TransferData(Stream dataStream, Stream requestStream)
        {
            if (dataStream.CanSeek)
            {
                dataStream.Position = 0;
            }

            ProgressManager progress = new ProgressManager(dataStream.Length);
            int length = (int)Math.Min(BufferSize, dataStream.Length);
            byte[] buffer = new byte[length];
            int bytesRead;

            while (!StopUploadRequested && (bytesRead = dataStream.Read(buffer, 0, length)) > 0)
            {
                requestStream.Write(buffer, 0, bytesRead);

                if (AllowReportProgress && progress.UpdateProgress(bytesRead))
                {
                    OnProgressChanged(progress);
                }
            }

            return !StopUploadRequested;
        }
Exemple #4
0
 private void OnProgressChanged(ProgressManager progress)
 {
     if (ProgressChanged != null)
     {
         ProgressChanged(progress);
     }
 }
Exemple #5
0
        private void bw_AsyncUploadDoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                AsyncUploadHelper upload = (AsyncUploadHelper)e.Argument;

                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(upload.URL);
                request.Proxy = Options.ProxySettings;
                request.Method = WebRequestMethods.Ftp.UploadFile;
                request.Credentials = new NetworkCredential(Options.Account.Username, Options.Account.Password);
                request.KeepAlive = false;
                request.UsePassive = !Options.Account.IsActive;

                using (upload.Stream)
                using (Stream requestStream = request.GetRequestStream())
                {
                    ProgressManager progress = new ProgressManager(upload.Stream.Length);

                    byte[] buffer = new byte[BufferSize];
                    int bytesRead;

                    while ((bytesRead = upload.Stream.Read(buffer, 0, BufferSize)) > 0)
                    {
                        requestStream.Write(buffer, 0, bytesRead);
                        progress.UpdateProgress(bytesRead);
                        upload.BackgroundWorker.ReportProgress((int)progress.Percentage, progress);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugHelper.WriteException(ex);
            }
        }
Exemple #6
0
        public bool Upload(Stream stream, string url)
        {
            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(url);
                request.Proxy = Options.ProxySettings;
                request.Method = WebRequestMethods.Ftp.UploadFile;
                request.Credentials = new NetworkCredential(Options.Account.Username, Options.Account.Password);
                request.KeepAlive = false;
                request.UsePassive = !Options.Account.IsActive;

                using (stream)
                using (Stream requestStream = request.GetRequestStream())
                {
                    ProgressManager progress = new ProgressManager(stream.Length);

                    byte[] buffer = new byte[BufferSize];
                    int bytesRead;

                    while ((bytesRead = stream.Read(buffer, 0, BufferSize)) > 0)
                    {
                        requestStream.Write(buffer, 0, bytesRead);
                        progress.UpdateProgress(bytesRead);
                        OnProgressChanged(progress);
                    }
                }

                WriteOutput("Upload: " + url);
                return true;
            }
            catch (Exception ex)
            {
                WriteOutput(string.Format("Error: {0} - Upload: {1}", ex.Message, url));
            }
            return false;
        }
Exemple #7
0
        private void TranscodeFile(string key, UploadResult result)
        {
            Dictionary<string, string> args = new Dictionary<string, string>();
            if (NoResize) args.Add("noResize", "true");
            if (IgnoreExisting) args.Add("noMd5", "true");

            string url = CreateQuery("https://upload.gfycat.com/transcodeRelease/" + key, args);
            string transcodeJson = SendRequest(HttpMethod.GET, url);
            GfycatTranscodeResponse transcodeResponse = JsonConvert.DeserializeObject<GfycatTranscodeResponse>(transcodeJson);

            if (transcodeResponse.IsOk)
            {
                ProgressManager progress = new ProgressManager(10000);

                if (AllowReportProgress)
                {
                    OnProgressChanged(progress);
                }

                while (!StopUploadRequested)
                {
                    string statusJson = SendRequest(HttpMethod.GET, "https://upload.gfycat.com/status/" + key);
                    GfycatStatusResponse response = JsonConvert.DeserializeObject<GfycatStatusResponse>(statusJson);

                    if (response.Error != null)
                    {
                        result.Errors.Add(response.Error);
                        result.IsSuccess = false;
                        break;
                    }
                    else if (response.GfyName != null)
                    {
                        result.IsSuccess = true;
                        result.URL = "https://gfycat.com/" + response.GfyName;
                        break;
                    }

                    if (AllowReportProgress && progress.UpdateProgress((progress.Length - progress.Position) / response.Time))
                    {
                        OnProgressChanged(progress);
                    }

                    Thread.Sleep(100);
                }
            }
            else
            {
                result.Errors.Add(transcodeResponse.Error);
                result.IsSuccess = false;
            }
        }
Exemple #8
0
        private string Send(Stream stream, Dictionary<string, string> arguments)
        {
            client.Connect(url.DnsSafeHost, 80);

            using (NetworkStream networkStream = client.GetStream())
            {
                networkStream.Write(postMethod, 0, postMethod.Length);
                networkStream.Write(headerBytes, 0, headerBytes.Length);
                networkStream.Write(request, 0, request.Length);

                byte[] buffer = new byte[(int)Math.Min(4096, stream.Length)];

                ProgressManager progress = new ProgressManager();

                using (stream)
                {
                    int bytesRead = stream.Read(buffer, 0, buffer.Length);

                    while (bytesRead > 0)
                    {
                        networkStream.Write(buffer, 0, bytesRead);

                        //if (progress.ChangeProgress(stream)) uploader.OnProgressChanged(progress.Progress);

                        bytesRead = stream.Read(buffer, 0, buffer.Length);
                    }
                }

                networkStream.Write(requestEnd, 0, requestEnd.Length);

                using (StreamReader reader = new StreamReader(networkStream))
                    return reader.ReadToEnd();
            }
        }