Event arguments for a Flickr.OnUploadProgress event.
Inheritance: System.EventArgs
示例#1
0
        private string UploadData(Stream imageStream, string fileName, Uri uploadUri, Dictionary <string, string> parameters)
        {
            string boundary = "FLICKR_MIME_" + DateTime.Now.ToString("yyyyMMddhhmmss", System.Globalization.DateTimeFormatInfo.InvariantInfo);

            string authHeader = FlickrResponder.OAuthCalculateAuthHeader(parameters);

            byte[] dataBuffer = CreateUploadData(imageStream, fileName, parameters, boundary);

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uploadUri);

            //req.UserAgent = "Mozilla/4.0 FlickrNet API (compatible; MSIE 6.0; Windows NT 5.1)";
            req.Method = "POST";
            if (Proxy != null)
            {
                req.Proxy = Proxy;
            }
            req.Timeout     = HttpTimeout;
            req.ContentType = "multipart/form-data; boundary=" + boundary;
            //req.Expect = String.Empty;
            if (!String.IsNullOrEmpty(authHeader))
            {
                req.Headers["Authorization"] = authHeader;
            }

            req.ContentLength = dataBuffer.Length;

            using (Stream reqStream = req.GetRequestStream())
            {
                int bufferSize = 32 * 1024;
                if (dataBuffer.Length / 100 > bufferSize)
                {
                    bufferSize = bufferSize * 2;
                }

                int uploadedSoFar = 0;

                while (uploadedSoFar < dataBuffer.Length)
                {
                    reqStream.Write(dataBuffer, uploadedSoFar, Math.Min(bufferSize, dataBuffer.Length - uploadedSoFar));
                    uploadedSoFar += bufferSize;

                    if (OnUploadProgress != null)
                    {
                        UploadProgressEventArgs args = new UploadProgressEventArgs(uploadedSoFar, dataBuffer.Length);
                        OnUploadProgress(this, args);
                    }
                }
                reqStream.Close();
            }

            HttpWebResponse res = (HttpWebResponse)req.GetResponse();

            StreamReader sr = new StreamReader(res.GetResponseStream());
            string       s  = sr.ReadToEnd();

            sr.Close();
            return(s);
        }
示例#2
0
        public void OnUploadProgress(object sender, UploadProgressEventArgs e)
        {
            var message = string.Format("Upload Progress: {0} ({1}/{2} - {3}%)", DateTime.Now, e.BytesSent, e.TotalBytesToSend, e.ProcessPercentage);

            var executeFlickrUploaderWorkflowMessage = _asyncUploadSettings.Message;

            var flickrUploaderProgressMessage = new FlickrUploaderProgressMessage
            {
                CorrelationId = executeFlickrUploaderWorkflowMessage.CorrelationId,
                InputFilePath = executeFlickrUploaderWorkflowMessage.InputFilePath,
                Output = message
            };

            var bus = BusDriver.Instance.GetBus(FlickrUploaderService.BusName);
            bus.Publish(flickrUploaderProgressMessage);
        }
        private string UploadData(Stream imageStream, string fileName, Uri uploadUri, Dictionary<string, string> parameters)
        {
            string boundary = "FLICKR_MIME_" + DateTime.Now.ToString("yyyyMMddhhmmss", System.Globalization.DateTimeFormatInfo.InvariantInfo);

            string authHeader = FlickrResponder.OAuthCalculateAuthHeader(parameters);
            byte[] dataBuffer = CreateUploadData(imageStream, fileName, parameters, boundary);

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uploadUri);
            //req.UserAgent = "Mozilla/4.0 FlickrNet API (compatible; MSIE 6.0; Windows NT 5.1)";
            req.Method = "POST";
            if (Proxy != null) req.Proxy = Proxy;
            req.Timeout = HttpTimeout;
            req.ContentType = "multipart/form-data; boundary=" + boundary;
            //req.Expect = String.Empty;
            if (!String.IsNullOrEmpty(authHeader))
            {
                req.Headers["Authorization"] = authHeader;
            }

            req.ContentLength = dataBuffer.Length;

            using (Stream reqStream = req.GetRequestStream())
            {
                int bufferSize = 32 * 1024;
                if (dataBuffer.Length / 100 > bufferSize) bufferSize = bufferSize * 2;

                int uploadedSoFar = 0;

                while (uploadedSoFar < dataBuffer.Length)
                {
                    reqStream.Write(dataBuffer, uploadedSoFar, Math.Min(bufferSize, dataBuffer.Length - uploadedSoFar));
                    uploadedSoFar += bufferSize;

                    if (OnUploadProgress != null)
                    {
                        UploadProgressEventArgs args = new UploadProgressEventArgs(uploadedSoFar, dataBuffer.Length);
                        OnUploadProgress(this, args);
                    }
                }
                reqStream.Close();
            }

            HttpWebResponse res = (HttpWebResponse)req.GetResponse();

            StreamReader sr = new StreamReader(res.GetResponseStream());
            string s = sr.ReadToEnd();
            sr.Close();
            return s;
        }
