/// <summary>
        /// Method is utilized to register an external service
        /// </summary>
        /// <param name="serviceDescription"></param>
        /// <returns></returns>
        public MBoolResponse RegisterService(MServiceDescription serviceDescription)
        {
            //Check if the adapter description is already available
            if (RuntimeData.ServiceInstances.ContainsKey(serviceDescription.ID))
            {
                Console.WriteLine($"Service: {serviceDescription.Name} already available -> nothing to do.");
                return(new MBoolResponse(true));
            }


            //Add a new remote service controller
            RemoteService remoteService = new RemoteService(serviceDescription);

            remoteService.Start();

            //Add the newly generated service description
            if (!RuntimeData.ServiceInstances.TryAdd(serviceDescription.ID, remoteService))
            {
                Console.WriteLine($"Cannot add service description {serviceDescription.Name}");
            }

            //Fire event
            this.OnServiceRegistered?.Invoke(this, remoteService);

            return(new MBoolResponse(true));
        }
        /// <summary>
        /// Method is called if a service should be unregistered
        /// </summary>
        /// <param name="serviceDescription"></param>
        /// <returns></returns>
        public MBoolResponse UnregisterService(MServiceDescription serviceDescription)
        {
            if (!RuntimeData.ServiceInstances.ContainsKey(serviceDescription.ID))
            {
                //Nothing to do no adapter available
                return(new MBoolResponse(true));
            }

            if (RuntimeData.ServiceInstances.ContainsKey(serviceDescription.ID))
            {
                RemoteService service = null;

                RuntimeData.ServiceInstances.TryGetValue(serviceDescription.ID, out service);

                //Dispose the adapter
                service.Dispose();

                //Remove the adapter
                RuntimeData.ServiceInstances.TryRemove(serviceDescription.ID, out service);

                //Fire event
                this.OnServiceUnregistered?.Invoke(this, service);

                //Return true
                return(new MBoolResponse(true));
            }

            return(new MBoolResponse(false)
            {
                LogData = new List <string>()
                {
                    "No matching service found"
                }
            });
        }
 /// <summary>
 /// Basic constructor
 /// </summary>
 /// <param name="filepath"></param>
 /// <param name="description"></param>
 /// <param name="hideWindow"></param>
 public RemoteService(MServiceDescription description)
 {
     this.Description = description;
     this.Port        = description.Addresses[0].Port;
     this.Address     = description.Addresses[0].Address;
     this.Name        = description.Name;
 }
Exemple #4
0
 /// <summary>
 /// Basic constructor
 /// </summary>
 /// <param name="description">The service description</param>
 /// <param name="mmiRegisterAddress">The address of the mmi register</param>
 /// <param name="processor">The assigned processor of the service controller</param>
 public ServiceController(MServiceDescription description, MIPAddress mmiRegisterAddress, TProcessor processor)
 {
     //Assign the adapter description
     this.serviceDescription = description;
     //Assign the addresses
     this.address            = description.Addresses[0];
     this.mmiRegisterAddress = mmiRegisterAddress;
     //Assign the processor
     this.processor = processor;
 }
        /// <summary>
        /// Basic constructor
        /// </summary>
        /// <param name="registerAddress"></param>
        /// <param name="description"></param>
        public ServiceRegistrationHandler(MIPAddress registerAddress, MServiceDescription description, bool autoStart = true)
        {
            this.address     = registerAddress;
            this.description = description;
            this.thread      = new Thread(new ThreadStart(this.HandleRegistration));
            this.cts         = new CancellationTokenSource();

            if (autoStart)
            {
                this.Start();
            }
        }
Exemple #6
0
        public RetargetingService(string ip, int port)
        {
            Console.WriteLine("Start Service at port" + port.ToString());
            var id        = Guid.NewGuid().ToString();
            var name      = "Retargeting";
            var language  = "C#";
            var addresses = new List <MIPAddress> {
                new MIPAddress(ip, port)
            };

            ServiceDescription = new MServiceDescription(name, id, language, addresses);

            //skeleton.InitializeAnthropometry(desc);
        }
        /// <summary>
        /// Returns the service description by name
        /// </summary>
        /// <param name="serviceName"></param>
        /// <returns></returns>
        private MServiceDescription GetServiceDescription(string serviceName)
        {
            MServiceDescription description = null;

            if (!serviceDescriptions.TryGetValue(serviceName, out description))
            {
                this.Initialize();
            }

            if (!serviceDescriptions.TryGetValue(serviceName, out description))
            {
                return(null);
            }

            return(serviceDescriptions[serviceName]);
        }
        /// <summary>
        /// Checks whether the registration is already available at the register
        /// </summary>
        /// <param name="serviceDescription"></param>
        /// <returns></returns>
        private bool RegistrationAvailable(MServiceDescription serviceDescription)
        {
            try
            {
                using (MMIRegisterServiceClient client = new MMIRegisterServiceClient(this.address.Address, this.address.Port))
                {
                    List <MServiceDescription> serviceDescriptions = client.Access.GetRegisteredServices("");

                    if (serviceDescriptions.Exists(s => s.ID == serviceDescription.ID && s.Addresses.Exists(x => x.Address == serviceDescription.Addresses[0].Address && x.Port == serviceDescription.Addresses[0].Port)))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception)
            {
            }

            return(false);
        }
Exemple #9
0
 /// <summary>
 /// Basic constructor
 /// </summary>
 /// <param name="filepath"></param>
 /// <param name="description"></param>
 /// <param name="hideWindow"></param>
 public MMIService(string filepath, MServiceDescription description, bool hideWindow)
 {
     this.Description = description;
     this.filepath    = filepath;
     this.hideWindow  = hideWindow;
 }