Exemple #1
0
        public void Run(ProgramComponentArgs args)
        {
            string[] currentEntries = Directory.GetFileSystemEntries(
                args.ParentDirPath).Select(
                e => Path.GetFileName(e)).ToArray();

            int i            = 1;
            var shortDirName = GetShortDirName(i);

            while (currentEntries.Contains(shortDirName))
            {
                i++;
                shortDirName = GetShortDirName(i);
            }

            string fullDirName = string.Join(' ', shortDirName, args.DirName);

            string shortDirPath = Path.Combine(args.ParentDirPath, shortDirName);
            string fullDirPath  = Path.Combine(args.ParentDirPath, fullDirName);

            Directory.CreateDirectory(shortDirPath);
            Directory.CreateDirectory(fullDirPath);

            string fileName = $"{fullDirName}.md";
            string filePath = Path.Combine(shortDirPath, fileName);

            string fileNameContent = $"# {args.DirName}{Environment.NewLine}";

            File.WriteAllText(filePath, fileNameContent);

            string nppArgs = GetNppArgs(filePath);

            Process.Start(NPP_PATH, nppArgs);
        }
Exemple #2
0
        public ProgramComponentArgs Parse(string[] args)
        {
            var parsedArgs       = new ProgramComponentArgs();
            int propParsersCount = propParsers.Count;

            for (int i = 0; i < propParsersCount; i++)
            {
                var    propParser = propParsers[i];
                string strArg     = GetStrArg(args, i, propParser.Item1);

                propParser.Item2(parsedArgs, strArg);
            }

            return(parsedArgs);
        }
Exemple #3
0
        static ProgramComponentArgsParser()
        {
            var d    = new ProgramComponentArgs();
            var list = new List <Tuple <string, Action <ProgramComponentArgs, string> > >();

            AddPropParser(list, nameof(d.ParentDirPath), (args, str) =>
            {
                if (string.IsNullOrWhiteSpace(str))
                {
                    args.ParentDirPath = Environment.CurrentDirectory;
                }
                else
                {
                    args.ParentDirPath = str;
                }
            });

            AddPropParser(list, nameof(d.DirName), (args, str) => args.DirName = str);

            propParsers = new ReadOnlyCollection <Tuple <string, Action <ProgramComponentArgs, string> > >(list.ToArray());
        }