Exemplo n.º 1
0
        private static void ProcessFiles(StaticFile staticFile, SnowSettings settings, IList <Post> parsedFiles, Browser browserComposer)
        {
            try
            {
                var processorName = staticFile.Loop ?? "";
                var processor     = ProcessorFactory.Get(processorName.ToLower());

                if (processor == null)
                {
                    throw new ProcessorNotFoundException(processorName.ToLower());
                }

                processor.Process(new SnowyData
                {
                    Settings = settings,
                    Files    = parsedFiles,
                    Browser  = browserComposer,
                    File     = staticFile
                }, settings);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Error processing static file: ");
                Console.WriteLine("- " + staticFile.Loop);
                Console.WriteLine("- " + staticFile.File);
                Console.WriteLine("- Exception:");
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 2
0
        public static void Start(SnowSettings settings)
        {
            Console.WriteLine("Sandra.Snow : Starting up a testing server");

            var options = new StartOptions
            {
                ServerFactory = "Nowin",
                Port          = 5498
            };

            Startup.Settings = settings;

            using (WebApp.Start <Startup>(options))
            {
                Console.WriteLine("Sandra.Snow : Listening on http://locahost:5498/");
                Console.WriteLine(" - attempting to open your browser...");

                Process.Start("http://localhost:5498/");

                Console.WriteLine(" - press any to quit the testing server...");
                Console.ReadKey();
                Console.WriteLine("");
                Console.WriteLine("Sandra.Snow : Exited testing server");
            }
        }
Exemplo n.º 3
0
        public static void Start(SnowSettings settings)
        {
            Console.WriteLine("Sandra.Snow : Starting up a testing server");

            var options = new StartOptions
            {
                ServerFactory = "Nowin",
                Port = 5498
            };

            Startup.Settings = settings;

            using (WebApp.Start<Startup>(options))
            {
                Console.WriteLine("Sandra.Snow : Listening on http://locahost:5498/");
                Console.WriteLine(" - attempting to open your browser...");
                
                Process.Start("http://localhost:5498/");

                Console.WriteLine(" - press any to quit the testing server...");
                Console.ReadKey();
                Console.WriteLine("");
                Console.WriteLine("Sandra.Snow : Exited testing server");
            }
        }
Exemplo n.º 4
0
        private static void SetupOutput(SnowSettings settings)
        {
            if (!Directory.Exists(settings.Output))
            {
                Directory.CreateDirectory(settings.Output);
            }

            new DirectoryInfo(settings.Output).Empty();
        }
        public static Post GetFileData(FileInfo file, Browser browser, SnowSettings snowSettings)
        {
            var response        = browser.Get("/post/" + HttpUtility.UrlEncodeUnicode(file.Name));
            var rawPost         = File.ReadAllText(file.FullName);
            var fileNameMatches = FileNameRegex.Match(file.Name);
            var settings        = new Dictionary <string, dynamic>();
            var rawSettings     = string.Empty;

            if (!fileNameMatches.Success)
            {
                throw new ApplicationException("File " + file.Name +
                                               " does not match the format {year}-{month}-{day}-{slug}.(md|markdown)");
            }

            //Get the Header info from a Post Markdown File
            //Find the first index of ---
            var startOfSettingsIndex = rawPost.IndexOf("---", StringComparison.InvariantCultureIgnoreCase);

            if (startOfSettingsIndex >= 0)
            {
                //Find the second index of --- after the first
                var endOfSettingsIndex = rawPost.IndexOf("---", startOfSettingsIndex + 3,
                                                         StringComparison.InvariantCultureIgnoreCase);

                //If we find the 2nd index, parse the settings
                //Otherwise we assume there's no header or settings...
                if (endOfSettingsIndex >= 0)
                {
                    rawSettings = rawPost.Substring(startOfSettingsIndex + 3, endOfSettingsIndex - 3);
                    settings    = ParseSettings(rawSettings);
                }
            }

            var year  = fileNameMatches.Groups["year"].Value;
            var month = fileNameMatches.Groups["month"].Value;
            var day   = fileNameMatches.Groups["day"].Value;
            var slug  = fileNameMatches.Groups["slug"].Value.ToUrlSlug();
            var date  = DateTime.ParseExact(year + month + day, "yyyyMMdd", CultureInfo.InvariantCulture);

            var result = new Post
            {
                FileName       = file.Name,
                MarkdownHeader = rawSettings,
                Content        = response.Body.AsString(),
                Settings       = settings,
                Year           = date.Year,
                Month          = date.Month,
                Day            = date.Day,
                Date           = date,
                Url            = slug
            };

            result.SetSnowSettings(snowSettings);
            result.SetHeaderSettings(settings);

            return(result);
        }
Exemplo n.º 6
0
        public static Post GetFileData(FileInfo file, SnowSettings snowSettings)
        {
            var rawPost = File.ReadAllText(file.FullName);
            var fileNameMatches = FileNameRegex.Match(file.Name);
            var rawSettings = string.Empty;

            if (!fileNameMatches.Success)
            {
                file.Name.OutputIfDebug(" - Skipping file: ");
                " - File does not match the format {year}-{month}-{day}-{slug}.(md|markdown)".OutputIfDebug();
                return new Post.MissingPost();
            }

            var result = MarkdownFileParser.ParseDataFromFile(rawPost);
            var settings = ParseSettings(result.Header);

            var year = fileNameMatches.Groups["year"].Value;
            var month = fileNameMatches.Groups["month"].Value;
            var day = fileNameMatches.Groups["day"].Value;
            var slug = fileNameMatches.Groups["slug"].Value.ToUrlSlug();
            var date = DateTime.ParseExact(year + month + day, "yyyyMMdd", CultureInfo.InvariantCulture);

            /// if a 'date' property is found in markdown file header, that date will be used instead of the date in the file name
            if (settings.ContainsKey("date"))
            {
                try
                {
                    date = DateTime.Parse((string)settings["date"]);
                }
                finally
                {
                    /// do nothing, let the current 'date' be as is
                }
            }

            var bodySerialized = Markdown.Transform(result.Body);
            var excerptSerialized = Markdown.Transform(result.Excerpt ?? string.Empty);

            var postHeader = new Post
            {
                FileName = file.Name,
                MarkdownHeader = rawSettings,
                Content = bodySerialized,
                ContentExcerpt = excerptSerialized,
                Settings = settings,
                Year = date.Year,
                Month = date.Month,
                Day = date.Day,
                Date = date,
                Url = slug
            };

            postHeader.SetSnowSettings(snowSettings);
            postHeader.SetHeaderSettings(settings);

            return postHeader;
        }
Exemplo n.º 7
0
        public static Post GetFileData(FileInfo file, SnowSettings snowSettings)
        {
            var rawPost         = File.ReadAllText(file.FullName);
            var fileNameMatches = FileNameRegex.Match(file.Name);
            var rawSettings     = string.Empty;

            if (!fileNameMatches.Success)
            {
                file.Name.OutputIfDebug(" - Skipping file: ");
                " - File does not match the format {year}-{month}-{day}-{slug}.(md|markdown)".OutputIfDebug();
                return(new Post.MissingPost());
            }

            var result   = MarkdownFileParser.ParseDataFromFile(rawPost);
            var settings = ParseSettings(result.Header);

            var year  = fileNameMatches.Groups["year"].Value;
            var month = fileNameMatches.Groups["month"].Value;
            var day   = fileNameMatches.Groups["day"].Value;
            var slug  = fileNameMatches.Groups["slug"].Value.ToUrlSlug();
            var date  = DateTime.ParseExact(year + month + day, "yyyyMMdd", CultureInfo.InvariantCulture);

            /// if a 'date' property is found in markdown file header, that date will be used instead of the date in the file name
            if (settings.ContainsKey("date"))
            {
                try
                {
                    date = DateTime.Parse((string)settings["date"]);
                }
                finally
                {
                    /// do nothing, let the current 'date' be as is
                }
            }

            var bodySerialized    = Markdown.Transform(result.Body);
            var excerptSerialized = Markdown.Transform(result.Excerpt ?? string.Empty);

            var postHeader = new Post
            {
                FileName       = file.Name,
                MarkdownHeader = rawSettings,
                Content        = bodySerialized,
                ContentExcerpt = excerptSerialized,
                Settings       = settings,
                Year           = date.Year,
                Month          = date.Month,
                Day            = date.Day,
                Date           = date,
                Url            = slug
            };

            postHeader.SetSnowSettings(snowSettings);
            postHeader.SetHeaderSettings(settings);

            return(postHeader);
        }
        public static Post GetFileData(FileInfo file, Browser browser, SnowSettings snowSettings)
        {
            var response = browser.Get("/post/" + HttpUtility.UrlEncodeUnicode(file.Name));
            var rawPost = File.ReadAllText(file.FullName);
            var fileNameMatches = FileNameRegex.Match(file.Name);
            var settings = new Dictionary<string, dynamic>();
            var rawSettings = string.Empty;

            if (!fileNameMatches.Success)
            {
                throw new ApplicationException("File " + file.Name +
                                               " does not match the format {year}-{month}-{day}-{slug}.(md|markdown)");
            }

            //Get the Header info from a Post Markdown File
            //Find the first index of ---
            var startOfSettingsIndex = rawPost.IndexOf("---", StringComparison.InvariantCultureIgnoreCase);
            if (startOfSettingsIndex >= 0)
            {
                //Find the second index of --- after the first
                var endOfSettingsIndex = rawPost.IndexOf("---", startOfSettingsIndex + 3,
                                                         StringComparison.InvariantCultureIgnoreCase);

                //If we find the 2nd index, parse the settings
                //Otherwise we assume there's no header or settings...
                if (endOfSettingsIndex >= 0)
                {
                    rawSettings = rawPost.Substring(startOfSettingsIndex + 3, endOfSettingsIndex - 3);
                    settings = ParseSettings(rawSettings);
                }
            }

            var year = fileNameMatches.Groups["year"].Value;
            var month = fileNameMatches.Groups["month"].Value;
            var day = fileNameMatches.Groups["day"].Value;
            var slug = fileNameMatches.Groups["slug"].Value.ToUrlSlug();
            var date = DateTime.ParseExact(year + month + day, "yyyyMMdd", CultureInfo.InvariantCulture);

            var result = new Post
            {
                FileName = file.Name,
                MarkdownHeader = rawSettings,
                Content = response.Body.AsString(),
                Settings = settings,
                Year = date.Year,
                Month = date.Month,
                Day = date.Day,
                Date = date,
                Url = slug
            };

            result.SetSnowSettings(snowSettings);
            result.SetHeaderSettings(settings);

            return result;
        }
Exemplo n.º 9
0
        private static SnowSettings CreateSettings(string currentDir)
        {
            var settings   = SnowSettings.Default(currentDir);
            var configFile = Path.Combine(currentDir, "snow.config");

            if (!File.Exists(configFile))
            {
                throw new FileNotFoundException("Snow config file not found");
            }

            var fileData = File.ReadAllText(configFile);

            var newSettings = JsonConvert.DeserializeObject <SnowSettings>(fileData);

            var properties = newSettings.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (var propertyInfo in properties)
            {
                var value = propertyInfo.GetValue(newSettings);

                var singleString = value as string;

                if (!string.IsNullOrWhiteSpace(singleString))
                {
                    propertyInfo.SetValue(settings, value);
                }

                var singleInt = value as int?;

                if (singleInt.HasValue && singleInt > 0)
                {
                    propertyInfo.SetValue(settings, value);
                }

                var strings = value as string[];
                if (strings != null && strings.Length > 0)
                {
                    propertyInfo.SetValue(settings, value);
                }

                var staticFiles = value as IEnumerable <StaticFile>;
                if (staticFiles != null && staticFiles.Any())
                {
                    propertyInfo.SetValue(settings, value);
                }
            }

            if (!string.IsNullOrWhiteSpace(settings.SiteUrl))
            {
                settings.SiteUrl = settings.SiteUrl.TrimEnd('/');
            }

            return(settings);
        }
Exemplo n.º 10
0
        public static Page GetFileData(FileInfo file, SnowSettings snowSettings)
        {
            var rawPage         = File.ReadAllText(file.FullName);
            var fileNameMatches = FileNameRegex.Match(file.Name);
            var rawSettings     = string.Empty;

            if (!fileNameMatches.Success)
            {
                file.Name.OutputIfDebug(" - Skipping file: ");
                " - File does not match the format {slug}.(md|markdown)".OutputIfDebug();
                return(null);
            }

            var result   = MarkdownFileParser.ParseDataFromFile(rawPage);
            var settings = PostParser.ParseSettings(result.Header);

            var slug = fileNameMatches.Groups["slug"].Value.ToUrlSlug();

            /// if a 'date' property is found in markdown file header, that date will be used instead of the date in the file name
            DateTime date = DateTime.Now;

            if (settings.ContainsKey("date"))
            {
                DateTime.TryParse((string)settings["date"], out date);
            }

            var markdown          = new Markdown();
            var bodySerialized    = markdown.Transform(result.Body);
            var excerptSerialized = markdown.Transform(result.Excerpt ?? string.Empty);

            var pageHeader = new Page
            {
                FileName       = file.Name,
                MarkdownHeader = rawSettings,
                Content        = bodySerialized,
                ContentExcerpt = excerptSerialized,
                Settings       = settings,
                Date           = date,
                Url            = "/" + slug
            };

            pageHeader.SetSnowSettings(snowSettings);
            pageHeader.SetHeaderSettings(settings);

            return(pageHeader);
        }
Exemplo n.º 11
0
        public static Post GetFileData(FileInfo file, SnowSettings snowSettings)
        {
            var rawPost = File.ReadAllText(file.FullName);
            var fileNameMatches = FileNameRegex.Match(file.Name);
            var rawSettings = string.Empty;

            if (!fileNameMatches.Success)
            {
                file.Name.OutputIfDebug(" - Skipping file: ");
                " - File does not match the format {year}-{month}-{day}-{slug}.(md|markdown)".OutputIfDebug();
                return new Post.MissingPost();
            }

            var result = MarkdownFileParser.ParseDataFromFile(rawPost);
            var settings = ParseSettings(result.Header);

            var year = fileNameMatches.Groups["year"].Value;
            var month = fileNameMatches.Groups["month"].Value;
            var day = fileNameMatches.Groups["day"].Value;
            var slug = fileNameMatches.Groups["slug"].Value.ToUrlSlug();
            var date = DateTime.ParseExact(year + month + day, "yyyyMMdd", CultureInfo.InvariantCulture);

            var bodySerialized = Markdown.Transform(result.Body);
            var excerptSerialized = Markdown.Transform(result.Excerpt ?? string.Empty);

            var postHeader = new Post
            {
                FileName = file.Name,
                MarkdownHeader = rawSettings,
                Content = bodySerialized,
                ContentExcerpt = excerptSerialized,
                Settings = settings,
                Year = date.Year,
                Month = date.Month,
                Day = date.Day,
                Date = date,
                Url = slug
            };

            postHeader.SetSnowSettings(snowSettings);
            postHeader.SetHeaderSettings(settings);

            return postHeader;
        }
Exemplo n.º 12
0
    public static Page GetFileData(FileInfo file, SnowSettings snowSettings)
    {
      var rawPage = File.ReadAllText(file.FullName);
      var fileNameMatches = FileNameRegex.Match(file.Name);
      var rawSettings = string.Empty;

      if (!fileNameMatches.Success)
      {
        file.Name.OutputIfDebug(" - Skipping file: ");
        " - File does not match the format {slug}.(md|markdown)".OutputIfDebug();
        return null;
      }

      var result = MarkdownFileParser.ParseDataFromFile(rawPage);
      var settings = PostParser.ParseSettings(result.Header);

      var slug = fileNameMatches.Groups["slug"].Value.ToUrlSlug();

      /// if a 'date' property is found in markdown file header, that date will be used instead of the date in the file name
      DateTime date = DateTime.Now;
      if (settings.ContainsKey("date"))
          DateTime.TryParse((string)settings["date"], out date);

      var markdown = new Markdown();
      var bodySerialized = markdown.Transform(result.Body);
      var excerptSerialized = markdown.Transform(result.Excerpt ?? string.Empty);

      var pageHeader = new Page
      {
        FileName = file.Name,
        MarkdownHeader = rawSettings,
        Content = bodySerialized,
        ContentExcerpt = excerptSerialized,
        Settings = settings,
        Date = date,
        Url = "/" + slug
      };

      pageHeader.SetSnowSettings(snowSettings);
      pageHeader.SetHeaderSettings(settings);

      return pageHeader;
    }
Exemplo n.º 13
0
        public static Post GetFileData(FileInfo file, Browser browser, SnowSettings snowSettings)
        {
            var response = browser.Get("/post/" + HttpUtility.UrlEncodeUnicode(file.Name));
            var rawPost = File.ReadAllText(file.FullName);
            var fileNameMatches = FileNameRegex.Match(file.Name);
            var rawSettings = string.Empty;

            if (!fileNameMatches.Success)
            {
                file.Name.OutputIfDebug(" - Skipping file: ");
                " - File does not match the format {year}-{month}-{day}-{slug}.(md|markdown)".OutputIfDebug();
                return new Post.MissingPost();
            }

            var result = ParseDataFromFile(rawPost);
            var settings = ParseSettings(result.Item1);

            var year = fileNameMatches.Groups["year"].Value;
            var month = fileNameMatches.Groups["month"].Value;
            var day = fileNameMatches.Groups["day"].Value;
            var slug = fileNameMatches.Groups["slug"].Value.ToUrlSlug();
            var date = DateTime.ParseExact(year + month + day, "yyyyMMdd", CultureInfo.InvariantCulture);

            var postHeader = new Post
            {
                FileName = file.Name,
                MarkdownHeader = rawSettings,
                Content = response.Body.AsString(),
                Settings = settings,
                Year = date.Year,
                Month = date.Month,
                Day = date.Day,
                Date = date,
                Url = slug
            };

            postHeader.SetSnowSettings(snowSettings);
            postHeader.SetHeaderSettings(settings);

            return postHeader;
        }
Exemplo n.º 14
0
        public static Post GetFileData(FileInfo file, Browser browser, SnowSettings snowSettings)
        {
            var response        = browser.Get("/post/" + HttpUtility.UrlEncodeUnicode(file.Name));
            var rawPost         = File.ReadAllText(file.FullName);
            var fileNameMatches = FileNameRegex.Match(file.Name);
            var rawSettings     = string.Empty;

            if (!fileNameMatches.Success)
            {
                file.Name.OutputIfDebug(" - Skipping file: ");
                " - File does not match the format {year}-{month}-{day}-{slug}.(md|markdown)".OutputIfDebug();
                return(new Post.MissingPost());
            }

            var result   = ParseDataFromFile(rawPost);
            var settings = ParseSettings(result.Item1);

            var year  = fileNameMatches.Groups["year"].Value;
            var month = fileNameMatches.Groups["month"].Value;
            var day   = fileNameMatches.Groups["day"].Value;
            var slug  = fileNameMatches.Groups["slug"].Value.ToUrlSlug();
            var date  = DateTime.ParseExact(year + month + day, "yyyyMMdd", CultureInfo.InvariantCulture);

            var postHeader = new Post
            {
                FileName       = file.Name,
                MarkdownHeader = rawSettings,
                Content        = response.Body.AsString(),
                Settings       = settings,
                Year           = date.Year,
                Month          = date.Month,
                Day            = date.Day,
                Date           = date,
                Url            = slug
            };

            postHeader.SetSnowSettings(snowSettings);
            postHeader.SetHeaderSettings(settings);

            return(postHeader);
        }
Exemplo n.º 15
0
        private static bool ProcessFile(StaticFile staticFile, SnowSettings settings, IList<Post> parsedFiles, Browser browserComposer)
        {
            try
            {
                var processorName = staticFile.Loop ?? "";
                var processor = ProcessorFactory.Get(processorName.ToLower());

                if (processor == null)
                {
                    throw new ProcessorNotFoundException(processorName.ToLower());
                }

                processor.Process(new SnowyData
                {
                    Settings = settings,
                    Files = parsedFiles,
                    Browser = browserComposer,
                    File = staticFile
                }, settings);
            }
            catch (Exception exception)
            {
                Console.WriteLine();
                Console.WriteLine("Error processing static file: ");
                Console.WriteLine();
                Console.WriteLine(" - Loop: " + staticFile.Loop);
                Console.WriteLine(" - File: " + staticFile.File);
                Console.WriteLine(" - Message:");
                Console.WriteLine();
                Console.WriteLine(exception.Message);

                return false;
            }

            return true;
        }
Exemplo n.º 16
0
        private static void SetupOutput(SnowSettings settings)
        {
            if (!Directory.Exists(settings.PostsOutput))
            {
                Directory.CreateDirectory(settings.PostsOutput);
            }

            new DirectoryInfo(settings.PostsOutput).Empty();
        }
Exemplo n.º 17
0
        private static void ProcessFiles(StaticFile staticFile, SnowSettings settings, IList<Post> parsedFiles, Browser browserComposer)
        {
            try
            {
                TestModule.StaticFile = staticFile;

                var processorName = staticFile.Loop ?? "";
                var processor = ProcessorFactory.Get(processorName.ToLower());

                if (processor == null)
                {
                    throw new ProcessorNotFoundException(processorName.ToLower());
                }

                processor.Process(new SnowyData
                {
                    Settings = settings,
                    Files = parsedFiles,
                    Browser = browserComposer,
                    File = staticFile
                }, settings);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Error processing static file: ");
                Console.WriteLine("- " + staticFile.Loop);
                Console.WriteLine("- " + staticFile.File);
                Console.WriteLine("- Exception:");
                Console.WriteLine(exception);
            }
        }