using System; using System.Collections.Generic; using System.Threading.Tasks; using MervisDb_SaveData_Example.MervisDbService; namespace MervisDb_SaveData_Example { class Program { static async Task Main(string[] args) { try { // // Create access to the real server. // Without SSL connections, you have to remove binding parameters "" in the App.config. // The client is automatically generated from the WSDL file available here: https://kb.mervis.info/doku.php/en:mervis-db:10-api // using (HistoryDbAccessClient client = new HistoryDbAccessClient(HistoryDbAccessClient.EndpointConfiguration.HistoryAccess, "https://localhost:9876/RcWareDbAccess")) { // Authentication credetials in the database. Credentials credentials = new Credentials { Name = "XXXX", Password = "YYYY" }; // Adding records... List records = new List(); DateTime utcTimeStamp = new DateTime(2018, 1, 1, 12, 0, 0, DateTimeKind.Utc); // Each value is stored in a ValueRecord structure ValueRecord rec = new ValueRecord(); rec.UtcTimeStamp = utcTimeStamp; // time stamp of the value, UTC date time must be used rec.HistoryValueType = HistoryValueType.Double; // type of the value rec.DoubleValue = 23.4; // value itself rec.Interval = 60.0; // sampling period in seconds. When the difference of timestamps of subsequent values if greater than 1.1 multiple of the interval, the data should be considered incomplete. rec.Keys = new ESG.Db.Server.Shared.KeyValuePair[] // identification of the variable. At least one key-value pair must be "IsKey" to identify a variable. { new ESG.Db.Server.Shared.KeyValuePair(true, "Root", "Building A"), new ESG.Db.Server.Shared.KeyValuePair(true, "Level1", "Floor 1"), new ESG.Db.Server.Shared.KeyValuePair(true, "Level2", "Room 7"), new ESG.Db.Server.Shared.KeyValuePair(true, "Level3", "Temperature"), new ESG.Db.Server.Shared.KeyValuePair(false, "Description", "Temperature in the room 7"), new ESG.Db.Server.Shared.KeyValuePair(false, "Unit", "°C"), }; records.Add(rec); // Save data method returns the number of stored records int recordsSaved = await client.SaveDataAsync(credentials, records.ToArray()); Console.WriteLine("Records saved: {0}", recordsSaved); } } catch (Exception exc) { Console.WriteLine("Exception: {0}", exc.ToString()); } Console.WriteLine("DB communication finished"); Console.ReadLine(); } } }