/// <summary> /// Creates a given stream for the given device /// </summary> /// <param name="device">The device that you would like to add a stream to</param> /// <param name="stream">The stream you will be adding to the given device</param> /// <returns>The stream that was actually created with all the fields populated</returns> public DeviceStream CreateStream(Device device, DeviceStream stream) { //Scrub all the data we need for creating a stream if (device.guid == Guid.Empty) { throw new Exception("Device requires a guid to create a stream"); } if (string.IsNullOrEmpty(stream.name)) { throw new Exception("The Stream Requires a Name"); } if (string.IsNullOrEmpty(stream.description)) { throw new Exception("The Stream requires a description"); } if (stream.streams.Count == 0) { throw new Exception("Invalid Stream"); } //POST the simple stream string response = POST(serverURL + baseURL + streamAPI + "create=a", JsonConvert.SerializeObject(stream, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }), device.guid.ToString()); stream = JsonConvert.DeserializeObject <DeviceStream>(response); //ensure we got a guid, if we didn't, try and see if we received an error if (String.IsNullOrEmpty(stream.streamid.ToString())) { //check for an error Error er = JsonConvert.DeserializeObject <Error>(response); if (string.IsNullOrEmpty(er.error)) { //we don't appear to have received an error, throw an exception showing the entire response throw new Exception("No guid retrieved during stream creation. No error was returned either. Response was: " + response); } else { //we did receive an error, throw it as an exception throw new Exception(er.error); } } return(stream); }
/// <summary> /// Deletes a stream from a device /// </summary> /// <param name="device">The device to delete the stream from</param> /// <param name="stream">The stream to delete</param> /// <returns>True if delete is successful, false otherwise</returns> public bool DeleteStream(Device device, DeviceStream stream) { //check to make sure a guid was given with the device if (device.guid == Guid.Empty) { throw new Exception("GUID of the device does not exist. Please use a valid device to delete the streams from."); } //check to make sure a stream guid if (string.IsNullOrEmpty(stream.streamid.ToString())) { throw new Exception("No streamID in the stream. Please use a valid stream to delete."); } if (POST(serverURL + baseURL + streamAPI + "delete=" + stream.streamid, "", device.guid.ToString()) != "{ \"status\" : \"success\" }") { return(false); } else { return(true); } }
/// <summary> /// Retrieves the statistics of a stream /// </summary> /// <param name="stream">the stream to get stats for</param> /// <returns>the stats of a stream</returns> public OverallStreamStatistics GetStatistics(DeviceStream stream) { return(GetStatistics(stream.streamid)); }
/// <summary> /// Gets data between two given dates /// </summary> /// <param name="stream">the stream containing the streamID</param> /// <param name="startDate">the date to get data before</param> /// <param name="endDate">the date to get data before</param> /// <param name="numberOfPoints">The number of points to retrieve</param> /// <param name="timeonly">true if you only want times</param> /// <returns>device containing the requested data</returns> public Device GetDataBetween(DeviceStream stream, DateTime startDate, DateTime endDate, int numberOfPoints, bool timeonly = false) { return(GetDataBetween(stream.streamid, startDate, endDate, numberOfPoints, timeonly)); }
/// <summary> /// Gets data between two given dates /// </summary> /// <param name="stream">the stream containing the streamID</param> /// <param name="startDate">the date to get data before</param> /// <param name="endDate">the date to get data before</param> /// <param name="timeonly">true if you only want times</param> /// <returns>device containing the requested data</returns> public Device GetDataBetween(DeviceStream stream, DateTime startDate, DateTime endDate, bool timeonly = false) { return(GetDataBetween(stream.streamid, startDate, endDate, dataPointsToRetrieve, timeonly)); }
/// <summary> /// Gets data from the given stream /// </summary> /// <param name="stream">the stream containing the streamid for retrieving the data</param> /// <param name="numberOfPoints">The number of data points to retrieve</param> /// <param name="timeonly">true if you only want to retrieve timestamps</param> /// <returns>device complete with stream and data</returns> public Device GetData(DeviceStream stream, int numberOfPoints, bool timeonly = false) { return(GetData(stream.streamid, numberOfPoints, timeonly)); }
/// <summary> /// Gets data from the given stream /// </summary> /// <param name="stream">the stream containing the streamid for retrieving the data</param> /// <param name="timeonly">true if you only want to retrieve times</param> /// <returns>device complete with stream and data</returns> public Device GetData(DeviceStream stream, bool timeonly = false) { return(GetData(stream.streamid, dataPointsToRetrieve, timeonly)); }
/// <summary> /// Gets the stream information by the streamID /// </summary> /// <param name="stream">The stream containing a streamID</param> /// <returns>a new device with the stream populated</returns> public Device GetStreamFromStreamID(DeviceStream stream) { return(GetStreamFromStreamID(stream.streamid)); }