private InMemoryKeyValueCache CreateCache(int size)
        {
            var factory = new InMemoryKeyValueCacheFactory(size, TaskTimerFactory.Current);

            factory.SetSerializer <int>(new IntSerializer());
            return((InMemoryKeyValueCache)factory.Create());
        }
Пример #2
0
        //--- 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>());
            }
        }
 public void FixtureSetup()
 {
     _factory = new InMemoryKeyValueCacheFactory(TaskTimerFactory.Current);
     _factory.SetSerializer <int>(new IntSerializer());
 }