public void AddMethodHandler(ObjectPath?path, string interfaceName, IMethodHandler handler) { ThrowIfDisposed(); if (string.IsNullOrEmpty(interfaceName)) { throw new ArgumentNullException(nameof(interfaceName)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } lock (_gate) { if (path.HasValue) { var pathParts = path.Value.Decomposed; MethodHandlerPathPart pathHandlers = RootPath; foreach (var part in pathParts) { if (!pathHandlers.OurSubParts.TryGetValue(part, out MethodHandlerPathPart next)) { next = new MethodHandlerPathPart(pathHandlers, part); pathHandlers.AddOurSubPart(part, next); } pathHandlers = next; } pathHandlers.OurInterfaceHandlers[interfaceName] = handler; } else { GlobalInterfaceHandlers[interfaceName] = handler; } } }
public IMethodHandler RemoveMethodHandler(ObjectPath?path, string interfaceName) { ThrowIfDisposed(); if (string.IsNullOrEmpty(interfaceName)) { throw new ArgumentNullException(nameof(interfaceName)); } lock (_gate) { if (path.HasValue) { var pathParts = path.Value.Decomposed; MethodHandlerPathPart pathHandlers = RootPath; foreach (var part in pathParts) { if (!pathHandlers.OurSubParts.TryGetValue(part, out MethodHandlerPathPart next)) { return(null); } pathHandlers = next; } if (!pathHandlers.OurInterfaceHandlers.TryGetValue(interfaceName, out IMethodHandler handler)) { return(null); } pathHandlers.OurInterfaceHandlers.Remove(interfaceName); // Remove any now empty path parts while (pathHandlers.Parent != null && !pathHandlers.InterfaceHandlers.Any() && !pathHandlers.SubParts.Any()) { pathHandlers.Parent.RemoveOurSubPart(pathHandlers.PathPart); pathHandlers = pathHandlers.Parent; } return(handler); } else { if (!GlobalInterfaceHandlers.TryGetValue(interfaceName, out IMethodHandler handler)) { return(null); } GlobalInterfaceHandlers.Remove(interfaceName); return(handler); } } }
public void AddOurSubPart(string part, MethodHandlerPathPart handler) { ourSubParts[part] = handler; UpdateSubParts(); }
public MethodHandlerPathPart(MethodHandlerPathPart parent, string pathPart) { Parent = parent; PathPart = pathPart; }