Ejemplo n.º 1
0
        public static RaciEndpointDriver AddDriver(string epName, string driverType, string driverName, string descr = "")
        {
            if (String.IsNullOrWhiteSpace(driverName))
            {
                logger?.LogWarning($"Unable to add endpoint: Invalid driverName '{driverName}'");
                return(null);
            }
            RaciEndpoint       ep  = GetEndpointByName(epName);
            RaciEndpointDriver drv = null;

            if (ep != null)
            {
                drv = GetDrivers(ep).WithName(driverName);
                if (drv == null)
                {
                    drv = new RaciEndpointDriver(driverName, descr)
                    {
                        DriverType          = driverType,
                        ParentProfileNodeId = ep.ProfileNodeId,
                        Parent = ep
                    };
                    ep.Nodes.Add(drv);
                }
            }
            else
            {
                logger?.LogWarning($"Unable to add endpoint: No service named '{epName}' found");
            }
            return(drv);
        }
Ejemplo n.º 2
0
        public static RaciEndpointDriver UpdateDriver(string epName, string driverName, string driverType, string descr, bool create = false)
        {
            RaciEndpoint ep = GetEndpointByName(epName);

            if (ep == null)
            {
                string msg = $"Cannot add driver '{driverType}:{driverName}'. Endpoint '{epName}' does not exist";
                logger.LogError(msg);
                throw new KeyNotFoundException(msg);
            }
            RaciEndpointDriver drv = ep.Nodes.WithName(driverName);

            if (drv == null)
            {
                drv = create ? AddDriver(ep?.Name, driverType, driverName, descr):null;
            }
            else
            {
                if (!String.IsNullOrWhiteSpace(driverType))
                {
                    drv.DriverType = driverType;
                }
                if (!String.IsNullOrWhiteSpace(descr))
                {
                    drv.Description = descr;
                }
            }
            return(GetDriverByName(epName, driverName));
        }
Ejemplo n.º 3
0
        public void DiscoverService()
        {
            RaciEndpoint ep = RaciClient.QueryEndpoint(_url);

            Assert.IsNotNull(ep, "Check returned endpoint is not null");
            Assert.IsTrue(ep.Nodes.Count > 0, "Check endpoint has at least one registered driver");
            string json = JsonConvert.SerializeObject(ep, Formatting.Indented);

            Console.WriteLine(json);
        }
Ejemplo n.º 4
0
        public static bool RemoveDriver(string epName, string driverName)
        {
            RaciEndpoint       ep  = GetEndpointByName(epName);
            RaciEndpointDriver drv = ep.Nodes.WithName(driverName);

            if (drv != null)
            {
                ep.Nodes.Remove(drv);
            }
            return(ep.Nodes.WithName(driverName) == null);
        }
Ejemplo n.º 5
0
        public static bool RemoveDrivers(string epName)
        {
            RaciEndpoint ep = GetEndpointByName(epName);

            if (ep == null)
            {
                return(false);
            }
            ep.Nodes.Clear();
            return(ep.Nodes.Count() == 0);
        }
Ejemplo n.º 6
0
        public static RaciEndpoint AddEndpoint(string url, string label = null)
        {
            url   = url?.Trim() ?? String.Empty;
            label = label?.Trim() ?? "";
            if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri))
            {
                logger?.LogWarning($"Url is not valid. Must be an absolute Uri. '{url}'");
                return(null);
            }
            RaciEndpoint ep = endpoints.WithUrl(url);

            if (ep != null)
            {
                if (label != "" && ep.Name != label)
                {
                    label   = makeServiceLabel(label);
                    ep.Name = label;
                }
            }
            else
            {
                lock (serviceSync)
                {
                    if (label == "")
                    {
                        label = uri.DnsSafeHost;
                    }
                    label = makeServiceLabel(label);
                    endpoints.Add(new RaciEndpoint(label)
                    {
                        ServiceRoot = url
                    });
                    ep = endpoints.WithUrl(url);
                }
            }
            if (ep == null)
            {
                logger?.LogWarning($"Unable to add or update endpoint: Label: '{label}', Url: '{url}'");
            }
            else
            {
                logger?.LogWarning($"Added or updated endpoint: Label: '{label}', Url: '{url}'");
            }
            return(ep);
        }
Ejemplo n.º 7
0
        public static RaciEndpointDriver AddDriver(string epName, RaciEndpointDriver drv)
        {
            if (drv?.Name == null || String.IsNullOrWhiteSpace(epName) || !HasEndpointName(epName))
            {
                return(null);
            }

            RaciEndpoint ep = GetEndpointByName(epName);

            var d = ep.Nodes.WithName(drv?.Name);

            if (d != null)
            {
                ep.Nodes.Remove(d);
            }
            drv.Parent = ep;
            ep.Nodes.Add(drv);
            return(drv);
        }
Ejemplo n.º 8
0
 public static RaciEndpointDriver GetDriverByName(RaciEndpoint ep, string driverName) =>
 GetDriverByName(ep?.Name, driverName);
Ejemplo n.º 9
0
 public static IQueryable <string> GetDriverNames(RaciEndpoint ep, string driverType) =>
 GetDriverNames(ep?.Name, driverType);
Ejemplo n.º 10
0
 public static IQueryable <RaciEndpointDriver> GetDrivers(RaciEndpoint ep) =>
 GetDrivers(ep?.Name);
Ejemplo n.º 11
0
 public static IQueryable <string> GetDriverTypes(RaciEndpoint ep) =>
 GetDriverTypes(ep?.Name);
Ejemplo n.º 12
0
 public static RaciEndpointDriver UpdateDriver(RaciEndpoint ep, string driverName, string driverType, string descr, bool create = false)
 {
     return(UpdateDriver(ep?.Name, driverName, driverType, descr, create));
 }
Ejemplo n.º 13
0
 public RestDriver(RaciEndpoint ep, string driverName) : this(ep?.ServiceRoot, driverName)
 {
 }
Ejemplo n.º 14
0
 public RaciClient(RaciEndpoint ep, string driverName) : this(ep?.ServiceRoot, driverName)
 {
 }
Ejemplo n.º 15
0
 public static bool HasDriver(RaciEndpoint ep, string driverName) =>
 HasDriver(ep?.Name, driverName);
Ejemplo n.º 16
0
 public static RaciEndpointDriver UpdateOrCreateDriver(RaciEndpoint ep, string driverName, string driverType, string descr)
 {
     return(UpdateDriver(ep, driverName, driverType, descr, true));
 }
Ejemplo n.º 17
0
 public DomeDriver(RaciEndpoint ep, string driverName) : base(ep?.ServiceRoot, driverName)
 {
 }