Esempio n. 1
0
        // Website action changed events

        private void WebsiteUriTextChanged(object sender, TextChangedEventArgs e)
        {
            if (!eventBlock)
            {
                WebsiteAction action = (WebsiteAction)Shortcut.Actions[0];
                action.Url = WebsiteUriField.Text;
            }

            eventBlock = false;
        }
Esempio n. 2
0
        public static void ExecuteShortcut(Shortcut shortcut)
        {
            foreach (Action action in shortcut.Actions)
            {
                switch (action.Type)
                {
                case "command":
                    CommandAction ca = action as CommandAction;
                    System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                    if (!ca.KeepOpen)
                    {
                        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                        startInfo.Arguments   = $"/C {ca.Command}";
                    }
                    else
                    {
                        startInfo.Arguments = $"/k {ca.Command}";
                    }

                    startInfo.FileName = "cmd.exe";
                    process.StartInfo  = startInfo;
                    process.Start();
                    break;

                case "file":
                    FileAction fa = action as FileAction;
                    System.Diagnostics.Process.Start(fa.Path);
                    break;

                case "folder":
                    FolderAction foa = action as FolderAction;
                    System.Diagnostics.Process.Start(foa.Path);
                    break;

                case "software":
                    SoftwareAction sa = action as SoftwareAction;
                    System.Diagnostics.Process.Start(sa.Path);
                    break;

                case "website":
                    WebsiteAction wa = action as WebsiteAction;
                    System.Diagnostics.Process.Start(wa.Url);
                    break;
                }
            }
        }
Esempio n. 3
0
        private void SetFieldValuesFromShortcut()
        {
            eventBlock                         = true;
            ShortcutTitleName.Text             = $"{Enum.GetName(typeof(ShortcutType), ShortcutType)} Action";
            eventBlock                         = true;
            ShortcutTypeComboBox.SelectedIndex = (int)ShortcutType;

            switch (ShortcutType)
            {
            case ShortcutType.Web:
                WebsiteAction webaction = (WebsiteAction)Shortcut.Actions[0];
                eventBlock           = true;
                WebsiteUriField.Text = webaction.Url;
                eventBlock           = true;
                break;

            case ShortcutType.File:
                FileAction fileAction = (FileAction)Shortcut.Actions[0];
                eventBlock       = true;
                FileUi_Path.Text = fileAction.Path;
                break;

            case ShortcutType.Folder:
                FolderAction folderAction = (FolderAction)Shortcut.Actions[0];
                eventBlock         = true;
                FolderUi_Path.Text = folderAction.Path;
                break;

            case ShortcutType.Software:
                SoftwareAction softwareAction = (SoftwareAction)Shortcut.Actions[0];
                eventBlock           = true;
                SoftwareUi_Path.Text = softwareAction.Path;
                break;

            case ShortcutType.Command:
                CommandAction comaction = (CommandAction)Shortcut.Actions[0];
                eventBlock                   = true;
                CommandUi_Comand.Text        = comaction.Command;
                eventBlock                   = true;
                CommandUi_KeepOpen.IsChecked = comaction.KeepOpen;
                break;
            }

            eventBlock = false;
        }
