public void GetApplicationPoolDetail(ApplicationPoolCollection applicationPoolCollection, string applicationPoolName)
        {
            ApplicationPoolProcessModel applicationPoolProcessModel = null;
            ApplicationPool             applicationPool             = null;

            if ((applicationPoolCollection != null) && (applicationPoolCollection.Any()))
            {
                _logger.InfoFormat("[{0}] - applicationPoolName: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolName);

                applicationPool = applicationPoolCollection.FirstOrDefault(p => p.Name == applicationPoolName);
                if (applicationPool != null)
                {
                    _logger.InfoFormat("[{0}] - applicationPool.Name: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.Name);
                    _logger.InfoFormat("[{0}] - applicationPool.AutoStart: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.AutoStart);
                    _logger.InfoFormat("[{0}] - applicationPool.Enable32BitAppOnWin64: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.Enable32BitAppOnWin64);
                    _logger.InfoFormat("[{0}] - applicationPool.ManagedRuntimeVersion: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.ManagedRuntimeVersion);
                    _logger.InfoFormat("[{0}] - applicationPool.State: {1}", MethodInfo.GetCurrentMethod().Name, (int)applicationPool.State);
                    _logger.InfoFormat("[{0}] - applicationPool.State[string]: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.State);

                    applicationPoolProcessModel = applicationPool.ProcessModel;
                    _logger.InfoFormat("[{0}] - applicationPoolProcessModel.IdentityType: {1}", MethodInfo.GetCurrentMethod().Name, (int)applicationPoolProcessModel.IdentityType);
                    _logger.InfoFormat("[{0}] - applicationPoolProcessModel.IdentityType[string]: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolProcessModel.IdentityType);
                    _logger.InfoFormat("[{0}] - applicationPoolProcessModel.UserName: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolProcessModel.UserName);
                    _logger.InfoFormat("[{0}] - applicationPoolProcessModel.Password: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolProcessModel.Password);
                }
                else
                {
                    _logger.InfoFormat("[{0}] - ApplicationPool doesn't exists", MethodInfo.GetCurrentMethod().Name);
                }
            }
            else
            {
                _logger.InfoFormat("[{0}] - Server doesn't have any ApplicationPool", MethodInfo.GetCurrentMethod().Name);
            }
        }
Example #2
0
        public void CreateApplicationSite(string applicationSiteFile)
        {
            applicationSiteFilePath = applicationSiteFile;
            ApplicationSiteModel applicationSite = ApplicationSiteParseConfig(applicationSiteFilePath);

            if (applicationSite != null)
            {
                try {
                    string applicationName = applicationSite.ApplicationName;

                    ServerManager             serverManager             = new ServerManager();
                    SiteCollection            siteCollection            = serverManager.Sites;
                    ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
                    Site            site            = null;
                    ApplicationPool applicationPool = null;

                    _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
                    _logger.InfoFormat("[{0}] - applicationName: {1}", MethodInfo.GetCurrentMethod().Name, applicationName);

                    if ((siteCollection != null) && (siteCollection.Any()))
                    {
                        site = siteCollection.FirstOrDefault(p => p.Name == applicationName);

                        if ((applicationPoolCollection != null) && (applicationPoolCollection.Any()))
                        {
                            applicationPool = applicationPoolCollection.FirstOrDefault(p => p.Name == applicationName);
                        }

                        if ((site != null) || (applicationPool != null))
                        {
                            _logger.InfoFormat("[{0}] - ApplicationSite already exists: {1} please use different name", MethodInfo.GetCurrentMethod().Name, applicationName);

                            return;
                        }
                    }

                    if ((!Directory.Exists(applicationSite.PhysicalPath.Source)) && (!File.Exists(applicationSite.PhysicalPath.SourcePackage)) && (!Directory.Exists(applicationSite.PhysicalPath.Destination)))
                    {
                        _logger.InfoFormat("[{0}] - ApplicationSite PhysicalPath doesn't exists, can't create ApplicationSite", MethodInfo.GetCurrentMethod().Name);
                        _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);

                        return;
                    }
                    else if (Directory.Exists(applicationSite.PhysicalPath.Destination))
                    {
                        _logger.InfoFormat("[{0}] - ApplicationSite PhysicalPath Destination already exists, can't create ApplicationSite", MethodInfo.GetCurrentMethod().Name);
                        _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);

                        return;
                    }
                    else if ((Directory.Exists(applicationSite.PhysicalPath.Source)) && (!Directory.Exists(applicationSite.PhysicalPath.Destination)))
                    {
                        try {
                            Directory.CreateDirectory(applicationSite.PhysicalPath.Destination);

                            if (Directory.Exists(applicationSite.PhysicalPath.Destination))
                            {
                                CopyApplicationSite(applicationSite.PhysicalPath.Source, applicationSite.PhysicalPath.Destination);
                            }
                            else
                            {
                                _logger.InfoFormat("[{0}] - Failed to create directory {1}, can't create ApplicationSite", MethodInfo.GetCurrentMethod().Name, applicationSite.PhysicalPath.Destination);
                                _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
                            }
                        } catch (Exception ex) {
                            _logger.Error(string.Format("[{0}] - Problem on create Directory: {1}. Message: {2}", MethodInfo.GetCurrentMethod().Name, applicationSite.PhysicalPath.Destination, ex.Message), ex);
                            _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
                        }
                    }
                    else if ((File.Exists(applicationSite.PhysicalPath.SourcePackage)) && (!Directory.Exists(applicationSite.PhysicalPath.Destination)))
                    {
                        try {
                            ZipFile.ExtractToDirectory(applicationSite.PhysicalPath.SourcePackage, applicationSite.PhysicalPath.Destination);

                            if (Directory.Exists(applicationSite.PhysicalPath.Destination))
                            {
                                _logger.InfoFormat("[{0}] - Package extracted into {1}, continue to configure ApplicationSite", MethodInfo.GetCurrentMethod().Name, applicationSite.PhysicalPath.Destination);

                                ConfigureApplicationSite(applicationSite);
                            }
                            else
                            {
                                _logger.InfoFormat("[{0}] - Failed to extract package into {1}, can't create ApplicationSite", MethodInfo.GetCurrentMethod().Name, applicationSite.PhysicalPath.Destination);
                                _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
                            }
                        } catch (Exception ex) {
                            _logger.Error(string.Format("[{0}] - Problem on extract package: {1} to destination: {2}. Message: {3}", MethodInfo.GetCurrentMethod().Name, applicationSite.PhysicalPath.SourcePackage,
                                                        applicationSite.PhysicalPath.Destination, ex.Message), ex);
                            _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
                        }
                    }
                } catch (Exception ex) {
                    _logger.Error(string.Format("[{0}] - Message: {1}", MethodInfo.GetCurrentMethod().Name, ex.Message), ex);
                }
            }
            else
            {
                _logger.InfoFormat("[{0}] - ApplicationSite file config not found, can't create ApplicationSite", MethodInfo.GetCurrentMethod().Name);
            }
        }
Example #3
0
        public bool CheckSpecificApplicationPool(ApplicationPoolCollection applicationPoolCollection, string applicationPoolName)
        {
            bool            changes         = false;
            ApplicationPool applicationPool = null;

            if ((applicationPoolCollection != null) && (applicationPoolCollection.Any()))
            {
                _logger.InfoFormat("[{0}] - applicationPoolName: {1}", MethodInfo.GetCurrentMethod().Name, applicationPoolName);

                applicationPool = applicationPoolCollection.FirstOrDefault(p => p.Name == applicationPoolName);
                if (applicationPool != null)
                {
                    ObjectState objectState = applicationPool.State;

                    _logger.InfoFormat("[{0}] - applicationPool.Name: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.Name);
                    _logger.InfoFormat("[{0}] - applicationPool.AutoStart: {1}", MethodInfo.GetCurrentMethod().Name, applicationPool.AutoStart);
                    _logger.InfoFormat("[{0}] - applicationPool.State: {1}", MethodInfo.GetCurrentMethod().Name, (int)objectState);
                    _logger.InfoFormat("[{0}] - applicationPool.State[string]: {1}", MethodInfo.GetCurrentMethod().Name, objectState);

                    if (objectState != ObjectState.Started)
                    {
                        bool retry = true;
                        int  ctr   = 0;

                        while (retry)
                        {
                            try {
                                _logger.InfoFormat("[{0}] - ApplicationSite is started but ApplicationPool is not started, try to start ApplicationPool", MethodInfo.GetCurrentMethod().Name);

                                ObjectState returnState = applicationPool.Start();

                                _logger.InfoFormat("[{0}] - returnState: {1}", MethodInfo.GetCurrentMethod().Name, (int)returnState);
                                _logger.InfoFormat("[{0}] - returnState[string]: {1}", MethodInfo.GetCurrentMethod().Name, returnState);

                                if (returnState == ObjectState.Started)
                                {
                                    _logger.InfoFormat("[{0}] - ApplicationPool is started", MethodInfo.GetCurrentMethod().Name);

                                    applicationPool.AutoStart = true;
                                    changes = true;

                                    retry = false;
                                }
                                else
                                {
                                    _logger.InfoFormat("[{0}] - ApplicationPool failed to start", MethodInfo.GetCurrentMethod().Name);

                                    retry = true;
                                }
                            } catch (Exception ex) {
                                retry = true;

                                _logger.Error(string.Format("[{0}] - Problem on start ApplicationPool. Message: {1}, retry {2} time(s)", MethodInfo.GetCurrentMethod().Name, ex.Message, ctr), ex);
                            }

                            _logger.InfoFormat("[{0}] - retry status: {1}", MethodInfo.GetCurrentMethod().Name, retry);

                            if (ctr > 10)
                            {
                                retry = false;
                            }

                            ctr++;

                            if (retry)
                            {
                                Thread.Sleep(THREAD_SLEEP);
                            }
                        }
                    }
                }
                else
                {
                    _logger.InfoFormat("[{0}] - ApplicationPool doesn't exists", MethodInfo.GetCurrentMethod().Name);
                }
            }
            else
            {
                _logger.InfoFormat("[{0}] - Server doesn't have any ApplicationPool", MethodInfo.GetCurrentMethod().Name);
            }

            return(changes);
        }