private void UpdateFx(TelemetryFunction fx) { if (fx != null) { fx.Name = txtFxName.Text.Trim(); fx.Body = txtFxBody.Text.Trim(); } }
private TelemetryFunction NewFx() { var fx = new TelemetryFunction() { Name = "New Function" }; fx.State = fx.Serialize(); return(fx); }
private void DisplayFx(TelemetryFunction fx) { txtFxName.Text = fx.Name; txtFxBody.Text = fx.Body; btnSaveFunction.Enabled = true; btnCloseFunction.Enabled = true; btnTestFunction.Enabled = true; pnlFxDetails.Enabled = true; txtFxBody.Enabled = true; }
private void ClearFx() { txtFxName.Clear(); txtFxBody.Clear(); btnSaveFunction.Enabled = false; btnCloseFunction.Enabled = false; btnTestFunction.Enabled = false; btnAddField.Enabled = false; pnlFxDetails.Enabled = false; txtFxBody.Enabled = false; _currentFunction = null; }
private void SaveCustomFunctionFile(TelemetryFunction fx) { JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }; var json = JsonConvert.SerializeObject(fx, settings); var fieldListFile = Path.Combine(Constants.AppFolder, fx.FileName); if (File.Exists(fieldListFile)) { File.Delete(fieldListFile); } File.WriteAllText(fieldListFile, json); fx.State = fx.Serialize(); }
private TelemetryFunction LoadCustomFunctionFile(string fileName) { TelemetryFunction fx = null; if (File.Exists(fileName)) { var json = File.ReadAllText(fileName); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }; fx = JsonConvert.DeserializeObject <TelemetryFunction>(json, settings); fx.State = fx.Serialize(); } return(fx); }
private bool CloseFx(TelemetryFunction fx) { var result = PromptToSaveChangesToFx(fx); if (result == DialogResult.Cancel) { return(false); } else if (result == DialogResult.Yes) { SaveFx(fx); } ClearFx(); return(true); }
private DialogResult PromptToSaveChangesToFx(TelemetryFunction fx) { if (_currentFunction == null) { return(DialogResult.No); } UpdateFx(_currentFunction); if (!_currentFunction.HasChanges) { return(DialogResult.No); } else { return(MessageBox.Show(this, $"Save changes to {fx.Name}?", "Save Changes?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)); } }
private void btnOpenFunction_Click(object sender, EventArgs e) { try { if (!CloseFx(_currentFunction)) { // user cancelled return; } _currentFunction = OpenFx(); DisplayFx(_currentFunction); } catch (Exception ex) { ExceptionHandler(ex); } }
private TelemetryFunction OpenFx() { TelemetryFunction fx = null; var dialog = new OpenFileDialog() { InitialDirectory = Constants.FunctionsFolder, Filter = "Function Files (*.fx.json)|*.fx.json|All Files (*.*)|*.*", FilterIndex = 1 }; var result = dialog.ShowDialog(this); if (result == DialogResult.OK) { fx = LoadCustomFunctionFile(dialog.FileName); } return(fx); }
private void SaveFx(TelemetryFunction fx) { UpdateFx(fx); var dialog = new SaveFileDialog() { InitialDirectory = Constants.FunctionsFolder, Filter = "Function Files (*.fx.json)|*.fx.json|All Files (*.*)|*.*", FilterIndex = 1, FileName = String.IsNullOrEmpty(fx.FileName) ? fx.Name : Path.GetFileName(fx.FileName) }; var result = dialog.ShowDialog(this); if (result == DialogResult.OK) { fx.FileName = dialog.FileName; SaveCustomFunctionFile(fx); } }