Exemple #1
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            XMLProfileSettings profile         = new XMLProfileSettings();
            List <string>      checkName       = new List <string>();
            List <string>      checkDataFolder = new List <string>();
            List <string>      duplicateItems  = new List <string>();
            List <string>      checkDataPath   = new List <string>();
            bool duplicateName       = false;
            bool duplicateDataFolder = false;
            bool invalidDataPath     = false;

            //Check for null values, duplicate profile name or datapath and non rooted datapath
            foreach (ProfileItem item in comboBoxProfiles.Items)
            {
                if (item.Name == null || item.DataFolder == null)
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Warning;                     //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("One or more of your profile entries has a blank name or data folder. You must correct this before continuing.",
                                                        @"Warning - Blank Entries", false, false);
                    messageBox.ShowDialog();
                }

                if (checkName.Contains(item.Name))
                {
                    duplicateName = true;
                    duplicateItems.Add(item.Name + ":\t " + item.DataFolder);
                }
                checkName.Add(item.Name);

                if (checkDataFolder.Contains(item.DataFolder))
                {
                    duplicateDataFolder = true;
                    duplicateItems.Add(item.Name + ":\t " + item.DataFolder);
                }

                checkDataFolder.Add(item.DataFolder);

                if (!Path.IsPathRooted(item.DataFolder) || !item.DataFolder.Contains(@"\"))
                {
                    invalidDataPath = true;
                    checkDataPath.Add(item.Name + ":\t " + item.DataFolder);
                }
            }

            if (duplicateName || duplicateDataFolder)
            {
                //Not pretty here, but works well on the dialog
                //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                MessageBoxForm.msgIcon = SystemIcons.Warning;                 //this is used if you want to add a system icon to the message form.
                var messageBox = new MessageBoxForm("A duplicate profile name, or data path exists." + Environment.NewLine + Environment.NewLine +
                                                    @"The duplicate items found were:" + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, duplicateItems) + Environment.NewLine + Environment.NewLine +
                                                    @"Click OK to accept and continue, or Cancel to go back and edit.",
                                                    @"Warning - Duplicate Entries", false, true);
                messageBox.ShowDialog();

                if (messageBox.DialogResult != DialogResult.OK)
                {
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            if (invalidDataPath)
            {
                //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                MessageBoxForm.msgIcon = SystemIcons.Warning;                 //this is used if you want to add a system icon to the message form.
                var messageBox = new MessageBoxForm("An invalid profile data folder exists." + Environment.NewLine + Environment.NewLine +
                                                    @"The items with invalid paths were:" + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, checkDataPath) + Environment.NewLine + Environment.NewLine +
                                                    @"Click OK to accept and continue, or Cancel to go back and edit.",
                                                    @"Warning - Invalid Data Path", false, true);
                messageBox.ShowDialog();

                if (messageBox.DialogResult != DialogResult.OK)
                {
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            SaveCurrentItem();
            profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "ProfileCount", comboBoxProfiles.Items.Count);
            for (int i = 0; i < comboBoxProfiles.Items.Count; i++)
            {
                ProfileItem item = comboBoxProfiles.Items[i] as ProfileItem;
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + i + "/Name", item.Name);
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + i + "/DataFolder", item.DataFolder);
                if (!Directory.Exists(item.DataFolder))
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Exclamation;                     //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("The data directory '" + item.DataFolder + "' for profile '" + item.Name + "' does not exist.  Would you like to create it?",
                                                        Application.ProductName, true, false);
                    messageBox.ShowDialog();
                    if (messageBox.DialogResult == DialogResult.OK)
                    {
                        try
                        {
                            Directory.CreateDirectory(item.DataFolder);
                        }
                        catch (Exception)
                        {
                            //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                            MessageBoxForm.msgIcon = SystemIcons.Error;                             //this is used if you want to add a system icon to the message form.
                            messageBox             = new MessageBoxForm("Could not create new profile directory: " + item.DataFolder + Environment.NewLine + Environment.NewLine +
                                                                        "Click OK to ignore and continue, or Cancel to go back and edit.",
                                                                        "Error", false, true);
                            messageBox.ShowDialog();
                            if (messageBox.DialogResult == DialogResult.Cancel)
                            {
                                DialogResult = DialogResult.None;
                                return;
                            }
                        }
                    }
                }
            }

            profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "LoadAction",
                               radioButtonAskMe.Checked ? "Ask" : "LoadSelected");

            if (comboBoxLoadThisProfile.SelectedIndex >= 0)
            {
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "ProfileToLoad", comboBoxLoadThisProfile.SelectedIndex);
            }

            DialogResult = DialogResult.OK;
            Close();
        }
