/// <summary> /// Writes <paramref name="data"/> received in <see cref="System.ServiceModel.Web.WebMessageFormat.Json"/> format to the <see cref="DataService.Archive"/>. /// </summary> /// <param name="data">An <see cref="SerializableTimeSeriesData"/> object.</param> public void WriteTimeSeriesDataAsJson(SerializableTimeSeriesData data) { WriteTimeSeriesData(data); }
private SerializableTimeSeriesData ReadCurrentTimeSeriesData(string fromID, string toID) { try { // Abort if services is not enabled. if (!Enabled) return null; // Ensure that data archive is available. if (Archive == null) throw new ArgumentNullException("Archive"); // Read current time-series data from the archive. byte[] buffer = null; StateRecord state = null; SerializableTimeSeriesData data = new SerializableTimeSeriesData(); List<SerializableTimeSeriesDataPoint> points = new List<SerializableTimeSeriesDataPoint>(); for (int id = int.Parse(fromID); id <= int.Parse(toID); id++) { buffer = Archive.ReadStateData(id); if (buffer == null) { // ID is invalid. continue; } else { // Add to resultset. state = new StateRecord(id, buffer, 0, buffer.Length); points.Add(new SerializableTimeSeriesDataPoint(state.CurrentData)); } } data.TimeSeriesDataPoints = points.ToArray(); return data; } catch (Exception ex) { // Notify about the encountered processing exception. OnServiceProcessException(ex); throw; } }
private SerializableTimeSeriesData ReadHistoricTimeSeriesData(string fromID, string toID, string startTime, string endTime) { try { // Abort if services is not enabled. if (!Enabled) return null; // Ensure that data archive is available. if (Archive == null) throw new ArgumentNullException("Archive"); // Read historic time-series data from the archive. SerializableTimeSeriesData data = new SerializableTimeSeriesData(); List<SerializableTimeSeriesDataPoint> points = new List<SerializableTimeSeriesDataPoint>(); List<int> historianIDs = new List<int>(); for (int id = int.Parse(fromID); id <= int.Parse(toID); id++) { historianIDs.Add(id); } foreach (IDataPoint point in Archive.ReadData(historianIDs, startTime, endTime)) { points.Add(new SerializableTimeSeriesDataPoint(point)); } data.TimeSeriesDataPoints = points.ToArray(); return data; } catch (Exception ex) { // Notify about the encountered processing exception. OnServiceProcessException(ex); throw; } }
private void WriteTimeSeriesData(SerializableTimeSeriesData data) { try { // Abort if services is not enabled. if (!Enabled) return; // Ensure that data archive is available. if (Archive == null) throw new ArgumentNullException("Archive"); // Write all time-series data to the archive. foreach (SerializableTimeSeriesDataPoint point in data.TimeSeriesDataPoints) { Archive.WriteData(point.Deflate()); } } catch (Exception ex) { // Notify about the encountered processing exception. OnServiceProcessException(ex); throw; } }