laatzen/Common/CommonConsole/Program.cs
2024-01-24 17:14:10 +01:00

364 lines
14 KiB
C#

using Newtonsoft.Json;
using OmniPlus;
using OmniPlus.Features;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
namespace CommonConsole
{
public class Program
{
public string Value { get; set; }
public static void Main()
{
var a = new Program() { Value = "test" };
var b = new Program();
a.CopyTo(b);
}
//{
//var time = new Epoch20000101(new byte[] { 0x01, 0xBA, 0xA9, 0x40, 0x2D });
//var connection = new OmniIrdaConnection("COM4");
//connection.Open();
//var commands = new List<byte[]>();
//commands.Add(new byte[] { 0x01 });
//commands.Add(new byte[] { 0x03 });
//commands.Add(new byte[] { 0x05 });
//commands.Add(new byte[] { 0x07 });
//commands.Add(new byte[] { 0x09 });
//commands.Add(new byte[] { 0x0B });
//commands.Add(new byte[] { 0x0D });
//commands.Add(new byte[] { 0x0F });
//commands.Add(new byte[] { 0x11 });
//commands.Add(new byte[] { 0x13 });
//commands.Add(new byte[] { 0x15 });
//commands.Add(new byte[] { 0x17 });
//commands.Add(new byte[] { 0x1F });
//commands.Add(new byte[] { 0x21 });
//commands.Add(new byte[] { 0x25 });
//commands.Add(new byte[] { 0x27 });
//commands.Add(new byte[] { 0x29 });
//commands.Add(new byte[] { 0x2B });
//commands.Add(new byte[] { 0xFD, 0x02 });
//commands.Add(new byte[] { 0xFD, 0x05 });
//commands.Add(new byte[] { 0xFD, 0x06 });
//commands.Add(new byte[] { 0xFD, 0x08 });
//commands.Add(new byte[] { 0xFD, 0x0A });
//commands.Add(new byte[] { 0xFD, 0x0E });
//commands.Add(new byte[] { 0xFD, 0x10 });
//commands.Add(new byte[] { 0xFD, 0x12 });
//commands.Add(new byte[] { 0xFD, 0x14 });
//commands.Add(new byte[] { 0xFD, 0x22 });
//commands.Add(new byte[] { 0xFD, 0x24 });
//commands.Add(new byte[] { 0xFD, 0x26 });
//commands.Add(new byte[] { 0xFD, 0x28 });
//commands.Add(new byte[] { 0xFD, 0x39 });
//commands.Add(new byte[] { 0xFD, 0x3D });
//commands.Add(new byte[] { 0xFD, 0x55 });
//commands.Add(new byte[] { 0xFD, 0x63 });
//commands.Add(new byte[] { 0xFD, 0x7B });
//commands.Add(new byte[] { 0xFD, 0x7E, 0x00 });
//commands.Add(new byte[] { 0xFD, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
//commands.Add(new byte[] { 0xFD, 0x8B });
//commands.Add(new byte[] { 0xFD, 0xA9 });
//commands.Add(new byte[] { 0xFD, 0xAA });
//commands.Add(new byte[] { 0xFD, 0xAC });
//commands.Add(new byte[] { 0xFD, 0xB7 });
//commands.Add(new byte[] { 0xFD, 0xBC });
//commands.Add(new byte[] { 0xFD, 0xC2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
//commands.Add(new byte[] { 0xFD, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
//commands.Add(new byte[] { 0xFD, 0xC4, 0x00 });
//commands.Add(new byte[] { 0xFD, 0xC6 });
//commands.Add(new byte[] { 0xFD, 0xC7 });
//var state = new StringBuilder();
//foreach (var cmd in commands)
//{
// var response = connection.Send(cmd);
// var entry = $"{BitConverter.ToString(cmd)}:{BitConverter.ToString(response)}";
// state.AppendLine(entry);
// Console.WriteLine(entry);
//}
//Console.WriteLine();
//Console.WriteLine(state.Length);
//Console.WriteLine();
//Console.WriteLine(state);
//connection.Close();
//using (var sqlConnection = new SqlConnection("Server=SLASQL01.emea.sensus.net; Database=AuftragKopie; User ID=sa; Password=sqlserver;"))
//{
// sqlConnection.FireInfoMessageEventOnUserErrors = true;
// sqlConnection.InfoMessage += SqlConnection_InfoMessage;
// sqlConnection.Open();
// using (var sqlCommand = sqlConnection.CreateCommand())
// {
// sqlCommand.CommandText = $@"
// INSERT
// INTO [OMNIPlus] ([OmniId], [FactoryID], [ProgrammableID])
// VALUES (@{nameof(omniID)}, @{nameof(factoryID)}, @{nameof(programmableID)})";
// sqlCommand.Parameters.AddWithValue(nameof(omniID), omniID);
// sqlCommand.Parameters.AddWithValue(nameof(factoryID), factoryID);
// sqlCommand.Parameters.AddWithValue(nameof(programmableID), programmableID);
// var rows = sqlCommand.ExecuteNonQuery();
// Console.WriteLine(rows);
// }
//}
//}
/**
results.Add(new byte[] { 0x01 }, new byte[1]);
results.Add(new byte[] { 0x03 }, new byte[1]);
results.Add(new byte[] { 0x05 }, new byte[1]);
results.Add(new byte[] { 0x07 }, new byte[1]);
results.Add(new byte[] { 0x09 }, new byte[1]);
results.Add(new byte[] { 0x0B }, new byte[1]);
results.Add(new byte[] { 0x0D }, new byte[1]);
results.Add(new byte[] { 0x0F }, new byte[1]);
results.Add(new byte[] { 0x11 }, new byte[1]);
results.Add(new byte[] { 0x13 }, new byte[1]);
results.Add(new byte[] { 0x15 }, new byte[1]);
results.Add(new byte[] { 0x17 }, new byte[1]);
results.Add(new byte[] { 0x1F }, new byte[1]);
results.Add(new byte[] { 0x21 }, new byte[1]);
results.Add(new byte[] { 0x25 }, new byte[1]);
results.Add(new byte[] { 0x27 }, new byte[1]);
results.Add(new byte[] { 0x29 }, new byte[1]);
results.Add(new byte[] { 0x2B }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x02 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x05 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x06 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x08 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x0A }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x0E }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x10 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x12 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x14 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x22 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x24 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x26 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x28 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x39 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x3D }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x55 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x63 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x7B }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x7E }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x80 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0x8B }, new byte[1]);
results.Add(new byte[] { 0xFD, 0xA9 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0xAA }, new byte[1]);
results.Add(new byte[] { 0xFD, 0xAC }, new byte[1]);
results.Add(new byte[] { 0xFD, 0xB7 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0xBC }, new byte[1]);
results.Add(new byte[] { 0xFD, 0xC2 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0xC3 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0xC4 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0xC6 }, new byte[1]);
results.Add(new byte[] { 0xFD, 0xC7 }, new byte[1]);
*/
private static void SqlConnection_InfoMessage(object sender, SqlInfoMessageEventArgs args)
{
Console.WriteLine(JsonConvert.SerializeObject(args, Formatting.Indented));
}
//static byte[] GetBytes(this string value)
//{
// var length = 0;
// var bytes = new byte[length];
// if (string.IsNullOrWhiteSpace(value))
// {
// return bytes;
// }
// var tokens = value.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
// if (tokens.Length == 0)
// {
// return bytes;
// }
// length = tokens.Length;
// bytes = new byte[length];
// for (int i = 0; i < length; i++)
// {
// bytes[i] = Convert.ToByte(tokens[i], 16);
// }
// return bytes;
//}
//public static void Main()
//{
// var connection = new OmniIrdaConnection("COM4");
// //var connection = new OmniUniProConnection("COM16");
// connection.Open();
// var response_ = connection.ViewFactorySeal();
// Console.WriteLine(JsonConvert.SerializeObject(response_, Formatting.Indented));
// var registerSettings = new RegisterSettings();
// registerSettings.IntPart = 0;
// registerSettings.Fraction = 34017;
// registerSettings.Size = 6;
// registerSettings.Range = 0;
// registerSettings.VolumePerPulseUnit = 0x00;
// registerSettings.MeterUnits = 0;
// registerSettings.FlowUnits = 0;
// registerSettings.FlowRate = 3;
// registerSettings.FactoryCorrection = 33;
// registerSettings.FieldCorrection = 0x00;
// registerSettings.PulseWeight = 0;
// registerSettings.PulseWidth = 7;
// registerSettings.PulseUpdate = 0;
// var response = connection.Set(registerSettings);
// Console.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
// var settings = connection.ViewRegisterSettings();
// Console.WriteLine(JsonConvert.SerializeObject(settings, Formatting.Indented));
// var readings = connection.ViewReadings();
// Console.WriteLine(JsonConvert.SerializeObject(readings, Formatting.Indented));
// connection.Close();
//}
//public static void Main()
//{
// try
// {
// using (var httpRequestMessage = new HttpRequestMessage())
// {
// var hostName = Dns.GetHostName();
// var ipAddress = Dns
// .GetHostEntry(hostName)
// .AddressList
// .FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork)
// .ToString();
// var content = JsonConvert.SerializeObject(new
// {
// //[Required]
// //public string StationNr { get; set; }
// StationNr = "2024",
// //[Required]
// //public string PCName { get; set; }
// PCName = hostName,
// //[Required]
// //public string IPAddress { get; set; }
// IPAddress = ipAddress,
// //[Required]
// //public string Trace { get; set; }
// Trace = $"CommonConsole.{nameof(Program)}.{nameof(Main)}",
// //[Required]
// //public string Sender { get; set; }
// Sender = "stoyan.zlatev@xylem.com",
// //[Required]
// //public string Subject { get; set; }
// Subject = "test email",
// //[Required]
// //public string Body { get; set; }
// Body = "<h1>It works!</h1>",
// //public bool IsHtml { get; set; }
// IsHtml = true,
// //[Required]
// //public string[] Recipients { get; set; }
// Recipients = new[] { "roland.drabesch@xylem.com" },
// //public string[] CC { get; set; }
// CC = new[] { "roland.drabesch@xylem.com", "stoyan.zlatev@xylem.com" }
// }, Formatting.Indented);
// httpRequestMessage.Content = new StringContent(content);
// httpRequestMessage.Content.Headers.ContentType.MediaType = "application/json";
// httpRequestMessage.Headers.Add("Accept", "application/json");
// httpRequestMessage.Method = HttpMethod.Post;
// httpRequestMessage.RequestUri = new Uri("http://sla12iis01.emea.sensus.net/LaaProductionWeb/api/Send/Email");
// Console.WriteLine(httpRequestMessage);
// using (var httpClient = new HttpClient())
// {
// using (var httpResponseMessage = httpClient.SendAsync(httpRequestMessage).Result)
// {
// Console.WriteLine(httpResponseMessage);
// var response = httpResponseMessage.Content.ReadAsStringAsync().Result;
// Console.WriteLine(response);
// }
// }
// }
// }
// catch (Exception e)
// {
// Console.WriteLine(e);
// }
//}
}
}
/**
* Defaults - aus karton genohmen
* {
* "IntPart": 0,
* "Fraction": 34017,
* "Size": 6,
* "Range": 0,
* "VolumePerPulseUnit": 0,
* "MeterUnits": 4,
* "FlowUnits": 4,
* "FlowRate": 2,
* "FactoryCorrection": 33,
* "FieldCorrection": 0,
* "PulseWeight": 0,
* "PulseWidth": 7,
* "PulseUpdate": 0,
* "Status": 1,
* "Completed": true
* }
* {
* "SensorID": 48,
* "Setting": 48,
* "Include": false,
* "Value": "00000101",
* "Status": 1,
* "Completed": true
* }
*/