コード例 #1
0
        /// <summary>
        /// This method will be executed as worker thread
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _MonitoringWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // initialize the locally needed variables
            bool doContinueMonitoring    = true;
            bool updateAvailable         = false;
            bool isInitialRun            = true;
            bool exitSignal              = false;
            UpdatePackageInfo updateinfo = null;

            //Now trigger the Start event
            OnMonitoringStarted(this, null);

            while (doContinueMonitoring)
            {
                doContinueMonitoring = !_IsOneTimeCheck;
                if ((!isInitialRun) || (isInitialRun && !_InitialCheck))
                {
                    // create the events array with the exit event in
                    WaitHandle[] handles = new WaitHandle[1] {
                        _MonitoringExitHandle
                    };

                    // Wait until exit signal or timeout
                    ReportStatusInfo(String.Format("Pausing update search vor {0} minutes.", _CheckFrequency.TotalMinutes));
                    int waitResult = WaitHandle.WaitAny(handles, _CheckFrequency);

                    // check wait result
                    switch (waitResult)
                    {
                    case 0: exitSignal = true;
                        break;

                    case WaitHandle.WaitTimeout:    ReportStatusInfo(String.Format("Waited {0} minutes", _CheckFrequency.TotalMinutes));
                        break;

                    default: ReportStatusInfo("Unknown event. Ignoring...");
                        break;
                    }
                }

                // check if we have an exit Signal
                if (exitSignal)
                {
                    ReportStatusInfo("Got exit signal");
                    break;
                }

                // Now Check for an update
                updateAvailable = CheckForApplicableUpdate(out updateinfo);

                if (updateAvailable)
                {
                    AvailableUpdatePackageInfo = updateinfo;
                    OnUpdateFound(this, new UpdateFoundEventArgs()
                    {
                        FoundTitle = updateinfo.Title, FoundVersion = new Version(updateinfo.Version)
                    });
                }

                if (updateAvailable && AutoDownload && !_IsOneTimeCheck)
                {
                    _DownloadWorker_DoWork(null, null);
                }

                // modify the loop controller variables
                doContinueMonitoring &= !updateAvailable;
                // Initial rune is now definitly over
                isInitialRun = false;
            }

            OnMonitoringFinished(this, null);
            _IsMonitoring = false;
        }
コード例 #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);
            }
        }