private static YConfig <T> Retrieve(string filename, Func <string, string> PreProccessContent = null) { if (string.IsNullOrWhiteSpace(filename)) { return(null); } try { //Read in configuration array from file pointed to by input param (or falling back to default file) #if NETFX var content = File.ReadAllText(filename); #elif UNIVERSAL var ss = new Tools.StorageService(false); var content = ss.LoadFile(filename).GetResults(); #endif if (PreProccessContent != null) { content = PreProccessContent(content); } //deserialize into List of Configurations and pick the active one return(content.FromJSON <YConfig <T> >()); } catch (Exception ex) { DebugEx.TraceLog("Failed to read config file : " + ex.Message); return(null); } }
public override bool Save() { if (string.IsNullOrWhiteSpace(this.Filename)) { return(false); } try { String cfg = JsonConvert.SerializeObject(this, Formatting.Indented); #if NETFX File.WriteAllText(Filename, cfg); return(true); #elif UNIVERSAL var ss = new Tools.StorageService(false); return(ss.SaveFile(Filename, cfg).GetResults()); #endif } catch (Exception ex) { DebugEx.TraceLog("Error: Failed to write configFile {0}", ex.Message); return(false); } }