133 lines
3.3 KiB
C#
133 lines
3.3 KiB
C#
///
|
|
/// Copyright (c) 2022 Sensus Slovensko a.s.
|
|
///
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.DataEntry.StandartCameraPurchaseOrder
|
|
{
|
|
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public string OcrWorkspace; /// Path to a Cognex workspace file
|
|
public string OcrStream; /// Cognex workspace stream name
|
|
|
|
|
|
public override void InitializeAll()
|
|
{
|
|
OcrWorkspace = string.Empty;
|
|
OcrStream = "default";
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"OCR workspace file",
|
|
"OCR stream",
|
|
};
|
|
public override string ParamName(int i) { return paramNames[i]; }
|
|
public override int ParamsCount() { return paramNames.Length; }
|
|
|
|
public override string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return OcrWorkspace;
|
|
case 1: return OcrStream;
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string str)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: OcrWorkspace = str; return CfgUpdateFlags.None;
|
|
case 1: OcrStream = str; return CfgUpdateFlags.None;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifiy the string representation of the parameter
|
|
/// </summary>
|
|
/// <param name="i">Parameter ID</param>
|
|
/// <param name="str">String representation of the parameter</param>
|
|
/// <param name="message">In case false is returned this is the error messsage to be displayed</param>
|
|
/// <returns>true = parameter OK, false = parameter NOK</returns>
|
|
public bool ValidateParam(int i, string str, out string message)
|
|
{
|
|
message = string.Empty;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
return true;
|
|
case 1:
|
|
if (!string.IsNullOrEmpty(str)) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(ProcParams prms)
|
|
{
|
|
prms.OcrWorkspace = OcrWorkspace;
|
|
prms.OcrStream = OcrStream;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
ProcParams pars = new ProcParams();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public override void UpdateFromDbEntity(ComponentProcedure dbEntity)
|
|
{
|
|
if (dbEntity == null) return;
|
|
try
|
|
{
|
|
ProcParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as ProcParams;
|
|
|
|
procedureParamsEntity = dbEntity;
|
|
componentName = dbEntity.CmpntName;
|
|
procedure = dbEntity.Procedure;
|
|
|
|
if (tmp != null) tmp.CopyContentTo(this);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parameterless constructor initializes the parameters
|
|
/// </summary>
|
|
public ProcParams()
|
|
{
|
|
}
|
|
|
|
public ProcParams(bool initialize)
|
|
{
|
|
if (initialize) InitializeAll();
|
|
}
|
|
|
|
public ProcParams(ComponentProcedure procParamsEntity, string componentName, Procedure procedure)
|
|
{
|
|
this.procedureParamsEntity = procParamsEntity;
|
|
this.componentName = componentName;
|
|
this.procedure = procedure;
|
|
}
|
|
}
|
|
}
|