Beispiel #1
0
        public static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Usage: dns-server <config-file> <ip-address> <port>");
                Environment.Exit(1);
            }

            var config = new XmlDocument();

            config.Load(args[0]);

            var zone       = DNSZone.Unserialize(config);
            var clock      = new StopwatchClock();
            var cache      = new ResolverCache(clock, 2048);
            var resolver   = new StubResolver(cache, ResolverUtils.SendQuery);
            var query_exec = new QueryExecutor(zone, resolver, cache);

            var bind_addr = new IPEndPoint(IPAddress.Parse(args[1]),
                                           int.Parse(args[2]));

            var server = new UDPServer(bind_addr, query_exec);

            server.Start();
        }
Beispiel #2
0
        /// <summary>
        /// Resolve information about episode from path.
        /// </summary>
        /// <param name="path">Path.</param>
        /// <param name="isDirectory">Is path for a directory or file.</param>
        /// <param name="isNamed">Do we want to use IsNamed expressions.</param>
        /// <param name="isOptimistic">Do we want to use Optimistic expressions.</param>
        /// <param name="supportsAbsoluteNumbers">Do we want to use expressions supporting absolute episode numbers.</param>
        /// <param name="fillExtendedInfo">Should we attempt to retrieve extended information.</param>
        /// <returns>Returns null or <see cref="EpisodeInfo"/> object if successful.</returns>
        public EpisodeInfo?Resolve(
            string path,
            bool isDirectory,
            bool?isNamed                 = null,
            bool?isOptimistic            = null,
            bool?supportsAbsoluteNumbers = null,
            bool fillExtendedInfo        = true)
        {
            bool   isStub    = false;
            string?container = null;
            string?stubType  = null;

            if (!isDirectory)
            {
                var extension = Path.GetExtension(path);
                // Check supported extensions
                if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
                {
                    // It's not supported. Check stub extensions
                    if (!StubResolver.TryResolveFile(path, _options, out stubType))
                    {
                        return(null);
                    }

                    isStub = true;
                }

                container = extension.TrimStart('.');
            }

            var flags          = new FlagParser(_options).GetFlags(path);
            var format3DResult = new Format3DParser(_options).Parse(flags);

            var parsingResult = new EpisodePathParser(_options)
                                .Parse(path, isDirectory, isNamed, isOptimistic, supportsAbsoluteNumbers, fillExtendedInfo);

            if (!parsingResult.Success && !isStub)
            {
                return(null);
            }

            return(new EpisodeInfo(path)
            {
                Container = container,
                IsStub = isStub,
                EndingEpisodeNumber = parsingResult.EndingEpisodeNumber,
                EpisodeNumber = parsingResult.EpisodeNumber,
                SeasonNumber = parsingResult.SeasonNumber,
                SeriesName = parsingResult.SeriesName,
                StubType = stubType,
                Is3D = format3DResult.Is3D,
                Format3D = format3DResult.Format3D,
                IsByDate = parsingResult.IsByDate,
                Day = parsingResult.Day,
                Month = parsingResult.Month,
                Year = parsingResult.Year
            });
        }
Beispiel #3
0
        public EpisodeInfo Resolve(string path, bool IsDirectory, bool fillExtendedInfo = true)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            var    isStub    = false;
            string container = null;
            string stubType  = null;

            if (!IsDirectory)
            {
                var extension = Path.GetExtension(path) ?? string.Empty;
                // Check supported extensions
                if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
                {
                    var stubResult = new StubResolver(_options, _logger).ResolveFile(path);

                    isStub = stubResult.IsStub;

                    // It's not supported. Check stub extensions
                    if (!isStub)
                    {
                        return(null);
                    }

                    stubType = stubResult.StubType;
                }

                container = extension.TrimStart('.');
            }

            var flags          = new FlagParser(_options).GetFlags(path);
            var format3DResult = new Format3DParser(_options, _logger).Parse(flags);

            var parsingResult = new EpisodePathParser(_options, _iRegexProvider)
                                .Parse(path, IsDirectory, fillExtendedInfo);

            return(new EpisodeInfo
            {
                Path = path,
                Container = container,
                IsStub = isStub,
                EndingEpsiodeNumber = parsingResult.EndingEpsiodeNumber,
                EpisodeNumber = parsingResult.EpisodeNumber,
                SeasonNumber = parsingResult.SeasonNumber,
                SeriesName = parsingResult.SeriesName,
                StubType = stubType,
                Is3D = format3DResult.Is3D,
                Format3D = format3DResult.Format3D,
                IsByDate = parsingResult.IsByDate,
                Day = parsingResult.Day,
                Month = parsingResult.Month,
                Year = parsingResult.Year
            });
        }
