private static void AddDependencies(FileDownloader downloader, AssemblyManifest deployManifest, AssemblyManifest appManifest, Uri sourceUriBase, string targetDirectory, string group) { Uri uri; long total = 0L; System.Deployment.Application.Manifest.File[] filesInGroup = appManifest.GetFilesInGroup(group, true); ReorderFilesForIconFile(appManifest, filesInGroup); foreach (System.Deployment.Application.Manifest.File file in filesInGroup) { uri = MapFileSourceUri(deployManifest, sourceUriBase, file.Name); AddFileToDownloader(downloader, deployManifest, appManifest, file, uri, targetDirectory, file.NameFS, file.HashCollection); total += (long) file.Size; } DependentAssembly[] privateAssembliesInGroup = appManifest.GetPrivateAssembliesInGroup(group, true); foreach (DependentAssembly assembly in privateAssembliesInGroup) { uri = MapFileSourceUri(deployManifest, sourceUriBase, assembly.Codebase); AddFileToDownloader(downloader, deployManifest, appManifest, assembly, uri, targetDirectory, assembly.CodebaseFS, assembly.HashCollection); total += (long) assembly.Size; } downloader.SetExpectedBytesTotal(total); if ((filesInGroup.Length == 0) && (privateAssembliesInGroup.Length == 0)) { throw new InvalidDeploymentException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_NoSuchDownloadGroup"), new object[] { group })); } }
private static void AddFileToDownloader(FileDownloader downloader, AssemblyManifest deployManifest, AssemblyManifest appManifest, object manifestElement, Uri fileSourceUri, string targetDirectory, string targetFileName, HashCollection hashCollection) { string targetFilePath = Path.Combine(targetDirectory, targetFileName); DependencyDownloadCookie cookie = new DependencyDownloadCookie(manifestElement, deployManifest, appManifest); downloader.AddFile(fileSourceUri, targetFilePath, cookie, hashCollection); }
protected void DownloadSingleFile(FileDownloader.DownloadQueueItem next) { Logger.AddMethodCall("DownloadSingleFile called"); Logger.AddInternalState("DownloadQueueItem : " + ((next != null) ? next.ToString() : "null")); WebRequest request = WebRequest.Create(next._sourceUri); request.Credentials = CredentialCache.DefaultCredentials; RequestCachePolicy policy = new RequestCachePolicy(RequestCacheLevel.BypassCache); request.CachePolicy = policy; HttpWebRequest httpreq = request as HttpWebRequest; if (httpreq != null) { httpreq.UnsafeAuthenticatedConnectionSharing = true; httpreq.AutomaticDecompression = DecompressionMethods.GZip; httpreq.CookieContainer = GetUriCookieContainer(httpreq.RequestUri); IWebProxy defaultWebProxy = WebRequest.DefaultWebProxy; if (defaultWebProxy != null) { defaultWebProxy.Credentials = CredentialCache.DefaultCredentials; } Logger.AddInternalState("HttpWebRequest=" + Logger.Serialize(httpreq)); } if (!base._fCancelPending) { WebResponse response = null; try { response = request.GetResponse(); UriHelper.ValidateSupportedScheme(response.ResponseUri); if (!base._fCancelPending) { base._eventArgs._fileSourceUri = next._sourceUri; base._eventArgs._fileResponseUri = response.ResponseUri; base._eventArgs.FileLocalPath = next._targetPath; base._eventArgs.Cookie = null; if (response.ContentLength > 0L) { base.CheckForSizeLimit((ulong) response.ContentLength, false); base._accumulatedBytesTotal += response.ContentLength; } base.SetBytesTotal(); base.OnModified(); Stream responseStream = null; Stream outputFileStream = null; int tickCount = Environment.TickCount; try { responseStream = response.GetResponseStream(); Directory.CreateDirectory(Path.GetDirectoryName(next._targetPath)); outputFileStream = GetOutputFileStream(next._targetPath); if (outputFileStream != null) { int num3; long num2 = 0L; if (response.ContentLength > 0L) { outputFileStream.SetLength(response.ContentLength); } do { if (base._fCancelPending) { return; } num3 = responseStream.Read(base._buffer, 0, base._buffer.Length); if (num3 > 0) { outputFileStream.Write(base._buffer, 0, num3); } base._eventArgs._bytesCompleted += num3; if (response.ContentLength <= 0L) { base._accumulatedBytesTotal += num3; base.SetBytesTotal(); } num2 += num3; if ((next._maxFileSize != -1) && (num2 > next._maxFileSize)) { throw new InvalidDeploymentException(ExceptionTypes.FileSizeValidation, string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_FileBeingDownloadedTooLarge"), new object[] { next._sourceUri.ToString(), next._maxFileSize })); } base.CheckForSizeLimit((ulong) num3, true); if (base._eventArgs._bytesTotal > 0L) { base._eventArgs._progress = (int) ((base._eventArgs._bytesCompleted * 100L) / base._eventArgs._bytesTotal); } base.OnModifiedWithThrottle(ref tickCount); } while (num3 > 0); if (response.ContentLength != num2) { outputFileStream.SetLength(num2); } } } finally { if (responseStream != null) { responseStream.Close(); } if (outputFileStream != null) { outputFileStream.Close(); } } base._eventArgs.Cookie = next._cookie; base._eventArgs._filesCompleted++; Logger.AddInternalState("HttpWebResponse=" + Logger.Serialize(response)); base.OnModified(); DownloadResult result = new DownloadResult { ResponseUri = response.ResponseUri }; result.ServerInformation.Server = response.Headers["Server"]; result.ServerInformation.PoweredBy = response.Headers["X-Powered-By"]; result.ServerInformation.AspNetVersion = response.Headers["X-AspNet-Version"]; base._downloadResults.Add(result); } } catch (InvalidOperationException exception) { throw new DeploymentDownloadException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_FailedWhileDownloading"), new object[] { next._sourceUri }), exception); } catch (IOException exception2) { throw new DeploymentDownloadException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_FailedWhileDownloading"), new object[] { next._sourceUri }), exception2); } catch (UnauthorizedAccessException exception3) { throw new DeploymentDownloadException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_FailedWhileDownloading"), new object[] { next._sourceUri }), exception3); } finally { if (response != null) { response.Close(); } } } }