Exemple #1
0
        private void ProjectingCachedQueryTest(int count)
        {
            var d = Domain;

            using (var ss = d.OpenSession()) {
                var s = ss.Session;
                using (var ts = s.OpenTransaction()) {
                    var id = 0;
                    TestHelper.CollectGarbage();
                    using (warmup ? null : new Measurement("Projecting Cached Query", count)) {
                        for (int i = 0; i < count; i++)
                        {
                            id = i % instanceCount;
                            var query = CachedQuery.Execute(() => Query <Simplest> .All
                                                            .Where(o => o.Id == id)
                                                            .Select(o => new { o.Id, o.Value }));
                            foreach (var simplest in query)
                            {
                                // Doing nothing, just enumerate
                            }
                        }
                        ts.Complete();
                    }
                }
            }
        }
        public void IsMatchByQueryType_IdMismatch_ReturnsFalse()
        {
            var type = typeof(Table);
            var sut  = new CachedQuery(_queryToCache, "id", type);

            Assert.False(sut.IsMatch("nonId", typeof(Table)));
        }
Exemple #3
0
        private async void CachedIqCallback(object Sender, IqResultEventArgs e)
        {
            try
            {
                object[]             P        = (object[])e.State;
                IqResultEventHandler Callback = (IqResultEventHandler)P[0];
                object State  = P[1];
                string Xml    = (string)P[2];
                string Method = (string)P[3];

                CachedQuery Query = new CachedQuery()
                {
                    Xml      = Xml,
                    Method   = Method,
                    Response = e.Response.OuterXml,
                    LastUsed = DateTime.Now
                };

                await Database.Insert(Query);

                if (Callback != null)
                {
                    e.State = State;
                    Callback(Sender, e);
                }

                await this.DeleteOld();
            }
            catch (Exception ex)
            {
                Log.Critical(ex);
            }
        }
        public void IsMatchById_CachedQueryHasQueryType_ReturnsFalse()
        {
            var id  = "QueryId";
            var sut = new CachedQuery(_queryToCache, id, typeof(Table));

            Assert.False(sut.IsMatch(id));
        }
        public void IsMatchByQueryType_QueryTypeMisMatch_ReturnsFalse()
        {
            var id = "id";

            var sut = new CachedQuery(_queryToCache, id, typeof(Left));

            Assert.False(sut.IsMatch(id, typeof(Right)));
        }
        public void IsMatchById_Match_ReturnsTrue()
        {
            var id = "id";

            var sut = new CachedQuery(_queryToCache, "id");

            Assert.True(sut.IsMatch(id));
        }
        public void Constructor_ConvertsQueryToStatementCache()
        {
            var sut = new CachedQuery(_queryToCache, "");

            _queryToCache.OrderBy <Table>(j => j.TableId);

            Assert.NotEqual(sut.Statement, _queryToCache.ToStatement());
        }
        public void IsMatchByQueryType_IdAnQueryTypeMatch_ReturnsTrue()
        {
            var id   = "id";
            var type = typeof(Table);
            var sut  = new CachedQuery(_queryToCache, id, type);

            Assert.True(sut.IsMatch(id, type));
        }
        public void Constructor_CachedQueryIsCloned()
        {
            var sut = new CachedQuery(_queryToCache, "");

            Assert.NotEqual(_queryToCache, sut.Query);

            var comparer = new CompareLogic();

            Assert.True(comparer.Compare(_queryToCache, sut.Query).AreEqual);
        }
Exemple #10
0
        public static object CacheContext(RequestAdapter req, string path, int level)
        {
            var cache = new CachedQuery()
            {
                Q = new Query(path, Unium.Root), Reselect = true
            };

            if (level > 0)
            {
                cache.Q.Select();
                cache.Reselect = false;
            }

            return(cache);
        }
