Beispiel #1
0
        public void ScanErrors(
            int count,
            int numberOfTasks,
            int numberOfProcessers,
            KeywordPair allocationPair,
            string taffFilename,
            Validations validations)
        {
            // Check TASKS, COUNT and PROCESSORS
            bool countExists = validations.CheckRequiredValueExist(
                count.ToString(),
                TaffKeywords.ALLOCATIONS_COUNT);
            bool taskExists = validations.CheckRequiredValueExist(
                numberOfTasks.ToString(),
                TaffKeywords.ALLOCATIONS_TASKS);
            bool processorsExists = validations.CheckRequiredValueExist(
                numberOfProcessers.ToString(),
                TaffKeywords.ALLOCATIONS_PROCESSORS);

            // Checking whether the number of allocation is the same as the defined COUNT
            if (countExists && taskExists && processorsExists)
            {
                validations.CheckValidQuantity(
                    allocationPair.CalculateNumOfPair().ToString(),
                    count.ToString(),
                    TaffKeywords.OPENING_ALLOCATION,
                    ErrorCode.MISSING_SECTION);

                validations.CheckValidQuantity(
                    Allocations.Count.ToString(),
                    count.ToString(),
                    TaffKeywords.OPENING_ALLOCATION,
                    ErrorCode.MISSING_SECTION);
            }
        }
        public bool ValidateFile(string taffFilename, Validations validations)
        {
            if (taffFilename == null)
            {
                return(false);
            }

            int beforeNumOfError, afterNumOfError;

            beforeNumOfError = validations.ErrorValidationManager.Errors.Count;
            TaffFilename     = taffFilename;

            // Extract and validate the configuration data section
            GetCffFilename(taffFilename, validations);

            // Validate the rest of the taff file
            KeywordPair allocationPair = new KeywordPair(
                TaffKeywords.OPENING_ALLOCATION,
                TaffKeywords.CLOSING_ALLOCATION);
            PairSection openClosingAllocations = new PairSection(
                TaffKeywords.OPENING_ALLOCATIONS,
                TaffKeywords.CLOSING_ALLOCATIONS);
            StreamReader    streamReader    = new StreamReader(taffFilename);
            TaffAllocations taffAllocations = new TaffAllocations();
            int             lineNumber      = 1;
            string          line;

            validations.Filename = taffFilename;

            while (!streamReader.EndOfStream)
            {
                line = streamReader.ReadLine();
                line = line.Trim();
                validations.LineNumber = lineNumber.ToString();

                // Check if keyword is valid or not
                validations.CheckValidKeyword(line, TaffKeywords.KEYWORD_DICT);

                // Count Allocation Section
                allocationPair.CheckValidKeyword(line);

                // Check whether the line starts Opening/Closing Allocations section
                // If yes, mark it exist
                openClosingAllocations.MarkSection(line, lineNumber);

                // Validate and extract data in the Allocations section
                if (openClosingAllocations.ValidSectionPair[0] &&
                    !openClosingAllocations.ValidSectionPair[1])
                {
                    // Check whether Allocations section exists and
                    // whether line strt with the expected keyword, "COUNT", "TASKS"
                    // and "PROCESSORS"
                    Count              = taffAllocations.ExtractCount(Count, line, validations);
                    NumberOfTasks      = taffAllocations.ExtractNumOfTasks(NumberOfTasks, line, validations);
                    NumberOfProcessors = taffAllocations.ExtractNumOfProcessors(NumberOfProcessors, line, validations);

                    // Check whether the reader goes within the Allocation section
                    taffAllocations.MarkInsideAllocation(line, lineNumber, validations);

                    // Extract new allocation
                    Allocation newAllocation = taffAllocations.ExtractAllocation(line, NumberOfProcessors, NumberOfTasks, validations);

                    if (newAllocation != null)
                    {
                        Allocations.Add(newAllocation);
                    }
                }

                lineNumber++;
            }

            streamReader.Close();

            // Checking whether the Allocations section exists
            openClosingAllocations.CheckValidPair(validations, taffFilename);

            // Validate Allocation
            taffAllocations.ScanErrors(
                Count,
                NumberOfTasks,
                NumberOfProcessors,
                allocationPair,
                taffFilename,
                validations);

            AllocationInFileCount = allocationPair.CalculateNumOfPair();

            afterNumOfError = validations.ErrorValidationManager.Errors.Count;

            // Console.WriteLine($"{Count} | {NumberOfTasks} | {NumberOfProcessors}");
            // Console.WriteLine($"{Allocations.Count} | {allocationPair.CalculateNumOfPair()}");

            return(beforeNumOfError == afterNumOfError);
        }