Dispatch() public method

public Dispatch ( string message, object parameter = null ) : void
message string
parameter object
return void
        public void AndItShouldNotDoThat()
        {
            var handlerActivator = new HandlerActivatorForTesting();
            var pipelineInspector = new TrivialPipelineInspector();
            var handleDeferredMessage = new MockDeferredMessageHandler();
            var dispatcher = new Dispatcher(new InMemorySagaPersister(),
                                        handlerActivator,
                                        new InMemorySubscriptionStorage(),
                                        pipelineInspector,
                                        handleDeferredMessage,
                                        null);

            dispatcher.Dispatch(new TimeoutReply
            {
                CorrelationId = TimeoutReplyHandler.TimeoutReplySecretCorrelationId,
                CustomData = TimeoutReplyHandler.Serialize(new Message { Id = "1" })
            });

            dispatcher.Dispatch(new TimeoutReply
            {
                CustomData = TimeoutReplyHandler.Serialize(new Message { Id = "2" })
            });

            handleDeferredMessage.DispatchedMessages.Count.ShouldBe(1);
            var dispatchedMessage = handleDeferredMessage.DispatchedMessages[0];
            dispatchedMessage.ShouldBeOfType<Message>();
            ((Message)dispatchedMessage).Id.ShouldBe("1");
        }
        public void AndItShouldNotDoThat()
        {
            var handlerActivator = new HandlerActivatorForTesting();
            var pipelineInspector = new TrivialPipelineInspector();
            var handleDeferredMessage = Mock<IHandleDeferredMessage>();
            var dispatcher = new Dispatcher(new InMemorySagaPersister(),
                                        handlerActivator,
                                        new InMemorySubscriptionStorage(),
                                        pipelineInspector,
                                        handleDeferredMessage);

            dispatcher.Dispatch(new TimeoutReply
            {
                CorrelationId = TimeoutReplyHandler.TimeoutReplySecretCorrelationId,
                CustomData = TimeoutReplyHandler.Serialize(new Message { Id = "1" })
            });

            dispatcher.Dispatch(new TimeoutReply
            {
                CustomData = TimeoutReplyHandler.Serialize(new Message { Id = "2" })
            });

            handleDeferredMessage.AssertWasCalled(x => x.Dispatch(Arg<Message>.Is.Anything), x => x.Repeat.Once());
            handleDeferredMessage.AssertWasCalled(x => x.Dispatch(Arg<Message>.Matches(y => y.Id == "1")));
        }
Example #3
0
        private void OnReadData(DataGridReadDataEventArgs <SearchItem> e)
        {
            var currLang1Id = Const.PlLangId;

            if (_currentLanguage1 is not null)
            {
                currLang1Id = _currentLanguage1.Id;
            }
            var currLang2Id = Const.EnLangId;

            if (_currentLanguage2 is not null)
            {
                currLang2Id = _currentLanguage2.Id;
            }
            if (_currentLanguage3 is not null)
            {
                currLang1Id = _currentLanguage3.Id;
                if (_currentLanguage3.Id == Const.PlLangId)
                {
                    currLang2Id = Const.EnLangId;
                }
                else
                {
                    currLang2Id = _currentLanguage3.Id;
                }
            }


            _searchPageNr = e.Page;
            Dispatcher?.Dispatch(
                new SearchPageNrChangeAction(e.Page.ToString(), searchText: SearchText, baseTermLangId: currLang1Id,
                                             translationLangId: currLang2Id, itemsPerPage: _itemsPerPage, searchPageNr: _searchPageNr, current: _currentTranslations,
                                             noResults: MyText?.NoResults ?? string.Empty,
                                             searchTranslationMessage: MyText?.Loaded ?? string.Empty));
        }
Example #4
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                if (LocalStorage != null)
                {
                    var decks = await LocalStorage.GetItemAsync <IImmutableList <Deck> >("decks");

                    var cards = await LocalStorage.GetItemAsync <IImmutableList <Card> >("cards");

                    if (decks != null)
                    {
                        Dispatcher?.Dispatch(new GetDecksAction(decks));
                    }

                    if (cards != null)
                    {
                        Dispatcher?.Dispatch(new GetCardsAction(cards));
                    }
                }

                if (DecksState != null)
                {
                    DecksState.StateChanged += DecksState_StateChanged !;
                }
                if (CardsState != null)
                {
                    CardsState.StateChanged += CardsState_StateChanged !;
                }
            }
        }
