Пример #1
0
        static void Main(string[] args)
        {
            string scanDirectory = Path.GetFullPath(args[0]);
            string outputDirectory = Path.GetFullPath(args[1]);

            Convertor convertor = new Convertor(new MarkdownSharpDialogue());
            WikiSite site = new WikiSite(
                new WikiConfig()
                {
                    SiteName = "Tester",
                    RootSourcePath = scanDirectory,
                    RootWikiPath = outputDirectory,
                    Convertor = new Convertor(new MarkdownSharpDialogue())
                },
                new MasterRepository(convertor.FileExtension),
                new NullSourceWatcher(),
                new PageCache());

            site.InitialisationComplete += site_InitialisationComplete;

            site.Start();

            waitHandle.WaitOne();

            site.Dispose();

            Console.Write("Done");
        }
Пример #2
0
        public TestWikiSite()
        {
            // setup initial site structure
            Directory.CreateDirectory(Path.Combine(".", "subdir1"));
            Directory.CreateDirectory(Path.Combine(".", "subdir1", "subdir2"));
            Directory.CreateDirectory(Path.Combine(".", "subdir1", "subdir2", "subdir3"));
            Directory.CreateDirectory(Path.Combine(".", "subdir1", "subdir2", "subdir3", "subdir4"));
            System.IO.File.AppendAllText(Path.Combine(".", "index.md"), "Hello World");
            System.IO.File.AppendAllText(Path.Combine(".", "subdir1", "index.md"), "Hello World Sub Directory");
            System.IO.File.AppendAllText(Path.Combine(".", "subdir1", "subdir2", "index.md"), "Hello World Sub Sub Directory");

            createdDirectories = new List<string>();
            updatedDirectories = new List<string>();
            deletedDirectories = new List<string>();
            movedDirectories = new List<string>();

            createdPages = new List<string>();
            updatedPages = new List<string>();
            deletedPages = new List<string>();
            movedPages = new List<string>();

            Convertor convertor = new Convertor(new MarkdownSharpDialogue());
            WikiConfig wikiConfig = new WikiConfig()
                {
                    SiteName = "Tester",
                    RootSourcePath = PathHelper.GetFullPath("."),
                    RootWikiPath = PathHelper.GetFullPath(".", "wiki"),
                    Convertor = new Convertor(new MarkdownSharpDialogue())
                };

            site = new WikiSite(wikiConfig,
                new MasterRepository(convertor.FileExtension),
                new SourceWatcher(wikiConfig.RootSourcePath, wikiConfig.Convertor.FileSearchString),
                new PageCache()
            );

            // setup event handlers
            site.DirectoryAdded += (source, args) => createdDirectories.Add(args.WikiUrl);
            site.DirectoryUpdated += (source, args) => updatedDirectories.Add(args.WikiUrl);
            site.DirectoryDeleted += (source, args) => deletedDirectories.Add(args.WikiUrl);
            site.DirectoryMoved += (source, args) => movedDirectories.Add(args.WikiUrl);

            site.PageAdded += (source, args) => createdPages.Add(args.WikiUrl);
            site.PageUpdated += (source, args) => updatedPages.Add(args.WikiUrl);
            site.PageDeleted += (source, args) => deletedPages.Add(args.WikiUrl);
            site.PageMoved += (source, args) => movedPages.Add(args.WikiUrl);

            site.Start();

            Thread.Sleep(1000);
        }
Пример #3
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/");
        }