예제 #1
0
파일: Elements.cs 프로젝트: rauldoblem/Tac
        public static ITokenMatching Has(this ITokenMatching self, IMaker pattern)
        {
            if (!(self is IMatchedTokenMatching))
            {
                return(self);
            }

            return(pattern.TryMake(self));
        }
예제 #2
0
파일: Elements.cs 프로젝트: rauldoblem/Tac
        public static ITokenMatching OptionalHas(this ITokenMatching self, IMaker pattern)
        {
            if (!(self is IMatchedTokenMatching))
            {
                return(self);
            }

            var next = pattern.TryMake(self);

            if (next is IMatchedTokenMatching)
            {
                return(next);
            }

            return(self);
        }
예제 #3
0
파일: Elements.cs 프로젝트: rauldoblem/Tac
        public static ITokenMatching <T> Has <T>(this ITokenMatching <T> self, IMaker pattern)
        {
            if (!(self is IMatchedTokenMatching <T> matchedTokenMatching))
            {
                return(self);
            }

            var patternMatch = pattern.TryMake(self);

            if (!(patternMatch is IMatchedTokenMatching matchedPattern))
            {
                return(TokenMatching <T> .MakeNotMatch(patternMatch.Context));
            }

            return(TokenMatching <T> .MakeMatch(matchedPattern.Tokens, matchedPattern.Context, matchedTokenMatching.Value));
        }
예제 #4
0
        public static ITokenMatching <T> Has <T>(this ITokenMatching self, IMaker <T> pattern)
            where T : class
        {
            if (!(self is IMatchedTokenMatching firstMatched))
            {
                return(TokenMatching <T> .MakeNotMatch(self.Context));
            }

            var res = pattern.TryMake(firstMatched);

            if (res is IMatchedTokenMatching <T> matched)
            {
                return(matched);
            }

            return(res);
        }
예제 #5
0
파일: Elements.cs 프로젝트: rauldoblem/Tac
        public static ITokenMatching <T> Has <T>(this ITokenMatching self, IMaker <T> pattern, out T t)
        {
            t = default;

            if (!(self is IMatchedTokenMatching firstMatched))
            {
                return(TokenMatching <T> .MakeNotMatch(self.Context));
            }

            var res = pattern.TryMake(firstMatched);

            if (res is IMatchedTokenMatching <T> matched)
            {
                t = matched.Value;
            }
            return(res);
        }
예제 #6
0
파일: Elements.cs 프로젝트: rauldoblem/Tac
        public static ITokenMatching OptionalHas <T>(this ITokenMatching self, IMaker <T> pattern, out T t)
            where T : class
        {
            if (!(self is IMatchedTokenMatching matchedTokenMatching))
            {
                t = default;
                return(self);
            }

            var res = pattern.TryMake(matchedTokenMatching);

            if (res is IMatchedTokenMatching <T> matched)
            {
                t = matched.Value;
                return(res);
            }

            t = default;
            return(self);
        }
예제 #7
0
        public static ITokenMatching <T> Has <T>(this ITokenMatching self, IMaker <T> pattern, out T t)
        {
            if (!(self is IMatchedTokenMatching firstMatched))
            {
#pragma warning disable CS8601 // Possible null reference assignment.
                t = default;
#pragma warning restore CS8601 // Possible null reference assignment.
                return(TokenMatching <T> .MakeNotMatch(self.Context));
            }

            var res = pattern.TryMake(firstMatched);
            if (res is IMatchedTokenMatching <T> matched)
            {
                t = matched.Value;
                return(res);
            }
#pragma warning disable CS8601 // Possible null reference assignment.
            t = default;
#pragma warning restore CS8601 // Possible null reference assignment.
            return(res);
        }
