/// <summary> /// Parse comma-separated Hosts /// </summary> /// <param name="store">Store</param> /// <returns>Comma-separated hosts</returns> public virtual string[] ParseHostValues(HostedSite store) { if (store == null) { throw new ArgumentNullException(nameof(store)); } var parsedValues = new List <string>(); if (string.IsNullOrEmpty(store.Hosts)) { return(parsedValues.ToArray()); } var hosts = store.Hosts.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var host in hosts) { var tmp = host.Trim(); if (!string.IsNullOrEmpty(tmp)) { parsedValues.Add(tmp); } } return(parsedValues.ToArray()); }
/// <summary> /// Updates the store /// </summary> /// <param name="store">Store</param> public virtual void UpdateHostedSite(HostedSite store) { if (store == null) { throw new ArgumentNullException(nameof(store)); } _hostedSiteRepository.Update(store); _cacheManager.RemoveByPrefix(BopHostedSiteDefaults.HostedSitesPrefixCacheKey); //event notification _eventPublisher.EntityUpdated(store); }
/// <summary> /// Indicates whether a store contains a specified host /// </summary> /// <param name="store">Store</param> /// <param name="host">Host</param> /// <returns>true - contains, false - no</returns> public virtual bool ContainsHostValue(HostedSite store, string host) { if (store == null) { throw new ArgumentNullException(nameof(store)); } if (string.IsNullOrEmpty(host)) { return(false); } var contains = ParseHostValues(store).Any(x => x.Equals(host, StringComparison.InvariantCultureIgnoreCase)); return(contains); }
/// <summary> /// Handle an incoming request using the hosted site /// </summary> public SerialisableResponse Request(SerialisableRequest request) { Interlocked.Increment(ref _callCount); var response = HostedSite.DirectCall(request); if (response.StatusCode > 499) { Interlocked.Increment(ref _failureCount); FailureHistory.Record(); } else { SuccessHistory.Record(); } return(response); }
private void WarmAndTest() { // Give the site an initial kick, so it's warm when it goes into the version table var healthRequest = new SerialisableRequest { Headers = new Dictionary <string, string> { { "Accept", "text/plain,application/json" } }, Method = "GET", RequestUri = "/health" }; var result = HostedSite.DirectCall(healthRequest); if (result.StatusCode > 499) { // We don't care about 'bad request' or 'file not found', in case the health endpoint is not implemented // However, if the site fails we will entirely reject this version HostedSite.Dispose(); throw new WarmupCallException("Version wake-up failed: v" + MajorVersion + " at " + TargetPath + "; " + result.StatusCode + " " + result.StatusMessage); } }
/// <summary> /// Deletes a store /// </summary> /// <param name="hostedSite">Store</param> public virtual void DeleteHostedSite(HostedSite hostedSite) { if (hostedSite == null) { throw new ArgumentNullException(nameof(hostedSite)); } var allStores = GetAllHostedSites(); if (allStores.Count == 1) { throw new Exception("You cannot delete the only configured store"); } _hostedSiteRepository.Delete(hostedSite); _cacheManager.RemoveByPrefix(BopHostedSiteDefaults.HostedSitesPrefixCacheKey); //event notification _eventPublisher.EntityDeleted(hostedSite); }