示例#1
0
 public WikiBootstrapper(ServerConfig config, bool enableDiagnostics = false, string diagnosticsPassword = "")
     : base()
 {
     this.config = config;
     this.enableDiagnostics = enableDiagnostics;
     this.diagnosticsPassword = diagnosticsPassword;
 }
示例#2
0
        public ServerStartup(ServerConfig config, bool enableDiagnostics = false, string diagnosticsPassword = "")
        {
            serverConfig = config;
            sites = new Dictionary<string, WikiSite>();

            // TODO: Investigate event ordering if these two schedulers are in fact the same (slow handling seems to cause notifications out of order)
            notificationScheduler = new EventLoopScheduler(threadStart => new Thread(threadStart) { Name = "NotificationScheduler" });
            modelSyncScheduler = new EventLoopScheduler(threadStart => new Thread(threadStart) { Name = "ModelSyncScheduler" });

            foreach (var wikiConfig in config.AllConfig)
            {
                // get the relevant repositories
                MasterRepository masterRepository;
                IPageCache pageCache;
                if (serverConfig.TryGetMasterRepository(wikiConfig.SiteName, out masterRepository) &&
                    serverConfig.TryGetPageCache(wikiConfig.SiteName, out pageCache))
                {
                    var sourceWatcher = new SourceWatcher(wikiConfig.RootSourcePath, wikiConfig.Convertor.FileSearchString);

                    // create site
                    var site = new WikiSite(wikiConfig, masterRepository, sourceWatcher, pageCache);

                    // subscribe to all the sites events for notification purposes
                    EventHelper.SubscribeToWikiEvent<WikiSiteEventArgs>(site, "PageAdded", notificationScheduler, (args) => HandleEvent(site.Name, args.WikiUrl));
                    EventHelper.SubscribeToWikiEvent<WikiSiteEventArgs>(site, "PageUpdated", notificationScheduler, (args) => HandleEvent(site.Name, args.WikiUrl));
                    EventHelper.SubscribeToWikiEvent<WikiSiteEventArgs>(site, "PageDeleted", notificationScheduler, (args) => HandleEvent(site.Name, args.WikiUrl));
                    EventHelper.SubscribeToWikiEvent<WikiSiteEventArgs>(site, "PageMoved", notificationScheduler, (args) => HandleEvent(site.Name, args.WikiUrl));
                    EventHelper.SubscribeToWikiEvent<WikiSiteEventArgs>(site, "DirectoryAdded", notificationScheduler, (args) => HandleEvent(site.Name, args.WikiUrl));
                    EventHelper.SubscribeToWikiEvent<WikiSiteEventArgs>(site, "DirectoryUpdated", notificationScheduler, (args) => HandleEvent(site.Name, args.WikiUrl));
                    EventHelper.SubscribeToWikiEvent<WikiSiteEventArgs>(site, "DirectoryDeleted", notificationScheduler, (args) => HandleEvent(site.Name, args.WikiUrl));
                    EventHelper.SubscribeToWikiEvent<WikiSiteEventArgs>(site, "DirectoryMoved", notificationScheduler, (args) => HandleEvent(site.Name, args.WikiUrl));

                    // store
                    sites[wikiConfig.SiteName] = site;
                }
            }

            WikiBootstrapper bootstrapper = new WikiBootstrapper(config, enableDiagnostics, diagnosticsPassword);

            nancyHost = new NancyHost(new Uri("http://localhost:8070/"), bootstrapper);
            signalrHost = new Server("http://localhost:8071/");
        }
