Пример #1
0
        public async Task Run()
        {
            // create a client for interacting with the NEM API
            var nemClient = new NEMClient();
            var data      = await nemClient.Get5MinDataAsync();

            var httpClient = new HttpClient();
            var authClient = new AuthenticationClient(httpClient);

            var token = await authClient.RequestTokenAsync("0", new TokenRequest { Username = settings.UserName, Password = settings.Password });

            token = token.Trim('\"'); // there may be extra quotes on that string
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            try
            {
                var amphoraeClient = new AmphoraeClient(httpClient);
                var map            = Mapping.Map; // load the Map
                // run in parallel for performance
                var nswTask = Task.Run(() => UploadPointsAsync(Region.Nsw1, data.Data.Where(d => d.Region == Region.Nsw1), amphoraeClient, map));
                var vicTask = Task.Run(() => UploadPointsAsync(Region.Vic1, data.Data.Where(d => d.Region == Region.Vic1), amphoraeClient, map));
                var qldTask = Task.Run(() => UploadPointsAsync(Region.Qld1, data.Data.Where(d => d.Region == Region.Qld1), amphoraeClient, map));
                var saTask  = Task.Run(() => UploadPointsAsync(Region.Sa1, data.Data.Where(d => d.Region == Region.Sa1), amphoraeClient, map));
                var tasTask = Task.Run(() => UploadPointsAsync(Region.Tas1, data.Data.Where(d => d.Region == Region.Tas1), amphoraeClient
                                                               , map));

                await Task.WhenAll(nswTask, vicTask, qldTask, saTask, tasTask);
            }
            catch (ApiException ex)
            {
                log.LogError($"Engine Failed, Message: {ex.Message} ", ex);
                throw ex;
            }
        }
Пример #2
0
        public async Task <RunSummary> Run()
        {
            // create a client for interacting with the NEM API
            var nemClient = new NEMClient();
            var data      = await nemClient.Get5MinDataAsync();

            var authClient = new AuthenticationClient(HttpClient);

            authClient.BaseUrl = settings.BaseUrl;
            var token = await authClient.RequestTokenAsync("0", new LoginRequest { Username = settings.UserName, Password = settings.Password });

            token = token.Trim('\"'); // there may be extra quotes on that string
            HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            try
            {
                var signalsClient = new AmphoraeSignalsClient(HttpClient);
                signalsClient.BaseUrl = settings.BaseUrl;
                var actualsMap   = Mapping.Actuals; // load the Maps
                var forecastsMap = Mapping.Forecasts;

                // run in parallel for performance
                // ACTUALS
                var nswActualsTask = Task.Run(() => UploadActualAsync(Region.Nsw1,
                                                                      data.Data,
                                                                      signalsClient, actualsMap));
                var vicActualsTask = Task.Run(() => UploadActualAsync(Region.Vic1,
                                                                      data.Data,
                                                                      signalsClient, actualsMap));
                var qldActualsTask = Task.Run(() => UploadActualAsync(Region.Qld1,
                                                                      data.Data,
                                                                      signalsClient, actualsMap));
                var saActualsTask = Task.Run(() => UploadActualAsync(Region.Sa1,
                                                                     data.Data,
                                                                     signalsClient, actualsMap));
                var tasActualsTask = Task.Run(() => UploadActualAsync(Region.Tas1,
                                                                      data.Data,
                                                                      signalsClient, actualsMap));

                // FORECASTS
                var nswForecastsTask = Task.Run(() => UploadForecastsAsync(Region.Nsw1,
                                                                           data.Data,
                                                                           signalsClient, forecastsMap));
                var vicForecastsTask = Task.Run(() => UploadForecastsAsync(Region.Vic1,
                                                                           data.Data,
                                                                           signalsClient, forecastsMap));
                var qldForecastsTask = Task.Run(() => UploadForecastsAsync(Region.Qld1,
                                                                           data.Data,
                                                                           signalsClient, forecastsMap));
                var saForecastsTask = Task.Run(() => UploadForecastsAsync(Region.Sa1,
                                                                          data.Data,
                                                                          signalsClient, forecastsMap));
                var tasForecastsTask = Task.Run(() => UploadForecastsAsync(Region.Tas1,
                                                                           data.Data,
                                                                           signalsClient, forecastsMap));

                var results = await Task.WhenAll(nswActualsTask,
                                                 vicActualsTask,
                                                 qldActualsTask,
                                                 saActualsTask,
                                                 tasActualsTask,
                                                 nswForecastsTask,
                                                 vicForecastsTask,
                                                 qldForecastsTask,
                                                 saForecastsTask,
                                                 tasForecastsTask);

                return(new RunSummary(results.ToList()));
            }
            catch (ApiException ex)
            {
                log.LogError($"Engine Failed, Message: {ex.Message} ", ex);
                throw ex;
            }
        }