示例#4
0
 private void Flickr_OnUploadProgress(object sender, FlickrNet.UploadProgressEventArgs e)
 {
     bgWorker.ReportProgress(e.ProcessPercentage);
 }
示例#5
0
        private void UploadDataAsync(Stream imageStream, string fileName, Uri uploadUri, Dictionary <string, string> parameters, Action <FlickrResult <string> > callback)
        {
            string boundary = "FLICKR_MIME_" + DateTime.Now.ToString("yyyyMMddhhmmss", System.Globalization.DateTimeFormatInfo.InvariantInfo);

            string authHeader = FlickrResponder.OAuthCalculateAuthHeader(parameters);

            byte[] dataBuffer = CreateUploadData(imageStream, fileName, parameters, boundary);

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uploadUri);

            req.Method      = "POST";
            req.ContentType = "multipart/form-data; boundary=" + boundary;
            if (!String.IsNullOrEmpty(authHeader))
            {
                req.Headers["Authorization"] = authHeader;
            }

            req.BeginGetRequestStream(
                r =>
            {
                Stream s       = req.EndGetRequestStream(r);
                int bufferSize = 1024 * 32;
                int soFar      = 0;
                while (soFar < dataBuffer.Length)
                {
                    if ((dataBuffer.Length - soFar) < bufferSize)
                    {
                        bufferSize = dataBuffer.Length - soFar;
                    }
                    s.Write(dataBuffer, soFar, bufferSize);
                    soFar += bufferSize;

                    if (OnUploadProgress != null)
                    {
                        UploadProgressEventArgs args = new UploadProgressEventArgs(soFar, dataBuffer.Length);
                        OnUploadProgress(this, args);
                    }
                }

                req.BeginGetResponse(
                    r2 =>
                {
                    FlickrResult <string> result = new FlickrResult <string>();

                    try
                    {
                        WebResponse res    = req.EndGetResponse(r2);
                        StreamReader sr    = new StreamReader(res.GetResponseStream());
                        string responseXml = sr.ReadToEnd();


                        XmlReaderSettings settings = new XmlReaderSettings();
                        settings.IgnoreWhitespace  = true;
                        XmlReader reader           = XmlReader.Create(new StringReader(responseXml), settings);

                        if (!reader.ReadToDescendant("rsp"))
                        {
                            throw new XmlException("Unable to find response element 'rsp' in Flickr response");
                        }
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.LocalName == "stat" && reader.Value == "fail")
                            {
                                throw ExceptionHandler.CreateResponseException(reader);
                            }
                            continue;
                        }

                        reader.MoveToElement();
                        reader.Read();

                        UnknownResponse t = new UnknownResponse();
                        ((IFlickrParsable)t).Load(reader);
                        result.Result   = t.GetElementValue("photoid");
                        result.HasError = false;
                    }
                    catch (Exception ex)
                    {
                        if (ex is WebException)
                        {
                            OAuthException oauthEx = new OAuthException(ex);
                            if (String.IsNullOrEmpty(oauthEx.Message))
                            {
                                result.Error = ex;
                            }
                            else
                            {
                                result.Error = oauthEx;
                            }
                        }
                        else
                        {
                            result.Error = ex;
                        }
                    }

                    callback(result);
                },
                    this);
            },
                this);
        }