示例#3
0
文件: Program.cs 项目: sbyse/icklewik
        static void StartUp(string[] args)
        {
            Thread.CurrentThread.Name = "Main";

            string coreDirectory = "D:\\ickletest";

            File.WriteAllText(Path.Combine(coreDirectory, "index.md"), "Hello World");

            Directory.CreateDirectory(Path.Combine(coreDirectory, "subdir"));

            // reference the bootstrapper (and turn on diagnostics)
            ServerConfig serverConfig = new ServerConfig(
                new List<Tuple<WikiConfig, IPageCache>>()
                {
                    new Tuple<WikiConfig, IPageCache>(
                        new WikiConfig()
                        {
                            SiteName = "Tester",
                            RootSourcePath = PathHelper.GetFullPath(coreDirectory),
                            RootWikiPath = PathHelper.GetFullPath(coreDirectory, "wiki"),
                            Convertor = new Convertor(new MarkdownSharpDialogue())
                        },
                        new PageCache()
                    )
                });

            // add filters
            foreach (var config in serverConfig.AllConfig)
            {
                config.Convertor.PostConvertors.Add(new MarkdownLinkPostFilter());
            }

            // basic startup pattern taken from:
            // https://github.com/loudej/owin-samples/blob/master/src/ConsoleNancySignalR/Program.cs
            // TODO: All this Gate/Owin stuff seems to be up in the air so this code needs reviewing
            // at some point

            startup = new ServerStartup(serverConfig, true, "password"); // this program's Startup.cs class

            startup.Start();

            Thread.Sleep(100);

            // add another page
            File.WriteAllText(Path.Combine(coreDirectory, "firstFile.md"), "Hello Again");

            // and another
            File.WriteAllText(Path.Combine(coreDirectory, "subdir", "index.md"), "Hello World Sub Directory");

            // then delete one
            File.Delete(Path.Combine(coreDirectory, "index.md"));
        }
示例#4
0
        public WikiModule(ServerConfig serverConfig)
            : base("/wiki")
        {
            config     = serverConfig;
            fileReader = new FileReader(FileReaderPolicy.LimitedBlock, 500);

            // add top level "site" route
            Get["/{site}"] = parameters =>
            {
                WikiConfig       wikiConfig       = null;
                MasterRepository masterRepository = null;
                if (config.TryGetConfig(parameters["site"], out wikiConfig) &&
                    config.TryGetMasterRepository(parameters["site"], out masterRepository))
                {
                    // TODO: Async-ify this
                    var pageResults = masterRepository.GetAvailableAssets().Result;

                    SiteModel model = new SiteModel()
                    {
                        IsPartialView = Request.Query.isPartial,
                        WikiUrl       = "/",
                        SiteMap       = pageResults
                    };

                    Context.ViewBag.SiteName = wikiConfig.SiteName;

                    return(View["Site.cshtml", model]);
                }
                else
                {
                    return(HttpStatusCode.NotFound);
                }
            };

            // add "directory" route, subpath should not contain a "." or a "/"
            Get[@"/{site}/(?<directory>[^\.]*)"] = parameters =>
            {
                WikiConfig wikiConfig;
                if (config.TryGetConfig(parameters["site"], out wikiConfig) &&
                    Directory.Exists(Path.Combine(wikiConfig.RootWikiPath, parameters["directory"])))
                {
                    DirectoryModel model = new DirectoryModel()
                    {
                        IsPartialView = Request.Query.isPartial,
                        WikiUrl       = parameters["directory"],
                    };

                    Context.ViewBag.SiteName = wikiConfig.SiteName;

                    return(View["Directory.cshtml", model]);
                }
                else
                {
                    return(HttpStatusCode.NotFound);
                }
            };

            // add "page" route, subpath should always have a file extension (and therefore at least one ".")
            Get[@"/{site}/(?<page>.*\..*)"] = parameters =>
            {
                WikiConfig       wikiConfig       = null;
                MasterRepository masterRepository = null;
                if (config.TryGetConfig(parameters["site"], out wikiConfig) &&
                    config.TryGetMasterRepository(parameters["site"], out masterRepository))
                {
                    // Async-ify
                    var results = masterRepository.GetPageByWikiUrl(parameters["page"]).Result;

                    if (results.Item1)
                    {
                        var results2 = TryGetPageContents(parameters["site"], results.Item2);

                        if (results2.Item1)
                        {
                            PageModel model = new PageModel()
                            {
                                IsPartialView = Request.Query.isPartial,
                                WikiUrl       = parameters["page"],
                                Contents      = results2.Item2
                            };

                            Context.ViewBag.SiteName = wikiConfig.SiteName;

                            return(View["Page.cshtml", model]);
                        }
                        else
                        {
                            // TODO: If the file doesn't exist we could potentially remove it from the cache
                            return(HttpStatusCode.NotFound);
                        }
                    }
                    else
                    {
                        // TODO: If the file doesn't exist we could potentially remove it from the cache
                        return(HttpStatusCode.NotFound);
                    }
                }
                else
                {
                    return(HttpStatusCode.NotFound);
                }
            };
        }