Example #5
0
        private void OnSaveClicked()
        {
            if (MyText is null)
            {
                return;
            }
            if (LocalStorage is null)
            {
                return;
            }

            if (BaseTermsState?.Value?.BaseTerm is null)
            {
                ShowAlert(MyText.SaveError);
                return;
            }
            var token    = LocalStorage.GetItem <Token>(Const.TokenKey);
            var baseTerm = BaseTermsState.Value.BaseTerm;

            baseTerm.LanguageId = Const.BaseLanguagesList[0].Id;

            Dispatcher?.Dispatch(
                new BaseTermsAddAction(
                    baseTerm: baseTerm,
                    token: token.AuthToken,
                    baseTermAddedMessage: MyText.DataSavedOk));
        }
Example #6
0
        private void OnSaveClicked()
        {
            if (MyText is null)
            {
                return;
            }
            if (LocalStorage is null)
            {
                return;
            }

            if (TranslationsState?.Value?.BaseTranslation.Translation is null)
            {
                ShowAlert(MyText.SaveError);
                return;
            }
            var token = LocalStorage.GetItem <Token>(Const.TokenKey);

            //additional check for new/null data
            TranslationsState.Value.BaseTranslation.Translation.LanguageId = TranslationLangId;
            TranslationsState.Value.BaseTranslation.Translation.Current    = true;

            Dispatcher?.Dispatch(
                new TranslationsAddAction(
                    TranslationsState.Value.BaseTranslation.Translation,
                    token.AuthToken,
                    MyText.TranslationAdded
                    ));
        }
        protected override void OnParametersSet()
        {
            if (PageRoute is null)
            {
                return;
            }
            if (LocalStorage is null)
            {
                return;
            }

            if (MyText is null)
            {
                return;
            }


            var s = PageRoute.Split('/');

            if (s.Length == 2)
            {
                UserId = s[0];
                Token  = s[1];
            }

            if (string.IsNullOrEmpty(UserId))
            {
                return;
            }
            if (string.IsNullOrEmpty(Token))
            {
                return;
            }

            User.UserId = UserId;
            User.Token  = Token;

            try
            {
                var token = LocalStorage.GetItem <Token>(Const.TokenKey);

                Dispatcher?.Dispatch(
                    new UsersCreationConfirmAction(
                        user: User,
                        token: token.AuthToken,
                        userPasswordResetConfirmMessage: MyText?.PasswordReseted ?? string.Empty));

                if (NavigationManager is null)
                {
                    return;
                }
                NavigationManager.NavigateTo("/");
            }
            catch
            {
                ShowAlert(MyText?.DataSavedNOk ?? string.Empty);
            }
        }
        public void Simple()
        {
            var unity = new UnityContainer();
            var tracker = new Tracker();
            unity.RegisterInstance(tracker);

            var registrator = new HandlerRegistrator(unity);
            registrator.RegisterAssemblies(new[] { Assembly.GetExecutingAssembly() });

            var dispatcher = new Dispatcher(unity, registrator);

            var message = new SimpleMessage();
            dispatcher.Dispatch(message);

            var message2 = new SimpleMessage2();
            dispatcher.Dispatch(message2);

            Assert.AreEqual(2, tracker.Handlers.Count);
            Assert.AreEqual(typeof(SimpleMessage), tracker.Handlers[0]);
            Assert.AreEqual(typeof(SimpleMessage2), tracker.Handlers[1]);
        }
