コード例 #1
0
        public void SetState(int assignmentId, EnumState state, EnumStateActionTaken action, string userName)
        {
            var itemState = new LeadAssignmentState
            {
                LeadAssignmentId = assignmentId,
                StateId          = state.ToString(),
                Actor            = userName,
                Action           = action.ToString(),
                ActionTimestamp  = DateHelper.Now
            };

            _context.LeadAssignmentStates.Add(itemState);
        }
コード例 #2
0
        public void SetState(Guid leadId, EnumState state, EnumStateActionTaken action, string userName)
        {
            var leadState = new LeadState()
            {
                LeadId          = leadId,
                StateId         = state.ToString(),
                Actor           = userName,
                Action          = action.ToString(),
                ActionTimestamp = DateHelper.Now
            };

            _context.LeadStates.Add(leadState);
        }
コード例 #3
0
        public void CheckApplicationSiteOldMethod()
        {
            string         path    = string.Format("IIS://{0}/W3SVC", SERVER_NAME);
            DirectoryEntry appSite = new DirectoryEntry(path);

            foreach (DirectoryEntry itemAppSite in appSite.Children)
            {
                _logger.InfoFormat("[{0}] - =======================================================================================", MethodInfo.GetCurrentMethod().Name);
                _logger.InfoFormat("[{0}] - itemAppSite: {1}", MethodInfo.GetCurrentMethod().Name, JsonConvert.SerializeObject(itemAppSite, Formatting.Indented));
                _logger.InfoFormat("[{0}] - itemAppSite.Name: {1}", MethodInfo.GetCurrentMethod().Name, itemAppSite.Name);

                string    serverComment   = null;
                string    appPoolName     = null;
                EnumState enumState       = EnumState.Unknown;
                EnumState enumServerState = enumState;

                if (itemAppSite.Properties.Contains("ServerComment"))
                {
                    serverComment = itemAppSite.InvokeGet("ServerComment").ToString();
                    appPoolName   = (serverComment == "Default Web Site") ? "DefaultAppPool" : serverComment;
                    _logger.InfoFormat("[{0}] - ServerComment: {1}", MethodInfo.GetCurrentMethod().Name, serverComment);
                }
                else
                {
                    _logger.InfoFormat("[{0}] - ServerComment property doesn't exists", MethodInfo.GetCurrentMethod().Name);
                }

                if (itemAppSite.Properties.Contains("ServerState"))
                {
                    int serverState = (int)itemAppSite.InvokeGet("ServerState");

                    bool enumParsed = Enum.TryParse(serverState.ToString(), true, out enumState);

                    if (enumParsed)
                    {
                        enumServerState = enumState;
                    }

                    _logger.InfoFormat("[{0}] - ServerState: {1}, enumServerState: {2}", MethodInfo.GetCurrentMethod().Name, serverState, enumServerState.ToString());

                    if (enumServerState == EnumState.Started)
                    {
                        try {
                            _logger.InfoFormat("[{0}] - ApplicationSite is running, need to check AppPoolState status", MethodInfo.GetCurrentMethod().Name);

                            CheckSpecificApplicationPool(appPoolName);
                        } catch (Exception ex) {
                            _logger.Error(string.Format("[{0}] - Problem on check AppPoolState status. serverComment: {1}, appPoolName: {2}, Message: {3}", MethodInfo.GetCurrentMethod().Name, serverComment,
                                                        appPoolName, ex.Message), ex);
                        }
                    }
                    else
                    {
                        _logger.InfoFormat("[{0}] - ApplicationSite is not running, no need to check AppPoolState status", MethodInfo.GetCurrentMethod().Name);
                    }
                }
                else
                {
                    _logger.InfoFormat("[{0}] - ServerState property doesn't exists", MethodInfo.GetCurrentMethod().Name);
                }

                _logger.InfoFormat("[{0}] - =======================================================================================", MethodInfo.GetCurrentMethod().Name);
            }
        }
コード例 #4
0
        public void CheckSpecificApplicationPool(string applicationName)
        {
            string         path    = string.Format("IIS://{0}/W3SVC/AppPools/{1}", SERVER_NAME, applicationName);
            DirectoryEntry appPool = new DirectoryEntry(path);

            _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
            _logger.InfoFormat("[{0}] - appPool: {1}", MethodInfo.GetCurrentMethod().Name, JsonConvert.SerializeObject(appPool, Formatting.Indented));
            _logger.InfoFormat("[{0}] - appPool.Name: {1}", MethodInfo.GetCurrentMethod().Name, appPool.Name);
            if (appPool.Properties.Contains("AppPoolState"))
            {
                int appPoolState = (int)appPool.InvokeGet("AppPoolState");

                EnumState enumState        = EnumState.Unknown;
                EnumState enumAppPoolState = enumState;

                bool enumParsed = Enum.TryParse(appPoolState.ToString(), true, out enumState);

                if (enumParsed)
                {
                    enumAppPoolState = enumState;
                }

                _logger.InfoFormat("[{0}] - appPoolState: {1}, enumAppPoolState: {2}", MethodInfo.GetCurrentMethod().Name, appPoolState, enumAppPoolState.ToString());

                if (enumAppPoolState != EnumState.Started)
                {
                    bool retry = true;
                    int  ctr   = 0;

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

                            appPool.Invoke("Start", null);

                            _logger.InfoFormat("[{0}] - AppPoolState is running", MethodInfo.GetCurrentMethod().Name);

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

                            _logger.Error(string.Format("[{0}] - Problem on invoke 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}] - AppPoolState is running", MethodInfo.GetCurrentMethod().Name);
                }
            }
            else
            {
                _logger.InfoFormat("[{0}] - AppPoolState property doesn't exists. Path: {1}", MethodInfo.GetCurrentMethod().Name, path);
            }
            _logger.InfoFormat("[{0}] - =============================================", MethodInfo.GetCurrentMethod().Name);
        }