示例#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);
            }
        }