Example #9
0
        private void GoSearch()
        {
            if (_currentLanguage1 is null)
            {
                _currentLanguage1 = Const.BaseLanguagesList[0];
            }

            bool goBaseLang = Const.BaseLanguagesList.Contains(_currentLanguage1);

            var currLang1Id = _currentLanguage1.Id;
            var currLang2Id = Const.EnLangId;

            if (_currentLanguage2 is not null)
            {
                currLang2Id = _currentLanguage2.Id;
            }

            if (_currentLanguage3 is not null)
            {
                if (_currentLanguage3.Id == Const.PlLangId)
                {
                    currLang2Id = Const.EnLangId;
                    currLang1Id = _currentLanguage3.Id;
                    goBaseLang  = true;
                }
                else
                {
                    currLang1Id = Const.PlLangId;
                    currLang2Id = _currentLanguage3.Id;
                    goBaseLang  = false;
                }
            }

            if (goBaseLang)
            {
                Dispatcher?.Dispatch(
                    new SearchBaseTermsAction(searchText: SearchText, baseTermLangId: currLang1Id,
                                              translationLangId: currLang2Id, searchPageNr: 1, itemsPerPage: _itemsPerPage,
                                              current: _currentTranslations, noResults: MyText?.NoResults ?? string.Empty,
                                              hasTranslations: _optionHasTranslations, searchBaseTermMessage: MyText?.Loaded ?? string.Empty));
            }
            else
            {
                Dispatcher?.Dispatch(new SearchTranslationsAction(searchText: SearchText, baseTermLangId: currLang1Id,
                                                                  translationLangId: currLang2Id, searchPageNr: 1, itemsPerPage: _itemsPerPage,
                                                                  current: _currentTranslations, noResults: MyText?.NoResults ?? string.Empty,
                                                                  searchTranslationMessage: MyText?.Loaded ?? string.Empty));
            }
        }
Example #10
0
        private void OnReadData(DataGridReadDataEventArgs <User> e)
        {
            if (!_reloadData)
            {
                return;
            }
            ReadLocalSettings();

            Dispatcher?.Dispatch(
                new UsersFetchDataAction(
                    token: _token,
                    searchPageNr: e.Page,
                    itemsPerPage: _itemsPerPage,
                    MyText?.Loaded ?? string.Empty));
        }
Example #11
0
        private void OnRowUpdated(SavedRowItem <User, Dictionary <string, object> > e)
        {
            var user = e.Item;

            if (user is null)
            {
                return;
            }

            try
            {
                user.UserName  = Convert.ToString(e.Values["UserName"]) ?? user.UserName;
                user.FirstName = Convert.ToString(e.Values["FirstName"]) ?? user.FirstName;
                user.LastName  = Convert.ToString(e.Values["LastName"]) ?? user.LastName;
                user.Email     = Convert.ToString(e.Values["Email"]) ?? user.Email;

                user.IsSuperuser = Convert.ToBoolean(e.Values["IsSuperuser"]);
                user.Assistant   = Convert.ToBoolean(e.Values["Assistant"]);

                var corLang  = (List <int>)e.Values["CoordinatingLanguages"];
                var tranLang = (List <int>)e.Values["TranslatingLanguages"];
                user.CoordinatingLanguages = corLang ?? user.CoordinatingLanguages;
                user.TranslatingLanguages  = tranLang ?? user.TranslatingLanguages;

                //user.CoordinatingLanguages = Convert.ToBoolean(e.Values["Assistant"]);
            } catch
            {
                return;
            }



            _selectedUser = user;

            if (MyText is null)
            {
                return;
            }

            ReadLocalSettings();

            Dispatcher?.Dispatch(
                new UsersUpdateAction(
                    userId: user.Id,
                    user: user,
                    token: _token,
                    MyText?.Updated ?? string.Empty));
        }
Example #12
0
        protected override async Task OnInitializedAsync()
        {
            await base.OnInitializedAsync();

            if (MyText is null)
            {
                return;
            }

            if (!LanguagesState?.Value.Languages.Any() ?? true)
            {
                Dispatcher?.Dispatch(new LanguagesFetchDataAction(LocalStorage));
            }

            Dispatcher?.Dispatch(new TranslationsFetchBaseTermAction(
                                     BaseTermId, MyText.Loaded));
        }
