/// <summary> /// Creates the runtime measurements to send. /// </summary> /// <param name="runtimeMeasurements">The runtime measurements.</param> /// <returns><c>true</c> if at least one measurement has been found, <c>false</c> otherwise.</returns> /// <remarks> /// This method is called either for the runtime view monitor or when a request from SupplyCare Enterprise comes. /// The method returns the list of current items to be sent to the calling client. /// </remarks> public bool CreateRuntimeMeasurementsToSend(out RuntimeMeasurements runtimeMeasurements) { runtimeMeasurements = null; var result = false; if (this.RuntimeMeasurementToSendReferences.Count > 0) { // Clone a list with the measurements that are ready to send. runtimeMeasurements = new RuntimeMeasurements(); runtimeMeasurements.AddRange( this.RuntimeMeasurementToSendReferences.Select( index => new RuntimeMeasurement(this.RuntimeMeasurements[index]))); if (this.MustClearReferences()) { this.RuntimeMeasurementToSendReferences.Clear(); } // The measurements here have the real value, as it was received from some communication. // There are limitations concerning maximal size of strings. // These limitations are implemented here to get same results in the online view and SCE / FIS sent data. TrimRuntimeMeasurementsToSend(runtimeMeasurements); result = true; } return(result); }
/// <summary> /// Creates the document to send to SupplyCare Enterprise. /// </summary> /// <param name="responseString">The response string.</param> private void CreateDocument(out string responseString) { try { RuntimeMeasurements measurements; if (!this.SceMonitorScheduler.DataToSend(out measurements)) { // Empty document is valid, only the header shall be sent. // The empty collection must be created here because the out variable can be unpredictable at this point. measurements = new RuntimeMeasurements(); } var document = new SceDocument(this.DataManager.Configuration, measurements); document.Create(); responseString = document.ToString(); } catch (Exception exception) { Logger.FatalException(this, "Error creating SupplyCare Enterprise document.", exception); DiagnosticsCollection.Instance.AddMessage("Error creating SupplyCare Enterprise document."); DiagnosticsCollection.Instance.AddMessage(exception); // Sets the local variables to prevent somehow unexpected values. responseString = string.Empty; } }
/// <summary> /// Called when [runtime measurements indication]. /// </summary> /// <param name="measurements">The measurements.</param> public void OnRuntimeMeasurementsIndication(RuntimeMeasurements measurements) { var serviceDataReceiver = this.GetServiceDataReceiver(); if (serviceDataReceiver != null) { serviceDataReceiver.RuntimeMeasurementsCompleted(measurements); } }
/// <summary> /// Called when [runtime measurements indication]. /// </summary> /// <param name="measurements">The measurements.</param> protected void OnRuntimeMeasurementsIndication(RuntimeMeasurements measurements) { System.Diagnostics.Debug.WriteLine(string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name)); foreach (var item in measurements) { System.Diagnostics.Debug.WriteLine(string.Format("Measurement - RequestIndex: {0}, DeviceId: {1}, SensorId: {2}, Unit: {3}, DataType: {4}, Timestamp: {5}, Quality: {6}, Value: {7} ", item.RequestIndex, item.DeviceId, item.SensorId, item.Unit, item.DataType, item.Timestamp, item.Quality, item.Value)); } }
/// <summary> /// Checks whether there is data to send. /// </summary> /// <param name="runtimeMeasurements">The runtime measurements.</param> /// <returns><c>true</c> if there is data to send, <c>false</c> otherwise.</returns> public bool DataToSend(out RuntimeMeasurements runtimeMeasurements) { runtimeMeasurements = null; var result = false; // Continue only if monitoring is running. if (this.IsRunning) { // Checks whether there is data to send. if (this.OpcMonitor.CreateRuntimeMeasurementsToSend(out runtimeMeasurements)) { result = true; } } return(result); }
/// <summary> /// Trims the runtime measurements to send. This method trims possibly some value according to the limitations specified in the Common Format Specification document. /// </summary> /// <param name="runtimeMeasurements">The runtime measurements.</param> private static void TrimRuntimeMeasurementsToSend(RuntimeMeasurements runtimeMeasurements) { if (runtimeMeasurements != null) { foreach (var runtimeMeasurement in runtimeMeasurements) { // A method that takes a reference to a string would work, but ONLY if the argument is the string itself, NOT a member of a class!!! Unfortunately. if (runtimeMeasurement.DataType != null && runtimeMeasurement.DataType.Length > CommonFormat.MaxCommonDataLength) { runtimeMeasurement.DataType = runtimeMeasurement.DataType.Substring(0, CommonFormat.MaxCommonDataLength); } if (runtimeMeasurement.DeviceId != null && runtimeMeasurement.DeviceId.Length > CommonFormat.MaxCommonDataLength) { runtimeMeasurement.DeviceId = runtimeMeasurement.DeviceId.Substring(0, CommonFormat.MaxCommonDataLength); } if (runtimeMeasurement.Quality != null && runtimeMeasurement.Quality.Length > CommonFormat.MaxCommonDataLength) { runtimeMeasurement.Quality = runtimeMeasurement.Quality.Substring(0, CommonFormat.MaxCommonDataLength); } if (runtimeMeasurement.SensorId != null && runtimeMeasurement.SensorId.Length > CommonFormat.MaxCommonDataLength) { runtimeMeasurement.SensorId = runtimeMeasurement.SensorId.Substring(0, CommonFormat.MaxCommonDataLength); } if (runtimeMeasurement.Timestamp != null && runtimeMeasurement.Timestamp.Length > CommonFormat.MaxCommonDataLength) { runtimeMeasurement.Timestamp = runtimeMeasurement.Timestamp.Substring(0, CommonFormat.MaxCommonDataLength); } if (runtimeMeasurement.Unit != null && runtimeMeasurement.Unit.Length > CommonFormat.MaxCommonDataLength) { runtimeMeasurement.Unit = runtimeMeasurement.Unit.Substring(0, CommonFormat.MaxCommonDataLength); } if (runtimeMeasurement.Value != null && runtimeMeasurement.Value.Length > CommonFormat.MaxValueDataLength) { runtimeMeasurement.Value = runtimeMeasurement.Value.Substring(0, CommonFormat.MaxValueDataLength); } } } }
/// <summary> /// Initializes a new instance of the <see cref="DocumentCreator"/> class. /// </summary> /// <param name="configuration">The current configuration.</param> /// <param name="measurements">The input measurements.</param> public DocumentCreator(Configuration configuration, RuntimeMeasurements measurements) { this.configuration = configuration; this.measurements = measurements; }
/// <summary> /// Handles the runtime measurements response. /// </summary> /// <param name="runtimeMeasurements">The runtime measurements.</param> private void HandleRuntimeMeasurementsResponse(RuntimeMeasurements runtimeMeasurements) { this.OnRuntimeMeasurementsResponse(runtimeMeasurements); }
/// <summary> /// Runtimes the measurements completed. /// </summary> /// <param name="runtimeMeasurements">The runtime measurements.</param> public void RuntimeMeasurementsCompleted(RuntimeMeasurements runtimeMeasurements) { Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Input, new Action <RuntimeMeasurements>(this.HandleRuntimeMeasurementsResponse), runtimeMeasurements); }
/// <summary> /// Called when [runtime measurements indication]. /// </summary> /// <param name="measurements">The measurements.</param> void ICommServerCallback.OnRuntimeMeasurementsIndication(RuntimeMeasurements measurements) { this.OnRuntimeMeasurementsIndication(measurements); }
/// <summary> /// Initializes a new instance of the <see cref="SceDocument" /> class. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="runtimeMeasurements">The runtime measurements.</param> public SceDocument(Configuration configuration, RuntimeMeasurements runtimeMeasurements) { this.configuration = configuration; this.runtimeMeasurements = runtimeMeasurements; }