Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var settings = new JsonSerializerSettings
            {
                MissingMemberHandling = MissingMemberHandling.Error,
                Error            = JsonLoader.DeserializationErrorHandler,
                ContractResolver = new PropertyContractResolver(PropertyMapperHelper.PriceDeserialization)
            };

            ILoader dataLoader = new JsonLoader();
            var     drinks     = dataLoader.Load <Drink>(Path.Combine("Data", "prices.json"), settings);

            settings = new JsonSerializerSettings
            {
                MissingMemberHandling = MissingMemberHandling.Error,
                Error            = JsonLoader.DeserializationErrorHandler,
                ContractResolver = new ErrorContractResolver()
            };
            var orders   = dataLoader.Load <Order>(Path.Combine("Data", "orders.json"), settings);
            var payments = dataLoader.Load <Payment>(Path.Combine("Data", "payments.json"), settings);

            ICalculator calculator            = new StandardCalculator();
            var         totalCostsForUsers    = calculator.CalculateTotalCosts(orders, drinks);
            var         totalPaymentsForUsers = calculator.CalculateTotalPayments(payments);
            var         balanceForUsers       = calculator.CalculateBalance(totalCostsForUsers, totalPaymentsForUsers).ToList();

            settings = new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new PropertyContractResolver(PropertyMapperHelper.BalanceSerialization)
            };
            dataLoader.Save(Path.Combine("Data", "result.json"), balanceForUsers, settings);
            Console.WriteLine($"The program has finished. The result was stored to {Path.Combine(Directory.GetCurrentDirectory(), "Data", "result.json")}");
        }
Ejemplo n.º 2
0
        async Task GetAssetMatadataAsync(AssetMetadata assetMetadata)
        {
            var uri = new Uri(string.Format($"http://{Utils.Config("assetsDiscovery")}/AssetMetadata/Index/" + HttpServerUtility.UrlTokenEncode(assetMetadata.Asset)));

            InfrastructureTrace.Information($"Loading asset metadata from web: {uri.AbsoluteUri}");
            using (var response = await new HttpClient().GetAsync(uri.AbsoluteUri))
            {
                if (response.IsSuccessStatusCode)
                {
                    var remoteString = await response.Content.ReadAsStringAsync();

                    try
                    {
                        //Version currentVersion = null;
                        //Version remoteVersion = null;

                        var remoteJson = JsonConvert.DeserializeObject <AssetMetadataJson>(remoteString);

                        //currentVersion = _Cache.Value.ContainsKey(_hash) ? new Version(_Cache.Value[_hash].version) : new Version();
                        //remoteVersion = remoteJson.version == null ? new Version() : new Version(remoteJson.version);

                        //TODO: check if newer version
                        //if (remoteVersion > currentVersion)

                        //TODO: fetch image

                        if (string.IsNullOrWhiteSpace(remoteJson.name))
                        {
                            //assetMetadata.Display += " (No metadada)";
                        }
                        else
                        {
                            lock (_lock)
                            {
                                assetMetadata.Display = remoteJson.name;
                                _CacheJsonStore.Value[Convert.ToBase64String(assetMetadata.Asset)] = remoteJson;
                                _CacheJsonStore.Save();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        InfrastructureTrace.Information($"Error fetching asset metadata from url: {uri.AbsoluteUri}");
                        assetMetadata.Display += " (Metadata error)";
                    }
                }
                else
                {
                    assetMetadata.Display += " (Network error)";
                }
            }
        }
Ejemplo n.º 3
0
 public void Save()
 {
     _userData._Gold = _goldData._Gold;
     _jsonLoader.Save(_userData);
 }