示例#1
0
        public Executor(ExecutionParameters executionParameters, CheckAlg checkAlgorithm)
        {
            if (executionParameters.executionFilesPaths.Count <= 0)
            {
                throw new Exception("Не указано ни одного исполняемого файла!");
            }
            if (executionParameters.startParams.Count <= 0)
            {
                throw new Exception("Не указано ни одного параметра запуска!");
            }
            if (executionParameters.launchNum <= 0)
            {
                throw new Exception("Количество запусков должно быть больше нуля!");
            }
            if (executionParameters.variance < 0)
            {
                throw new Exception("Среднеквадратичное отклонение должно быть больше нуля!");
            }

            this.executionParameters = executionParameters;

            tasksNumber = executionParameters.executionFilesPaths.Count *
                          executionParameters.startParams.Count *
                          executionParameters.launchNum;
            if (executionParameters.textProgramFilesPaths.Count != 0)
            {
                tasksNumber *= executionParameters.textProgramFilesPaths.Count;
            }

            this.checkAlgorithm = checkAlgorithm;
        }
示例#2
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());
        }