Beispiel #4
0
        private void Test(string path, bool isStub, string stubType)
        {
            var isStubResult = StubResolver.TryResolveFile(path, _namingOptions, out var stubTypeResult);

            Assert.Equal(isStub, isStubResult);

            if (isStub)
            {
                Assert.Equal(stubType, stubTypeResult);
            }
            else
            {
                Assert.Null(stubTypeResult);
            }
        }
Beispiel #5
0
        private void Test(string path, bool isStub, string stubType)
        {
            var options = new NamingOptions();

            var resultStubType = StubResolver.ResolveFile(path, options);

            Assert.Equal(isStub, resultStubType.IsStub);

            if (stubType == null)
            {
                Assert.Null(resultStubType.StubType);
            }
            else
            {
                Assert.Equal(stubType, resultStubType.StubType, true);
            }
        }
        public void CanAppendFileHashToAbsoluteUri()
        {
            var hashQueryStringKeyName = "v";
            var hashValue        = "hashValue";
            var hasher           = new StubHasher(hashValue);
            var uri              = Assembly.GetExecutingAssembly().CodeBase;
            var cssFilePath      = Path.Combine(Path.GetDirectoryName(uri), @"output.css");
            var url              = "/" + Path.GetFileName(uri);
            var pathToResolveTo  = Assembly.GetExecutingAssembly().Location;
            var fileResolver     = StubResolver.ForFile(pathToResolveTo);
            var assetsFileHasher = new CssAssetsFileHasher(hashQueryStringKeyName, fileResolver, hasher);

            var expectedUrl = url + "?" + hashQueryStringKeyName + "=" + hashValue;

            var rewrittenUrl = assetsFileHasher.AppendFileHash(cssFilePath, url);

            Assert.That(rewrittenUrl, Is.EqualTo(expectedUrl));
        }
Beispiel #7
0
        private void Test(string path, bool isStub, string stubType)
        {
            var options = new NamingOptions();
            var parser  = new StubResolver(options, new NullLogger());

            var result = parser.ResolveFile(path);

            Assert.AreEqual(isStub, result.IsStub);

            if (stubType == null)
            {
                Assert.IsNull(result.StubType);
            }
            else
            {
                Assert.AreEqual(stubType, result.StubType, true, CultureInfo.InvariantCulture);
            }
        }
Beispiel #8
0
        private void Test(string path, bool isStub, string stubType)
        {
            var options = new NamingOptions();
            var parser  = new StubResolver(options);

            var resultStubType = parser.ResolveFile(path.AsSpan());

            Assert.AreEqual(isStub, !string.IsNullOrEmpty(resultStubType));

            if (stubType == null)
            {
                Assert.IsNull(resultStubType);
            }
            else
            {
                Assert.AreEqual(stubType, resultStubType, true, CultureInfo.InvariantCulture);
            }
        }
        public void CanAppendFileHashToAbsoluteUriWithAnExistingQueryString()
        {
            var hashQueryStringKeyName = "v";
            var hashValue       = "hashValue";
            var hasher          = new StubHasher(hashValue);
            var uri             = Assembly.GetExecutingAssembly().CodeBase;
            var cssFilePath     = Path.GetDirectoryName(uri) + @"\output.css";
            var url             = "/" + Path.GetFileName(uri) + "?test=value";
            var pathToResolveTo = Assembly.GetExecutingAssembly().Location;
            var fileResolver    = StubResolver.ForFile(pathToResolveTo);
            var pathTranslator  = new PathTranslator();

            var assetsFileHasher = new CSSAssetsFileHasher(hashQueryStringKeyName, fileResolver, hasher, pathTranslator);

            var expectedUrl = url + "&" + hashQueryStringKeyName + "=" + hashValue;

            var rewrittenUrl = assetsFileHasher.AppendFileHash(cssFilePath, url);

            Assert.That(rewrittenUrl, Is.EqualTo(expectedUrl));
        }
