private static bool UpdateCustomization(CommandLineParams o, Session epiSession)
        {
            using (StreamReader sr = new StreamReader($@"{o.ProjectFolder}\Script.cs"))
            {
                var oTrans = new ILauncher(epiSession);
                Ice.Adapters.GenXDataAdapter ad = new Ice.Adapters.GenXDataAdapter(oTrans);
                ad.BOConnect();

                GenXDataImpl i      = (GenXDataImpl)ad.BusinessObject;
                string       script = (sr.ReadToEnd().Replace("public partial class Script", "public class Script").Replace("public static partial class Script", "public static class Script").EscapeXml());
                var          ds     = i.GetByID(o.Company, o.ProductType, o.LayerType, o.CSGCode, o.Key1, o.Key2, o.Key3);
                var          chunk  = ds.XXXDef[0];
                if (chunk.SysRevID != o.Version && o.Version > 0)
                {
                    if (MessageBox.Show("The customization appears to have been updated internally within Epicor, this means that if you continue you may be over-writing some changes made. Would you like to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        return(false);
                    }
                }
                string content = ad.GetDechunkedStringByIDWithCompany(o.Company, o.ProductType, o.LayerType, o.CSGCode, o.Key1, o.Key2, o.Key3);

                string newC = Regex.Replace(content, @"(?=\/\/ \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*)[\s\S]*?(?=<\/PropertyValue>)", script,
                                            RegexOptions.IgnoreCase);
                ad.ChunkNSaveUncompressedStringByID(o.Company, o.ProductType, o.LayerType, o.CSGCode, o.Key1, o.Key2, o.Key3, chunk.Description, chunk.Version, false, newC);
            }
            return(true);
        }
        /// <summary>
        /// Updates Epicor Customization
        /// Deprecated will be replaced shortly.
        /// </summary>
        /// <param name="o"></param>
        /// <param name="epiSession"></param>
        /// <returns></returns>
        private static bool UpdateCustomization(CommandLineParams o, Session epiSession)
        {
            var r = o;

            Log.Information($"Updating Customization. Company: {r.Company}, CGCCode: {r.CSGCode}, Key1: {r.Key1}, Key3:{r.Key2}, Key3: {r.Key3}, LayerType: {r.LayerType}, ProductType: {r.ProductType}");
            using (StreamReader sr = new StreamReader($@"{o.ProjectFolder}\Script.cs"))
            {
                try
                {
                    var oTrans = new ILauncher(epiSession);
                    Ice.Adapters.GenXDataAdapter ad = new Ice.Adapters.GenXDataAdapter(oTrans);
                    ad.BOConnect();

                    GenXDataImpl i      = (GenXDataImpl)ad.BusinessObject;
                    string       script = (sr.ReadToEnd().Replace("public partial class Script", "public class Script").Replace("public static partial class Script", "public static class Script"));
                    var          ds     = i.GetByID(o.Company, o.ProductType, o.LayerType, o.CSGCode, o.Key1, o.Key2, o.Key3);
                    var          chunk  = ds.XXXDef[0];
                    if (chunk.SysRevID != o.Version && o.Version > 0)
                    {
                        if (MessageBox.Show("The customization appears to have been updated internally within Epicor, this means that if you continue you may be over-writing some changes made. Would you like to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            return(false);
                        }
                    }
                    string     content = ad.GetDechunkedStringByIDWithCompany(o.Company, o.ProductType, o.LayerType, o.CSGCode, o.Key1, o.Key2, o.Key3);
                    XDocument  doc     = XDocument.Load(new StringReader(content));
                    XNamespace ns      = "http://tempuri.org/XMLSchema.xsd";
                    var        elList  = doc.Descendants(ns + "PropertyName").ToList().Where(xm => xm.Value == "Script").FirstOrDefault();
                    (elList.NextNode as XElement).Value = script;
                    //string newC = Regex.Replace(content, @"(?=\/\/ \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*)[\s\S]*?(?=<\/PropertyValue>)", script,
                    //RegexOptions.IgnoreCase);
                    ad.ChunkNSaveUncompressedStringByID(o.Company, o.ProductType, o.LayerType, o.CSGCode, o.Key1, o.Key2, o.Key3, chunk.Description, chunk.Version, false, doc.ToString());
                    Log.Information("Customization Updated");
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Failed to Update Customization");
                }
            }
            return(true);
        }
        public static void ExportCustmization(CustomizationDS nds, Ice.Adapters.GenXDataAdapter ad, CommandLineParams o)
        {
            string       s  = ad.GetDechunkedStringByIDWithCompany(o.Company, o.ProductType, o.LayerType, o.Key1, o.Key2, o.Key3);
            StringReader sr = new StringReader(s);

            nds.ReadXml(sr, XmlReadMode.IgnoreSchema);
            sr.Close();
            if (!nds.ExtendedProperties.ContainsKey("Company"))
            {
                nds.ExtendedProperties.Add("Company", o.Company);
            }
            else
            {
                nds.ExtendedProperties["Company"] = o.Company;
            }
            if (!nds.ExtendedProperties.ContainsKey("ProductID"))
            {
                nds.ExtendedProperties.Add("ProductID", o.ProductType);
            }
            else
            {
                nds.ExtendedProperties["ProductID"] = o.ProductType;
            }
            if (!nds.ExtendedProperties.ContainsKey("TypeCode"))
            {
                nds.ExtendedProperties.Add("TypeCode", o.LayerType);
            }
            else
            {
                nds.ExtendedProperties["TypeCode"] = o.LayerType;
            }
            if (!nds.ExtendedProperties.ContainsKey("CGCCode"))
            {
                nds.ExtendedProperties.Add("CGCCode", o.CSGCode);
            }
            else
            {
                nds.ExtendedProperties["CGCCode"] = o.CSGCode;
            }

            if (!nds.ExtendedProperties.ContainsKey("Key1"))
            {
                nds.ExtendedProperties.Add("Key1", o.Key1);
            }
            else
            {
                nds.ExtendedProperties["Key1"] = o.Key1;
            }
            if (!nds.ExtendedProperties.ContainsKey("Key2"))
            {
                nds.ExtendedProperties.Add("Key2", o.Key2);
            }
            else
            {
                nds.ExtendedProperties["Key2"] = o.Key2;
            }
            if (!nds.ExtendedProperties.ContainsKey("Key3"))
            {
                nds.ExtendedProperties.Add("Key3", o.Key3);
            }
            else
            {
                nds.ExtendedProperties["Key3"] = o.Key3;
            }
        }