Example #1
0
        /// <summary>
        /// Updates the mapping state of a monitored system, if the mapping duration of this monitored system is out of date
        /// </summary>
        /// <param name="monitoredSystemID">MAC Adress of the monitored system to update</param>
        public void UpdateMappingState(string monitoredSystemMac)
        {
            try
            {
                using (var dataContext = DataContextFactory.CreateDataContext())
                {
                    var          monitoredSystem = PrecompiledQueries.GetMonitoredSystemByMAC(dataContext, monitoredSystemMac);
                    MappingState newState        = MappingState.Critical;

                    // Critical state
                    if (monitoredSystem.CriticalEnd != null)
                    {
                        if (monitoredSystem.CriticalEnd < DateTime.Now.Ticks)
                        {
                            newState = MappingState.Warning;
                        }
                    }
                    else
                    {
                        newState = MappingState.Warning;
                    }


                    // Warning state
                    if (monitoredSystem.WarningEnd != null)
                    {
                        if (monitoredSystem.WarningEnd < DateTime.Now.Ticks)
                        {
                            newState = MappingState.OK;
                        }
                    }
                    else
                    {
                        newState = MappingState.OK;
                    }


                    // Maintenance state
                    if (PrecompiledQueries.GetMonitoredSystemMaintenanceModeByID(dataContext, monitoredSystem.ID))
                    {
                        newState = MappingState.Maintenance;
                    }

                    monitoredSystem.Status = (byte)newState;
                    dataContext.SubmitChanges();
                }
            }
            catch (Exception e)
            {
                Logger.Instance.WriteEntry("ValueManager_UpdateMappingState: Can't update the mapping of workstation (MAC: " + monitoredSystemMac + "). " + e.StackTrace, LogType.Exception);
            }
        }