public void OnNewDataItems(DataItemBase[] dataitems, bool logicallyGrouped, DataItemAcknowledgementCallback acknowledgeCallback, object acknowledgedState, DataItemProcessingCompleteCallback completionCallback, object completionState) { Log($"Entering {nameof(OnNewDataItems)}; Managed thread: {Thread.CurrentThread.ManagedThreadId}\r\n"); Log($"Received {(dataitems == null ? 0 : dataitems.Length)} inbound data items of {(dataitems == null && dataitems.Length >=1 ? "<unknown>" : dataitems[0].DataItemTypeName)} type.\r\n"); lock (shutdownLock) { // don't start if shutdown is in progress if (shutdown) { return; } Log($"No shutdown in progress.\r\n"); PropertyBagDataItem[] ReturningResults = null; try { // put the actual monitoring code here: ReturningResults = <get result code> Log($"Competed output data item.\r\n"); } catch (Exception e) { Log($"Error while getting output data: {e.Message}.\r\n"); } if (ReturningResults != null && ReturningResults.Length != 0) { // send data back to SCOM Agent, if any if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0]); } else { ModuleHost.PostOutputDataItems(ReturningResults, logicallyGrouped); } Log($"Output data item(s) posted.\r\n"); } // completed the current run, ask for next ModuleHost.RequestNextDataItem(); Log($"Next data item requested.\r\n"); } }
protected void PostOutputData(TOutputDataType[] ReturningResults, DataItemAcknowledgementCallback AcknowledgementCallback, bool LogicallyGrouped) { lock (shutdownLock) { if (shutdown) { return; } } try { if (ReturningResults != null || ReturningResults.Length > 0) { if (AcknowledgementCallback == null) { if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0]); } else { ModuleHost.PostOutputDataItems(ReturningResults, LogicallyGrouped); } } else { if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0], AcknowledgementCallback, null); } else { ModuleHost.PostOutputDataItems(ReturningResults, LogicallyGrouped, AcknowledgementCallback, null); } } } } catch (Exception e) { ModuleHost.NotifyError(ModuleErrorSeverity.DataLoss, e); } }
public void QueueCallback() { // this method can access shared static resource, because QueueManager ensures, that other queued actions called sequentially. try { bool NeedAcknowledge = (_acknowledgeCallback != null); lock (shutdownLock) { if (shutdown) { return; } TOutputDataType[] ReturningResults; try { ReturningResults = GetOutputData(); } catch (Exception e) { try { if (NeedAcknowledge) { _acknowledgeCallback(_acknowledgedState); _completionCallback(_completionState); } } catch (Exception ae) { Global.logWriteException("Failed to acknowledge action completion.", ae, this); } ModuleHost.RequestNextDataItem(); throw new ModuleException(e.Message, e); } if (ReturningResults == null || ReturningResults.Length == 0) { if (NeedAcknowledge) { _acknowledgeCallback(_acknowledgedState); _completionCallback(_completionState); } ModuleHost.RequestNextDataItem(); } else if (NeedAcknowledge) { void AcknowledgeBypass(object ackState) { lock (shutdownLock) { if (shutdown) { return; } _acknowledgeCallback(_acknowledgedState); _completionCallback(_completionState); ModuleHost.RequestNextDataItem(); } } if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0], AcknowledgeBypass, null); } else { ModuleHost.PostOutputDataItems(ReturningResults, _logicallyGrouped, AcknowledgeBypass, null); } } else { if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0]); } else { ModuleHost.PostOutputDataItems(ReturningResults, _logicallyGrouped); } ModuleHost.RequestNextDataItem(); } } } finally { enqueuedSemaphore.Release(); } }
public void OnNewDataItems(DataItemBase[] dataItems, bool logicallyGrouped, DataItemAcknowledgementCallback acknowledgeCallback, object acknowledgedState, DataItemProcessingCompleteCallback completionCallback, object completionState) { if ((acknowledgeCallback == null && completionCallback != null) || (acknowledgeCallback != null && completionCallback == null)) { throw new ArgumentOutOfRangeException("acknowledgeCallback, completionCallback"); } bool NeedAcknowledge = (acknowledgeCallback != null); lock (shutdownLock) { if (shutdown) { return; } TOutputDataType[] ReturningResults; try { ReturningResults = GetOutputData(dataItems); } catch (Exception e) { if (NeedAcknowledge) { acknowledgeCallback(acknowledgedState); completionCallback(completionState); } ModuleHost.RequestNextDataItem(); throw new ModuleException(e.Message, e); } if (ReturningResults == null || ReturningResults.Length == 0) { if (NeedAcknowledge) { acknowledgeCallback(acknowledgedState); completionCallback(completionState); } ModuleHost.RequestNextDataItem(); } else if (NeedAcknowledge) { void AcknowledgeBypass(object ackState) { lock (shutdownLock) { if (shutdown) { return; } acknowledgeCallback(acknowledgedState); completionCallback(completionState); ModuleHost.RequestNextDataItem(); } } if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0], AcknowledgeBypass, null); } else { ModuleHost.PostOutputDataItems(ReturningResults, logicallyGrouped, AcknowledgeBypass, null); } } else { if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0]); } else { ModuleHost.PostOutputDataItems(ReturningResults, logicallyGrouped); } ModuleHost.RequestNextDataItem(); } } }