Exemple #11
0
        private async Task CachedIq(string Xml, string Method, IqResultEventHandler Callback, object State)
        {
            CachedQuery Query = await Database.FindFirstDeleteRest <CachedQuery>(new FilterAnd(
                                                                                     new FilterFieldEqualTo("Xml", Xml), new FilterFieldEqualTo("Method", Method)));

            if (Query != null)
            {
                Query.LastUsed = DateTime.Now;
                await Database.Update(Query);

                if (Callback != null)
                {
                    try
                    {
                        XmlDocument Doc = new XmlDocument();
                        Doc.LoadXml(Query.Response);

                        XmlElement E    = Doc.DocumentElement;
                        string     Type = XML.Attribute(E, "type");
                        string     Id   = XML.Attribute(E, "id");
                        string     To   = XML.Attribute(E, "to");
                        string     From = XML.Attribute(E, "from");
                        bool       Ok   = (Type == "result");

                        IqResultEventArgs e = new IqResultEventArgs(E, Id, To, From, Ok, State);

                        Callback(this.client, e);
                    }
                    catch (Exception ex)
                    {
                        Log.Critical(ex);
                    }
                }
            }
            else
            {
                this.client.SendIq(null, this.provisioningServerAddress, Xml, "get", this.CachedIqCallback, new object[] { Callback, State, Xml, Method },
                                   this.client.DefaultRetryTimeout, this.client.DefaultNrRetries,
                                   this.client.DefaultDropOff, this.client.DefaultMaxRetryTimeout);
            }
        }
Exemple #12
0
#pragma warning disable IDE0051 // Remove unused private members
        static void ConfigureMagnetoManually(IServiceCollection services)
#pragma warning restore IDE0051 // Remove unused private members
        {
            // Here we add IMagneto as the main entry point for consumers, because it can do everything. We could also add any of
            // the interfaces which IMagneto is comprised of, to enable exposing limited functionality to some consumers.
            // Internally, Conductor relies on IMediary to do its work, so we could also add that or any of the interfaces
            // it's comprised of in order to take control of passing the context when executing queries or commands.
            services.AddTransient <IMagneto, Conductor>();

            // Here we add a decorator object which performs exception logging and timing telemetry for all our Magneto operations.
            services.AddSingleton <IDecorator, ApplicationInsightsDecorator>();

            // Here we add the our cache store associated with the Microsoft memory cache.
            services.AddSingleton <ICacheStore <MemoryCacheEntryOptions>, MemoryCacheStore>();

            // Here we add our cache store and serializer associated with the Microsoft distributed cache. Normally we'd only
            // have one type of cache in an application, but this is a sample application so we've got both here as examples.
            services.AddSingleton <IStringSerializer, SystemTextStringSerializer>();
            services.AddSingleton <ICacheStore <DistributedCacheEntryOptions>, DistributedCacheStore>();

            // Here we specify how cache keys are created. This is optional as there is already a default built-in method,
            // but consumers may want to use their own method instead.
            CachedQuery.UseKeyCreator((prefix, varyBy) => $"{prefix}.{JsonSerializer.Serialize(varyBy)}");
        }
        private static void LoadArchiveControl()
        {
            if (mCachedQuery == null) {
                CachedQuery.CacheUpdatedDelegate cb = new CachedQuery.CacheUpdatedDelegate(CacheCB);
                mCachedQuery = new CachedQuery(TDatabase.Shared, "select * from ArchiveControl order by id asc", 180, cb);
                mCachedQuery.AllowErrors = 2;
            }

            mCachedQuery.CheckCache();
        }
        public void IsMatchById_IdMismatch_ReturnsFalse()
        {
            var sut = new CachedQuery(_queryToCache, "id");

            Assert.False(sut.IsMatch("notId"));
        }
Exemple #15
0
        public static ArchiveConfig Get(string TablePath)
        {
            if (mCachedQuery == null) {
                mCache = new Dictionary<string, ArchiveConfig>();
                CachedQuery.CacheUpdatedDelegate cb = new CachedQuery.CacheUpdatedDelegate(CacheCB);
                mCachedQuery = new CachedQuery(TDatabase.Shared, "select * from ArchiveConfig", 180, cb);
                mCachedQuery.AllowNoRows = true;
            }

            mCachedQuery.CheckCache();
            if (mCache.ContainsKey(TablePath.ToLower()))
                return mCache[TablePath.ToLower()];
            return null;
        }
Exemple #16
0
 public static TCachedResult PeekCachedResult <TContext, TCacheEntryOptions, TCachedResult>(this CachedQuery <TContext, TCacheEntryOptions, TCachedResult> cachedQuery)
 {
     return(cachedQuery.GetStateProperty <TCachedResult>("CachedResult"));
 }