Exemplo n.º 1
0
        public override async void DispatchSearchAsync(string[] ids = null)
        {
            if (ids == null)
            {
                throw new ArgumentException();
            }

            for (var i = 0; i <= ids.Length / 10; i++)
            {
                var subIds    = ids.Skip(i * 10).Take(10);
                var concatIds = string.Join(",", subIds);

                PrintColorMsg(ConsoleColor.Blue, "New", concatIds);

                if (string.IsNullOrWhiteSpace(concatIds) || string.IsNullOrWhiteSpace(concatIds))
                {
                    continue;
                }

                // Make POST request
                var jsonString = await AsyncRequest(concatIds);

                try {
                    var data = jsonString?.ParseJSON <ApiDeserializer>();
                    data?.result.ForEach(t => DispatchNewItem?.Invoke(Converter.ConvertPoe(t)));
                } catch (JsonSerializationException e) {
                    Console.WriteLine(jsonString);
                    Console.WriteLine(e);
                }
            }
        }
Exemplo n.º 2
0
        public override async void DispatchSearchAsync(string[] ids = null)
        {
            if (ids != null)
            {
                throw new ArgumentException();
            }

            PrintColorMsg(ConsoleColor.Blue, "Notify", _lastId.ToString());

            // Make POST request
            var jsonString = await AsyncRequest(_lastId.ToString());

            var data = jsonString?.ParseJSON <ApiDeserializer>();

            if (jsonString == null)
            {
                PrintColorMsg(ConsoleColor.Blue, "Invalid reply", _lastId.ToString());
                return;
            }

            _lastId = data.NewId;

            // Subscribe
            foreach (var uniq in data.Uniqs)
            {
                var payload = new { type = "subscribe", value = uniq };
                WebSocket.Send(payload.ToJSON());
            }

            // Parse item data
            var items = HtmlParser.ParsePoeTrade(data.Data);

            // Give each item its uniq
            for (var i = 0; i < data.Count; i++)
            {
                items[i].Uniq = data.Uniqs[i];
            }

            items.ForEach(t => DispatchNewItem?.Invoke(Converter.ConvertPt(t)));
        }