Rozdíly

Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.

Odkaz na výstup diff

Obě strany předchozí revize Předchozí verze
Následující verze
Předchozí verze
cs:mervis-db:10-api [2021/10/25 08:27]
v.kohout [C#]
cs:mervis-db:10-api [2024/05/08 10:42] (aktuální)
Řádek 25: Řádek 25:
 ^GetVariableStatsAsync|Obsolete| ^GetVariableStatsAsync|Obsolete|
 ^CheckCredentials| | ^CheckCredentials| |
 +
 +===== Vlastnosti objektu =====
 +  * (UTC) Časová známka - UTC časová známka záznamu
 +  * Platnost do - UTC časová známka konce platnosti konkrétního záznamu
 +  * Interval - doba (v sekundách), kdy by měla být zaznamenána další hodnota
  
 ===== Příklady použití ===== ===== Příklady použití =====
Řádek 42: Řádek 47:
  
 <code csharp MervisDB_GetData_Example.cs> <code csharp MervisDB_GetData_Example.cs>
 +using ESG.Core.Access.Client;
 +using ESG.Db.Server.Shared;
 +using ESG.Db.ServerAccess;
 using System; using System;
 +using System.Collections.Generic;
 using System.Linq; using System.Linq;
 using System.Threading.Tasks; using System.Threading.Tasks;
-using MervisDb_GetData_Example.MervisDbService; 
  
-namespace MervisDb_GetData_Example +namespace DbClientTest 
- class Program { +
-  static void Main(string[] args) { + class Program 
-   // +
-   // Demo of asynchronous methods. + static async Task Main(string[] args) 
-   // +
-   var task = Task.Run(async() => + try 
-    // +
-    // Create access to the real server. + // 
-    // Without SSL connections, you have to remove binding parameters "<security mode="Transport"/>" in the App.config. + // Create access to the real server. 
-    // The client is automatically generated from the WSDL file available here: https://kb.mervis.info/doku.php/en:mervis-db:10-api + // Without SSL connections, you have to remove binding parameters "<security mode="Transport"/>" 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("HistoryAccess", "https://localhost:9876/RcWareDbAccess")) { + // 
-     // Authentication credetials in the database. + using (HistoryDbAccessClient client = new HistoryDbAccessClient(HistoryDbAccessClient.EndpointConfiguration.HistoryAccess, "https://localhost:9876/RcWareDbAccess")) 
-     Credentials credentials = new Credentials { +
-      Name = "XXXX", Password = "YYYY" + // Authentication credetials in the database. 
-     };+ Credentials credentials = new Credentials 
 +
 + Name = "XXXX", 
 + Password = "YYYY" 
 + };
  
-     // Specification of the variables through Key-Value. + // Specification of the variables through Key-Value. 
-     // Here we use 2 variables. + // Here we use 2 variables. 
-     KeyValuePair[][] keys = new KeyValuePair[][] { + ESG.Db.Server.Shared.KeyValuePair[][] keys = new ESG.Db.Server.Shared.KeyValuePair[][] { 
-      new KeyValuePair[] { +  new ESG.Db.Server.Shared.KeyValuePair[] { 
-        new KeyValuePair +  new ESG.Db.Server.Shared.KeyValuePair(true, "DPGuid","338E2882-D72B-4D17-A241-73E8BC30F458"), 
-         Key = "DPGuid", Value = "338E2882-D72B-4D17-A241-73E8BC30F458" +  new ESG.Db.Server.Shared.KeyValuePair(true, "StationName", "AAABBB") 
-        }, new KeyValuePair +  }, 
-         Key = "StationName", Value = "AAABBB" +    new ESG.Db.Server.Shared.KeyValuePair[] { 
-        } +  new ESG.Db.Server.Shared.KeyValuePair(true, "DPGuid", "CC80211D-3D29-4CC2-91A2-F69483D566B5"), 
-       }, +  new ESG.Db.Server.Shared.KeyValuePair(true, "StationName", "AAABBB") 
-       new KeyValuePair[] { +  
-        new KeyValuePair +  };
-         Key = "DPGuid", Value = "CC80211D-3D29-4CC2-91A2-F69483D566B5" +
-        }, new KeyValuePair +
-         Key = "StationName", Value = "AAABBB" +
-        } +
-       +
-     };+
  
-     // From-To dates. The dates must be specified in the UTC time zone. + // From-To dates. The dates must be specified in the UTC time zone. 
-     DateTime utcTo = DateTime.UtcNow; + DateTime utcTo = DateTime.UtcNow; 
-     DateTime utcFrom = DateTime.UtcNow.AddDays(-1);+ DateTime utcFrom = DateTime.UtcNow.AddDays(-1);
  
-     // Retrieving the data goes through cycling of values and variables. The server returns recommended values needed for the the next cycle. + // Retrieving the data goes through cycling of values and variables. The server returns recommended values needed for the the next cycle. 
-     int variableOffset = 0; // the offset of the variable + int variableOffset = 0; // the offset of the variable 
-     int variableCount = 10; // maximal number of variables returned in one request + int variableCount = 10; // maximal number of variables returned in one request 
-     int valueOffset; // the offset of the value + int valueOffset; // the offset of the value 
-     int valueCount = 1000; // maximal values in on request+ int valueCount = 1000; // maximal values in on request
  
-     Console.WriteLine("Reading values...");+ Console.WriteLine("Reading values...");
  
-     do { + do 
-      valueOffset = 0; +
-      do { + valueOffset = 0; 
-       // Execute the request. + do 
-       var result = await client.GetDataAsyncAsync(credentials, keys, utcFrom, utcTo, variableOffset, variableCount, valueOffset, valueCount);+
 + // Execute the request. 
 + var result = await client.GetDataAsyncAsync(credentials, keys, utcFrom, utcTo, variableOffset, variableCount, valueOffset, valueCount);
  
-       // Check the return code. "0;OK" is what we want. + // Check the return code. "0;OK" is what we want. 
-       if (!result.ReturnCode.StartsWith("0;")) { + if (!result.ReturnCode.StartsWith("0;")) 
-        Console.WriteLine("Error on reading: {0}", result.ReturnCode); +
-       }+ Console.WriteLine("Error on reading: {0}", result.ReturnCode); 
 + }
  
-       // Cycle through the data and print it out. + // Cycle through the data and print it out. 
-       foreach(var valRecord in result.Data) { + foreach (var valRecord in result.Data) 
-        Console.WriteLine("Variable: {0}", String.Concat(valRecord.Keys.Select((i) => { +
-         return String.Format("{0}={1}; ", i.Key, i.Value); + Console.WriteLine("Variable: {0}", String.Concat(valRecord.Keys.Select((i) => 
-        })));+
 + return String.Format("{0}={1}; ", i.Key, i.Value); 
 + })));
  
-        foreach(var value in valRecord.Vals) { + foreach (var value in valRecord.Values) 
-         Console.WriteLine("{0}->{1} [{2}] {3}", value.Ts, value.Gt, value.Hvt, value.Dv /* Use value type according to the Hvt (History Value Type) */ ); +
-        + Console.WriteLine("{0}->{1} [{2}] {3}", value.UtcTimeStamp, value.GoodThrough, value.HistoryValueType, value.DoubleValue /* Use value type according to the Hvt (History Value Type) */ ); 
-       }+
 + }
  
-       valueOffset = result.NextValueOffset; + valueOffset = result.NextValueOffset; 
-       variableOffset = result.NextVariableOffset; + variableOffset = result.NextVariableOffset; 
-      +
-      while (valueOffset != -1); + while (valueOffset != -1); 
-     +
-     while (variableOffset != -1); + while (variableOffset != -1); 
-    } + }
-   });+
  
