コード例 #1
0
        public static UpdatePackageInfo FromXml(string xmldata, string rsakey)
        {
            if (String.IsNullOrWhiteSpace(xmldata))
            {
                throw new ArgumentException("Empty xmldata provided");
            }

            if (String.IsNullOrWhiteSpace(rsakey))
            {
                throw new ArgumentException("Empty rsakey provided");
            }

            RSACryptoServiceProvider rsa;

            try
            {
                rsa = new RSACryptoServiceProvider();
                rsa.FromXmlString(rsakey);
            }
            catch
            {
                throw new ArgumentException("Invalid rsakey provided");
            }

            XmlDocument xdoc;

            try
            {
                xdoc = new XmlDocument();
                xdoc.LoadXml(xmldata);
                if (!xdoc.VerifySignature(rsa))
                {
                    return(null);
                }

                return(UpdatePackageInfo.FromXml(xdoc.OuterXml));
            }
            catch
            {
                return(null);
            }
        }
コード例 #2
0
        public bool IsUpdateInfoAvailable()
        {
            string xmldata;

            _LastException = null;

            ReportStatusInfo("Starting IsUpdateInfoAvailable");
            try
            {
                // Generate the Request object based on the url type
                ReportStatusInfo("Creating request");
                WebRequest request = GetRequest(_Url);

                // request the cast and build the stream
                using (WebResponse response = request.GetResponse())
                {
                    // now use a stream to read data from the server
                    ReportStatusInfo("Reading Response");
                    using (Stream inputstream = response.GetResponseStream())
                    {
                        StreamReader sr = new StreamReader(inputstream);
                        xmldata = sr.ReadToEnd();
                    }
                }

                // finally try to parse the data
                ReportStatusInfo("Deserializing result");
                if (String.IsNullOrEmpty(_RsaKey))
                {
                    _currentUpdatePackageInfo = UpdatePackageInfo.FromXml(xmldata);
                }
                else
                {
                    _currentUpdatePackageInfo = UpdatePackageInfo.FromXml(xmldata, _RsaKey);
                }
                return(true);
            }
            catch (WebException ex)
            {
                ReportStatusError("Could not download info package. Checking reason");
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    // Check if File just doesnt exist
                    if ((ex.Response is HttpWebResponse) && (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound))
                    {
                        return(false);
                    }

                    if ((ex.Response is FtpWebResponse) && (((FtpWebResponse)ex.Response).StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable))
                    {
                        return(false);
                    }
                }
                ReportStatusError("Unplaned WebException", ex);
                _LastException = ex;
                return(false);
            }
            catch (Exception ex)
            {
                ReportStatusError("Unplaned Exception", ex);
                _LastException = ex;
                return(false);
            }
        }