Rozdíly
Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
Obě strany předchozí revize Předchozí verze Následující verze | Předchozí verze | ||
cs:mervis-db:10-api [2019/03/12 08:27] m.chlupac |
cs:mervis-db:10-api [2024/04/10 13:47] (aktuální) k.capka |
||
---|---|---|---|
Řádek 18: | Řádek 18: | ||
^DeleteVariables| | | ^DeleteVariables| | | ||
^DeleteData| | | ^DeleteData| | | ||
+ | ^ReplaceData|Delete data from time range and save one or multiple records from one or multiple variables in one API call| | ||
^EnsureVariables| | | ^EnsureVariables| | | ||
- | ^GetTransformedData/ | + | ^GetTransformedData/ |
^GetServerVersion| | | ^GetServerVersion| | | ||
^GetVariableStats|Obsolete| | ^GetVariableStats|Obsolete| | ||
^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), | ||
===== Příklady použití ===== | ===== Příklady použití ===== | ||
Řádek 41: | Řá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 | + | namespace |
- | class Program { | + | { |
- | static | + | class Program |
- | // | + | { |
- | // Demo of asynchronous methods. | + | static |
- | // | + | { |
- | var task = Task.Run(async() => { | + | try |
- | // | + | { |
- | // Create access to the real server. | + | // |
- | // Without SSL connections, | + | // Create access to the real server. |
- | // The client is automatically generated from the WSDL file available here: https:// | + | // Without SSL connections, |
- | // | + | // The client is automatically generated from the WSDL file available here: https:// |
- | using(HistoryDbAccessClient client = new HistoryDbAccessClient("HistoryAccess", " | + | // |
- | | + | using (HistoryDbAccessClient client = new HistoryDbAccessClient(HistoryDbAccessClient.EndpointConfiguration.HistoryAccess, |
- | | + | { |
- | Name = " | + | // Authentication credetials in the database. |
- | | + | Credentials credentials = new Credentials |
+ | { | ||
+ | Name = " | ||
+ | Password = " | ||
+ | }; | ||
- | // Specification of the variables through Key-Value. | + | // Specification of the variables through Key-Value. |
- | | + | // Here we use 2 variables. |
- | | + | 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, |
- | Key = " | + | new ESG.Db.Server.Shared.KeyValuePair(true, |
- | | + | }, |
- | Key = " | + | new ESG.Db.Server.Shared.KeyValuePair[] { |
- | } | + | new ESG.Db.Server.Shared.KeyValuePair(true, |
- | }, | + | |
- | | + | } |
- | new KeyValuePair | + | }; |
- | Key = " | + | |
- | }, new KeyValuePair | + | |
- | Key = " | + | |
- | } | + | |
- | } | + | |
- | | + | |
- | // 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 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 variableCount = 10; // maximal number of variables returned in one request |
- | | + | int valueOffset; |
- | | + | int valueCount = 1000; // maximal values in on request |
- | Console.WriteLine(" | + | Console.WriteLine(" |
- | do { | + | do |
- | valueOffset = 0; | + | { |
- | do { | + | valueOffset = 0; |
- | | + | do |
- | | + | { |
+ | // Execute the request. | ||
+ | var result = await client.GetDataAsyncAsync(credentials, | ||
- | // Check the return code. " | + | // Check the return code. " |
- | | + | if (!result.ReturnCode.StartsWith(" |
- | Console.WriteLine(" | + | { |
- | | + | Console.WriteLine(" |
+ | } | ||
- | // Cycle through the data and print it out. | + | // Cycle through the data and print it out. |
- | | + | foreach (var valRecord in result.Data) |
- | Console.WriteLine(" | + | { |
- | | + | Console.WriteLine(" |
- | }))); | + | { |
+ | return String.Format(" | ||
+ | }))); | ||
- | | + | foreach (var value in valRecord.Values) |
- | | + | { |
- | } | + | Console.WriteLine(" |
- | | + | } |
+ | } | ||
- | valueOffset = result.NextValueOffset; | + | valueOffset = result.NextValueOffset; |
- | | + | variableOffset = result.NextVariableOffset; |
- | } | + | } |
- | while (valueOffset != -1); | + | while (valueOffset != -1); |
- | | + | } |
- | | + | while (variableOffset != -1); |
- | } | + | } |
- | }); | + | |
- | Console.WriteLine(" | + | } |
+ | catch (Exception exc) | ||
+ | { | ||
+ | Console.WriteLine(" | ||
+ | } | ||
- | try { | + | Console.WriteLine(" |
- | task.Wait(); | + | |
- | } catch (Exception exc) { | + | |
- | | + | |
- | } | + | |
- | Console.WriteLine("DB communication finished" | + | Console.ReadLine(); |
+ | } | ||
- | | ||
- | } | ||
} | } | ||
}</ | }</ | ||
Řádek 151: | Řádek 162: | ||
class Program | class Program | ||
{ | { | ||
- | static | + | static |
{ | { | ||
- | // | + | try |
- | // Demo of asynchronous methods. | + | |
- | // | + | |
- | var task = Task.Run(async () => | + | |
{ | { | ||
// | // | ||
Řádek 163: | Řádek 171: | ||
// The client is automatically generated from the WSDL file available here: https:// | // The client is automatically generated from the WSDL file available here: https:// | ||
// | // | ||
- | using (HistoryDbAccessClient client = new HistoryDbAccessClient("HistoryAccess", " | + | using (HistoryDbAccessClient client = new HistoryDbAccessClient(HistoryDbAccessClient.EndpointConfiguration.HistoryAccess, |
{ | { | ||
// Authentication credetials in the database. | // Authentication credetials in the database. | ||
Řádek 180: | Řá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[] // | + | rec.Keys = new ESG.Db.Server.Shared.KeyValuePair[] // |
{ | { | ||
- | new KeyValuePair | + | new |
- | new KeyValuePair | + | new |
- | new KeyValuePair | + | new |
- | new KeyValuePair | + | new |
- | new KeyValuePair | + | new |
- | new KeyValuePair | + | new |
}; | }; | ||
Řádek 197: | Řádek 205: | ||
Console.WriteLine(" | Console.WriteLine(" | ||
} | } | ||
- | }); | ||
- | Console.WriteLine(" | ||
- | |||
- | try | ||
- | { | ||
- | task.Wait(); | ||
} | } | ||
catch (Exception exc) | catch (Exception exc) | ||
Řádek 220: | Řádek 222: | ||
+ | <code csharp MervisDb_ReplaceData_Example.cs> | ||
+ | using ESG.Core.Access.Client; | ||
+ | using ESG.Db.Server.Shared; | ||
+ | using ESG.Db.ServerAccess; | ||
+ | using System; | ||
+ | using System.Collections.Generic; | ||
+ | namespace DbClientTest | ||
+ | { | ||
+ | class Program | ||
+ | { | ||
+ | static async Task Main(string[] args) | ||
+ | { | ||
+ | RcWareDbClient dbClient = new RcWareDbClient(false, | ||
+ | dbClient.Credentials = new ESG.Db.Server.Shared.Credentials(" | ||
+ | |||
+ | DateTime utcNow = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)); | ||
+ | |||
+ | ESG.Db.Server.Shared.KeyValuePair[] varKeysNew = new ESG.Db.Server.Shared.KeyValuePair[] | ||
+ | { | ||
+ | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
+ | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
+ | }; | ||
+ | |||
+ | ESG.Db.Server.Shared.KeyValuePair[] varKeys1 = new ESG.Db.Server.Shared.KeyValuePair[] | ||
+ | { | ||
+ | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
+ | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
+ | }; | ||
+ | |||
+ | ESG.Db.Server.Shared.KeyValuePair[] varKeys = varKeys1; | ||
+ | |||
+ | // generate some records | ||
+ | List< | ||
+ | TimeSpan recsLength = TimeSpan.FromMinutes(2); | ||
+ | int recsPerMinute = 4; | ||
+ | |||
+ | Random r = new Random((int)DateTime.UtcNow.Ticks); | ||
+ | double rBase = r.NextDouble() * 10; | ||
+ | |||
+ | for (int i = 0; i < (recsLength.TotalSeconds / 60) * recsPerMinute; | ||
+ | { | ||
+ | recsToSave.Add(new ValueRecord(utcNow - recsLength + TimeSpan.FromMinutes(i * (1.0 / recsPerMinute)), | ||
+ | recsToSave[recsToSave.Count - 1].Keys = varKeys; | ||
+ | recsToSave[recsToSave.Count - 1].Interval = 60 / recsPerMinute; | ||
+ | |||
+ | recsToSave.Add(new ValueRecord(utcNow - recsLength + TimeSpan.FromMinutes(i * (1.0 / recsPerMinute)), | ||
+ | recsToSave[recsToSave.Count - 1].Keys = varKeysNew; | ||
+ | recsToSave[recsToSave.Count - 1].Interval = 60 / recsPerMinute; | ||
+ | } | ||
+ | |||
+ | var res = await dbClient.ReplaceDataAsync(new List< | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
<code csharp MervisDb_GetTransformedData_Example.cs> | <code csharp MervisDb_GetTransformedData_Example.cs> | ||
Řádek 232: | Řádek 289: | ||
class Program | class Program | ||
{ | { | ||
- | static | + | static |
{ | { | ||
// | // | ||
- | // Demo of asynchronous method. | + | // Create access to the real server. |
+ | // Without SSL connections, | ||
+ | // The client is automatically generated from the WSDL file available here: https:// | ||
// | // | ||
- | var task = Task.Run(async () => | + | try |
{ | { | ||
- | // | + | using (HistoryDbAccessClient client = new HistoryDbAccessClient(HistoryDbAccessClient.EndpointConfiguration.HistoryAccess, |
- | // Create access to the real server. | + | |
- | // Without SSL connections, | + | |
- | // The client is automatically generated from the WSDL file available here: https:// | + | |
- | // | + | |
- | using (HistoryDbAccessClient client = new HistoryDbAccessClient("HistoryAccess", " | + | |
{ | { | ||
// Authentication credentials in the database. | // Authentication credentials in the database. | ||
Řádek 251: | Řá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 |
- | new KeyValuePair (false, /*Key*/ " | + | new |
- | new KeyValuePair (false, /*Key*/ " | + | new |
}, | }, | ||
- | new KeyValuePair[] { | + | new |
- | new KeyValuePair (false, /*Key*/ " | + | new |
- | new KeyValuePair (false, /*Key*/ " | + | new |
} | } | ||
}; | }; | ||
Řádek 269: | Řádek 323: | ||
aggregation.IsoPattern = new string[] { " | aggregation.IsoPattern = new string[] { " | ||
aggregation.From = new DateTime(2018, | aggregation.From = new DateTime(2018, | ||
- | aggregation.To = | + | aggregation.To = new DateTime(2018, |
aggregation.TimeZone = @" | aggregation.TimeZone = @" | ||
Řádek 323: | Řádek 377: | ||
} while (variableOffset != -1); | } while (variableOffset != -1); | ||
} | } | ||
- | }); | ||
Console.WriteLine(" | Console.WriteLine(" | ||
- | try | ||
- | { | ||
- | task.Wait(); | ||
} | } | ||
catch (Exception exc) | catch (Exception exc) | ||
Řádek 340: | Řádek 390: | ||
Console.ReadLine(); | Console.ReadLine(); | ||
} | } | ||
- | |||
} | } | ||
} | } |