private Boolean GetFrontendInfo()
        {
            txtProcessInfo.Text += Environment.NewLine + "Coletando dados de instalação...";
            const String retrieveFail = "Falha ao coletar dados de instalação. ";

            if (String.IsNullOrEmpty(txtSiteName.Text))
            {
                txtProcessInfo.Text += Environment.NewLine + retrieveFail + Environment.NewLine + "É necessário informar o nome do site. ";
                return(false);
            }

            String iisDirectory = IISHandler.GetWebRootDirectory();

            if (iisDirectory == null)
            {
                txtProcessInfo.Text += Environment.NewLine + retrieveFail + Environment.NewLine + "Não foi possivel localizar o diretório base do IIS (wwwRoot). ";
                txtProcessInfo.Text += Environment.NewLine + "Verifique se o Internet Information Services está instalado.";
                return(false);
            }

            // Ajusta o formato do caminho de instalação
            String installDirectory = PathFormat.Adjust(iisDirectory) + (txtSiteName.Text + "WebDir");

            // Se não houve nenhuma falha retorna informações do frontend e notifica sucesso
            frontendInfo = new FrontendInfo(txtSiteName.Text, installDirectory);
            return(true);
        }
示例#2
0
        AddApplication(IISHandler handler, string physPath, string siteName)
        {
            String[] paths = null;
            if (PathHelper.ContainsWildcard(physPath))
            {
                paths = PathHelper.ExpandWildcardDirectories(physPath);
                foreach (var subPath in paths)
                {
                    string virPath = "";
                    Site   site    = handler.GetSiteByName(siteName);
                    if (site != null)
                    {
                        virPath = PathHelper.SuggestVirtualDirectory(site, subPath);
                    }

                    AddApplication(handler, virPath, subPath, siteName);
                }
            }
            else
            {
                string virPath = "";
                Site   site    = handler.GetSiteByName(siteName);
                if (site != null)
                {
                    virPath = PathHelper.SuggestVirtualDirectory(site, physPath);
                }

                AddApplication(handler, virPath, physPath, siteName);
            }
        }
示例#3
0
文件: mksite.cs 项目: thehexia/iismgr
        private static void SetPool(IISHandler handler, string siteName, string poolName)
        {
            Site            site = handler.GetSiteByName(siteName);
            ApplicationPool pool = handler.AddApplicationPool(poolName);

            handler.SetSiteApplicationPool(site, pool);
        }
