Exemplo n.º 1
0
        public void ComplexQuery()
        {
            SimpleClass[] someItems =
            {
                new SimpleClass {
                    Name = "Jason", Age = 25
                },
                new SimpleClass {
                    Name = "Aaron", Age = 37, FavoriteColor = Color.Green
                },
                new SimpleClass {
                    Name = "Erin", Age = 34
                },
                new SimpleClass {
                    Name = "Adriana", Age = 13
                },
            };
            var indexSpec = IndexSpecification <SimpleClass> .Build()
                            .With(person => person.FavoriteColor)
                            .And(person => person.Age);

            var theIndexSet = new IndexSet <SimpleClass>(someItems, indexSpec);
            var twoResults  =
                from item in theIndexSet
                where item.FavoriteColor == Color.Green || item.Age == 13 && item.Name == "Adriana"
                select item;

            Assert.AreEqual(2, twoResults.Count());
        }
 internal static IIndexCriteria ToIndexCriteria(this IndexSet set,
                                                IDataService svc,
                                                StaticFieldCollection indexFieldPolicies,
                                                IEnumerable <IndexField> additionalUserFields = null)
 {
     return(new LazyIndexCriteria(set, svc, indexFieldPolicies, additionalUserFields));
 }
Exemplo n.º 3
0
        public void SuperComplexQuery()
        {
            SimpleClass[] someItems =
            {
                new SimpleClass {
                    Name = "Jason Jarett", Age = 25, FavoriteColor = Color.Aqua
                },
                new SimpleClass {
                    Name = "Aaron Erickson", Age = 37, FavoriteColor = Color.Green
                },
                new SimpleClass {
                    Name = "Erin Erickson", Age = 34, FavoriteColor = Color.Green
                },
                new SimpleClass {
                    Name = "Adriana Erickson", Age = 13, FavoriteColor = Color.Aqua
                },
            };
            var indexSpec = IndexSpecification <SimpleClass> .Build()
                            .With(person => person.FavoriteColor)
                            .And(person => person.Age)
                            .And(person => person.Name);

            var theIndexSet = new IndexSet <SimpleClass>(someItems, indexSpec);
            var oneResult   =
                from item in theIndexSet
                where
                (
                    (item.FavoriteColor == Color.Green && item.Age == 37) ||
                    (item.Name == "Adriana Erickson" && item.Age == 13) ||
                    (item.Name == "Jason Jarett" && item.Age == 25)
                ) && item.Name == "Aaron Erickson"
                select item;

            Assert.AreEqual(1, oneResult.Count());
        }
Exemplo n.º 4
0
        public void should_be_able_to_get_an_enumerator_of_the_indexable_collection()
        {
            var indexedTestClasses = new IndexSet <TestClass>(TestClass.GetIndexSpec());

            Assert.IsNotNull((indexedTestClasses as IEnumerable <TestClass>).GetEnumerator());
            Assert.IsNotNull((indexedTestClasses as IEnumerable).GetEnumerator());
        }
Exemplo n.º 5
0
 public unsafe IslandScaffoldConstraintBatch(Solver solver, BufferPool pool, int batchIndex)
 {
     pool.TakeAtLeast(solver.TypeProcessors.Length, out TypeIdToIndex);
     Unsafe.InitBlockUnaligned(TypeIdToIndex.Memory, 0xFF, (uint)(TypeIdToIndex.Length * sizeof(int)));
     TypeBatches           = new QuickList <IslandScaffoldTypeBatch>(solver.TypeProcessors.Length, pool);
     ReferencedBodyIndices = batchIndex < solver.FallbackBatchThreshold ? new IndexSet(pool, solver.bodies3D.ActiveSet.Count) : default;
 }
Exemplo n.º 6
0
        public static UmbracoContentIndexer GetUmbracoIndexer(
            Lucene.Net.Store.Directory luceneDir,
            Analyzer analyzer        = null,
            IDataService dataService = null)
        {
            if (dataService == null)
            {
                dataService = new TestDataService();
            }

            if (analyzer == null)
            {
                analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
            }

            var indexSet      = new IndexSet();
            var indexCriteria = indexSet.ToIndexCriteria(dataService, UmbracoContentIndexer.IndexFieldPolicies);

            var i = new UmbracoContentIndexer(indexCriteria,
                                              luceneDir,         //custom lucene directory
                                              dataService,
                                              analyzer,
                                              false);

            //i.IndexSecondsInterval = 1;

            i.IndexingError += IndexingError;

            return(i);
        }
