Ejemplo n.º 1
0
        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);

            DownloadManager.DependencyDownloadCookie dependencyDownloadCookie = new DownloadManager.DependencyDownloadCookie(manifestElement, deployManifest, appManifest);
            downloader.AddFile(fileSourceUri, targetFilePath, (object)dependencyDownloadCookie, hashCollection);
        }
Ejemplo n.º 2
0
        private static void ProcessDownloadedFile(object sender, DownloadEventArgs e)
        {
            if (e.Cookie == null)
            {
                return;
            }
            string         fileName   = Path.GetFileName(e.FileLocalPath);
            FileDownloader downloader = (FileDownloader)sender;

            if (e.FileResponseUri != (Uri)null && !e.FileResponseUri.Equals((object)e.FileSourceUri))
            {
                throw new InvalidDeploymentException(ExceptionTypes.AppFileLocationValidation, string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_DownloadAppFileAsmRedirected"), new object[1]
                {
                    (object)fileName
                }));
            }
            DownloadManager.DependencyDownloadCookie cookie = (DownloadManager.DependencyDownloadCookie)e.Cookie;
            if (cookie.ManifestElement is DependentAssembly)
            {
                DependentAssembly manifestElement  = (DependentAssembly)cookie.ManifestElement;
                AssemblyManifest  deployManifest   = cookie.DeployManifest;
                AssemblyManifest  appManifest      = cookie.AppManifest;
                AssemblyManifest  assemblyManifest = new AssemblyManifest(e.FileLocalPath);
                if (!assemblyManifest.Identity.Matches(manifestElement.Identity, true))
                {
                    throw new InvalidDeploymentException(ExceptionTypes.RefDefValidation, string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_DownloadRefDefMismatch"), new object[1]
                    {
                        (object)fileName
                    }));
                }
                if (assemblyManifest.Identity.Equals((object)deployManifest.Identity) || assemblyManifest.Identity.Equals((object)appManifest.Identity))
                {
                    throw new InvalidDeploymentException(ExceptionTypes.ManifestSemanticValidation, string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_AppPrivAsmIdSameAsDeployOrApp"), new object[1]
                    {
                        (object)assemblyManifest.Identity.ToString()
                    }));
                }
                System.Deployment.Application.Manifest.File[] files = assemblyManifest.Files;
                for (int index = 0; index < files.Length; ++index)
                {
                    Uri fileSourceUri = DownloadManager.MapFileSourceUri(deployManifest, e.FileSourceUri, files[index].Name);
                    if (!fileSourceUri.AbsoluteUri.Equals(e.FileSourceUri.AbsoluteUri, StringComparison.OrdinalIgnoreCase))
                    {
                        string directoryName = Path.GetDirectoryName(e.FileLocalPath);
                        DownloadManager.AddFileToDownloader(downloader, deployManifest, appManifest, (object)files[index], fileSourceUri, directoryName, files[index].NameFS, files[index].HashCollection);
                    }
                }
                downloader.ComponentVerifier.AddFileForVerification(e.FileLocalPath, manifestElement.HashCollection);
                if (assemblyManifest.Identity.PublicKeyToken == null)
                {
                    downloader.ComponentVerifier.AddSimplyNamedAssemblyForVerification(e.FileLocalPath, assemblyManifest);
                }
                else
                {
                    downloader.ComponentVerifier.AddStrongNameAssemblyForVerification(e.FileLocalPath, assemblyManifest);
                }
            }
            else
            {
                if (!(cookie.ManifestElement is System.Deployment.Application.Manifest.File))
                {
                    return;
                }
                System.Deployment.Application.Manifest.File manifestElement = (System.Deployment.Application.Manifest.File)cookie.ManifestElement;
                downloader.ComponentVerifier.AddFileForVerification(e.FileLocalPath, manifestElement.HashCollection);
            }
        }