public ScriptResultControl(SqlEditor parent)
 {
     this.Editor = parent;
     tabControl  = this;
 }
Exemple #2
0
        public void edit(Command cmd, Side theSide)
        {
            if (cmd.HasHelp)
            {
                stdio.WriteLine("edit, view and execute sql script");
                stdio.WriteLine("edit                          : create new file and edit");
                stdio.WriteLine("edit [file]                   : edit file, it is read-only if file is hyperlink");
                stdio.WriteLine("options:");
                stdio.WriteLine("   /usr                       : FTP user name");
                stdio.WriteLine("   /pwd                       : FTP password");
                stdio.WriteLine("examples:");
                stdio.WriteLine("  edit c:\\db\\northwind.sql");
                stdio.WriteLine("  edit file://datconn/northwind.sql");
                stdio.WriteLine("  edit http://www.datconn.com/demos/northwind.sql");
                stdio.WriteLine("  edit ftp://www.datconn.com/demos/northwind.sql /usr:user /pwd:password");
                return;
            }

            FileLink fileLink = null;
            if (cmd.arg1 != null)
            {
                string inputfile = cmd.arg1;

                if (inputfile.IndexOf("://") < 0)
                {
                    if (Path.GetDirectoryName(inputfile) == string.Empty)
                    {
                        string path = cmd.Configuration.GetValue<string>("MyDocuments", Directory.GetCurrentDirectory());
                        inputfile = $"{path}\\{inputfile}";
                    }
                }

                fileLink = FileLink.CreateLink(inputfile, cmd.GetValue("usr"), cmd.GetValue("pwd"));

                try
                {
                    if (!fileLink.Exists)
                    {
                        if (!fileLink.IsLocalLink)
                        {
                            stdio.ErrorFormat("file {0} doesn't exist", fileLink);
                            return;
                        }
                        else
                        {
                            File.WriteAllText(inputfile, string.Empty);
                            fileLink = FileLink.CreateLink(inputfile);
                        }
                    }
                }
                catch (Exception ex)
                {
                    stdio.Error(ex.Message);
                    return;
                }

            }

            try
            {
                var editor = new Windows.SqlEditor(cmd.Configuration, theSide.Provider, fileLink);
                editor.ShowDialog();
            }
            catch (Exception ex)
            {
                stdio.Error(ex.Message);
                return;
            }
        }