示例#6
0
 private void HandleFlickrProgress(object sender, UploadProgressEventArgs args)
 {
     if (args.UploadComplete) {
         progress_dialog.Fraction = photo_index / (double) selection.Count;
         progress_dialog.ProgressText = String.Format (Catalog.GetString ("Waiting for response {0} of {1}"),
                                   photo_index, selection.Count);
     }
     progress_dialog.Fraction = (photo_index - 1.0 + (args.Bytes / (double) info.Length)) / (double) selection.Count;
 }
示例#7
0
        private void UploadDataAsync(Stream imageStream, string fileName, Uri uploadUri, Dictionary<string, string> parameters, Action<FlickrResult<string>> callback)
        {
            string boundary = "FLICKR_MIME_" + DateTime.Now.ToString("yyyyMMddhhmmss", System.Globalization.DateTimeFormatInfo.InvariantInfo);

            string authHeader = FlickrResponder.OAuthCalculateAuthHeader(parameters);

            byte[] dataBuffer = CreateUploadData(imageStream, fileName, parameters, boundary);

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uploadUri);
            req.Method = "POST";
            req.ContentType = "multipart/form-data; boundary=" + boundary;
            if (!String.IsNullOrEmpty(authHeader))
            {
                req.Headers["Authorization"] = authHeader;
            }

            req.BeginGetRequestStream(
                r =>
                {
                    Stream s = req.EndGetRequestStream(r);
                    int bufferSize = 1024 * 32;
                    int soFar = 0;
                    while (soFar < dataBuffer.Length)
                    {
                        s.Write(dataBuffer, soFar, Math.Min(bufferSize, dataBuffer.Length - soFar));
                        soFar += bufferSize;

                        if (OnUploadProgress != null)
                        {
                            UploadProgressEventArgs args = new UploadProgressEventArgs(soFar, dataBuffer.Length);
                            OnUploadProgress(this, args);
                        }
                    }
                    s.Close();

                    req.BeginGetResponse(
                        r2 =>
                        {
                            FlickrResult<string> result = new FlickrResult<string>();

                            try
                            {
                                WebResponse res = req.EndGetResponse(r2);
                                StreamReader sr = new StreamReader(res.GetResponseStream());
                                string responseXml = sr.ReadToEnd();
                                sr.Close();

                                XmlReaderSettings settings = new XmlReaderSettings();
                                settings.IgnoreWhitespace = true;
                                XmlReader reader = XmlReader.Create(new StringReader(responseXml), settings);

                                if (!reader.ReadToDescendant("rsp"))
                                {
                                    throw new XmlException("Unable to find response element 'rsp' in Flickr response");
                                }
                                while (reader.MoveToNextAttribute())
                                {
                                    if (reader.LocalName == "stat" && reader.Value == "fail")
                                        throw ExceptionHandler.CreateResponseException(reader);
                                    continue;
                                }

                                reader.MoveToElement();
                                reader.Read();

                                UnknownResponse t = new UnknownResponse();
                                ((IFlickrParsable)t).Load(reader);
                                result.Result = t.GetElementValue("photoid");
                                result.HasError = false;
                            }
                            catch (Exception ex)
                            {
                                if (ex is WebException)
                                {
                                    OAuthException oauthEx = new OAuthException(ex);
                                    if (String.IsNullOrEmpty(oauthEx.Message))
                                        result.Error = ex;
                                    else
                                        result.Error = oauthEx;
                                }
                                else
                                {
                                    result.Error = ex;
                                }
                            }

                            callback(result);

                        },
                        this);
                },
                this);
        }
示例#8
0
 // Fonction appelée lors de la progression de l'envoi d'une photo
 private void flickrProgressionEnvoiPhoto(object sender, UploadProgressEventArgs progression)
 {
     // Change la valeur de la barre de progression
     valProgression = progression.ProcessPercentage;
 }
示例#9
0
 private void OnUploadProgress(object sender, FlickrNet.UploadProgressEventArgs e)
 {
     UploadProgress.Value = e.ProcessPercentage;
 }
示例#10
0
 private void Flickr_OnUploadProgress(object sender, UploadProgressEventArgs e)
 {
     if (progress != null)
         progress(e.Bytes);
 }