Exemple #1
0
        private string ProcessEntry(string entry)
        {
            var accountNumber   = m_EntryParser.Parse(entry);
            var processedNumber = m_NumberProcessor.Process(accountNumber);

            return(processedNumber);
        }
Exemple #2
0
 public void EntryActivated(object obj, EventArgs args)
 {
     if (!entry.BinFound)
     {
         parser.Parse(entry.Text);
     }
     else
     {
         string[] command = entry.Text.Split(new char[] { ' ' }, 2);
         try {
             ProcessStartInfo info = new ProcessStartInfo(entry.Text);
             info.UseShellExecute = true;
             Process process;
             if (command.Length == 1)
             {
                 process = Process.Start(command[0]);
             }
             else
             {
                 process = Process.Start(command[0], command[1]);
             }
         } catch {
             Console.WriteLine("ERROR: Launching process.");
         }
     }
     Application.Quit();
 }
Exemple #3
0
        public IEnumerable <string> GenerateAccountNumbers(string fileName)
        {
            if (String.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            //read the file
            var fileParserResponse = FileParser.Read(fileName);

            //extract the lines into entries
            var entryParserResponse = EntryParser.Parse(new EntryParserRequest()
            {
                Lines = fileParserResponse.Lines
            });

            //extract the digital numbers form the entries
            var digitalNumberParserResponse = DigitalNumberParser.Parse(new DigitalNumberParserRequest()
            {
                Entries = entryParserResponse.Entries
            });

            //convert the digital numbers to ints
            var integerParserResponse = IntegerParser.Parse(new IntegerParserRequest()
            {
                DigitalNumbers = digitalNumberParserResponse.DigitalNumbers
            });

            var formatedNumbers = integerParserResponse.Numbers.Select(i => _checkSumService.Format(i)).ToList();

            FileParser.Write(fileName + ".out", formatedNumbers);

            return(formatedNumbers);
        }
        private void ParseLine(string line)
        {
            var lineInfo = _entryParser.Parse(line);
            var stock    = new Material()
            {
                Id = lineInfo.MaterialId
            };

            foreach (var warehouseStock in lineInfo.WarehouseStock)
            {
                var warehouse = GetWarehouse(warehouseStock.Key);
                warehouse.AddMaterial(stock, warehouseStock.Value);
            }
        }
Exemple #5
0
        public IDictionary <string, IDictionary <string, string> > Parse(IEnumerable <string> lines)
        {
            if (lines == null)
            {
                throw new ArgumentNullException(nameof(lines));
            }

            var result = new Dictionary <string, IDictionary <string, string> >();

            Dictionary <string, string> currentSection = null;

            foreach (var line in lines)
            {
                if (line.StartsWith('['))
                {
                    // Technically, should check that a section definition is correctly closed, but I don't see any harm in simply accepting that.
                    var sectionName = line.TrimStart('[').TrimEnd(']')
                                      .Trim();

                    // TODO: maybe simply silently ignore that?
                    if (string.IsNullOrWhiteSpace(sectionName))
                    {
                        throw new InvalidSectionDeclaration(line);
                    }

                    // TODO: do I want to fobid spaces in section names?

                    currentSection = new Dictionary <string, string>();
                    result.Add(sectionName, currentSection);
                }
                else if (IsConfigEntry(line))
                {
                    var keyValuePair = entryParser.Parse(line);

                    if (keyValuePair != null)
                    {
                        if (currentSection == null)
                        {
                            currentSection = new Dictionary <string, string>();
                            result.Add(DefaultSectionName, currentSection);
                        }

                        currentSection.Add(keyValuePair.Value.Key, keyValuePair.Value.Value);
                    }
                }
            }

            return(result);
        }