Beispiel #10
0
        public void CanBundleJavascriptInRelease(Type preprocessorType)
        {
            var preprocessor = Activator.CreateInstance(preprocessorType) as IPreprocessor;

            const string template         = "<h1>{{message}}</h1>";
            var          templateFileName = "test.hogan.html";
            var          resolver         = StubResolver.ForFile(TestUtilities.PrepareRelativePath(templateFileName));

            var readerFactory = new StubFileReaderFactory();

            readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(templateFileName), template);

            var writerFactory = new StubFileWriterFactory();

            string tag;

            using (new ResolverFactoryScope(typeof(FileSystemResolver).FullName, resolver))
            {
                tag = javaScriptBundleFactory
                      .WithFileReaderFactory(readerFactory)
                      .WithFileWriterFactory(writerFactory)
                      .WithDebuggingEnabled(false)
                      .Create()
                      .WithPreprocessor(preprocessor)
                      .Add("~/" + templateFileName)
                      .Render("~/template.js");
            }

            //are minifier's optimizations here OK?
            var compiled =
                @"var JST=JST||{};JST.test=new Hogan.Template(function(n,t,i){var r=this;return r.b(i=i||""""),r.b(""<h1>""),r.b(r.v(r.f(""message"",n,t,0))),r.b(""<\/h1>""),r.fl()},""" + template.Replace("/", @"\/") + "\",Hogan,{});";

            Assert.AreEqual(1, writerFactory.Files.Count);
            var expectedTag = "<script type=\"text/javascript\" src=\"template.js?r=hash\"></script>";

            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));

            var actual = writerFactory.Files[TestUtilities.PrepareRelativePath("template.js")];

            Assert.AreEqual(compiled + "\n", actual);
        }
Beispiel #11
0
        public void CanBundleJavascriptInDebug(Type preprocessorType)
        {
            var preprocessor = Activator.CreateInstance(preprocessorType) as IPreprocessor;

            const string template         = "<h1>{{message}}</h1>";
            var          templateFileName = "test.hogan.html";
            var          resolver         = StubResolver.ForFile(TestUtilities.PrepareRelativePath(templateFileName));

            var readerFactory = new StubFileReaderFactory();

            readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(templateFileName), template);

            var writerFactory = new StubFileWriterFactory();

            string tag;

            using (new ResolverFactoryScope(typeof(FileSystemResolver).FullName, resolver))
            {
                tag = javaScriptBundleFactory
                      .WithFileReaderFactory(readerFactory)
                      .WithFileWriterFactory(writerFactory)
                      .WithDebuggingEnabled(true)
                      .Create()
                      .WithPreprocessor(preprocessor)
                      .Add("~/" + templateFileName)
                      .Render("~/template.js");
            }

            var sb = new StringBuilder();

            sb.AppendLine(@"var JST = JST || {};");
            sb.AppendLine(@"JST['test'] = new Hogan.Template(function(c,p,i){var _=this;_.b(i=i||"""");_.b(""<h1>"");_.b(_.v(_.f(""message"",c,p,0)));_.b(""</h1>"");return _.fl();;},""" + template + "\",Hogan,{});");
            var compiled = sb.ToString();

            Assert.AreEqual(1, writerFactory.Files.Count);
            var expectedTag = "<script type=\"text/javascript\" src=\"test.hogan.html.squishit.debug.js\"></script>\n";

            Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));

            Assert.AreEqual(compiled, writerFactory.Files[TestUtilities.PrepareRelativePath("test.hogan.html.squishit.debug.js")]);
        }
Beispiel #12
0
        public void CanBundleDirectoryContentsInRelease_Ignores_Duplicates()
        {
            var path  = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.css");
            var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.css");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, css2);
                frf.SetContentsForFile(file2, css);

                var writerFactory = new StubFileWriterFactory();

                var tag = cssBundleFactory.WithDebuggingEnabled(false)
                          .WithFileReaderFactory(frf)
                          .WithFileWriterFactory(writerFactory)
                          .WithHasher(new StubHasher("hashy"))
                          .Create()
                          .Add(path)
                          .Add(file1)
                          .Render("~/output.css");

                var expectedTag = "<link rel=\"stylesheet\" type=\"text/css\" href=\"output.css?r=hashy\" />";
                Assert.AreEqual(expectedTag, tag);

                var combined = "li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}";
                Assert.AreEqual(combined, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.css")]);
            }
        }
