Пример #1
0
        /// <summary>
        /// Class constructor.
        /// </summary>
        public AppViewModel()
        {
            DummySuggestions = new DummySuggestions();

            // Construct SuggestBoxAuto properties
            FakeViewModel fvm = new FakeViewModel();

            SuggestBoxAuto_SuggestSources = new AutoSuggestSource(new LocationIndicator(fvm));
            SuggestBoxAuto_SuggestSources.SetProcessing(true);
            var t = ConstructHierarchy(fvm);

            t.ContinueWith((result) =>
            {
                SuggestBoxAuto_SuggestSources.SetProcessing(false);
            });

            // Construct SuggestBoxAuto2 properties
            var fakeViewModel = new LocationIndicator(FakeViewModel.GenerateFakeViewModels(TimeSpan.FromSeconds(0.5)));

            SuggestBoxAuto2_SuggestSources = new AutoSuggestSource(fakeViewModel);

            // Construct properties for diskpath suggestion demo
            SuggestDirectory = new DirectorySuggestSource();
            SuggestDirectoryWithRecentList = new DirectorySuggestSource();

            _RecentLocationItemsItemsLock = new object();
            _RecentLocationItems          = new ObservableCollection <string>();
            BindingOperations.EnableCollectionSynchronization(_RecentLocationItems, _RecentLocationItemsItemsLock);

            _RecentLocationItems.Add("C:");
            _RecentLocationItems.Add("D:");
            _RecentLocationItems.Add("E:");
            _RecentLocationItems.Add("F:");
        }
Пример #2
0
        /// <summary>
        /// Returns a tree of <see cref="FakeViewModel"/> items with a depth
        /// of <paramref name="iLevels"/> and
        /// a number of <paramref name="iSubDirectories"/> per item.
        ///
        /// Be careful when playing with these parameters because memory consumption
        /// grows exponentially if you increase both parameters or only one of them
        /// by a large amount :-(
        /// </summary>
        /// <param name="fvm"></param>
        /// <param name="iLevels"></param>
        /// <param name="iSubDirectories"></param>
        /// <returns></returns>
        private Task <FakeViewModel> ConstructHierarchy(
            FakeViewModel fvm,
            int iLevels         = 9,
            int iSubDirectories = 5)
        {
            return(Task.Run(() =>
            {
                List <FakeViewModel> models = new List <FakeViewModel>();
                int counter = 0;
                Queue <Tuple <int, FakeViewModel> > queue = new Queue <Tuple <int, FakeViewModel> >();

                if (fvm != null)
                {
                    queue.Enqueue(new Tuple <int, FakeViewModel>(0, fvm));
                }

                while (queue.Count() > 0)
                {
                    var queueItem = queue.Dequeue();
                    int iLevel = queueItem.Item1;
                    FakeViewModel current = queueItem.Item2;

                    if (iLevel < iLevels)
                    {
                        models.Clear();
                        for (int i = 0; i < iSubDirectories; i++, counter++)
                        {
                            string nextItem = "Sub" + (iLevel + 1) + "_" + counter;
                            var vm = new FakeViewModel()
                            {
                                Header = nextItem,
                                Value = (current.Value + "\\" + nextItem),
                                //Latency = TimeSpan.FromSeconds(0.1),
                                Parent = current
                            };

                            if (iLevel == 0)
                            {
                                vm.Value = nextItem;
                            }

                            current.AddSubDirectoryItem(vm);
                            models.Add(vm);
                        }

                        if (iLevel + 1 <= iLevels) // end this as soon as we reached the max level
                        {
                            foreach (var item in models)
                            {
                                queue.Enqueue(new Tuple <int, FakeViewModel>(iLevel + 1, item));
                            }
                        }
                    }
                }

                return fvm;
            }));
        }
Пример #3
0
        public static FakeViewModel GenerateFakeViewModels(TimeSpan latency)
        {
            var root = new FakeViewModel()
            {
                Latency = latency
            };

            generate(root, 5);
            return(root);
        }
Пример #4
0
 private static void generate(FakeViewModel root, int level, string str = "")
 {
     if (level > 0)
     {
         for (int i = 1; i < 5; i++)
         {
             var vm = new FakeViewModel()
             {
                 Header  = "Sub" + str + i.ToString(),
                 Value   = (root.Value + "\\Sub" + str + i.ToString()).TrimStart('\\'),
                 Latency = root.Latency,
                 Parent  = root
             };
             generate(vm, level - 1, str + i.ToString());
             root._subDirectories.Add(vm);
         }
     }
 }
Пример #5
0
 /// <summary>
 /// Add another childitem into the collection.
 /// </summary>
 /// <param name="item"></param>
 public void AddSubDirectoryItem(FakeViewModel item)
 {
     _subDirectories.Add(item);
 }