コード例 #1
0
ファイル: AlarmFactory.cs プロジェクト: rbgx/gtc-pems-duncan
        /// <summary>
        /// Gets details of a historic alarm
        /// </summary>
        private AlarmModel GetHistoricalAlarmDetails(int customerID, HistoricalAlarm alarm)
        {
            var alarmModel = new AlarmModel();

            if (alarm != null)
            {
                //Get the meter map for this alarm
                var metermap =
                    PemsEntities.MeterMaps.FirstOrDefault(x => x.Areaid == alarm.AreaID && x.Customerid == alarm.CustomerID && x.MeterId == alarm.MeterId);
                var alarmEventCode = PemsEntities.EventCodes.FirstOrDefault(x => x.EventCode1 == alarm.EventCode && x.CustomerID == customerID);
                //Asset / Location Information
                alarmModel.Latitude     = alarm.Meter == null ? 0 : alarm.Meter.Latitude ?? 0;
                alarmModel.Longitude    = alarm.Meter == null ? 0 : alarm.Meter.Longitude ?? 0;
                alarmModel.MeterGroupId = alarm.Meter == null ? 0 : alarm.Meter.MeterGroup ?? 0;
                alarmModel.AssetClass   = alarm.Meter == null ? AssetClass.Unknown : AssetFactory.GetAssetClass(alarm.Meter.MeterGroup);
                alarmModel.AssetType    = alarm.Meter == null ? string.Empty : (new AssetFactory(ConnectionStringName)).GetAssetTypeDescription(alarm.Meter.MeterGroup, customerID);

                OperationalStatu opStatus = null;
                //name ans state are based on class
                if (alarmModel.AssetClass == AssetClass.Sensor)
                {
                    alarmModel.AssetName         = PemsEntities.Sensors.FirstOrDefault(x => x.SensorID == metermap.SensorID) == null ? "" : PemsEntities.Sensors.FirstOrDefault(x => x.SensorID == metermap.SensorID).SensorName;
                    opStatus                     = PemsEntities.OperationalStatus.FirstOrDefault(x => x.OperationalStatusId == metermap.Sensor.OperationalStatus);
                    alarmModel.OperationalStatus = opStatus == null ? "" : opStatus.OperationalStatusDesc ?? "";
                }
                else if (alarmModel.AssetClass == AssetClass.Gateway)
                {
                    alarmModel.AssetName         = PemsEntities.Gateways.FirstOrDefault(x => x.GateWayID == metermap.GatewayID) == null ? "" : PemsEntities.Gateways.FirstOrDefault(x => x.GateWayID == metermap.GatewayID).Description;
                    opStatus                     = PemsEntities.OperationalStatus.FirstOrDefault(x => x.OperationalStatusId == metermap.Gateway.OperationalStatus);
                    alarmModel.OperationalStatus = opStatus == null ? "" : opStatus.OperationalStatusDesc ?? "";
                }
                //everything else falls under meter for now
                else
                {
                    alarmModel.AssetName         = alarm.Meter == null ? "" : alarm.Meter.MeterName;
                    opStatus                     = PemsEntities.OperationalStatus.FirstOrDefault(x => x.OperationalStatusId == metermap.Meter.OperationalStatusID);
                    alarmModel.OperationalStatus = opStatus == null ? "" : opStatus.OperationalStatusDesc ?? "";
                }
                alarmModel.AssetID      = alarm.Meter.MeterId;
                alarmModel.Area         = PemsEntities.Areas.FirstOrDefault(x => x.CustomerID == metermap.Customerid && x.AreaID == metermap.AreaId2) == null ? "" : PemsEntities.Areas.FirstOrDefault(x => x.AreaID == metermap.AreaId2 && x.CustomerID == metermap.Customerid).AreaName; //alarm.Meter.Area.AreaName;
                alarmModel.AreaId       = metermap.AreaId2;                                                                                                                                                                                                                                // alarm.Meter.Area.AreaID;
                alarmModel.Zone         = metermap.Zone == null ? string.Empty : PemsEntities.Zones.FirstOrDefault(x => x.ZoneId == metermap.ZoneId && metermap.Customerid == x.customerID) == null ? string.Empty : PemsEntities.Zones.FirstOrDefault(x => x.ZoneId == metermap.ZoneId && metermap.Customerid == x.customerID).ZoneName;
                alarmModel.Suburb       = metermap == null ? string.Empty : metermap.CustomGroup11 == null ? string.Empty : metermap.CustomGroup11.DisplayName;
                alarmModel.Street       = alarm.Meter.Location;
                alarmModel.BaysAffected = alarm.Meter.MaxBaysEnabled ?? 0;

                //Alarm / Meter information
                alarmModel.AlarmID                = alarm.AlarmUID ?? 0;
                alarmModel.AlarmCode              = alarmEventCode == null ? 0 : alarmEventCode.EventCode1;
                alarmModel.AlarmDesription        = alarmEventCode == null ? string.Empty : alarmEventCode.EventDescAbbrev;
                alarmModel.AlarmDesriptionVerbose = alarmEventCode == null ? string.Empty : alarmEventCode.EventDescVerbose;
                alarmModel.ServiceTargetTime      = alarm.SLADue ?? DateTime.MinValue;
                alarmModel.AlarmStatus            = "Closed";
                var alarmStatus = PemsEntities.AlarmStatus.FirstOrDefault(x => x.AlarmStatusId == 3);
                if (alarmStatus != null)
                {
                    alarmModel.AlarmStatus = alarmStatus.AlarmStatusDesc;
                }
                alarmModel.TimeNotified = alarm.TimeOfNotification;
                alarmModel.TimeCleared  = alarm.TimeOfClearance ?? DateTime.MinValue;

                //SLA Values
                //calculation for historical alarm time remaining: Service Target time - Time Cleared. NOTE, this is different for active alarms. using time cleared instead of current local time
                //set the defaults
                alarmModel.TimeRemainingTillTargetTime        = 0;
                alarmModel.TimeRemainingTillTargetTimeDisplay = Constants.TimeFormats.timeFormatToDisplay_HHH_MM;

                if (alarm.SLADue.HasValue)
                {
                    if (!String.IsNullOrEmpty(alarm.SLADue.Value.ToString()))
                    {
                        TimeSpan diffTime = (alarm.SLADue.Value - alarm.TimeOfClearance.Value);
                        if (diffTime.TotalHours > 0)
                        {
                            alarmModel.TimeRemainingTillTargetTimeDisplay = FormatHelper.FormatTimeFromMinutes(Math.Round(diffTime.TotalMinutes, 0), (int)PEMSEnums.PEMSEnumsTimeFormats.timeFormat_HHH_MM);
                        }
                    }
                }
                else
                {
                    alarmModel.TimeRemainingTillTargetTimeDisplay = FormatHelper.FormatTimeFromMinutes(0, (int)PEMSEnums.PEMSEnumsTimeFormats.timeFormat_HHH_MM);
                }

                //Target Service Designation - note, we are NOT regenerating this, just using what is assigned to the
                alarmModel.ServiceDesignation   = "N/A";
                alarmModel.ServiceDesignationId = -1;
                if (alarm.TargetServiceDesignation1 != null)
                {
                    alarmModel.ServiceDesignation   = alarm.TargetServiceDesignation1.TargetServiceDesignationDesc;
                    alarmModel.ServiceDesignationId = alarm.TargetServiceDesignation1.TargetServiceDesignationId;
                }

                alarmModel.TimeOccured = alarm.TimeOfOccurrance;
                AddTimeTypes(alarm, alarmModel);
                alarmModel.TimeType1     = alarm.TimeType1 ?? 0;
                alarmModel.TimeType2     = alarm.TimeType2 ?? 0;
                alarmModel.TimeType3     = alarm.TimeType3 ?? 0;
                alarmModel.TimeType4     = alarm.TimeType4 ?? 0;
                alarmModel.TimeType5     = alarm.TimeType5 ?? 0;
                alarmModel.AlarmSource   = PemsEntities.EventSources.FirstOrDefault(x => x.EventSourceCode == alarm.EventSource).EventSourceDesc;
                alarmModel.AlarmSeverity = alarmEventCode == null ? string.Empty : alarmEventCode.AlarmTier1 == null ? string.Empty : alarmEventCode.AlarmTier1.TierDesc;
                alarmModel.EntryNotes    = alarm.Notes;
                alarmModel.CustomerId    = customerID;
                //Closure Information
                var maintenanceEvent = PemsEntities.SFMeterMaintenanceEvents.FirstOrDefault(
                    x => x.AreaId == alarm.Meter.AreaID && x.CustomerId == customerID && x.MeterId == alarm.MeterId && x.WorkOrderID == alarm.WorkOrderId);
                alarmModel.ResolutionCode     = maintenanceEvent == null ? 1 : maintenanceEvent.MaintenanceCode;
                alarmModel.ResolutionCodeDesc = maintenanceEvent == null
                                                    ? ""
                                                    : PemsEntities.MaintenanceCodes.FirstOrDefault(x => x.MaintenanceCode1 == maintenanceEvent.MaintenanceCode) == null
                                                          ? ""
                                                          : PemsEntities.MaintenanceCodes.FirstOrDefault(x => x.MaintenanceCode1 == maintenanceEvent.MaintenanceCode).Description;

                //RJH: Set ClosureNotification = TimeCleared if no maintenance event.
                alarmModel.ClosureNotification = maintenanceEvent == null ? alarmModel.TimeCleared : maintenanceEvent.EventDateTime;

                alarmModel.TechnicianID = maintenanceEvent == null ? -1 : maintenanceEvent.TechnicianId;
                if (alarmModel.TechnicianID > 0)
                {
                    alarmModel.TechnicianName =
                        PemsEntities.TechnicianDetails.FirstOrDefault(x => x.TechnicianId == alarmModel.TechnicianID) ==
                        null
                            ? ""
                            : PemsEntities.TechnicianDetails.FirstOrDefault(
                            x => x.TechnicianId == alarmModel.TechnicianID).Name;
                }
                alarmModel.ClosureNotes = alarm.ClosureNote;
                alarmModel.ClosedBy     = alarm.ClearedByUserId ?? 0;
                if (alarm.ClearedByUserId != null)
                {
                    var user = (new UserFactory()).GetUserById(alarm.ClearedByUserId.Value);
                    if (user != null)
                    {
                        alarmModel.ClosedByName = user.Username;
                    }
                }
                alarmModel.IsClosed = true;
            }

            alarmModel.ResolutionCodes = GetResolutionCodes();
            alarmModel.TechnicianIDs   = GetAlarmTechnicians();

            return(alarmModel);
        }
