예제 #1
0
 /// <summary>
 /// Creates an in-memory content tracker token from a login.
 /// </summary>
 /// <param name="login">
 /// An authenticated user's login.
 /// </param>
 /// <param name="tracker">
 /// A reference to an in-memory content tracker.
 /// </param>
 public InMemoryContentTrackerToken(
     string login,
     InMemoryContentTracker tracker)
 {
     this.Login   = login;
     this.Tracker = tracker;
 }
        public static int Main(string[] args)
        {
            // Create a pretty log.
            var log = new RecordingLog(CreateDiagnosticLog(TerminalLog.Acquire()));

            // Parse command-line arguments.
            var optParser = new GnuOptionSetParser(Options.All);

            // Actually parse the options.
            var parsedOptions = optParser.Parse(args, log);

            if (log.Contains(Severity.Error))
            {
                // Ouch. Command-line arguments were bad. Stop testing now.
                return(1);
            }

            if (parsedOptions.GetValue <bool>(Options.Help))
            {
                // Print a cute little help message (to stdout instead of stderr).
                var helpLog = TerminalLog.AcquireStandardOutput();
                helpLog.Log(
                    new Pixie.LogEntry(
                        Severity.Message,
                        new HelpMessage(
                            "Runs an UnSHACLed collaboration server.",
                            "collaboration-server [options...]",
                            Options.All)));
                return(0);
            }

            var domainUris = ParseDomains(parsedOptions, log);

            if (parsedOptions.GetValue <bool>(Options.MockContentTracker))
            {
                var memTracker = new InMemoryContentTracker();
                memTracker.CreateRepository("dubious-developments", "editor-test");
                ContentTrackerCredentials.ContentTracker = memTracker;
            }
            else
            {
                var clientId     = parsedOptions.GetValue <string>(Options.ClientId);
                var clientSecret = parsedOptions.GetValue <string>(Options.ClientSecret);

                CheckMandatoryStringOptionHasArg(Options.ClientId, parsedOptions, log);
                CheckMandatoryStringOptionHasArg(Options.ClientSecret, parsedOptions, log);

                ContentTrackerCredentials.ContentTracker = new GitHubContentTracker(
                    domainUris[0], clientId, clientSecret);
            }

            if (log.Contains(Severity.Error))
            {
                // Looks like the options were ill-formatted.
                // An error has already been reported. Just exit.
                return(1);
            }

            GlobalLog = parsedOptions.GetValue <bool>(Options.Verbose)
                ? (ILog)log
                : new FilteringLog(log);

            using (var nancyHost = new NancyHost(new CorsBootstrapper(), domainUris))
            {
                nancyHost.Start();
                log.Log(
                    new LogEntry(
                        Severity.Message,
                        "server started",
                        "server is up now."));

                // Keep serving until the application is closed.
                while (true)
                {
                    Thread.Sleep(Timeout.Infinite);
                }
            }
        }