当前位置: 首页>>代码示例>>C#>>正文


C# IProgress.GetCanceled方法代码示例

本文整理汇总了C#中IProgress.GetCanceled方法的典型用法代码示例。如果您正苦于以下问题:C# IProgress.GetCanceled方法的具体用法?C# IProgress.GetCanceled怎么用?C# IProgress.GetCanceled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IProgress的用法示例。


在下文中一共展示了IProgress.GetCanceled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadFile

        private bool UploadFile(string strURL, string strFile, string strCompleteURI, IProgress pProgress)
        {
            VimeoLogger.Log("Vimeo::UploadFile");
             Debug.Assert(File.Exists(strFile));
             Debug.Assert(!String.IsNullOrWhiteSpace(strURL));

             m_strClipURI = null;

             FileInfo fi = new FileInfo(strFile);
             long lFileSize = fi.Length;

             FileStream fstream = File.OpenRead(strFile);

             long lChunkSize = m_lChunkSize;

             byte[] buffer = new byte[lChunkSize];
             long lStart = 0;
             while (true)
             {
            if (pProgress != null && pProgress.GetCanceled())
            {
               fstream.Close();
               return false;
            }

            long lEnd = Math.Min(lStart + lChunkSize, lFileSize);
            long lBytes = lEnd - lStart;

            HttpWebRequest request = WebRequest.CreateDefault(new Uri(strURL)) as HttpWebRequest;
            request.Method = @"PUT";
            request.Accept = @"application/vnd.vimeo.*+json; version=3.2";
            request.ContentType = @"video/mp4";
            request.Headers = new WebHeaderCollection()
            {
               {"Content-Range", String.Format("bytes {0}-{1}/{2}", lStart, lEnd, lFileSize)}
            };
            request.KeepAlive = false;

            try
            {
               {
                  long lRead = (long)fstream.Read(buffer, 0, (int)lBytes);
                  Debug.Assert(lRead == lBytes);
                  request.ContentLength = lRead;
                  Stream requestStream = request.GetRequestStream();
                  requestStream.Write(buffer, 0, (int)lRead);
                  requestStream.Close();
               }

               //Do call
               HttpWebResponse response = request.GetResponse() as HttpWebResponse;
               VimeoLogger.Log(response);

               HttpStatusCode status = response.StatusCode;
               //Successful uploads with have a HTTP 200 status code. A 501 error means you did not perform a PUT or the request was malformed.

               //Not sure exactly what to do if I get an error :(
               if (status != HttpStatusCode.OK)
                  return false;

               Stream responseStream = response.GetResponseStream();
               StreamReader r = new StreamReader(responseStream);
               string strResponse = r.ReadToEnd();
               VimeoLogger.Log("Vimeo::UploadFile; response: " + strResponse);
               r.Close();
               responseStream.Close();
               response.Close();

               if (pProgress != null)
               {
                  double dPercentage = lEnd * 100.0 / lFileSize;
                  pProgress.SetProgress(dPercentage);
               }

               lStart += lBytes;
               if (lEnd >= lFileSize)
                  break;
            }
            catch (WebException wex)
            {
               VimeoLogger.Log(wex);
               m_strErrorMessage = wex.Message;
               fstream.Close();
               return false;
            }
             }

             fstream.Close();

             //Verify the upload
             bool bOK = VerifyUpload(strURL);

             if (bOK)
             {
            bOK = CompleteUpload(strCompleteURI);
             }

             return bOK;
        }
开发者ID:TechSmith,项目名称:VimeoAPI,代码行数:99,代码来源:Vimeo.cs

示例2: Upload

        public bool Upload(string strFile, string strTitle, string strDescription, string strTags, Privacy ePrivacy, string strPassword, IProgress pProgress)
        {
            VimeoLogger.Log("Vimeo::Upload");
             Debug.Assert(File.Exists(strFile));

             Debug.Assert(!String.IsNullOrEmpty(m_strAccessToken));//Did you call ObtainAccessToken?
             if (String.IsNullOrEmpty(m_strAccessToken))
             {
            return false;
             }

             if (pProgress != null && pProgress.GetCanceled())
            return false;

             UploadTicketResponse ticket = GenerateUploadTicket();

             //Make sure ticket is good! :)
             if (ticket == null || String.IsNullOrWhiteSpace(ticket.ticket_id))
            return false;

             if (pProgress != null && pProgress.GetCanceled())
            return false;

             bool bOK = UploadFile(ticket.upload_link_secure, strFile, ticket.complete_uri, pProgress);

             if (pProgress != null && pProgress.GetCanceled())
            return false;

             if (bOK)
             {
            bOK = SetVideoInformation(m_strClipURI, strTitle, strDescription);
             }

             if (pProgress != null && pProgress.GetCanceled())
            return false;

             if( bOK )
             {
            bool bSetPrivacy = SetPrivacyInformation( m_strClipURI, ePrivacy, strPassword );
            if ( !bSetPrivacy )
            {
               //TODO: keep note; but not fail upload.
            }
             }

             if (pProgress != null && pProgress.GetCanceled())
            return false;

             if (bOK)
             {
            bOK = SetVideoTags(m_strClipURI, strTags);
             }

             if (pProgress != null && pProgress.GetCanceled())
            return false;

             return bOK;
        }
开发者ID:TechSmith,项目名称:VimeoAPI,代码行数:58,代码来源:Vimeo.cs


注:本文中的IProgress.GetCanceled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。