Example #13
0
        //Pagination clicked
        private void OnPageClick(string pageActionName)
        {
            var currLang1Id = Const.PlLangId;

            if (_currentLanguage1 is not null)
            {
                currLang1Id = _currentLanguage1.Id;
            }
            var currLang2Id = Const.EnLangId;

            if (_currentLanguage2 is not null)
            {
                currLang2Id = _currentLanguage2.Id;
            }

            if (_searchPageNr < 1)
            {
                _searchPageNr = 1;
            }
            switch (pageActionName)
            {
            case Const.PaginationBackName:
                _searchPageNr--;
                break;

            case Const.PaginationNextName:
                _searchPageNr++;
                break;

            default:
                _searchPageNr = int.Parse(pageActionName);
                break;
            }
            if (_searchPageNr < 1)
            {
                _searchPageNr = 1;
            }


            Dispatcher?.Dispatch(
                new SearchPageNrChangeAction(
                    pageActionName: pageActionName, searchText: SearchText, baseTermLangId: currLang1Id,
                    translationLangId: currLang2Id, itemsPerPage: _itemsPerPage, searchPageNr: _searchPageNr,
                    current: _currentTranslations, noResults: MyText?.NoResults ?? string.Empty,
                    searchTranslationMessage: MyText?.Loaded ?? string.Empty));
        }
Example #14
0
        protected override async Task OnInitializedAsync()
        {
            await base.OnInitializedAsync();

            if (!LanguagesState?.Value.Languages.Any() ?? true)
            {
                Dispatcher?.Dispatch(new LanguagesFetchDataAction(LocalStorage));
            }

            ReadLocalSettings();

            Dispatcher?.Dispatch(
                new UsersFetchDataAction(
                    token: _token,
                    searchPageNr: 1,
                    itemsPerPage: _itemsPerPage,
                    MyText?.Loaded ?? string.Empty));
        }
        private void HandlePasswordReset()
        {
            if (LocalStorage is null)
            {
                return;
            }

            if (MyText is null)
            {
                return;
            }
            if (string.IsNullOrEmpty(UserId))
            {
                return;
            }
            if (string.IsNullOrEmpty(Token))
            {
                return;
            }

            User.UserId = UserId;
            User.Token  = Token;

            try
            {
                var token = LocalStorage.GetItem <Token>(Const.TokenKey);

                Dispatcher?.Dispatch(
                    new UsersPasswordResetConfirmAction(
                        user: User,
                        token: token.AuthToken,
                        userPasswordResetConfirmMessage: MyText?.PasswordReseted ?? string.Empty));

                if (NavigationManager is null)
                {
                    return;
                }
                NavigationManager.NavigateTo("/");
            }
            catch
            {
                ShowAlert(MyText?.DataSavedNOk ?? string.Empty);
            }
        }
Example #16
0
        private void OnRowRemoved(User user)
        {
            _selectedUser = user;

            if (_selectedUser is null)
            {
                return;
            }
            ReadLocalSettings();

            if (_selectedUser != null)
            {
                Dispatcher?.Dispatch(
                    new UsersDeleteAction(
                        userId: _selectedUser.Id,
                        token: _token,
                        userDeleteMessage: MyText?.Deleted ?? string.Empty));
            }
        }
Example #17
0
        private void OnRowInserted(SavedRowItem <User, Dictionary <string, object> > e)
        {
            var user = e.Item;

            if (user is null)
            {
                return;
            }

            try
            {
                user.UserName  = Convert.ToString(e.Values["UserName"]) ?? user.UserName;
                user.FirstName = Convert.ToString(e.Values["FirstName"]) ?? user.FirstName;
                user.LastName  = Convert.ToString(e.Values["LastName"]) ?? user.LastName;
                user.Email     = Convert.ToString(e.Values["Email"]) ?? user.Email;
            }
            catch { }

            _selectedUser = user;



            if (MyText is null)
            {
                return;
            }

            ReadLocalSettings();
            var userAdd = new UserAdd
            {
                UserName  = user.UserName,
                Email     = user.Email,
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Password  = Func.CreatePassword(12, Func.EnumPasswordOptions.All)
            };

            Dispatcher?.Dispatch(
                new UsersAddAction(
                    user: userAdd,
                    token: _token,
                    MyText?.AddedUser ?? string.Empty));
        }
        protected override async Task OnInitializedAsync()
        {
            await base.OnInitializedAsync();

            _isLoading = true;

            if (!LanguagesState?.Value.Languages.Any() ?? true)
            {
                Dispatcher?.Dispatch(new LanguagesFetchDataAction(LocalStorage));
            }

            if (LocalStorage is not null)
            {
                _currentBaseLangPl   = LocalStorage.GetItem <bool>(Const.CurrentBaseLangKey);
                _rowsPerPage         = LocalStorage.GetItem <int>(Const.ItemsPerPageKey);
                _currentTranslations = LocalStorage.GetItem <bool>(Const.CurrentTranslations);

                ThemeColor   = LocalStorage.GetItem <string>(Const.ThemePrimaryColor);
                ThemeEnabled = LocalStorage.GetItem <bool>(Const.ThemeIsEnabled);
                ThemeRounded = LocalStorage.GetItem <bool>(Const.ThemeIsRounded);
            }



            UpdateTheme();



            if (_currentBaseLangPl)
            {
                _selectedLanguage = 1;
            }
            if (_rowsPerPage == 0)
            {
                _rowsPerPage = Const.DefaultItemsPerPage;
            }

            _isLoading = false;
        }
