Beispiel #1
0
        public static string TestBatch(LeagueServer server, int client, string args)
        {
            var batched = new Batched();
            var packet1 = new UnitAddEXP();

            packet1.TargetNetID = 0x40000001;
            packet1.ExpAmmount  = 100.0f;

            var packet2 = new BuyItemAns();

            packet2.SenderNetID      = 0x40000001;
            packet2.Item.ItemID      = 3100;
            packet2.Item.ItemsInSlot = 1;

            var packet3 = new BuyItemAns();

            packet3.SenderNetID      = 0x40000001;
            packet3.Item.ItemID      = 3025;
            packet3.Item.ItemsInSlot = 1;
            packet3.Item.Slot        = 2;

            batched.Packets.Add(packet1);
            batched.Packets.Add(packet2);
            batched.Packets.Add(packet3);

            server.SendEncrypted(client, ChannelID.Broadcast, batched);
            return("Batched!");
        }
 public Slice[] PackMany <TSource, TTuple>(IEnumerable <TSource> items, Func <TSource, TTuple> selector)
     where TTuple : IVarTuple
 {
     return(Batched <TSource, IDynamicKeyEncoder> .Convert(
                this.Parent.OpenWriter(),
                items,
                (ref SliceWriter writer, TSource item, IDynamicKeyEncoder encoder) => encoder.PackKey <TTuple>(ref writer, selector(item)),
                this.Encoder
                ));
 }
 public Slice[] PackMany <TTuple>(IEnumerable <TTuple> items)
     where TTuple : IVarTuple
 {
     return(Batched <TTuple, IDynamicKeyEncoder> .Convert(
                this.Parent.OpenWriter(),
                items,
                (ref SliceWriter writer, TTuple item, IDynamicKeyEncoder encoder) => encoder.PackKey(ref writer, item),
                this.Encoder
                ));
 }
Beispiel #4
0
        internal async Task <IReadOnlyCollection <FunFairWalletPriceResultPairDto?> > GetBasePricesAsync()
        {
            List <(string cryptoSymbol, string fiatSymbol)> symbols =
                (from cryptoSymbol in this._cryptoSymbols from fiatSymbol in this._fiatSymbols select(cryptoSymbol, fiatSymbol)).ToList();

            try
            {
                return(await Batched.WhenAllAsync(concurrent : 10, symbols.Select(this.GetCurrentPriceCommonAsync)));
            }
            catch (Exception exception)
            {
                EventId eventId = new(exception.HResult);
                this.Logger.LogError(eventId: eventId, exception: exception, message: exception.Message);

                throw;
            }
        }
Beispiel #5
0
        /// <inheritdoc />
        public async Task <IReadOnlyCollection <MarketSummaryDto> > GetAsync(ICoinBuilder builder)
        {
            try
            {
                IReadOnlyList <GdaxProduct> products = await this.GetProductsAsync();

                IReadOnlyList <GdaxTicker?> tickers = await Batched.WhenAllAsync(concurrent : 2, products.Select(selector: product => this.GetTickerAsync(product.Id)));

                return(tickers.RemoveNulls()
                       .Select(selector: ticker => this.CreateMarketSummaryDto(ticker: ticker, builder: builder))
                       .RemoveNulls()
                       .ToList());
            }
            catch (Exception e)
            {
                this.Logger.LogError(new EventId(e.HResult), exception: e, message: e.Message);

                throw;
            }
        }
Beispiel #6
0
        /// <inheritdoc />
        public async Task <IReadOnlyCollection <MarketSummaryDto> > GetAsync(ICoinBuilder builder)
        {
            try
            {
                IReadOnlyList <KrakenAsset> assets = await this.GetAssetsAsync();

                bool IsValid(KrakenPair pair)
                {
                    // todo: can't get kraken details on these markets
                    if (pair.PairId.EndsWith(value: ".d", comparisonType: StringComparison.Ordinal))
                    {
                        return(false);
                    }

                    string?bc = FindCurrency(assets: assets, search: pair.BaseCurrency);

                    if (bc == null)
                    {
                        return(false);
                    }

                    string?qc = FindCurrency(assets: assets, search: pair.QuoteCurrency);

                    if (qc == null)
                    {
                        return(false);
                    }

                    Currency?baseCurrency = builder.Get(bc);

                    if (baseCurrency == null)
                    {
                        return(false);
                    }

                    Currency?quoteCurrency = builder.Get(qc);

                    if (quoteCurrency == null)
                    {
                        return(false);
                    }

                    return(true);
                }

                IReadOnlyList <KrakenPair> pairs = await this.GetPairsAsync();

                IReadOnlyList <KrakenTicker?> tickers = await Batched.WhenAllAsync(concurrent : 5,
                                                                                   pairs.Where(IsValid)
                                                                                   .Select(this.GetTickerAsync));

                return(tickers.RemoveNulls()
                       .Select(selector: m => this.CreateMarketSummaryDto(assets: assets, ticker: m, builder: builder))
                       .RemoveNulls()
                       .ToList());
            }
            catch (Exception e)
            {
                this.Logger.LogError(new EventId(e.HResult), exception: e, message: e.Message);

                throw;
            }
        }