示例#5
0
        public WikiModule(ServerConfig serverConfig)
            : base("/wiki")
        {
            config = serverConfig;
            fileReader = new FileReader(FileReaderPolicy.LimitedBlock, 500);

            // add top level "site" route
            Get["/{site}"] = parameters =>
                {
                    WikiConfig wikiConfig = null;
                    MasterRepository masterRepository = null;
                    if (config.TryGetConfig(parameters["site"], out wikiConfig) &&
                        config.TryGetMasterRepository(parameters["site"], out masterRepository))
                    {
                        // TODO: Async-ify this
                        var pageResults = masterRepository.GetAvailableAssets().Result;

                        SiteModel model = new SiteModel()
                        {
                            IsPartialView = Request.Query.isPartial,
                            WikiUrl = "/",
                            SiteMap = pageResults
                        };

                        Context.ViewBag.SiteName = wikiConfig.SiteName;

                        return View["Site.cshtml", model];
                    }
                    else
                    {
                        return HttpStatusCode.NotFound;
                    }
                };

            // add "directory" route, subpath should not contain a "." or a "/"
            Get[@"/{site}/(?<directory>[^\.]*)"] = parameters =>
                {
                    WikiConfig wikiConfig;
                    if (config.TryGetConfig(parameters["site"], out wikiConfig) && 
                        Directory.Exists(Path.Combine(wikiConfig.RootWikiPath, parameters["directory"])))
                    {
                        DirectoryModel model = new DirectoryModel()
                        {
                            IsPartialView = Request.Query.isPartial,
                            WikiUrl = parameters["directory"],
                        };

                        Context.ViewBag.SiteName = wikiConfig.SiteName;

                        return View["Directory.cshtml", model];
                    }
                    else
                    {
                        return HttpStatusCode.NotFound;
                    }
                };

            // add "page" route, subpath should always have a file extension (and therefore at least one ".")
            Get[@"/{site}/(?<page>.*\..*)"] = parameters => 
                {
                    WikiConfig wikiConfig = null;
                    MasterRepository masterRepository = null;
                    if (config.TryGetConfig(parameters["site"], out wikiConfig) &&
                        config.TryGetMasterRepository(parameters["site"], out masterRepository))
                    {
                        // Async-ify
                        var results = masterRepository.GetPageByWikiUrl(parameters["page"]).Result;

                        if (results.Item1)
                        {
                            var results2 = TryGetPageContents(parameters["site"], results.Item2);

                            if (results2.Item1)
                            {
                                PageModel model = new PageModel()
                                {
                                    IsPartialView = Request.Query.isPartial,
                                    WikiUrl = parameters["page"],
                                    Contents = results2.Item2
                                };

                                Context.ViewBag.SiteName = wikiConfig.SiteName;

                                return View["Page.cshtml", model];
                            }
                            else
                            {
                                // TODO: If the file doesn't exist we could potentially remove it from the cache
                                return HttpStatusCode.NotFound;
                            }
                        }
                        else
                        {
                            // TODO: If the file doesn't exist we could potentially remove it from the cache
                            return HttpStatusCode.NotFound;
                        }
                    }
                    else
                    {
                        return HttpStatusCode.NotFound;
                    }
                };
        }