Exemple #1
0
        void MainWindowLoaded(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                string defaultFileName = @"C:\users\leon\dropbox\secretgeek\all_someday_projects\ddd_linux_core\demo\scripts.md";
                var    f = new OpenFileDialog();

                if (File.Exists(defaultFileName))
                {
                    f.InitialDirectory = Path.GetDirectoryName(defaultFileName);
                    f.FileName         = Path.GetFileName(defaultFileName);
                }

                f.Title = "Select snippet file";
                var result = f.ShowDialog();

                if (result == true &&
                    File.Exists(f.FileName))
                {
                    fileName = f.FileName;
                }
                else
                {
                    // Failed to pick a file to load snippets from?
                    // Time to die, application.
                    Application.Current.Shutdown();
                    //Application.Exit();
                    return;
                }
            }

            //this.replacements = replacements ?? Replacement.CreateList("45.55.151.240`45.55.151.239,ddd-test-4`ddd-test-3");
            this.replacements = replacements ?? Replacement.CreateList("138.197.25.125`138.197.29.193");

            LoadSnippets(fileName);
            LoadReplacements(replacements);
            GetSnippet(snippetIndex);
        }
Exemple #2
0
 public Form1(string fileName, List <Replacement> replacements)
 {
     InitializeComponent();
     this.fileName     = fileName;
     this.replacements = replacements ?? Replacement.CreateList("45.55.151.240`45.55.151.239,ddd-test-4`ddd-test-3");
 }
Exemple #3
0
        public static Settings ParseArgs(string[] args)
        {
            var settings = new Settings();

            if (args.Length == 0)
            {
                return(settings);
            }

            AllocateConsole();

            var p = new OptionSet()
            {
                { "s|snippets=", "snippet file (separated by '#' comments)", s => settings.FileName = s },
                { "r|replacements=", "comma separated set of {{ReplaceThis}}`{{WithThis}} token pairs", s => settings.Replacements = Replacement.CreateList(s) },
                { "?|h|help", "show this message and exit", v => settings.ShowHelp = v != null }
            };

            List <string> extra;

            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException e)
            {
                //SIN: Coupling.
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\r\nError parsing arguments");

                Console.WriteLine(e.Message);
                Console.ResetColor();

                if (e.Option != null)
                {
                    int i = 0;
                    p.WriteOptionPrototype(Console.Out, e.Option, ref i);
                    p.WriteOptionDetails(Console.Out, e.Option, i);
                    Console.WriteLine();
                }

                Console.WriteLine(String.Format("Try '{0} --help' for more information.", Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)));
            }

            if (settings.ShowHelp)
            {
                ShowHelp(p);
            }

            return(settings);
        }