Example #19
0
        protected override async Task OnInitializedAsync()
        {
            if (MyText is not null)
            {
                _currentHeader = MyText.HeaderShowDashboardBase;
            }

            if (LocalStorage is not null)
            {
                _currentTranslations = LocalStorage.GetItem <bool>(Const.CurrentTranslations);
                _itemsPerPage        = LocalStorage.ContainKey(Const.ItemsPerPageKey)
                    ? LocalStorage.GetItem <long>(Const.ItemsPerPageKey)
                    : Const.DefaultItemsPerPage;
                UpdateTheme();
            }
            if (!LanguagesState?.Value?.Languages.Any() ?? true)
            {
                Dispatcher?.Dispatch(new LanguagesFetchDataAction(LocalStorage));
            }

            await base.OnInitializedAsync();
        }
 private void Settings(MouseEventArgs e)
 {
     voteAddr = walletState.Value.wallet.VoteFor;
     Dispatcher.Dispatch(new WebWalletSettingsAction {
     });
 }
Example #21
0
 /// <inheritdoc />
 public IClearCacheResponse ClearCache(IClearCacheRequest request) =>
 Dispatcher.Dispatch <IClearCacheRequest, ClearCacheRequestParameters, ClearCacheResponse>(
     request,
     (p, d) => LowLevelDispatch.IndicesClearCacheDispatch <ClearCacheResponse>(p)
     );
 private void SaveSettings(MouseEventArgs e)
 {
     Dispatcher.Dispatch(new WebWalletSaveSettingsAction {
         VoteFor = voteAddr
     });
 }
 private void Transactions(MouseEventArgs e)
 {
     Dispatcher.Dispatch(new WebWalletTransactionsAction {
         wallet = walletState.Value.wallet
     });
 }
Example #24
0
 /// <inheritdoc />
 public IClearCacheResponse ClearCache(Indices indices, Func <ClearCacheDescriptor, IClearCacheRequest> selector = null) =>
 Dispatcher.Dispatch <IClearCacheRequest, ClearCacheRequestParameters, ClearCacheResponse>(
     selector.InvokeOrDefault(new ClearCacheDescriptor().Index(indices)),
     (p, d) => LowLevelDispatch.IndicesClearCacheDispatch <ClearCacheResponse>(p)
     );
