Beispiel #1
0
        //----------------------------------------------------------
        // Constructor
        //----------------------------------------------------------
        public static WebRequest Create(Uri uri, Uri appBase, string appStorePath)
        {
            ApplicationMonikerRequest apm = new ApplicationMonikerRequest();

            apm._appStorePath   = appStorePath;
            apm._appBase        = appBase;
            apm._appMonResponse = new ApplicationMonikerResponse(uri, appBase, appStorePath);
            apm.type            = FileType.Unknown;
            apm._requestUri     = uri;
            return(apm);
        }
        //----------------------------------------------------------
        // GetNextRequest
        //----------------------------------------------------------
        public ApplicationMonikerRequest GetNextRequest(IAssemblyManifestImport ami)
        {
            FileType type;
            Uri      codebase;

            DependentFileInfo     dfi;
            DependentAssemblyInfo dai;

            // we can't do components for now.
            if (ami.GetFileType() == FileType.ComponentManifest)
            {
                return(null);
            }

            dfi = ami.GetNextDependentFileInfo();
            if (dfi != null)
            {
                codebase = new Uri(_appBase, dfi["name"]);
                type     = FileType.RawFile;
            }
            else
            {
                // Don't follow component dependencies.
//				if (ami.GetFileType() == FileType.ComponentManifest)
//					return null;

                dai = ami.GetNextDependentAssemblyInfo();
                if (dai != null)
                {
                    codebase = new Uri(_appBase, dai["codeBase"]);
                    type     = FileType.ComponentManifest;
                }
                else
                {
                    codebase = null;
                    type     = FileType.Unknown;
                }
            }

            if (codebase == null)
            {
                return(null);
            }

            ApplicationMonikerRequest request =
                (ApplicationMonikerRequest)ApplicationMonikerRequest.Create(codebase, _appBase, _appStorePath);

            request.type = type;

            return(request);
        }
        //----------------------------------------------------------
        // 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);
        }
        //----------------------------------------------------------
        // DoDownload
        //----------------------------------------------------------
        void DoDownload(Uri appManifestUri)
        {
            ApplicationMonikerRequest request =
                (ApplicationMonikerRequest)
                ApplicationMonikerRequest.Create(appManifestUri, _appBase, _appStorePath);

            request.type = FileType.ApplicationManifest;

            _jobTable[appManifestUri] = request;

            RequestState rs = new RequestState();

            rs.Request = request;

            IAsyncResult r = (IAsyncResult)request.BeginGetResponse(
                new AsyncCallback(RespCallback), rs);
        }
 //----------------------------------------------------------
 // ApplicationMoniker
 //----------------------------------------------------------
 public WebRequest Create(Uri uri)
 {
     return(ApplicationMonikerRequest.Create(uri, _appBase, _appStorePath));
 }
 //----------------------------------------------------------
 // ctor
 //----------------------------------------------------------
 public RequestState()
 {
     BufferRead     = new byte[BufferSize];
     Request        = null;
     ResponseStream = null;
 }
        //----------------------------------------------------------
        // 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;
        }
Beispiel #8
0
        //----------------------------------------------------------
        // Constructor
        //----------------------------------------------------------
        public static new WebRequest Create(System.Uri uri)
        {
            ApplicationMonikerRequest apm = new ApplicationMonikerRequest();

            return(apm);
        }