Exemple #2
0
        private void ProcessProfiles()
        {
            XMLProfileSettings profile = new XMLProfileSettings();

            // if we don't have any profiles yet, fall through so the "Default" profile will be created
            int profileCount = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "ProfileCount", 0);

            if (profileCount == 0)
            {
                return;
            }

            // now that we know we have profiles, get the rest of the settings
            string loadAction    = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "LoadAction", "LoadSelected");
            int    profileToLoad = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "ProfileToLoad", -1);

            // try to load the selected profile
            if (loadAction != "Ask" && profileToLoad > -1 && profileToLoad < profileCount)
            {
                string directory = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + profileToLoad + "/DataFolder", string.Empty);
                if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))
                {
                    _rootDataDirectory = directory;
                    string profileName = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + profileToLoad + "/Name", string.Empty);
                    UpdateTitleWithProfileName(profileName);
                }
                else
                {
                    string name = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + profileToLoad + "/Name", string.Empty);
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Error;                     //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("Selected profile '" + name + "' data directory does not exist!" + Environment.NewLine + Environment.NewLine +
                                                        directory + Environment.NewLine + Environment.NewLine +
                                                        "Select a different profile to load or use the Profile Editor to create a new profile.",
                                                        "Error", false, false);
                    messageBox.ShowDialog();
                }
            }

            // if _rootDataDirectory is still empty at this point either we're configured to always ask or loading the selected profile failed
            // keep asking until we get a good profile directory
            while (string.IsNullOrEmpty(_rootDataDirectory))
            {
                SelectProfile selectProfile = new SelectProfile();
                DialogResult  result        = selectProfile.ShowDialog();

                if (result == DialogResult.OK)
                {
                    string directory = selectProfile.DataFolder;
                    if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))
                    {
                        _rootDataDirectory = directory;
                        UpdateTitleWithProfileName(selectProfile.ProfileName);
                        break;
                    }
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Error;                     //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("The data directory for the selected profile does not exist!" + Environment.NewLine + Environment.NewLine +
                                                        directory + Environment.NewLine + Environment.NewLine +
                                                        "Select a different profile to load or use the Profile Editor to create a new profile.",
                                                        "Error", false, false);
                    messageBox.ShowDialog();
                }
                else if (result == DialogResult.Cancel)
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Warning;
                    var messageBox = new MessageBoxForm(Application.ProductName + " cannot continue without a vaild profile." + Environment.NewLine + Environment.NewLine +
                                                        "Are you sure you want to exit " + Application.ProductName + "?",
                                                        Application.ProductName, true, false);
                    messageBox.ShowDialog();
                    if (messageBox.DialogResult == DialogResult.OK)
                    {
                        Environment.Exit(0);
                    }
                }
                else
                {
                    // SelectProfile.ShowDialog() should only return DialogResult.OK or Cancel, how did we get here?
                    throw new NotImplementedException("SelectProfile.ShowDialog() returned " + result.ToString());
                }
            }

            SetLogFilePaths();
        }
