Ejemplo n.º 1
0
        private void HandleException(Exception ex)
        {
            Trace.WriteLine("Failed to upload video: " + ex);
            _status = VideoPublishStatus.Error;

            _message = Res.Get(StringId.YouTubeVideoError) + Environment.NewLine + Res.Get(StringId.VideoErrorTryAgain);
        }
Ejemplo n.º 2
0
 private void HandleWebException(WebException ex)
 {
     HttpRequestHelper.LogException(ex);
     _status = VideoPublishStatus.Error;
     if (ex.Status != WebExceptionStatus.ProtocolError)
     {
         _message = Res.Get(StringId.VideoNetworkError) + Environment.NewLine + Res.Get(StringId.VideoErrorTryAgain);
     }
     else
     {
         _message = Res.Get(StringId.YouTubeVideoError) + Environment.NewLine + Res.Get(StringId.VideoErrorTryAgain);
     }
 }
Ejemplo n.º 3
0
        public VideoSmartContentWaitOperation(ISynchronizeInvoke context, SmartContentOperationType checkType, IExtensionData[] extendionDataList)
            : base(context)
        {
            validState   = VideoPublishStatus.Completed;
            invalidState = VideoPublishStatus.Error;

            if (checkType == SmartContentOperationType.Close)
            {
                validState |= VideoPublishStatus.RemoteProcessing;
            }

            _extensionDataList = extendionDataList;
        }
Ejemplo n.º 4
0
        private bool IsVideoComepleted()
        {
            // Send a request to get the status
            HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest(_updateUrl, true, -1, -1);

            YouTubeUploadRequestHelper.AddSimpleHeader(req, _authToken);
            string innerResult;

            using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
            {
                using (StreamReader responseReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    innerResult = responseReader.ReadToEnd();
                }
            }

            // Find the status elemnt
            XmlDocument xmlDoc = new XmlDocument(NamespaceManager.NameTable);

            xmlDoc.LoadXml(innerResult);
            XmlNode stateNode = xmlDoc.SelectSingleNode("//atom:entry/app:control/yt:state", NamespaceManager);

            // If there is no element with status, then the video is completed
            if (stateNode == null)
            {
                _status  = VideoPublishStatus.Completed;
                _message = Res.Get("Video" + _status);
                return(true);
            }

            // Check to make sure the video doesnt have a bad status
            string value = stateNode.Attributes["name"] != null ? stateNode.Attributes["name"].Value : "";

            if (value == "rejected" || value == "failed")
            {
                throw new Exception(Res.Get("YouTube" + stateNode.Attributes["reasonCode"].Value));
            }

            return(false);
        }