Exemplo n.º 7
0
        public void TestRemoveWhereContainsIndexUnorderedly()
        {
            void Test(IEnumerable <int> init, params int[] targets)
            {
                var list     = init.ToList();
                var expected = list.Where((_, i) => !targets.Contains(i)).ToList();


                var targetSet = new IndexSet();

                foreach (var t in targets)
                {
                    targetSet.Add(t);
                }

                list.RemoveWhereContainsIndexUnorderedly(targetSet);
                list.Should().BeEquivalentTo(expected);
            }

            Test(Enumerable.Range(0, 5));
            Test(Enumerable.Range(0, 5), 0, 1, 2, 3, 4);
            Test(Enumerable.Range(0, 5), 0, 4);
            Test(Enumerable.Range(0, 5), 0, 1);
            Test(Enumerable.Range(0, 5), 1, 2, 3);
            Test(Enumerable.Range(0, 5), 3, 4);
            Test(Enumerable.Range(0, 5), 1, 3);
        }
        protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
        {
            // examine fields
            var data = base.GetIndexerData(indexSet);

            // azure config
            var path          = System.Web.Hosting.HostingEnvironment.MapPath("~/");
            var serviceClient = new AzureSearchIndexClient(path);

            var examineStandardFields = data.StandardFields;
            var examineUserFields     = data.UserFields;

            var azureStandardFields = serviceClient.GetStandardUmbracoFields().ToDictionary(f => f.Name);
            var azureUserFields     = serviceClient.GetConfiguration().SearchFields.ToDictionary(f => f.Name);

            var standardToRemove    = examineStandardFields.Where(examineField => !azureStandardFields.Keys.InvariantContains(examineField.Name));
            var validStandardFields = examineStandardFields.Except(standardToRemove);

            var userToRemove    = examineUserFields.Where(examineField => !azureUserFields.Keys.InvariantContains(examineField.Name));
            var validUserFields = examineUserFields.Except(userToRemove);

            var newData = new IndexCriteria(validStandardFields, validUserFields, data.IncludeNodeTypes, data.ExcludeNodeTypes, data.ParentNodeId);

            return(newData);
        }
Exemplo n.º 9
0
        public void TestElementClass()
        {
            var iComp = new IndexSet<TestClassB>(
                new TestClassB[] {
                    new TestClassB() { T = 10 },
                    new TestClassB() { T = 20 },
                    new TestClassB() { T = 30 },
                    new TestClassB() { T = 40 }
                },
                new IndexSpecification<TestClassB>().Add(q => q.T)); ;

            Assert.AreEqual(4, iComp.Where(c => c.T2 == 0).Count());

            bool failed = false;
            try
            {
                iComp.WhereIndexed(c => c.T2 == 0).Count();
            }
            catch
            {
                failed = true;
            }

            Assert.IsTrue(failed);
        }
        /// <summary>
        /// Creates an <see cref="IIndexCriteria"/>.
        /// </summary>
        /// <param name="set">
        /// The set.
        /// </param>
        /// <param name="indexFieldNames">
        /// The index field names.
        /// </param>
        /// <param name="indexFieldPolicies">
        /// The index field policies.
        /// </param>
        /// <returns>
        /// The <see cref="IIndexCriteria"/>.
        /// </returns>
        internal static IIndexCriteria ToIndexCriteria(this IndexSet set, IEnumerable <string> indexFieldNames, IEnumerable <StaticField> indexFieldPolicies)
        {
            if (set.IndexAttributeFields.Count == 0)
            {
                foreach (var fn in indexFieldNames)
                {
                    var field = new IndexField()
                    {
                        Name = fn
                    };
                    var policy = indexFieldPolicies.FirstOrDefault(x => x.Name == fn);
                    if (policy != null)
                    {
                        field.Type          = policy.Type;
                        field.EnableSorting = policy.EnableSorting;
                    }
                    set.IndexAttributeFields.Add(field);
                }
            }

            return(new IndexCriteria(
                       set.IndexAttributeFields.Cast <IIndexField>().ToArray(),
                       set.IndexUserFields.Cast <IIndexField>().ToArray(),
                       set.IncludeNodeTypes.ToList().Select(x => x.Name).ToArray(),
                       set.ExcludeNodeTypes.ToList().Select(x => x.Name).ToArray(),
                       set.IndexParentId));
        }
        /// <summary>
        /// Ensures that the'_searchEmail' is added to the user fields so that it is indexed - without having to modify the config
        /// </summary>
        /// <param name="indexSet"></param>
        /// <returns></returns>
        protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
        {
            var indexerData = base.GetIndexerData(indexSet);

            if (CanInitialize())
            {
                //If the fields are missing a custom _searchEmail, then add it

                if (indexerData.UserFields.Any(x => x.Name == "_searchEmail") == false)
                {
                    var field = new IndexField {
                        Name = "_searchEmail"
                    };

                    StaticField policy;
                    if (IndexFieldPolicies.TryGetValue("_searchEmail", out policy))
                    {
                        field.Type          = policy.Type;
                        field.EnableSorting = policy.EnableSorting;
                    }

                    return(new IndexCriteria(
                               indexerData.StandardFields,
                               indexerData.UserFields.Concat(new[] { field }),
                               indexerData.IncludeNodeTypes,
                               indexerData.ExcludeNodeTypes,
                               indexerData.ParentNodeId
                               ));
                }
            }

            return(indexerData);
        }
