コード例 #1
0
        // This gets the application's deployment manifest and parses out the info needed to
        // determine the shortcut path.  Returns null if it fails or this isn't a ClickOnce app.
        private static DeploymentDescription GetDeploymentDescription()
        {
            using (Log.InfoCall())
            {
                DeploymentDescription result = null;

                try
                {
                    if (ApplicationDeployment.IsNetworkDeployed)
                    {
                        result = new DeploymentDescription();

                        Log.Info("Getting ClickOnce deployment manifest: ", ApplicationDeployment.CurrentDeployment.UpdateLocation);

                        using (WebClient client = new WebClient())
                        {
                            string manifest = client.DownloadString(ApplicationDeployment.CurrentDeployment.UpdateLocation);

                            Log.Info("Got manifest of length ", manifest.Length, ", parsing it now.");

                            using (var stringReader = new StringReader(manifest))
                            {
                                var xmlReader = new XmlTextReader(stringReader);
                                result.ExtractDescriptions(xmlReader);
                                Log.Info("Constructed shortcut is ", result.shortcut);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    result = null;
                }

                return(result);
            }
        }
コード例 #2
0
        public static void StartNewViewer(string file = null, string server = null)
        {
            using (Log.InfoCall())
            {
                // If this is a ClickOnce app we can't just
                // call Process.Start(Application.ExecutablePath) because the new process won't use the
                // same application settings file as the current process.  To use the same settings file we need to
                // start the new process via the same shortcut that started the current process.
                // Here we try to determine that shortcut.

                DeploymentDescription clickOnceInfo = Instance;
                string arguments = "";

                Log.Info("file = ", file);
                Log.Info("server = ", server);
                Log.Info("clickOnceInfo = ", clickOnceInfo);

                if (clickOnceInfo == null)
                {
                    // Not a ClickOnce app.  Just invoke the .exe directly.

                    if (file != null)
                    {
                        arguments = "\"" + file + "\"";
                    }

                    if (!server.NullOrWhiteSpace())
                    {
                        arguments += " -server:\"" + server + "\"";
                    }

                    Process.Start(System.Windows.Forms.Application.ExecutablePath, arguments);
                }
                else
                {
                    // We're a ClickOnce app. Invoke process via the ClickOnce shortcut.  In this case the argument string cannot
                    // have embedded spaces or double-quotes. Use the '&' char where we would normally use a space to separate
                    // the arguments and percent-encode each individual argument in case they contain spaces or '&'s.

                    if (file != null)
                    {
                        //arguments = "%22" + file + "%22"; // Truncated at first blank.
                        //arguments = "\"" + file + "\""; // Quotes are removed, embedded blanks look like multiple args.
                        //arguments = "file:" + ArgParser.PercentEncode(file); // Invalid URI and invalid file.
                        //arguments = "-file:\"" + file + "\""; // Truncated at first quote.

                        // The Uri class will correctly percent-encode the file path so there are no embedded spaces.

                        Uri uri = new Uri(file);
                        arguments = uri.AbsoluteUri;
                    }

                    if (!server.NullOrWhiteSpace())
                    {
                        arguments += "&-server:" + ArgParserTX.PercentEncode(server);
                    }

                    Log.Info("argument string: ", arguments);
                    Process.Start(clickOnceInfo.Shortcut, arguments);
                }
            }
        }