Пример #1
0
		public void RestoreArchive(JsonDb archive)
		{
			this.db.data.InsertRange(0, archive.data);
			this.db.count += archive.count;
		}
Пример #2
0
		void LoadJson()
		{
			// load cache
			try
			{
				using (var stream = System.IO.File.OpenText(Config.Resource_Prefix + Config.DB_CAR_FILE))
					this.db = Newtonsoft.Json.JsonConvert.DeserializeObject<JsonDb>(stream.ReadToEnd());
				return; // return and delete cache
			}
			catch (System.NullReferenceException)
			{
				Debug.WriteLine("DB:\t\tLoading: Unrecognizable JsonDb");
			}
			catch (System.IO.FileNotFoundException)
			{
				Debug.WriteLine("DB:\t\tLoading: FNF: " + Config.DB_CAR_FILE);
			}
			finally
			{
				// delete cache
				try
				{
					if (System.IO.File.Exists(Config.Resource_Prefix + Config.DB_CAR_FILE))
						System.IO.File.Delete(Config.Resource_Prefix + Config.DB_CAR_FILE);
				}
				catch (System.IO.IOException e)
				{
					Debug.WriteLine("DB:\t\tLoading: Couldn't delete cache: " + e.Message);
				}
			}

			// if load failed, create new and initialize new JsonDb for Solar.Status
			this.db = new JsonDb { count = 0, headers = new List<string> { }, data = new List<List<object>> { } };
			foreach (var prop in typeof(Status).GetProperties())
				this.db.headers.Add(prop.Name);
		}
Пример #3
0
		public JsonDb GetArchive()
		{
			JsonDb archive = this.db;
			this.db = new JsonDb
			{
				count = 0,
				headers = new List<string>(archive.headers), 
				data = new List<List<object>>{ } 
			};
			return archive;
		}