Exemplo n.º 12
0
        public void CanParseIndexExpression()
        {
            var A = Tensor.TwoD("A", (4, 3), "a", out Index a, out Index b);
            var B = Tensor.TwoD("B", (6, 7));
            var C = Tensor.TwoD("C", (8, 9));
            TensorExpression te = A[a, b];

            Assert.Single(te.TensorReferences);
            Assert.Equal(A, te.TensorReferences.First());

            TensorExpressionVisitor v = new TensorExpressionVisitor(te);

            Assert.Equal(5, v.Tree.Count);
            Assert.Equal(TensorOp.Index, v.Tree.OperatorNodeAtIndex(2).Op);
            Assert.NotNull(v.Tree.OperatorNodeAtIndex(2).Left);
            Assert.NotNull(v.Tree.OperatorNodeAtIndex(2).Right);
            Assert.IsType <Tensor>(v.Tree.ValueNodeAtIndex(3).Value);
            Assert.IsType <IndexSet>(v.Tree.ValueNodeAtIndex(4).Value);

            IndexSet s = v.Tree.ValueNodeAtIndex(4).ValueAs <IndexSet>();

            Assert.Equal(2, s.Indices.Count);
            Assert.Equal(1, s.Indices.ElementAt(1).Order);
            Assert.Equal("b", s.Indices.ElementAt(1).Name);
        }
        IEnumerable<NeuralVectors> DoGetNextVectors(IndexSet indexes)
        {
            var privIndexes = new IndexSet(indexes);

            foreach (int index in privIndexes.ToList())
            {
                string key = CacheKeyPrefix + index;
                var foundVector = cache[key] as NeuralVectors;
                if (foundVector != null)
                {
                    yield return foundVector;
                    privIndexes.Remove(index);
                }
            }

            if (privIndexes.Count > 0)
            {
                var indexList = privIndexes.ToList();
                int listIndex = 0;
                foreach (var vector in BaseProvider.GetNextVectors(privIndexes))
                {
                    int vectorIndex = indexList[listIndex++];
                    string key = CacheKeyPrefix + vectorIndex;
                    cache[key] = vector;
                    keys.Add(key);
                    yield return vector;
                }
            }
        }
 protected override IEnumerable<NeuralVectors> DoGetNextVectors(IndexSet indexes)
 {
     Contract.Requires(indexes != null);
     Contract.Requires(Contract.ForAll(indexes, (index) => index >= 0 && index < ItemCount));
     Contract.Ensures(Contract.Result<IEnumerable<NeuralVectors>>() != null);
     Contract.Ensures(Contract.ForAll(Contract.Result<IEnumerable<NeuralVectors>>(), vf => vf != null));
     return null;
 }
Exemplo n.º 15
0
 protected override IEnumerable<NeuralVectorFlow> DoGetNext(IndexSet indexes)
 {
     foreach (var index in indexes)
     {
         var nv = CreateNeuralVectors(index);
         yield return nv;
     }
 }
 IEnumerable<NeuralVectorFlow> IUnorderedNeuralVectorFlowProvider.GetNext(IndexSet indexes)
 {
     IUnorderedNeuralVectorFlowProvider prov = this;
     Contract.Requires(indexes != null);
     Contract.Requires(Contract.ForAll(indexes, (index) => index >= 0 && index < prov.ItemCount));
     Contract.Ensures(Contract.Result<IEnumerable<NeuralVectorFlow>>() != null);
     Contract.Ensures(Contract.ForAll(Contract.Result<IEnumerable<NeuralVectorFlow>>(), vf => vf != null));
     return null;
 }
Exemplo n.º 17
0
        public void IndexSet_GoodData_Success()
        {
            IEnumerable <IndexSet> indexes = IndexSet.RetrieveIndexData(InstanceName, "master");

            Assert.IsNotNull(indexes);
            Assert.AreNotEqual(0, indexes.Count());
            Assert.AreEqual("master", indexes.ElementAt(0).DatabaseName);
            Assert.AreEqual(InstanceName, indexes.ElementAt(0).ServerName);
        }
 protected override void Init_internal()
 {
     IndexedLINQCellTree      = new ObservableCollection <Cell>();
     IndexedLINQCellTreeIndex = new IndexSet <Cell>(IndexedLINQCellTree, IndexSpecification <Cell> .Build()
                                                    .With(cell => cell.MinX)
                                                    .And(cell => cell.MaxX)
                                                    .And(cell => cell.MinY)
                                                    .And(cell => cell.MaxY));
 }
Exemplo n.º 19
0
        public ExpressionTree(Tensor lhsTensor, IndexSet lhsTensorIndices) : base(0, null, TreeNodePosition.RIGHT,
                                                                                  TensorOp.IndexedAssign)
        {
            HashSet.Add(this);
            var n = AddNode(CreateOperatorNode(this, TensorOp.Index)) as OperatorNode;

            AddNode(CreateValueNode(n, lhsTensor));
            AddNode(CreateValueNode(n, lhsTensorIndices));
        }
Exemplo n.º 20
0
        internal static IIndexCriteria ToIndexCriteria(this IndexSet set, IDataService svc,
                                                       IEnumerable <StaticField> indexFieldPolicies)
        {
            if (set.IndexUserFields.Count == 0)
            {
                lock (Locker)
                {
                    //we need to add all user fields to the collection if it is empty (this is the default if none are specified)
                    var userFields = svc.ContentService.GetAllUserPropertyNames();
                    foreach (var u in userFields)
                    {
                        var field = new IndexField()
                        {
                            Name = u
                        };
                        var policy = indexFieldPolicies.FirstOrDefault(x => x.Name == u);
                        if (policy != null)
                        {
                            field.Type          = policy.Type;
                            field.EnableSorting = policy.EnableSorting;
                        }
                        set.IndexUserFields.Add(field);
                    }
                }
            }

            if (set.IndexAttributeFields.Count == 0)
            {
                lock (Locker)
                {
                    //we need to add all system fields to the collection if it is empty (this is the default if none are specified)
                    var sysFields = svc.ContentService.GetAllSystemPropertyNames();
                    foreach (var s in sysFields)
                    {
                        var field = new IndexField()
                        {
                            Name = s
                        };
                        var policy = indexFieldPolicies.FirstOrDefault(x => x.Name == s);
                        if (policy != null)
                        {
                            field.Type          = policy.Type;
                            field.EnableSorting = policy.EnableSorting;
                        }
                        set.IndexAttributeFields.Add(field);
                    }
                }
            }

            return(new IndexCriteria(
                       set.IndexAttributeFields.Cast <IIndexField>().ToArray(),
                       set.IndexUserFields.Cast <IIndexField>().ToArray(),
                       set.IncludeNodeTypes.ToList().Select(x => x.Name).ToArray(),
                       set.ExcludeNodeTypes.ToList().Select(x => x.Name).ToArray(),
                       set.IndexParentId));
        }
