Ejemplo n.º 1
0
        public Form1()
        {
            // initialise
            InitializeComponent();
            FormClosing += Form1_FormClosing;
            FormClosed  += Form1_FormClosed;
            Resize      += Form1_Resize;

            ApplicationEvents.Instance.Start();

            // setup lists
            SetupServerList();

            // show server tab if no servers setup
            if (Servers == default(IList <CIServer>) || !Servers.Any())
            {
                tabControl1.SelectedTab = ServersTab;
            }

            // setup notify event
            TaskbarNotifier.BalloonTipClicked += TaskbarNotifier_BalloonTipClicked;
            TaskbarNotifier.MouseDoubleClick  += TaskbarNotifier_MouseDoubleClick;

            // start parallel task
            JobTask    = new JobTask(UpdateJobsList);
            NotifyTask = new NotifyTask(NotifyJob);
            Task.Run(() => Parallel.ForEach(new ITask[] { JobTask, NotifyTask }, task => task.Run()));
        }
Ejemplo n.º 2
0
        private static ViewModelState ToViewModelState(NotifyTask notifyTask)
        {
            if (notifyTask == null)
            {
                return(new ViewModelState(DisplayState.NotStarted));
            }

            if (notifyTask.IsSuccessfullyCompleted)
            {
                return(new ViewModelState(DisplayState.Result));
            }

            if (notifyTask.IsFaulted)
            {
                return(new ViewModelState(
                           DisplayState.Error,
                           notifyTask.InnerException is CommunicationException ? ErrorType.Communication : ErrorType.Unhandled));
            }

            if (notifyTask.IsNotCompleted)
            {
                return(new ViewModelState(DisplayState.Loading));
            }

            throw new InvalidOperationException("Shouldn't get there: a task is either Completed or not");
        }
        private void LongTapAction(UIGestureRecognizerState state)
        {
            switch (state)
            {
            case UIGestureRecognizerState.Began:
                break;

            case UIGestureRecognizerState.Ended:
                if (_longCommand == null)
                {
                    TapAction();
                }
                else
                {
                    NotifyTask.Create(
                        async() =>
                    {
                        await Task.Delay(50);
                        _longCommand.Execute(_longParameter);
                    });
                }

                break;

            case UIGestureRecognizerState.Cancelled:
            case UIGestureRecognizerState.Failed:
                break;
            }
        }
Ejemplo n.º 4
0
        public static ViewModelState ToViewModelState <TResult>(this NotifyTask <TResult> notifyTask)
        {
            if (notifyTask == null)
            {
                return(new ViewModelState(DisplayState.NotStarted));
            }

            if (notifyTask.IsSuccessfullyCompleted)
            {
                var collection = notifyTask.Result as ICollection;
                if (collection?.Count == 0 || notifyTask.Result == null)
                {
                    return(new ViewModelState(DisplayState.Error, ErrorType.NoResults));
                }

                return(new ViewModelState(DisplayState.Result));
            }

            if (notifyTask.IsFaulted)
            {
                return(new ViewModelState(
                           DisplayState.Error,
                           notifyTask.InnerException is CommunicationException ? ErrorType.Communication : ErrorType.Unhandled));
            }

            if (notifyTask.IsNotCompleted)
            {
                return(new ViewModelState(DisplayState.Loading));
            }

            throw new InvalidOperationException("Shouldn't get there: a task is either Completed or not");
        }
Ejemplo n.º 5
0
        public void PropertyChanged_NoListeners_DoesNotThrow()
        {
            var tcs      = new TaskCompletionSource <object>();
            var notifier = NotifyTask.Create(() => (Task)tcs.Task);

            tcs.SetResult(null);
        }
