Exemplo n.º 1
0
        private static MoneyEvent ReadMoneyEvent(dynamic moneyEventD)
        {
            MoneyEventType?type = null;

            if (moneyEventD.type != null)
            {
                type = StringToMoneyEventType((string)moneyEventD.type);
                if (type == MoneyEventType.Unknown)
                {
                    return(null);
                }
            }

            DateTime?time = null;

            if (moneyEventD.time != null)
            {
                time = DateTimeExtension.FromUnixTime((long)moneyEventD.time);
            }

            double?amount      = null;
            string description = "";

            if (type == MoneyEventType.ItemBought || type == MoneyEventType.ItemSold)
            {
                amount = moneyEventD.price ?? null;
                if (moneyEventD.medium.app_id != null && moneyEventD.medium.market_hash_name != null)
                {
                    description = $"{moneyEventD.medium.app_id}:{moneyEventD.medium.market_hash_name}";
                }
            }
            else if (type == MoneyEventType.SaleFee || type == MoneyEventType.BuyCredit || type == MoneyEventType.StoreCredit)
            {
                amount = moneyEventD.amount ?? null;
                if (moneyEventD.medium != null)
                {
                    description = $"{moneyEventD.medium}";
                }
            }
            else
            {
                throw new InvalidOperationException();
            }

            MoneyEvent moneyEvent = new MoneyEvent(type, amount, description, time);

            return(moneyEvent);
        }
Exemplo n.º 2
0
        private static List <MoneyEvent> ReadMoneyEvents(string result)
        {
            dynamic responseServerD = JsonConvert.DeserializeObject(result);
            dynamic moneyEventsD    = responseServerD.data.events;

            List <MoneyEvent> moneyEvents = new List <MoneyEvent>();

            if (moneyEventsD != null)
            {
                foreach (dynamic moneyEventD in moneyEventsD)
                {
                    MoneyEvent moneyEvent = ReadMoneyEvent(moneyEventD);
                    if (moneyEvent != null)
                    {
                        moneyEvents.Add(moneyEvent);
                    }
                }
            }

            return(moneyEvents);
        }