Exemple #1
0
        public void InstallApplication(string deployManifestUriStr)
        {
            try
            {
                Uri deploymentUri = new Uri(deployManifestUriStr);
                iphm = new InPlaceHostingManager(deploymentUri, false);
            }
            catch (UriFormatException uriEx)
            {
                MessageBox.Show("Cannot install the application: " +
                                "The deployment manifest URL supplied is not a valid URL. " +
                                "Error: " + uriEx.Message);
                return;
            }
            catch (PlatformNotSupportedException platformEx)
            {
                MessageBox.Show("Cannot install the application: " +
                                "This program requires Windows XP or higher. " +
                                "Error: " + platformEx.Message);
                return;
            }
            catch (ArgumentException argumentEx)
            {
                MessageBox.Show("Cannot install the application: " +
                                "The deployment manifest URL supplied is not a valid URL. " +
                                "Error: " + argumentEx.Message);
                return;
            }

            //<SNIPPET4>
            iphm.GetManifestCompleted += new EventHandler <GetManifestCompletedEventArgs>(iphm_GetManifestCompleted);
            iphm.GetManifestAsync();
            //</SNIPPET4>
        }
Exemple #2
0
        private void InstallApplication(Uri app)
        {
            var manager = new InPlaceHostingManager(app, false);

            manager.GetManifestCompleted +=
                new EventHandler <GetManifestCompletedEventArgs>(
                    OnGetManifestCompleted
                    );

            // I would love to just "await manager.GetManifestAsync" here
            // but GetManifestAsync returns void
            _event = new AutoResetEvent(false);
            // Console.WriteLine("Getting manifest for {0}", app);
            manager.GetManifestAsync();
            _event.WaitOne();

            // this call is synchronous
            // Console.WriteLine("Asserting application requirements for {0}", app);
            manager.AssertApplicationRequirements(true);
            // Console.WriteLine("AssertApplicationRequirements passes");

            manager.DownloadApplicationCompleted +=
                new EventHandler <DownloadApplicationCompletedEventArgs>(
                    OnDownloadApplicationCompleted
                    );
            // Console.WriteLine("Downloading and installing {0}", app);
            manager.DownloadApplicationAsync();
            _event.WaitOne();
        }
 public void CloseDeploymentManager()
 {
     if (_deployManager != null)
     {
         this.DeploymentService.EndServiceRightNow();
         _deployManager.Dispose();
         _deployManager = null;
     }
 }
        public async Task InstallClickOnceApp(Uri deploymentUri)
        {
            using (var host = new InPlaceHostingManager(deploymentUri, false))
            {
                await GetApplicationManifest(host);

                AssertApplicationRequirements(host);
                await DownloadApplication(host);
            }
        }
        public void Dispose()
        {
            if (_deployManager != null)
            {
                _deployManager.Dispose();
                _deployManager = null;
            }

            if (_deployService != null)
            {
                _deployService.EndServiceRightNow();
                _deployService = null;
            }
        }
        public void Close()
        {
            if (_deployManager != null)
            {
                _deployManager.Dispose();
                _deployManager = null;

                if (Process.GetProcessesByName(ClickOnceManager.ClickOnceServiceName).Any())
                {
                    foreach (Process proc in Process.GetProcessesByName(ClickOnceManager.ClickOnceServiceName))
                    {
                        proc.Kill();
                        Thread.Sleep(500);
                    }
                    Thread.Sleep(1500);
                }
            }
        }
        private static Task GetApplicationManifest(InPlaceHostingManager host)
        {
            var completion = new TaskCompletionSource <int>();

            host.GetManifestCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    completion.SetException(e.Error);
                }

                else
                {
                    completion.SetResult(0);
                }
            };

            host.GetManifestAsync();

            return(completion.Task);
        }
        // Token: 0x06006471 RID: 25713 RVA: 0x001C2C78 File Offset: 0x001C0E78
        internal static MissingDependencyType GetWinFXRequirement(Exception e, InPlaceHostingManager hostingManager, out string version, out Uri fwlinkUri)
        {
            version   = string.Empty;
            fwlinkUri = null;
            if (e is DependentPlatformMissingException)
            {
                Regex  regex   = new Regex(".NET Framework (v\\.?)?(?<version>\\d{1,2}(\\.\\d{1,2})?)", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
                string message = e.Message;
                Match  match   = regex.Match(message);
                if (match.Success)
                {
                    version = match.Groups[1].Value;
                    DeploymentExceptionMapper.ConstructFwlinkUrl(version, out fwlinkUri);
                    return(MissingDependencyType.WinFX);
                }
            }
            Assembly assembly = Assembly.GetAssembly(hostingManager.GetType());

            if (assembly == null)
            {
                return(MissingDependencyType.Others);
            }
            ResourceManager resourceManager = new ResourceManager("System.Deployment", assembly);

            if (resourceManager == null)
            {
                return(MissingDependencyType.Others);
            }
            string text  = resourceManager.GetString("PlatformMicrosoftCommonLanguageRuntime", CultureInfo.CurrentUICulture);
            string text2 = resourceManager.GetString("PlatformDependentAssemblyVersion", CultureInfo.CurrentUICulture);

            if (text == null || text2 == null)
            {
                return(MissingDependencyType.Others);
            }
            text  = text.Replace("{0}", "");
            text2 = text2.Replace("{0}", "");
            text2 = text2.Replace("{1}", "");
            string[] array = new string[]
            {
                "WindowsBase",
                "System.Core",
                "Sentinel.v3.5Client",
                "System.Data.Entity"
            };
            string message2 = e.Message;
            int    num      = message2.IndexOf(text2, StringComparison.Ordinal);

            if (num != -1)
            {
                version = string.Copy(message2.Substring(num + text2.Length));
                int num2 = version.IndexOf(".", StringComparison.Ordinal);
                int num3 = version.IndexOf(".", num2 + 1, StringComparison.Ordinal);
                if (message2.IndexOf(text, StringComparison.Ordinal) != -1)
                {
                    if (OperatingSystemVersionCheck.IsVersionOrLater(OperatingSystemVersion.Windows8))
                    {
                        int num4 = version.IndexOf(".", num3 + 1, StringComparison.Ordinal);
                        if (num4 != -1)
                        {
                            version = version.Substring(0, num4);
                        }
                    }
                    else if (num3 != -1)
                    {
                        version = version.Substring(0, num3);
                    }
                    string version2 = "CLR" + version;
                    if (!DeploymentExceptionMapper.ConstructFwlinkUrl(version2, out fwlinkUri))
                    {
                        return(MissingDependencyType.Others);
                    }
                    return(MissingDependencyType.CLR);
                }
                else
                {
                    if (num3 != -1)
                    {
                        version = version.Substring(0, num3);
                    }
                    bool flag = false;
                    foreach (string value in array)
                    {
                        if (message2.IndexOf(value, StringComparison.OrdinalIgnoreCase) > 0)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        version = string.Empty;
                    }
                }
            }
            if (!DeploymentExceptionMapper.ConstructFwlinkUrl(version, out fwlinkUri))
            {
                return(MissingDependencyType.Others);
            }
            return(MissingDependencyType.WinFX);
        }
Exemple #9
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------
        #region Internal Methods

        // Check if the platform exception is due to missing WinFX or CLR dependency
        // Parse the exception message and find out the dependent WinFX version and create the
        // corresponding fwlink Uri.
        static internal MissingDependencyType GetWinFXRequirement(Exception e,
                                                                  InPlaceHostingManager hostingManager,
                                                                  out string version,
                                                                  out Uri fwlinkUri)
        {
            version   = String.Empty;
            fwlinkUri = null;

            // ClickOnce detects whether it's running as part of the v3.5 "client" subset ("Arrowhead") and
            // if so blocks older applications that don't explicitly opt into the subset framework.
            // (Unfortunately, it does not block an application targeting the full 3.5 SP1 framework this way.)
            // The exception message has ".NET Framework 3.5 SP1" hard-coded in it (referring to the version
            // of the framework needed to run the application, which is not strictly right, but older versions
            // can't/shouldn't be installed on top of the "client" subset).
            // To make this exception message parsing at least potentially somewhat future-proof, a regex is
            // used that allows for some variability of syntax and version number.
            // We don't include the "SP1" part in the fwlink query. This is for consistency with the detection
            // via sentinel assemblies. The server can be updated to offer the latest release/SP compatible
            // with the requested major.minor version.
            if (e is DependentPlatformMissingException)
            {
                Regex regex = new Regex(@".NET Framework (v\.?)?(?<version>\d{1,2}(\.\d{1,2})?)",
                                        RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
                string msg   = e.Message;
                Match  match = regex.Match(msg);
                if (match.Success)
                {
                    version = match.Groups[1].Value;
                    ConstructFwlinkUrl(version, out fwlinkUri);
                    return(MissingDependencyType.WinFX);
                }
            }

            // Load the clickonce resource and use it to parse the exception message
            Assembly deploymentDll = Assembly.GetAssembly(hostingManager.GetType());

            if (deploymentDll == null)
            {
                return(MissingDependencyType.Others);
            }

            ResourceManager resourceManager = new ResourceManager("System.Deployment", deploymentDll);

            if (resourceManager == null)
            {
                return(MissingDependencyType.Others);
            }

            String clrProductName = resourceManager.GetString("PlatformMicrosoftCommonLanguageRuntime", CultureInfo.CurrentUICulture);
            String versionString  = resourceManager.GetString("PlatformDependentAssemblyVersion", CultureInfo.CurrentUICulture);

            if ((clrProductName == null) || (versionString == null))
            {
                return(MissingDependencyType.Others);
            }

            // Need to trim off the parameters in the ClickOnce strings:
            // "{0} Version {1}" -> "Version"
            // "Microsoft Common Language Runtime Version {0}" -> "Microsoft Common Language Runtime Version"
            clrProductName = clrProductName.Replace("{0}", "");
            versionString  = versionString.Replace("{0}", "");
            versionString  = versionString.Replace("{1}", "");

            string[] sentinelAssemblies =
            {
                // The Original & "Only"
                "WindowsBase",
                // A reference to System.Core is what makes an application target .NET v3.5.
                // Because WindowsBase still has v3.0.0.0, it's not the one that fails the platform requirements
                // test when a v3.5 app is run on the v3 runtime. (This additional check added for v3 SP1.)
                "System.Core",
                // New sentinel assemblies for v3.5 SP1 (see the revision history)
                "Sentinel.v3.5Client", "System.Data.Entity"
            };

            // Parse the required version and trim it to major and minor only
            string excpMsg = e.Message;
            int    index   = excpMsg.IndexOf(versionString, StringComparison.Ordinal);

            if (index != -1)
            {
                // ClickOnce exception message is ErrorMessage_Platform*
                // from clickonce/system.deployment.txt
                version = String.Copy(excpMsg.Substring(index + versionString.Length));
                int indexToFirstDot  = version.IndexOf(".", StringComparison.Ordinal);
                int indexToSecondDot = version.IndexOf(".", indexToFirstDot + 1, StringComparison.Ordinal);


                if (excpMsg.IndexOf(clrProductName, StringComparison.Ordinal) != -1)
                {
                    if (OperatingSystemVersionCheck.IsVersionOrLater(OperatingSystemVersion.Windows8))
                    {
                        // CLR version are Major.Minor.Revision
                        // Defense in depth here in case CLR changes the version scheme to major + minor only
                        // and we might never see the third dot
                        int indexToThirdDot = version.IndexOf(".", indexToSecondDot + 1, StringComparison.Ordinal);
                        if (indexToThirdDot != -1)
                        {
                            version = version.Substring(0, indexToThirdDot);
                        }
                    }
                    else if (indexToSecondDot != -1)
                    {
                        // Defense in depth here in case Avalon change the version scheme to major + minor only
                        // and we might never see the second dot
                        version = version.Substring(0, indexToSecondDot);
                    }

                    // prepend CLR to distinguish CLR version fwlink query
                    // vs. WinFX version query.
                    string clrVersion = String.Concat("CLR", version);
                    return(ConstructFwlinkUrl(clrVersion, out fwlinkUri) ? MissingDependencyType.CLR : MissingDependencyType.Others);
                }
                else
                {
                    if (indexToSecondDot != -1)
                    {
                        // Defense in depth here in case Avalon change the version scheme to major + minor only
                        // and we might never see the second dot
                        version = version.Substring(0, indexToSecondDot);
                    }

                    bool sentinelMissing = false;
                    foreach (string sentinelAssembly in sentinelAssemblies)
                    {
                        if (excpMsg.IndexOf(sentinelAssembly, StringComparison.OrdinalIgnoreCase) > 0)
                        {
                            sentinelMissing = true;
                            break;
                        }
                    }
                    if (!sentinelMissing)
                    {
                        version = String.Empty;
                    }
                }
            }

            return(ConstructFwlinkUrl(version, out fwlinkUri) ? MissingDependencyType.WinFX : MissingDependencyType.Others);
        }
 private static void AssertApplicationRequirements(InPlaceHostingManager host)
 {
     host.AssertApplicationRequirements(true);
 }