コード例 #1
0
        string GetNewMetaschemeFilePath(MetaschemeFileInfo metaschemeFileInfo, bool useGenericName, int index = 0)
        {
            string newFilePath = null;

            string nameString = useGenericName ? "RandomScheme" : Path.GetFileNameWithoutExtension(metaschemeFileInfo.FullPath);
            string dateString = DateTime.Now.ToString("yyyMMdd");

            while (index++ < 99)
            {
                string newFilename = String.Format("{0}_{1}_{2}.wsc", dateString, nameString, index.ToString("D2"));
                newFilePath = Path.Combine(Settings.Default.OutputDirectory, newFilename);

                if (!File.Exists(newFilePath))
                {
                    return(newFilePath);
                }
            }

            return(newFilePath);
        }
コード例 #2
0
        private void metaschemesListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            generateButton.Enabled = metaschemesListBox.SelectedIndices.Count > 0;

            MetaschemeFileInfo metaschemeFileInfo = null;

            if (metaschemesListBox.SelectedIndex >= 0)
            {
                metaschemeFileInfo = (MetaschemeFileInfo)metaschemesListBox.Items[metaschemesListBox.SelectedIndex];
            }

            if (metaschemeFileInfo != null)
            {
                metaschemeNameLabel.Text          = metaschemeFileInfo.DisplayName;
                metaschemeAuthorLabel.Text        = metaschemeFileInfo.AuthorName;
                metaschemeDescriptionTextBox.Text = metaschemeFileInfo.Description;
            }
            else
            {
                metaschemeNameLabel.Text          = "";
                metaschemeAuthorLabel.Text        = "";
                metaschemeDescriptionTextBox.Text = "";
            }
        }
コード例 #3
0
        private void generateButton_Click(object sender, EventArgs e)
        {
            if (metaschemesListBox.SelectedItems.Count == 0)
            {
                MessageBox.Show(this, "No metaschemes selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (String.IsNullOrEmpty(Settings.Default.OutputDirectory))
            {
                MessageBox.Show(this, "No output directory specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MetaschemeFileInfo[] metaschemeFileInfos = metaschemesListBox.SelectedItems.Cast <MetaschemeFileInfo>().ToArray();

            int?         randomSeed     = GetRandomSeed();
            bool         isUsingSetSeed = randomSeed.HasValue;
            Random       rng            = randomSeed.HasValue ? new Random(randomSeed.Value) : new Random();
            StringWriter stringWriter   = new StringWriter();

            for (int i = 0; i < (int)numberOfSchemesUpDown.Value; ++i)
            {
                int metaSchemeIndex = i % (int)metaschemeFileInfos.Length;

                //Shuffle once we've added one of each.
                if (metaSchemeIndex == 0)
                {
                    for (int j = metaschemeFileInfos.Length - 1; j >= 1; --j)
                    {
                        int randomIndex         = rng.Next(j);
                        MetaschemeFileInfo temp = metaschemeFileInfos[j];
                        metaschemeFileInfos[j]           = metaschemeFileInfos[randomIndex];
                        metaschemeFileInfos[randomIndex] = temp;
                    }
                }

                MetaschemeFileInfo metaschemeFileInfo = metaschemeFileInfos[metaSchemeIndex];
                if (metaschemeFileInfo == null)
                {
                    continue;
                }

                string outputPath = GetNewMetaschemeFilePath(metaschemeFileInfo, useGenericNameCheckBox.Checked, i / metaschemeFileInfos.Length);

                try
                {
                    SchemeGen2.SchemeGen2.Generate(metaschemeFileInfo.FullPath, GetSchemeVersion(), outputPath, randomSeed, stringWriter);
                }
                catch (Exception ex)
                {
                    stringWriter.WriteLine("Exception occurred while writing to file {0}: {1}\r\nStack:\r\n{2}", outputPath, ex.Message, ex.StackTrace);
                }

                //Ensure next scheme doesn't use the same seed.
                if (!isUsingSetSeed)
                {
                    randomSeed = rng.Next();
                }
            }

            //Output to message log.
            string messageLogString = stringWriter.ToString();

            if (_currentMessageLog == null)
            {
                if (!String.IsNullOrEmpty(messageLogString))
                {
                    _currentMessageLog              = new MessageLog(messageLogString);
                    _currentMessageLog.FormClosing += delegate(object o, FormClosingEventArgs ee) { _currentMessageLog = null; };
                    _currentMessageLog.Show();
                }
            }
            else
            {
                _currentMessageLog.UpdateMessage(!String.IsNullOrEmpty(messageLogString) ? messageLogString : "Scheme(s) generated successfully.");
            }

            stringWriter.Close();
        }