Ejemplo n.º 1
0
 public Main()
 {
     InitializeComponent();
     //DataBase.Create();
     windowVars = ReadSettingsFile(settingsPath);
     InitFields();
 }
Ejemplo n.º 2
0
        private void загрузитьКонфигурациюToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog OFD = new OpenFileDialog
            {
                Title           = "Выберите файл с конфигурацией.",
                CheckFileExists = true,
                Filter          = "Конфигурация|*.ASconfig"
            };

            if (OFD.ShowDialog() != DialogResult.OK || OFD.FileName == String.Empty)
            {
                return;
            }
            windowVars = ReadSettingsFile(OFD.FileName);
            InitFields();
        }
Ejemplo n.º 3
0
        private Executor.ExecutionParameters ReadSettingsFile(string path)
        {
            if (!File.Exists(path))
            {
                return(new Executor.ExecutionParameters());
            }

            try
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    BinaryFormatter formatter          = new BinaryFormatter();
                    Executor.ExecutionParameters state = (Executor.ExecutionParameters)formatter.Deserialize(fs);

                    if (state.launchNum <= 0)
                    {
                        state.launchNum = 1;
                    }
                    if (state.variance < 0)
                    {
                        state.variance = 0.0005f;
                    }
                    if (state.backProcLimit <= 0 || state.backProcLimit > 100)
                    {
                        state.backProcLimit = 100;
                    }

                    if (state.executionFilesPaths == null)
                    {
                        state.executionFilesPaths = new List <string>();
                    }
                    List <string> removePathList = new List <string>();
                    foreach (string executionFile in state.executionFilesPaths)
                    {
                        if (String.IsNullOrEmpty(executionFile) || !File.Exists(executionFile))
                        {
                            removePathList.Add(executionFile);
                        }
                    }
                    foreach (string executionFile in removePathList)
                    {
                        state.executionFilesPaths.Remove(executionFile);
                    }

                    if (state.textProgramFilesPaths == null)
                    {
                        state.textProgramFilesPaths = new List <string>();
                    }
                    removePathList = new List <string>();
                    foreach (string programPath in state.textProgramFilesPaths)
                    {
                        if (String.IsNullOrEmpty(programPath) || !File.Exists(programPath))
                        {
                            removePathList.Add(programPath);
                        }
                    }
                    foreach (string programPath in removePathList)
                    {
                        state.textProgramFilesPaths.Remove(programPath);
                    }

                    if (state.interprParams == null)
                    {
                        state.interprParams = new List <string>();
                    }
                    if (state.startParams == null)
                    {
                        state.startParams = new List <string>();
                    }
                    if (state.referenceResults == null)
                    {
                        state.referenceResults = new List <string>();
                    }

                    while (state.referenceResults.Count < state.startParams.Count)
                    {
                        state.referenceResults.Add("");
                    }

                    while (state.interprParams.Count < state.startParams.Count)
                    {
                        state.interprParams.Add("");
                    }

                    List <int> removeIndexList = new List <int>();
                    for (var i = 0; i < state.startParams.Count; ++i)
                    {
                        if (String.IsNullOrEmpty(state.startParams[i]))
                        {
                            removeIndexList.Add(i);
                        }
                        else
                        {
                            if (String.IsNullOrEmpty(state.referenceResults[i]))
                            {
                                state.referenceResults[i] = "";
                            }
                            if (String.IsNullOrEmpty(state.interprParams[i]))
                            {
                                state.interprParams[i] = "";
                            }
                        }
                    }
                    for (var j = removeIndexList.Count - 1; j >= 0; --j)
                    {
                        state.startParams.RemoveAt(removeIndexList[j]);
                        state.referenceResults.RemoveAt(removeIndexList[j]);
                        state.interprParams.RemoveAt(removeIndexList[j]);
                    }

                    if (String.IsNullOrEmpty(state.checkAlgorithmText))
                    {
                        state.checkAlgorithmText = CheckAlg.defaultAlg;
                        state.checkAlgorithmText = "";
                        state.checkAlgorithmText = "";
                    }

                    try
                    {
                        checkAlgorithm = new CheckAlg(state.checkAlgorithmUsingsText, state.checkAlgorithmClassesText, state.checkAlgorithmText);
                    }
                    catch (Exception)
                    {
                        state.checkAlgorithmText = CheckAlg.defaultAlg;
                        state.checkAlgorithmText = "";
                        state.checkAlgorithmText = "";
                        checkAlgorithm           = new CheckAlg();
                    }

                    return(state);
                }
            }
            catch (Exception exc)
            {
                ShowError("Файл настроек повреждён.\n", exc);
            }
            return(new Executor.ExecutionParameters());
        }