Example #1
0
        private void SaveScriptSourceCode()
        {
            IScriptingService scripting  = Services.GetService <IScriptingService>();
            TSqlFragment      syntaxTree = scripting.ParseScript(ScriptCode, out IList <ParseError> errors);

            if (errors.Count > 0)
            {
                ShowParseErrors(errors);
                throw new InvalidOperationException("Saving script failed: incorrect syntax.");
            }

            ScriptingController controller = Services.GetService <ScriptingController>();
            string catalogName             = controller.GetScriptsCatalogName(MyServer, MyDatabase, ScriptType);

            if (controller.ScriptFileExists(catalogName, Name))
            {
                controller.SaveScriptFile(catalogName, Name, ScriptCode);
            }
            else
            {
                if (controller.GetScriptTreeNodeByName(MyServer, MyDatabase, ScriptType, Name) != null)
                {
                    throw new InvalidOperationException($"Script node \"{Name}\" already exists!");
                }
                controller.SaveScriptFile(catalogName, Name, ScriptCode);
            }

            MainWindowViewModel mainWindow = Services.GetService <MainWindowViewModel>();
            TreeNodeViewModel   treeNode   = mainWindow.GetTreeNodeByPayload(mainWindow.MainTreeRegion.TreeNodes, this);

            if (treeNode == null)
            {
                controller.CreateScriptTreeNode(this);
            }
        }