Files
cms_thermo_active/Step.Client/Config/CMSConfiguration.cs
T
CMS3762\carminatini 2a28a201be Added C# CMS Client
2017-12-01 16:51:09 +01:00

217 lines
5.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CMS_Client.Config
{
public static class CMSConfiguration
{
public static String CustomUrl = "";
public static String FirstUrl = "http://google.it";
public static ushort NCType = 0; /* 0: Demo - 1: Fanuc - 2: Siemens - 3: Osai */
public static ushort IDClient = 0; /* 0: Demo - 1: Fanuc - 2: Siemens - 3: Osai */
public static Color TransparencyKey = Color.Fuchsia;
public static bool HMINcPresent = false;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Read All setup Variables
public static String InitializeSettings()
{
//Setup the first URL
if (String.IsNullOrEmpty(CustomUrl))
{
if (!readFirstUrl(out FirstUrl))
return @"Configuration Error: ""Url"" is not a valid URL";
}
else
FirstUrl = CustomUrl;
//Setup NC Type
if (!readNcPresent(out HMINcPresent))
return @"Configuration Error: ""OpenNcHMI"" is not a valid Boolean Type";
//Setup NC Type
if (!readNCType(out NCType))
return @"Configuration Error: ""NCType"" is not a valid NC Type";
//Setup ID Client
if (!readIdClient(out IDClient))
return @"Configuration Error: ""IDClient"" is not a valid Id of CMS-Client";
//Setup the Transparency Key
if (!readTransparencyKey(out TransparencyKey))
return @"Configuration Error: ""TranspColor"" is not a valid Hex Color";
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region SINGLE_PROPERTY_READS
//Setup the first URL
public static bool readFirstUrl(out String Url)
{
Url = "http://localhost:8080";
//Read the Key
String UrlNew = ConfigurationManager.AppSettings["Url"];
//Check if it's NULL
if (String.IsNullOrWhiteSpace(UrlNew))
return false;
//Check if it a valid URL
try
{
new Uri(UrlNew);
}
catch (Exception)
{
return false;
}
//Returns
Url = UrlNew;
return true;
}
//Setup the Transparency Key
public static bool readTransparencyKey(out Color color)
{
//Default Value
color = Color.Fuchsia;
//Read the Key
String TranspKey = ConfigurationManager.AppSettings["TranspColor"];
//Check if it's NULL
if (String.IsNullOrWhiteSpace(TranspKey))
return false;
//Check if it a valid Color
try
{
color = ColorTranslator.FromHtml(TranspKey);
}
catch (Exception)
{
return false;
}
//Returns
return true;
}
//Setup the Transparency Key
public static bool readNCType(out ushort Type)
{
//Default Value
Type = 0;
//Read the Key
String Stype = ConfigurationManager.AppSettings["NCType"];
//Check if it's NULL
if (String.IsNullOrWhiteSpace(Stype))
return false;
//Check if it a valid NC
try
{
Type = ushort.Parse(Stype);
//Check if it is not valid
if(Type > 3)
return false;
}
catch (Exception)
{
return false;
}
//Returns
return true;
}
//Setup the Transparency Key
public static bool readIdClient(out ushort IdClient)
{
//Default Value
IdClient = 1;
//Read the Key
String Sid = ConfigurationManager.AppSettings["IDClient"];
//Check if it's NULL
if (String.IsNullOrWhiteSpace(Sid))
return false;
//Check if it a valid NC
try
{
IdClient = ushort.Parse(Sid);
//Check if it is not valid
if (IdClient == 0)
return false;
}
catch (Exception)
{
return false;
}
//Returns
return true;
}
//Setup the Transparency Key
public static bool readNcPresent(out bool NcHmiPresent)
{
//Default Value
NcHmiPresent = false;
//Read the Key
String Sid = ConfigurationManager.AppSettings["OpenNcHMI"];
//Check if it's NULL
if (String.IsNullOrWhiteSpace(Sid))
return false;
//Check if it a valid NC
try
{
NcHmiPresent = Boolean.Parse(Sid);
}
catch (Exception)
{
return false;
}
//Returns
return true;
}
#endregion
}
}