예제 #1
0
        public static void Main(string[] args)
        {
            var options = new CommandlineOptions {
            };
            var parser  = new Parser((settings) =>
            {
                settings.HelpWriter = Console.Out;
            });

            var result = parser.ParseArguments <CommandlineOptions>(args);

            if (result.Tag == ParserResultType.Parsed)
            {
                result.WithParsed((opts) =>
                {
                    options = opts;
                });
                CreateProcessor(options);
                CreateWatcher(options);
                ScanDirectories(options);

                Console.WriteLine($"start watching for files is {options.Path} {options.Filter}");

                CreateWebHostBuilder(args).Build().Run();

                Console.WriteLine($"stop watching for files is {options.Path} {options.Filter}");
                watcher.Dispose();
                processor.Dispose();
            }
        }
예제 #2
0
        /// <summary>
        /// Run the logic of the app with the given parameters.
        /// Given folders are checked if they exist.
        /// </summary>
        /// <param name="o">Parsed commandline options.</param>
        private static void RunLogic(CommandlineOptions o)
        {
            options = o;
            message = new MessageHelper(options);

            // correction needed if relative path is given as parameter
            o.DocFolder = Path.GetFullPath(o.DocFolder);

            message.Verbose($"Documentation folder: {options.DocFolder}");
            message.Verbose($"Verbose             : {options.Verbose}");

            foreach (string file in Directory.EnumerateFiles(options.DocFolder, "*.*", SearchOption.AllDirectories))
            {
                allFiles.Add(file.ToLowerInvariant());
            }

            if (!Directory.Exists(options.DocFolder))
            {
                message.Error($"ERROR: Documentation folder '{options.DocFolder}' doesn't exist.");
                returnvalue = 1;
                return;
            }

            // we start at the root to generate the TOC items
            DirectoryInfo rootDir = new DirectoryInfo(options.DocFolder);

            WalkDirectoryTree(rootDir);

            if (options.Attachments)
            {
                CheckUnreferencedAttachments();
            }
        }
예제 #3
0
 private static IBackend CreateBackend(CommandlineOptions options)
 {
     switch (options.Backend)
     {
     case "gcs":
         return(new GCSBackend(options.DatabaseName, options.Dry));
     }
     throw new NotSupportedException(options.Backend);
 }
 public override void InitializePresenter(dynamic context)
 {
     _groupCount = 0;
     _options    = context.Options;
     if (_options.WriteToOutput)
     {
         _sw = _textWriter.Create(_options.OutputPath, true);
     }
 }
        /// <summary>
        /// Run the logic of the app with the given parameters.
        /// Given folders are checked if they exist.
        /// </summary>
        /// <param name="o">Parsed commandline options.</param>
        private static void RunLogic(CommandlineOptions o)
        {
            options = o;
            message = new MessageHelper(options);

            if (string.IsNullOrEmpty(options.OutputFolder))
            {
                options.OutputFolder = options.DocFolder;
            }

            message.Verbose($"Documentation folder: {options.DocFolder}");
            message.Verbose($"Output folder       : {options.OutputFolder}");
            message.Verbose($"Verbose             : {options.Verbose}");
            message.Verbose($"Use .order          : {options.UseOrder}");
            message.Verbose($"Use .override       : {options.UseOverride}");
            message.Verbose($"Use .ignore         : {options.UseIgnore}");
            message.Verbose($"Auto index          : {options.AutoIndex}\n");

            if (!Directory.Exists(options.DocFolder))
            {
                message.Error($"ERROR: Documentation folder '{options.DocFolder}' doesn't exist.");
                returnvalue = 1;
                return;
            }

            if (!Directory.Exists(options.OutputFolder))
            {
                message.Error($"ERROR: Destination folder '{options.OutputFolder}' doesn't exist.");
                returnvalue = 1;
                return;
            }

            // we start at the root to generate the TOC items
            TocItem       tocRootItems = new TocItem();
            DirectoryInfo rootDir      = new DirectoryInfo(options.DocFolder);

            WalkDirectoryTree(rootDir, tocRootItems);

            // we have the TOC, so serialize to a string
            using (StringWriter sw = new StringWriter())
            {
                using (IndentedTextWriter writer = new IndentedTextWriter(sw, "  "))
                {
                    writer.WriteLine("# This is an automatically generated file");
                    Serialize(writer, tocRootItems, true);
                }

                // now write the TOC to disc
                File.WriteAllText(Path.Combine(options.OutputFolder, "toc.yml"), sw.ToString());
            }

            message.Verbose($"{Path.Combine(options.OutputFolder, "toc.yml")} created.");
        }
예제 #6
0
        private static void ScanDirectories(CommandlineOptions options)
        {
            if (!System.IO.Directory.Exists(options.Path))
            {
                throw new ArgumentException(options.Path);
            }
            var subDirs = System.IO.Directory.GetDirectories(options.Path, "*", SearchOption.AllDirectories);

            foreach (var currentDir in subDirs)
            {
                processor.EnqueueItem(currentDir, null);
            }
        }
