コード例 #1
0
        /// <summary>
        /// Sets up the adapters
        /// </summary>
        /// <param name="adapterPath"></param>
        private void SetupServices(string adapterPath, string mmuPath, string servicePath)
        {
            //Setup the services
            foreach (string folderPath in Directory.GetDirectories(servicePath))
            {
                //Find the description file
                string descriptionFile = Directory.GetFiles(folderPath).ToList().Find(s => s.Contains("description.json"));

                //Skip if no description file
                if (descriptionFile == null)
                {
                    continue;
                }


                //Get the ExecutableDescription of the service
                MExecutableDescription executableDescription = Serialization.FromJsonString <MExecutableDescription>(File.ReadAllText(descriptionFile));
                string executableFile = Directory.GetFiles(folderPath).ToList().Find(s => s.Contains(executableDescription.ExecutableName));

                port = NetworkAdapters.getNextAvailablePort(port, this.settings.MaxPort);
                if (port == -1)
                {
                    System.Windows.MessageBox.Show("No ports are available to start service or adapters.", "Network error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                ExecutableController exeController = new ExecutableController(executableDescription, new MIPAddress(RuntimeData.MMIRegisterAddress.Address, port), RuntimeData.MMIRegisterAddress, mmuPath, executableFile, settings.HideWindows);

                RuntimeData.ExecutableControllers.Add(exeController);
            }
        }
コード例 #2
0
        /// <summary>
        /// Setups the environment and starts the modules
        /// </summary>
        /// <param name="adapterPath">The path of the modules</param>
        /// <param name="mmuPath">The path of the mmus</param>
        private void SetupEnvironment(string adapterPath, string mmuPath, string servicePath)
        {
            port = settings.MinPort - 1; //on the first use the port number is incremented so we don't want to skip the actual first port specified in the settings, thus -1
            //Set the running flag to true
            this.running = true;

            //Fetch all modules and start them
            foreach (string folderPath in Directory.GetDirectories(adapterPath))
            {
                //Find the description file
                string descriptionFile = Directory.GetFiles(folderPath).ToList().Find(s => s.Contains("description.json"));

                //Skip if no description file
                if (descriptionFile == null)
                {
                    continue;
                }

                //Get the ExecutableDescription of the adapter
                MExecutableDescription executableDescription = Serialization.FromJsonString <MExecutableDescription>(File.ReadAllText(descriptionFile));

                //Determine the filename of the executable file
                string executableFile = Directory.GetFiles(folderPath).ToList().Find(s => s.Contains(executableDescription.ExecutableName));

                port = NetworkAdapters.getNextAvailablePort(port, this.settings.MaxPort);
                if (port == -1)
                {
                    System.Windows.MessageBox.Show("No ports are available to start service or adapters.", "Network error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                //Create a controller for the executable process
                ExecutableController exeController = new ExecutableController(executableDescription, new MIPAddress(RuntimeData.MMIRegisterAddress.Address, port), RuntimeData.MMIRegisterAddress, mmuPath, executableFile, settings.HideWindows);

                RuntimeData.ExecutableControllers.Add(exeController);
            }

            //Setup the services
            foreach (string folderPath in Directory.GetDirectories(servicePath))
            {
                //Find the description file
                string descriptionFile = Directory.GetFiles(folderPath).ToList().Find(s => s.Contains("description.json"));

                //Skip if no description file
                if (descriptionFile == null)
                {
                    continue;
                }


                //Get the ExecutableDescription of the service
                MExecutableDescription executableDescription = Serialization.FromJsonString <MExecutableDescription>(File.ReadAllText(descriptionFile));
                string executableFile = Directory.GetFiles(folderPath).ToList().Find(s => s.Contains(executableDescription.ExecutableName));

                port = NetworkAdapters.getNextAvailablePort(port, this.settings.MaxPort);
                if (port == -1)
                {
                    System.Windows.MessageBox.Show("No ports are available to start service or adapters.", "Network error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                ExecutableController exeController = new ExecutableController(executableDescription, new MIPAddress(RuntimeData.MMIRegisterAddress.Address, port), RuntimeData.MMIRegisterAddress, mmuPath, executableFile, settings.HideWindows);

                RuntimeData.ExecutableControllers.Add(exeController);
            }

            //Start the controllers
            foreach (ExecutableController executableController in RuntimeData.ExecutableControllers)
            {
                MBoolResponse response = executableController.Start();

                if (!response.Successful)
                {
                    System.Windows.MessageBox.Show("Cannot start application: " + executableController.Name + " " + (response.LogData.Count > 0? response.LogData[0]: ""));
                }
            }

            //Create a new thread which checks the loadable MMUs
            ThreadPool.QueueUserWorkItem(delegate
            {
                while (this.running)
                {
                    Thread.Sleep(1000);

                    this.UpdateLoadableMMUs();
                }
            });
        }
コード例 #3
0
        /// <summary>
        /// Setups the environment and starts the modules
        /// </summary>
        /// <param name="adapterPath">The path of the modules</param>
        /// <param name="mmuPath">The path of the mmus</param>
        private static void SetupEnvironment(string adapterPath, string mmuPath, string servicePath)
        {
            //Fetch all modules and start them
            foreach (string folderPath in Directory.GetDirectories(adapterPath))
            {
                //Find the description file
                string descriptionFile = Directory.GetFiles(folderPath).ToList().Find(s => s.Contains("description.json"));

                //Skip if no description file
                if (descriptionFile == null)
                {
                    continue;
                }

                //Get the ExecutableDescription of the adapter
                MExecutableDescription executableDescription = Serialization.FromJsonString <MExecutableDescription>(File.ReadAllText(descriptionFile));

                //Determine the filename of the executable file
                string executableFile = Directory.GetFiles(folderPath).ToList().Find(s => s.Contains(executableDescription.ExecutableName));

                //Create a controller for the executable process
                ExecutableController exeController = new ExecutableController(executableDescription, new MIPAddress(address, port), RuntimeData.MMIRegisterAddress, mmuPath, executableFile, false);

                RuntimeData.ExecutableControllers.Add(exeController);
                port += 1;
            }

            //Setup the services
            foreach (string folderPath in Directory.GetDirectories(servicePath))
            {
                //Find the description file
                string descriptionFile = Directory.GetFiles(folderPath).ToList().Find(s => s.Contains("description.json"));

                //Skip if no description file
                if (descriptionFile == null)
                {
                    continue;
                }


                //Get the ExecutableDescription of the service
                MExecutableDescription executableDescription = Serialization.FromJsonString <MExecutableDescription>(File.ReadAllText(descriptionFile));
                string executableFile = Directory.GetFiles(folderPath).ToList().Find(s => s.Contains(executableDescription.ExecutableName));

                ExecutableController exeController = new ExecutableController(executableDescription, new MIPAddress(address, port), RuntimeData.MMIRegisterAddress, mmuPath, executableFile, false);

                RuntimeData.ExecutableControllers.Add(exeController);
                port += 1;
            }

            //Start the controllers
            foreach (ExecutableController executableController in RuntimeData.ExecutableControllers)
            {
                MBoolResponse response = executableController.Start();

                if (!response.Successful)
                {
                    System.Console.WriteLine("Cannot start application: " + executableController.Name + " " + (response.LogData.Count > 0 ? response.LogData[0] : ""));
                }
            }
        }