public static void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            FormPublisher formPublisher = ((FormPublisher)Form.ActiveForm);

            formPublisher.CursorChange();
            formPublisher.btnLocate.Menu.Close();
            AdditionalFunctionality.Locate(e.ClickedItem.ToString());
            formPublisher.CursorChange();
        }
Beispiel #2
0
        /// <summary>
        /// Checks whether the listed directories in all TextBoxes exist and alerts the user and stops execution if any do not.
        /// </summary>
        /// <returns>
        /// "True" if all directories exist, otherwise "False".
        /// </returns>
        public static bool DirectoriesExist()
        {
            //This list will hold all text boxes whose listed directories do not exist.
            List <TextBox> tbDoesNotExistList = new List <TextBox>();

            //For each TextBox we check if its listed directory exists and add it to the list if it does not.
            foreach (var tb in allTextBoxes)
            {
                //A new task is started asynchronously that checks if the given directory exists.
                //If the task does not return a result after one second or returns that the
                //directory does not exist the TextBox with said directory path is added to the list.
                var task = new System.Threading.Tasks.Task <bool>(() => { return(Directory.Exists(tb.Text)); });
                task.Start();

                if (!(task.Wait(1000) && task.Result))
                {
                    tbDoesNotExistList.Add(tb);
                }
            }

            //If all directories exist we continue.
            if (tbDoesNotExistList.Count == 0)
            {
                return(true);
            }

            //For user-friendlyness-ness-ness-ness we format the shown error in singular or plural case.
            if (tbDoesNotExistList.Count == 1)
            {
                //If the folder that does not exist is the QA one we prompt the user to create it.
                if (tbDoesNotExistList[0] == formPublisher.tbQAFolderPath)
                {
                    DialogResult create = MessageBox.Show("The directory for " + StringOperations.NameReplace(tbDoesNotExistList[0]) + " does not exist.\nWould you like to create it?" + "\n\nOperation will continue if either \"Yes\" or \"No\" are chosen.", "Path error", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Error);
                    if (create == DialogResult.Yes) //User chose to create the directory.
                    {
                        return(AdditionalFunctionality.CreateQAFolder());
                    }
                    else if (create == DialogResult.Cancel) //User chose to abort the operation.
                    {
                        return(false);
                    }
                    else //User chose not to create the direcotry.
                    {
                        return(true);
                    }
                }
                else
                {
                    MessageBox.Show("The directory for " + StringOperations.NameReplace(tbDoesNotExistList[0]) + " does not exist.\nPlease, check that the path is correct.", "Path error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }
            else if (tbDoesNotExistList.Count > 1)
            {
                StringBuilder stringBuilder = new StringBuilder("The directories for the following do not exist:" + Environment.NewLine + Environment.NewLine);
                foreach (var txtb in tbDoesNotExistList)
                {
                    stringBuilder.AppendLine(StringOperations.NameReplace(txtb));
                }
                stringBuilder.Append(Environment.NewLine + "Please, check that the paths are correct.");
                if (tbDoesNotExistList.Contains(formPublisher.tbQAFolderPath))
                {
                    stringBuilder.AppendLine(Environment.NewLine + "The QA Folder can be automatically created but the other paths need to be corrected, first.");
                }
                MessageBox.Show(stringBuilder.ToString(), "Path error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }