public void EditFunction(Guid id, Action <FunctionMetadata> saveAction, bool modal = true, string displayName = null, Window owner = null)
        {
            //Try to get the function service.
            var functionService = _serviceContext.Services
                                  .OfType <IFunctionService>()
                                  .FirstOrDefault();

            if (functionService == null)
            {
                throw new InvalidOperationException("No function service has been registered.");
            }

            var existing = _functionEditorManager.Get(id);

            if (existing == null)
            {
                //Get the metadata.
                var metadata = functionService.GetFunction(id);

                //Create the function view model
                var function = CreateRuntimeFunctionInner(metadata);

                //Create the editor view model
                var editorViewModel = new FunctionEditorDialogViewModel(_serviceContext, function, saveAction,
                                                                        new TextEditService(), displayName, _functionEditorManager);

                //Create the view
                var view = new FunctionEditorDialog(_serviceContext.CustomResources)
                {
                    DataContext = editorViewModel,
                    Owner       = owner
                };

                //Show the dialog
                if (modal)
                {
                    view.ShowDialog();
                }
                else
                {
                    view.Owner = owner;
                    view.Show();
                }
            }
            else
            {
                //Activate this one
                existing.Activate();
            }
        }
        public void EditFunction(FunctionMetadata metadata, Action <FunctionMetadata> saveAction, bool modal, string displayName)
        {
            var existing = _functionEditorManager.Get(metadata.Id);

            if (existing == null)
            {
                //Create the function view model
                var function = CreateRuntimeFunctionInner(metadata);

                //Create the editor view model
                var editorViewModel = new FunctionEditorDialogViewModel(_serviceContext, function, saveAction,
                                                                        new TextEditService(), displayName, _functionEditorManager);

                //Create the view
                var view = new FunctionEditorDialog(_serviceContext.CustomResources)
                {
                    DataContext = editorViewModel,
                };

                //Show the dialog
                if (modal)
                {
                    view.Owner = WindowUtil.GetActiveWindow();
                    view.ShowDialog();
                }
                else
                {
                    view.Show();
                }
            }
            else
            {
                //Activate this one
                existing.Activate();
            }
        }