static void Main(string[] args) { //Invoke Log4Net Helpers.InvokeLog4Net(); //Dynamic Appsettings File for different options string appsetttingsFile = "appsettings.json"; //Argument for appsetting file if (args.Length > 0) { if (args[0] == "help") { WriteLine("Usage -->"); WriteLine("-----------------------"); WriteLine("NetCoreTwinCatXport.exe YOUR APPSETTINGS_FILE.json\n"); WriteLine("------------------------"); WriteLine("otherwise appsettings.json will be used"); WriteLine("------------------------"); return; } appsetttingsFile = args[0]; } Helpers.DebugLogger(appsetttingsFile, true); //Configuration Builder var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile(appsetttingsFile, optional: true, reloadOnChange: true); //Get Json Data via Configuration Builder IConfigurationRoot configuration = null; try { configuration = builder.Build(); } catch (Exception e) { Helpers.DebugLogger(e.Message, true); return; } var xaeFileData = new XaeFileData(); var xaeInterfaceData = new XaeInterfaceData(); try { configuration.GetSection("XaeInterfaceData").Bind(xaeInterfaceData); } catch (Exception e) { Helpers.DebugLogger(e.Message, xaeInterfaceData.debugmode); } //Output Operation Comment Helpers.DebugLogger("------------Operation Comment----------", xaeInterfaceData.debugmode); Helpers.DebugLogger(xaeInterfaceData.operationComment, xaeInterfaceData.debugmode); Helpers.DebugLogger("------------Operation Comment----------", xaeInterfaceData.debugmode); //Start Xae Interface ITcSysManager10 systemManager = XaeInterface.AttachToXae(configuration); if (systemManager == null) { Helpers.DebugLogger("No SystemManager Project Found", xaeInterfaceData.debugmode); return; } //Determine priority and execute - highest prio = 20 for (int prorityLoop = 1; prorityLoop <= 20; prorityLoop++) { //Execute XaeIo DataHandling if (xaeInterfaceData.executeIo == prorityLoop) { XaeIo.DataHandling(configuration, systemManager, xaeInterfaceData.debugmode); } //Execute XaeMapping DataHandling if (xaeInterfaceData.executeMapping == prorityLoop) { XaeMapping.DataHandling(configuration, systemManager, xaeInterfaceData.debugmode); } //Execute XaeMotion DataHandling if (xaeInterfaceData.executeMotion == prorityLoop) { XaeMotion.DataHandling(configuration, systemManager, xaeInterfaceData.debugmode); } //Execute Io Tree if (xaeInterfaceData.executeIoTree == prorityLoop) { XaeIoTree.DataHandling(configuration, systemManager, xaeInterfaceData.debugmode); } //Execute PLC if (xaeInterfaceData.executePlc == prorityLoop) { XaePlc.DataHandling(configuration, systemManager, xaeInterfaceData.debugmode); } } //Activate Actual Configuration if (xaeInterfaceData.activateConfiguration) { XaeSystem.ActivateActualConfiguration(configuration, systemManager, xaeInterfaceData.debugmode); } //Close Solution if (xaeInterfaceData.closeActiveXae) { XaeInterface.CloseSolution(); } //Build Solution if (xaeInterfaceData.buildSolution) { XaeInterface.BuildSolution(false); } }
public static ITcSysManager10 AttachToXae(IConfigurationRoot configuration) { //Get JSon Settings var xaeInterfaceData = new XaeInterfaceData(); try { configuration.GetSection("XaeInterfaceData").Bind(xaeInterfaceData); } catch (Exception e) { Helpers.DebugLogger(e.Message, xaeInterfaceData.debugmode); } //Check ProgID if (xaeInterfaceData.progID == "" || xaeInterfaceData.progID == null) { Helpers.DebugLogger("No/Wrong Program Id in Settingsfile", xaeInterfaceData.debugmode); } //Check ProgID if (xaeInterfaceData.projectSolution == "" || xaeInterfaceData.projectSolution == null) { Helpers.DebugLogger("No/Wrong Projetct in Settingsfile", xaeInterfaceData.debugmode); } //Static Variables string progId = xaeInterfaceData.progID; string projectSolution = xaeInterfaceData.projectSolution; EnvDTE.DTE dte; //Get Program Type Type programType = System.Type.GetTypeFromProgID(progId, true); //Create Xae Instance if (!xaeInterfaceData.attachActiveXae) { Helpers.DebugLogger("Starting new XAE/IDE Instance ...", xaeInterfaceData.debugmode); dte = (EnvDTE.DTE)System.Activator.CreateInstance(programType); Helpers.DebugLogger("DTE Instance started: " + dte.FullName, xaeInterfaceData.debugmode); } //Attaching XAE INstance Helpers.DebugLogger("Attaching XAE/IDE ...", xaeInterfaceData.debugmode); GetRunningObjectTable(); GetIDEInstances(false, progId); dte = AttachToExistingDte(projectSolution, progId, xaeInterfaceData.debugmode); //Parameters if (dte != null) { dte.SuppressUI = false; dte.MainWindow.Visible = true; } else { Helpers.DebugLogger("Error DTE = NUll", xaeInterfaceData.debugmode); return(null); } //Open Solution EnvDTE.Solution activeSolution = dte.Solution; activeSolution.Open(projectSolution); //Wait for Solution Task.Delay(5000).Wait(); //Iterare through project and select right one EnvDTE.Project actualProject = null;; foreach (EnvDTE.Project project in activeSolution.Projects) { Helpers.DebugLogger($"Found Project: {project.Name}", xaeInterfaceData.debugmode); if (project.Name == xaeInterfaceData.projectName) { Helpers.DebugLogger($"Return Project: {project.Name}", xaeInterfaceData.debugmode); actualProject = project; break; } else { Helpers.DebugLogger($"No Project Found", xaeInterfaceData.debugmode); actualProject = null; return(null); } } if (activeSolution.IsOpen) { Helpers.DebugLogger("Solution " + activeSolution.FullName + " IsOpen", xaeInterfaceData.debugmode); } //Wait for MessageFilter Task.Delay(2000).Wait(); //TC SysManageer //ITcSysManager15 systemManager = (ITcSysManager15)actualProject.Object; if (actualProject.Object != null) { return((ITcSysManager10)actualProject.Object); } return(null); }