A class that is used to manage a CLI thread in a similar way that other platforms synchronize work on a UI thread
Inheritance: ObservableObject
 public TestLoadMoreDataSource(CliMessagePump pump, int numberOfObjectsToSimulate, TimeSpan maxDelay)
     : base(pump)
 {
     serverData = new List<Item>();
     this.MaxDelay = maxDelay;
     for (int i = 0; i < numberOfObjectsToSimulate; i++)
     {
         serverData.Add(new Item(i, "StringValue-" + i));
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new console app given a set of boundaries
 /// </summary>
 /// <param name="x">The left position on the target console to bound this app</param>
 /// <param name="y">The right position on the target console to bound this app</param>
 /// <param name="w">The width of the app</param>
 /// <param name="h">The height of the app</param>
 public ConsoleApp(int x, int y, int w, int h)
 {
     SetFocusOnStart = true;
     Theme           = new Theme();
     Bitmap          = new ConsoleBitmap(x, y, w, h);
     MessagePump     = new CliMessagePump(Bitmap.Console, KeyPressed);
     LayoutRoot      = new ConsolePanel {
         Width = w, Height = h
     };
     FocusManager            = new FocusManager();
     LayoutRoot.Application  = this;
     AutoFillOnConsoleResize = false;
     FocusManager.SubscribeForLifetime(nameof(FocusManager.FocusedControl), Paint, LifetimeManager);
     LayoutRoot.Controls.BeforeAdded.SubscribeForLifetime((c) => { c.Application = this; c.BeforeAddedToVisualTreeInternal(); }, LifetimeManager);
     LayoutRoot.Controls.BeforeRemoved.SubscribeForLifetime((c) => { c.BeforeRemovedFromVisualTreeInternal(); }, LifetimeManager);
     LayoutRoot.Controls.Added.SubscribeForLifetime(ControlAddedToVisualTree, LifetimeManager);
     LayoutRoot.Controls.Removed.SubscribeForLifetime(ControlRemovedFromVisualTree, LifetimeManager);
     MessagePump.WindowResized.SubscribeForLifetime(HandleDebouncedResize, LifetimeManager);
 }
Exemplo n.º 3
0
        public LoadMoreDataSource(CliMessagePump pump)
        {
            this.pump = pump;

            this.cachedData = new Dictionary <string, CachedDataSet>();
        }
 public ContainerListDataSource(CloudBlobClient client, CliMessagePump pump) : base(pump)
 {
     this.client = client;
 }
        public LoadMoreDataSource(CliMessagePump pump)
        {
            this.pump = pump;

            this.cachedData = new Dictionary<string, CachedDataSet>();
        }
Exemplo n.º 6
0
        public void LoadMoreBasic()
        {
            int expectedNumberOfItems = 95;
            CliMessagePump pump = new CliMessagePump(ConsoleProvider.Current);
            TestLoadMoreDataSource dataSource = new TestLoadMoreDataSource(pump, expectedNumberOfItems, TimeSpan.FromMilliseconds(50));

            var query = new CollectionQuery(0, 7, null);
            List<object> viewedData = new List<object>();
            var pumpTask = pump.Start();
            try
            {
                // make sure the pump has started up
                Thread.Sleep(20);

                // the first call to GetDataView should return an empty result that indicates that the view is incomplete
                // because it is still loading data
                var initialDataView = dataSource.GetDataView(query);
                Assert.IsFalse(initialDataView.IsViewComplete);
                Assert.IsFalse(initialDataView.IsViewEndOfData);
                Assert.AreEqual(0, initialDataView.Items.Count);

                // Since we're simulating the server call and we know the max amount of time it can take wait twice that long
                Thread.Sleep(dataSource.MaxDelay + dataSource.MaxDelay);

                // Now there should be a full page of data available to us
                var nextAttemptDataView = dataSource.GetDataView(query);
                Assert.AreEqual(query.Take, nextAttemptDataView.Items.Count);
                Assert.IsTrue(nextAttemptDataView.IsViewComplete);
                Assert.IsFalse(nextAttemptDataView.IsViewEndOfData);

                viewedData.AddRange(nextAttemptDataView.Items);
                query.Skip += query.Take;

                // now ask for data in a tight loop.  Sometimes we will get more data, sometimes we'll get an empty page
                // while more data is being loaded
                while (nextAttemptDataView.IsViewEndOfData == false)
                {
                    nextAttemptDataView = dataSource.GetDataView(query);

                    Console.WriteLine(nextAttemptDataView.Items.Count + " items, viewComplete == " + nextAttemptDataView.IsViewComplete);

                    if (nextAttemptDataView.Items.Count < query.Take && nextAttemptDataView.IsViewEndOfData == false)
                    {
                        Thread.Sleep(10);
                        Assert.IsFalse(nextAttemptDataView.IsViewComplete);
                    }
                    else if (nextAttemptDataView.Items.Count == query.Take)
                    {
                        Assert.IsTrue(nextAttemptDataView.IsViewComplete);
                    }
                    else if (nextAttemptDataView.Items.Count > query.Take)
                    {
                        Assert.Fail(nextAttemptDataView.Items.Count + " should never exceed " + query.Take);
                    }

                    viewedData.AddRange(nextAttemptDataView.Items);
                    query.Skip += nextAttemptDataView.Items.Count;
                }

                int nextExpectedId = 0;
                foreach (var item in viewedData)
                {
                    Assert.IsNotNull(item);
                    Console.WriteLine(item);
                    Assert.AreEqual(nextExpectedId++, ((Item)item).Id);
                }

                Assert.AreEqual(expectedNumberOfItems, viewedData.Count);
                console.Input.Enqueue(new ConsoleKeyInfo(' ', ConsoleKey.Escape, false, false, false));
            } finally
            {
                pump.Stop();
                pumpTask.Wait();
            }
        }
Exemplo n.º 7
0
 public CustomSyncContext(CliMessagePump pump)
 {
     this.pump = pump;
 }
 public TableListDataSource(CloudTableClient client, CliMessagePump pump) : base(pump)
 {
     this.client = client;
 }
 public TableEntityDataSource(CloudTable table, CliMessagePump pump) : base(pump)
 {
     this.table = table;
 }
Exemplo n.º 10
0
 public BlobDataSource(CloudBlobContainer container, CliMessagePump pump) : base(pump)
 {
     this.container = container;
 }