Exemple #1
0
        private static void Main(string[] args)
        {
            StaticConfiguration.DisableErrorTraces = false;

            Console.WriteLine("Sandra.Snow : " + DateTime.Now.ToString("HH:mm:ss") + " : Begin processing");

            try
            {
                var commands = args.Select(x => x.Split('=')).ToDictionary(x => x[0], x => x[1]);

                if (commands.ContainsKey("debug"))
                {
                    DebugHelperExtensions.EnableDebugging();
                }

                if (commands.ContainsKey("vsdebug"))
                {
                    DebugHelperExtensions.WaitForContinue();
                }

                string currentDir;

                if (commands.ContainsKey("config"))
                {
                    currentDir = new FileInfo(commands["config"]).DirectoryName;
                }
                else
                {
                    currentDir = Path.GetDirectoryName(typeof(Program).Assembly.Location);
                }

                currentDir.OutputIfDebug(prefixWith: " - Current directory: ");

                var settings = CreateSettings(currentDir);

                var extensions = new HashSet <string>(new[] { ".md", ".markdown" }, StringComparer.OrdinalIgnoreCase);
                var files      = new DirectoryInfo(settings.Posts).EnumerateFiles()
                                 .Where(x => extensions.Contains(x.Extension));

                SetupOutput(settings);

                StaticPathProvider.Path = settings.CurrentDir;
                SnowViewLocationConventions.Settings = settings;

                var posts = files.Select(x => PostParser.GetFileData(x, settings))
                            .OrderByDescending(x => x.Date)
                            .Where(x => x.Published != Published.Private && !(x is Post.MissingPost))
                            .ToList();

                posts.SetPostUrl(settings);
                posts.UpdatePartsToLatestInSeries();

                TestModule.Posts      = posts;
                TestModule.Drafts     = posts.Where(x => x.Published == Published.Draft).ToList();
                TestModule.Categories = CategoriesPage.Create(posts);
                TestModule.PostsGroupedByYearThenMonth = ArchivePage.Create(posts);
                TestModule.MonthYear = ArchiveMenu.Create(posts);
                TestModule.Settings  = settings;

                var browserComposer = new Browser(with =>
                {
                    with.Module <TestModule>();
                    with.RootPathProvider <StaticPathProvider>();
                    with.ViewEngines(typeof(SuperSimpleViewEngineWrapper), typeof(RazorViewEngine));
                });

                // Compile all Posts
                posts.ForEach(x => ComposeParsedFiles(x, settings.Output, browserComposer));

                // Compile all Drafts
                var drafts = posts.Where(x => x.Published == Published.Draft).ToList();
                drafts.ForEach(x => ComposeDrafts(x, settings.Output, browserComposer));

                // Compile all static files
                foreach (var processFile in settings.ProcessFiles)
                {
                    var success =
                        ProcessFile(processFile, settings, posts, browserComposer);

                    if (!success)
                    {
                        break;
                    }
                }

                foreach (var copyDirectory in settings.CopyDirectories)
                {
                    var sourceDir = (settings.ThemesDir + Path.DirectorySeparatorChar + settings.Theme + Path.DirectorySeparatorChar + copyDirectory);

                    var destinationDir = copyDirectory;

                    if (copyDirectory.Contains(" => "))
                    {
                        var directorySplit = copyDirectory.Split(new[] { " => " }, StringSplitOptions.RemoveEmptyEntries);

                        sourceDir      = directorySplit[0];
                        destinationDir = directorySplit[1];
                    }

                    var source = Path.Combine(settings.CurrentDir, sourceDir);

                    if (!Directory.Exists(source))
                    {
                        source = Path.Combine(settings.CurrentDir, copyDirectory);

                        if (!Directory.Exists(source))
                        {
                            copyDirectory.OutputIfDebug("Unable to find the directory, so we're skipping it: ");
                            continue;
                        }
                    }

                    // If the destination directory is "." copy the folder files to the output folder root
                    var destination = destinationDir == "." ? settings.Output : Path.Combine(settings.Output, destinationDir);

                    new DirectoryInfo(source).Copy(destination, true);
                }

                foreach (var copyFile in settings.CopyFiles)
                {
                    var sourceFile      = (settings.ThemesDir + Path.DirectorySeparatorChar + settings.Theme + Path.DirectorySeparatorChar + copyFile);
                    var source          = Path.Combine(settings.CurrentDir, sourceFile);
                    var destinationFile = copyFile;

                    if (!File.Exists(source))
                    {
                        source = Path.Combine(settings.CurrentDir, copyFile);

                        if (!File.Exists(source))
                        {
                            copyFile.OutputIfDebug("Unable to find the directory, so we're skipping it: ");
                            continue;
                        }
                    }

                    var destination = Path.Combine(settings.Output, destinationFile);

                    File.Copy(source, destination, true);
                }

                Console.WriteLine("Sandra.Snow : " + DateTime.Now.ToString("HH:mm:ss") + " : Finish processing");

                if (commands.ContainsKey("server"))
                {
                    SnowServer.Start(settings);
                }

                if (commands.ContainsKey("debug"))
                {
                    DebugHelperExtensions.WaitForContinue();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.ToString());

                DebugHelperExtensions.WaitForContinue();
            }
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Sandra.Snow : " + DateTime.Now.ToString("HH:mm:ss") + " : Begin processing");

            try
            {
                var commands = args.Select(x => x.Split('=')).ToDictionary(x => x[0], x => x[1]);

                if (commands.ContainsKey("debug"))
                {
                    DebugHelperExtensions.EnableDebugging();
                }

                string currentDir;

                if (commands.ContainsKey("config"))
                {
                    currentDir = new FileInfo(commands["config"]).DirectoryName;
                }
                else
                {
                    currentDir = Path.GetDirectoryName(typeof(Program).Assembly.Location);
                }

                currentDir.OutputIfDebug(prefixWith: "current directory: ");

                var settings = CreateSettings(currentDir);

                var extensions = new HashSet <string>(new[] { ".md", ".markdown" }, StringComparer.OrdinalIgnoreCase);
                var files      = new DirectoryInfo(settings.Posts).EnumerateFiles()
                                 .Where(x => extensions.Contains(x.Extension));

                SetupOutput(settings);

                StaticPathProvider.Path = settings.CurrentDir;
                SnowViewLocationConventions.Settings = settings;

                var browserParser = new Browser(with =>
                {
                    with.Module <TestModule>();
                    with.RootPathProvider <StaticPathProvider>();
                    with.ViewEngine <CustomMarkDownViewEngine>();
                });

                var posts = files.Select(x => PostParser.GetFileData(x, browserParser, settings))
                            .OrderByDescending(x => x.Date)
                            .Where(x => x.Published != Published.Private)
                            .ToList();

                posts.SetPostUrl(settings);
                posts.UpdatePartsToLatestInSeries();

                TestModule.Posts      = posts;
                TestModule.Drafts     = posts.Where(x => x.Published == Published.Draft).ToList();
                TestModule.Categories = CategoriesPage.Create(posts);
                TestModule.PostsGroupedByYearThenMonth = ArchivePage.Create(posts);
                TestModule.MonthYear = ArchiveMenu.Create(posts);
                TestModule.Settings  = settings;

                var browserComposer = new Browser(with =>
                {
                    with.Module <TestModule>();
                    with.RootPathProvider <StaticPathProvider>();
                    with.ViewEngines(typeof(SuperSimpleViewEngineWrapper), typeof(RazorViewEngine));
                });

                // Compile all Posts
                posts.ForEach(x => ComposeParsedFiles(x, settings.Output, browserComposer));

                // Compile all Drafts
                var drafts = posts.Where(x => x.Published == Published.Draft).ToList();
                drafts.ForEach(x => ComposeDrafts(x, settings.Output, browserComposer));

                // Compile all static files
                settings.ProcessFiles.ForEach(x => ProcessFiles(x, settings, posts, browserComposer));

                foreach (var copyDirectory in settings.CopyDirectories)
                {
                    var sourceDir      = copyDirectory;
                    var destinationDir = copyDirectory;

                    if (copyDirectory.Contains(" => "))
                    {
                        var directorySplit = copyDirectory.Split(new[] { " => " }, StringSplitOptions.RemoveEmptyEntries);

                        sourceDir      = directorySplit[0];
                        destinationDir = directorySplit[1];
                    }

                    var source      = Path.Combine(settings.CurrentDir, sourceDir);
                    var destination = Path.Combine(settings.Output, destinationDir);
                    new DirectoryInfo(source).Copy(destination, true);
                }

                if (commands.ContainsKey("debug"))
                {
                    DebugHelperExtensions.WaitForContinue();
                }

                Console.WriteLine("Sandra.Snow : " + DateTime.Now.ToString("HH:mm:ss") + " : Finish processing");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                DebugHelperExtensions.WaitForContinue();
            }
        }