async Task ProcessCallback(CallbackParam cbp)
        {
            switch (cbp)
            {
            case CallbackParam.GapMinus:
                StateHasChanged();
                break;

            case CallbackParam.GapPlus:
                StateHasChanged();
                break;

            case CallbackParam.MouseMove:
                StateHasChanged();
                break;

            case CallbackParam.PlayAsync:
                await PlayAsync();

                break;

            case CallbackParam.Play:
                Play();
                break;

            case CallbackParam.Submit:
                await Submit();

                break;

            default:
                break;
            }
        }
        async Task ProcessCallback(CallbackParam callbackParam)
        {
            switch (callbackParam)
            {
            case CallbackParam.PlayAsyncA:
                await PlayAsyncA();

                break;

            case CallbackParam.PlayA:
                PlayA();
                break;

            case CallbackParam.PlayAsyncB:
                await PlayAsyncB();

                break;

            case CallbackParam.PlayB:
                PlayB();
                break;

            case CallbackParam.AHasErrors:
            case CallbackParam.BHasErrors:
            case CallbackParam.DontKnow:
                await Submit(callbackParam);

                break;

            default:
                break;
            }
        }
        public static void Main()
        {
            Console.WriteLine(GetValue());

#if false
            // GC 誘発
            for (int i = 0; i < 10000; i++)
            {
                var x = new byte[10000];
            }

            var param = new CallbackParam();
            var h     = GCHandle.Alloc(param, GCHandleType.Pinned);

            Sub(h);

            //Console.WriteLine($"&d = {GetAddress(param)}, &c = {GetAddress(c)}, fp(c) = {Marshal.GetFunctionPointerForDelegate(c)}");

            // GC 誘発
            for (int i = 0; i < 10000; i++)
            {
                var x = new byte[10000];
            }
            GC.Collect(2, GCCollectionMode.Forced);

            //Console.WriteLine($"&d = {GetAddress(param)}, &c = {GetAddress(c)}, fp(c) = {Marshal.GetFunctionPointerForDelegate(c)}");

            for (uint i = 0; i < 5; i++)
            {
                FireCallback(i);
            }

            //Console.WriteLine($"&d = {GetAddress(param)}, &c = {GetAddress(c)}, fp(c) = {Marshal.GetFunctionPointerForDelegate(c)}");

            return;
Exemple #4
0
        public async void Start()
        {
            IsActive = true;

            listener.Start();


            while (IsActive)
            {
                TCPConnection connection = null;

                try
                {
                    TcpClient client = await listener.AcceptTcpClientAsync();

                    client.SendBufferSize    = connectionBufferSize;
                    client.ReceiveBufferSize = connectionBufferSize;
                    client.SendTimeout       = DefaultSendTimeoutMs;
                    client.ReceiveTimeout    = DefaultReceiveTimeoutMs;

                    connection             = new TCPConnection(client, connectionBufferSize);
                    connection.SyncContext = SyncContext;
                }
                catch //(Exception e)
                {
                    if (OnConnected != null)
                    {
                        OnConnected(null);
                    }
                    //Util.Log(e.Message);
                }

                if (SyncContext != null)
                {
                    SyncContext.Post((state) => {
                        CallbackParam param = (CallbackParam)state;
                        if (OnConnected != null)
                        {
                            OnConnected(param.Connection);
                        }

                        if (param.Connection != null)
                        {
                            param.Connection.Start();
                        }
                    }, new CallbackParam(connection));
                }
                else
                {
                    if (OnConnected != null)
                    {
                        OnConnected(connection);
                    }
                    if (connection != null)
                    {
                        connection.Start();
                    }
                }
            }
        }
Exemple #5
0
 public void InsertBefore <TViewModel, TResult>(
     ViewModelBase beforeViewModel,
     CallbackParam <TResult> callbackParam)
     where TViewModel : ViewModelBase, IWithResult <TResult>
 {
     InsertBefore <TViewModel, TResult>(
         beforeViewModel,
         null,
         callbackParam);
 }
Exemple #6
0
 public async Task NavigateToAsync <TViewModel, TResult>(
     CallbackParam <TResult> callbackParam,
     Action <NavigationConfigBuilder> config = null)
     where TViewModel : ViewModelBase, IWithResult <TResult>
 {
     await NavigateToAsync <TViewModel, TResult>(
         null,
         callbackParam,
         config);
 }
Exemple #7
0
 public void InsertBefore <TViewModel, TResult>(
     ViewModelBase beforeViewModel,
     Action <TViewModel> viewModelInitialization,
     CallbackParam <TResult> callbackParam)
     where TViewModel : ViewModelBase, IWithResult <TResult>
 {
     InsertBeforePrivate <TViewModel, object, TResult>(
         beforeViewModel,
         null,
         viewModelInitialization,
         callbackParam);
 }
Exemple #8
0
 public async Task NavigateToAsync <TResult>(
     Type viewModelType,
     CallbackParam <TResult> callbackParam,
     Action <NavigationConfigBuilder> config = null)
 {
     await NavigateToAsync(
         viewModelType,
         null,
         null,
         callbackParam,
         config);
 }
Exemple #9
0
 public async Task NavigateToAsync <TViewModel, TResult>(
     Action <TViewModel> viewModelInitialization,
     CallbackParam <TResult> callbackParam,
     Action <NavigationConfigBuilder> config = null)
     where TViewModel : ViewModelBase, IWithResult <TResult>
 {
     await NavigateToPrivateAsync <TViewModel, object, TResult>(
         null,
         viewModelInitialization,
         callbackParam,
         config);
 }
Exemple #10
0
 public void InsertBefore <TResult>(
     ViewModelBase beforeViewModel,
     Type viewModelType,
     CallbackParam <TResult> callbackParam)
 {
     InsertBefore(
         beforeViewModel,
         viewModelType,
         null,
         null,
         callbackParam);
 }
Exemple #11
0
 public void InsertBefore <TResult>(
     ViewModelBase beforeViewModel,
     Type viewModelType,
     Action <ViewModelBase> viewModelInitialization,
     CallbackParam <TResult> callbackParam)
 {
     InsertBefore(
         beforeViewModel,
         viewModelType,
         null,
         viewModelInitialization,
         callbackParam);
 }
Exemple #12
0
 public void InsertBefore <TViewModel, TParam, TResult>(
     ViewModelBase beforeViewModel,
     TParam param,
     Action <TViewModel> viewModelInitialization,
     CallbackParam <TResult> callbackParam)
     where TViewModel : ViewModelBase, IWithInit <TParam>, IWithResult <TResult>
 {
     InsertBeforePrivate(
         beforeViewModel,
         param,
         viewModelInitialization,
         callbackParam);
 }
Exemple #13
0
        private async Task NavigateToPrivateAsync <TViewModel, TParam, TResult>(
            TParam param,
            Action <TViewModel> viewModelInitialization,
            CallbackParam <TResult> callbackParam,
            Action <NavigationConfigBuilder> config = null)
            where TViewModel : ViewModelBase
        {
            await ExecuteInNavigateSafelyAsync(async() =>
            {
                var navigationConfig = new NavigationConfigBuilder(_navigationConfigProvider.Get(), config).Instance;
                var newView          = CreateView(param, viewModelInitialization, callbackParam);

                await _stackAlgorithms[navigationConfig.StackType].NavigateToAsync(newView, navigationConfig.WithAnimation);
            });
        }
Exemple #14
0
        public async Task ReceiveAsync()
        {
            while (IsActive)
            {
                try
                {
                    var result = await client.ReceiveAsync().ConfigureAwait(false);

                    if (!IsActive)
                    {
                        break;
                    }
                    if (cancelToken.IsCancellationRequested)
                    {
                        break;
                    }

                    if (Global.SyncContext != null)
                    {
                        Global.SyncContext.Post((state) =>
                        {
                            if (cancelToken.IsCancellationRequested)
                            {
                                return;
                            }
                            CallbackParam param = (CallbackParam)state;
                            if (OnReceive != null)
                            {
                                OnReceive(param.Ip, param.buffer, param.size);
                            }
                        }, new CallbackParam(result.RemoteEndPoint.Address.ToString(), result.Buffer, result.Buffer.Length));
                    }
                    else
                    {
                        if (OnReceive != null)
                        {
                            OnReceive(result.RemoteEndPoint.Address.ToString(), result.Buffer, result.Buffer.Length);
                        }
                    }
                }
                catch//(Exception e)
                {
                    //Util.Log("UDPReceiver:" + e.Message);
                    break;
                }
            }
        }
Exemple #15
0
        private void InsertBeforePrivate <TViewModel, TParam, TResult>(
            ViewModelBase beforeViewModel,
            TParam param,
            Action <TViewModel> viewModelInitialization,
            CallbackParam <TResult> callbackParam)
            where TViewModel : ViewModelBase
        {
            var mainParent = GetMainParentFor(beforeViewModel);

            if (_stackAlgorithms[typeof(NavigationStack)].TryGetFromStack(mainParent, out _, out var index))
            {
                var beforeView = _navigationViewProvider.NavigationView.Navigation.NavigationStack[index];
                var newView    = CreateView(param, viewModelInitialization, callbackParam);

                _navigationViewProvider.NavigationView.Navigation.InsertPageBefore(newView, beforeView);
            }
        }
Exemple #16
0
        public async Task NavigateToAsync <TResult>(
            Type viewModelType,
            object param,
            Action <ViewModelBase> viewModelInitialization,
            CallbackParam <TResult> callbackParam,
            Action <NavigationConfigBuilder> config = null)
        {
            if (!typeof(ViewModelBase).IsAssignableFrom(viewModelType))
            {
                throw new ArgumentException($"{viewModelType.Name} must be inherited from the {nameof(ViewModelBase)}");
            }

            await ReflectionHelper.CallByReflectionFromAsync(
                this,
                nameof(NavigateToPrivateAsync),
                new [] { viewModelType, param?.GetType() ?? typeof(object), typeof(TResult) },
                param,
                viewModelInitialization,
                callbackParam,
                config);
        }
Exemple #17
0
        public void InsertBefore <TResult>(
            ViewModelBase beforeViewModel,
            Type viewModelType,
            object param,
            Action <ViewModelBase> viewModelInitialization,
            CallbackParam <TResult> callbackParam)
        {
            if (!typeof(ViewModelBase).IsAssignableFrom(viewModelType))
            {
                throw new ArgumentException($"{viewModelType.Name} must be inherited from the {nameof(ViewModelBase)}");
            }

            ReflectionHelper.CallByReflectionFrom(
                this,
                nameof(InsertBeforePrivate),
                new[] { viewModelType, param?.GetType() ?? typeof(object), typeof(TResult) },
                beforeViewModel,
                param,
                viewModelInitialization,
                callbackParam);
        }
Exemple #18
0
        private Page CreateView <TViewModel, TParam, TResult>(
            TParam param,
            Action <TViewModel> viewModelInitialization,
            CallbackParam <TResult> callbackParam)
            where TViewModel : ViewModelBase
        {
            var viewType = _navigationMapper.GetViewTypeFor <TViewModel>();
            var view     = (Page)_resolver.Resolve(viewType, param);

            var viewModel = (TViewModel)_resolver.Resolve(typeof(TViewModel), param);

            viewModelInitialization?.Invoke(viewModel);

            view.BindingContext = viewModel;

            view.Appearing += (sender, args) => viewModel.OnAppearing();
            view.Appearing += async(sender, args) => await viewModel.OnAppearingAsync();

            view.Disappearing += (sender, args) => viewModel.OnDisappearing();
            view.Disappearing += async(sender, args) => await viewModel.OnDisappearingAsync();

            var children = SetBingingContextForChildren(
                view,
                viewModel,
                param,
                viewModelInitialization,
                callbackParam);

            _viewModelWrapperStorage.Add(
                viewModel,
                new ViewModelWrapper <TResult>(callbackParam)
            {
                Parent   = null,
                Children = children
            });

            return(view);
        }
Exemple #19
0
        public async Task Connect(string ip)
        {
            TcpClient client = new TcpClient();

            client.SendBufferSize    = connectionBufferSize;
            client.ReceiveBufferSize = connectionBufferSize;
            client.SendTimeout       = DefaultSendTimeoutMs;
            client.ReceiveTimeout    = DefaultReceiveTimeoutMs;

            try
            {
                Task con_task = client.ConnectAsync(ip, portNum);
                if (!con_task.Wait(connectTimeOutSec))
                {
                    client.Close();
                    throw new SocketException(10060); // 10060:WSAETIMEDOUT
                }
            }
            catch (SocketException e)
            {
                if (Global.SyncContext != null)
                {
                    Global.SyncContext.Post((state) => {
                        CallbackParam param = (CallbackParam)state;
                        if (OnConnected != null)
                        {
                            OnConnected(param.Ip, param.Connection);
                        }
                    }, new CallbackParam(ip, null));
                }
                else
                {
                    if (OnConnected != null)
                    {
                        OnConnected(ip, null);
                    }
                }
                //Util.Log("SocketException");
            }
            catch (AggregateException e)
            {
                if (e.InnerException is SocketException)
                {
                    if (Global.SyncContext != null)
                    {
                        Global.SyncContext.Post((state) => {
                            CallbackParam param = (CallbackParam)state;
                            if (OnConnected != null)
                            {
                                OnConnected(param.Ip, param.Connection);
                            }
                        }, new CallbackParam(ip, null));
                    }
                    else
                    {
                        if (OnConnected != null)
                        {
                            OnConnected(ip, null);
                        }
                    }
                    //Util.Log("AggregateException");
                }
            }

            TCPConnection connection = new TCPConnection(client, connectionBufferSize);

            if (Global.SyncContext != null)
            {
                Global.SyncContext.Post((state) => {
                    CallbackParam param = (CallbackParam)state;
                    if (OnConnected != null)
                    {
                        OnConnected(param.Ip, param.Connection);
                    }
                }, new CallbackParam(ip, connection));
            }
            else
            {
                if (OnConnected != null)
                {
                    OnConnected(ip, connection);
                }
            }
            await connection.Start();
        }
        async Task Submit(CallbackParam callbackParam)
        {
            if (testSpec.SelectedTest != 0 && testSpec.SelectedTest != -1)
            {
                ABResult aBResult;

                // Set the applicable submit button to Wait with a spinner
                switch (callbackParam)
                {
                case CallbackParam.AHasErrors:
                    testSpec.SpinnerSubmitting1 = true;
                    testSpec.SubmitLabel1       = "Wait";
                    aBResult = ABResult.AHasErrors;
                    break;

                case CallbackParam.BHasErrors:
                    testSpec.SpinnerSubmitting2 = true;
                    testSpec.SubmitLabel2       = "Wait";
                    aBResult = ABResult.BHasErrors;
                    break;

                case CallbackParam.DontKnow:
                    testSpec.SpinnerSubmitting3 = true;
                    testSpec.SubmitLabel3       = "Wait";
                    aBResult = ABResult.DontKnow;
                    break;

                default:
                    aBResult = ABResult.DontKnow;
                    break;
                }

                testSpec.ControlsDisabled    = true;
                testSpec.TenorWeightDisabled = true;
                screenA.PlayDisabled         = true;
                screenB.PlayDisabled         = true;
                StateHasChanged();

                // Create a TestSubmission object
                TestSubmission testSubmission = new TestSubmission()
                {
                    UserId   = string.Empty,
                    TestType = "A/B Test",
                    TestId   = testSpec.SelectedTest,
                    TestDate = DateTime.Now,
                    Gap      = 0,
                    ABResult = aBResult
                };

                // Push the testSubmission to the API in JSON format
                await TJBarnesService.GetHttpClient().PostAsJsonAsync("api/testsubmissions", testSubmission);

                switch (callbackParam)
                {
                case CallbackParam.AHasErrors:
                    testSpec.SpinnerSubmitting1 = false;
                    testSpec.Submitted1         = true;
                    break;

                case CallbackParam.BHasErrors:
                    testSpec.SpinnerSubmitting2 = false;
                    testSpec.Submitted2         = true;
                    break;

                case CallbackParam.DontKnow:
                    testSpec.SpinnerSubmitting3 = false;
                    testSpec.Submitted3         = true;
                    break;

                default:
                    break;
                }

                StateHasChanged();

                await Task.Delay(1000);

                switch (callbackParam)
                {
                case CallbackParam.AHasErrors:
                    testSpec.Submitted1   = false;
                    testSpec.SubmitLabel1 = "A has errors";
                    break;

                case CallbackParam.BHasErrors:
                    testSpec.Submitted2   = false;
                    testSpec.SubmitLabel2 = "B has errors";
                    break;

                case CallbackParam.DontKnow:
                    testSpec.Submitted3   = false;
                    testSpec.SubmitLabel3 = "I can't tell which has errors";
                    break;

                default:
                    break;
                }

                testSpec.ControlsDisabled    = false;
                testSpec.TenorWeightDisabled = TenorWeightSelect.TenorWeightDisabled(testSpec.Stage);
                screenA.PlayDisabled         = false;
                screenB.PlayDisabled         = false;
                StateHasChanged();
            }
            else
            {
                testSpec.ShowGaps      = true;
                testSpec.ResultEntered = true;

                if (callbackParam == CallbackParam.AHasErrors || callbackParam == CallbackParam.BHasErrors)
                {
                    switch (callbackParam)
                    {
                    case CallbackParam.AHasErrors:
                        if (testSpec.AHasErrors == true)
                        {
                            testSpec.ResultSource = "/audio/right.mp3";
                        }
                        else
                        {
                            testSpec.ResultSource = "/audio/wrong.mp3";
                        }

                        break;

                    case CallbackParam.BHasErrors:
                        if (testSpec.AHasErrors == true)
                        {
                            testSpec.ResultSource = "/audio/wrong.mp3";
                        }
                        else
                        {
                            testSpec.ResultSource = "/audio/right.mp3";
                        }

                        break;

                    default:
                        break;
                    }

                    testSpec.ResultSound = true;

                    // Wait for 1.5 seconds for the sound to finish
                    await Task.Delay(1500);

                    testSpec.ResultSound = false;
                }
            }
        }
Exemple #21
0
        async Task <bool> OnPoll(
            TCPConnection connection,
            NetworkStream nStream,
            byte[] receiveBuffer,
            BytePacker receivePacker,
            CancellationTokenSource cancelToken
            )
        {
            int   resSize   = 0;
            int   tmpSize   = 0;
            short channelId = 0;

            bool isRent = false;

            byte[] buffer = null;

            try
            {
                resSize = await ReadAsync(nStream, receiveBuffer, 2, cancelToken).ConfigureAwait(false);

                if (resSize != 0)
                {
                    receivePacker.Position = 0;
                    resSize = receivePacker.ReadShort();
#if DISABLE_CHANNEL_VARINT
                    tmpSize = await ReadAsync(nStream, receiveBuffer, 2, cancelToken).ConfigureAwait(false);

                    if (tmpSize == 0)
                    {
                        throw new EndOfStreamException();
                    }

                    receivePacker.Position = 0;
                    channelId = receivePacker.ReadShort();
#else
                    int s = 0;
                    channelId = VarintBitConverter.ToShort(nStream, out s);
#endif
                    tmpSize = await ReadAsync(nStream, receiveBuffer, resSize, cancelToken).ConfigureAwait(false);

                    if (tmpSize == 0)
                    {
                        throw new EndOfStreamException();
                    }

                    buffer = arrayPool.Rent(resSize);
                    if (buffer != null)
                    {
                        isRent = true;
                    }
                    else
                    {
                        buffer = new byte[resSize];
                        isRent = false;
                    }

                    Array.Copy(receiveBuffer, buffer, resSize);

                    //Util.Log("TCP:" + resSize);
                }
            }
            catch//(Exception e)
            {
                //Util.Log("TCP:" + e.Message);
                return(false);
            }

            if (resSize == 0)
            {
                return(false);
            }

            if (cancelToken.IsCancellationRequested)
            {
                return(false);
            }

            if (syncContext != null)
            {
                syncContext.Post((state) =>
                {
                    if (cancelToken.IsCancellationRequested)
                    {
                        return;
                    }
                    CallbackParam param = (CallbackParam)state;
                    OnReliableReceived(param.endPoint, param.channelId, param.buffer, param.size);
                    if (isRent)
                    {
                        arrayPool.Return(buffer);
                    }
                }, new CallbackParam((IPEndPoint)connection.Client.Client.RemoteEndPoint, channelId, buffer, resSize, isRent));
            }
            else
            {
                OnReliableReceived((IPEndPoint)connection.Client.Client.RemoteEndPoint, channelId, buffer, resSize);
            }

            return(true);
        }
Exemple #22
0
 public ViewModelWrapper(CallbackParam <TResult> callbackParam)
 {
     ViewClosing = callbackParam?.ViewClosing;
     ViewClosed  = callbackParam?.ViewClosed;
 }
Exemple #23
0
        public async Task Start()
        {
            cancelToken.Token.Register(() => client.Close());
            int   resSize   = 0;
            short channelId = 0;

            bool isRent = false;

            byte[] buffer = null;

            do
            {
                try
                {
                    resSize = await nStream.ReadAsync(receiveBuffer, 0, 2, cancelToken.Token).ConfigureAwait(false);

                    if (resSize != 0)
                    {
                        receivePacker.Position = 0;
                        resSize = receivePacker.ReadShort();
#if DISABLE_CHANNEL_VARINT
                        await nStream.ReadAsync(receiveBuffer, 0, 2, cancelToken.Token).ConfigureAwait(false);

                        receivePacker.Position = 0;
                        channelId = receivePacker.ReadShort();
                        await nStream.ReadAsync(receiveBuffer, 0, resSize, cancelToken.Token).ConfigureAwait(false);
#else
                        int s = 0;
                        channelId = VarintBitConverter.ToInt16(nStream, out s);
                        await nStream.ReadAsync(receiveBuffer, 0, resSize, cancelToken.Token).ConfigureAwait(false);
#endif


                        buffer = arrayPool.Rent(resSize);
                        if (buffer != null)
                        {
                            isRent = true;
                        }
                        else
                        {
                            buffer = new byte[resSize];
                            isRent = false;
                        }

                        Array.Copy(receiveBuffer, buffer, resSize);

                        //Util.Log("TCP:" + resSize);
                    }
                }
                catch//(Exception e)
                {
                    //Util.Log("TCP:" + e.Message);
                    break;
                }

                if (resSize == 0)
                {
                    break;
                }

                if (cancelToken.IsCancellationRequested)
                {
                    break;
                }

                if (Global.SyncContext != null)
                {
                    Global.SyncContext.Post((state) => {
                        if (cancelToken.IsCancellationRequested)
                        {
                            return;
                        }
                        CallbackParam param = (CallbackParam)state;
                        if (OnReceive != null)
                        {
                            OnReceive(param.Ip, param.channelId, param.buffer, param.size);
                        }
                        if (isRent)
                        {
                            arrayPool.Return(buffer);
                        }
                    }, new CallbackParam(IP, channelId, buffer, resSize, isRent));
                }
                else
                {
                    if (OnReceive != null)
                    {
                        OnReceive(IP, channelId, receiveBuffer, resSize);
                    }
                }
            } while (client.Connected);

            Disconnect();
        }
Exemple #24
0
        private List <ViewModelBase> SetBingingContextForChildren <TParentViewModel, TParam, TResult>(
            Page view,
            ViewModelBase parentViewModel,
            TParam param,
            Action <TParentViewModel> parentViewModelInitialization,
            CallbackParam <TResult> callbackParam)
            where TParentViewModel : ViewModelBase
        {
            var resultChildren = new List <ViewModelBase>();

            var childViews = view is TabbedPage tabbedPage
                                ? tabbedPage.Children
                                : view is FlyoutPage flyoutPage
                                        ? new[] { flyoutPage.Flyout, flyoutPage.Detail }
                                        : Array.Empty <Page>();

            foreach (var childView in childViews)
            {
                var currentView      = childView is NavigationPage navigationPage ? navigationPage.RootPage : childView;
                var currentViewModel = null as ViewModelBase;

                if (!currentView.GetType().IsDefined(typeof(ParentBindingContextAttribute)))
                {
                    var viewModelType = _navigationMapper.GetViewModelTypeFor(currentView);
                    currentViewModel = (ViewModelBase)_resolver.Resolve(viewModelType, param);
                    if (currentViewModel is TParentViewModel parentViewModelType)
                    {
                        parentViewModelInitialization?.Invoke(parentViewModelType);
                    }

                    currentView.BindingContext = currentViewModel;

                    currentView.Appearing += (sender, args) => currentViewModel.OnAppearing();
                    currentView.Appearing += async(sender, args) => await currentViewModel.OnAppearingAsync();

                    currentView.Disappearing += (sender, args) => currentViewModel.OnDisappearing();
                    currentView.Disappearing += async(sender, args) => await currentViewModel.OnDisappearingAsync();
                }

                var children = SetBingingContextForChildren(
                    currentView,
                    currentViewModel ?? parentViewModel,
                    param,
                    parentViewModelInitialization,
                    callbackParam);

                if (currentViewModel != null)
                {
                    resultChildren.Add(currentViewModel);

                    _viewModelWrapperStorage.Add(currentViewModel,
                                                 new ViewModelWrapper <TResult>(callbackParam)
                    {
                        Parent   = parentViewModel,
                        Children = children
                    });
                }
                else
                {
                    resultChildren.AddRange(children);
                }
            }

            return(resultChildren);
        }