Exemple #3
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            XMLProfileSettings profile         = new XMLProfileSettings();
            List <string>      checkName       = new List <string>();
            List <string>      checkDataFolder = new List <string>();
            List <string>      duplicateItems  = new List <string>();
            List <string>      checkDataPath   = new List <string>();
            bool duplicateName       = false;
            bool duplicateDataFolder = false;
            bool invalidDataPath     = false;

            //Check for null values, duplicate profile name or datapath and non rooted datapath
            foreach (ProfileItem item in comboBoxProfiles.Items)
            {
                if (item.Name == null || item.DataFolder == null)
                {
                    MessageBox.Show(
                        @"One or more of your profile entries has a blank name or data folder. You must correct this before continuing.",
                        @"Warning - Blank Entries", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                if (checkName.Contains(item.Name))
                {
                    duplicateName = true;
                    duplicateItems.Add(item.Name + ":\t " + item.DataFolder);
                }
                checkName.Add(item.Name);

                if (checkDataFolder.Contains(item.DataFolder))
                {
                    duplicateDataFolder = true;
                    duplicateItems.Add(item.Name + ":\t " + item.DataFolder);
                }

                checkDataFolder.Add(item.DataFolder);

                if (!Path.IsPathRooted(item.DataFolder) || !item.DataFolder.Contains(@"\"))
                {
                    invalidDataPath = true;
                    checkDataPath.Add(item.Name + ":\t " + item.DataFolder);
                }
            }

            if (duplicateName || duplicateDataFolder)
            {
                //Not pretty here, but works well on the dialog
                var result =
                    MessageBox.Show(
                        @"A duplicate profile name, or data path exists." + Environment.NewLine + Environment.NewLine +
                        @"The duplicate items found were:" + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, duplicateItems) + Environment.NewLine + Environment.NewLine +
                        @"Click OK to accept and contine, or Cancel to go back and edit.",
                        @"Warning - Duplicate Entries", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

                if (result != DialogResult.OK)
                {
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            if (invalidDataPath)
            {
                var result =
                    MessageBox.Show(
                        @"An invalid profile data folder exists." + Environment.NewLine + Environment.NewLine +
                        @"The items with invalid paths were:" + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, checkDataPath) + Environment.NewLine + Environment.NewLine +
                        @"Click OK to accept and contine, or Cancel to go back and edit.",
                        @"Warning - Invalid Data Path", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

                if (result != DialogResult.OK)
                {
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            SaveCurrentItem();
            profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "ProfileCount", comboBoxProfiles.Items.Count);
            for (int i = 0; i < comboBoxProfiles.Items.Count; i++)
            {
                ProfileItem item = comboBoxProfiles.Items[i] as ProfileItem;
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + i + "/Name", item.Name);
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + i + "/DataFolder", item.DataFolder);
                //We're getting out of here and expect a restart by user, if the specified DataFolder doesn't exist, we should create it.

                if (item.DataFolder != string.Empty)
                {
                    if (!Directory.Exists(item.DataFolder))
                    {
                        Directory.CreateDirectory(item.DataFolder);
                    }
                }
            }

            profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "LoadAction",
                               radioButtonAskMe.Checked ? "Ask" : "LoadSelected");

            if (comboBoxLoadThisProfile.SelectedIndex >= 0)
            {
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "ProfileToLoad", comboBoxLoadThisProfile.SelectedIndex);
            }

            DialogResult = DialogResult.OK;
            Close();
        }
Exemple #4
0
        private void ProcessProfiles()
        {
            XMLProfileSettings profile = new XMLProfileSettings();

            // if we don't have any profiles yet, fall through so the "Default" profile will be created
            int profileCount = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "ProfileCount", 0);

            if (profileCount == 0)
            {
                return;
            }

            // now that we know we have profiles, get the rest of the settings
            string loadAction    = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "LoadAction", "LoadSelected");
            int    profileToLoad = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "ProfileToLoad", -1);

            // try to load the selected profile
            if (loadAction != "Ask" && profileToLoad > -1 && profileToLoad < profileCount)
            {
                string directory = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + profileToLoad + "/DataFolder", string.Empty);
                var    isLocked  = IsProfileLocked(directory);
                if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory) && !isLocked)
                {
                    _rootDataDirectory = directory;
                    string profileName = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + profileToLoad + "/Name", string.Empty);
                    UpdateTitleWithProfileName(profileName);
                }
                else
                {
                    string name = profile.GetSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + profileToLoad + "/Name", string.Empty);
                    ShowLoadProfileErrorMessage(name, isLocked);
                }
            }

            // if _rootDataDirectory is still empty at this point either we're configured to always ask or loading the selected profile failed
            // keep asking until we get a good profile directory
            while (string.IsNullOrEmpty(_rootDataDirectory))
            {
                SelectProfile selectProfile = new SelectProfile();
                DialogResult  result        = selectProfile.ShowDialog();

                if (result == DialogResult.OK)
                {
                    string directory = selectProfile.DataFolder;
                    var    isLocked  = IsProfileLocked(directory);
                    if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory) && !isLocked)
                    {
                        _rootDataDirectory = directory;
                        UpdateTitleWithProfileName(selectProfile.ProfileName);
                        break;
                    }
                    ShowLoadProfileErrorMessage(selectProfile.ProfileName, isLocked);
                }
                else if (result == DialogResult.Cancel)
                {
                    var messageBox = new MessageBoxForm(Application.ProductName + " cannot continue without a vaild profile." + Environment.NewLine + Environment.NewLine +
                                                        "Are you sure you want to exit " + Application.ProductName + "?",
                                                        Application.ProductName, MessageBoxButtons.YesNo, SystemIcons.Warning);
                    messageBox.ShowDialog();
                    if (messageBox.DialogResult == DialogResult.OK)
                    {
                        Environment.Exit(0);
                    }
                }
                else
                {
                    // SelectProfile.ShowDialog() should only return DialogResult.OK or Cancel, how did we get here?
                    throw new NotImplementedException("SelectProfile.ShowDialog() returned " + result.ToString());
                }
            }

            SetLogFilePaths();
        }