Beispiel #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);
        }
Beispiel #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));
        }
        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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #8
0
 public static RaciEndpointDriver GetDriverByName(RaciEndpoint ep, string driverName) =>
 GetDriverByName(ep?.Name, driverName);
Beispiel #9
0
 public static IQueryable <string> GetDriverNames(RaciEndpoint ep, string driverType) =>
 GetDriverNames(ep?.Name, driverType);
Beispiel #10
0
 public static IQueryable <RaciEndpointDriver> GetDrivers(RaciEndpoint ep) =>
 GetDrivers(ep?.Name);
Beispiel #11
0
 public static IQueryable <string> GetDriverTypes(RaciEndpoint ep) =>
 GetDriverTypes(ep?.Name);
Beispiel #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));
 }
 public RestDriver(RaciEndpoint ep, string driverName) : this(ep?.ServiceRoot, driverName)
 {
 }
Beispiel #14
0
 public RaciClient(RaciEndpoint ep, string driverName) : this(ep?.ServiceRoot, driverName)
 {
 }
Beispiel #15
0
 public static bool HasDriver(RaciEndpoint ep, string driverName) =>
 HasDriver(ep?.Name, driverName);
Beispiel #16
0
 public static RaciEndpointDriver UpdateOrCreateDriver(RaciEndpoint ep, string driverName, string driverType, string descr)
 {
     return(UpdateDriver(ep, driverName, driverType, descr, true));
 }
 public DomeDriver(RaciEndpoint ep, string driverName) : base(ep?.ServiceRoot, driverName)
 {
 }