Ejemplo n.º 6
0
 public DebtBookPageViewModel(IStore <Debt> store, INavigationService navigationService)
 {
     Title              = "Długi";
     DebtStore          = store;
     _navigationService = navigationService;
     InitializeTask     = NotifyTask.Create(InitializeAsync);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Direct workflow View => ViewModel
        /// </summary>
        public void Load(Action <ViewModelState> onLoadCompleted)
        {
            _loadingTask = new NotifyTaskBase.Builder <SillyDudeModel>(() => LoadSillyDude(_sillyDudeId))
                           .WithWhenCompleted(() => onLoadCompleted(GetState()))
                           .Build();

            _loadingTask.Start();
        }
 private void TapAction()
 {
     NotifyTask.Create(async() =>
     {
         await Task.Delay(50);
         _tapCommand?.Execute(_tapParameter);
     });
 }
Ejemplo n.º 9
0
 public MainWindowViewModel(InventoryContext context)
 {
     this._context          = context;
     this.AsyncCommandTest1 = new AsyncCommand(() => Task.Run(() => this.Populate()));
     this.completed         = NotifyTask.Create(this.AsyncCommandTest1.Execution.TaskCompleted);
     this._context.InventoryItems.OfType <Product>().Include(e => e.Instances).Include(e => e.Lots).Include(e => e.ProductType).Include(e => e.Warehouse).LoadAsync();
     this.LabelText = "Text Here";
 }
        public JobListViewModel(INavigation navigation)
        {
            _navigation = navigation;

            _jobsService = new JobsService();

            GetJobsNotifier = NotifyTask.Create(GetJobsAsync);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Tries to connect.
        /// </summary>
        public void TryConnect()
        {
            if (!Settings.IsValid || HasConnected)
            {
                return;
            }

            ConnectionTask = new NotifyTask(Connect(Settings.GetSettings()));
        }
Ejemplo n.º 12
0
 public ContactBookPageViewModel(IStore <Contact> store, INavigationService navigationService)
 {
     Title              = "Kontakty";
     ContactStore       = store;
     _navigationService = navigationService;
     InitializeTask     = NotifyTask.Create(InitializeAsync);
     AddContactCommand  = new AsyncCommand(AddContactAsync);
     SelectCommand      = new DelegateCommand <Contact>(SelectItem);
 }
Ejemplo n.º 13
0
        private void AddNotifyTask(GuildSettings guild, Notify notify)
        {
            var notifyHashCode = guild.Notifys[guild.Notifys.IndexOf(notify)].GetHashCode();
            var task           = new NotifyTask(() =>
            {
                if (_client.ConnectionState != ConnectionState.Connected)
                {
                    RaiseLog(LogSeverity.Warning, $"No connection to perform notify task.");
                    return;
                }
                var newNotifyEntry = guild.Notifys.Find(n => n.GetHashCode() == notifyHashCode);
                if (newNotifyEntry.Info.SourceId == null)
                {
                    var obj = _vk.ResolveScreeName(newNotifyEntry.Info.SourceDomain);
                    newNotifyEntry.Info.SourceId = obj.Id;
                    if (obj.Type == VkNet.Enums.VkObjectType.Group)
                    {
                        newNotifyEntry.Info.SourceId *= -1;
                    }
                }
                var posts = CheckWallPosts(newNotifyEntry);
                if (posts.Count != 0)
                {
                    var typingState      = ((SocketTextChannel)_client.GetChannel(notify.Info.ChannelId)).EnterTypingState();
                    DateTime?newLastSent = newNotifyEntry.LastSent;
                    posts.ForEach((post) => newLastSent = newLastSent < post.Date ? post.Date : newLastSent);
                    newNotifyEntry.LastCheck            = DateTime.Now;
                    newNotifyEntry.LastSent             = (DateTime)newLastSent;
                    guild.Notifys.Remove(guild.Notifys.Find(n => n.GetHashCode() == notifyHashCode));
                    guild.Notifys.Add(newNotifyEntry);
                    notifyHashCode = newNotifyEntry.GetHashCode();
                    _data.UpdateGuildSettings(guild.GuildId, guild);
                    SentNotify(posts, newNotifyEntry.Info);
                    typingState.Dispose();
                }
            }, notify.Info, DataManager.BotSettings.NotifyDueTime, notify.Info.UpdatePeriod * MILLISECONDS_PER_MINUTE);

            task.TaskStarted += (t) =>
            {
                RaiseLog(LogSeverity.Debug, $"Notify task started. TaskId={t.Id}");
            };
            task.TaskEnded += (t, result) =>
            {
                var severety = LogSeverity.Debug;
                if (result == TaskStatus.Canceled || result == TaskStatus.Faulted)
                {
                    severety = LogSeverity.Warning;
                }
                RaiseLog(severety, $"Notify task ended. TaskId={t.Id} Result={result.ToString()}");
            };
            if (!_notifys.ContainsKey(guild.GuildId))
            {
                _notifys.Add(guild.GuildId, new List <NotifyTask>());
            }
            _notifys[guild.GuildId].Add(task);
            RaiseLog(LogSeverity.Debug, $"Added notify task. GuildId={guild.GuildId}");
        }
Ejemplo n.º 14
0
 private void ViewOnClick(object sender, EventArgs eventArgs)
 {
     NotifyTask.Create(
         async() =>
     {
         await Task.Delay(50);
         TapCommandEffect.GetTap(Element)?.Execute(TapCommandEffect.GetTapParameter(Element));
     });
 }
Ejemplo n.º 15
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var task = Task.Run(async() =>
            {
                await Task.Delay(5000);
                return("test");
            });

            return(NotifyTask.Create(task));
        }
        private async Task ExecuteLoadData(object args)
        {
            var notifyTask = NotifyTask.Create(LoadData);

            if (notifyTask.IsCompleted)
            {
                Info = notifyTask.Result as ObservableCollection <ItemInfo>;
                OnPropertyChanged(nameof(Info));
            }
        }
Ejemplo n.º 17
0
        public void NotifierT_TaskCompletesSuccessfully_NotifiesProperties()
        {
            var tcs                                 = new TaskCompletionSource <object>();
            var notifier                            = NotifyTask.Create(() => tcs.Task);
            var result                              = new object();
            var taskNotification                    = TestUtils.PropertyNotified(notifier, n => n.Task);
            var statusNotification                  = TestUtils.PropertyNotified(notifier, n => n.Status);
            var isCompletedNotification             = TestUtils.PropertyNotified(notifier, n => n.IsCompleted);
            var isSuccessfullyCompletedNotification = TestUtils.PropertyNotified(notifier, n => n.IsSuccessfullyCompleted);
            var isCanceledNotification              = TestUtils.PropertyNotified(notifier, n => n.IsCanceled);
            var isFaultedNotification               = TestUtils.PropertyNotified(notifier, n => n.IsFaulted);
            var exceptionNotification               = TestUtils.PropertyNotified(notifier, n => n.Exception);
            var innerExceptionNotification          = TestUtils.PropertyNotified(notifier, n => n.InnerException);
            var errorMessageNotification            = TestUtils.PropertyNotified(notifier, n => n.ErrorMessage);
            var resultNotification                  = TestUtils.PropertyNotified(notifier, n => n.Result);

            Assert.AreSame(tcs.Task, notifier.Task);
            Assert.False(notifier.TaskCompleted.IsCompleted);
            Assert.AreEqual(tcs.Task.Status, notifier.Status);
            Assert.False(notifier.IsCompleted);
            Assert.True(notifier.IsNotCompleted);
            Assert.False(notifier.IsSuccessfullyCompleted);
            Assert.Null(notifier.Result);
            Assert.False(notifier.IsCanceled);
            Assert.False(notifier.IsFaulted);
            Assert.Null(notifier.Exception);
            Assert.Null(notifier.InnerException);
            Assert.Null(notifier.ErrorMessage);

            tcs.SetResult(result);

            Assert.AreSame(tcs.Task, notifier.Task);
            Assert.True(notifier.TaskCompleted.IsCompleted && !notifier.TaskCompleted.IsCanceled && !notifier.TaskCompleted.IsFaulted);
            Assert.AreEqual(tcs.Task.Status, notifier.Status);
            Assert.True(notifier.IsCompleted);
            Assert.False(notifier.IsNotCompleted);
            Assert.True(notifier.IsSuccessfullyCompleted);
            Assert.AreSame(result, notifier.Result);
            Assert.False(notifier.IsCanceled);
            Assert.False(notifier.IsFaulted);
            Assert.Null(notifier.Exception);
            Assert.Null(notifier.InnerException);
            Assert.Null(notifier.ErrorMessage);

            Assert.False(taskNotification());
            Assert.True(statusNotification());
            Assert.True(isCompletedNotification());
            Assert.True(isSuccessfullyCompletedNotification());
            Assert.False(isCanceledNotification());
            Assert.False(isFaultedNotification());
            Assert.False(exceptionNotification());
            Assert.False(innerExceptionNotification());
            Assert.False(errorMessageNotification());
            Assert.True(resultNotification());
        }
Ejemplo n.º 18
0
        public void NotifierT_TaskFaulted_NotifiesProperties()
        {
            var tcs                                 = new TaskCompletionSource <object>();
            var notifier                            = NotifyTask.Create(() => tcs.Task);
            var exception                           = new NotImplementedException(Guid.NewGuid().ToString("N"));
            var taskNotification                    = TestUtils.PropertyNotified(notifier, n => n.Task);
            var statusNotification                  = TestUtils.PropertyNotified(notifier, n => n.Status);
            var isCompletedNotification             = TestUtils.PropertyNotified(notifier, n => n.IsCompleted);
            var isSuccessfullyCompletedNotification = TestUtils.PropertyNotified(notifier, n => n.IsSuccessfullyCompleted);
            var isCanceledNotification              = TestUtils.PropertyNotified(notifier, n => n.IsCanceled);
            var isFaultedNotification               = TestUtils.PropertyNotified(notifier, n => n.IsFaulted);
            var exceptionNotification               = TestUtils.PropertyNotified(notifier, n => n.Exception);
            var innerExceptionNotification          = TestUtils.PropertyNotified(notifier, n => n.InnerException);
            var errorMessageNotification            = TestUtils.PropertyNotified(notifier, n => n.ErrorMessage);
            var resultNotification                  = TestUtils.PropertyNotified(notifier, n => n.Result);

            Assert.Same(tcs.Task, notifier.Task);
            Assert.False(notifier.TaskCompleted.IsCompleted);
            Assert.Equal(tcs.Task.Status, notifier.Status);
            Assert.False(notifier.IsCompleted);
            Assert.True(notifier.IsNotCompleted);
            Assert.False(notifier.IsSuccessfullyCompleted);
            Assert.Null(notifier.Result);
            Assert.False(notifier.IsCanceled);
            Assert.False(notifier.IsFaulted);
            Assert.Null(notifier.Exception);
            Assert.Null(notifier.InnerException);
            Assert.Null(notifier.ErrorMessage);

            tcs.SetException(exception);

            Assert.Same(tcs.Task, notifier.Task);
            Assert.True(notifier.TaskCompleted.IsCompleted && !notifier.TaskCompleted.IsCanceled && !notifier.TaskCompleted.IsFaulted);
            Assert.Equal(tcs.Task.Status, notifier.Status);
            Assert.True(notifier.IsCompleted);
            Assert.False(notifier.IsNotCompleted);
            Assert.False(notifier.IsSuccessfullyCompleted);
            Assert.Null(notifier.Result);
            Assert.False(notifier.IsCanceled);
            Assert.True(notifier.IsFaulted);
            Assert.NotNull(notifier.Exception);
            Assert.Same(exception, notifier.InnerException);
            Assert.Equal(exception.Message, notifier.ErrorMessage);

            Assert.False(taskNotification());
            Assert.True(statusNotification());
            Assert.True(isCompletedNotification());
            Assert.False(isSuccessfullyCompletedNotification());
            Assert.False(isCanceledNotification());
            Assert.True(isFaultedNotification());
            Assert.True(exceptionNotification());
            Assert.True(innerExceptionNotification());
            Assert.True(errorMessageNotification());
            Assert.False(resultNotification());
        }
Ejemplo n.º 19
0
        public override void Load(object parameter)
        {
            if (parameter is ObservableCollection <SillyDudeVmo> observableDudes)
            {
                SillyPeople = observableDudes;
                RaisePropertyChanged(nameof(SillyPeople));
                return;
            }

            NotifyTask.Create(NavigationService.NavigateBackAsync(typeof(SortSillyPeopleVm)));
        }
Ejemplo n.º 20
0
        public void NotifierT_NonDefaultResult_TaskCanceled_KeepsNonDefaultResult()
        {
            var tcs           = new TaskCompletionSource <object>();
            var defaultResult = new object();
            var notifier      = NotifyTask.Create(() => tcs.Task, defaultResult);

            Assert.Same(defaultResult, notifier.Result);

            tcs.SetCanceled();

            Assert.Same(defaultResult, notifier.Result);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Launch the loading of a data page.
        /// If a task is currently running, it gets discarded (callbacks won't be called).
        /// If the first page loading is asked whereas one or several pages have already been loaded, a "refresh" is detected.
        /// </summary>
        /// <param name="pageNumber">The page number to load (pageNumber = 1 for the first page).</param>
        /// <param name="calledFromScroll">True if LoadPage has been called from OnScroll method of the IInfiniteListLoader.</param>
        public Task <PageResult <TResult> > LoadPage(int pageNumber, bool calledFromScroll = false)
        {
            //Contract.Requires(() => pageNumber > 0);
            //Contract.Requires(
            //    () => calledFromScroll || (pageNumber == 1 || pageNumber == (PageLoadedCount + 1)),
            //    "The paginator can only load sequential pages");

            //InternalLogger.Info($"Requesting page n°{pageNumber} load, {PageLoadedCount} pages loaded so far");
            lock (_syncRoot)
            {
                if (calledFromScroll)
                {
                    if (pageNumber <= PageLoadedCount)
                    {
                        //InternalLogger.Info($"Aborting IInfiniteListLoader call: only a direct call to LoadPage can lead to a refresh");
                        return(Task.FromResult(PageResult <TResult> .Empty));
                    }
                }

                if (pageNumber > PageLoadedCount && IsFull)
                {
                    //InternalLogger.Info($"Cannot load page {pageNumber} total item count has already been reached ({TotalCount})");
                    return(Task.FromResult(PageResult <TResult> .Empty));
                }

                if (pageNumber == 1 && PageLoadedCount > 0)
                {
                    //InternalLogger.Info("Refresh detected");
                    _refreshRequested = true;
                }
                else
                {
                    _refreshRequested = false;
                }

                if (LoadingTask != null && LoadingTask.IsNotCompleted)
                {
                    // Cancels callbacks of previous task if not completed
                    LoadingTask.CancelCallbacks();
                }

                LoadingTask = new NotifyTask <PageResult <TResult> > .Builder(
                    () => _pageSourceLoader(pageNumber, PageSize, _refreshRequested))
                              .WithWhenSuccessfullyCompleted(OnPageRetrieved)
                              .WithWhenCompleted(OnTaskCompleted)
                              .Build();

                //InternalLogger.Info($"Page n°{pageNumber} loading started");
                LoadingTask.Start();
                return(LoadingTask.Task);
            }
        }
Ejemplo n.º 22
0
        public aVMTabBase()
        {
            this._TaskCargando = new ObservableCollection <INotifyTask>();
            this._TaskCargando.CollectionChanged += TaskCargando_OnCollectionChanged;

            NotifyTask initializeOwnersTask = NotifyTask.Create(InitializeOwners(), x =>
            {
                this._TaskCargando.Remove(x);
                NotifyPropChanged("TaskCargando");
            });

            this._TaskCargando.Add(initializeOwnersTask);
        }
Ejemplo n.º 23
0
        public void NotifierT_NonDefaultResult_TaskFaulted_KeepsNonDefaultResult()
        {
            var tcs           = new TaskCompletionSource <object>();
            var defaultResult = new object();
            var notifier      = NotifyTask.Create(() => tcs.Task, defaultResult);
            var exception     = new NotImplementedException(Guid.NewGuid().ToString("N"));

            Assert.Same(defaultResult, notifier.Result);

            tcs.SetException(exception);

            Assert.Same(defaultResult, notifier.Result);
        }
Ejemplo n.º 24
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        private async Task SetCuentaAsync(string numCuenta)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            int numeroCuenta = int.Parse(numCuenta);
            var ntcCuenta    = NotifyTask.Create <CuentaMayor>(
                this.CuentaRepo.GetByNumCuentaAsync(numeroCuenta, base.TabCodigoComunidad, base._TabCodigoEjercicio, this),
                x => base.RemoveFromTaskCargando(x));

            //x => base.TaskCargando.Remove(x));
            //base.TaskCargando.Add(ntcCuenta);
            base.AddToTaskCargando(ntcCuenta);
            this.Cuenta = ntcCuenta;
        }
Ejemplo n.º 25
0
    public RepositoriesPageViewModel(INavigationService navigationService, ISecuredDataProvider securedDataProvider)
    {
        _navigationService = navigationService;
        var token = securedDataProvider.Retreive(ConstantsService.ProviderName, UserManager.GetLastUser());

        _session = new Session(UserManager.GetLastUser(), token.Properties.First().Value);
        var navigationParameters = new NavigationParameters {
            { "Session", _session }
        };

        _repositoriesManager = new RepositoriesManager(_session);
        Repositories         = NotifyTask.Create(GetRepositoriesAsync());
    }
            public override void OnScrollStateChanged(RecyclerView recyclerView, int newState)
            {
                InternalLogger.Info($"OnScrollStateChanged( newState: {newState} )");
                switch (newState)
                {
                case RecyclerView.ScrollStateSettling:
                case RecyclerView.ScrollStateDragging:
                {
                    if (!_weakNativeView.TryGetTarget(out AndroidHorizontalListViewRenderer nativeView))
                    {
                        return;
                    }

                    if (nativeView.IsScrolling)
                    {
                        return;
                    }

                    if (_cts != null && !_cts.IsCancellationRequested)
                    {
                        // System.Diagnostics.Debug.WriteLine("DEBUG_SCROLL: Cancelling previous update index task");
                        _cts.Cancel();
                    }

                    nativeView.IsScrolling = true;

                    _element.ScrollBeganCommand?.Execute(null);
                    break;
                }

                case RecyclerView.ScrollStateIdle:
                {
                    if (!_weakNativeView.TryGetTarget(out AndroidHorizontalListViewRenderer nativeView))
                    {
                        return;
                    }

                    if (!nativeView.IsScrolling)
                    {
                        return;
                    }

                    nativeView.IsScrolling = false;

                    _cts = new CancellationTokenSource();
                    NotifyTask.Create(UpdateCurrentIndexAsync(nativeView, _cts.Token));

                    break;
                }
                }
            }
Ejemplo n.º 27
0
 /// <summary>
 /// This method must be called by the UI element in charge of displaying data.
 /// Per example, on android, a scroll listener can reference this paginator as an IInfiniteListLoader and call it from OnScroll.
 /// The call to this method is nearly transparent as it returns immediately and doesn't block the caller.
 /// (benchmarked as 4 ticks for a call (10 000 ticks == 1ms)).
 /// </summary>
 public void OnScroll(int lastVisibleIndex)
 {
     NotifyTask <bool> .Create(
         ShouldLoadNextPage(lastVisibleIndex),
         whenSuccessfullyCompleted : (task, shouldLoad) =>
     {
         if (shouldLoad)
         {
             //InternalLogger.Info($"Scrolled: loading more (max index of visible item {lastVisibleIndex})");
             int pageToLoad = lastVisibleIndex / PageSize + 2;
             LoadPage(pageToLoad, calledFromScroll: true);
         }
     });
 }
        private void LongTapAction(UIGestureRecognizerState state)
        {
            switch (state)
            {
            case UIGestureRecognizerState.Began:
                NotifyTask.Create(TapAnimationAsync(0.5, 0, _alpha, false));
                break;

            case UIGestureRecognizerState.Ended:
            case UIGestureRecognizerState.Cancelled:
            case UIGestureRecognizerState.Failed:
                NotifyTask.Create(TapAnimationAsync(0.5, _alpha));
                break;
            }
        }
Ejemplo n.º 29
0
        public void NotifierT_NonDefaultResult_TaskCompletesSuccessfully_UpdatesResult()
        {
            var tcs                = new TaskCompletionSource <object>();
            var defaultResult      = new object();
            var notifier           = NotifyTask.Create(() => tcs.Task, defaultResult);
            var result             = new object();
            var resultNotification = TestUtils.PropertyNotified(notifier, n => n.Result);

            Assert.Same(defaultResult, notifier.Result);

            tcs.SetResult(result);

            Assert.Same(result, notifier.Result);
            Assert.True(resultNotification());
        }
        /// <summary>
        /// Execute method is called when any item is requested for load-on-demand items.
        /// </summary>
        /// <param name="obj">TreeViewNode is passed as default parameter </param>
        private async Task ExecuteOnDemandLoading(object obj)
        {
            var notifyTask = NotifyTask.Create(PopulateChildAsync(obj));
            await notifyTask.TaskCompleted;

            if (notifyTask.IsCompleted)
            {
                var items = notifyTask.Result as IEnumerable <MusicInfo>;
                if (items.Count() > 0)
                {
                    //Expand the node after child items are added.
                    (obj as TreeViewNode).IsExpanded = true;
                }
            }
        }