コード例 #2
0
ファイル: AlarmFactory.cs プロジェクト: rbgx/gtc-pems-duncan
        /// <summary>
        /// Gets an active alarm based on the parameters passed in
        /// </summary>
        private AlarmModel GetActiveAlarmDetails(int customerID, ActiveAlarm alarm, DateTime localTime)
        {
            var alarmModel = new AlarmModel();

            if (alarm != null)
            {
                //Get the meter map for this alarm
                MeterMap metermap =
                    PemsEntities.MeterMaps.FirstOrDefault(
                        x =>
                        x.Areaid == alarm.AreaID && x.Customerid == alarm.CustomerID &&
                        x.MeterId == alarm.MeterId);

                //Asset / Location Information
                alarmModel.EventSource  = alarm.EventSource;
                alarmModel.Latitude     = alarm.Meter == null ? 0 : alarm.Meter.Latitude ?? 0;
                alarmModel.Longitude    = alarm.Meter == null ? 0 : alarm.Meter.Longitude ?? 0;
                alarmModel.MeterGroupId = alarm.Meter == null ? 0 : alarm.Meter.MeterGroup ?? 0;
                alarmModel.AssetClass   = alarm.Meter == null ? AssetClass.Unknown : AssetFactory.GetAssetClass(alarm.Meter.MeterGroup);
                alarmModel.AssetType    = alarm.Meter == null ? string.Empty : (new AssetFactory(ConnectionStringName)).GetAssetTypeDescription(alarm.Meter.MeterGroup, customerID);
                alarmModel.CustomerId   = customerID;
                //name ans state are based on class
                OperationalStatu opStatus = null;

                if (alarmModel.AssetClass == AssetClass.Sensor)
                {
                    alarmModel.AssetName         = PemsEntities.Sensors.FirstOrDefault(x => x.SensorID == metermap.SensorID) == null? "": PemsEntities.Sensors.FirstOrDefault(x => x.SensorID == metermap.SensorID).SensorName;
                    opStatus                     = PemsEntities.OperationalStatus.FirstOrDefault(x => x.OperationalStatusId == metermap.Sensor.OperationalStatus);
                    alarmModel.OperationalStatus = opStatus == null ? "" : opStatus.OperationalStatusDesc ?? "";
                }
                else if (alarmModel.AssetClass == AssetClass.Gateway)
                {
                    alarmModel.AssetName         = PemsEntities.Gateways.FirstOrDefault(x => x.GateWayID == metermap.GatewayID) == null ? "" : PemsEntities.Gateways.FirstOrDefault(x => x.GateWayID == metermap.GatewayID).Description;
                    opStatus                     = PemsEntities.OperationalStatus.FirstOrDefault(x => x.OperationalStatusId == metermap.Gateway.OperationalStatus);
                    alarmModel.OperationalStatus = opStatus == null ? "" : opStatus.OperationalStatusDesc ?? "";
                }
                //everything else falls under meter for now
                else
                {
                    alarmModel.AssetName         = alarm.Meter == null ? "" : alarm.Meter.MeterName;
                    opStatus                     = PemsEntities.OperationalStatus.FirstOrDefault(x => x.OperationalStatusId == metermap.Meter.OperationalStatusID);
                    alarmModel.OperationalStatus = opStatus == null ? "" : opStatus.OperationalStatusDesc ?? "";
                }
                alarmModel.AssetID      = alarm.Meter.MeterId;
                alarmModel.Area         = PemsEntities.Areas.FirstOrDefault(x => x.CustomerID == metermap.Customerid && x.AreaID == metermap.AreaId2) == null ? "" : PemsEntities.Areas.FirstOrDefault(x => x.CustomerID == metermap.Customerid && x.AreaID == metermap.AreaId2).AreaName;
                alarmModel.AreaId       = metermap.AreaId2; //alarm.Meter.Area.AreaID;
                alarmModel.Zone         = metermap.Zone == null ? string.Empty : PemsEntities.Zones.FirstOrDefault(x => x.ZoneId == metermap.ZoneId && metermap.Customerid == x.customerID) == null ? string.Empty : PemsEntities.Zones.FirstOrDefault(x => x.ZoneId == metermap.ZoneId && metermap.Customerid == x.customerID).ZoneName;
                alarmModel.Suburb       = metermap == null? string.Empty: metermap.CustomGroup11 == null ? string.Empty : metermap.CustomGroup11.DisplayName;
                alarmModel.Street       = alarm.Meter.Location;
                alarmModel.BaysAffected = alarm.Meter.MaxBaysEnabled ?? 0;

                //Alarm / Meter information
                alarmModel.AlarmID                = alarm.AlarmUID ?? 0;
                alarmModel.AlarmCode              = alarm.EventCode1.EventCode1;
                alarmModel.AlarmDesription        = alarm.EventCode1.EventDescAbbrev;
                alarmModel.AlarmDesriptionVerbose = alarm.EventCode1.EventDescVerbose;
                alarmModel.ServiceTargetTime      = alarm.SLADue ?? DateTime.MinValue;
                alarmModel.AlarmStatus            = "Open";
                var alarmStatus = PemsEntities.AlarmStatus.FirstOrDefault(x => x.AlarmStatusId == 2);
                if (alarmStatus != null)
                {
                    alarmModel.AlarmStatus = alarmStatus.AlarmStatusDesc;
                }
                alarmModel.TimeNotified = alarm.TimeOfNotification;
                alarmModel             = DetermineSlaValues(alarmModel, alarm, localTime);
                alarmModel.TimeOccured = alarm.TimeOfOccurrance;
                //Time Types here

                AddTimeTypes(alarm, alarmModel);
                alarmModel.TimeType1     = alarm.TimeType1 ?? 0;
                alarmModel.TimeType2     = alarm.TimeType2 ?? 0;
                alarmModel.TimeType3     = alarm.TimeType3 ?? 0;
                alarmModel.TimeType4     = alarm.TimeType4 ?? 0;
                alarmModel.TimeType5     = alarm.TimeType5 ?? 0;
                alarmModel.AlarmSource   = PemsEntities.EventSources.FirstOrDefault(x => x.EventSourceCode == alarm.EventSource).EventSourceDesc;
                alarmModel.AlarmSeverity = alarm.EventCode1.AlarmTier1 == null ? string.Empty : alarm.EventCode1.AlarmTier1.TierDesc;
                alarmModel.EntryNotes    = alarm.Notes;
                alarmModel.IsClosed      = false;
                alarmModel.CustomerId    = customerID;
                //Closure Information -  this alarm hasnt been closed, so most of them are not needed
                //closed by is current user
                alarmModel.ClosedBy     = WebSecurity.CurrentUserId;
                alarmModel.ClosedByName = WebSecurity.CurrentUserName;
            }

            alarmModel.ResolutionCodes = GetResolutionCodes();
            alarmModel.TechnicianIDs   = GetAlarmTechnicians();
            return(alarmModel);
        }