Пример #1
0
        private void Verify(MatcherContext context, int i)
        {
            if (_requests[i].IsMatch)
            {
                if (context.Endpoint == null)
                {
                    throw new InvalidOperationException($"Failed {i}");
                }

                var values = _requests[i].Values;
                if (values.Count != context.Values.Count)
                {
                    throw new InvalidOperationException($"Failed {i}");
                }
            }
            else
            {
                if (context.Endpoint != null)
                {
                    throw new InvalidOperationException($"Failed {i}");
                }

                if (context.Values.Count != 0)
                {
                    throw new InvalidOperationException($"Failed {i}");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Searches the directory specified for all files matching patterns added to this instance of <see cref="Matcher" />
        /// </summary>
        /// <param name="directoryInfo">The root directory for the search</param>
        /// <returns>Always returns instance of <see cref="PatternMatchingResult" />, even if no files were matched</returns>
        public virtual PatternMatchingResult Execute(DirectoryInfoBase directoryInfo)
        {
            ThrowHelper.ThrowIfNull(directoryInfo);

            var context = new MatcherContext(_includePatterns, _excludePatterns, directoryInfo, _comparison);

            return(context.Execute());
        }
Пример #3
0
        /// <summary>
        /// Searches the directory specified for all files matching patterns added to this instance of <see cref="Matcher" />
        /// </summary>
        /// <param name="directoryInfo">The root directory for the search</param>
        /// <returns>Always returns instance of <see cref="PatternMatchingResult" />, even if no files were matched</returns>
        public virtual PatternMatchingResult Execute(DirectoryInfoBase directoryInfo)
        {
            if (directoryInfo is null)
            {
                throw new ArgumentNullException(nameof(directoryInfo));
            }

            var context = new MatcherContext(_includePatterns, _excludePatterns, directoryInfo, _comparison);

            return(context.Execute());
        }
Пример #4
0
        public async Task AttributeRouting()
        {
            for (var i = 0; i < Iterations; i++)
            {
                for (var j = 0; j < _requests.Length; j++)
                {
                    var context = new MatcherContext(_requests[j].HttpContext);

                    await _treeMatcher.MatchAsync(context);

                    Verify(context, j);
                }
            }
        }
Пример #5
0
 protected string CalculateStem(FileInfoBase matchedFile)
 {
     return(MatcherContext.CombinePath(Frame.Stem, matchedFile.Name));
 }
Пример #6
0
 public virtual PatternMatchingResult Execute(DirectoryInfoBase directoryInfo)
 {
     var context = new MatcherContext(_includePatterns, _excludePatterns, directoryInfo, _comparison);
     return context.Execute();
 }
Пример #7
0
        static void Main(string[] args)
        {
            WriteInfo("".PadRight(79, '*'));
            WriteInfo("ezPacker, Copyright (C) 2016 Sascha-Christian Hensel");
            WriteInfo("ezPacker comes with ABSOLUTELY NO WARRANTY.");
            WriteInfo("This is free software, and you are welcome to redistribute it");
            WriteInfo("under certain conditions; see LICENSE.");
            WriteInfo("".PadRight(79, '*'));
            WriteInfo("");

            if (args.Length != 1)
            {
                WriteError("No configuration file given!");
            }
            else
            {
                FileInfo projectFile = new FileInfo(args[0]);

                WriteInfo("Trying to load configuration file '{0}'...", projectFile);

                IProject project = null;

                IProjectContext projectContext = new DefaultProjectContext(projectFile);

                IProjectParser parser = new XmlProjectParser();
                using (FileStream stream = projectFile.OpenRead())
                {
                    project = parser.Parse(projectContext, stream);
                }

                IMatcherContext context = new MatcherContext()
                {
                    Project = project
                };

                IFileCollector collector = new DefaultFileCollector();
                foreach (FileInfo item in Matcher.GetMatches(context))
                {
                    collector.Add(item);
                }

                WriteInfo("Success! Found  '{0}' possible file(s) to include for packing.", collector.Count);

                if (project.Replacements.Count == 0)
                {
                    WriteInfo("No files need to replaced.");
                }
                else
                {
                    WriteInfo("Trying to replace '{0}' file(s)...", project.Replacements.Count);

                    foreach (Replacement replacement in project.Replacements)
                    {
                        WriteInfo("  Attempt to replace file '{0}'...", replacement.FileName);
                        if (!replacement.Exists())
                        {
                            WriteWarning("  ... failed: replacement file '{0}' does not exist!", replacement.ReplacementFile.FullName);
                            continue;
                        }

                        bool replaced = collector.Replace(context, replacement.FileName, replacement.ReplacementFile, replacement.Mode);
                        if (replaced)
                        {
                            WriteInfo("  ... succeeded!");
                        }
                        else
                        {
                            WriteWarning("  ... failed: file to be replaced wasn't found in list of files to be packed.");
                        }
                    }

                    WriteInfo("Replacement procedure completed.");
                }

                WriteInfo("Begin packing...");

                if (!project.OutPath.Exists)
                {
                    project.OutPath.Create();
                }

                string outputFilePath = Path.Combine(project.OutPath.FullName, project.PackedName + ".zip");

                using (IPacker packer = new ZipPacker())
                {
                    foreach (var pair in collector.GetAll())
                    {
                        if (pair.Item2.FullName == outputFilePath)
                        {
                            continue;
                        }

                        string archiveFileName = context.GetRelativePath(pair.Item1.FullName);

                        packer.Add(archiveFileName, pair.Item2.OpenRead());

                        WriteInfo("  Added '{0}'.", archiveFileName);
                    }

                    WriteInfo("Writing archive to '{0}'...", outputFilePath);

                    using (FileStream output = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        packer.Save(output);
                    }

                    WriteInfo("... success!");
                }
            }

            WriteInfo("");

            if (Properties.Settings.Default.InteractiveMode)
            {
                WriteInfo("");
                WriteInfo("Press any key to quit . . .");
                Console.ReadKey();
            }
        }
Пример #8
0
        public static void RequestShortCircuited(this ILogger logger, MatcherContext matcherContext)
        {
            var requestPath = matcherContext.HttpContext.Request.Path;

            _requestShortCircuited(logger, requestPath, null);
        }