Пример #1
0
		public static async Task InitializeAsync()
		{
			if (!IsInitialized)
			{
				var today = DateTime.Now.Date;
				using (var store = new Datastore(true))
				{
					bool minDateSet = false;
					DateTime minDate = today.AddDays(-31).Date;
					var lastRecordedStartDate = await store.ReadImageInfoLastStartdate();

					if (lastRecordedStartDate.HasValue)
					{
						DateTime newMinDate;
						if (BingDataHelper.TryConvertStartdate(lastRecordedStartDate.Value, out newMinDate) && newMinDate >= minDate)
						{
							minDate = newMinDate;
						}
						var tmp = await store.ReadImageInfoFirstStartdate();
						if (tmp.HasValue && BingDataHelper.TryConvertStartdate(tmp.Value, out newMinDate))
						{
							Setting.GetCurrentSetting().SetBingDateMin(newMinDate);
							minDateSet = true;
						}
					}

					if (minDate < today)
					{
						var infos = InitializeAsyncAcquireMissingInfos(ref today, ref minDate);
						await store.SaveDatesAsync(infos);
					}

					if (!minDateSet)
					{
						Setting.GetCurrentSetting().SetBingDateMin(minDate);
						minDateSet = true;
					}
					Setting.GetCurrentSetting().SetBingDateMax(today);
				}
				_readonlyStore = new Datastore();
				_isInitialized = true;
			};
		}