public static string GetFileSuffixForOpenETSyncHistoryDto(this OpenETSyncHistoryDto openETSyncHistoryDto,
                                                           string platformName)
 {
     return
         ($"{platformName}_{openETSyncHistoryDto.WaterYear.Year}_{openETSyncHistoryDto.CreateDate:yyyyMMddhhmmss}");
 }
Esempio n. 2
0
        public static bool RasterUpdatedSinceMinimumLastUpdatedDate(RioConfiguration rioConfiguration,
                                                                    RioDbContext rioDbContext, int year, OpenETSyncHistoryDto newSyncHistory)
        {
            var openETRequestURL =
                $"{rioConfiguration.OpenETCheckRasterUpdatedDateBaseURL}?geom=-120.30921936035156,36.99542364399086,-120.30887603759766,36.98143783973302,-120.2918815612793,36.982260605282676,-120.29170989990234,36.99556074698967,-120.30921936035156,36.99542364399086&api_key={rioConfiguration.OpenETAPIKey}&start_date={new DateTime(year, 1, 1):yyyy-MM-dd}&end_date={new DateTime(year, 12, 31):yyyy-MM-dd}&model=ensemble&vars=et&prop=date_ingested";

            var httpClient = new HttpClient
            {
                Timeout = new TimeSpan(60 * TimeSpan.TicksPerSecond)
            };

            var response = httpClient.GetAsync(openETRequestURL).Result;

            //If we don't get a good response, let's just say that there needs to be an update to cover our bases
            if (!response.IsSuccessStatusCode)
            {
                return(true);
            }

            var responseObject = JsonConvert.DeserializeObject <RasterMetadataDateIngested>(response.Content.ReadAsStringAsync().Result);

            if (string.IsNullOrEmpty(responseObject.DateIngested) ||
                !DateTime.TryParse(responseObject.DateIngested, out DateTime responseDate))
            {
                OpenETSyncHistory.UpdateSyncResultByID(rioDbContext, newSyncHistory.OpenETSyncHistoryID, OpenETSyncResultTypeEnum.DataNotAvailable);
                return(false);
            }

            var openETSyncHistoriesThatHaventFailed = rioDbContext.OpenETSyncHistory
                                                      .Include(x => x.WaterYear)
                                                      .Where(x => x.WaterYear.Year == year &&
                                                             (x.OpenETSyncResultTypeID != (int)OpenETSyncResultTypeEnum.Failed) && x.OpenETSyncHistoryID != newSyncHistory.OpenETSyncHistoryID);

            if (!openETSyncHistoriesThatHaventFailed.Any())
            {
                return(true);
            }

            var mostRecentSyncHistory = openETSyncHistoriesThatHaventFailed?.OrderByDescending(x => x.UpdateDate).First();

            if (responseDate > mostRecentSyncHistory.UpdateDate)
            {
                return(true);
            }

            OpenETSyncHistory.UpdateSyncResultByID(rioDbContext, newSyncHistory.OpenETSyncHistoryID, OpenETSyncResultTypeEnum.NoNewData);
            return(false);
        }