public string[] GetServiceUrls(string contractFullName, int contractMajorVersion, string infrastructureScopeName) { DiscoveryStoreEntry entry = this.PickStoreEntry(contractFullName, contractMajorVersion, infrastructureScopeName, false); string[] urls; if (entry is null) { if (infrastructureScopeName.Contains("/")) { string[] tokens = infrastructureScopeName.Split('/'); tokens = tokens.Take(tokens.Length - 1).ToArray(); infrastructureScopeName = String.Join("/", tokens); urls = this.GetServiceUrls(contractFullName, contractMajorVersion, infrastructureScopeName); } else { urls = new string[] {}; } } else { urls = entry.UrlEntries.Where((u) => u.AvailabilityState >= 0).OrderBy((u) => u.AvailabilityState).Select((u) => u.Url).ToArray(); } return(urls); }
public bool AnnounceServiceUrl(string serviceUrl, string contractFullName, int contractMajorVersion, string infrastructureScopeName, int initialAvailabilityState, DateTime timestampUtc, string legitimationHash) { this.ThrowOnInvalidHash(serviceUrl, timestampUtc, legitimationHash); DiscoveryStoreEntry entry = this.PickStoreEntry(contractFullName, contractMajorVersion, infrastructureScopeName, true); entry.LastUpdateUtc = DateTime.UtcNow; DiscoveryStoreUrlEntry urlEntry = entry.UrlEntries.Where((e) => e.Url.Equals(serviceUrl, StringComparison.InvariantCultureIgnoreCase)).SingleOrDefault(); if (urlEntry is null) { urlEntry = new DiscoveryStoreUrlEntry(); urlEntry.Url = serviceUrl; urlEntry.AvailabilityState = initialAvailabilityState; entry.UrlEntries = entry.UrlEntries.Union(new DiscoveryStoreUrlEntry[] { urlEntry }).ToArray(); } else { urlEntry.AvailabilityState = initialAvailabilityState; } try { this.SaveStoreEntry(entry); } catch { return(false); } return(true); }
private DiscoveryStoreEntry PickStoreEntry(string contractFullName, int contractMajorVersion, string infrastructureScopeName, bool createIfNotEists) { DiscoveryStoreEntry entry; lock (_StoreEntries) { entry = _StoreEntries.Where((e) => e.ContractFullName == contractFullName && e.ContractMajorVersion == contractMajorVersion && e.InfrastructureScopeName == infrastructureScopeName).SingleOrDefault(); if (entry is null && createIfNotEists) { entry = new DiscoveryStoreEntry(); entry.ContractFullName = contractFullName; entry.ContractMajorVersion = contractMajorVersion; entry.InfrastructureScopeName = infrastructureScopeName; entry.LastUpdateUtc = DateTime.MinValue; entry.UrlEntries = new DiscoveryStoreUrlEntry[] { }; _StoreEntries.Add(entry); } } return(entry); }
private void SaveStoreEntry(DiscoveryStoreEntry entry) { _PersistentStore.SaveEntry(entry); }