private void Initialize(object state) { List <NetObjectDowntime> netObjectDowntimeList1 = new List <NetObjectDowntime>(); try { using (IInformationServiceProxy2 iinformationServiceProxy2 = this._swisServiceProxyCreator.Create()) { DateTime utcNow = DateTime.UtcNow; foreach (DataRow row in (InternalDataCollectionBase)((IInformationServiceProxy)iinformationServiceProxy2).Query("SELECT Uri, Status, InstanceType, AncestorDetailsUrls\n FROM System.ManagedEntity\n WHERE UnManaged = false").Rows) { try { if (this.IsValid(row)) { List <NetObjectDowntime> netObjectDowntimeList2 = netObjectDowntimeList1; NetObjectDowntime netObjectDowntime = new NetObjectDowntime(); netObjectDowntime.set_DateTimeFrom(utcNow); netObjectDowntime.set_EntityID(this._swisUriParser.GetEntityId(row["Uri"].ToString())); netObjectDowntime.set_NodeID(this.ExtractStatusID((object)this.GetNodeIDFromUrl((string[])row["AncestorDetailsUrls"]))); netObjectDowntime.set_EntityType(row["InstanceType"].ToString()); netObjectDowntime.set_StatusID((int)row["Status"]); netObjectDowntimeList2.Add(netObjectDowntime); } } catch (Exception ex) { DowntimeMonitoringNotificationSubscriber.log.Error((object)string.Format("Unable to create NetObjectDowntime instance from ManagedEntity with Uri '{0}', {1}", row["Uri"], (object)ex)); } } } } catch (Exception ex) { DowntimeMonitoringNotificationSubscriber.log.ErrorFormat("Exception while initializing NetObjectDowntime table with ManagedEntities. {0}", (object)ex); } this._netObjectDowntimeDal.Insert((IEnumerable <NetObjectDowntime>)netObjectDowntimeList1); Scheduler.get_Instance().Remove("NetObjectDowntimeInitializator"); }
public Task OnNotificationAsync(Notification notification) { Stopwatch stopwatch = new Stopwatch(); try { stopwatch.Start(); if (notification.get_SourceInstanceProperties() == null) { throw new ArgumentNullException("sourceInstanceProperties"); } if (DowntimeMonitoringNotificationSubscriber.log.get_IsDebugEnabled()) { DowntimeMonitoringNotificationSubscriber.log.Debug((object)this.DetailInfo(notification.get_SubscriptionId(), notification.get_IndicationType(), notification.get_IndicationProperties(), notification.get_SourceInstanceProperties())); } object obj1 = (object)null; notification.get_SourceInstanceProperties().TryGetValue("InstanceType", out obj1); if (obj1 == null) { notification.get_SourceInstanceProperties().TryGetValue("SourceInstanceType", out obj1); } if (!(obj1 is string instanceType)) { DowntimeMonitoringNotificationSubscriber.log.Error((object)"Wrong PropertyBag data. InstanceType or SourceInstanceType are null"); return(Task.CompletedTask); } string columnForSwisEntity = this.GetNetObjectIdColumnForSwisEntity(instanceType); if (columnForSwisEntity == null) { DowntimeMonitoringNotificationSubscriber.log.DebugFormat("Not a supported instance type: {0}", (object)instanceType); return(Task.CompletedTask); } object obj2; if (!notification.get_SourceInstanceProperties().TryGetValue(columnForSwisEntity, out obj2)) { DowntimeMonitoringNotificationSubscriber.log.DebugFormat("Unable to get Entity ID. InstanceType : {0}, ID Field: {1}", (object)instanceType, (object)columnForSwisEntity); return(Task.CompletedTask); } if (notification.get_IndicationType() == IndicationHelper.GetIndicationType((IndicationType)2) || notification.get_IndicationType() == IndicationHelper.GetIndicationType((IndicationType)0)) { object statusObject1; notification.get_SourceInstanceProperties().TryGetValue("Status", out statusObject1); if (statusObject1 == null) { DowntimeMonitoringNotificationSubscriber.log.DebugFormat("No Status reported for InstanceType : {0}", (object)instanceType); return(Task.CompletedTask); } if (this._nodeNetObjectIdColumn == null) { this._nodeNetObjectIdColumn = this.GetNetObjectIdColumnForSwisEntity("Orion.Nodes"); } object statusObject2; notification.get_SourceInstanceProperties().TryGetValue(this._nodeNetObjectIdColumn, out statusObject2); if (statusObject2 == null) { DowntimeMonitoringNotificationSubscriber.log.DebugFormat("SourceBag must include NodeId. InstanceType : {0}", (object)instanceType); return(Task.CompletedTask); } INetObjectDowntimeDAL objectDowntimeDal = this._netObjectDowntimeDal; NetObjectDowntime netObjectDowntime = new NetObjectDowntime(); netObjectDowntime.set_EntityID(obj2.ToString()); netObjectDowntime.set_NodeID(this.ExtractStatusID(statusObject2)); netObjectDowntime.set_EntityType(instanceType); netObjectDowntime.set_DateTimeFrom((DateTime)notification.get_IndicationProperties()[(string)IndicationConstants.IndicationTime]); netObjectDowntime.set_StatusID(this.ExtractStatusID(statusObject1)); objectDowntimeDal.Insert(netObjectDowntime); } else if (notification.get_IndicationType() == IndicationHelper.GetIndicationType((IndicationType)1)) { this._netObjectDowntimeDal.DeleteDowntimeObjects(obj2.ToString(), instanceType); } } catch (Exception ex) { DowntimeMonitoringNotificationSubscriber.log.Error((object)string.Format("Exception occured when processing incoming indication of type \"{0}\"", (object)notification.get_IndicationType()), ex); } finally { stopwatch.Stop(); DowntimeMonitoringNotificationSubscriber.log.DebugFormat("Downtime notification has been processed in {0} miliseconds.", (object)stopwatch.ElapsedMilliseconds); } return(Task.CompletedTask); }