//--- Constructors --- internal DekiContext(DekiWikiService deki, DekiInstance instance, string requestHost, DateTime requestTime, IPlainTextResourceManager resourceManager) { if (deki == null) { throw new ArgumentNullException("deki"); } this.Deki = deki; this.RequestHost = requestHost; _resourceManager = resourceManager; _now = requestTime; _instance = instance; // Note (arnec): this context string formattingis duplicated in DekiWikiService.Start, because we have two separate // context logger types. This one ought to be deprecated over time. DreamContext.Current.SetState(LOGGING_CONTEXT_KEY, "[" + _instance.Id + "] "); }
//--- Constructor --- public DekiInstance(DekiWikiService deki, string id, XDoc instanceConfig) { if(deki == null) { throw new ArgumentNullException("deki"); } if(string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } this.Id = id; this.TimerFactory = TaskTimerFactory.Create(this); this.Cache = new DreamCache(TimerFactory); var cacheFactory = new InMemoryKeyValueCacheFactory(TimerFactory); var searchSerializer = new SearchSerializer(); cacheFactory.SetSerializer<SearchResult>(searchSerializer); cacheFactory.SetSerializer<SearchResultDetail>(searchSerializer); this.SearchCache = cacheFactory.Create(); this.Config = instanceConfig; this.Log = LogManager.GetLogger(deki.GetType().Name + "_" + id); _deki = deki; _status = DekiInstanceStatus.CREATED; foreach(XDoc hostDoc in Config["host"]) { string host = hostDoc.Contents; if(!StringUtil.EqualsInvariantIgnoreCase(host, "*")) { string port = hostDoc["@port"].AsText; string scheme = hostDoc["@https"].AsBool.GetValueOrDefault() ? "https://" : "http://"; string uri = scheme + host + (string.IsNullOrEmpty(port) ? "" : ":" + port); _canonicalUri = new XUri(uri); _log.DebugFormat("divined canonical use from hosts as {0}", _canonicalUri); break; } } if(_canonicalUri == null) { // Note (arnec): this is a best guess fallback. It will only work in these scenarios: // a) The host was set up with a uri.public that has ends in @api and with the @api points to the site uri, or // b) The api lives on the same machine as the site, so that deriving uri.public for the host from the machine // IP happens to point to the same machine // Either way it relies on the hard-coded assumption that the api is accessible via {site}/@api _canonicalUri = DreamContext.Current.ServerUri; if(_canonicalUri.LastSegment.EqualsInvariantIgnoreCase("@api")) { _canonicalUri = _canonicalUri.WithoutLastSegment(); } _log.DebugFormat("using server uri as canonical uri: {0}", _canonicalUri); } else { // Note (arnec): Propagating a much hard-coded assumption, i.e. that the Api for any Deki instance can be accessed // at the instances' canonical uri plus @api // register the api uri with the dream host so that requests originating from within Dream are guaranteed to be locally routed _deki.Env.At("status", "aliases").Post(new XDoc("aliases").Elem("uri.alias", _canonicalUri.At("@api")), new Result<DreamMessage>()); } }
//--- Constructor --- internal DekiInstance(DekiWikiService deki, string id, XDoc instanceConfig, ILicenseController licenseController) { if (deki == null) { throw new ArgumentNullException("deki"); } if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } this.Id = id; // Note (arnec): this is now the the third place we define a wikiid based logger repository, however constructors interdependencies // currently neccessitates this duplication, and fortunately it is mostly an aesthetic issue. _loggerRepository = new ContextLoggerRepository("[" + Id + "] "); _log = _loggerRepository.Get(GetType()); this.TimerFactory = TaskTimerFactory.Create(this); this.Cache = new DreamCache(TimerFactory); var cacheFactory = new InMemoryKeyValueCacheFactory(TimerFactory); var searchSerializer = new SearchSerializer(); cacheFactory.SetSerializer <SearchResult>(searchSerializer); cacheFactory.SetSerializer <SearchResultDetail>(searchSerializer); this.SearchCache = cacheFactory.Create(); this.Config = instanceConfig; _licenseController = licenseController; this.Log = LogManager.GetLogger(deki.GetType().Name + "_" + id); _deki = deki; _status = DekiInstanceStatus.CREATED; _apiKey = Config[ConfigBL.SECURITY_APIKEY].AsText; foreach (XDoc hostDoc in Config["host"]) { string host = hostDoc.Contents; if (!StringUtil.EqualsInvariantIgnoreCase(host, "*")) { string port = hostDoc["@port"].AsText; string scheme = hostDoc["@https"].AsBool.GetValueOrDefault() ? "https://" : "http://"; string uri = scheme + host + (string.IsNullOrEmpty(port) ? "" : ":" + port); _canonicalUri = new XUri(uri); _log.DebugFormat("divined canonical use from hosts as {0}", _canonicalUri); break; } } if (_canonicalUri == null) { // Note (arnec): this is a best guess fallback. It will only work in these scenarios: // a) The host was set up with a uri.public that has ends in @api and with the @api points to the site uri, or // b) The api lives on the same machine as the site, so that deriving uri.public for the host from the machine // IP happens to point to the same machine // Either way it relies on the hard-coded assumption that the api is accessible via {site}/@api _canonicalUri = DreamContext.Current.ServerUri; if (_canonicalUri.LastSegment.EqualsInvariantIgnoreCase("@api")) { _canonicalUri = _canonicalUri.WithoutLastSegment(); } _log.DebugFormat("using server uri as canonical uri: {0}", _canonicalUri); } else { // Note (arnec): Propagating a much hard-coded assumption, i.e. that the Api for any Deki instance can be accessed // at the instances' canonical uri plus @api // register the api uri with the dream host so that requests originating from within Dream are guaranteed to be locally routed _deki.Env.At("status", "aliases").Post(new XDoc("aliases").Elem("uri.alias", _canonicalUri.At("@api")), new Result <DreamMessage>()); } }
//--- Constructors --- internal DekiContext(DekiWikiService deki, DekiInstance instance, string requestHost, DateTime requestTime, IPlainTextResourceManager resourceManager) { if(deki == null) { throw new ArgumentNullException("deki"); } this.Deki = deki; this.RequestHost = requestHost; _resourceManager = resourceManager; _now = requestTime; _instance = instance; // Note (arnec): this context string formattingis duplicated in DekiWikiService.Start, because we have two separate // context logger types. This one ought to be deprecated over time. DreamContext.Current.SetState(LOGGING_CONTEXT_KEY, "[" + _instance.Id + "] "); }