Exemplo n.º 21
0
        public void IndexSet_GoodData_ConnectionString_Success()
        {
            string ConnectionString        = String.Format("server={0};database={1};trusted_connection=yes", InstanceName, DatabaseName);
            IEnumerable <IndexSet> indexes = IndexSet.RetrieveIndexData(InstanceName, DatabaseName, ConnectionString);

            Assert.IsNotNull(indexes);
            Assert.AreNotEqual(0, indexes.Count());
            Assert.AreEqual("master", indexes.ElementAt(0).DatabaseName);
            Assert.AreEqual(InstanceName, indexes.ElementAt(0).ServerName);
        }
Exemplo n.º 22
0
        private static void DoStuff()
        {
            var ts = DefaultSets.GetTrainingSet();
            var vs = DefaultSets.GetValidationSet();

            var tp = new FullSampleProvider(ts, Settings.Default.SampleSize);

            var idx = new IndexSet(new[] { 1, 4, 6, 7, 19 });

            var nv = tp.GetNextVectors(idx);
        }
 /// <summary>
 /// Creates an IIndexCriteria object based on the indexSet passed in and our DataService
 /// </summary>
 /// <param name="indexSet"></param>
 /// <returns></returns>
 /// <remarks>
 /// If we cannot initialize we will pass back empty indexer data since we cannot read from the database
 /// </remarks>
 protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
 {
     if (CanInitialize())
     {
         return(indexSet.ToIndexCriteria(DataService, IndexFieldPolicies));
     }
     else
     {
         return(base.GetIndexerData(indexSet));
     }
 }
Exemplo n.º 24
0
 /// <summary>
 /// Used to replace any available tokens in the index path before the lucene directory is assigned to the path
 /// </summary>
 /// <param name="indexSet"></param>
 internal static void ReplaceTokensInIndexPath(this IndexSet indexSet)
 {
     if (indexSet == null)
     {
         return;
     }
     indexSet.IndexPath = indexSet.IndexPath
                          .Replace("{machinename}", NetworkHelper.FileSafeMachineName)
                          .Replace("{appdomainappid}", (HttpRuntime.AppDomainAppId ?? string.Empty).ReplaceNonAlphanumericChars(""))
                          .EnsureEndsWith('/');
 }
Exemplo n.º 25
0
 protected override IEnumerable<NeuralVectorFlow> DoGetNext(IndexSet indexes)
 {
     using (var ctx = new LeCunDataEntities())
     {
         var selectIndexes = indexes.ToDictionary(i => indexMap[i]);
         foreach (var sample in (from s in ctx.Samples
                                 where s.IsTraining == IsTraining && selectIndexes.Keys.Contains(s.ID)
                                 select s))
         {
             yield return ToFlow(selectIndexes[sample.ID], sample);
         }
     }
 }
Exemplo n.º 26
0
        private static string GetExcludedDocTypesFilter(IndexSet indexSet)
        {
            var excludeDocs = indexSet?.ExcludeNodeTypes?.ToList();

            if (excludeDocs?.Any() == false)
            {
                return(string.Empty);
            }

            var docNames = excludeDocs?.Select(i => i?.Name) ?? Enumerable.Empty <string>();

            return($"not search.in(ContentTypeAlias, '{string.Join(", ", docNames)}')");
        }
Exemplo n.º 27
0
        /// <summary>
        /// Awakens a list of set indices.
        /// </summary>
        /// <param name="setIndices">List of set indices to wake up.</param>
        /// <param name="threadDispatcher">Thread dispatcher to use when waking the bodies3D. Pass null to run on a single thread.</param>
        public void AwakenSets(ref QuickList <int> setIndices, IThreadDispatcher threadDispatcher = null)
        {
            var uniqueSetIndices = new QuickList <int>(setIndices.Count, pool);
            var uniqueSet        = new IndexSet(pool, bodies3D.Sets.Length);

            AccumulateUniqueIndices(ref setIndices, ref uniqueSet, ref uniqueSetIndices);
            uniqueSet.Dispose(pool);

            //Note that we use the same codepath as multithreading, we just don't use a multithreaded dispatch to execute jobs.
            //TODO: It would probably be a good idea to add a little heuristic to avoid doing multithreaded dispatches if there are only like 5 total bodies3D.
            //Shouldn't matter too much- the threaded variant should only really be used when doing big batched changes, so having a fixed constant cost isn't that bad.
            int threadCount = threadDispatcher == null ? 1 : threadDispatcher.ThreadCount;

            //Note that direct wakes always reset activity states. I suspect this is sufficiently universal that no one will ever want the alternative,
            //even though the narrowphase does avoid resetting activity states for the sake of faster resleeping when possible.
            var(phaseOneJobCount, phaseTwoJobCount) = PrepareJobs(ref uniqueSetIndices, true, threadCount);

            if (threadCount > 1)
            {
                this.jobIndex = -1;
                this.jobCount = phaseOneJobCount;
                threadDispatcher.DispatchWorkers(phaseOneWorkerDelegate);
            }
            else
            {
                for (int i = 0; i < phaseOneJobCount; ++i)
                {
                    ExecutePhaseOneJob(i);
                }
            }

            if (threadCount > 1)
            {
                this.jobIndex = -1;
                this.jobCount = phaseTwoJobCount;
                threadDispatcher.DispatchWorkers(phaseTwoWorkerDelegate);
            }
            else
            {
                for (int i = 0; i < phaseTwoJobCount; ++i)
                {
                    ExecutePhaseTwoJob(i);
                }
            }

            DisposeForCompletedAwakenings(ref uniqueSetIndices);

            uniqueSetIndices.Dispose(pool);
        }
