Exemple #1
0
        public void Unregister(GuardService service)
        {
            Guid token = Guid.Empty;

            lock (this.guardedServices)
            {
                foreach (var pair in this.guardedServices)
                {
                    if (pair.Value.Service == service)
                    {
                        token = pair.Value.Token;
                        break;
                    }
                }
            }
            if (token != Guid.Empty)
            {
                Unregister(token);
            }
        }
Exemple #2
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);
            }
        }