예제 #7
0
        private static ScriptRunner <Dictionary <string, string> > BuildScript <T>(CommandlineOptions options)
        {
            var scriptOptions = ScriptOptions.Default.
                                WithImports("System.IO", "System.Linq").
                                WithReferences(typeof(System.Linq.Enumerable).Assembly, typeof(System.IO.Path).Assembly, typeof(System.IO.DirectoryInfo).Assembly);

            var script = CSharpScript.Create <Dictionary <string, string> >(
                File.Exists(options.DataSourceScript) ? File.ReadAllText(options.DataSourceScript) : options.DataSourceScript,
                options: scriptOptions,
                globalsType: typeof(T));

            return(script.CreateDelegate());
        }
        public void PublicConstructor_ShouldSetUpInternalReferenceToDefaultParser()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var sut = new CommandlineOptions(new[] { "-h" }, RandomValueGen.GetRandomString(), RandomValueGen.GetRandomString());

            //---------------Test Result -----------------------
            var actual = sut.OptionsParser.GetPropertyValue("Actual");

            Assert.AreEqual(actual, Parser.Default);
        }
예제 #9
0
        public void TestLanguageOption()
        {
            var arguments = new[] { "-language", "de-DE" };

            CommandlineCaptureOptions captureOptions     = null;
            CommandlineOptions        commandlineOptions = null;

            Parser.Default.ParseArguments <CommandlineOptions>(arguments)
            .WithParsed(opts => commandlineOptions = opts)
            .WithNotParsed(errs => throw new Exception(string.Join(",", errs.Select(e => e.Tag))));

            Assert.Null(captureOptions);
            Assert.NotNull(commandlineOptions);
            Assert.Equal("de-DE", commandlineOptions.Language);
        }
예제 #10
0
        private static void CreateWatcher(CommandlineOptions options)
        {
            switch (options.Mode)
            {
            case "files":
                watcher = new FileWatcher(options.Path, options.Filter);
                break;

            case "single_file":
                watcher = new SingleFileWatcher(options.Path, options.Filter);
                break;

            default:
                throw new NotSupportedException(options.Mode);
            }
            watcher.OnFile += OnFile;
        }
예제 #11
0
 public static void Main(string[] args)
 {
     try
     {
         var commandlineOptions = new CommandlineOptions(args);
         foreach (var commandlineOption in commandlineOptions)
         {
             commandlineOption.Execute();
         }
     }
     catch (UnknownOptionException exception)
     {
         Console.WriteLine(exception.Message);
     }
     catch (ExecutionException exception)
     {
         Console.WriteLine(exception.Message);
     }
 }
예제 #12
0
        public void TestCaptureParser()
        {
            var arguments = new[] { "capture", "-s", "fullscreen", "-d", "Clipboard" };

            CommandlineCaptureOptions captureOptions     = null;
            CommandlineOptions        commandlineOptions = null;

            Parser.Default.ParseArguments <CommandlineOptions, CommandlineCaptureOptions>(arguments)
            .WithParsed <CommandlineCaptureOptions>(opts => captureOptions = opts)
            .WithParsed <CommandlineOptions>(opts => commandlineOptions    = opts)
            .WithNotParsed(errs => throw new Exception(string.Join(",", errs.Select(e => e.Tag))));

            Assert.NotNull(captureOptions);
            Assert.Null(commandlineOptions);

            Assert.NotEmpty(captureOptions.Destinations);
            Assert.NotEmpty(captureOptions.Source);

            Assert.Equal("fullscreen", captureOptions.Source);
            Assert.Contains("Clipboard", captureOptions.Destinations);
        }
예제 #13
0
        private static ConfigFileCrypter CreateCrypter(CommandlineOptions options)
        {
            ICertificateLoader certLoader = null;

            if (!string.IsNullOrEmpty(options.CertificatePath))
            {
                certLoader = new FilesystemCertificateLoader(options.CertificatePath);
            }
            else if (!string.IsNullOrEmpty(options.CertSubjectName))
            {
                certLoader = new StoreCertificateLoader(options.CertSubjectName);
            }

            var configCrypter = new JsonConfigCrypter(new RSACrypter(certLoader));

            var fileCrypter = new ConfigFileCrypter(configCrypter, new ConfigFileCrypterOptions()
            {
                ReplaceCurrentConfig = options.Replace
            });

            return(fileCrypter);
        }
