//---------------------------------------------------------- // ctor //---------------------------------------------------------- public ApplicationMoniker(string manifestUri, string appBase) { _manifestUri = new Uri(manifestUri); string path = _manifestUri.LocalPath; _manifestFileName = System.IO.Path.GetFileName(path); if (appBase != null) { _appBase = new Uri(appBase); } else { string appBaseString = manifestUri.Substring(0, manifestUri.Length - _manifestFileName.Length); _appBase = new Uri(appBaseString); } _applicationManifestImport = new ApplicationManifestImport(_manifestUri); _assemblyIdentity = _applicationManifestImport.GetAssemblyIdentity(); string appDirName = _assemblyIdentity.GetDirectoryName(); string userprofile = Environment.GetEnvironmentVariable("userprofile"); _appStorePath = userprofile + "\\Local Settings\\My Programs\\__temp__\\" + appDirName; _progress = new Progress(); _jobTable = new Hashtable(); _jobQueue = new Queue(); _totalRead = 0; _totalSize = 0; }
//---------------------------------------------------------------------------- // ParseManifest //---------------------------------------------------------------------------- public void ParseManifest() { Uri sManifestUri = new Uri(_sManifestPath); ApplicationManifestImport ami = new ApplicationManifestImport(sManifestUri); ActivationInfo ai = ami.GetActivationInfo(); SecurityInfo si = ami.GetSecurityInfo(); _sAsmName = ai["assemblyName"]; _sAsmClass = ai["assemblyClass"]; _sAsmMethod = ai["assemblyMethod"]; _sAsmArgs = ai["assemblyMethodArgs"]; if (si != null) { _sSecurityStatement = si["Security"]; } Console.WriteLine("AsmName=\t" + _sAsmName); Console.WriteLine("Class=\t\t" + _sAsmClass); Console.WriteLine("Method=\t\t" + _sAsmMethod); Console.WriteLine("Args=\t\t" + _sAsmArgs); Console.WriteLine("\n"); Console.WriteLine("Security=\t\t" + _sSecurityStatement); }
//---------------------------------------------------------- // 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; }