155 lines
5.0 KiB
C#
155 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using Config.Entities;
|
|
using RestClient;
|
|
using Results.Entities;
|
|
using TBF.Rig.TestMethods.S640Communication;
|
|
|
|
namespace S640TestApp
|
|
{
|
|
public partial class S640TestWnd : Form
|
|
{
|
|
ProcParams procParams;
|
|
S640StartCfg startCfg;
|
|
S640EndCfg endCfg;
|
|
|
|
Test test;
|
|
IList<WaterMeter> waterMeters;
|
|
|
|
|
|
public S640TestWnd()
|
|
{
|
|
InitializeComponent();
|
|
|
|
baseUrlTextBox.Text = "https://api-operations.sensus-emea.com/core/";
|
|
relativeUrlTextBox.Text = "metrology/q2correction/Locations/Wztyp/{0}";
|
|
|
|
test = new Test()
|
|
{
|
|
};
|
|
|
|
waterMeters = new List<WaterMeter>();
|
|
waterMeters.Add(new WaterMeter() { });
|
|
waterMeters.Add(new WaterMeter() { });
|
|
waterMeters.Add(new WaterMeter() { });
|
|
}
|
|
|
|
private void procParamsCfgButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (procParams == null)
|
|
{
|
|
procParams = new ProcParams(true);
|
|
}
|
|
|
|
}
|
|
|
|
private void startCfgButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (startCfg == null)
|
|
{
|
|
startCfg = new S640StartFactory().DefaultConfig() as S640StartCfg;
|
|
}
|
|
|
|
var cfgForm = new TBF.UI.Bench.Components.ComponentParametersDlg(this);
|
|
var cfgControl = startCfg.GetControl(null);
|
|
cfgControl.Config = startCfg;
|
|
cfgControl.Config.ItemNr = 1;
|
|
cfgForm.ComponentCfgCtrl = cfgControl;
|
|
cfgForm.UnlockAfterStart = true;
|
|
|
|
DialogResult dr = cfgForm.ShowDialog();
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void startButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (startCfg == null || procParams == null)
|
|
{
|
|
MessageBox.Show("Not configured");
|
|
}
|
|
|
|
(new S640CommForm(S640Activity.Start, startCfg, procParams, test, waterMeters)).ShowDialog();
|
|
}
|
|
|
|
private void endCfgButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (endCfg == null)
|
|
{
|
|
endCfg = new S640EndFactory().DefaultConfig() as S640EndCfg;
|
|
}
|
|
|
|
var cfgForm = new TBF.UI.Bench.Components.ComponentParametersDlg(this);
|
|
var cfgControl = endCfg.GetControl(null);
|
|
cfgControl.Config = endCfg;
|
|
cfgControl.Config.ItemNr = 1;
|
|
cfgForm.ComponentCfgCtrl = cfgControl;
|
|
cfgForm.UnlockAfterStart = true;
|
|
|
|
DialogResult dr = cfgForm.ShowDialog();
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void endButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (endCfg == null || procParams == null)
|
|
{
|
|
MessageBox.Show("Not configured");
|
|
}
|
|
|
|
(new S640CommForm(S640Activity.End, endCfg, procParams, test, waterMeters)).ShowDialog();
|
|
}
|
|
|
|
private void getButton_Click(object sender, EventArgs e)
|
|
{
|
|
string baseUrl = baseUrlTextBox.Text;
|
|
string relativeUrl = relativeUrlTextBox.Text;
|
|
int wmType = 0;
|
|
int q2PreCorrectionLR;
|
|
int q2PreCorrectionRL;
|
|
|
|
if (string.IsNullOrEmpty(baseUrl) || string.IsNullOrEmpty(relativeUrl) ||
|
|
!int.TryParse(idWzTypTextBox.Text, out wmType) || wmType <= 0)
|
|
{
|
|
MessageBox.Show("Invalid parameter(s)");
|
|
return;
|
|
}
|
|
|
|
/// Get Q2 pre-correction values from REST service
|
|
try
|
|
{
|
|
GetQ2PreCorrectionClient client = new GetQ2PreCorrectionClient(baseUrl);
|
|
client.GetToken("ReadUser", "sensus",
|
|
"https://deluh1web03.world.fluidtechnology.net/SensusCore/api/v1/Locations/1/Login2").Wait();
|
|
string finalRelativeUrl = string.Format(relativeUrl, wmType);
|
|
Q2PreCorrection response = client.GetQ2Correction(finalRelativeUrl).Result;
|
|
if (response != null && response.AreDataCalculated)
|
|
{
|
|
q2PreCorrectionLR = response.CorrLR;
|
|
q2PreCorrectionRL = response.CorrRL;
|
|
MessageBox.Show(string.Format(
|
|
"Q2 corrections from a REST client for WM Type = {0} are: LR = {1}, RL = {2}",
|
|
wmType, q2PreCorrectionLR, q2PreCorrectionRL));
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(string.Format(
|
|
"Failed to obtain Q2 corrections from a REST client for WM Type = {0}", wmType));
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
MessageBox.Show(string.Format(
|
|
"Failed to obtain Q2 corrections from a REST client for WM Type = {0}: {1}",
|
|
wmType, exc.Message));
|
|
}
|
|
}
|
|
}
|
|
}
|