-   Console.WriteLine("DB communication is running in background");+
 + catch (Exception exc) 
 +
 + Console.WriteLine("Exception: {0}", exc.ToString()); 
 + }
  
-   try { + Console.WriteLine("DB communication finished");
-    task.Wait(); +
-   } catch (Exception exc) { +
-    Console.WriteLine("Exception: {0}", exc.ToString()); +
-   }+
  
-   Console.WriteLine("DB communication finished");+ Console.ReadLine(); 
 + }
  
-   Console.ReadLine(); 
-  } 
  }  }
 }</code> }</code>
Řádek 152: Řádek 162:
  class Program  class Program
  {  {
- static void Main(string[] args)+ static async Task Main(string[] args)
  {  {
- // + try
- // Demo of asynchronous methods. +
- // +
- var task = Task.Run(async () =>+
  {  {
  //  //
Řádek 164: Řádek 171:
  // The client is automatically generated from the WSDL file available here: https://kb.mervis.info/doku.php/en:mervis-db:10-api  // 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("HistoryAccess", "https://localhost:9876/RcWareDbAccess"))+ using (HistoryDbAccessClient client = new HistoryDbAccessClient(HistoryDbAccessClient.EndpointConfiguration.HistoryAccess, "https://localhost:9876/RcWareDbAccess"))
  {  {
  // Authentication credetials in the database.  // Authentication credetials in the database.
Řádek 181: Řádek 188:
  rec.DoubleValue = 23.4;                         // value itself  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.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 KeyValuePair[] // identification of the variable. At least one key-value pair must be "IsKey" to identify a variable.+ 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 KeyValuePair { IsKey = true, Key = "Root", Value = "Building A"}+ new ESG.Db.Server.Shared.KeyValuePair(true, "Root", "Building A")
- new KeyValuePair { IsKey = true, Key = "Level1", Value = "Floor 1"}+ new ESG.Db.Server.Shared.KeyValuePair(true, "Level1", "Floor 1")
- new KeyValuePair { IsKey = true, Key = "Level2", Value = "Room 7"}+ new ESG.Db.Server.Shared.KeyValuePair(true, "Level2", "Room 7")
- new KeyValuePair { IsKey = true, Key = "Level3", Value = "Temperature"}+ new ESG.Db.Server.Shared.KeyValuePair(true, "Level3", "Temperature")
- new KeyValuePair { IsKey = false, Key = "Description", Value = "Temperature in the room 7"}+ new ESG.Db.Server.Shared.KeyValuePair(false, "Description", "Temperature in the room 7")
- new KeyValuePair { IsKey = false, Key = "Unit", Value = "°C"},+ new ESG.Db.Server.Shared.KeyValuePair(false, "Unit", "°C"),
  };  };
  
Řádek 198: Řádek 205:
  Console.WriteLine("Records saved: {0}", recordsSaved);  Console.WriteLine("Records saved: {0}", recordsSaved);
  }  }
- }); 
  
- Console.WriteLine("DB communication is running in background"); 
- 
- try 
- { 
- task.Wait(); 
  }  }
  catch (Exception exc)  catch (Exception exc)
Řádek 272: Řádek 273:
  }  }
  
