Esempio n. 1
0
        public ServiceData Register(GuardedServiceDescription description, GuardService service)
        {
            lock (this.guardedServices)
            {
                bool nameConflict = false;
                bool pathConflict = false;
                foreach (var s in this.guardedServices.Values)
                {
                    nameConflict |= s.Description.Name == description.Name;
                    pathConflict |= s.Description.ExecutablePath == description.ExecutablePath && s.Description.Arguments == description.Arguments;
                    if (nameConflict || pathConflict)
                    {
                        break;
                    }
                }
                if (nameConflict)
                {
                    throw new InvalidOperationException("A service that has the same name is already registered.");
                }
                if (pathConflict)
                {
                    throw new InvalidOperationException("A service that has the same path and argument is already registered.");
                }

                Guid        token       = Guid.NewGuid();
                ServiceData serviceData = new ServiceData()
                {
                    Description   = description,
                    Service       = service,
                    SemaphoreName = "NodeServerGuardedService-" + token.ToString(),
                    Token         = token,
                };
                this.guardedServices.Add(token, serviceData);
                service.Callback.Start(serviceData.SemaphoreName);
                return(serviceData);
            }
        }
Esempio n. 2
0
        public Guid Register(GuardedServiceDescription description)
        {
            var data = this.SharedData.Register(description, this);

            return(data.Token);
        }