Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Samples/DotNetSdk/DotNetSdkExamples.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29403.142
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObservationValidator", "ObservationValidator\ObservationValidator.csproj", "{4BB8F57C-DD37-4401-85F7-C1B4D97F36C7}"
EndProject
Expand All @@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NWFWMD-LabFileImporter", "N
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObservationReportExporter", "ObservationReportExporter\ObservationReportExporter.csproj", "{8D25D462-6D50-48A1-A5E4-05116EC7B51F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReflectedSeriesAggregator", "ReflectedSeriesAggregator\ReflectedSeriesAggregator.csproj", "{E86145A8-0713-4CF3-9EC2-A955B58C6A3B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -56,6 +58,10 @@ Global
{8D25D462-6D50-48A1-A5E4-05116EC7B51F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D25D462-6D50-48A1-A5E4-05116EC7B51F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D25D462-6D50-48A1-A5E4-05116EC7B51F}.Release|Any CPU.Build.0 = Release|Any CPU
{E86145A8-0713-4CF3-9EC2-A955B58C6A3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E86145A8-0713-4CF3-9EC2-A955B58C6A3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E86145A8-0713-4CF3-9EC2-A955B58C6A3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E86145A8-0713-4CF3-9EC2-A955B58C6A3B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
54 changes: 54 additions & 0 deletions Samples/DotNetSdk/ReflectedSeriesAggregator/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.FileProviders.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Configuration.Binder" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
180 changes: 180 additions & 0 deletions Samples/DotNetSdk/ReflectedSeriesAggregator/AquariusClientHelperExt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
using Aquarius.TimeSeries.Client;
using Aquarius.TimeSeries.Client.ServiceModels.Provisioning;
using Aquarius.TimeSeries.Client.ServiceModels.Publish;
using NodaTime;
using System;
using System.Collections.Generic;
using System.Linq;
using MonitoringMethod = Aquarius.TimeSeries.Client.ServiceModels.Provisioning.MonitoringMethod;

namespace ReflectedSeriesAggregator
{
internal static class AquariusClientHelperExt
{
public static readonly Duration NoGaps = Duration.FromTicks(long.MaxValue);

public class GetOrCreateTimeSeriesResponse
{
public bool IsNew { get; set; }
public Guid UniqueId { get; set; }
public string SeriesIdentifier { get; set; }
}

static public GetOrCreateTimeSeriesResponse GetOrCreateTimeSeries(this IAquariusClient client,
LocationDescription location,
Parameter parameter,
string label,
string methodCode,
bool publish,
Duration gapTolerance,
SeriesCreateType seriesCreateType = SeriesCreateType.Reflected,
Dictionary<string, string> extendedAttributes = null)
{
var timeSeriesDescriptions = GetTimeSeriesDescriptions(client, location.Identifier, parameter.Identifier);

var timeSeriesDescription = timeSeriesDescriptions.FirstOrDefault(ts => ts.Label == label);
if (timeSeriesDescription != null)
return new GetOrCreateTimeSeriesResponse { IsNew = false, UniqueId = timeSeriesDescription.UniqueId, SeriesIdentifier = timeSeriesDescription.Identifier };

Dictionary<string, string> remappedExtendedAttibutesByUniqueId = new Dictionary<string, string>();
if (extendedAttributes != null)
{
var timeseriesExtendedAttributes = new GetExtendedAttributes()
{
Applicability = new List<ExtendedAttributeApplicability>()
{
ExtendedAttributeApplicability.AppliesToTimeSeries
}
};

// Remap extended attributes
var aqExtendedAttributes = client.Provisioning.Get(timeseriesExtendedAttributes).Results;
foreach (var userExtendedAttribute in extendedAttributes)
{
var aqExtendedAttribute = aqExtendedAttributes.Where(a => a.Key.Equals(userExtendedAttribute.Key, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
if (aqExtendedAttribute != null)
remappedExtendedAttibutesByUniqueId.Add(aqExtendedAttribute.UniqueId.ToString("N"), userExtendedAttribute.Value);
}
}

var timeSeries = seriesCreateType == SeriesCreateType.Basic
? client.CreateBasicTimeSeries(location.UniqueId, label, parameter, Offset.FromMilliseconds((int)location.UtcOffset * 60 * 60 * 1000), methodCode, publish, gapTolerance, remappedExtendedAttibutesByUniqueId)
: client.CreateReflectedTimeSeries(location.UniqueId, label, parameter, Offset.FromMilliseconds((int)location.UtcOffset * 60 * 60 * 1000), methodCode, publish, gapTolerance, remappedExtendedAttibutesByUniqueId);

return new GetOrCreateTimeSeriesResponse { IsNew = true, UniqueId = timeSeries.UniqueId, SeriesIdentifier = timeSeries.Identifier };
}

private static Aquarius.TimeSeries.Client.ServiceModels.Provisioning.TimeSeries CreateReflectedTimeSeries(
this IAquariusClient client,
Guid locationUniqueId,
string label,
Parameter parameter,
Offset utcOffset,
string methodCode,
bool publish,
Duration gapTolerance,
Dictionary<string, string> extendedAttributes)
{
return client.Provisioning.Post(
new PostReflectedTimeSeries
{
LocationUniqueId = locationUniqueId,
Parameter = parameter.ParameterId,
Label = label,
Unit = parameter.UnitIdentifier,
InterpolationType = parameter.InterpolationType,
Method = methodCode,
UtcOffset = utcOffset,
Publish = publish,
GapTolerance = gapTolerance,
ExtendedAttributeValues = extendedAttributes?.Select(
x => new ExtendedAttributeValue { UniqueId = x.Key, Value = x.Value }).ToList()
});
}


private static Aquarius.TimeSeries.Client.ServiceModels.Provisioning.TimeSeries CreateBasicTimeSeries(
this IAquariusClient client,
Guid locationUniqueId,
string label,
Parameter parameter,
Offset utcOffset,
string methodCode,
bool publish,
Duration gapTolerance,
Dictionary<string, string> extendedAttributes)
{
return client.Provisioning.Post(
new PostBasicTimeSeries
{
LocationUniqueId = locationUniqueId,
Parameter = parameter.ParameterId,
Label = label,
Unit = parameter.UnitIdentifier,
InterpolationType = parameter.InterpolationType,
Method = methodCode,
Publish = publish,
UtcOffset = utcOffset,
GapTolerance = gapTolerance,
ExtendedAttributeValues = extendedAttributes?.Select(
x => new ExtendedAttributeValue { UniqueId = x.Key, Value = x.Value }).ToList()
});
}

public static List<LocationDescription> GetLocationDescriptions(this IAquariusClient client, List<string> tags) =>
(client.Publish.Get(new LocationDescriptionListServiceRequest
{
TagKeys = tags,
})).LocationDescriptions;


public static List<LocationDescription> GetLocationDescriptions(this IAquariusClient client, string tag = null) => GetLocationDescriptions(client, new List<string> { tag });

public static List<TimeSeriesDescription> GetTimeSeriesDescriptions(this IAquariusClient client, string locationIdentifier,
string parameter = null) =>
client.Publish.Get(new TimeSeriesDescriptionServiceRequest
{
LocationIdentifier = locationIdentifier,
Parameter = parameter
}).TimeSeriesDescriptions;

public static List<TimeSeriesDescription> GetTimeSeriesDescriptionsByTag(this IAquariusClient client, string tag)
{
List<TimeSeriesDescription> timeSeriesDescriptions = new List<TimeSeriesDescription>();
var locations = client.GetLocationDescriptions(tag);
foreach (var location in locations)
timeSeriesDescriptions.AddRange(client.GetTimeSeriesDescriptions(location.Identifier));

return timeSeriesDescriptions;
}

public static TimeSeriesDescription GetTimeSeries(this IAquariusClient client, Guid timeSeriesUniqueId)
{
var ts = client.Provisioning.Get(new GetTimeSeries
{
TimeSeriesUniqueId = timeSeriesUniqueId
});

return GetTimeSeriesDescriptions(client, ts.LocationIdentifier, ts.Parameter).FirstOrDefault(tsd => tsd.Label == ts.Label);
}

private static TimeSeriesType ParseTimeSeriesType(TimeSeriesDescription timeSeriesDescription)
{
return
(TimeSeriesType)
Enum.Parse(typeof(TimeSeriesType), timeSeriesDescription.TimeSeriesType, true);
}

public static List<Parameter> GetParameters(this IAquariusClient client) =>
(client.Provisioning.Get(new GetParameters())).Results;

public static List<MonitoringMethod> GetMonitoringMethods(this IAquariusClient client) => client.Provisioning.Get(
new GetMonitoringMethods()).Results;
}

public enum SeriesCreateType
{
Basic,
Reflected
}
}
77 changes: 77 additions & 0 deletions Samples/DotNetSdk/ReflectedSeriesAggregator/Encryption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Microsoft.Win32;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace ReflectedSeriesAggregator
{
internal class Encryption
{
private static string SecurityKey = ""; // Add your unique security per customer.

public static string EncryptPlainTextToCipherText(string PlainText)
{
if (string.IsNullOrWhiteSpace(SecurityKey))
return PlainText;

// Getting the bytes of Input String.
byte[] toEncryptedArray = UTF8Encoding.UTF8.GetBytes(PlainText);

MD5CryptoServiceProvider objMD5CryptoService = new MD5CryptoServiceProvider();
//Gettting the bytes from the Security Key and Passing it to compute the Corresponding Hash Value.
byte[] securityKeyArray = objMD5CryptoService.ComputeHash(UTF8Encoding.UTF8.GetBytes(SecurityKey));
//De-allocatinng the memory after doing the Job.
objMD5CryptoService.Clear();

var objTripleDESCryptoService = new TripleDESCryptoServiceProvider();
//Assigning the Security key to the TripleDES Service Provider.
objTripleDESCryptoService.Key = securityKeyArray;
//Mode of the Crypto service is Electronic Code Book.
objTripleDESCryptoService.Mode = CipherMode.ECB;
//Padding Mode is PKCS7 if there is any extra byte is added.
objTripleDESCryptoService.Padding = PaddingMode.PKCS7;


var objCrytpoTransform = objTripleDESCryptoService.CreateEncryptor();
//Transform the bytes array to resultArray
byte[] resultArray = objCrytpoTransform.TransformFinalBlock(toEncryptedArray, 0, toEncryptedArray.Length);
objTripleDESCryptoService.Clear();
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}

//This method is used to convert the Encrypted/Un-Readable Text back to readable format.
public static string DecryptCipherTextToPlainText(string CipherText)
{
if (string.IsNullOrWhiteSpace(SecurityKey))
return CipherText;

byte[] toEncryptArray = Convert.FromBase64String(CipherText);
MD5CryptoServiceProvider objMD5CryptoService = new MD5CryptoServiceProvider();

//Gettting the bytes from the Security Key and Passing it to compute the Corresponding Hash Value.
byte[] securityKeyArray = objMD5CryptoService.ComputeHash(UTF8Encoding.UTF8.GetBytes(SecurityKey));
objMD5CryptoService.Clear();

var objTripleDESCryptoService = new TripleDESCryptoServiceProvider();
//Assigning the Security key to the TripleDES Service Provider.
objTripleDESCryptoService.Key = securityKeyArray;
//Mode of the Crypto service is Electronic Code Book.
objTripleDESCryptoService.Mode = CipherMode.ECB;
//Padding Mode is PKCS7 if there is any extra byte is added.
objTripleDESCryptoService.Padding = PaddingMode.PKCS7;

var objCrytpoTransform = objTripleDESCryptoService.CreateDecryptor();
//Transform the bytes array to resultArray
byte[] resultArray = objCrytpoTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
objTripleDESCryptoService.Clear();

//Convert and return the decrypted data/byte into string format.
return UTF8Encoding.UTF8.GetString(resultArray);
}
}
}
41 changes: 41 additions & 0 deletions Samples/DotNetSdk/ReflectedSeriesAggregator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.Extensions.Configuration;
using Serilog;
using System;
using System.IO;

namespace ReflectedSeriesAggregator
{
internal class Program
{
static void Main(string[] args)
{
// Read app settings
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
var configuration = builder.Build();

// Configure & create serilog logger using above configuration
using (var logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger())
{
try
{
// Parse command line
if (!ArgHandler.Parse(args, logger, out Settings settings))
Environment.Exit(0);

// Do some work
new Work(logger, settings).Run();
Environment.Exit(0);
}
catch (Exception ex)
{
logger.Fatal(ex.Message, ex);
Environment.Exit(-1);
}
}
}
}
}
Loading