Exemplo n.º 28
0
        public void TestNonComparableIndex()
        {
            object o1 = "test";
            object o2 = 10;

            var iComp = new IndexSet<TestClassB>(
                new TestClassB[] {
                    new TestClassB() { NonComparable = o1 },
                    new TestClassB() { NonComparable = o2 }
                },
                new IndexSpecification<TestClassB>().Add(q => q.NonComparable));

            Assert.AreEqual(1, iComp.WhereIndexed(q => q.NonComparable == o1).Count());
            Assert.AreEqual(1, iComp.WhereIndexed(q => q.NonComparable == o2).Count());
        }
        public IEnumerable<NeuralVectors> GetNextVectors(IndexSet indexes)
        {
            foreach (var vector in DoGetNextVectors(indexes))
            {
                if (ReinitalizationFrequency.HasValue)
                {
                    itemsSoFar++;
                    if (itemsSoFar % ReinitalizationFrequency.Value == 0)
                    {
                        ClearCache();
                    }
                }

                yield return vector;
            }
        }
Exemplo n.º 30
0
        public void TestComparableIndex()
        {
            var iComp = new IndexSet<TestClassB>(
                new TestClassB[] {
                    new TestClassB() { T = 10 },
                    new TestClassB() { T = 20 },
                    new TestClassB() { T = 30 },
                    new TestClassB() { T = 40 }
                },
                new IndexSpecification<TestClassB>().Add(q => q.T));

            Assert.AreEqual(1, iComp.WhereIndexed(q => q.T == 20).Count());
            Assert.AreEqual(3, iComp.WhereIndexed(q => q.T >= 20).Count());
            Assert.AreEqual(2, iComp.WhereIndexed(q => q.T > 20).Count());
            Assert.AreEqual(2, iComp.WhereIndexed(q => q.T <= 20).Count());
            Assert.AreEqual(1, iComp.WhereIndexed(q => q.T < 20).Count());
        }
Exemplo n.º 31
0
        public void IndexSet_BadInstanceName_Failure()
        {
            try
            {
                IEnumerable <IndexSet> indexes = IndexSet.RetrieveIndexData(BadInstanceName, "master");
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                Assert.IsTrue(ex.Message.Contains("A network-related or instance-specific error occurred while establishing a connection to SQL Server."),
                              "An unexpected SqlException occurred:  " + ex.Message);
                return;
            }
            catch (Exception ex)
            {
                Assert.Fail("Some unexpected exception occurred:  " + ex.Message);
            }

            Assert.Fail("The test should not have gotten this far--it should have caught an exception.  Make sure that BadInstanceName really doesn't exist.");
        }
Exemplo n.º 32
0
        public void IndexSet_BadDatabaseName_Failure()
        {
            try
            {
                IEnumerable <IndexSet> indexes = IndexSet.RetrieveIndexData(InstanceName, BadDatabaseName);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                Assert.IsTrue(ex.Message.Contains("Cannot open database \"" + BadDatabaseName + "\" requested by the login. The login failed."),
                              "An unexpected SqlException occurred:  " + ex.Message);
                return;
            }
            catch (Exception ex)
            {
                Assert.Fail("Some unexpected exception occurred:  " + ex.Message);
            }

            Assert.Fail("The test should not have gotten this far--it should have caught an exception.  Make sure that BadInstanceName really doesn't exist.");
        }
Exemplo n.º 33
0
        /// <summary>
        /// Convert the indexset to indexerdata.
        /// This detects if there are no user/system fields specified and if not, uses the data service to look them
        /// up and update the in memory IndexSet.
        /// </summary>
        /// <param name="set"></param>
        /// <param name="svc"></param>
        /// <returns></returns>
        public static IIndexCriteria ToIndexCriteria(this IndexSet set, IDataService svc)
        {
            if (set.IndexUserFields.Count == 0)
            {
                lock (Locker)
                {
                    //we need to add all user fields to the collection if it is empty (this is the default if none are specified)
                    var userFields = svc.ContentService.GetAllUserPropertyNames();
                    foreach (var u in userFields)
                    {
                        set.IndexUserFields.Add(new IndexField()
                        {
                            Name = u
                        });
                    }
                }
            }

            if (set.IndexAttributeFields.Count == 0)
            {
                lock (Locker)
                {
                    //we need to add all system fields to the collection if it is empty (this is the default if none are specified)
                    var sysFields = svc.ContentService.GetAllSystemPropertyNames();
                    foreach (var s in sysFields)
                    {
                        set.IndexAttributeFields.Add(new IndexField()
                        {
                            Name = s
                        });
                    }
                }
            }

            return(new IndexCriteria(
                       set.IndexAttributeFields.Cast <IIndexField>().ToArray(),
                       set.IndexUserFields.Cast <IIndexField>().ToArray(),
                       set.IncludeNodeTypes.ToList().Select(x => x.Name).ToArray(),
                       set.ExcludeNodeTypes.ToList().Select(x => x.Name).ToArray(),
                       set.IndexParentId));
        }
