コード例 #1
0
        //----------------------------------------------------------
        // RespCallback
        //----------------------------------------------------------
        void RespCallback(IAsyncResult ar)
        {
            RequestState rs = (RequestState)ar.AsyncState;

            ApplicationMonikerRequest req = rs.Request;

            ApplicationMonikerResponse resp = (ApplicationMonikerResponse)req.EndGetResponse(ar);

            ApplicationMonikerStream ResponseStream = (ApplicationMonikerStream)resp.GetResponseStream();

            rs.ResponseStream = ResponseStream;

            IAsyncResult iarRead = ResponseStream.BeginRead(rs.BufferRead, 0,
                                                            BUFFER_SIZE, new AsyncCallback(ReadCallBack), rs);
        }
コード例 #2
0
        //----------------------------------------------------------
        // ReadCallback
        //----------------------------------------------------------
        void ReadCallBack(IAsyncResult asyncResult)
        {
            RequestState rs = (RequestState)asyncResult.AsyncState;

            ApplicationMonikerStream responseStream = rs.ResponseStream;

            int read = responseStream.EndRead(asyncResult);

            if (read > 0)
            {
                _totalRead += read;
                IAsyncResult ar = responseStream.BeginRead(
                    rs.BufferRead, 0, BUFFER_SIZE,
                    new AsyncCallback(ReadCallBack), rs);
            }
            else
            {
                _progress.SetStatus((int)_totalRead);
                _progress.SetText("Downloading: " + responseStream.path);
                _progress.SetTotal("Total: " + _totalRead.ToString() + "/" + _totalSize.ToString() + " bytes read");

                responseStream.Close();

                if ((rs.Request.type == FileType.ApplicationManifest) ||
                    (rs.Request.type == FileType.ComponentManifest))
                {
                    IAssemblyManifestImport assemblyManifestImport;

                    Uri cachePath = responseStream.GetCachePath();

                    if (rs.Request.type == FileType.ApplicationManifest)
                    {
                        assemblyManifestImport = new ApplicationManifestImport(cachePath);
                    }
                    else
                    {
//						this is a drag - we can't even do this - the loadfrom will fail if modules not present.
//						soln for now is to ignore component constituents (don't enqueue them)
//						assemblyManifestImport = new ComponentManifestImport(cachePath);
                        goto done;
                    }

                    ApplicationMonikerRequest newRequest;
                    while ((newRequest = GetNextRequest(assemblyManifestImport)) != null)
                    {
                        if (_jobTable[newRequest.RequestUri] == null)
                        {
                            if (newRequest.CachedCopyExists() != true)
                            {
                                _jobQueue.Enqueue(newRequest);
                                _jobTable[newRequest.RequestUri] = newRequest;
                            }
                            else
                            {
                                _totalRead += (int)newRequest.GetCacheFileSize();
                                _progress.SetStatus((int)_totalRead);
                                newRequest.Dispose();
                            }
                        }
                    }
                }

done:

                if (_jobQueue.Count == 0)
                {
                    _bDone = true;
                }
                else
                {
                    ApplicationMonikerRequest nextRequest = (ApplicationMonikerRequest)_jobQueue.Dequeue();

                    RequestState rsnext = new RequestState();
                    rsnext.Request = nextRequest;

                    IAsyncResult r = (IAsyncResult)nextRequest.BeginGetResponse(
                        new AsyncCallback(RespCallback), rsnext);
                }
            }
            return;
        }