108 lines
2.3 KiB
C#
108 lines
2.3 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Text.RegularExpressions;
|
|
using System.Windows.Forms;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.Network.RestAPI
|
|
{
|
|
public partial class RestApiCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
RestAPIadapterCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as RestAPIadapterCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public RestApiCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
nameTextBox.Enabled = false;
|
|
textBoxFtpDir.Enabled = false;
|
|
}
|
|
|
|
private void EntryFormCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
if (ParentForm == null) return; /// Return is executed when tab page is open in Designer
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
Localize();
|
|
|
|
Redraw();
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
textBoxFtpDir.Text = config.Path;
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
textBoxFtpDir.Enabled = true;
|
|
}
|
|
|
|
// Define the regex pattern for HTTP or HTTPS URLs
|
|
private static string urlPattern = @"^(http|https):\/\/([a-zA-Z0-9\.-]+)(:[0-9]+)?(\/[a-zA-Z0-9\._\-~]+)*\/?$";
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
// Create regex object
|
|
Regex regex = new Regex(urlPattern);
|
|
|
|
if (!regex.IsMatch(textBoxFtpDir.Text))
|
|
{
|
|
flags = CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'URL'";
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
config.Name = nameTextBox.Text;
|
|
|
|
/// Network adapter
|
|
string strAdapter = textBoxFtpDir.Text;
|
|
int iDash = strAdapter.IndexOf(" - ");
|
|
config.Description = iDash < 0 ? "" : strAdapter.Substring(iDash + 3);
|
|
|
|
config.Path = textBoxFtpDir.Text;
|
|
|
|
return flags;
|
|
}
|
|
|
|
}
|
|
}
|