/// <summary> /// Load the collection from a remote json file /// </summary> /// <param name="remoteUri">the url to the remote json file</param> /// <returns>the loaded collection</returns> public static async Task <PadoruCollection> FromRemoteJson(Uri remoteUri) { //download uri as string using (WebClient web = new WebClient()) { //download json string string json = await web.DownloadStringTaskAsync(remoteUri); //deserialize object PadoruCollection padoru = FromJson(json); //set collection source padoru.LoadedFrom = remoteUri.ToString(); padoru.LoadedLocal = false; //return loaded collection return(padoru); } }
/// <summary> /// Load the collection from a json file /// </summary> /// <param name="filePath">the path to the json file</param> /// <returns>the loaded collection</returns> public static PadoruCollection FromFile(string filePath) { //read from file using (StreamReader reader = File.OpenText(filePath)) { //read serialized object PadoruCollection collection = GetSerializer().Deserialize(reader, typeof(PadoruCollection)) as PadoruCollection; //set collection load type collection.LoadedFrom = filePath; collection.LoadedLocal = true; //set parent collection of all entries foreach (PadoruEntry entry in collection.Entries) { entry.ParentCollection = collection; } //return the deserialized and initialized object return(collection); } }
/// <summary> /// Load the collection from a json string /// </summary> /// <param name="json">the json string</param> /// <returns>the loaded collection</returns> public static PadoruCollection FromJson(string json) { //read from file using (StringReader reader = new StringReader(json)) { //read serialized object PadoruCollection collection = GetSerializer().Deserialize(reader, typeof(PadoruCollection)) as PadoruCollection; //set collection load type collection.LoadedFrom = string.Empty; collection.LoadedLocal = true; //set parent collection of all entries foreach (PadoruEntry entry in collection.Entries) { entry.ParentCollection = collection; } //return the deserialized and initialized object return(collection); } }