예제 #14
0
        private static void CreateProcessor(CommandlineOptions options)
        {
            switch (options.Mode)
            {
            case "files":
                processor = new FileProcessor(
                    options.MaxWorkers,
                    CreateBackend(options),
                    BuildScript <Data>(options));
                break;

            case "single_file":
                processor = new SingleFileProcessor(
                    options.MaxWorkers,
                    CreateBackend(options),
                    BuildScript <SingleLineData>(options),
                    options.Path
                    );
                break;

            default:
                throw new NotSupportedException(options.Mode);
            }
        }
예제 #15
0
        public static async Task <VoiceBot> CreateInstanceAsync(CommandlineOptions opts)
        {
            if (instance != null)
            {
                // TRANSLATORS: Log message. Initializing Rein.
                Logger.Log(T._("Already initialized."));
                return(instance);
            }
            // TRANSLATORS: Log message. Initializing Rein.
            Logger.Log(T._("Load config ..."));
            try {
                Config.Initialize(opts);
                Config.Instance.Load();
                Config.Instance.MainConfig.Debug = opts.Debug;
                Logger.SetDebug(opts.Debug);
            } catch (Exception e) {
                // TRANSLATORS: Log message. Initializing Rein.
                Logger.Log(T._("Could not load config. Check your config file."));
                Logger.DebugLog(e.ToString());
                return(null);
            }
            Program.ShowVersions();
            // TRANSLATORS: Log message. Initializing Rein.
            Logger.Log(T._("Create VoiceBot ..."));
            try {
                instance = new VoiceBot();
            } catch (Exception e) {
                // TRANSLATORS: Log message. Initializing Rein.
                Logger.Log(T._("Could not load config. Check your config file."));
                Logger.DebugLog(e.ToString());
                return(null);
            }
            // TRANSLATORS: Log message. Initializing Rein.
            Logger.Log(T._("- set Discord events ..."));
            instance.discord.MessageReceived += instance.Client_MessageReceived;
            instance.discord.LoggedIn        += (async() => {
                await Task.Run(() => {
                    // TRANSLATORS: Log message. Initializing Rein.
                    Logger.Log(T._("- Logged in!"));
                });
            });
            instance.discord.LoggedOut += (async() => {
                await Task.Run(() => {
                    // TRANSLATORS: Log message. Initializing Rein.
                    Logger.Log(T._("- Logged out!"));
                });
            });
            instance.discord.Connected += (async() => {
                await Task.Run(() => {
                    // TRANSLATORS: Log message. Initializing Rein.
                    Logger.Log(T._("- Connected!"));
                });
            });
            instance.discord.Disconnected += (async(ex) => {
                await Task.Run(() => {
                    // TRANSLATORS: Log message. Initializing Rein.
                    Logger.Log(T._("- Disconnected!"));
                    if (ex != null)
                    {
                        // TRANSLATORS: DebugLog message. Initializing Rein.
                        Logger.DebugLog(T._("Exception in disconnecting:"));
                        Logger.DebugLog(ex.ToString());
                    }
                });
            });
            // TRANSLATORS: Log message. Initializing Rein.
            Logger.Log(T._("- login to Discord ..."));
            try {
                await instance.discord.LoginAsync(TokenType.Bot, Config.Instance.MainConfig.Token);

                await instance.discord.StartAsync();

                await instance.discord.SetGameAsync("Rein");
            } catch (Exception e) {
                // TRANSLATORS: Log message. Initializing Rein.
                Logger.Log(T._("Could not login to Discord. Please check bot account and its token."));
                Logger.DebugLog(e.ToString());
                instance.Dispose();
                instance = null;
                return(null);
            }
            var timeout = 0;

            while (true)
            {
                if (instance.discord.LoginState == LoginState.LoggedIn && instance.discord.ConnectionState == ConnectionState.Connected)
                {
                    // TRANSLATORS: Log message. Initializing Rein.
                    Logger.Log(T._("- Logged in and Connected!"));
                    break;
                }
                if (timeout > 300)
                {
                    timeout = -1;
                    break;
                }
                timeout++;
                await Task.Delay(100);
            }
            if (timeout < 0)
            {
                // TRANSLATORS: Log message. Initializing Rein.
                Logger.Log(T._("Could not login to Discord. Login challange was timeouted."));
                instance.Dispose();
                instance = null;
                return(null);
            }
            // TRANSLATORS: Log message. Initializing Rein.
            Logger.Log(T._("Start timer..."));
            instance.timer.Start();
            // TRANSLATORS: Log message. Initializing Rein.
            Logger.Log(T._("Done!"));
            Logger.Log("/////////////");
            Logger.Log("// Rein //");
            Logger.Log("/////////////");
            return(instance);
        }
예제 #16
0
 public Login(CommandlineOptions options)
 {
     username    = options.ApiUsername;
     password    = options.ApiPassword;
     application = options.ApiApplication;
 }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageHelper"/> class.
 /// </summary>
 /// <param name="options">Command line options.</param>
 public MessageHelper(CommandlineOptions options)
 {
     this.options = options;
 }