Example #25
0
        public IActionResult Index()
        {
            var roles = _dispatcher.Dispatch(new GetRolesQuery {
                AsNoTracking = true
            });

            return(View(roles));
        }
 private void SendToken(MouseEventArgs e)
 {
     Dispatcher.Dispatch(new WebWalletSendTokenAction {
         DstAddr = dstAddr, TokenName = tokenName, Amount = amount, wallet = walletState.Value.wallet
     });
 }
        private void CreateWallet(MouseEventArgs e)
        {
            altDisplay = "************";

            Dispatcher.Dispatch(new WebWalletCreateAction());
        }
 private void CancelSend(MouseEventArgs e)
 {
     Dispatcher.Dispatch(new WebWalletCancelSendAction());
 }
 private void FreeToken(MouseEventArgs e)
 {
     Dispatcher.Dispatch(new WebWalletFreeTokenAction {
         faucetPvk = Configuration["faucetPvk"]
     });
 }
 private void Refresh(MouseEventArgs e)
 {
     Dispatcher.Dispatch(new WebWalletRefreshBalanceAction {
         wallet = walletState.Value.wallet
     });
 }
 private void Return(MouseEventArgs e)
 {
     Dispatcher.Dispatch(new WebWalletCancelSaveSettingsAction {
     });
 }
 private void CloseWallet(MouseEventArgs e)
 {
     Dispatcher.Dispatch(new WebWalletCloseAction());
 }
        private async Task BeginSwapTLYR(MouseEventArgs e)
        {
            IsDisabled        = true;
            swapResultMessage = "Checking for configurations...";
            await InvokeAsync(() =>
            {
                StateHasChanged();
            });

            // do check
            swapResultMessage = "";

            // check network id
            CurrentChainName = await metamaskService.GetChainName();

            if (Configuration["network"] == "testnet" && CurrentChainName != "Rinkeby Test Network")
            {
                swapResultMessage = "Only Rinkeby Test Network is supported for testnet.";
            }
            else if (Configuration["network"] == "mainnet" && CurrentChainName != "Ethereum Main Network")
            {
                swapResultMessage = "Only Ethereum Main Network is supported for mainnet.";
            }
            else if (!EthereumEnabled || !walletState.Value.IsOpening)
            {
                swapResultMessage = "Wallet(s) not opening or connected.";
            }
            else if (swapFromToken == swapToToken)
            {
                swapResultMessage = "No need to swap.";
            }
            else if (!((swapFromToken == "LYR" && swapToToken == "TLYR") || (swapFromToken == "TLYR" && swapToToken == "LYR")))
            {
                swapResultMessage = "Unknown token pair";
            }
            else if (swapFromCount < 10)
            {
                swapResultMessage = "Swap amount too small. (< 10)";
            }
            else if (swapFromCount > 1000000)
            {
                swapResultMessage = "Swap amount too large. (> 1M)";
            }
            else if (swapFromToken == "LYR" && swapFromCount > walletState.Value.wallet.BaseBalance)
            {
                swapResultMessage = "Not enough LYR in Lyra Wallet.";
            }
            else if (string.IsNullOrWhiteSpace(swapToAddress))
            {
                swapResultMessage = "Not valid swap to address.";
            }
            else if (swapToToken == "TLYR" && swapToCount > 0.8m * tlyrReserveBalance)
            {
                swapResultMessage = "Reserve account of TLYR is running low. Please contact support.";
            }
            else if (swapToToken == "LYR" && swapToCount > 0.8m * lyrReserveBalance)
            {
                swapResultMessage = "Reserve account of LYR is running low. Please contact support.";
            }
            else if (swapToCount < 1)
            {
                swapResultMessage = "Swap to amount too small.";
            }
            else if (swapFromToken == "TLYR")
            {
                try
                {
                    var tlyrBalance = await SwapUtils.GetEthContractBalanceAsync(swapOptions.CurrentValue.ethUrl,
                                                                                 swapOptions.CurrentValue.ethContract, SelectedAccount);

                    if (tlyrBalance < swapFromCount)
                    {
                        swapResultMessage = "Not enough TLYR in Ethereum Wallet.";
                    }
                }
                catch (Exception)
                {
                    swapResultMessage = "Unable to get TLYR balance.";
                }
            }

            if (!string.IsNullOrEmpty(swapResultMessage))
            {
                IsDisabled = false;
                await InvokeAsync(() =>
                {
                    StateHasChanged();
                });

                return;
            }

            var mmmsg = swapFromToken == "TLYR" ? "Please open Matamask and confirm transaction." : "";

            swapResultMessage         = $"Do swapping... {mmmsg} Please wait for a moment... ";
            walletState.Value.Message = "";
            await InvokeAsync(() =>
            {
                StateHasChanged();
            });

            var arg = new WebWalletBeginSwapTLYRAction
            {
                wallet = walletState.Value.wallet,

                fromToken   = swapFromToken,
                fromAddress = swapFromToken == "LYR" ? walletState.Value.wallet.AccountId : SelectedAccount,
                fromAmount  = swapFromCount,

                toToken   = swapToToken,
                toAddress = swapToAddress,
                toAmount  = swapToCount,

                gasPrice = EthGasPrice,
                gasLimit = EthGasLimit,

                options  = swapOptions.CurrentValue,
                metamask = metamaskInterceptor
            };

            logger.LogInformation($"TokenSwap: Begin  {arg.fromAmount} from {arg.fromAddress} to {arg.toAddress} amount {arg.toAmount}");
            Dispatcher.Dispatch(arg);
            IsDisabled = true;
        }