Ejemplo n.º 1
0
        /// <summary>
        /// Displays program greeting.
        /// </summary>
        /// <param name="pOutS"></param>
        private static void WriteGreeting(iOutputStream pOutS)
        {
            Assembly        assembly = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
            string          version  = fvi.FileVersion;

            pOutS.Standard(string.Format(Resource.Greeting_Version, version));
            pOutS.Standard(Resource.Greeting_Company);
            pOutS.Standard(Resource.Greeting_Contact);
            pOutS.Standard("");
        }
Ejemplo n.º 2
0
 private static string getStandard(iOutputStream pOutput, string pStr)
 {
     using (StringWriter sw = new StringWriter())
     {
         Console.SetOut(sw);
         pOutput.Standard(pStr);
         return(sw.ToString().Trim());
     }
 }
Ejemplo n.º 3
0
        public void Create()
        {
            ConsoleFactory factory = new ConsoleFactory();
            iOutputStream  stream  = factory.Create();

            Assert.IsNotNull(stream);

            stream.Standard("test");
            stream.Error("test");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Displays a parameter description.
        /// </summary>
        /// <param name="pMaxNameWidth">Width of the name column.</param>
        /// <param name="pDesc">The parameter description to display.</param>
        private void Display(int pMaxNameWidth, Description pDesc)
        {
            int max = pMaxNameWidth + _options.Prefix.Length;

            string    padding   = new String(' ', max);
            const int chunkSize = 80;

            string[] lines = SplitByLength(pDesc.Help, chunkSize).ToArray();

            for (int i = 0; i < lines.Length; i++)
            {
                string format = i == 0 ? @"  {0} {1}" : "  {2} {1}";

                string name = (pDesc.Role == eROLE.NAMED ? _options.Prefix : "") +
                              pDesc.Name +
                              (pDesc.Scope == eSCOPE.OPTIONAL ? "*" : "");

                _output.Standard(string.Format(format,
                                               name.PadRight(max),
                                               lines[i],
                                               padding));
            }
        }
Ejemplo n.º 5
0
 private static string getStandard(iOutputStream pOutput, string pStr)
 {
     using (StringWriter sw = new StringWriter())
     {
         Console.SetOut(sw);
         pOutput.Standard(pStr);
         return sw.ToString().Trim();
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Entry
        /// </summary>
        /// <param name="pArgs">The arguments from the command line.</param>
        private static void Main(string[] pArgs)
        {
            ConsoleFactory consoleFactory = new ConsoleFactory();
            iOutputStream  outS           = consoleFactory.Create();

            WriteGreeting(outS);

            CliOptions options = CliOptions.WindowsStyle;

            List <Description> descs = DescriptionFactory.Create(
                options, new HelpResource(Help.ResourceManager),
                "[/domains:string] [/limit:int] [/count] [/sort:string] [/desc] [/max:int] [/min:int] pattern"
                );

            if (pArgs.Length == 0)
            {
                OutputHelp outputHelp = new OutputHelp(options, consoleFactory.Create());
                outputHelp.Show(descs);
                return;
            }

            Request req = RequestFactory.Create(options, pArgs, descs, consoleFactory);

            if (!req.Valid)
            {
                return;
            }

            string pattern = req.Get <string>("pattern");

            outS.Standard(pattern);
            outS.Standard("");

            int max = req.Contains("max") ? Math.Min(req.Get <int>("max"), _MAX_LENGTH) :_MAX_LENGTH;
            int min = req.Contains("min") ? Math.Max(req.Get <int>("min"), 1) : 1;

            IEnumerable <string> domains = (from topLevel in getTopLevel(req)
                                            from domain in getPattern(req)
                                            where !domain.StartsWith("-") &&
                                            !domain.EndsWith("-") &&
                                            domain.Length <= max &&
                                            domain.Length >= min
                                            let str = string.Format("{0}.{1}", domain, topLevel)
                                                      where str.Length <= _MAX_LENGTH &&
                                                      !AnyLabelTooLong(domain, 63)
                                                      select str).Distinct();

            if (req.Contains("count"))
            {
                outS.Standard(domains.Count().ToString(CultureInfo.InvariantCulture));
                return;
            }

            if (req.Contains("sort"))
            {
                string sort = req.Get <string>("sort").ToLower();
                domains = sort == "width"
                    ? domains.OrderBy(pDomain => pDomain.Length)
                    : domains.OrderBy(pDomain => pDomain);

                if (req.Contains("desc"))
                {
                    domains = domains.Reverse();
                }
            }

            foreach (string domain in setLimit(req, domains))
            {
                if (isFree(domain))
                {
                    outS.Standard(domain);
                }
            }
        }