Exemplo n.º 34
0
        public void CanGenerateTermNames()
        {
            var B = Tensor.FiveD(tn.B, (4, 5, 6, 7, 8));

            Assert.Equal("B", B.Name);
            var I = new IndexSet(B, "m0", B.Dimensions);

            Assert.Equal("m0", I[0].Name);
            var J = new IndexSet(B, "i0", B.Dimensions);

            Assert.Equal("i0", J[0].Name);
            var(m0, m1, m2, m3, m4) = I;
            Assert.Equal("m4", m4.Name);

            var(N1, N2, N3, N4) = Tensor.FourD("N1", (2, 7, 9, 6), "n1", out Index n1, out Index n2, out Index n3,
                                               out Index n4).Four();
            Assert.Equal("N2", N2.Name);
            Assert.Equal("N4", N4.Name);
            Assert.Equal("n3", n3.Name);
            Assert.Equal("n4", n4.Name);
        }
Exemplo n.º 35
0
        private void PopulateGrid(bool ForceRefresh)
        {
            //Show the waiting page.
            SetVisibility(PageToShow.Waiting);

            //Set the async values
            MainWindowValues mwvSetup = LoadMainWindowValues(ForceRefresh);

            System.Windows.Threading.Dispatcher d = this.Dispatcher;

            //Set up a worker
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                try
                {
                    MainWindowValues mwv = e.Argument as MainWindowValues;

                    if (mwv.ForceRefresh || mwv.DatabaseListingChanged || PrimaryGroup == null || SecondaryGroup == null)
                    {
                        PrimaryGroup   = IndexSet.RetrieveIndexData(mwv.CurrentPrimaryInstanceName, mwv.CurrentPrimaryDatabaseName);
                        SecondaryGroup = IndexSet.RetrieveIndexData(mwv.CurrentSecondaryInstanceName, mwv.CurrentSecondaryDatabaseName);
                        Groups         = IndexGroup.PopulateIndexGroups(PrimaryGroup, SecondaryGroup, mwv.IgnoreMissingTables);
                    }

                    //Now update the display
                    RefreshGridDelegate refresh = new RefreshGridDelegate(RefreshDataGrid);
                    d.BeginInvoke(refresh, mwv, Groups);
                }
                catch (Exception ex)
                {
                    ShowErrorDelegate error = new ShowErrorDelegate(ShowErrorMessage);
                    d.BeginInvoke(error, ex.Message);
                }
            };
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            worker.RunWorkerAsync(mwvSetup);
        }
        /// <summary>
        /// Ensures that the'_searchEmail' is added to the user fields so that it is indexed - without having to modify the config
        /// </summary>
        /// <param name="indexSet"></param>
        /// <returns></returns>
        protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
        {
            if (CanInitialize())
            {
                //Add a custom _searchEmail to the index criteria no matter what is in config
                var field = new IndexField {
                    Name = "_searchEmail"
                };
                StaticField policy;
                if (IndexFieldPolicies.TryGetValue("_searchEmail", out policy))
                {
                    field.Type          = policy.Type;
                    field.EnableSorting = policy.EnableSorting;
                }

                return(indexSet.ToIndexCriteria(DataService, IndexFieldPolicies,
                                                //add additional explicit fields
                                                new [] { field }));
            }
            else
            {
                return(base.GetIndexerData(indexSet));
            }
        }
 protected abstract IEnumerable<NeuralVectors> DoGetNextVectors(IndexSet indexes);
        public IEnumerable<NeuralVectors> GetNextVectors(IndexSet indexes)
        {
            EnsureInitialization();

            return DoGetNextVectors(indexes);
        }
Exemplo n.º 39
0
 protected override IEnumerable<NeuralVectorFlow> DoGetNext(IndexSet indexes)
 {
     foreach (var index in indexes) yield return GetVectors(index);
 }
Exemplo n.º 40
0
 public static void Index <T, I1, I2, E>(T value, I1 index1, I2 index2, E element)
 => IndexSet <T, I1, I2, E> .Invoke(value, index1, index2, element);
Exemplo n.º 41
0
 public static void Index <T, I, E>(T value, I index, E element)
 => IndexSet <T, I, E> .Invoke(value, index, element);
Exemplo n.º 42
0
 protected override IEnumerable<NeuralVectorFlow> DoGetNext(IndexSet indexes)
 {
     return indexes.AsParallel().Select(idx => GetVectors(idx));
 }
Exemplo n.º 43
0
        public void TestIndexSet()
        {
            var set     = new IndexSet(70);
            var set2    = new IndexSet();
            var example = new SortedSet <int>();

            void AssertEquavalent()
            {
                set.Count.Should().Be(example.Count);
                set.Should().Equal(example);
                set2.Count.Should().Be(example.Count);
                set2.Should().Equal(example);

                for (var i = 0; i < 70; i++)
                {
                    set.Contains(i).Should().Be(example.Contains(i));
                    set2.Contains(i).Should().Be(example.Contains(i));
                }
            }

            AssertEquavalent();


            void Set(int index, bool value)
            {
                if (value)
                {
                    set.Add(index).Should().Be(example.Add(index));
                    set2.Add(index);
                }
                else
                {
                    set.Remove(index).Should().Be(example.Remove(index));
                    set2.Remove(index);
                }

                AssertEquavalent();
            }

            void Clear()
            {
                set.Clear();
                set2.Clear();
                example.Clear();

                AssertEquavalent();
            }

            AssertEquavalent();


            Set(0, true);
            Set(0, true);
            Set(0, false);
            Set(1, true);
            Set(12, true);
            Set(31, true);
            Set(31, false);
            Set(32, true);
            Set(32, false);
            Set(50, true);
            Set(64, true);
            Set(64, false);

            Set(65, false);
            Set(66, true);
            Set(69, true);
            Set(69, false);


            Clear();

            Set(69, true);
            Set(68, true);

            Set(3, true);
            Set(4, true);

            for (var i = 0; i < 70; i++)
            {
                Set(i, true);
            }
        }