예제 #8
0
        /// <summary>
        /// Manage the steps of parsing and creation of the various reports.
        /// </summary>
        /// <param name="filesToProcess">Files to parse</param>
        public static void DoTheMagic(string[] filesToProcess)
        {
            var             unitySection = (UnityConfigurationSection)ConfigurationManager.GetSection("Unity");
            IUnityContainer container    = new UnityContainer();

            unitySection.Configure(container);

            IMaker  maker  = container.Resolve <IMaker>();
            IParser parser = container.Resolve <IParser>();
            ILogger logger = container.Resolve <ILogger>();

            byte[] outputFile = null;

            int correctCounter = 0;
            int failedCounter  = 0;

            FiltersSection section = ConfigurationManager.GetSection("Filters") as FiltersSection;

            foreach (var file in filesToProcess)
            {
                try
                {
                    logger.Info(string.Format("Inizio a processare il file {0}", Path.GetFileName(file)), 0, 0);

                    string path = Directory.GetParent(file).FullName;
                    string name = Path.GetFileNameWithoutExtension(file);

                    // Step #1: Parsing
                    ShipmentsData info = parser.Parse(File.ReadAllLines(file));
                    logger.Info(string.Format("===> Parsing completato correttamente. {0} corrieri trovati.", info.Shipments.Count), 0, 0);

                    List <ShipmentsData> filteredData = new List <ShipmentsData>();

                    int subReport = 1;

                    foreach (FiltersSettingsElement v in section.FiltersSettings)
                    {
                        string outputFileName = string.Format("{0}{1}.pdf", name, v.Suffix);

                        // Step #2: Filtering
                        Regex         currentRegex = new Regex(v.Pattern);
                        ShipmentsData currentData  = new ShipmentsData()
                        {
                            MetaInformation = info.MetaInformation,
                            Shipments       = info.Shipments.Where(x => currentRegex.IsMatch(x.Name)).ToList(),
                            Date            = info.Date
                        };

                        info.Shipments.RemoveAll(x => currentRegex.IsMatch(x.Name));

                        // Step #3: Making the final report
                        try
                        {
                            outputFile = maker.MakeFinalReport(currentData);
                            logger.Info(string.Format("===> [{1}/{2}] Report creato correttamente. {0} kB totali.", outputFile.Length / 1024, subReport, section.FiltersSettings.Count), 0, 0);

                            // Step #4: Writing the report
                            File.WriteAllBytes(Path.Combine(path, outputFileName), outputFile);
                            logger.Info(string.Format("===> [{2}/{3}] Report scritto correttamente: {0}. {1} Corrieri.", outputFileName, currentData.Shipments.Count, subReport, section.FiltersSettings.Count), 0, 0);
                        }
                        catch (Exception ex)
                        {
                            logger.Error(string.Format("Errore durante la creazione/scrittura del report {0}: {1}", outputFileName, ex.Message), 0, 0);
                        }
                        subReport++;
                    }

                    if (info.Shipments.Count > 0)
                    {
                        logger.Warning("**WARNING** Trovati corrieri spuri!", 0, 0);

                        outputFile = maker.MakeFinalReport(info);
                        logger.Info(string.Format("===> Report creato correttamente. {0} kB totali.", outputFile.Length / 1024), 0, 0);

                        string outputFileName = string.Format("{0}_Spurious.pdf", name);

                        File.WriteAllBytes(Path.Combine(path, outputFileName), outputFile);
                        logger.Info(string.Format("===> Report corrieri spuri scritto correttamente: {0}.", outputFileName), 0, 0);
                    }

                    correctCounter++;
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message, 0, 0);
                    failedCounter++;
                }
            }

            Console.WriteLine();
            Console.WriteLine(string.Format("Finito! {0} file totali, {1} processati correttamente, {2} file falliti!", filesToProcess.Length, correctCounter, failedCounter));
        }
예제 #9
0
        public static ITokenMatching <T1, T2, T3, T4, T5> Has <T1, T2, T3, T4, T5>(this ITokenMatching <T1, T2, T3, T4> self, IMaker <T5> pattern)
            where T1 : class
            where T2 : class
            where T3 : class
        {
            if (self is IMatchedTokenMatching <T1, T2, T3, T4> firstMatched)
            {
                var res = pattern.TryMake(firstMatched);
                if (res is IMatchedTokenMatching <T5> matched)
                {
                    return(TokenMatching <T1, T2, T3, T4, T5> .MakeMatch(firstMatched, firstMatched.Value1, firstMatched.Value2, firstMatched.Value3, firstMatched.Value4, matched.Value, matched.EndIndex));
                }
            }

            return(TokenMatching <T1, T2, T3, T4, T5> .MakeNotMatch(self.Context));
        }
        public override void SetUp()
        {
            base.SetUp();

            // Creating mock object
            Maker = Mocks.NewMock<IMaker>();
        }
예제 #11
0
 public void RenderMakerDetails(IMaker maker)
 {
     throw new System.NotImplementedException();
 }