Exemple #1
0
        public static void Main(string[] args)
        {
            bool   optAllApps = false;
            bool   help       = false;
            bool   poolOpt    = false;
            string site       = "";

            var opts = new OptionSet()
            {
                { "h|help", "show this message and exit", v => help = true },
                { "a|apps", "List sites and applications under them.", v => optAllApps = true },
                { "p|pool", "Lists all application pools.", v => poolOpt = true }
            };

            List <string> extra;

            try
            {
                extra = opts.Parse(args);
            }
            catch (OptionException e) {
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `--help' for more information.");
                return;
            }

            if (help)
            {
                Usage(opts);
                return;
            }

            try
            {
                IISHandler handler = new IISHandler();

                if (poolOpt)
                {
                    handler.ListApplicationPools();
                    return;
                }

                if (extra != null && extra.Count == 1)
                {
                    site = extra[0];
                }

                if (optAllApps && String.IsNullOrEmpty(site))
                {
                    handler.ListAllApplications();
                }
                else if (!optAllApps && String.IsNullOrEmpty(site))
                {
                    handler.ListSites();
                }
                else if (!String.IsNullOrEmpty(site))
                {
                    handler.ListSiteApplications(site);
                }
            } catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }