protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Array == null || Index1 == null || Index2 == null)
            {
                return(Completion.Exception(Language.NullException, this));
            }
            var a = Array.Execute(enviroment);

            if (!a.IsValue)
            {
                return(a);
            }
            if (!(a.ReturnValue is object[, ]))
            {
                return(Completion.Exception(Language.NotNumberException, Array));
            }

            object[,] arra = a.ReturnValue as object[, ];

            var i = Index1.Execute(enviroment);

            if (!i.IsValue)
            {
                return(i);
            }
            if (!(i.ReturnValue is int))
            {
                return(Completion.Exception(Language.NotNumberException, Index1));
            }
            var iv = (int)i.ReturnValue;

            var r = Index2.Execute(enviroment);

            if (!r.IsValue)
            {
                return(r);
            }
            if (!(r.ReturnValue is int))
            {
                return(Completion.Exception(Language.NotNumberException, Index2));
            }
            var jv = (int)r.ReturnValue;

            if (iv < 0 && iv >= arra.GetLength(0))
            {
                return(Completion.Exception(Language.IndexOutOfRangeException, Index1));
            }
            if (jv < 0 && jv >= arra.GetLength(1))
            {
                return(Completion.Exception(Language.IndexOutOfRangeException, Index2));
            }
            try
            {
                return(new Completion(arra[iv, jv]));
            }catch (Exception e)
            {
                return(Completion.Exception(e.Message, this));
            }
        }
Exemplo n.º 2
0
        public void StalenessShouldWorkProperlyWhenReferenceIsChanged()
        {
            using (var store = GetDocumentStore())
            {
                var index1 = new Index1();
                index1.Execute(store);

                var index2 = new Index2();
                index2.Execute(store);

                using (var session = store.OpenSession())
                {
                    var address = new Address
                    {
                        City = "New York"
                    };

                    session.Store(address);
                    session.Store(new User
                    {
                        AddressId = address.Id
                    });

                    session.SaveChanges();
                }

                Indexes.WaitForIndexing(store);

                var stats = store.Maintenance.Send(new GetIndexStatisticsOperation(index1.IndexName));
                Assert.False(stats.IsStale);
                stats = store.Maintenance.Send(new GetIndexStatisticsOperation(index2.IndexName));
                Assert.False(stats.IsStale);

                store.Maintenance.Send(new StopIndexingOperation());

                stats = store.Maintenance.Send(new GetIndexStatisticsOperation(index1.IndexName));
                Assert.False(stats.IsStale);
                stats = store.Maintenance.Send(new GetIndexStatisticsOperation(index2.IndexName));
                Assert.False(stats.IsStale);

                using (var session = store.OpenSession())
                {
                    var address = session.Load <Address>("addresses/1-A");
                    address.City = "Barcelona";

                    session.SaveChanges();
                }

                stats = store.Maintenance.Send(new GetIndexStatisticsOperation(index1.IndexName));
                Assert.True(stats.IsStale);
                stats = store.Maintenance.Send(new GetIndexStatisticsOperation(index2.IndexName));
                Assert.True(stats.IsStale);

                store.Maintenance.Send(new StartIndexingOperation());

                Indexes.WaitForIndexing(store);

                stats = store.Maintenance.Send(new GetIndexStatisticsOperation(index1.IndexName));
                Assert.False(stats.IsStale);
                stats = store.Maintenance.Send(new GetIndexStatisticsOperation(index2.IndexName));
                Assert.False(stats.IsStale);
            }
        }