コード例 #1
0
        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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        public void DownloadAndSyncDashboard(Session epiSession, CommandLineParams o)
        {
            string file = Path.GetTempFileName();

            using (StreamWriter swLog = new StreamWriter(file))
            {
                swLog.WriteLine("Got in the Function");
                try
                {
                    epiSession["Customizing"] = false;
                    var oTrans             = new ILauncher(epiSession);
                    CustomizationVerify cm = new CustomizationVerify(epiSession);
                    swLog.WriteLine("Customization Verify");
                    string dll = cm.getDllName(o.Key2);
                    swLog.WriteLine("Got Epicor DLL");
                    StringBuilder refds          = new StringBuilder();
                    dynamic       epiBaseForm    = null;
                    dynamic       epiTransaction = null;
                    if (string.IsNullOrEmpty(dll))
                    {
                        dll = "*.UI.*.dll";
                    }


                    Assembly assy = ClientAssemblyRetriever.ForILaunch(oTrans).RetrieveAssembly(dll);
                    swLog.WriteLine("Finding File");
                    string s = "";

                    s = assy.Location;
                    var typeE     = assy.DefinedTypes.Where(r => r.FullName.ToUpper().Contains(o.Key2.ToUpper())).FirstOrDefault();
                    var typeTList = assy.DefinedTypes.Where(r => r.BaseType.Name.Equals("EpiTransaction")).ToList();

                    epiTransaction = new EpiTransaction(oTrans);



                    refds.AppendLine($"<Reference Include=\"{typeE.Assembly.FullName}\">");
                    refds.AppendLine($"<HintPath>{s}</HintPath>");
                    refds.AppendLine($"</Reference>");


                    var     typ      = assy.DefinedTypes.Where(r => r.Name == "Launch").FirstOrDefault();
                    dynamic launcher = Activator.CreateInstance(typ);
                    launcher.Session = epiSession;
                    launcher.GetType().GetMethod("InitializeLaunch", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(launcher, null);

                    epiBaseForm = launcher.GetType().GetField("lForm", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(launcher);
                    swLog.WriteLine("Initialize EpiUI Utils");
                    EpiUIUtils eu = epiBaseForm.GetType().GetField("utils", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(epiBaseForm);
                    eu.GetType().GetField("currentSession", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(eu, epiTransaction.Session);
                    eu.GetType().GetField("customizeName", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(eu, o.Key1);
                    eu.GetType().GetField("baseExtentionName", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(eu, o.Key3.Replace("BaseExtension^", string.Empty));
                    eu.ParentForm = epiBaseForm;
                    swLog.WriteLine("Get composite Customize Data Set");
                    var  mi        = eu.GetType().GetMethod("getCompositeCustomizeDataSet", BindingFlags.Instance | BindingFlags.NonPublic);
                    bool customize = false;
                    mi.Invoke(eu, new object[] { o.Key2, customize, customize, customize });
                    Ice.Adapters.GenXDataAdapter ad = new Ice.Adapters.GenXDataAdapter(epiTransaction);
                    ad.BOConnect();
                    GenXDataImpl i = (GenXDataImpl)ad.BusinessObject;
                    swLog.WriteLine("Customization Get By ID");
                    var             ds     = i.GetByID(o.Company, o.ProductType, o.LayerType, o.CSGCode, o.Key1, o.Key2, o.Key3);
                    string          beName = o.Key3.Replace("BaseExtension^", string.Empty);
                    string          exName = (string)eu.GetType().GetField("extensionName", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(eu);
                    CustomizationDS nds    = new CustomizationDS();


                    if (string.IsNullOrEmpty(o.Company))
                    {
                        eu.CustLayerMan.GetType().GetProperty("RetrieveFromCache", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).SetValue(eu.CustLayerMan, false);
                        eu.CustLayerMan.GetType().GetField("custAllCompanies", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).SetValue(eu.CustLayerMan, string.IsNullOrEmpty(o.Company));
                        eu.CustLayerMan.GetType().GetField("selectCompCode", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).SetValue(eu.CustLayerMan, o.Company);
                        eu.CustLayerMan.GetType().GetField("companyCode", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).SetValue(eu.CustLayerMan, o.Company);
                        eu.CustLayerMan.GetType().GetField("loadDeveloperMode", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).SetValue(eu.CustLayerMan, string.IsNullOrEmpty(o.Company));

                        bool cancel = false;
                        eu.CustLayerMan.GetType().GetMethod("GetCompositeCustomDataSet", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).Invoke(eu.CustLayerMan, new object[] { o.Key2, exName, o.Key1, cancel });
                    }


                    PersonalizeCustomizeManager csm = new PersonalizeCustomizeManager(epiBaseForm, epiTransaction, o.ProductType, o.Company, beName, exName, o.Key1, eu.CustLayerMan, DeveloperLicenseType.Partner, LayerType.Customization);

                    swLog.WriteLine("Init Custom Controls");
                    csm.InitCustomControlsAndProperties(ds, LayerName.CompositeBase, true);
                    CustomScriptManager csmR = csm.CurrentCustomScriptManager;
                    swLog.WriteLine("Generate Refs");
                    List <string> aliases = new List <string>();
                    Match         match   = Regex.Match(csmR.CustomCodeAll, "((?<=extern alias )(.*)*(?=;))");
                    while (match.Success)
                    {
                        aliases.Add(match.Value.Replace("_", ".").ToUpper());
                        match = match.NextMatch();
                    }
                    o.Version = ds.XXXDef[0].SysRevID;
                    GenerateRefs(refds, csmR, o, null);
                    ExportCustmization(nds, ad, o);
                    Resync(o, swLog, refds, ds, nds, csmR);



                    epiBaseForm.Dispose();


                    ad.Dispose();
                    cm = null;
                    eu.CloseCacheRespinSplash();
                    eu.Dispose();
                }
                catch (Exception ee)
                {
                    swLog.WriteLine(ee.ToString());
                }
            }


            //MessageBox.Show(file);
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
        public void DownloadAndSync(Session epiSession, CommandLineParams o)
        {
            string file = Path.GetTempFileName();

            using (StreamWriter swLog = new StreamWriter(file))
            {
                swLog.WriteLine("Got in the Function");
                try
                {
                    epiSession["Customizing"] = false;
                    var oTrans             = new ILauncher(epiSession);
                    CustomizationVerify cm = new CustomizationVerify(epiSession);
                    swLog.WriteLine("Customization Verify");
                    string dll = cm.getDllName(o.Key2);
                    swLog.WriteLine("Got Epicor DLL");
                    StringBuilder refds          = new StringBuilder();
                    dynamic       epiBaseForm    = null;
                    dynamic       epiTransaction = null;
                    if (string.IsNullOrEmpty(dll))
                    {
                        dll = "*.UI.*.dll";
                    }


                    Assembly assy = ClientAssemblyRetriever.ForILaunch(oTrans).RetrieveAssembly(dll);
                    swLog.WriteLine("Finding File");
                    string s = "";
                    if (assy == null)
                    {
                        foreach (string x in Directory.GetFiles(o.EpicorClientFolder, dll))
                        {
                            assy = Assembly.LoadFile(x);
                            if (assy.DefinedTypes.Where(r => r.FullName.ToUpper().Contains(o.Key2.ToUpper())).Any())
                            {
                                s = x;
                                break;
                            }
                        }
                    }
                    s = assy.Location;
                    var typeE = assy.DefinedTypes.Where(r => r.FullName.ToUpper().Contains(o.Key2.ToUpper())).FirstOrDefault();

                    var typeTList = assy.DefinedTypes.Where(r => r.BaseType.Name.Equals("EpiTransaction") || r.BaseType.Name.Equals("EpiMultiViewTransaction") || r.BaseType.Name.Equals("EpiSingleViewTransaction") || r.BaseType.Name.Equals("UDMultiViewTransaction") || r.BaseType.Name.Equals("UDSingleViewTransaction")).ToList();
                    if (typeTList != null && typeTList.Count > 0)
                    {
                        foreach (var typeT in typeTList)
                        {
                            try
                            {
                                if (typeT != null)
                                {
                                    epiTransaction = Activator.CreateInstance(typeT, new object[] { oTrans });
                                }
                                else
                                {
                                    epiTransaction = new EpiTransaction(oTrans);
                                }

                                epiBaseForm = Activator.CreateInstance(typeE, new object[] { epiTransaction });
                                break;
                            }
                            catch (Exception e)
                            { }
                        }
                    }
                    else
                    {
                        epiTransaction = new EpiTransaction(oTrans);
                        epiBaseForm    = Activator.CreateInstance(typeE, new object[] { epiTransaction });
                    }



                    epiBaseForm.IsVerificationMode = true;
                    epiBaseForm.CustomizationName  = o.Key1;


                    refds.AppendLine($"<Reference Include=\"{typeE.Assembly.FullName}\">");
                    refds.AppendLine($"<HintPath>{s}</HintPath>");
                    refds.AppendLine($"</Reference>");


                    swLog.WriteLine("Initialize EpiUI Utils");


                    EpiUIUtils eu = new EpiUIUtils(epiBaseForm, epiTransaction, epiBaseForm.MainToolManager, null);
                    eu.GetType().GetField("currentSession", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(eu, epiTransaction.Session);
                    eu.GetType().GetField("customizeName", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(eu, o.Key1);
                    eu.GetType().GetField("baseExtentionName", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(eu, o.Key3.Replace("BaseExtension^", string.Empty));

                    swLog.WriteLine("Get composite Customize Data Set");

                    var  mi        = eu.GetType().GetMethod("getCompositeCustomizeDataSet", BindingFlags.Instance | BindingFlags.NonPublic);
                    bool customize = false;
                    mi.Invoke(eu, new object[] { o.Key2, customize, customize, customize });

                    Ice.Adapters.GenXDataAdapter ad = new Ice.Adapters.GenXDataAdapter(epiTransaction);
                    ad.BOConnect();
                    GenXDataImpl i = (GenXDataImpl)ad.BusinessObject;
                    swLog.WriteLine("Customization Get By ID");
                    var             ds     = i.GetByID(o.Company, o.ProductType, o.LayerType, o.CSGCode, o.Key1, o.Key2, o.Key3);
                    string          beName = o.Key3.Replace("BaseExtension^", string.Empty);
                    string          exName = (string)eu.GetType().GetField("extensionName", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(eu);
                    CustomizationDS nds    = new CustomizationDS();
                    if (string.IsNullOrEmpty(o.Company))
                    {
                        eu.CustLayerMan.GetType().GetProperty("RetrieveFromCache", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).SetValue(eu.CustLayerMan, false);
                        eu.CustLayerMan.GetType().GetField("custAllCompanies", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).SetValue(eu.CustLayerMan, string.IsNullOrEmpty(o.Company));
                        eu.CustLayerMan.GetType().GetField("selectCompCode", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).SetValue(eu.CustLayerMan, o.Company);
                        eu.CustLayerMan.GetType().GetField("companyCode", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).SetValue(eu.CustLayerMan, o.Company);
                        eu.CustLayerMan.GetType().GetField("loadDeveloperMode", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).SetValue(eu.CustLayerMan, string.IsNullOrEmpty(o.Company));

                        bool cancel = false;
                        eu.CustLayerMan.GetType().GetMethod("GetCompositeCustomDataSet", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).Invoke(eu.CustLayerMan, new object[] { o.Key2, exName, o.Key1, cancel });
                    }



                    PersonalizeCustomizeManager csm = new PersonalizeCustomizeManager(epiBaseForm, epiTransaction, o.ProductType, o.Company, beName, exName, o.Key1, eu.CustLayerMan, DeveloperLicenseType.Partner, LayerType.Customization);
                    swLog.WriteLine("Init Custom Controls");
                    csm.InitCustomControlsAndProperties(ds, LayerName.CompositeBase, true);
                    CustomScriptManager csmR = csm.CurrentCustomScriptManager;
                    swLog.WriteLine("Generate Refs");


                    GenerateRefs(refds, csmR, o, null);
                    ExportCustmization(nds, ad, o);
                    Resync(o, swLog, refds, ds, nds, csmR);

                    epiBaseForm.Dispose();


                    ad.Dispose();
                    cm = null;
                    eu.CloseCacheRespinSplash();
                    eu.Dispose();
                }
                catch (Exception ee)
                {
                    swLog.WriteLine(ee.ToString());
                }
            }

            Console.WriteLine(o.ProjectFolder);
            //MessageBox.Show(file);
        }
コード例 #6
0
        private static void DownloadAndSync(Session epiSession, CommandLineParams o)
        {
            string file = Path.GetTempFileName();

            using (StreamWriter swLog = new StreamWriter(file))
            {
                swLog.WriteLine("Got in the Function");
                try
                {
                    epiSession["Customizing"] = false;
                    var oTrans             = new ILauncher(epiSession);
                    CustomizationVerify cm = new CustomizationVerify(epiSession);
                    swLog.WriteLine("Customization Verify");
                    string dll = cm.getDllName(o.Key2);
                    swLog.WriteLine("Got Epicor DLL");
                    StringBuilder refds          = new StringBuilder();
                    dynamic       epiBaseForm    = null;
                    dynamic       epiTransaction = null;
                    if (string.IsNullOrEmpty(dll))
                    {
                        dll = "*.UI.*.dll";
                    }


                    Assembly assy = ClientAssemblyRetriever.ForILaunch(oTrans).RetrieveAssembly(dll);
                    swLog.WriteLine("Finding File");
                    string s = "";
                    if (assy == null)
                    {
                        foreach (string x in Directory.GetFiles(o.EpicorClientFolder, dll))
                        {
                            assy = Assembly.LoadFile(x);
                            if (assy.DefinedTypes.Where(r => r.FullName.ToUpper().Contains(o.Key2.ToUpper())).Any())
                            {
                                s = x;
                                break;
                            }
                        }
                    }
                    s = assy.Location;
                    var typeE = assy.DefinedTypes.Where(r => r.FullName.ToUpper().Contains(o.Key2.ToUpper())).FirstOrDefault();

                    var typeTList = assy.DefinedTypes.Where(r => r.BaseType.Name.Equals("EpiTransaction") || r.BaseType.Name.Equals("EpiMultiViewTransaction") || r.BaseType.Name.Equals("EpiSingleViewTransaction") || r.BaseType.Name.Equals("UDMultiViewTransaction") || r.BaseType.Name.Equals("UDSingleViewTransaction")).ToList();
                    if (typeTList != null && typeTList.Count > 0)
                    {
                        foreach (var typeT in typeTList)
                        {
                            try
                            {
                                if (typeT != null)
                                {
                                    epiTransaction = Activator.CreateInstance(typeT, new object[] { oTrans });
                                }
                                else
                                {
                                    epiTransaction = new EpiTransaction(oTrans);
                                }

                                epiBaseForm = Activator.CreateInstance(typeE, new object[] { epiTransaction });
                                break;
                            }
                            catch (Exception e)
                            { }
                        }
                    }
                    else
                    {
                        epiTransaction = new EpiTransaction(oTrans);
                        epiBaseForm    = Activator.CreateInstance(typeE, new object[] { epiTransaction });
                    }

                    bool dashboard = false;
                    try
                    {
                        epiBaseForm.IsVerificationMode = true;
                        epiBaseForm.CustomizationName  = o.Key1;
                    }
                    catch (Exception) {
                        //Dashboard
                        dashboard = true;
                    }

                    refds.AppendLine($"<Reference Include=\"{typeE.Assembly.FullName}\">");
                    refds.AppendLine($"<HintPath>{s}</HintPath>");
                    refds.AppendLine($"</Reference>");
                    if (dashboard)
                    {
                        //epiBaseForm.GetType().GetMethod("InitializeLaunch", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(epiBaseForm);
                        var     typ      = assy.DefinedTypes.Where(r => r.Name == "Launch").FirstOrDefault();
                        dynamic launcher = Activator.CreateInstance(typ);
                        launcher.Session = epiSession;
                        launcher.GetType().GetMethod("InitializeLaunch", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(launcher, null);
                    }

                    swLog.WriteLine("Initialize EpiUI Utils");
                    EpiUIUtils eu = new EpiUIUtils(epiBaseForm, epiTransaction, epiBaseForm.MainToolManager, null);
                    eu.GetType().GetField("currentSession", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(eu, epiTransaction.Session);
                    eu.GetType().GetField("customizeName", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(eu, o.Key1);
                    eu.GetType().GetField("baseExtentionName", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(eu, o.Key3.Replace("BaseExtension^", string.Empty));

                    swLog.WriteLine("Get composite Customize Data Set");
                    var  mi        = eu.GetType().GetMethod("getCompositeCustomizeDataSet", BindingFlags.Instance | BindingFlags.NonPublic);
                    bool customize = false;
                    mi.Invoke(eu, new object[] { o.Key2, customize, customize, customize });
                    Ice.Adapters.GenXDataAdapter ad = new Ice.Adapters.GenXDataAdapter(epiTransaction);
                    ad.BOConnect();
                    GenXDataImpl i = (GenXDataImpl)ad.BusinessObject;
                    swLog.WriteLine("Customization Get By ID");
                    var                         ds     = i.GetByID(o.Company, o.ProductType, o.LayerType, o.CSGCode, o.Key1, o.Key2, o.Key3);
                    string                      beName = o.Key3.Replace("BaseExtension^", string.Empty);
                    string                      exName = (string)eu.GetType().GetField("extensionName", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(eu);
                    CustomizationDS             nds    = new CustomizationDS();
                    PersonalizeCustomizeManager csm    = new PersonalizeCustomizeManager(epiBaseForm, epiTransaction, o.ProductType, o.Company, beName, exName, o.Key1, eu.CustLayerMan, DeveloperLicenseType.Partner, LayerType.Customization);
                    swLog.WriteLine("Init Custom Controls");
                    csm.InitCustomControlsAndProperties(ds, LayerName.CompositeBase, true);
                    CustomScriptManager csmR = csm.CurrentCustomScriptManager;
                    swLog.WriteLine("Generate Refs");

                    /*List<string> aliases = new List<string>();
                     * Match match =Regex.Match(csmR.CustomCodeAll, "((?<=extern alias )(.*)*(?=;))");
                     * while(match.Success)
                     * {
                     *  aliases.Add(match.Value.Replace("_",".").ToUpper());
                     *  match =match.NextMatch();
                     * }*/

                    GenerateRefs(refds, csmR, o, null);
                    ExportCustmization(nds, ad, o);
                    int    start = csmR.CustomCodeAll.IndexOf("// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **");
                    int    end   = csmR.CustomCodeAll.Length - start;
                    string allCode;
                    string script;
                    allCode = csmR.CustomCodeAll.Replace(csmR.CustomCodeAll.Substring(start, end), "}").Replace("public class Script", "public partial class Script").Replace("public static class Script", "public static partial class Script");
                    script  = csmR.Script.Replace("public class Script", "public partial class Script");
                    script  = script.Replace("public static class Script", "public static partial class Script");
                    swLog.WriteLine("Write Project");
                    string projectFile = Resource.BasicProjc;
                    projectFile = projectFile.Replace("<CUSTID>", o.Key1);
                    projectFile = projectFile.Replace("<!--<ReferencesHere>-->", refds.ToString());
                    o.Version   = ds.XXXDef[0].SysRevID;

                    swLog.WriteLine("Create Folder");
                    if (string.IsNullOrEmpty(o.ProjectFolder))
                    {
                        string origFolderName = ($@"{o.Folder}\{o.Key2}_{ o.Key1}").Replace('.', '_');
                        string newFolderName  = origFolderName;
                        int    ct             = 0;
                        while (Directory.Exists(newFolderName))
                        {
                            newFolderName = ($"{origFolderName}_{++ct}").Replace('.', '_');
                        }
                        o.ProjectFolder = newFolderName;
                        Directory.CreateDirectory(o.ProjectFolder);
                    }


                    using (StreamWriter sw = new StreamWriter($@"{o.ProjectFolder}\{o.Key1}.csproj"))
                    {
                        sw.Write(projectFile);
                        sw.Close();
                    }
                    swLog.WriteLine("Write Script");
                    using (StreamWriter sw = new StreamWriter($@"{o.ProjectFolder}\Script.cs"))
                    {
                        sw.Write(script);
                        sw.Close();
                    }

                    swLog.WriteLine("Write ScriptRO");
                    using (StreamWriter sw = new StreamWriter($@"{o.ProjectFolder}\ScriptReadOnly.cs"))
                    {
                        sw.Write(allCode);
                        sw.Close();
                    }

                    swLog.WriteLine("Write Command");
                    string command = Newtonsoft.Json.JsonConvert.SerializeObject(o);
                    using (StreamWriter sw = new StreamWriter($@"{o.ProjectFolder}\CustomizationInfo.json"))
                    {
                        sw.Write(command);
                        sw.Close();
                    }

                    File.SetAttributes($@"{o.ProjectFolder}\ScriptReadOnly.cs", File.GetAttributes($@"{o.ProjectFolder}\ScriptReadOnly.cs") & ~FileAttributes.ReadOnly);
                    swLog.WriteLine("Write Customization");
                    nds.WriteXml($@"{o.ProjectFolder}\{o.Key2}_Customization_{o.Key1}_CustomExport.xml", XmlWriteMode.WriteSchema);



                    epiBaseForm.Dispose();


                    ad.Dispose();
                    cm = null;

                    eu.Dispose();
                }
                catch (Exception ee)
                {
                    swLog.WriteLine(ee.ToString());
                }
            }

            Console.WriteLine(o.ProjectFolder);
            //MessageBox.Show(file);
        }