예제 #1
0
 private void UpdateFx(TelemetryFunction fx)
 {
     if (fx != null)
     {
         fx.Name = txtFxName.Text.Trim();
         fx.Body = txtFxBody.Text.Trim();
     }
 }
예제 #2
0
        private TelemetryFunction NewFx()
        {
            var fx = new TelemetryFunction()
            {
                Name = "New Function"
            };

            fx.State = fx.Serialize();
            return(fx);
        }
예제 #3
0
        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;
        }
예제 #4
0
        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;
        }
예제 #5
0
        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();
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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));
            }
        }
예제 #9
0
        private void btnOpenFunction_Click(object sender, EventArgs e)
        {
            try
            {
                if (!CloseFx(_currentFunction))
                {
                    // user cancelled
                    return;
                }

                _currentFunction = OpenFx();

                DisplayFx(_currentFunction);
            }
            catch (Exception ex)
            {
                ExceptionHandler(ex);
            }
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
            }
        }