示例#4
0
        public static void Main(string[] args)
        {
            bool recursiveRmv = false;
            bool help         = false;

            var opts = new OptionSet()
            {
                { "h|help", "show this message and exit", v => help = true },
                { "r|recursive", "recursively remove all sub applications", v => recursiveRmv = true }
            };

            // All arguments that are not options or optional arguments.
            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();
                // Handle two possible arguments.
                if (extra.Count == 2)
                {
                    if (recursiveRmv)
                    {
                        RemoveApplicationRecursively(handler, extra[0], extra[1]);
                    }
                    else
                    {
                        RemoveApplication(handler, extra[0], extra[1]);
                    }
                }
                else
                {
                    Console.WriteLine("Invalid usage. Use --help.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#5
0
        public static void Main(string[] args)
        {
            bool help = false;
            var  opts = new OptionSet()
            {
                { "h|help", "show this message and exit", v => help = true },
            };

            // All arguments that are not options or optional arguments.
            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();
                string     kind    = "";
                if (!(extra.Count > 1))
                {
                    throw new ArgumentException("Not enough arguments.");
                }

                kind = extra[0];
                if (kind.Equals("add"))
                {
                    handler.AddApplicationPool(extra[1]);
                }
                else if (kind.Equals("remove"))
                {
                    handler.RemoveApplicationPool(extra[1]);
                }
                else
                {
                    Usage(opts);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        private Boolean InstallWebFrontend()
        {
            txtProcessInfo.Text += Environment.NewLine + "Iniciando instalação...";
            const String installFail = "Falha ao instalar frontend web. ";

            // Verifica se o ASP.NET está registrado no IIS
            Boolean aspNetRegistered = IISHandler.IsAspNetRegistered();

            if (!aspNetRegistered)
            {
                txtProcessInfo.Text += Environment.NewLine + installFail + Environment.NewLine + "O ASP.NET 2.0 não está registrado/habilitado no IIS.";
                return(false);
            }

            // Tenta criar os diretórios virtuais no IIS
            IISHandler iisHandler          = new IISHandler();
            Boolean    dirCreated          = false;
            String     webAccountingDir    = PathFormat.Adjust(frontendInfo.installDirectory) + "WebAccounting";
            String     webAdministratorDir = PathFormat.Adjust(frontendInfo.installDirectory) + "WebAdministrator";

            dirCreated = iisHandler.CreateVirtualDirectory(txtSiteName.Text, webAccountingDir, "LoginPage.aspx");
            if (!dirCreated)
            {
                txtProcessInfo.Text += Environment.NewLine + installFail + Environment.NewLine + iisHandler.GetLastError();
                return(false);
            }
            dirCreated = iisHandler.CreateVirtualDirectory(txtSiteName.Text + "Admin", webAdministratorDir, "LoginPage.aspx");
            if (!dirCreated)
            {
                txtProcessInfo.Text += Environment.NewLine + installFail + Environment.NewLine + iisHandler.GetLastError();
                return(false);
            }

            // Pergunta ao usuário se deseja reiniciar o IIS
            String dialogText = "O instalador precisa reiniciar o serviço de publicação na internet (IIS)." + Environment.NewLine +
                                "Escolha 'sim' para reiniciar agora ou 'não' para reiniciar mais tarde.";
            DialogResult dialogResult = MessageBox.Show(dialogText, "Reiniciar IIS agora?", MessageBoxButtons.YesNo);

            if (dialogResult != DialogResult.Yes)
            {
                return(true);                                  // recusou IISreset, sai do instalador (instalação OK)
            }
            // Tenta resetar o IIS
            Boolean iisReset = iisHandler.ResetIIS();

            if (!iisReset)
            {
                txtProcessInfo.Text += Environment.NewLine + installFail + Environment.NewLine + iisHandler.GetLastError();
                return(false);
            }

            // Se não houve nenhuma falha notifica sucesso
            return(true);
        }
示例#7
0
        RemoveApplication(IISHandler handler, string appName, string siteName)
        {
            if (appName.Equals("/"))
            {
                Console.WriteLine(appName + " cannot be removed safely. It is the site default. Removing would corrupt website.");
                return;
            }

            String[] paths = null;
            if (PathHelper.ContainsWildcard(appName))
            {
                Site site = handler.GetSiteByName(siteName);
                if (site == null)
                {
                    Console.WriteLine("Site " + siteName + " does not exist.");
                    return;
                }

                paths = PathHelper.ExpandWildcardDirectories(appName);
                List <Application> apps =
                    new List <Application>(site.Applications.Where(p => paths.Contains(p.VirtualDirectories["/"].PhysicalPath)));

                foreach (var app in apps)
                {
                    Console.WriteLine("Removing app " + app);
                    try
                    {
                        handler.RemoveApplicationNonCommit(site, app);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

                handler.CommitChanges();
                return;
            }

            try
            {
                handler.RemoveApplication(siteName, appName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#8
0
        RemoveApplicationRecursively(IISHandler handler, string appPrefix, string siteName)
        {
            if (appPrefix.Equals("/"))
            {
                Console.WriteLine(appPrefix + " cannot be removed safely. It is the site default. Removing would corrupt website.");
                return;
            }

            try
            {
                Site site = handler.GetSiteByName(siteName);
                if (site == null)
                {
                    Console.WriteLine("Site " + siteName + " does not exist.");
                    return;
                }

                if (!appPrefix.StartsWith(site.Name))
                {
                    appPrefix = site.Name + appPrefix;
                }

                List <Application> apps =
                    new List <Application>(site.Applications
                                           .Where(p => p.ToString().StartsWith(appPrefix)));

                foreach (var app in apps)
                {
                    Console.WriteLine("Removing app: " + app);
                    try
                    {
                        handler.RemoveApplicationNonCommit(site, app);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                handler.CommitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#9
0
        AddApplication(IISHandler handler, string virPath, string physPath, string siteName)
        {
            string fullPath = Path.GetFullPath(physPath);

            Console.WriteLine("Adding app from dir: " + fullPath);
            Console.WriteLine("With virtual dir: " + virPath);
            Site site = handler.GetSiteByName(siteName);

            try
            {
                if (site != null)
                {
                    site.Applications.Add(virPath, fullPath);
                }
            }
            catch (Exception e) { Console.WriteLine(e.Message); }

            handler.CommitChanges();
        }
示例#10
0
        public static void Main(string[] args)
        {
            bool recursiveAdd = false;
            bool help         = false;

            var opts = new OptionSet()
            {
                { "h|help", "show this message and exit", v => help = true },
                { "r|recursive", "recursively add all sub folders", v => recursiveAdd = true }
            };

            // All arguments that are not options or optional arguments.
            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();
                // Handle two possible arguments.
                if (extra.Count == 2)
                {
                    if (recursiveAdd)
                    {
                        // Add the top level folder.
                        AddApplication(handler, extra[0], extra[1]);
                        // Recursively find all subfolders excluding bin and App_* folders.
                        List <string> dirs = PathHelper.GetDirectoriesRecursively(extra[0]);
                        // Add sub folders to the site as applications.
                        foreach (var dirPath in dirs)
                        {
                            try
                            {
                                AddApplication(handler, dirPath, extra[1]);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }
                        }
                    }
                    else
                    {
                        AddApplication(handler, extra[0], extra[1]);
                    }
                }
                else if (extra.Count == 3)
                {
                    if (recursiveAdd)
                    {
                        Console.WriteLine("Cannot use -r while specifying virtual path.");
                    }
                    else
                    {
                        AddApplication(handler, extra[0], extra[1], extra[2]);
                    }
                }
                else
                {
                    Usage(opts);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#11
0
文件: mksite.cs 项目: thehexia/iismgr
        public static void Main(string[] args)
        {
            bool   help        = false;
            string appPoolName = "";
            int    port        = 80; // Default to 80.

            var opts = new OptionSet()
            {
                { "h|help", "show this message and exit", v => help = true },
                { "pool=", "name of an existing app pool", v => appPoolName = v },
                { "port=", "specific port number", v => int.TryParse(v, out port) },
            };

            // All arguments that are not options or optional arguments.
            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
            {
                string kind = "";
                if (extra.Count > 0)
                {
                    kind = extra[0];
                }

                IISHandler handler = new IISHandler();

                if (kind.Equals("add"))
                {
                    if (!(extra.Count > 2))
                    {
                        throw new ArgumentException("Invalid number of arguments.");
                    }

                    // handle adding sites.
                    if (!String.IsNullOrEmpty(appPoolName))
                    {
                        ApplicationPool pool = handler.AddApplicationPool(appPoolName);
                        AddSite(handler, pool, extra[1], extra[2], port);
                    }
                    else
                    {
                        AddSite(handler, extra[1], extra[2], port);
                    }
                }
                else if (kind.Equals("remove"))
                {
                    // Remove site.
                    if (!(extra.Count > 1))
                    {
                        throw new ArgumentException("Invalid number of arguments.");
                    }

                    RemoveSite(handler, extra[1]);
                }
                else if (kind.Equals("start"))
                {
                    if (!(extra.Count > 1))
                    {
                        throw new ArgumentException("Invalid number of arguments.");
                    }

                    StartSite(handler, extra[1]);
                }
                else if (kind.Equals("stop"))
                {
                    if (!(extra.Count > 1))
                    {
                        throw new ArgumentException("Invalid number of arguments.");
                    }

                    StopSite(handler, extra[1]);
                }
                else if (kind.Equals("setpool"))
                {
                    if (!(extra.Count > 2))
                    {
                        throw new ArgumentException("Invalid number of arguments.");
                    }
                    SetPool(handler, extra[1], extra[2]);
                }
                else
                {
                    throw new ArgumentException("Second argument " + kind + " not valid.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#12
0
文件: mksite.cs 项目: thehexia/iismgr
 private static void StopSite(IISHandler handler, string siteName)
 {
     handler.StopSite(siteName);
 }
示例#13
0
文件: mksite.cs 项目: thehexia/iismgr
 private static void RemoveSite(IISHandler handler, string siteName)
 {
     handler.RemoveSite(siteName);
 }
示例#14
0
文件: mksite.cs 项目: thehexia/iismgr
        private static void AddSite(IISHandler handler, string siteName, string filePath, int port = 80)
        {
            ApplicationPool appPool = handler.AddApplicationPool(siteName);

            AddSite(handler, appPool, siteName, filePath, port);
        }
示例#15
0
文件: mksite.cs 项目: thehexia/iismgr
 private static void AddSite(IISHandler handler, ApplicationPool appPool, string siteName, string filePath, int port = 80)
 {
     filePath = Path.GetFullPath(filePath);
     handler.AddSite(appPool, siteName, filePath, port);
 }
示例#16
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);
            }
        }