コード例 #1
0
        private CurrencyCache DownloadPrice(int WantItemId, int HaveItemId)
        {
            var url = @"http://currency.poe.trade/search?league=" + League + "&online=x&have=" + HaveItemId + "&want=" + WantItemId;

            CurrencyCache price = new CurrencyCache()
            {
                Url           = url,
                bIsDownloaded = false,
                Value         = 0,
                topX          = TopN,
                CurrencyId    = WantItemId
            };

            if (WantItemId == HaveItemId)
            {
                price.bIsDownloaded = true;
                price.Value         = 1;
                return(price);
            }

            try
            {
                WebClient webClient = new WebClient();
                webClient.DownloadStringCompleted += price.OnGetDownloadedStringCompleted;
                webClient.DownloadStringAsync(new Uri(price.Url));
            }
            catch
            {
                MessageBox.Show("DropStatistics Error processing: Url: " + price.Url,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(price);
        }
コード例 #2
0
        public void Initialize()
        {
            ServiceProvider.MessageBuilder   = new MessageBuilder();
            ServiceProvider.MainMenuFactory  = new MainMenuListFactory();
            ServiceProvider.CurrencyProvider = new DefaultCurrencyProvider();

            StorageFactory storageFactory = new StorageFactory();

            ServiceProvider.EventSourcingContextFactory = storageFactory;
            ServiceProvider.ReadModelContextFactory     = storageFactory;
            ServiceProvider.StorageContainerFactory     = storageFactory;

            Domain();

            PriceCalculator priceCalculator = new PriceCalculator(eventDispatcher.Handlers);

            ServiceProvider.PriceConverter = priceCalculator;

            ReadModels();

            ServiceProvider.QueryDispatcher   = new UserQueryDispatcher(queryDispatcher, () => UserKey);
            ServiceProvider.CommandDispatcher = new UserCommandDispatcher(commandDispatcher, () => UserKey);
            ServiceProvider.EventHandlers     = eventDispatcher.Handlers;

            UpgradeService upgradeService = new UpgradeService(ServiceProvider.CommandDispatcher, EventStore, EventFormatter, storageFactory, storageFactory, storageFactory, priceCalculator, () => UserKey);

            ServiceProvider.UpgradeService = upgradeService;

            ServiceProvider.TileService      = new TileService();
            ServiceProvider.DevelopmentTools = new DevelopmentService(upgradeService, storageFactory);
            ServiceProvider.RestartService   = new RestartService(launchArguments);
            ServiceProvider.AppDataService   = new AppDataService(storageFactory, upgradeService);
            ServiceProvider.UserPreferences  = new ApplicationSettingsService(new CompositeTypeFormatterFactory(typeProvider), storageFactory);

            CurrencyCache currencyCache = new CurrencyCache(eventDispatcher.Handlers, queryDispatcher);

            using (var eventSourcing = ServiceProvider.EventSourcingContextFactory.Create())
                eventSourcing.Database.EnsureCreated();

            using (var readModels = ServiceProvider.ReadModelContextFactory.Create())
                readModels.Database.EnsureCreated();

            if (ServiceProvider.UpgradeService.IsRequired())
            {
                ServiceProvider.UpgradeService.Completed += async() =>
                {
                    Task delay           = Task.Delay(5000);
                    Task currencyCreated = eventDispatcher.Handlers.Await <CurrencyCreated>();

                    await Task.WhenAny(delay, currencyCreated);

                    await Task.Delay(1000);
                    await InitializeCacheAsync(priceCalculator, currencyCache);
                };
            }
            else
            {
                _ = InitializeCacheAsync(priceCalculator, currencyCache);
            }
        }
コード例 #3
0
        public double GetPriceInChaos(string ItemBaseNameFriendly)
        {
            CurrencyCache result;

            if (!PriceCache.TryGetValue(ItemBaseNameFriendly, out result))
            {
                if (PoeTradeCurrencyIndex.ContainsKey(ItemBaseNameFriendly))
                {
                    result = DownloadPrice(PoeTradeCurrencyIndex[ItemBaseNameFriendly], PoeTradeCurrencyIndex["Chaos Orb"]);
                }
                else
                {
                    result       = new CurrencyCache();
                    result.Value = -1;
                }
                PriceCache.Add(ItemBaseNameFriendly, result);
            }
            if (result.bIsDownloaded)
            {
                return(result.Value);
            }
            else
            {
                return(0);
            }
        }
コード例 #4
0
        public void Initialize()
        {
            ServiceProvider.MessageBuilder   = new MessageBuilder();
            ServiceProvider.MainMenuFactory  = new MainMenuListFactory();
            ServiceProvider.CurrencyProvider = new DefaultCurrencyProvider();

            StorageFactory storageFactory = new StorageFactory();

            ServiceProvider.EventSourcingContextFactory = storageFactory;
            ServiceProvider.ReadModelContextFactory     = storageFactory;
            ServiceProvider.StorageContainerFactory     = storageFactory;

            Domain();

            PriceCalculator priceCalculator = new PriceCalculator(eventDispatcher.Handlers);

            ServiceProvider.PriceConverter = priceCalculator;

            ReadModels();

            ServiceProvider.QueryDispatcher   = new UserQueryDispatcher(queryDispatcher, () => UserKey);
            ServiceProvider.CommandDispatcher = new UserCommandDispatcher(commandDispatcher, () => UserKey);
            ServiceProvider.EventHandlers     = eventDispatcher.Handlers;

            UpgradeService upgradeService = new UpgradeService(ServiceProvider.CommandDispatcher, EventStore, EventFormatter, storageFactory, storageFactory, storageFactory, priceCalculator, () => UserKey);

            ServiceProvider.UpgradeService = upgradeService;

            ServiceProvider.TileService      = new TileService();
            ServiceProvider.DevelopmentTools = new DevelopmentService(upgradeService, storageFactory);
            ServiceProvider.RestartService   = new RestartService(launchArguments);
            ServiceProvider.UserPreferences  = new ApplicationSettingsService(new CompositeTypeFormatterFactory(typeProvider), storageFactory);

            CurrencyCache currencyCache = new CurrencyCache(eventDispatcher.Handlers, queryDispatcher);

            using (var eventSourcing = ServiceProvider.EventSourcingContextFactory.Create())
                eventSourcing.Database.EnsureCreated();

            using (var readModels = ServiceProvider.ReadModelContextFactory.Create())
                readModels.Database.EnsureCreated();

            currencyCache.InitializeAsync(ServiceProvider.QueryDispatcher);
            priceCalculator.InitializeAsync(ServiceProvider.QueryDispatcher);
        }
コード例 #5
0
        public async Task <JObject> FetchCurrencyData(string baseCurrency, string symbol, int cooldownTimeMs)
        {
            try
            {
                string dictKey = $"{baseCurrency}{symbol}";
                if (dictCurrencyCache.ContainsKey(dictKey))
                {
                    var currencyCache = dictCurrencyCache[dictKey];
                    if (currencyCache != null && (DateTime.Now - currencyCache.LastRefresh).TotalMilliseconds <= cooldownTimeMs)
                    {
                        Logger.Instance.LogMessage(TracingLevel.INFO, $"FetchCurrencyData in Cooldown for Base: {baseCurrency} Symbol: {symbol}");
                        return(currencyCache.CurrencyData);
                    }
                }

                using (HttpClient client = new HttpClient())
                {
                    string url      = String.Format(CURRENCY_FETCH_URI, baseCurrency, symbol);
                    var    response = await client.GetAsync(url);

                    if (!response.IsSuccessStatusCode)
                    {
                        Logger.Instance.LogMessage(TracingLevel.WARN, $"FetchCurrencyData: Could not fetch data for Base: {baseCurrency} and Symbol: {symbol} - {response.StatusCode}");
                        return(null);
                    }

                    string body = await response.Content.ReadAsStringAsync();

                    JObject obj = JObject.Parse(body);
                    dictCurrencyCache[dictKey] = new CurrencyCache(DateTime.Now, obj);
                    return(obj);
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"FetchCurrencyData: Error fetching currency data {ex}");
                return(null);
            }
        }
コード例 #6
0
ファイル: BootstrapTask.cs プロジェクト: onixus74/Money
        public void Initialize()
        {
            logFactory = new DefaultLogFactory("Root").AddSerializer(new ConsoleSerializer());
            errorLog   = logFactory.Scope("Error");

            readModelContextFactory     = Factory.Getter(() => new ReadModelContext(connectionStrings.ReadModel));
            eventSourcingContextFactory = Factory.Getter(() => new EventSourcingContext(connectionStrings.EventSourcing));
            CreateReadModelContext();
            CreateEventSourcingContext();

            exceptionHandlerBuilder = new ExceptionHandlerBuilder();

            services
            .AddSingleton(readModelContextFactory)
            .AddSingleton(eventSourcingContextFactory)
            .AddSingleton(exceptionHandlerBuilder)
            .AddSingleton <IExceptionHandler>(exceptionHandlerBuilder);

            Domain();

            priceCalculator = new PriceCalculator(eventDispatcher.Handlers, queryDispatcher);

            services
            .AddSingleton(priceCalculator)
            .AddSingleton(new FormatterContainer(commandFormatter, eventFormatter, queryFormatter, exceptionFormatter));

            ReadModels();

            services
            .AddSingleton <IEventHandlerCollection>(eventDispatcher.Handlers)
            .AddScoped <ICommandDispatcher>(provider => new UserCommandDispatcher(commandDispatcher, provider.GetService <IHttpContextAccessor>().HttpContext, provider.GetService <ApiHub>()))
            .AddScoped <IQueryDispatcher>(provider => new UserQueryDispatcher(queryDispatcher, provider.GetService <IHttpContextAccessor>().HttpContext));

            CurrencyCache currencyCache = new CurrencyCache(eventDispatcher.Handlers, queryDispatcher, queryDispatcher);

            services
            .AddSingleton(currencyCache);
        }
コード例 #7
0
ファイル: BootstrapTask.cs プロジェクト: ScriptBox21/Money
        public void Initialize()
        {
            Logging();

            exceptionHandlerBuilder = new ExceptionHandlerBuilder();
            exceptionHandlerBuilder.Handler(Handle);

            services
            .AddDbContextWithSchema <ReadModelContext>(connectionStrings.GetSection("ReadModel"), pathResolver)
            .AddDbContextWithSchema <EventSourcingContext>(connectionStrings.GetSection("EventSourcing"), pathResolver)
            .AddSingleton(exceptionHandlerBuilder)
            .AddSingleton <IExceptionHandler>(exceptionHandlerBuilder);

            var provider = services.BuildServiceProvider();

            Domain(provider);

            priceCalculator = new PriceCalculator(eventDispatcher.Handlers, queryDispatcher);

            services
            .AddSingleton(priceCalculator)
            .AddSingleton(new FormatterContainer(commandFormatter, eventFormatter, queryFormatter, exceptionFormatter));

            CreateReadModelContext(provider);
            CreateEventSourcingContext(provider);
            ReadModels(provider);

            services
            .AddSingleton <IEventHandlerCollection>(eventDispatcher.Handlers)
            .AddScoped <ICommandDispatcher>(provider => new UserCommandDispatcher(commandDispatcher, provider.GetService <IHttpContextAccessor>().HttpContext, provider.GetService <ApiHub>()))
            .AddScoped <IQueryDispatcher>(provider => new UserQueryDispatcher(queryDispatcher, provider.GetService <IHttpContextAccessor>().HttpContext));

            CurrencyCache currencyCache = new CurrencyCache(eventDispatcher.Handlers, queryDispatcher, queryDispatcher);

            services
            .AddSingleton(currencyCache);
        }
コード例 #8
0
        private async Task InitializeCacheAsync(PriceCalculator priceCalculator, CurrencyCache currencyCache)
        {
            await currencyCache.InitializeAsync(ServiceProvider.QueryDispatcher);

            await priceCalculator.InitializeAsync(ServiceProvider.QueryDispatcher);
        }
コード例 #9
0
        internal async Task <float?> FetchCurrencyData(CurrencyType baseCurrency, CurrencyType symbol)
        {
            if (!TokenExists())
            {
                Logger.Instance.LogMessage(TracingLevel.WARN, $"{this.GetType()} FetchCurrencyData was called without a valid API token");
                return(null);
            }

            try
            {
                string dictKey = $"{baseCurrency}_{symbol}";
                if (dictCurrencyCache.ContainsKey(dictKey))
                {
                    var currencyCache = dictCurrencyCache[dictKey];
                    if (currencyCache != null && (DateTime.Now - currencyCache.LastRefresh).TotalSeconds <= CURRENCY_FETCH_COOLDOWN_SEC)
                    {
                        return(currencyCache.Value);
                    }
                }

                Logger.Instance.LogMessage(TracingLevel.INFO, $"FetchCurrencyData called for Base: {baseCurrency} Symbol: {symbol}");
                using (HttpClient client = new HttpClient())
                {
                    string apiKey = TokenManager.Instance.Token?.CurrencyToken;
                    if (string.IsNullOrEmpty(apiKey))
                    {
                        Logger.Instance.LogMessage(TracingLevel.ERROR, $"{this.GetType()}: TokenManager returned empty currency API token");
                        return(null);
                    }
                    string url      = String.Format(CURRENCY_FETCH_URI, dictKey, apiKey);
                    var    response = await client.GetAsync(url);

                    if (!response.IsSuccessStatusCode)
                    {
                        Logger.Instance.LogMessage(TracingLevel.WARN, $"FetchCurrencyData: Server failed when fetching data for Base: {baseCurrency} and Symbol: {symbol} - {response.StatusCode}");
                        // Try and parse error
                        try
                        {
                            string error = await response.Content.ReadAsStringAsync();

                            Logger.Instance.LogMessage(TracingLevel.WARN, $"{this.GetType()} Server Error: {error}");
                        }
                        catch { }
                        return(null);
                    }

                    string body = await response.Content.ReadAsStringAsync();

                    JObject obj = JObject.Parse(body);
                    if (!obj.ContainsKey(dictKey))
                    {
                        Logger.Instance.LogMessage(TracingLevel.ERROR, $"{this.GetType()} FetchCurrencyData server returned invalid data: {obj}");
                        return(null);
                    }
                    float value = (float)obj[dictKey];
                    dictCurrencyCache[dictKey] = new CurrencyCache(DateTime.Now, dictKey, value);
                    return(value);
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"FetchCurrencyData: Error fetching currency data {ex}");
                return(null);
            }
        }
コード例 #10
0
ファイル: WebFigureProvider.cs プロジェクト: bg0jr/RaynMaker
 public WebFigureProvider(StorageService storageService, ILutService lutService)
 {
     myStorageService = storageService;
     myLutService     = lutService;
     myCurrencyCache  = new CurrencyCache();
 }