示例#1
0
        private IIndexStrategy CreateResolver(object source)
        {
            IIndexStrategy resolver = null;

            var numericIndex = 0;

            if (int.TryParse(_index, out numericIndex))
            {
                var dict = source as IDictionary;
                var list = source as IList;
                if (dict != null)
                {
                    resolver = new NumericDictStrategy(numericIndex);
                }
                else if (list != null)
                {
                    resolver = new ListStrategy(numericIndex);
                }
            }

            // Numeric failed, try text
            if (resolver == null)
            {
                if (source is IDictionary)
                {
                    resolver = new TextDictStrategy(_index);
                }
                else
                {
                    resolver = new NullStrategy();
                }
            }

            return(resolver);
        }
        /// <summary>
        /// Creates a new strategy for indexing the specified type.
        /// </summary>
        /// <param name="typeName">The short name of the type involved in the strategy.</param>
        /// <param name="requiresAutorisation">A value indicating whether or not the strategy requires authorisation.</param>
        static public IIndexStrategy New(string typeName, bool requiresAuthorisation)
        {
            IIndexStrategy strategy = StrategyState.Strategies.Creator.NewIndexer(typeName);

            strategy.RequireAuthorisation = requiresAuthorisation;
            return(strategy);
        }
        public void Test_Index_PageIndex0_Size1()
        {
            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Test Title";

            TestArticle article2 = new TestArticle();

            article2.ID    = Guid.NewGuid();
            article2.Title = "Test Title 2";

            DataAccess.Data.Saver.Save(article);
            DataAccess.Data.Saver.Save(article2);

            PagingLocation location = new PagingLocation(0, 1);

            IIndexStrategy strategy = IndexStrategy.New <TestArticle>(location, "TitleAscending", false);

            strategy.TypeName     = "TestArticle";
            strategy.EnablePaging = true;

            TestArticle[] foundArticles = Collection <TestArticle> .ConvertAll(strategy.Index());

            Assert.IsNotNull(foundArticles);

            Assert.AreEqual(2, location.AbsoluteTotal, "Absolute total invalid.");

            Assert.AreEqual(1, foundArticles.Length, "Invalid number of test articles found.");
        }
        public void Test_Index_FilterValues()
        {
            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Test Title";

            TestArticle article2 = new TestArticle();

            article2.ID    = Guid.NewGuid();
            article2.Title = "Test Title 2";

            DataAccess.Data.Saver.Save(article);
            DataAccess.Data.Saver.Save(article2);

            IIndexStrategy strategy = IndexStrategy.New <TestArticle>(false);

            strategy.TypeName = "TestArticle";

            Dictionary <string, object> filterValues = new Dictionary <string, object>();

            filterValues.Add("Title", article.Title);

            TestArticle[] foundArticles = Collection <TestArticle> .ConvertAll(strategy.Index(filterValues));

            Assert.IsNotNull(foundArticles);

            Assert.AreEqual(1, foundArticles.Length, "Invalid number of test articles found.");
        }
        public void Test_Index_PageIndex1_Size2()
        {
            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Test Title";

            TestArticle article2 = new TestArticle();

            article2.ID    = Guid.NewGuid();
            article2.Title = "Test Title 2";

            DataAccess.Data.Saver.Save(article);
            DataAccess.Data.Saver.Save(article2);

            PagingLocation location = new PagingLocation(1, 2);

            IIndexStrategy strategy = IndexStrategy.New <TestArticle>(location, "TitleAscending", false);

            strategy.TypeName     = "TestArticle";
            strategy.EnablePaging = true;

            TestArticle[] foundArticles = Collection <TestArticle> .ConvertAll(strategy.Index());

            Assert.IsNotNull(foundArticles);

            // There should be no articles found because it's requesting a page outside the available range
            Assert.AreEqual(0, foundArticles.Length, "Invalid number of test articles found.");
        }
示例#6
0
        /// <inheritdoc />
        protected sealed override bool Update(object source, object value)
        {
            if (_cachedResolver == null)
            {
                _cachedResolver = CreateResolver(source);
            }

            return(_cachedResolver.Update(source, value));
        }
示例#7
0
        /// <inheritdoc />
        protected sealed override object Resolve(object source)
        {
            if (_cachedResolver == null)
            {
                _cachedResolver = CreateResolver(source);
            }

            return(_cachedResolver.Resolve(source));
        }
        /// <summary>
        /// Creates a new strategy for indexing a single page of entities the specified type.
        /// </summary>
        static public IIndexStrategy New <T>(PagingLocation location, string sortExpression)
        {
            IIndexStrategy strategy = StrategyState.Strategies.Creator.NewIndexer(typeof(T).Name);

            strategy.EnablePaging   = true;
            strategy.Location       = location;
            strategy.SortExpression = sortExpression;

            return(strategy);
        }
示例#9
0
        public Searcher WithIndexStrategy(IIndexStrategy indexStrategy)
        {
            if (_initialized)
            {
                throw new Exception("IIndexStrategy cannot be set after initialization");
            }
            IndexStrategy = indexStrategy;

            return(this);
        }
示例#10
0
        /// <summary>
        /// Creates a new strategy for indexing a single page of entities the specified type.
        /// </summary>
        static public IIndexStrategy New(PagingLocation location, string typeName, string sortExpression, bool requireAuthorisation)
        {
            IIndexStrategy strategy = StrategyState.Strategies.Creator.NewIndexer(typeName);

            strategy.EnablePaging         = true;
            strategy.Location             = location;
            strategy.RequireAuthorisation = requireAuthorisation;
            strategy.SortExpression       = sortExpression;

            return(strategy);
        }
 public override void Dispose()
 {
     try
     {
         if (m_offsetMap != null)
         {
             m_offsetMap.Close();
             m_offsetMap = null;
         }
         m_cacheLookup      = null;
         m_cachePriority    = null;
         m_staticIdLookup   = null;
         m_staticReferences = null;
     }
     finally
     {
         base.Dispose();
     }
 }
        public void Test_Index()
        {
            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Test Title";

            TestArticle article2 = new TestArticle();

            article2.ID    = Guid.NewGuid();
            article2.Title = "Test Title 2";

            DataAccess.Data.Saver.Save(article);
            DataAccess.Data.Saver.Save(article2);

            IIndexStrategy strategy = IndexStrategy.New <TestArticle>(false);

            TestArticle[] foundArticles = strategy.Index <TestArticle>();

            Assert.IsNotNull(foundArticles);

            Assert.AreEqual(2, foundArticles.Length, "Invalid number of test articles found.");
        }
示例#13
0
        public void Flush(IStorage storage, IIndexStrategy indexStrategy)
        {
            bool isTemporary = Id.IsTemporary;

            if (isTemporary)
            {
                Id = indexStrategy.GenerateId(Id);
            }
            UnlinkReferences(isTemporary);
            if (Offset >= 0)
            {
                long num = storage.Update(this, Offset, PersistedSize);
                if (num != Offset)
                {
                    Offset = num;
                    indexStrategy.Update(Id, Offset);
                }
            }
            else
            {
                Offset = storage.Allocate(this);
                indexStrategy.Update(Id, Offset);
            }
        }
 public ScalabilityCache(IStorage storage, IIndexStrategy indexStrategy, ComponentType ownerComponent, long minReservedMemoryBytes)
     : base(storage, 3000L, 0.2, ownerComponent, minReservedMemoryBytes)
 {
     m_cachePriority = new LinkedLRUCache <StorageItem>();
     m_offsetMap     = indexStrategy;
 }