Ejemplo n.º 1
0
        private void InitializeProfiles(bool reload = false)
        {
            var errors = new StringBuilder();

            cbProfiles.Items.Clear();
            cbProfiles.Items.Add("Select or add a profile");
            foreach (var profileFile in
                     Directory.GetFiles(Paths.ProfilePath, Vendor.All + Vendor.ProfileExtension).Where(
                         profileFile => Path.GetExtension(profileFile) == Vendor.ProfileExtension))
            {
                try {
                    var nativeIO = FileIOHelper.GetNativeHelper();
                    cbProfiles.Items.Add(nativeIO.OpenProfile(profileFile));
                }
                catch (XmlException e) {
                    errors.AppendLine(string.Format("{0}\nFailed to load because: {1}\n", profileFile, e.Message));
                }
            }

            if (errors.Length <= 0 || _suppressErrors || reload)
            {
                return;
            }

            errors.AppendLine(
                "You will continue to see this message until the offending files are fixed, moved or deleted. You can also supress this message in preferences by selecting 'Silence profile editor errors'");
            MessageBox.Show(errors.ToString(), "Errors loading some profiles");
        }
Ejemplo n.º 2
0
        private void AddProfile(Profile profileData = null)
        {
            var isNew = profileData == null;

            var newName = GetFileName("Profile Name", Paths.ProfilePath, new[] { Vendor.ProfileExtension }, "", "Create");

            if (string.Empty == newName)
            {
                return;
            }

            var root = (null != _contextProfile && _contextProfile.FileName != null)
                ? Path.GetDirectoryName(_contextProfile.FileName) ?? Paths.ProfilePath : Paths.ProfilePath;

            var newFileName = Path.Combine(root, newName + Vendor.ProfileExtension);

            DeleteIfExists(newFileName);

            var profile = isNew ? new Profile() : profileData;

            profile.FileName      = newFileName;
            profile.Name          = newName;
            profile.FileIOHandler = FileIOHelper.GetNativeHelper();
            SaveProfile(profile);

            RefreshProfileComboBox(newName);
        }
Ejemplo n.º 3
0
        private void buttonImportChannels_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var fileIO   = FileIOHelper.GetNativeHelper();
            var sequence = fileIO.OpenSequence(openFileDialog.FileName);

            textBoxChannelCount.Text = sequence.FullChannelCount.ToString(CultureInfo.InvariantCulture);
            var builder = new StringBuilder();

            foreach (var channel in sequence.FullChannels)
            {
                builder.AppendLine(channel.Name);
            }
            textBoxChannelNames.Text = builder.ToString();
            _eventSequence.FullChannels.Clear();
            _eventSequence.FullChannels.AddRange(sequence.FullChannels);
        }
Ejemplo n.º 4
0
        private void tabControl_Deselecting(object sender, TabControlCancelEventArgs e)
        {
            if (!_back)
            {
                _history.Push(e.TabPageIndex);
                buttonPrev.Enabled = true;
            }

            if (_skip)
            {
                return;
            }

            var errorText = string.Empty;

            switch (e.TabPageIndex)
            {
            case TabEventPeriod: {
                int eventPeriod;
                if (int.TryParse(textBoxEventPeriod.Text, out eventPeriod))
                {
                    if (eventPeriod < Vendor.MinimumEventPeriod)
                    {
                        errorText = String.Format(Resources.EventPeriodTooShort, Vendor.MinimumEventPeriod);
                        textBoxEventPeriod.Text = Vendor.MinimumEventPeriod.ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        _eventSequence.EventPeriod = eventPeriod;
                    }
                }
                else
                {
                    errorText = textBoxChannelCount.Text + Resources.EventPeriodInvalid;
                }
                break;
            }

            case TabProfile:
                if (comboBoxProfiles.SelectedIndex == 0)
                {
                    _eventSequence.FileIOHandler = FileIOHelper.GetNativeHelper();
                    _eventSequence.Profile       = null;
                }
                else
                {
                    var profilePath = Path.Combine(Paths.ProfilePath, comboBoxProfiles.SelectedItem + ".pro");
                    _eventSequence.FileIOHandler = FileIOHelper.GetProfileVersion(profilePath);
                    _eventSequence.Profile       = _eventSequence.FileIOHandler.OpenProfile(profilePath);
                }

                if (_eventSequence.Profile != null)
                {
                    _eventSequence.Groups = _eventSequence.Profile.Groups;
                }
                break;

            case TabChannelCount: {
                int channelCount;
                if (int.TryParse(textBoxChannelCount.Text, out channelCount))
                {
                    if (channelCount < 1)
                    {
                        errorText = Resources.ChannelCountMinimums;
                    }
                    else
                    {
                        if ((channelCount > 1024) &&
                            (MessageBox.Show(string.Format(Resources.ConfirmChannelCount, channelCount), Vendor.ProductName,
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes))
                        {
                            tabControl.TabIndex = 1;
                        }
                        else
                        {
                            Cursor = Cursors.WaitCursor;
                            try {
                                _eventSequence.FullChannelCount = channelCount;
                            }
                            finally {
                                Cursor = Cursors.Default;
                            }
                        }
                    }
                }
                else
                {
                    errorText = textBoxChannelCount.Text + Resources.InvalidChannelCount;
                }
                break;
            }

            case TabChannelNames:
                if (textBoxChannelNames.Lines.Length == Convert.ToInt32(textBoxChannelCount.Text))
                {
                    if (textBoxChannelNames.Lines.Any(str2 => str2.Trim() == string.Empty))
                    {
                        errorText = Resources.ChannelNameCantBeBlank;
                    }
                    Cursor = Cursors.WaitCursor;
                    try {
                        for (var i = 0; i < _eventSequence.FullChannelCount; i++)
                        {
                            _eventSequence.FullChannels[i].Name = textBoxChannelNames.Lines[i];
                        }
                    }
                    finally {
                        Cursor = Cursors.Default;
                    }
                    break;
                }
                errorText = Resources.ChannelCountAndNameInequal;
                break;

            case TabSequenceTime: {
                var sequenceTimeInMills = ParseTimeString(textBoxTime.Text);
                if (sequenceTimeInMills != 0)
                {
                    _eventSequence.Time = sequenceTimeInMills;
                }
                else
                {
                    errorText = "Bad time format";
                }
                break;
            }
            }

            if (errorText == string.Empty)
            {
                return;
            }
            e.Cancel = true;
            MessageBox.Show(errorText, Vendor.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }