Example #1
0
        /// <summary>
        /// Determines she SLA times for the alarm model based on the active alarm passed in and the local time.
        /// </summary>
        private AlarmModel DetermineSlaValues(AlarmModel alarmModel, ActiveAlarm alarm, DateTime localTime)
        {
            //set the defaults
            alarmModel.ServiceDesignation                 = "N/A";
            alarmModel.ServiceDesignationId               = -1;
            alarmModel.TimeRemainingTillTargetTime        = 0;
            alarmModel.TimeRemainingTillTargetTimeDisplay = "0";

            SetTSDS(alarm.CustomerID);
            if (alarm.SLADue.HasValue)
            {
                //set the time remaining until the sla is due - have to set this against the local customer time
                var diffTime = (alarm.SLADue.Value - localTime);
                alarmModel.TimeRemainingTillTargetTime = diffTime.TotalHours;
                if (diffTime.TotalHours > 0)
                {
                    alarmModel.TimeRemainingTillTargetTimeDisplay = FormatHelper.FormatTimeFromMinutes(diffTime.TotalMinutes);
                }
                //calculate the target  service designnation here as well
                var masterId = GetTsdMasterId(diffTime.TotalHours);
                //now determine the correct TSD Master
                var tds = Tsds.FirstOrDefault(x => x.MasterId == masterId);
                if (tds != null)
                {
                    alarmModel.ServiceDesignation   = tds.Description;
                    alarmModel.ServiceDesignationId = tds.Id;
                }
            }
            return(alarmModel);
        }
Example #2
0
 /// <summary>
 /// Updates the alarm model to include the correct time  types for this active alarm.
 /// </summary>
 private void AddTimeTypes(ActiveAlarm alarm, AlarmModel alarmModel)
 {
     alarmModel.TimeTypes = new List <TimeType>();
     if (alarm.TimeType1 != null)
     {
         var tt = PemsEntities.TimeTypes.FirstOrDefault(x => x.TimeTypeId == alarm.TimeType1);
         if (tt != null)
         {
             alarmModel.TimeTypes.Add(new TimeType {
                 Description = tt.TimeTypeDesc, Id = tt.TimeTypeId
             });
         }
     }
     if (alarm.TimeType2 != null)
     {
         var tt = PemsEntities.TimeTypes.FirstOrDefault(x => x.TimeTypeId == alarm.TimeType2);
         if (tt != null)
         {
             alarmModel.TimeTypes.Add(new TimeType {
                 Description = tt.TimeTypeDesc, Id = tt.TimeTypeId
             });
         }
     }
     if (alarm.TimeType3 != null)
     {
         var tt = PemsEntities.TimeTypes.FirstOrDefault(x => x.TimeTypeId == alarm.TimeType3);
         if (tt != null)
         {
             alarmModel.TimeTypes.Add(new TimeType {
                 Description = tt.TimeTypeDesc, Id = tt.TimeTypeId
             });
         }
     }
     if (alarm.TimeType4 != null)
     {
         var tt = PemsEntities.TimeTypes.FirstOrDefault(x => x.TimeTypeId == alarm.TimeType4);
         if (tt != null)
         {
             alarmModel.TimeTypes.Add(new TimeType {
                 Description = tt.TimeTypeDesc, Id = tt.TimeTypeId
             });
         }
     }
     if (alarm.TimeType5 != null)
     {
         var tt = PemsEntities.TimeTypes.FirstOrDefault(x => x.TimeTypeId == alarm.TimeType5);
         if (tt != null)
         {
             alarmModel.TimeTypes.Add(new TimeType {
                 Description = tt.TimeTypeDesc, Id = tt.TimeTypeId
             });
         }
     }
 }
Example #3
0
        /// <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);
        }