Пример #1
0
        private void ProcessTAN()
        {
            //Process TAN file
            CompleteErrorList.Add(startTanFile + openFileDialog1.SafeFileName);
            TaskAllocations.TryParse(openFileDialog1.FileName, out aTaskAllocation);
            if (aTaskAllocation.AllocationErrorList != null)
            {
                UpdateErrors(aTaskAllocation.AllocationErrorList);
            }
            CompleteErrorList.Add(endTanFile + openFileDialog1.SafeFileName);

            if (aTaskAllocation.isValid)
            {
                fileValiditys += tanFileValid;
            }
            else
            {
                fileValiditys += tanFileInvalid;
            }

            //Get directory of TAN file and add config path
            string directoryPath  = Path.GetDirectoryName(openFileDialog1.FileName);
            string configFullPath = directoryPath + "\\" + aTaskAllocation.ConfigPath;

            if (aTaskAllocation.ConfigPath != null)
            {
                ProcessConfig(configFullPath);
            }

            if (aTaskAllocation.isValid == true && aConfiguration.isValid == true)
            {
                allocationsToolStripMenuItem.Enabled = true;
            }
            else
            {
                allocationsToolStripMenuItem.Enabled = false;
            }

            //Update text
            label1.Text  = "";
            label1.Text += fileValiditys;
            foreach (Allocation al in aTaskAllocation.SetOfAllocations)
            {
                label1.Text += string.Format(allocationDisplayString, al.ID);
                label1.Text += al.MatrixToString();
            }
        }
Пример #2
0
        /// <summary>
        /// Determines if a .tan file is valid and parses the data to an instance of TaskAllocation
        /// </summary>
        /// <param name="path">A string containg the filepath of a .tan file</param>
        /// <param name="anAllocation">An instance of TaskAllocation that is populated with data from the .tan file being parsed</param>
        /// <returns>A bool depending on if the file is valid and error free.</returns>
        public static bool TryParse(string path, out TaskAllocations anAllocation)
        {
            anAllocation = new TaskAllocations(path);
            List <String> ParsingErrorList = new List <string>();

            anAllocation.SetOfAllocations = new List <Allocation>();

            Regex seperatorRegex = new Regex(seperatorPattern);

            //Begin parsing TAN file
            StreamReader file = new StreamReader(path);

            while (!file.EndOfStream)
            {
                string          line           = file.ReadLine();
                MatchCollection seperatorMatch = seperatorRegex.Matches(line);

                if (line.Length == 0)
                {
                }
                else if (line.Contains(comment))
                {
                    if (line.StartsWith(comment))
                    {
                        //Comment Found
                    }
                    else
                    {
                        ParsingErrorList.Add(commentLineError + line);
                    }
                }
                else if (seperatorMatch.Count == 0)
                {
                    ParsingErrorList.Add(invalidSeperatorError + line);
                }
                else if (line.Contains(anAllocation.configPathKey))
                {
                    string[] substrings = line.Split(delimiter);

                    //Check Line is valid and only contains expected number of arguements
                    if (substrings[0] == anAllocation.configPathKey && substrings.Count() == 2)
                    {
                        string configPath = substrings[1].Replace(doubleQuote, emptySpace);
                        anAllocation.ConfigPath = configPath;
                    }
                    else
                    {
                        ParsingErrorList.Add(invalidLineError + line);
                    }
                }
                else if (line.Contains(anAllocation.tasksKey))
                {
                    string[] substrings = line.Split(delimiter);
                    int      input      = ToInt32(substrings[1]);

                    if (input == -1)
                    {
                        ParsingErrorList.Add(stringToIntError + line);
                    }
                    else
                    {
                        anAllocation.Tasks = input;
                    }
                }
                else if (line.Contains(anAllocation.processorsKey))
                {
                    string[] substrings = line.Split(delimiter);

                    int input = ToInt32(substrings[1]);
                    if (input == -1)
                    {
                        string error = stringToIntError + line;
                        ParsingErrorList.Add(error);
                    }
                    else
                    {
                        anAllocation.Processors = input;
                    }
                }
                else if (line.Contains(anAllocation.allocationsKey))
                {
                    string[] substrings = line.Split(delimiter);
                    int      input      = ToInt32(substrings[1]);
                    if (input == -1)
                    {
                        string error = stringToIntError + line;
                        ParsingErrorList.Add(error);
                    }
                    else
                    {
                        anAllocation.NumAllocations = input;
                    }
                }
                else if (line.Contains(anAllocation.allocationIDKey))
                {
                    string[] substrings = line.Split(delimiter);
                    int      id         = ToInt32(substrings[1]);
                    if (id == -1)
                    {
                        string error = stringToIntError + line;
                        ParsingErrorList.Add(error);
                    }

                    List <String> allocationMatrix = new List <string>();

                    while (line.Length != 0)
                    {
                        line = file.ReadLine();

                        if (line != emptySpace && line != null)
                        {
                            allocationMatrix.Add(line);
                        }
                        else
                        {
                            break;
                        }
                    }

                    Allocation aAllocation = new Allocation(id, allocationMatrix);
                    anAllocation.SetOfAllocations.Add(aAllocation);
                }
                else
                {
                    string error = invalidLineError + line;
                    ParsingErrorList.Add(error);
                }
            }
            file.Close();

            //Add parsing errors to instance error list
            anAllocation.AllocationErrorList.AddRange(ParsingErrorList);

            //Check validity of file
            anAllocation.isValid = (anAllocation.Validate() && ParsingErrorList.Count == 0);

            return(ParsingErrorList.Count == 0);
        }