Exemplo n.º 44
0
 /// <summary>
 /// Creates an IIndexCriteria object based on the indexSet passed in and our DataService
 /// </summary>
 /// <param name="indexSet">
 /// The index Set.
 /// </param>
 /// <remarks>
 /// If we cannot initialize we will pass back empty indexer data since we cannot read from the database
 /// </remarks>
 /// <returns>
 /// The <see cref="IIndexCriteria"/>.
 /// </returns>
 protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
 {
     return indexSet.ToIndexCriteria(DataService.InvoiceDataService.GetIndexFieldNames(), IndexFieldPolicies);
 }
Exemplo n.º 45
0
        private void ScheduleGetNextVectors(NativeActivityContext context)
        {
            var vars = ComputationContext.GetVariables(context, this);

            var strategy = vars.Get<BatchingStrategy>(StrategyVarName);

            if (LastResult != null && !strategyHasJustInited.Get(context))
            {
                var obs = strategy as OptimizationBatchingStrategy;
                if (obs != null)
                {
                    var last = LastResult.Get(context);
                    if (!last.IsEmpty)
                    {
                        obs.SetLastResult(last);
                    }
                }
            }

            var indexSet = new IndexSet(strategy.GetNextIndexes());

            if (IsCached(context))
            {
                // Get From Cache:
                var cache = vars.Get<SerializableCache>(CacheVarName).Cache;
                // Create variable:
                var vectorsFromCache = new LinkedList<NeuralVectors>();
                cachedVectors.Set(context, vectorsFromCache);

                var newIndexSet = new IndexSet(indexSet);

                foreach (var index in indexSet)
                {
                    string key = index.ToString();
                    var cached = cache[key] as NeuralVectors;
                    if (cached != null)
                    {
                        // Cached, add to variable, and remove from indexes:
                        vectorsFromCache.AddLast(cached);
                        newIndexSet.Remove(index);
                    }
                }

                indexSet = newIndexSet;
            }

            if (indexSet.Count > 0)
            {
                // Are there any non-cached item requests? Get it!
                context.ScheduleFunc(GetNextVectors, indexSet, OnGetNextVectorsCompleted);
            }
            else
            {
                // All items was in cache, proccess'em!
                ProcessNextVectors(context, null);
            }
        }
Exemplo n.º 46
0
		public void ComplexQuery()
		{
			SimpleClass[] someItems = {
																					new SimpleClass {Name = "Jason", Age = 25},
																					new SimpleClass {Name = "Aaron", Age = 37, FavoriteColor = Color.Green},
																					new SimpleClass {Name = "Erin", Age = 34},
																					new SimpleClass {Name = "Adriana", Age = 13},
																			};
			var indexSpec = IndexSpecification<SimpleClass>.Build()
					.With(person => person.FavoriteColor)
					.And(person => person.Age);
			var theIndexSet = new IndexSet<SimpleClass>(someItems, indexSpec);
			var twoResults =
					from item in theIndexSet
					where item.FavoriteColor == Color.Green || item.Age == 13 && item.Name == "Adriana"
					select item;
			Assert.AreEqual(2, twoResults.Count());
		}
