private void SaveDashBoardAs() { string filename = DashBoardFileName_; if (filename == null) { filename = $"dashboard_template_{DateTime.Now.ToString("dd.MM.yyyy_HH.mm.ss")}.dash"; } DashboardConfigBundle configBundle = GetDashBoardConfigBundle(); string jsonText = JsonConvert.SerializeObject(configBundle, Formatting.Indented); SaveFileDialog savefileDialog = new SaveFileDialog { // set a default file name FileName = filename, // set filters - this can be done in properties as well Filter = "dash Files (*.dash)|*.dash|All files (*.*)|*.*" }; if (savefileDialog.ShowDialog() == true) { File.WriteAllText(savefileDialog.FileName, jsonText); dc.AddItemsToConsole("Saved the updated template file!!!"); if (savefileDialog.FileName != null) { DashBoardFileName_ = savefileDialog.FileName; } } }
private DashboardConfigBundle GetDashBoardConfigBundle() { DashboardConfigBundle configBundle = new DashboardConfigBundle() { DashboardConfig_ = DashboardConfig_, DashboardCellConfigs_ = GetDashboardCellConfigs() }; return(configBundle); }
public void OpenFileName(string str) { if (str != null) { DashboardConfigBundle configBundle = JsonConvert.DeserializeObject <DashboardConfigBundle>(File.ReadAllText(str)); //dc.AddItemsToConsole(JsonConvert.SerializeObject(configBundle, Formatting.Indented)); DashboardConfig_ = configBundle.DashboardConfig_; List <IDashboardCellConfig> dashboardCellConfigs = configBundle.DashboardCellConfigs_; ClearDashboardCells(); AddDashBoardCells(dashboardCellConfigs); dc.AddItemsToConsole($"Dashboard \"{DashboardConfig_.DashboardName_}\" loaded"); } }
private void Save_Click(object sender, RoutedEventArgs e) { // get the filename if (MessageBox.Show("Save this Dashboard?", "Save", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { string filename = DashBoardFileName_; if (filename != null) { DashboardConfigBundle configBundle = GetDashBoardConfigBundle(); JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }; string jsonText = JsonConvert.SerializeObject(configBundle, Formatting.Indented, jsonSerializerSettings); File.WriteAllText(filename, jsonText); dc.AddItemsToConsole("Saved the updated Dashboard!!!"); } else { // open save as window SaveDashBoardAs(); } } }