- var res = await dbClient.ReplaceDataAsync(new List<ESG.Db.Server.Shared.KeyValuePair[]> { varKeys }, utcNow.Subtract(TimeSpan.FromMinutes(10)), utcNow, recsToSave.ToArray());+ var res = await dbClient.ReplaceDataAsync(new List<ESG.Db.Server.Shared.KeyValuePair[]> { varKeys }, utcNow.Subtract(recsLength), utcNow, recsToSave.ToArray());
  }  }
  }  }
Řádek 288: Řádek 289:
  class Program  class Program
  {  {
- static void Main(string[] args)+ static async Task Main(string[] args)
  {  {
  //  //
- // Demo of asynchronous method.+ // Create access to the real server. 
 + // Without SSL connections, you have to remove binding parameters "<security mode="Transport"/>" 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
  //  //
- var task = Task.Run(async () =>+ try
  {  {
- // + using (HistoryDbAccessClient client = new HistoryDbAccessClient(HistoryDbAccessClient.EndpointConfiguration.HistoryAccess, "http://localhost:9876/RcWareDbAccess"))
- // Create access to the real server. +
- // Without SSL connections, you have to remove binding parameters "<security mode="Transport"/>" 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("HistoryAccess", "http://localhost:9876/RcWareDbAccess"))+
  {  {
  // Authentication credentials in the database.  // Authentication credentials in the database.
Řádek 307: Řádek 305:
  // Specification of the variables through Key-Value.  // Specification of the variables through Key-Value.
  // Here we use 2 variables.  // Here we use 2 variables.
- KeyValuePair[][] variableKeys = new KeyValuePair[][] { + ESG.Db.Server.Shared.KeyValuePair[][] variableKeys = new ESG.Db.Server.Shared.KeyValuePair[][] { 
- new KeyValuePair[] { + new ESG.Db.Server.Shared.KeyValuePair[] { 
- new KeyValuePair (false, /*Key*/ "DPGuid", /*Value*/ "338E2882-D72B-4D17-A241-73E8BC30F458"), + new ESG.Db.Server.Shared.KeyValuePair (/*IsKeyId*/ false, /*Key*/ "DPGuid", /*Value*/ "338E2882-D72B-4D17-A241-73E8BC30F458"), 
- new KeyValuePair (false, /*Key*/ "StationName", /*Value*/ "AAABBB")+ new ESG.Db.Server.Shared.KeyValuePair (/*IsKeyId*/ false, /*Key*/ "StationName", /*Value*/ "AAABBB")
  },  },
- new KeyValuePair[] { + new ESG.Db.Server.Shared.KeyValuePair[] { 
- new KeyValuePair (false, /*Key*/ "DPGuid", /*Value*/ "CC80211D-3D29-4CC2-91A2-F69483D566B5"), + new ESG.Db.Server.Shared.KeyValuePair (/*IsKeyId*/ false, /*Key*/ "DPGuid", /*Value*/ "CC80211D-3D29-4CC2-91A2-F69483D566B5"), 
- new KeyValuePair (false, /*Key*/ "StationName", /*Value*/ "AAABBB")+ new ESG.Db.Server.Shared.KeyValuePair (/*IsKeyId*/ false, /*Key*/ "StationName", /*Value*/ "AAABBB")
  }  }
  };  };
Řádek 325: Řádek 323:
  aggregation.IsoPattern = new string[] { "PT15M" }; // 15 min period (ISO 8601 duration pattern)  aggregation.IsoPattern = new string[] { "PT15M" }; // 15 min period (ISO 8601 duration pattern)
  aggregation.From = new DateTime(2018, 11, 24, 0, 0, 0, 0, DateTimeKind.Unspecified);  aggregation.From = new DateTime(2018, 11, 24, 0, 0, 0, 0, DateTimeKind.Unspecified);
- aggregation.To =   new DateTime(2018, 11, 25, 0, 0, 0, 0, DateTimeKind.Unspecified);+ aggregation.To = new DateTime(2018, 11, 25, 0, 0, 0, 0, DateTimeKind.Unspecified);
  aggregation.TimeZone = @"Europe/Prague";  aggregation.TimeZone = @"Europe/Prague";
  
Řádek 379: Řádek 377:
  } while (variableOffset != -1);  } while (variableOffset != -1);
  }  }
- }); 
  
  Console.WriteLine("DB communication is running in background");  Console.WriteLine("DB communication is running in background");
  
- try 
- { 
- task.Wait(); 
  }  }
  catch (Exception exc)  catch (Exception exc)
Řádek 396: Řádek 390:
  Console.ReadLine();  Console.ReadLine();
  }  }
- 
  }  }
 } }
  • © Energocentrum Plus, s.r.o. 2017 - 2024