예제 #1
0
        private async Task onLoadProgressAsync(LoadProgressMessage message)
        {
            //
            // This method alwyas runs on a background thread.  Executed at program start only.
            //
            // Due to requirements of the Bitmap class (used by FontAwesome) the entities must be created on the
            // UI thread.
            //
            await asyncService.RunUiContext(() => viewModel.Loaders = buildEntityList());

            messenger.SendUi(new OpenDialogMessage {
                Name = DialogNames.LoadProgressDialog
            });

            await commonDataStore.LoadDataFilesAsync(onProgressCallbackAsync, false);
        }
예제 #2
0
        private void onTickerEventCallback(PushMessageBase message)
        {
            if (!(message is TickerMessage ticker))
            {
                return;
            }

            CurrencyViewEntity currency = viewModel.MarketTabs.SelectMany(market => market.Currencies).SingleOrDefault(c => c.Id == ticker.Id);

            if (currency != null)
            {
                asyncService.RunUiContext(async() => {
                    double oldChange = currency.Price;
                    double newChange = ticker.Last;

                    mapper.Map(message, currency);

                    if (oldChange.EqualInPercentRange(newChange))
                    {
                        return;
                    }

                    if (newChange < oldChange)
                    {
                        currency.IsChangeDown = true;
                    }
                    else if (newChange > oldChange)
                    {
                        currency.IsChangeUp = true;
                    }

                    await Task.Delay(TimeSpan.FromMilliseconds(500));

                    if (newChange < oldChange)
                    {
                        currency.IsChangeDown = false;
                    }
                    else if (newChange > oldChange)
                    {
                        currency.IsChangeUp = false;
                    }
                }).FireAndForget();
            }
        }
예제 #3
0
        private void buildHexDataAsync(byte[] data, int fileOffset, CancellationToken token)
        {
            isBuilding = true;

            try
            {
                asyncService.RunUiContext(token, () => viewModel.HexData.Clear()).Wait(token);

                List <DomainHexData> cache = new List <DomainHexData>();

                for (int i = 0; i < data.Length; i += 16)
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    StringBuilder hexStr = new StringBuilder();
                    StringBuilder ascStr = new StringBuilder();

                    for (int j = 0; j < 16; ++j)
                    {
                        if (i + j >= data.Length || token.IsCancellationRequested)
                        {
                            break;
                        }

                        byte c = data[i + j];

                        hexStr.AppendFormat("{0:X2} ", c);
                        ascStr.Append(isDisplayable(c) ? (char)c : '.');
                    }

                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    DomainHexData hexData = new DomainHexData
                    {
                        FileIndex   = fileOffset + i,
                        Index       = i,
                        HexValues   = hexStr.ToString().Trim(),
                        AsciiValues = ascStr.ToString()
                    };

                    cache.Add(hexData);

                    if (cache.Count > 512)
                    {
                        int i1 = i;

                        asyncService.RunUiContext(token, () =>
                        {
                            viewModel.HexData.AddRange(cache);

                            viewModel.Title = $"{title} {i1 / (double)data.Length:P1}";
                        }).Wait(token);

                        cache.Clear();
                    }
                }

                asyncService.RunUiContext(token, () =>
                {
                    if (cache.Any())
                    {
                        viewModel.HexData.AddRange(cache);
                    }

                    viewModel.Title = $"{title} \u2713";
                }).Wait(token);
            }
            catch (TaskCanceledException) { }
            catch (OperationCanceledException) { }
            catch (Exception ex)
            {
                messenger.SendUi(new ApplicationErrorMessage {
                    HeaderText = "Error Building Hex Display", Exception = ex
                });
            }

            isBuilding = false;
        }