private static void SaveConfiguration(string configFilename, MainForm form) { XmlDataFormat.SerializeTo(configFilename, writer => { var root = writer.BeginChildObject("Configuration"); var uiWriter = root.BeginChildObject("UI"); form.SaveConfiguration(uiWriter); root.EndChildObject(uiWriter); writer.EndChildObject(root); }); }
private static void LoadConfiguration(string configFilename, MainForm form) { try { XmlDataFormat.DeserializeFrom(configFilename, reader => { var root = reader.TryGetChildStorage("Configuration"); var uiReader = root?.TryGetChildStorage("UI"); if (uiReader != null) { form.LoadConfiguration(uiReader); } }); } catch (Exception exc) { Log.Error("Configuration load fail.", exc); } }
static void Main(string[] args) { // Set up data string initialDirectory = "C:\\Users\\eedee\\Documents"; string jsonSource = "test_json.json"; string jsonForDB = "test_db_json.json"; string excelSource = "testExcel.xlsx"; string apiSource = "http://ewhiting.eastus.cloudapp.azure.com/midterm/Classes/Genre/read.php"; // Basic demo List <string> attrs = new List <string>(); attrs.Add("name"); attrs.Add("job"); attrs.Add("age"); DataFormat excelDF = new ExcelDataFormat(initialDirectory + "\\" + jsonSource, attrs, SourceDataType.JSON); DataFormat jsonDF = new JsonDataFormat(initialDirectory + "\\" + excelSource, attrs, SourceDataType.Excel); excelDF.WriteData(initialDirectory, "excelTest"); jsonDF.WriteData(initialDirectory, "jsonTest"); // API demo List <string> apiAttrs = new List <string>(); apiAttrs.Add("id"); apiAttrs.Add("name"); apiAttrs.Add("picture_path"); DataFormat xmlDF = new XmlDataFormat(apiSource, apiAttrs, SourceDataType.API); xmlDF.WriteData(initialDirectory, "xmlTest"); // Bulk data actions demo List <DataFormat> dataFormats = new List <DataFormat>(); dataFormats.Add(xmlDF); dataFormats.Add(jsonDF); dataFormats.Add(excelDF); BulkActions.WriteDataFormatsToFile(dataFormats, initialDirectory, "bulktest"); // Generics Demo MultiDataFormat <DataFormat> jsonGeneric = new MultiDataFormat <DataFormat>(jsonSource, attrs, SourceDataType.JSON); MultiDataFormat <DataFormat> excelGeneric = new MultiDataFormat <DataFormat>(excelSource, attrs, SourceDataType.Excel); List <DataFormat> dfs = new List <DataFormat>(); List <MultiDataFormat <DataFormat> > genericDFs = new List <MultiDataFormat <DataFormat> >(); genericDFs.Add(jsonGeneric); genericDFs.Add(excelGeneric); DataFormat excelFromGeneric = BulkActions.FromMultipleSources(genericDFs, "excel"); excelFromGeneric.WriteData(initialDirectory, "GenericExcel"); // Database demo List <string> dbAttrs = new List <string>(); dbAttrs.Add("fname"); dbAttrs.Add("lname"); dbAttrs.Add("age"); string server = Environment.MachineName; string db = "LearningTest"; string user = "******"; string password = "******"; DatabaseDataFormat dbDF = new DatabaseDataFormat( server: server, catalog: db, username: user, password: password, dbSystem: "sqlserver", source: initialDirectory + "\\" + jsonForDB, KeepValues: dbAttrs, sourceDataType: SourceDataType.JSON ); dbDF.WriteData("", "People"); }