A RequestState is used to store request information between asynchronous calls to callbacks.
        /// <summary>
        /// Starts fetching a file, and notifies the OnFetchedFile event
        /// when done.
        /// </summary>
        public void FetchFile(string URL)
        {
            WebRequest Request = WebRequest.Create(URL);
            Request.Method = "GET";
            RequestState ReqState = new RequestState();

            ReqState.Request = Request;
            ReqState.TransferStart = DateTime.Now;
            Request.BeginGetResponse(new AsyncCallback(GotInitialResponse), ReqState);
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);
        }
        public void Initialize()
        {
            try
            {
                WebRequest Request = WebRequest.Create(m_ManifestAddress);
                RequestState ReqState = new RequestState();

                ReqState.Request = Request;
                ReqState.TransferStart = DateTime.Now;
                Request.BeginGetResponse(new AsyncCallback(GotInitialResponse), ReqState);
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);
            }
            catch (Exception E)
            {
                Logger.Log("Exception in Requester.Initialize:\n" + E.ToString(), LogLevel.error);
            }
        }
Beispiel #3
0
        /// <summary>
        /// The requester ticked, supplying information about a download in progress.
        /// </summary>
        /// <param name="State">The state of the download in progress.</param>
        private void m_Requester_OnTick(RequestState State)
        {
            if (LblDownloading.InvokeRequired)
                this.Invoke(new MethodInvoker(() => { LblDownloading.Text = "Downloading: " + State.Response.ResponseUri; }));
            else
                LblDownloading.Text = "Downloading: " + State.Response.ResponseUri;

            if(LblSpeed.InvokeRequired)
                this.Invoke(new MethodInvoker(() => { LblSpeed.Text = State.KBPerSec.ToString() + " KB/Sec"; }));
            else
                LblSpeed.Text = State.KBPerSec.ToString() + "KB / Sec";

            if (PrgFile.InvokeRequired)
            {
                this.Invoke(new MethodInvoker(() =>
                    {
                        PrgFile.Step = (int)(PrgFile.Width * (State.ContentLength / State.PctComplete));
                        PrgFile.PerformStep();
                    }));
            }
            else
            {
                PrgFile.Step = (int)(PrgFile.Width * (State.ContentLength / State.PctComplete));
                PrgFile.PerformStep();
            }
        }