Ejemplo n.º 5
0
        protected override void DoWork()
        {
            _status  = VideoPublishStatus.LocalProcessing;
            _message = Res.Get(StringId.VideoLoading);

            try
            {
                if (string.IsNullOrEmpty(_updateUrl))
                {
                    _message = Res.Get("Video" + _status);
                    string result;
                    try
                    {
                        result = Upload();
                    }
                    catch (WebException ex)
                    {
                        HandleWebException(ex);
                        return;
                    }
                    catch (Exception ex)
                    {
                        HandleException(ex);
                        return;
                    }

                    // Get the ID for this video
                    _id = ExtractIdFromResult(result);
                }

                _status  = VideoPublishStatus.RemoteProcessing;
                _message = String.Format(CultureInfo.CurrentCulture, Res.Get(StringId.VideoRemoteProcessing), Res.Get(StringId.Plugin_Video_Youtube_Publish_Name));

                bool allow404 = true;

                // Check to see if this video has been canceled already or is completed
                while (_status != VideoPublishStatus.Completed && !CancelRequested)
                {
                    try
                    {
                        // Check to see if the video has finished
                        if (IsVideoComepleted())
                        {
                            _status  = VideoPublishStatus.Completed;
                            _message = Res.Get("Video" + _status);
                            return;
                        }
                    }
                    catch (WebException ex)
                    {
                        HttpWebResponse response = ex.Response as HttpWebResponse;
                        if (allow404 && response != null && response.StatusCode == HttpStatusCode.NotFound)
                        {
                            allow404 = false;
                        }
                        else
                        {
                            HandleWebException(ex);
                            return;
                        }
                    }

                    Thread.Sleep(30000);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
        public VideoSmartContentWaitOperation(ISynchronizeInvoke context, SmartContentOperationType checkType, IExtensionData[] extendionDataList)
            : base(context)
        {
            validState = VideoPublishStatus.Completed;
            invalidState = VideoPublishStatus.Error;

            if (checkType == SmartContentOperationType.Close)
                validState |= VideoPublishStatus.RemoteProcessing;

            _extensionDataList = extendionDataList;
        }
Ejemplo n.º 7
0
 internal PublishStatus(VideoPublishStatus status, string displayMessage, string id)
 {
     DisplayMessage = displayMessage;
     Status         = status;
     Id             = id;
 }
Ejemplo n.º 8
0
 internal PublishStatus(VideoPublishStatus status, string displayMessage, string id)
 {
     DisplayMessage = displayMessage;
     Status = status;
     Id = id;
 }
        private bool IsVideoComepleted()
        {
            // Send a request to get the status
            HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest(_updateUrl, true, -1, -1);
            YouTubeUploadRequestHelper.AddSimpleHeader(req, _authToken);
            string innerResult;
            using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
            {
                using (StreamReader responseReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    innerResult = responseReader.ReadToEnd();
                }
            }

            // Find the status elemnt
            XmlDocument xmlDoc = new XmlDocument(NamespaceManager.NameTable);
            xmlDoc.LoadXml(innerResult);
            XmlNode stateNode = xmlDoc.SelectSingleNode("//atom:entry/app:control/yt:state", NamespaceManager);

            // If there is no element with status, then the video is completed
            if (stateNode == null)
            {
                _status = VideoPublishStatus.Completed;
                _message = Res.Get("Video" + _status);
                return true;
            }

            // Check to make sure the video doesnt have a bad status
            string value = stateNode.Attributes["name"] != null ? stateNode.Attributes["name"].Value : "";
            if (value == "rejected" || value == "failed")
            {
                throw new Exception(Res.Get("YouTube" + stateNode.Attributes["reasonCode"].Value));
            }

            return false;
        }
 private void HandleWebException(WebException ex)
 {
     HttpRequestHelper.LogException(ex);
     _status = VideoPublishStatus.Error;
     if (ex.Status != WebExceptionStatus.ProtocolError)
         _message = Res.Get(StringId.VideoNetworkError) + Environment.NewLine + Res.Get(StringId.VideoErrorTryAgain);
     else
         _message = Res.Get(StringId.YouTubeVideoError) + Environment.NewLine + Res.Get(StringId.VideoErrorTryAgain);
 }
        private void HandleException(Exception ex)
        {
            Trace.WriteLine("Failed to upload video: " + ex);
            _status = VideoPublishStatus.Error;

            _message = Res.Get(StringId.YouTubeVideoError) + Environment.NewLine + Res.Get(StringId.VideoErrorTryAgain);
        }
        protected override void DoWork()
        {
            _status = VideoPublishStatus.LocalProcessing;
            _message = Res.Get(StringId.VideoLoading);

            try
            {
                if (string.IsNullOrEmpty(_updateUrl))
                {

                    _message = Res.Get("Video" + _status);
                    string result;
                    try
                    {
                        result = Upload();
                    }
                    catch (WebException ex)
                    {
                        HandleWebException(ex);
                        return;
                    }
                    catch (Exception ex)
                    {
                        HandleException(ex);
                        return;
                    }

                    // Get the ID for this video
                    _id = ExtractIdFromResult(result);
                }

                _status = VideoPublishStatus.RemoteProcessing;
                _message = String.Format(CultureInfo.CurrentCulture, Res.Get(StringId.VideoRemoteProcessing), Res.Get(StringId.Plugin_Video_Youtube_Publish_Name));

                bool allow404 = true;

                // Check to see if this video has been canceled already or is completed
                while (_status != VideoPublishStatus.Completed && !CancelRequested)
                {
                    try
                    {
                        // Check to see if the video has finished
                        if (IsVideoComepleted())
                        {
                            _status = VideoPublishStatus.Completed;
                            _message = Res.Get("Video" + _status);
                            return;
                        }
                    }
                    catch (WebException ex)
                    {
                        HttpWebResponse response = ex.Response as HttpWebResponse;
                        if (allow404 && response != null && response.StatusCode == HttpStatusCode.NotFound)
                        {
                            allow404 = false;
                        }
                        else
                        {
                            HandleWebException(ex);
                            return;
                        }
                    }

                    Thread.Sleep(30000);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }