diff --git a/EgwProxy.Icoel.Test/EgwProxy.Icoel.Test.csproj b/EgwProxy.Icoel.Test/EgwProxy.Icoel.Test.csproj index bf6470c2..981c75ef 100644 --- a/EgwProxy.Icoel.Test/EgwProxy.Icoel.Test.csproj +++ b/EgwProxy.Icoel.Test/EgwProxy.Icoel.Test.csproj @@ -43,11 +43,20 @@ + + + + + PreserveNewest + + + PreserveNewest + diff --git a/EgwProxy.Icoel.Test/INI/BatchDetails.cs b/EgwProxy.Icoel.Test/INI/BatchDetails.cs new file mode 100644 index 00000000..581f3fb5 --- /dev/null +++ b/EgwProxy.Icoel.Test/INI/BatchDetails.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EgwProxy.Icoel.INI +{ + class BatchDetails + { + private const string NameFile = "batch.ini"; + private readonly IniFile _sett; + + + public BatchDetails() + { + _sett = new IniFile(); + } + public string GrowerCode + { + get { return _sett.GetKeyValue("Batch", "GrowerCode"); } + set { _sett.SetKeyValue("Batch", "GrowerCode", value); } + } + + public string GrowerName + { + get { return _sett.GetKeyValue("Batch", "GrowerName"); } + set { _sett.SetKeyValue("Batch", "GrowerName", value); } + } + public string Comment1 + { + get { return _sett.GetKeyValue("Batch", "Comment1"); } + set { _sett.SetKeyValue("Batch", "Comment1", value); } + } + public string Comment2 + { + get { return _sett.GetKeyValue("Batch", "Comment2"); } + set { _sett.SetKeyValue("Batch", "Comment2", value); } + } + public string Comment3 + { + get { return _sett.GetKeyValue("Batch", "Comment3"); } + set { _sett.SetKeyValue("Batch", "Comment3", value); } + } + + public void Load() + { + if (!File.Exists(NameFile)) + { + var fs = File.Create(NameFile); + fs.Close(); + } + _sett.Load(NameFile, false); + } + + public void Save() + { + _sett.Save(NameFile); + } + } +} diff --git a/EgwProxy.Icoel.Test/INI/IniFileCs.cs b/EgwProxy.Icoel.Test/INI/IniFileCs.cs new file mode 100644 index 00000000..5726dc2a --- /dev/null +++ b/EgwProxy.Icoel.Test/INI/IniFileCs.cs @@ -0,0 +1,479 @@ +/* +Date: 08\23\2010 - Ludvik Jerabek - Initial Release +Version: 1.0 +Comment: Allow INI manipulation in .NET +License: CPOL + +Revisions: + +08\23\2010 - Ludvik Jerabek - Initial Release +11\12\2010 - Ludvik Jerabek - Fixed section regex matching on key values with brackets +06\20\2015 - Ludvik Jerabek - Fixed key parsing regex to account for keys with spaces in names + + +**DISCLAIMER** +THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE +EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT +APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY +DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY +USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST +PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON +YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE +EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +*/ + +using System.IO; +using System.Text.RegularExpressions; +using System.Collections; +using System.Diagnostics; +using System; + +// IniFile class used to read and write ini files by loading the file into memory +public class IniFile +{ + // List of IniSection objects keeps track of all the sections in the INI file + private Hashtable m_sections; + + // Public constructor + public IniFile() + { + m_sections = new Hashtable(StringComparer.InvariantCultureIgnoreCase); + } + + // Loads the Reads the data in the ini file into the IniFile object + public void Load(string sFileName ) + { + Load(sFileName, false); + } + + // Loads the Reads the data in the ini file into the IniFile object + public void Load(string sFileName, bool bMerge ) + { + if (!bMerge) + { + RemoveAllSections(); + } + // Clear the object... + IniSection tempsection = null; + StreamReader oReader = new StreamReader(sFileName); + Regex regexcomment = new Regex("^([\\s]*#.*)", (RegexOptions.Singleline | RegexOptions.IgnoreCase)); + Regex regexsection = new Regex("^[\\s]*\\[[\\s]*([^\\[\\s].*[^\\s\\]])[\\s]*\\][\\s]*$", (RegexOptions.Singleline | RegexOptions.IgnoreCase)); + Regex regexkey = new Regex("^\\s*([^=]*[^\\s=])\\s*=(.*)", (RegexOptions.Singleline | RegexOptions.IgnoreCase)); + + while (!oReader.EndOfStream) + { + string line = oReader.ReadLine(); + if (line != string.Empty) + { + Match m = null; + if (regexcomment.Match(line).Success) + { + m = regexcomment.Match(line); + Trace.WriteLine(string.Format("Skipping Comment: {0}", m.Groups[0].Value)); + } + else if (regexsection.Match(line).Success) + { + m = regexsection.Match(line); + Trace.WriteLine(string.Format("Adding section [{0}]", m.Groups[1].Value)); + tempsection = AddSection(m.Groups[1].Value); + } + else if ( regexkey.Match(line).Success && tempsection != null) + { + m = regexkey.Match(line); + Trace.WriteLine(string.Format("Adding Key [{0}]=[{1}]", m.Groups[1].Value, m.Groups[2].Value)); + tempsection.AddKey(m.Groups[1].Value).Value = m.Groups[2].Value; + } + else if ( tempsection != null ) + { + // Handle Key without Value + Trace.WriteLine(string.Format("Adding Key [{0}]", line)); + tempsection.AddKey(line); + } + else + { + // This should not occur unless the tempsection is not created yet... + Trace.WriteLine(string.Format("Skipping unknown type of data: {0}", line)); + } + } + } + oReader.Close(); + } + + // Used to save the data back to the file or your choice + public void Save(string sFileName) + { + StreamWriter oWriter = new StreamWriter(sFileName, false); + foreach (IniSection s in Sections) + { + Trace.WriteLine(string.Format("Writing Section: [{0}]", s.Name)); + oWriter.WriteLine(string.Format("[{0}]", s.Name)); + foreach (IniSection.IniKey k in s.Keys) + { + if (k.Value != string.Empty) + { + Trace.WriteLine(string.Format("Writing Key: {0}={1}", k.Name, k.Value)); + oWriter.WriteLine(string.Format("{0}={1}", k.Name, k.Value)); + } + else + { + Trace.WriteLine(string.Format("Writing Key: {0}", k.Name)); + oWriter.WriteLine(string.Format("{0}", k.Name)); + } + } + } + oWriter.Close(); + } + + // Gets all the sections names + public System.Collections.ICollection Sections + { + get + { + return m_sections.Values; + } + } + + // Adds a section to the IniFile object, returns a IniSection object to the new or existing object + public IniSection AddSection(string sSection ) + { + IniSection s = null; + sSection = sSection.Trim(); + // Trim spaces + if (m_sections.ContainsKey(sSection)) + { + s = (IniSection)m_sections[sSection]; + } + else + { + s = new IniSection(this, sSection); + m_sections[sSection] = s; + } + return s; + } + + // Removes a section by its name sSection, returns trus on success + public bool RemoveSection(string sSection) + { + sSection = sSection.Trim(); + return RemoveSection(GetSection(sSection)); + } + + // Removes section by object, returns trus on success + public bool RemoveSection(IniSection Section) + { + if (Section != null) + { + try + { + m_sections.Remove(Section.Name); + return true; + } + catch( Exception ex ) + { + Trace.WriteLine(ex.Message); + } + } + return false; + } + + // Removes all existing sections, returns trus on success + public bool RemoveAllSections() + { + m_sections.Clear(); + return (m_sections.Count == 0); + } + + // Returns an IniSection to the section by name, NULL if it was not found + public IniSection GetSection(string sSection) + { + sSection = sSection.Trim(); + // Trim spaces + if (m_sections.ContainsKey(sSection)) + { + return (IniSection)m_sections[sSection]; + } + return null; + } + + // Returns a KeyValue in a certain section + public string GetKeyValue(string sSection, string sKey) + { + IniSection s = GetSection(sSection); + if (s != null) + { + IniSection.IniKey k = s.GetKey(sKey); + if (k != null) + { + return k.Value; + } + } + return string.Empty; + } + + // Sets a KeyValuePair in a certain section + public bool SetKeyValue(string sSection, string sKey, string sValue) + { + IniSection s = AddSection(sSection); + if (s != null) + { + IniSection.IniKey k = s.AddKey(sKey); + if (k != null) + { + k.Value = sValue; + return true; + } + } + return false; + } + + // Renames an existing section returns true on success, false if the section didn't exist or there was another section with the same sNewSection + public bool RenameSection(string sSection, string sNewSection) + { + // Note string trims are done in lower calls. + bool bRval = false; + IniSection s = GetSection(sSection); + if (s != null) + { + bRval = s.SetName(sNewSection); + } + return bRval; + } + + // Renames an existing key returns true on success, false if the key didn't exist or there was another section with the same sNewKey + public bool RenameKey(string sSection, string sKey, string sNewKey) + { + // Note string trims are done in lower calls. + IniSection s = GetSection(sSection); + if (s != null) + { + IniSection.IniKey k = s.GetKey(sKey); + if (k != null) + { + return k.SetName(sNewKey); + } + } + return false; + } + + // IniSection class + public class IniSection + { + // IniFile IniFile object instance + private IniFile m_pIniFile; + // Name of the section + private string m_sSection; + // List of IniKeys in the section + private Hashtable m_keys; + + // Constuctor so objects are internally managed + protected internal IniSection(IniFile parent, string sSection) + { + m_pIniFile = parent; + m_sSection = sSection; + m_keys = new Hashtable(StringComparer.InvariantCultureIgnoreCase); + } + + // Returns and hashtable of keys associated with the section + public System.Collections.ICollection Keys + { + get + { + return m_keys.Values; + } + } + + // Returns the section name + public string Name + { + get + { + return m_sSection; + } + } + + // Adds a key to the IniSection object, returns a IniKey object to the new or existing object + public IniKey AddKey(string sKey) + { + sKey = sKey.Trim(); + IniSection.IniKey k = null; + if (sKey.Length != 0) + { + if (m_keys.ContainsKey(sKey)) + { + k = (IniKey)m_keys[sKey]; + } + else + { + k = new IniSection.IniKey(this, sKey); + m_keys[sKey] = k; + } + } + return k; + } + + // Removes a single key by string + public bool RemoveKey(string sKey) + { + return RemoveKey(GetKey(sKey)); + } + + // Removes a single key by IniKey object + public bool RemoveKey(IniKey Key) + { + if (Key != null) + { + try + { + m_keys.Remove(Key.Name); + return true; + } + catch (Exception ex) + { + Trace.WriteLine(ex.Message); + } + } + return false; + } + + // Removes all the keys in the section + public bool RemoveAllKeys() + { + m_keys.Clear(); + return (m_keys.Count == 0); + } + + // Returns a IniKey object to the key by name, NULL if it was not found + public IniKey GetKey(string sKey) + { + sKey = sKey.Trim(); + if (m_keys.ContainsKey(sKey)) + { + return (IniKey)m_keys[sKey]; + } + return null; + } + + // Sets the section name, returns true on success, fails if the section + // name sSection already exists + public bool SetName(string sSection) + { + sSection = sSection.Trim(); + if (sSection.Length != 0) + { + // Get existing section if it even exists... + IniSection s = m_pIniFile.GetSection(sSection); + if (s != this && s != null) return false; + try + { + // Remove the current section + m_pIniFile.m_sections.Remove(m_sSection); + // Set the new section name to this object + m_pIniFile.m_sections[sSection] = this; + // Set the new section name + m_sSection = sSection; + return true; + } + catch (Exception ex) + { + Trace.WriteLine(ex.Message); + } + } + return false; + } + + // Returns the section name + public string GetName() + { + return m_sSection; + } + + // IniKey class + public class IniKey + { + // Name of the Key + private string m_sKey; + // Value associated + private string m_sValue; + // Pointer to the parent CIniSection + private IniSection m_section; + + // Constuctor so objects are internally managed + protected internal IniKey(IniSection parent, string sKey) + { + m_section = parent; + m_sKey = sKey; + } + + // Returns the name of the Key + public string Name + { + get + { + return m_sKey; + } + } + + // Sets or Gets the Value of the key + public string Value + { + get + { + return m_sValue; + } + set + { + m_sValue = value; + } + } + + // Sets the Value of the key + public void SetValue(string sValue) + { + m_sValue = sValue; + } + // Returns the Value of the Key + public string GetValue() + { + return m_sValue; + } + + // Sets the key name + // Returns true on success, fails if the section name sKey already exists + public bool SetName(string sKey) + { + sKey = sKey.Trim(); + if (sKey.Length != 0) + { + IniKey k = m_section.GetKey(sKey); + if (k != this && k != null) return false; + try + { + // Remove the current key + m_section.m_keys.Remove(m_sKey); + // Set the new key name to this object + m_section.m_keys[sKey] = this; + // Set the new key name + m_sKey = sKey; + return true; + } + catch (Exception ex) + { + Trace.WriteLine(ex.Message); + } + } + return false; + } + + // Returns the name of the Key + public string GetName() + { + return m_sKey; + } + } // End of IniKey class + } // End of IniSection class +} // End of IniFile class + + diff --git a/EgwProxy.Icoel.Test/INI/Settaggi.cs b/EgwProxy.Icoel.Test/INI/Settaggi.cs new file mode 100644 index 00000000..f198eddb --- /dev/null +++ b/EgwProxy.Icoel.Test/INI/Settaggi.cs @@ -0,0 +1,70 @@ +using System.IO; + +namespace EgwProxy.Icoel.Test.INI +{ + public class Settaggi + { + #region Public Constructors + + public Settaggi() + { + _sett = new IniFile(); + } + + #endregion Public Constructors + + #region Public Properties + + public string IndirizzoIpSizer + { + get { return _sett.GetKeyValue("Sizer", "IndirizzoIp"); } + set { _sett.SetKeyValue("Sizer", "IndirizzoIp", value); } + } + + public string IndirizzoIpSizerClient + { + get { return _sett.GetKeyValue("Sizer", "IndirizzoIpTracciabilità"); } + set { _sett.SetKeyValue("Sizer", "IndirizzoIpTracciabilità", value); } + } + + public string SizerTcpPort + { + get { return _sett.GetKeyValue("Sizer", "TcpPort"); } + set { _sett.SetKeyValue("Sizer", "TcpPort", value); } + } + + public string TcpPortSizerClient + { + get { return _sett.GetKeyValue("Sizer", "TcpPortTracciabilità"); } + set { _sett.SetKeyValue("Sizer", "TcpPortTracciabilità", value); } + } + + #endregion Public Properties + + #region Public Methods + + public void Load() + { + if (!File.Exists(NameFile)) + { + var fs = File.Create(NameFile); + fs.Close(); + } + _sett.Load(NameFile, false); + } + + public void Save() + { + _sett.Save(NameFile); + } + + #endregion Public Methods + + #region Private Fields + + private const string NameFile = "conf.ini"; + private readonly IniFile _sett; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/EgwProxy.Icoel.Test/Program.cs b/EgwProxy.Icoel.Test/Program.cs index c8b487ab..68936465 100644 --- a/EgwProxy.Icoel.Test/Program.cs +++ b/EgwProxy.Icoel.Test/Program.cs @@ -1,38 +1,243 @@ -using System; +using EgwProxy.Icoel.SizerService; +using EgwProxy.Icoel.Test.INI; +using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using EgwProxy.Icoel; namespace EgwProxy.Icoel.Test { internal class Program { - static void Main(string[] args) + #region Internal Methods + + /// + /// Generazione di una list di info sui dati variety + /// + /// + /// + internal static void DisplayVariety(Variety[] varietyData) { - // ersempio funzionamento connector via console app - // setp 1: legge conf da file ini che si trovano in bin (riportati come conf principali) + foreach (var item in varietyData) + { + Console.WriteLine("--------------------------"); + Console.WriteLine($"Variety Id: {item.Id} | Variety Name: {item.Name}"); + Console.WriteLine(" - Qualities"); + foreach (var quality in item.Qualities) + { + Console.WriteLine($" Name: {quality.Name}"); + } + Console.WriteLine(" - Grades"); + foreach (var grade in item.Grades) + { + Console.WriteLine($" Name: {grade.Name}"); + } + Console.WriteLine(" - Sizes"); + foreach (var size in item.SizingMaps) + { + Console.WriteLine($" Name: {size.Name}"); + } + } + } + + /// + /// Generazione di una list di info sui dati variety + /// + /// + /// + internal static void DisplayVarietyLayout(Dictionary varietyData) + { + foreach (var item in varietyData) + { + Console.WriteLine("--------------------------"); + Console.WriteLine($"Variety Id: {item.Key.Id} | Variety Name: {item.Key.Name}"); + Console.WriteLine(" - Qualities"); + foreach (var quality in item.Key.Qualities) + { + Console.WriteLine($" Name: {quality.Name}"); + } + Console.WriteLine(" - Grades"); + foreach (var grade in item.Key.Grades) + { + Console.WriteLine($" Name: {grade.Name}"); + } + Console.WriteLine(" - Sizes"); + foreach (var size in item.Key.SizingMaps) + { + Console.WriteLine($" Name: {size.Name}"); + } + Console.WriteLine(" - LAYOUTS"); + foreach (var layout in item.Value) + { + Console.WriteLine($" Id: {layout.Id} | Name: {layout.Name}"); + Console.WriteLine(" - Products"); + foreach (var product in layout.Products) + { + Console.WriteLine($" Id: {product.Id} | Name: {product.Name} | DisplayName: {product.DisplayName} | Pack: {product.Pack}"); + } + } + } + } + + /// + /// Mostra elenco variety e quanod utente seleziona restituisce varGuid + /// + /// + internal static Guid selLayout(Connector IcoelSizer, Guid varGuid) + { + int idxLay = -1; + Guid layGuid = Guid.NewGuid(); + + // recupero layout della varietà + var layoutList = IcoelSizer.GetLayoutForVariety(varGuid); + + Console.WriteLine("--------------------"); + Console.WriteLine("Layout disponibili:"); + Console.WriteLine("--------------------"); + DisplayLayout(layoutList); + // recupero layout x varietà + while (idxLay <= 0) + { + Console.WriteLine(""); + Console.WriteLine("indicare layout"); + var rawData = Console.ReadLine(); + if (!string.IsNullOrEmpty(rawData)) + { + int.TryParse(rawData, out idxLay); + // verifico sia valida.. + if (layoutList.Length >= idxLay && idxLay > 0) + { + layGuid = layoutList[idxLay - 1].Id; + } + else + { + idxLay = -1; + } + } + } + return layGuid; + } + + /// + /// Mostra elenco variety e quanod utente seleziona restituisce varGuid + /// + /// + internal static Guid selVariety(Connector IcoelSizer) + { + int idxVar = -1; + Guid varGuid = Guid.NewGuid(); + var varList = IcoelSizer.GetVarietyList(true); + + Console.WriteLine("--------------------"); + Console.WriteLine("Varietà disponibili:"); + Console.WriteLine("--------------------"); + DisplayVariety(varList); + // chiedo di selezionare + while (idxVar <= 0) + { + Console.WriteLine(""); + Console.WriteLine("indicare varietà richiesta (#)"); + var rawData = Console.ReadLine(); + if (!string.IsNullOrEmpty(rawData)) + { + int.TryParse(rawData, out idxVar); + // verifico sia valida.. + if (varList.Length >= idxVar && idxVar > 0) + { + varGuid = varList[idxVar - 1].Id; + } + else + { + idxVar = -1; + } + } + } + return varGuid; + } + + #endregion Internal Methods + + #region Private Methods + + /// + /// Generazione di una list di layout dato elenco + /// + /// + /// + private static void DisplayLayout(Layout[] layoutList) + { + foreach (var layout in layoutList) + { + Console.WriteLine($" Id: {layout.Id} | Name: {layout.Name}"); + Console.WriteLine(" - Products"); + foreach (var product in layout.Products) + { + Console.WriteLine($" Id: {product.Id} | Name: {product.Name} | DisplayName: {product.DisplayName} | Pack: {product.Pack}"); + } + } + } + + /// + /// Programma principale + /// + /// + private static void Main(string[] args) + { + // leggo conf da file ini (ip/port) Console.WriteLine("Loading Files..."); - Connector.Load(); - - // ora effettua lettura Varietà e Layout disponibili + Settaggi setup = new Settaggi(); + setup.Load(); + string userInput = ""; + // oggetto x connessione + Connector IcoelSizer = new Connector(setup.IndirizzoIpSizer, setup.TcpPortSizerClient); + // ora effettua un pò di letture/scritture try { - var varList = Connector.RecuperaVarietyLayout(); - if (varList != null) + Console.WriteLine("------------ TUTTE variety ------------"); + var varList = IcoelSizer.GetVarietyList(false); + var varietyData = IcoelSizer.GetLayoutForVarietyList(varList); + if (varietyData != null) { - Connector.DisplayVarietyLayout(varList); + DisplayVarietyLayout(varietyData); } + Console.WriteLine(); + Console.WriteLine("Premere un tasto x continuare..."); + userInput = Console.ReadLine(); - Connector.VerificaLottoCorrente(); + // solo attive + Console.WriteLine("------------ solo attive ------------"); + varList = IcoelSizer.GetVarietyList(); + varietyData = IcoelSizer.GetLayoutForVarietyList(varList); + if (varietyData != null) + { + DisplayVarietyLayout(varietyData); + } + Console.WriteLine(); + Console.WriteLine("Premere un tasto x continuare..."); + userInput = Console.ReadLine(); - Connector.MettiLottoInCoda(); + Console.WriteLine("------------ BATCH correnti ------------"); + var currBatch = IcoelSizer.GetCurrentBatch(); + foreach (var item in currBatch) + { + string lato = item.Key == 1 ? "SX" : "DX"; + Console.WriteLine($"[{item.Key}-{lato}] Grower code: {item.Value.GrowerCode} | Layout Name: {item.Value.LayoutName} | Totalling: [{item.Value.TotallingVarietyCode}] {item.Value.TotallingVariety} | Sizing: {item.Value.SizingProfileName} | Start {item.Value.StartTime} | End {item.Value.EndTime}"); + } + Console.WriteLine(); + Console.WriteLine("Premere un tasto x continuare..."); + userInput = Console.ReadLine(); - Connector.VerificaLottoCorrente(); + Console.WriteLine("------------ Prova invio BATCH ------------"); + // recupero GUID x variety e layout + var varGuid = selVariety(IcoelSizer); + var layGuid = selLayout(IcoelSizer, varGuid); - Console.WriteLine("Done."); + GrowerInfo GrowerData = new GrowerInfo(); + IcoelSizer.EnqueueBatch(GrowerData, varGuid, layGuid); + + IcoelSizer.GetCurrentBatch(); + + Console.WriteLine("Test completato"); + Console.WriteLine("Premere un tasto x chiudere"); Console.ReadKey(); } catch (Exception ex) @@ -41,5 +246,7 @@ namespace EgwProxy.Icoel.Test Console.ReadKey(); } } + + #endregion Private Methods } -} +} \ No newline at end of file diff --git a/EgwProxy.Icoel.Test/batch.ini b/EgwProxy.Icoel.Test/batch.ini new file mode 100644 index 00000000..a7e6ca86 --- /dev/null +++ b/EgwProxy.Icoel.Test/batch.ini @@ -0,0 +1,6 @@ +[Batch] +GrowerCode=02 +GrowerName=Egalware +Comment1=Prova Invio +Comment2=Console app +Comment3=Selezionato Variety e layout \ No newline at end of file diff --git a/EgwProxy.Icoel.Test/conf.ini b/EgwProxy.Icoel.Test/conf.ini new file mode 100644 index 00000000..ebbeb530 --- /dev/null +++ b/EgwProxy.Icoel.Test/conf.ini @@ -0,0 +1,3 @@ +[Sizer] +IndirizzoIp=192.168.137.50 +TcpPort=8001 \ No newline at end of file diff --git a/EgwProxy.Icoel/Compac/ComClient.cs b/EgwProxy.Icoel/Compac/ComClient.cs index 5e4242bb..e4b0bd56 100644 --- a/EgwProxy.Icoel/Compac/ComClient.cs +++ b/EgwProxy.Icoel/Compac/ComClient.cs @@ -5,7 +5,7 @@ using System.ServiceModel; namespace EgwProxy.Icoel.Compac { - public class ComClient + public class ComClient : IDisposable { #region Public Constructors @@ -17,8 +17,13 @@ namespace EgwProxy.Icoel.Compac /// Porta di connessione del sizer (def: 8001) public ComClient(string sizerIp, string port) { + // Salvo IP e porta + ipAddress = sizerIp; + tcpPort = port; + + // inizializzazione servizio comunicazione var url = "http://" + sizerIp + ":" + port + "/SizerService/"; - var epa = new EndpointAddress(new Uri(url)); + EndpointAddress epa = new EndpointAddress(new Uri(url)); SSClient = new SizerServiceClient("WSHttpBinding_ISizerService", epa); } @@ -46,10 +51,53 @@ namespace EgwProxy.Icoel.Compac #region Public Methods + /// + /// Dispose dell'oggetto + /// + public void Dispose() + { + Close(); + } + + #endregion Public Methods + + #region Internal Properties + + /// + /// Inidirizzo IP + /// + internal string ipAddress { get; set; } = "127.0.0.1"; + + /// + /// Porta del webservice (SOAP) + /// + internal string tcpPort { get; set; } = "8001"; + + #endregion Internal Properties + + #region Internal Methods + + /// + /// Verifica del grower da codice/nome con eventuale creazione se mancante + /// + /// Codice del produttore + /// Denominazione del produttore + internal void CheckGrower(string growerCode, string growerName) + { + var grower = SSClient.GetGrower(growerCode); + + if (grower == null) + { + var nuovo = new Grower() { Code = growerCode, Name = growerName }; + + SSClient.AddGrower(nuovo); + } + } + /// /// Effettua chiusura del proxy di comunicazione /// - public void Close() + internal void Close() { if (SSClient.State != CommunicationState.Closed) { @@ -57,10 +105,6 @@ namespace EgwProxy.Icoel.Compac } } - #endregion Public Methods - - #region Internal Methods - /// /// Elenco dei layout attivi della varietà /// @@ -80,6 +124,15 @@ namespace EgwProxy.Icoel.Compac return SSClient.GetActiveVarieties(); } + /// + /// Elenco varietà (tutte) + /// + /// + internal Variety[] GetAllVarieties() + { + return SSClient.GetAllVarieties(); + } + /// /// Recupera il batch corrente (se monolinea) /// @@ -118,23 +171,6 @@ namespace EgwProxy.Icoel.Compac SSClient.AddBatch(batch); } - /// - /// Verifica del grower da codice/nome - /// - /// Codice del produttore - /// Denominazione del produttore - internal void VerificaEsistenzaGrower(string growerCode, string growerName) - { - var grower = SSClient.GetGrower(growerCode); - - if (grower == null) - { - var nuovo = new Grower() { Code = growerCode, Name = growerName }; - - SSClient.AddGrower(nuovo); - } - } - #endregion Internal Methods #region Private Properties diff --git a/EgwProxy.Icoel/Connector.cs b/EgwProxy.Icoel/Connector.cs index 47949463..b00b7014 100644 --- a/EgwProxy.Icoel/Connector.cs +++ b/EgwProxy.Icoel/Connector.cs @@ -1,289 +1,197 @@ -using BinsTracker.INI; -using EgwProxy.Icoel.Compac; -using EgwProxy.Icoel.INI; +using EgwProxy.Icoel.Compac; using EgwProxy.Icoel.SizerService; using System; +using System.Collections.Generic; namespace EgwProxy.Icoel { - public static class Connector + public class Connector { + #region Public Constructors + + /// + /// Inizializazzione classe con salvataggio ip/porta del webservice del sizer + /// + /// + /// + public Connector(string ipAddress, string tcpPort) + { + this.ipAddress = ipAddress; + this.tcpPort = tcpPort; + } + + #endregion Public Constructors + #region Public Methods - public static void DisplayVarietyLayout(Variety[] varietiesList) + /// + /// Verifica il fornitore e se non ci fosse crea + /// + /// + public void CheckGrower(GrowerInfo GrowerData) { - if (Client == null || !Client.connected) + using (var Client = new ComClient(ipAddress, tcpPort)) { - Client = new ComClient(Settaggi.IndirizzoIpSizer, Settaggi.SizerTcpPort); + Client.CheckGrower(GrowerData.GrowerCode, GrowerData.GrowerName); } - foreach (var item in varietiesList) + } + + /// + /// Invia un lotto in coda produzione sul sizer + /// + /// Batch da accodare + public void EnqueueBatch(GrowerInfo GrowerData, Guid varGuid, Guid layGuid) + { + using (var Client = new ComClient(ipAddress, tcpPort)) { - Console.WriteLine("--------------------------"); - Console.WriteLine($"Variety Id: {item.Id} | Variety Name: {item.Name}"); - Console.WriteLine(" - Qualities"); - foreach (var quality in item.Qualities) + string sizingProfile = Client.GetCurrentBatch().SizingProfileName; + Batch newBatch = CreateBatch(GrowerData, varGuid, layGuid, sizingProfile); + Client.MettiLottoInCoda(newBatch); + } + } + + /// + /// Recupera elenco dei Batch correnti (su L1 SX e L2 DX) + /// + /// + public Dictionary GetCurrentBatch() + { + Dictionary outVal = new Dictionary(); + using (var Client = new ComClient(ipAddress, tcpPort)) + { + //Client.GetCurrentBatch(); + for (int i = 1; i <= 2; i++) { - Console.WriteLine($" Name: {quality.Name}"); + var batch = Client.GetCurrentBatchByLane(i); + outVal.Add(i, batch); } - Console.WriteLine(" - Grades"); - foreach (var grade in item.Grades) + } + return outVal; + } + + /// + /// Restituisce un dictionary di varietà e relativi layout + /// + /// + /// + public Dictionary GetLayoutAndVariety() + { + Dictionary outVal = new Dictionary(); + using (var Client = new ComClient(ipAddress, tcpPort)) + { + Variety[] varietiesList = Client.GetActiveVarieties(); + foreach (var item in varietiesList) { - Console.WriteLine($" Name: {grade.Name}"); - } - Console.WriteLine(" - Sizes"); - foreach (var size in item.SizingMaps) - { - Console.WriteLine($" Name: {size.Name}"); + // recupero layout della varietà + var layoutList = Client.GetLayouts(item.Id); + outVal.Add(item, layoutList); } + } + // restituisco dati + return outVal; + } + + /// + /// Restituisce un array di Layout validi data Guid della Variety + /// + /// + /// + public Layout[] GetLayoutForVariety(Guid varGuid) + { + Layout[] outVal = new Layout[1]; + using (var Client = new ComClient(ipAddress, tcpPort)) + { // recupero layout della varietà - var layoutList = Client.GetLayouts(item.Id); - Console.WriteLine(" - LAYOUTS"); - foreach (var layout in layoutList) + var layoutList = Client.GetLayouts(varGuid); + outVal = layoutList; + } + // restituisco dati + return outVal; + } + + /// + /// Restituisce un dictionary di layout validi x un array di varietà fornito + /// + /// + /// + public Dictionary GetLayoutForVarietyList(Variety[] varietiesList) + { + Dictionary outVal = new Dictionary(); + using (var Client = new ComClient(ipAddress, tcpPort)) + { + foreach (var item in varietiesList) { - Console.WriteLine($" Id: {layout.Id} | Name: {layout.Name}"); - // ciclo su sub info -#if false - Console.WriteLine(" - Assignments"); - foreach (var assign in layout.Assignments) - { - Console.WriteLine($" Key: {assign.Key} | Val: {assign.Value}"); - } -#endif - Console.WriteLine(" - Products"); - foreach (var product in layout.Products) - { - Console.WriteLine($" Id: {product.Id} | Name: {product.Name} | DisplayName: {product.DisplayName} | Pack: {product.Pack}"); - } + // recupero layout della varietà + var layoutList = Client.GetLayouts(item.Id); + outVal.Add(item, layoutList); } } - - // chiudo se fosse rimasto aperto - Client.Close(); + // restituisco dati + return outVal; } - public static void Load() + /// + /// Restituisce elenco delle Variety + /// + /// Solo attive (true) o tutte (false) + /// + public Variety[] GetVarietyList(bool onlyActive = true) { - Settaggi = new Settaggi(); - Details = new BatchDetails(); - - Settaggi.Load(); - Details.Load(); - } - - public static void MettiLottoInCoda() - { - Client = new ComClient(Settaggi.IndirizzoIpSizer, Settaggi.SizerTcpPort); - - Client.VerificaEsistenzaGrower(Details.GrowerCode, Details.GrowerName); - - // recupero varietà x selezione - var varList = Connector.RecuperaVarietyLayout(); - - int idxVar = -1; - int idxLay = -1; - - Guid varGuid = Guid.NewGuid(); - Guid layGuid = Guid.NewGuid(); - - Console.WriteLine("--------------------"); - Console.WriteLine("Varietà disponibili:"); - Console.WriteLine("--------------------"); - DisplayVarietyLayout(varList); - // chiedo di selezionare - while (idxVar <= 0) - { - Console.WriteLine(""); - Console.WriteLine("indicare varietà richiesta (#)"); - var rawData = Console.ReadLine(); - if (!string.IsNullOrEmpty(rawData)) - { - int.TryParse(rawData, out idxVar); - // verifico sia valida.. - if (varList.Length >= idxVar) - { - varGuid = varList[idxVar - 1].Id; - } - else - { - idxVar = -1; - } - } - } - if (Client == null || !Client.connected) - { - Client = new ComClient(Settaggi.IndirizzoIpSizer, Settaggi.SizerTcpPort); - } // recupero layout della varietà - var layoutList = Client.GetLayouts(varGuid); - // recupero layout x varietà - while (idxLay <= 0) - { - Console.WriteLine(""); - Console.WriteLine("indicare layout"); - var rawData = Console.ReadLine(); - if (!string.IsNullOrEmpty(rawData)) - { - int.TryParse(rawData, out idxLay); - // verifico sia valida.. - if (layoutList.Length >= idxLay) - { - layGuid = layoutList[idxLay - 1].Id; - } - else - { - idxLay = -1; - } - } - } - - // compongo batch e metto in coda - var newBatch = GeneraBatchDaSelezione(varGuid, layGuid, Client.GetCurrentBatch().SizingProfileName); - - Client.MettiLottoInCoda(newBatch); - - Client.Close(); - } - - public static void MettiLottoInCodaDefault() - { - Client = new ComClient(Settaggi.IndirizzoIpSizer, Settaggi.SizerTcpPort); - - Client.VerificaEsistenzaGrower(Details.GrowerCode, Details.GrowerName); - - Client.MettiLottoInCoda(GeneraBatchDaFile()); - - Client.Close(); - } - - public static Variety[] RecuperaVarietyLayout() - { - //Client = new CompacClient(Settaggi.IndirizzoIpSizer, Settaggi.SizerTcpPort); - if (Client == null || !Client.connected) - { - Client = new ComClient(Settaggi.IndirizzoIpSizer, Settaggi.SizerTcpPort); - } Variety[] varietiesList; - varietiesList = Client.GetActiveVarieties(); -#if false - foreach (var item in varietiesList) + using (var cClient = new ComClient(ipAddress, tcpPort)) { - Console.WriteLine("--------------------------"); - Console.WriteLine($"Variety Id: {item.Id} | Variety Name: {item.Name}"); - Console.WriteLine(" - Qualities"); - foreach (var quality in item.Qualities) + if (onlyActive) { - Console.WriteLine($" Name: {quality.Name}"); + varietiesList = cClient.GetActiveVarieties(); } - Console.WriteLine(" - Grades"); - foreach (var grade in item.Grades) + else { - Console.WriteLine($" Name: {grade.Name}"); - } - Console.WriteLine(" - Sizes"); - foreach (var size in item.SizingMaps) - { - Console.WriteLine($" Name: {size.Name}"); - } - // recupero layout della varietà - var layoutList = Client.GetLayouts(item.Id); - Console.WriteLine(" - LAYOUTS"); - foreach (var layout in layoutList) - { - Console.WriteLine($" Id: {layout.Id} | Name: {layout.Name}"); - // ciclo su sub info - Console.WriteLine(" - Assignments"); - foreach (var assign in layout.Assignments) - { - Console.WriteLine($" Key: {assign.Key} | Val: {assign.Value}"); - } - Console.WriteLine(" - Products"); - foreach (var product in layout.Products) - { - Console.WriteLine($" Id: {product.Id} | Name: {product.Name} | DisplayName: {product.DisplayName} | Pack: {product.Pack}"); - } + varietiesList = cClient.GetAllVarieties(); } } -#endif - - Client.Close(); - return varietiesList; } - public static void VerificaLottoCorrente() - { - Client = new ComClient(Settaggi.IndirizzoIpSizer, Settaggi.SizerTcpPort); - - //Client.GetCurrentBatch(); - var batch = Client.GetCurrentBatchByLane(1); - Console.WriteLine($"[1-SX] Grower code: {batch.GrowerCode} | Layout Name: {batch.LayoutName} | Totalling: [{batch.TotallingVarietyCode}] {batch.TotallingVariety} | Sizing: {batch.SizingProfileName} | Start {batch.StartTime} | End {batch.EndTime}"); - - batch = Client.GetCurrentBatchByLane(2); - Console.WriteLine($"[2-DX] Grower code: {batch.GrowerCode} | Layout Name: {batch.LayoutName} | Totalling: [{batch.TotallingVarietyCode}] {batch.TotallingVariety} | Sizing: {batch.SizingProfileName} | Start {batch.StartTime} | End {batch.EndTime}"); - - Client.Close(); - } - #endregion Public Methods - #region Internal Properties + #region Private Properties /// - /// Oggetto di connessione client + /// Inidirizzo IP /// - internal static ComClient Client { get; set; } - /// - /// Dettaglio dei batch - /// - internal static BatchDetails Details { get; set; } - /// - /// Parametri di setup - /// - internal static Settaggi Settaggi { get; set; } + private string ipAddress { get; set; } = "127.0.0.1"; - #endregion Internal Properties + /// + /// Porta del webservice (SOAP) + /// + private string tcpPort { get; set; } = "8001"; + + #endregion Private Properties #region Private Methods - private static Batch GeneraBatchDaFile() - { - var batch = new Batch(); - - batch.GrowerCode = Details.GrowerCode; - - batch.AvoidLayoutChange = true; - batch.AvoidSavingOldLayouts = true; - - batch.Comments = new string[3]; - batch.Comments[0] = Details.Comment1; - batch.Comments[1] = Details.Comment2; - batch.Comments[2] = Details.Comment3; - - batch.VarietyId = Client.GetCurrentBatch().VarietyId; - batch.LayoutId = Client.GetCurrentBatch().LayoutId; - batch.SizingProfileName = Client.GetCurrentBatch().SizingProfileName; - - return batch; - } - - private static Batch GeneraBatchDaSelezione(Guid VarietyId, Guid LayoutId, string SizingProfileName) + /// + /// Genera un obj batch dati i parametri necessari + /// + /// + /// + /// + /// + /// + private Batch CreateBatch(GrowerInfo GrowerData, Guid VarietyId, Guid LayoutId, string SizingProfileName) { var batch = new Batch(); batch.AvoidLayoutChange = true; batch.AvoidSavingOldLayouts = true; - batch.GrowerCode = Details.GrowerCode; - batch.Comments = new string[3]; - batch.Comments[0] = Details.Comment1; - batch.Comments[1] = Details.Comment2; - batch.Comments[2] = Details.Comment3; + batch.GrowerCode = GrowerData.GrowerCode; + batch.Comments = new string[GrowerData.Comments.Count]; + batch.Comments = GrowerData.Comments.ToArray(); batch.VarietyId = VarietyId; batch.LayoutId = LayoutId; batch.SizingProfileName = SizingProfileName; - //batch.VarietyId = Client.GetCurrentBatch().VarietyId; - //batch.LayoutId = Client.GetCurrentBatch().LayoutId; - //batch.SizingProfileName = Client.GetCurrentBatch().SizingProfileName; return batch; } diff --git a/EgwProxy.Icoel/EgwProxy.Icoel.csproj b/EgwProxy.Icoel/EgwProxy.Icoel.csproj index b10ce5ca..77e5750a 100644 --- a/EgwProxy.Icoel/EgwProxy.Icoel.csproj +++ b/EgwProxy.Icoel/EgwProxy.Icoel.csproj @@ -54,14 +54,12 @@ + True True Reference.svcmap - - - @@ -70,12 +68,6 @@ - - PreserveNewest - - - PreserveNewest - Designer diff --git a/EgwProxy.Icoel/GrowerInfo.cs b/EgwProxy.Icoel/GrowerInfo.cs new file mode 100644 index 00000000..b3fd979f --- /dev/null +++ b/EgwProxy.Icoel/GrowerInfo.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; + +namespace EgwProxy.Icoel +{ + /// + /// Classe rappresentazione dati del Grower + /// + public class GrowerInfo + { + #region Public Properties + + /// + /// Riga commento 01 + /// + public List Comments { get; set; } = new List() { "Commento 01", "Commento 02", "Commento 01" }; + + /// + /// Codice univoco fornitore + /// + public string GrowerCode { get; set; } = "02"; + + /// + /// Denominazione del fornitore + /// + public string GrowerName { get; set; } = "Egalware"; + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/EgwProxy.Icoel/index.pdf b/EgwProxy.Icoel/index.pdf deleted file mode 100644 index 4f78add4..00000000 Binary files a/EgwProxy.Icoel/index.pdf and /dev/null differ diff --git a/IOB-WIN-NEXT/ExtLib/CndexLinkDotNet.dll b/IOB-WIN-NEXT/ExtLib/CndexLinkDotNet.dll deleted file mode 100644 index d86313f1..00000000 Binary files a/IOB-WIN-NEXT/ExtLib/CndexLinkDotNet.dll and /dev/null differ diff --git a/IOB-WIN-NEXT/ExtLib/Siemens.Sinumerik.Operate.Services.Wrapper.dll b/IOB-WIN-NEXT/ExtLib/Siemens.Sinumerik.Operate.Services.Wrapper.dll deleted file mode 100644 index b8d54cf9..00000000 Binary files a/IOB-WIN-NEXT/ExtLib/Siemens.Sinumerik.Operate.Services.Wrapper.dll and /dev/null differ diff --git a/IOB-WIN-NEXT/ExtLib/Siemens.Sinumerik.Operate.Services.dll b/IOB-WIN-NEXT/ExtLib/Siemens.Sinumerik.Operate.Services.dll deleted file mode 100644 index f00469d5..00000000 Binary files a/IOB-WIN-NEXT/ExtLib/Siemens.Sinumerik.Operate.Services.dll and /dev/null differ diff --git a/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj b/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj index e05a06bd..3d169ebe 100644 --- a/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj +++ b/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj @@ -87,17 +87,20 @@ ..\packages\EasyModbusTCP.5.6.0\lib\net40\EasyModbus.dll - ..\packages\EgwProxy.MultiCncLib.3.6.2205.1913\lib\net40\EgwProxy.MultiCncLib.dll + ..\packages\EgwProxy.MultiCncLib.3.6.2205.1917\lib\EgwProxy.MultiCncLib.dll - ..\packages\EgwProxy.OsaiCncLib.3.6.2205.1913\lib\net40\EgwProxy.OsaiCncLib.dll + ..\packages\EgwProxy.OsaiCncLib.3.6.2205.1917\lib\EgwProxy.OsaiCncLib.dll + + + ..\packages\EgwProxy.OsaiCncLib.3.6.2205.1917\lib\EgwProxy.OsaiCncLib.XmlSerializers.dll False ExtLib\krcc.dll - - ..\packages\MapoSDK.6.14.2204.2115\lib\net40\MapoSDK.dll + + ..\packages\MapoSDK.6.14.2204.2616\lib\MapoSDK.dll ..\packages\MathNet.Numerics.4.15.0\lib\net461\MathNet.Numerics.dll @@ -308,14 +311,10 @@ Always - - Always - - Always diff --git a/IOB-WIN-NEXT/arstcomm.ico b/IOB-WIN-NEXT/arstcomm.ico deleted file mode 100644 index 8dac1124..00000000 Binary files a/IOB-WIN-NEXT/arstcomm.ico and /dev/null differ diff --git a/IOB-WIN-NEXT/packages.config b/IOB-WIN-NEXT/packages.config index 457c3e12..7f3fa7f1 100644 --- a/IOB-WIN-NEXT/packages.config +++ b/IOB-WIN-NEXT/packages.config @@ -2,9 +2,9 @@ - - - + + +