示例#1
0
        private void ProcessInstallRequest(XElement outputDoc, string appxurl)
        {
            var uriSegments = new System.Uri(appxurl).Segments;
            var fileName    = uriSegments[uriSegments.Length - 1];
            var filePath    = TempPath + fileName;

            this.Output.AppendText("Installing " + fileName + Environment.NewLine);
            this.Output.AppendText("  from " + appxurl + Environment.NewLine);
            this.Output.AppendText("  at " + DateTime.Now + Environment.NewLine);

            var result = new InstallResult();

            result.Error = DownloadAppx(appxurl, filePath);
            if (string.IsNullOrWhiteSpace(result.Error))
            {
                result = InstallAppx(filePath);
            }

            if (string.IsNullOrWhiteSpace(result.Error))
            {
                outputDoc.Add(new XElement("success", "true"));
                NotifyIcon.ShowBalloonTip(500, "OrgPortal", "App installed", System.Windows.Forms.ToolTipIcon.Info);
                this.Output.AppendText("**SUCCESS" + Environment.NewLine);
            }
            else
            {
                outputDoc.Add(new XElement("success", "false"));
                outputDoc.Add(new XElement("error", result.ToString()));
                NotifyIcon.ShowBalloonTip(500, "OrgPortal", "App not installed", System.Windows.Forms.ToolTipIcon.Warning);
                this.Output.AppendText("**FAILED" + Environment.NewLine);
                this.Output.AppendText(result.ToString() + Environment.NewLine);
            }

            GetInstalledPackages();
        }
示例#2
0
        public InstallResult InstallAppx(string filepath)
        {
            var result = new InstallResult();

            try
            {
                var sb = new StringBuilder();
                sb.Append(@"add-appxpackage ");
                sb.Append(filepath);

                var process = new System.Diagnostics.Process();
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.RedirectStandardOutput = true;

                process.StartInfo.FileName  = "powershell.exe";
                process.StartInfo.Arguments = sb.ToString();

                process.StartInfo.CreateNoWindow = false;
                process.StartInfo.WindowStyle    = System.Diagnostics.ProcessWindowStyle.Hidden;

                process.Start();

                var stdout = process.StandardOutput;
                var stderr = process.StandardError;

                result.Output = stdout.ReadToEnd();
                result.Error  = stderr.ReadToEnd();

                if (!process.HasExited)
                {
                    process.Kill();
                }

                stdout.Close();
                stderr.Close();
            }
            catch (Exception ex)
            {
                if (string.IsNullOrWhiteSpace(result.Error))
                {
                    result.Error = ex.Message;
                }
                else
                {
                    result.Error += Environment.NewLine + ex.Message;
                }
            }
            finally
            {
                File.Delete(filepath);
            }

            return(result);
        }
示例#3
0
        private void ProcessInstallRequest(XElement outputDoc, string[] input)
        {
            var appxurl = input[1];

              var uriSegments = new System.Uri(appxurl).Segments;
              var fileName = uriSegments[uriSegments.Length - 1];
              var filePath = TempPath + fileName;

              this.Output.AppendText("Installing " + fileName + Environment.NewLine);
              this.Output.AppendText("  from " + appxurl + Environment.NewLine);
              this.Output.AppendText("  at " + DateTime.Now + Environment.NewLine);

              var result = new InstallResult();
              result.Error = DownloadAppx(appxurl, filePath);
              if (string.IsNullOrWhiteSpace(result.Error))
            result = InstallAppx(filePath);

              if (string.IsNullOrWhiteSpace(result.Error))
              {
            outputDoc.Add(new XElement("success", "true"));
            NotifyIcon.ShowBalloonTip(500, "OrgPortal", "App installed", System.Windows.Forms.ToolTipIcon.Info);
            this.Output.AppendText("**SUCCESS" + Environment.NewLine);
              }
              else
              {
            outputDoc.Add(new XElement("success", "false"));
            outputDoc.Add(new XElement("error", result.ToString()));
            NotifyIcon.ShowBalloonTip(500, "OrgPortal", "App not installed", System.Windows.Forms.ToolTipIcon.Warning);
            this.Output.AppendText("**FAILED" + Environment.NewLine);
            this.Output.AppendText(result.ToString() + Environment.NewLine);
              }

              GetInstalledPackages();
        }
示例#4
0
        public InstallResult InstallAppx(string filepath)
        {
            var result = new InstallResult();

              try
              {
            var sb = new StringBuilder();
            sb.Append(@"add-appxpackage ");
            sb.Append(filepath);

            var process = new System.Diagnostics.Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.RedirectStandardOutput = true;

            process.StartInfo.FileName = "powershell.exe";
            process.StartInfo.Arguments = sb.ToString();

            process.StartInfo.CreateNoWindow = false;
            process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

            process.Start();

            var stdout = process.StandardOutput;
            var stderr = process.StandardError;

            result.Output = stdout.ReadToEnd();
            result.Error = stderr.ReadToEnd();

            if (!process.HasExited)
              process.Kill();

            stdout.Close();
            stderr.Close();
              }
              catch (Exception ex)
              {
            if (string.IsNullOrWhiteSpace(result.Error))
              result.Error = ex.Message;
            else
              result.Error += Environment.NewLine + ex.Message;
              }
              finally
              {
            File.Delete(filepath);
              }

              return result;
        }