Beispiel #13
0
        public void CanBundleDirectoryContentsInDebug_Ignores_Duplicates()
        {
            var path  = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.css");
            var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.css");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, css2);
                frf.SetContentsForFile(file2, css);

                var writerFactory = new StubFileWriterFactory();

                var tag = cssBundleFactory.WithDebuggingEnabled(true)
                          .WithFileReaderFactory(frf)
                          .WithFileWriterFactory(writerFactory)
                          .WithHasher(new StubHasher("hashy"))
                          .Create()
                          .Add(path)
                          .Render("~/output.css");

                var expectedTag = string.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"/{0}/file1.css\" />\n<link rel=\"stylesheet\" type=\"text/css\" href=\"/{0}/file2.css\" />\n", path);
                Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
            }
        }
Beispiel #14
0
        public void CanBundleCssWithRemote()
        {
            //this is rendering tag correctly but incorrectly(?) merging both files
            using (new ResolverFactoryScope(typeof(Framework.Resolvers.HttpResolver).FullName, StubResolver.ForFile("http://www.someurl.com/css/first.css")))
            {
                CSSBundle cssBundle = cssBundleFactory
                                      .WithHasher(hasher)
                                      .WithDebuggingEnabled(false)
                                      .WithContents(css)
                                      .Create();

                string tag = cssBundle
                             .AddRemote("/css/first.css", "http://www.someurl.com/css/first.css")
                             .Add("/css/second.css")
                             .Render("/css/output_remote.css");
                Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.someurl.com/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"/css/output_remote.css?r=67F81278D746D60E6F711B5A29747388\" />", tag);
                Assert.AreEqual(1, cssBundleFactory.FileWriterFactory.Files.Count);
                Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}", cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output_remote.css")]);
            }
        }
        public void RenderRelease_OmitsRenderedTag_IfOnlyRemoteAssets()
        {
            //this is rendering tag correctly but incorrectly(?) merging both files
            using (new ResolverFactoryScope(typeof(Framework.Resolvers.HttpResolver).FullName, StubResolver.ForFile("http://www.someurl.com/css/first.css")))
            {
                string tag = javaScriptBundle
                             .ForceRelease()
                             .AddRemote("/css/first.js", "http://www.someurl.com/js/first.js")
                             .Render("/css/output_remote.js");

                Assert.AreEqual("<script type=\"text/javascript\" src=\"http://www.someurl.com/js/first.js\"></script>", tag);
                Assert.AreEqual(0, fileWriterFactory.Files.Count);
            }
        }
        public void CanBundleDirectoryContentsInDebug_Ignores_Duplicates()
        {
            var path  = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PreparePath(Environment.CurrentDirectory + "\\" + path + "\\file1.js");
            var file2 = TestUtilities.PreparePath(Environment.CurrentDirectory + "\\" + path + "\\file2.js");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, javaScript2.Replace("sum", "replace"));
                frf.SetContentsForFile(file2, javaScript);

                var writerFactory = new StubFileWriterFactory();

                var tag = new JavaScriptBundleFactory()
                          .WithDebuggingEnabled(true)
                          .WithFileReaderFactory(frf)
                          .WithFileWriterFactory(writerFactory)
                          .WithHasher(new StubHasher("hashy"))
                          .Create()
                          .Add(path)
                          .Add(file1)
                          .Render("~/output.js");

                var expectedTag = string.Format("<script type=\"text/javascript\" src=\"/{0}/file1.js\"></script>\n<script type=\"text/javascript\" src=\"/{0}/file2.js\"></script>\n", path);
                Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
            }
        }
        public void CanBundleDirectoryContentsInRelease_Ignores_Duplicates()
        {
            var path  = Guid.NewGuid().ToString();
            var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.js");
            var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.js");

            using (new ResolverFactoryScope(typeof(SquishIt.Framework.Resolvers.FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) {
                var frf = new StubFileReaderFactory();
                frf.SetContentsForFile(file1, javaScript2.Replace("sum", "replace"));
                frf.SetContentsForFile(file2, javaScript);

                var writerFactory = new StubFileWriterFactory();

                var tag = new JavaScriptBundleFactory()
                          .WithDebuggingEnabled(false)
                          .WithFileReaderFactory(frf)
                          .WithFileWriterFactory(writerFactory)
                          .WithHasher(new StubHasher("hashy"))
                          .Create()
                          .Add(path)
                          .Add(file1)
                          .Render("~/output.js");

                var expectedTag = "<script type=\"text/javascript\" src=\"output.js?r=hashy\"></script>";
                Assert.AreEqual(expectedTag, tag);

                var combined = "function replace(n,t){return n+t}function product(n,t){return n*t}function sum(n,t){return n+t}";
                Assert.AreEqual(combined, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.js")]);
            }
        }