Exemplo n.º 47
0
        public void GenerateTestData()
        {
            //Quick description of indexes:
            //isp1 = iss1
                //isp1 is for the Primary list and iss1 for the Secondary list
            //isp2 is unique
            //iss2 is unique
            //isp3 ~= iss3
                //The primary columns match, but there are secondary column differences
            //isp4 ~= iss4
                //The primary columns match, but there are secondary column differences

            PrimaryIndexes = new List<BusinessObjects.IndexSet>();
            SecondaryIndexes = new List<BusinessObjects.IndexSet>();

            isp1 = new IndexSet();
            isp1.ServerName = "Server 1";
            isp1.DatabaseName = "Database 1";
            isp1.SchemaName = "dbo";
            isp1.TableName = "Table1";
            isp1.IndexName = "Index1";
            isp1.IndexType = "CLUSTERED";
            isp1.IndexIsUnique = true;
            isp1.Columns = "ID";
            isp1.IncludedColumns = String.Empty;
            isp1.HasFilter = false;
            isp1.FilterDefinition = String.Empty;

            isp2 = new IndexSet();
            isp2.ServerName = "Server 1";
            isp2.DatabaseName = "Database 1";
            isp2.SchemaName = "dbo";
            isp2.TableName = "Table1";
            isp2.IndexName = "Index6";
            isp2.IndexType = "CLUSTERED";
            isp2.IndexIsUnique = true;
            isp2.Columns = "ID";
            isp2.IncludedColumns = String.Empty;
            isp2.HasFilter = false;
            isp2.FilterDefinition = String.Empty;

            isp3 = new IndexSet();
            isp3.ServerName = "Server 1";
            isp3.DatabaseName = "Database 1";
            isp3.SchemaName = "dbo";
            isp3.TableName = "Table2";
            isp3.IndexName = "Index6";
            isp3.IndexType = "NONCLUSTERED";
            isp3.IndexIsUnique = true;
            isp3.Columns = "ID,Column6";
            isp3.IncludedColumns = "SomeColumn";
            isp3.HasFilter = false;
            isp3.FilterDefinition = "(ID < 50)";

            isp4 = new IndexSet();
            isp4.ServerName = "Server 1";
            isp4.DatabaseName = "Database 1";
            isp4.SchemaName = "dbo";
            isp4.TableName = "Table2";
            isp4.IndexName = "IndexX";
            isp4.IndexType = "CLUSTERED";
            isp4.IndexIsUnique = true;
            isp4.Columns = "ID";
            isp4.IncludedColumns = String.Empty;
            isp4.HasFilter = false;
            isp4.FilterDefinition = String.Empty;

            iss1 = new IndexSet();
            iss1.ServerName = "Server 1";
            iss1.DatabaseName = "Database 1";
            iss1.SchemaName = "dbo";
            iss1.TableName = "Table1";
            iss1.IndexName = "Index1";
            iss1.IndexType = "CLUSTERED";
            iss1.IndexIsUnique = true;
            iss1.Columns = "ID";
            iss1.IncludedColumns = String.Empty;
            iss1.HasFilter = false;
            iss1.FilterDefinition = String.Empty;

            iss2 = new IndexSet();
            iss2.ServerName = "Server 1";
            iss2.DatabaseName = "Database 1";
            iss2.SchemaName = "dbo";
            iss2.TableName = "Table1";
            iss2.IndexName = "Index51";
            iss2.IndexType = "NONCLUSTERED";
            iss2.IndexIsUnique = true;
            iss2.Columns = "ID";
            iss2.IncludedColumns = String.Empty;
            iss2.HasFilter = false;
            iss2.FilterDefinition = String.Empty;

            iss3 = new IndexSet();
            iss3.ServerName = "Server 1";
            iss3.DatabaseName = "Database 1";
            iss3.SchemaName = "dbo";
            iss3.TableName = "Table2";
            iss3.IndexName = "Index6";
            iss3.IndexType = "NONCLUSTERED";
            iss3.IndexIsUnique = true;
            iss3.Columns = "ID,Column4";
            iss3.IncludedColumns = "SomeColumn2";
            iss3.HasFilter = false;
            iss3.FilterDefinition = "(ID < 50)";

            iss4 = new IndexSet();
            iss4.ServerName = "Server 1";
            iss4.DatabaseName = "Database 1";
            iss4.SchemaName = "dbo";
            iss4.TableName = "Table2";
            iss4.IndexName = "IndexX";
            iss4.IndexType = "HEAP";
            iss4.IndexIsUnique = true;
            iss4.Columns = "ID";
            iss4.IncludedColumns = String.Empty;
            iss4.HasFilter = false;
            iss4.FilterDefinition = String.Empty;
        }
Exemplo n.º 48
0
        private void ScheduleGetNextVectors(NativeActivityContext context)
        {
            var vars = ComputationContext.GetVariables(context, this);

            var strategy = vars.Get<BatchingStrategy>(StrategyVarName);

            if (LastResult != null)
            {
                var obs = strategy as OptimizationBatchingStrategy;
                if (obs != null)
                {
                    var last = LastResult.Get(context);
                    if (!last.IsEmpty)
                    {
                        obs.SetLastResult(last);
                    }
                }
            }

            var indexSet = new IndexSet(strategy.GetNextIndexes());



            context.ScheduleFunc(GetNextVectors, indexSet, OnGetNextVectorsCompleted);
        }
Exemplo n.º 49
0
 /// <summary>
 /// Creates an IIndexCriteria object based on the indexSet passed in and our DataService
 /// </summary>
 /// <param name="indexSet">
 /// The index Set.
 /// </param>
 /// <remarks>
 /// If we cannot initialize we will pass back empty indexer data since we cannot read from the database
 /// </remarks>
 /// <returns>
 /// The <see cref="IIndexCriteria"/>.
 /// </returns>
 protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
 {
     return(indexSet.ToIndexCriteria(DataService.OrderDataService.GetIndexFieldNames(), IndexFieldPolicies));
 }
Exemplo n.º 50
0
		public void SuperComplexQuery()
		{
			SimpleClass[] someItems = {
																					new SimpleClass {Name = "Jason Jarett", Age = 25, FavoriteColor = Color.Aqua},
																					new SimpleClass {Name = "Aaron Erickson", Age = 37, FavoriteColor = Color.Green},
																					new SimpleClass {Name = "Erin Erickson", Age = 34, FavoriteColor = Color.Green},
																					new SimpleClass {Name = "Adriana Erickson", Age = 13, FavoriteColor = Color.Aqua},
																			};
			var indexSpec = IndexSpecification<SimpleClass>.Build()
					.With(person => person.FavoriteColor)
					.And(person => person.Age)
					.And(person => person.Name);
			var theIndexSet = new IndexSet<SimpleClass>(someItems, indexSpec);
			var oneResult =
					from item in theIndexSet
					where
					(
						(item.FavoriteColor == Color.Green && item.Age == 37) ||
						(item.Name == "Adriana Erickson" && item.Age == 13) ||
						(item.Name == "Jason Jarett" && item.Age == 25)
					) && item.Name == "Aaron Erickson"
					select item;
			Assert.AreEqual(1, oneResult.Count());
		}