Esempio n. 4
0
        public ValidationError IsValid()
        {
            if (string.IsNullOrEmpty(Name))
            {
                return(new ValidationError("Shortcut Name Cannot be Empty.", this));
            }

            foreach (Action action in Actions)
            {
                switch (action.Type)
                {
                case "command":
                    CommandAction   a1    = action as CommandAction;
                    ValidationError a1Err = a1.IsValid();
                    if (a1Err != null)
                    {
                        a1Err.Shortcut = this;
                        return(a1Err);
                    }

                    break;

                case "file":
                    FileAction      a2    = action as FileAction;
                    ValidationError a2Err = a2.IsValid();
                    if (a2Err != null)
                    {
                        a2Err.Shortcut = this;
                        return(a2Err);
                    }

                    break;

                case "folder":
                    FolderAction    a3    = action as FolderAction;
                    ValidationError a3Err = a3.IsValid();
                    if (a3Err != null)
                    {
                        a3Err.Shortcut = this;
                        return(a3Err);
                    }

                    break;

                case "software":
                    SoftwareAction  a4    = action as SoftwareAction;
                    ValidationError a4Err = a4.IsValid();
                    if (a4Err != null)
                    {
                        a4Err.Shortcut = this;
                        return(a4Err);
                    }

                    break;

                case "website":
                    WebsiteAction   a5    = action as WebsiteAction;
                    ValidationError a5Err = a5.IsValid();
                    if (a5Err != null)
                    {
                        a5Err.Shortcut = this;
                        return(a5Err);
                    }

                    break;
                }
            }

            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// Starts or stops website on the remote server.
        /// </summary>
        /// <param name="windowHandle"></param>
        /// <param name="psExecPath"></param>
        /// <param name="serverName"></param>
        /// <param name="websites"></param>
        /// <param name="action"></param>
        /// <param name="waitForExit"></param>
        /// <returns></returns>
        public static Process StartOrStopWebsites(IntPtr windowHandle, string psExecPath, string serverName, IEnumerable<string> websites, WebsiteAction action, NetworkCredential credential = null, bool waitForExit = true)
        {
            if (serverName.Equals("localhost", StringComparison.CurrentCultureIgnoreCase))
            {
                StartOrStopWebsites(windowHandle, websites, action);
                return null;
            }
            else
            {
                if (!File.Exists(psExecPath) || !websites.Any())
                {
                    return null;
                }

                var psExecFile = new FileInfo(psExecPath);
                var currentDir = Environment.CurrentDirectory;
                Environment.CurrentDirectory = psExecFile.Directory.FullName;                

                // Generate the batch file that will contain the commands
                var batchFileName = "Websites.bat";
                var batchFilePath = Path.Combine(psExecFile.Directory.FullName, batchFileName);
                var sb = new StringBuilder(@"SET APPCMD=%windir%\system32\inetsrv\appcmd.exe");
                sb.AppendLine();
                foreach (var website in websites)
                {
                    if (action == WebsiteAction.Recycle || action == WebsiteAction.Stop)
                    {
                        sb.AppendFormat("%APPCMD% stop sites \"{0}\"\r\n", website);
                    }
                    if (action == WebsiteAction.Recycle || action == WebsiteAction.Start)
                    {
                        sb.AppendFormat("%APPCMD% start sites \"{0}\"\r\n", website);
                    }
                }
                File.WriteAllText(batchFilePath, sb.ToString());

                string cmdParameters = string.Empty;
                if (credential == null)
                {
                    cmdParameters = string.Format(@"\\{0} -c {1}", serverName, batchFileName);
                }
                else
                {
                    cmdParameters = string.Format(@"\\{0} -c {1} -u {2} -p {3}", serverName, credential.UserName, credential.Password, batchFileName);
                }

                var info = new ProcessStartInfo(psExecFile.Name, cmdParameters);
                info.WorkingDirectory = Environment.CurrentDirectory;
                info.WindowStyle = ProcessWindowStyle.Normal;
                info.CreateNoWindow = false;
                if (windowHandle != IntPtr.Zero)
                {
                    info.ErrorDialogParentHandle = windowHandle;
                }
                var process = Process.Start(info);
                if (waitForExit)
                {
                    process.WaitForExit();
                    // If there were no errors, delete the batch file.
                    if (process.ExitCode == 0)
                    {
                        File.Delete(batchFilePath);
                    }
                }

                Environment.CurrentDirectory = currentDir;
                return process;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Starts or stops websites on the local IIS.
        /// </summary>
        /// <param name="windowHandle"></param>
        /// <param name="websites"></param>
        /// <param name="waitForExit"></param>
        /// <returns></returns>
        public static string[] StartOrStopWebsites(IntPtr windowHandle, IEnumerable<string> websites, WebsiteAction action)
        {
            var successSites = new List<string>(websites);
            var matchingSites = new List<Site>(websites.Count());
            var targetWebsites = websites.ToList();
            foreach (var s in ServerManager.Sites)
            {
                if (targetWebsites.Contains(s.Name, StringComparer.OrdinalIgnoreCase))                
                {
                    matchingSites.Add(s);
                }
            }

            foreach (var site in matchingSites)
            {
                var state = ObjectState.Stopped;
                if (action == WebsiteAction.Recycle || action == WebsiteAction.Stop)
                {
                    site.Stop();                    
                }
                if (site.State == ObjectState.Stopped)
                {
                    if (action == WebsiteAction.Stop)
                    {
                        successSites.Add(site.Name);
                    }

                    if (action == WebsiteAction.Recycle || action == WebsiteAction.Start)
                    {
                        site.Start();
                        if (site.State == ObjectState.Started)
                        {
                            successSites.Add(site.Name);
                        }
                    }
                }
            }

            return successSites.ToArray();
        }
Esempio n. 7
0
        private void SetFieldValuesFromShortcut()
        {
            eventBlock                         = true;
            ShortcutNameField.Text             = Shortcut.Name;
            ShortcutTitleName.Text             = Shortcut.Name;
            eventBlock                         = true;
            ShortcutTypeComboBox.SelectedIndex = (int)ShortcutType;
            if (!string.IsNullOrEmpty(Shortcut.IconPath))
            {
                if (!File.Exists(Shortcut.IconPath))
                {
                    Shortcut.IconPath    = string.Empty;
                    ShotcutNameText.Text = "No icon selected.";
                }
                else
                {
                    ShotcutNameText.Text = Path.GetFileName(Shortcut.IconPath);
                }
            }
            else
            {
                ShotcutNameText.Text = "No icon selected.";
            }

            switch (ShortcutType)
            {
            case ShortcutType.Web:
                WebsiteAction webaction = (WebsiteAction)Shortcut.Actions[0];
                eventBlock           = true;
                WebsiteUriField.Text = webaction.Url;
                eventBlock           = true;
                break;

            case ShortcutType.File:
                FileAction fileAction = (FileAction)Shortcut.Actions[0];
                eventBlock       = true;
                FileUi_Path.Text = fileAction.Path;
                break;

            case ShortcutType.Folder:
                FolderAction folderAction = (FolderAction)Shortcut.Actions[0];
                eventBlock         = true;
                FolderUi_Path.Text = folderAction.Path;
                break;

            case ShortcutType.Software:
                SoftwareAction softwareAction = (SoftwareAction)Shortcut.Actions[0];
                eventBlock           = true;
                SoftwareUi_Path.Text = softwareAction.Path;
                break;

            case ShortcutType.Command:
                CommandAction comaction = (CommandAction)Shortcut.Actions[0];
                eventBlock                   = true;
                CommandUi_Comand.Text        = comaction.Command;
                eventBlock                   = true;
                CommandUi_KeepOpen.IsChecked = comaction.KeepOpen;
                break;

            case ShortcutType.Multi:
                break;
            }

            eventBlock = false;
        }