示例#1
0
        internal static void OpenInclude()
        {
            Thread gothread = new Thread((ThreadStart) delegate {
                string LineNum    = NppFunctions.GetLine(NppFunctions.GetLineNumber());
                OpenMember Member = Include.HandleInclude(LineNum);

                if (Member != null)
                {
                    string FileLoc = "";

                    FileLoc = IBMiUtilities.DownloadMember(Member.GetLibrary(), Member.GetObject(), Member.GetMember());

                    if (FileLoc != "")
                    {
                        NppFunctions.OpenFile(FileLoc, true);
                    }
                    else
                    {
                        MessageBox.Show("Unable to download member " + Member.GetLibrary() + "/" + Member.GetObject() + "." + Member.GetMember() + ". Please check it exists and that you have access to the remote system.");
                    }
                }
                else
                {
                    MessageBox.Show("Unable to parse out member.");
                }
            });

            gothread.Start();
        }
示例#2
0
文件: IBMi.cs 项目: mlanglet/IBMiCmd
        private static void RunFTP(string FileLoc)
        {
            IBMiUtilities.DebugLog("Starting FTP of command file " + FileLoc);

            _notConnected = false;
            Process process = new Process();

            process.StartInfo.FileName               = "cmd.exe";
            process.StartInfo.Arguments              = "/c FTP -n -s:\"" + FileLoc + "\" " + _config["system"];
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;

            process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
            process.ErrorDataReceived  += new DataReceivedEventHandler(OutputHandler);

            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();

#if DEBUG
            foreach (string retMsg in _output)
            {
                IBMiUtilities.DebugLog(retMsg);
            }
#endif

            IBMiUtilities.DebugLog("FTP of command file " + FileLoc + " completed");
        }
示例#3
0
        /// <summary>
        /// Loads the files in the plugin folder /plugins/config/IBMiCmd/cache/
        /// and parses and adds the content into the data structure list
        /// </summary>
        internal static void LoadFileCache()
        {
            XmlSerializer xf = new XmlSerializer(typeof(DataStructure));

            dataStructures = new List <DataStructure>();
            foreach (string file in Directory.GetFiles(Main.FileCacheDirectory))
            {
                if (!file.EndsWith(".ffd"))
                {
                    continue;
                }

                using (Stream stream = File.Open(file, FileMode.Open))
                {
                    try
                    {
                        dataStructures.Add((DataStructure)xf.Deserialize(stream));
                    }
                    catch (Exception e)
                    {
                        IBMiUtilities.Log($"{file} could not be loaded..");
                        IBMiUtilities.Log(e.ToString());
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Installs the remote objects that the plugin requires on the server
        /// </summary>
        internal static void InstallRemoteLib(string library = "QGPL")
        {
            Thread thread = new Thread((ThreadStart) delegate {
                IBMiUtilities.DebugLog($"InstallRemoteLib -> {library}!");
                try
                {
                    List <string> sourceFiles = GenerateRemoteSource();

                    IBMi.RunCommands(IBMiCommandRender.RenderRemoteInstallScript(sourceFiles, library));

                    // Cleanup temp files
                    foreach (string file in sourceFiles)
                    {
                        File.Delete(file);
                    }

                    IBMi.SetConfig("installlib", library);
                } catch (Exception e) {
                    IBMiUtilities.Log(e.ToString()); // TODO: Show error?
                }
                IBMiUtilities.DebugLog("InstallRemoteLib - DONE!");
            });

            thread.Start();
        }
示例#5
0
        /// <summary>
        /// TODO: ?
        /// </summary>
        internal static void RebuildRelic()
        {
            Thread gothread = new Thread((ThreadStart) delegate {
                IBMiUtilities.DebugLog("RebuildRelic!");
                string tmpFile = Path.GetTempFileName();
                IBMi.AddOutput("Starting build of '" + IBMi.GetConfig("relicdir") + "' into " + IBMi.GetConfig("reliclib"));
                if (Main.CommandWindow != null)
                {
                    Main.CommandWindow.loadNewCommands();
                }
                IBMi.RunCommands(IBMiCommandRender.RenderRelicRebuildScript(tmpFile));
                IBMi.AddOutput("");
                foreach (string line in File.ReadAllLines(tmpFile))
                {
                    IBMi.AddOutput($"> { line }");
                }
                IBMi.AddOutput("");
                IBMi.AddOutput("End of build.");
                File.Delete(tmpFile);
                if (Main.CommandWindow != null)
                {
                    Main.CommandWindow.loadNewCommands();
                }
                IBMiUtilities.DebugLog("RebuildRelic - DONE!");
            });

            gothread.Start();
        }
示例#6
0
        internal static void InstallLocalDefinitions()
        {
            IBMiUtilities.DebugLog("InstallLocalDefinitions starting...");
            string        functionList = $"%APPDATA%/Roaming/Notepad++/functionList.xml";
            List <string> outputBuffer = new List <string>();
            StringBuilder sb           = new StringBuilder();

            bool associationFound = false;
            bool parserFound      = false;

            IBMiUtilities.DebugLog("InstallLocalDefinitions parsing functionList...");
            foreach (string line in File.ReadAllLines(functionList))
            {
                if (!associationFound)
                {
                    if (line.Contains("<association ext=\".sqlrpgle\""))
                    {
                        associationFound = true;
                    }
                }
                if (line.Contains("</associationMap>") && !associationFound)
                {
                    IBMiUtilities.DebugLog("InstallLocalDefinitions writing association to functionList...");
                    outputBuffer.Add("<association ext=\".sqlrpgle\" userDefinedLangName=\"sqlrpgle\" id=\"sqlrpgle\"/>");
                }

                if (!parserFound)
                {
                    if (line.Contains("<parser id=\"sqlrpgle\""))
                    {
                        parserFound = true;
                    }
                }
                if (line.Contains("</parser>") && !parserFound)
                {
                    IBMiUtilities.DebugLog("InstallLocalDefinitions writing parser to functionList...");
                    outputBuffer.Add("\t\t\t<parser id=\"sqlrpgle\" displayName=\"SQLRPGLE\">");
                    outputBuffer.Add("\t\t\t\t<function");
                    outputBuffer.Add("\t\t\t\t\tmainExpr=\"(\bdcl - proc\\s)(\\w +)\"");
                    outputBuffer.Add("\t\t\t\t\tdisplayMode=\"$functionName\">");
                    outputBuffer.Add("\t\t\t\t\t<functionName>");
                    outputBuffer.Add("\t\t\t\t\t\t<nameExpr expr=\"(?<= dcl - proc).*\"/>");
                    outputBuffer.Add("\t\t\t\t\t</functionName>");
                    outputBuffer.Add("\t\t\t\t</function>");
                    outputBuffer.Add("\t\t\t</parser>");
                }
                outputBuffer.Add(line);
            }
            IBMiUtilities.DebugLog("InstallLocalDefinitions parsing functionList comeplted!");
            File.WriteAllLines(functionList, outputBuffer);
            IBMi.SetConfig("localDefintionsInstalled", "true");
            IBMiUtilities.DebugLog("InstallLocalDefinitions completed!");
        }
示例#7
0
        /// <summary>
        /// Returns a list of SourceLine structs that contains names of externally described files
        /// in the searchResult field of the data structure
        /// </summary>
        /// <returns>SourceLine(s) from current file containing EXTNAME</returns>
        private static List <SourceLine> ParseCurrentFileForExtName()
        {
            const int         MINIMUM_LINE_LENGTH_FOR_EXTNAME = 12;
            const short       END_OF_FILE  = 0;
            int               line         = 0;
            List <SourceLine> lines        = new List <SourceLine>();
            IntPtr            curScintilla = PluginBase.GetCurrentScintilla();

            while (true)
            {
                int lineLength = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_LINELENGTH, ++line, 0);
                if (lineLength == END_OF_FILE)
                {
                    break;
                }
                else if (lineLength < MINIMUM_LINE_LENGTH_FOR_EXTNAME)
                {
                    continue;
                }

                StringBuilder sb = new StringBuilder(lineLength);
                Win32.SendMessage(curScintilla, SciMsg.SCI_GETLINE, line, sb);

                if (sb == null)
                {
                    break;
                }

                string sourceStatement = sb.ToString().ToUpper();

                if (sourceStatement.Contains("EXTNAME("))
                {
                    SourceLine result = new SourceLine()
                    {
                        statement    = sourceStatement,
                        searchResult = IBMiUtilities.ExtractString(sourceStatement, "EXTNAME('", "')"),
                        lineNumber   = line
                    };
                    if (sourceStatement.Contains("ALIAS"))
                    {
                        result.alias = true;
                    }
                    else
                    {
                        result.alias = false;
                    }

                    lines.Add(result);
                }
            }
            return(lines);
        }
示例#8
0
        internal static string[] RenderFFDCollectionScript(List <SourceLine> src, string[] tmp)
        {
            IBMiUtilities.DebugLog("RenderFFDCollectionScript");
            string[] cmd = new string[(src.Count * 3) + 2];
            int      i = 0, t = 0;

            // Run commands on remote
            cmd[i++] = "ASCII";
            cmd[i++] = $"QUOTE RCMD CHGLIBL LIBL({ IBMi.GetConfig("datalibl").Replace(',', ' ')})  CURLIB({ IBMi.GetConfig("curlib") })";
            foreach (SourceLine sl in src)
            {
                cmd[i++] = $"QUOTE RCMD {IBMi.GetConfig("installlib")}/NPPDSPFFD {sl.searchResult}";
                cmd[i++] = $"RECV /home/{ IBMi.GetConfig("username") }/{ sl.searchResult }.tmp \"{ tmp[t++] }\"";
                cmd[i++] = $"QUOTE RCMD RMVLNK OBJLNK('/home/{ IBMi.GetConfig("username") }/{ sl.searchResult }.tmp')";
            }

            IBMiUtilities.DebugLog("RenderFFDCollectionScript - DONE!");
            return(cmd);
        }
示例#9
0
        /// <summary>
        /// Executes remote commands on the configured server to collect data on externally
        /// referenced tables that is then put into both memory and the file cache
        /// </summary>
        internal static void LaunchFFDCollection()
        {
            Thread thread = new Thread((ThreadStart) delegate
            {
                List <SourceLine> src = ParseCurrentFileForExtName();
                if (src.Count == 0)
                {
                    return;
                }
                // Generate temporary files to receive data
                string[] tmp = new string[src.Count];
                for (int i = 0; i < src.Count; i++)
                {
                    tmp[i] = Path.GetTempFileName();
                }

                // Receive record formats via remote command IICDSPFFD
                IBMi.RunCommands(IBMiCommandRender.RenderFFDCollectionScript(src, tmp)); // Get all record formats to local temp files

                // Load Context & Cleanup temp files
                for (int i = 0; i < src.Count; i++)
                {
                    try
                    {
                        RPGParser.LoadFFD(tmp[i], src[i]);
                    }
                    catch (Exception e)
                    {
                        IBMiUtilities.Log(e.ToString()); // TODO: Show error?
                    }
                    finally
                    {
                        File.Delete(tmp[i]);
                    }
                }
            });

            thread.Start();
        }
示例#10
0
文件: IBMi.cs 项目: mlanglet/IBMiCmd
        public static void RunCommands(string[] list)
        {
            try
            {
                FlushOutput();
                string tempfile = Path.GetTempFileName();
                File.Move(tempfile, tempfile + ".ftp");
                tempfile += ".ftp";
                List <string> lines = new List <string>();

                lines.Add("user " + _config["username"]);
                lines.Add(_config["password"]);
                lines.Add("bin");
                foreach (string cmd in list)
                {
                    if (cmd == null)
                    {
                        continue;
                    }
                    if (cmd.Trim() != "")
                    {
                        IBMiUtilities.DebugLog("Collecting command for ftp file: " + cmd);
                        lines.Add(cmd);
                    }
                }
#if DEBUG
                lines.Add("QUOTE RCMD DSPJOBLOG");
#endif
                lines.Add("quit");

                File.WriteAllLines(tempfile, lines.ToArray());
                RunFTP(tempfile);
                File.Delete(tempfile);
            }
            catch (Exception e) {
                IBMiUtilities.Log(e.ToString());
            }
        }
示例#11
0
文件: Main.cs 项目: mlanglet/IBMiCmd
        internal static void CommandMenuInit()
        {
            StringBuilder pluginsConfigDir = new StringBuilder(Win32.MAX_PATH);

            Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETPLUGINSCONFIGDIR, Win32.MAX_PATH, pluginsConfigDir);
            ConfigDirectory    = $"{ pluginsConfigDir.ToString() }\\{ PluginName }\\";
            FileCacheDirectory = $"{ConfigDirectory}cache\\";

            if (!Directory.Exists(ConfigDirectory))
            {
                Directory.CreateDirectory(ConfigDirectory);
            }
            if (!Directory.Exists(FileCacheDirectory))
            {
                Directory.CreateDirectory(FileCacheDirectory);
            }

            IBMiUtilities.CreateLog(ConfigDirectory + PluginName);
            RPGParser.LoadFileCache();

            IBMi.LoadConfig(ConfigDirectory + PluginName);
            //if (IBMi.GetConfig("localDefintionsInstalled") == "false")
            //{
            //    IBMiNPPInstaller.InstallLocalDefinitions();
            //}

            PluginBase.SetCommand(0, "About IBMiCmd", About, new ShortcutKey(false, false, false, Keys.None));
            PluginBase.SetCommand(1, "IBM i Remote System Setup", RemoteSetup);
            PluginBase.SetCommand(2, "IBM i Command Entry", CommandDialog);
            PluginBase.SetCommand(3, "IBM i Error Listing", ErrorDialog);
            PluginBase.SetCommand(4, "IBM i Command Bindings", BindsDialog);
            PluginBase.SetCommand(5, "IBM i RPG Conversion", LaunchConversion, new ShortcutKey(true, false, false, Keys.F4));
            PluginBase.SetCommand(6, "IBM i Relic Build", LaunchRBLD, new ShortcutKey(true, false, false, Keys.F5));
            PluginBase.SetCommand(7, "IBM i Refresh Definitions", BuildSourceContext, new ShortcutKey(true, false, false, Keys.F6));
            PluginBase.SetCommand(8, "IBM i Auto Complete", AutoComplete, new ShortcutKey(false, true, false, Keys.Space));
            PluginBase.SetCommand(9, "IBM i Library List", LiblDialog, new ShortcutKey(true, false, false, Keys.F7));
            PluginBase.SetCommand(10, "IBM i Remote Install Plugin Server", RemoteInstall);
        }
示例#12
0
        internal static void CommandMenuInit()
        {
            StringBuilder pluginsConfigDir = new StringBuilder(Win32.MAX_PATH);

            Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETPLUGINSCONFIGDIR, Win32.MAX_PATH, pluginsConfigDir);
            ConfigDirectory    = $"{ pluginsConfigDir.ToString() }\\{ PluginName }\\";
            SystemsDirectory   = $"{ConfigDirectory}systems\\";
            FileCacheDirectory = $"{ConfigDirectory}cache\\";

            if (!Directory.Exists(ConfigDirectory))
            {
                Directory.CreateDirectory(ConfigDirectory);
            }
            if (!Directory.Exists(SystemsDirectory))
            {
                Directory.CreateDirectory(SystemsDirectory);
            }
            if (!Directory.Exists(FileCacheDirectory))
            {
                Directory.CreateDirectory(FileCacheDirectory);
            }

            IBMiUtilities.CreateLog(ConfigDirectory + PluginName);
            RPGParser.LoadFileCache();
            CLParser.LoadFileCache();

            if (File.Exists(ConfigDirectory + "dftcfg"))
            {
                Config.SwitchToConfig(File.ReadAllText(ConfigDirectory + "dftcfg"));
            }
            else
            {
                LoadConfigSelect();
                if (Config.GetConfigs().Length == 0)
                {
                    return;
                }
                if (IBMi._ConfigFile == "" || IBMi._ConfigFile == null)
                {
                    string UseConfig = Config.GetConfigs()[0];
                    MessageBox.Show("No config selected. Defaulted to " + UseConfig + ".");
                    Config.SwitchToConfig(UseConfig);
                }
            }
            //if (IBMi.GetConfig("localDefintionsInstalled") == "false")
            //{
            //    IBMiNPPInstaller.InstallLocalDefinitions();
            //}

            bool ExperimentalFeatures = (IBMi.GetConfig("experimental") == "true");
            int  ItemOrder            = 0;

            PluginBase.SetCommand(ItemOrder++, "About IBMiCmd", About, new ShortcutKey(false, false, false, Keys.None));
            PluginBase.SetCommand(ItemOrder++, "-SEPARATOR-", null);
            PluginBase.SetCommand(ItemOrder++, "Select Remote System", LoadConfigSelect);
            PluginBase.SetCommand(ItemOrder++, "Remote System Setup", RemoteSetup);
            PluginBase.SetCommand(ItemOrder++, "Library List", LiblDialog, new ShortcutKey(true, false, false, Keys.F7));
            if (ExperimentalFeatures)
            {
                PluginBase.SetCommand(ItemOrder++, "Remote Install Plugin Server", RemoteInstall);
            }
            PluginBase.SetCommand(ItemOrder++, "-SEPARATOR-", null);
            PluginBase.SetCommand(ItemOrder++, "Command Entry", CommandDialog);
            PluginBase.SetCommand(ItemOrder++, "Error Listing", ErrorDialog);
            PluginBase.SetCommand(ItemOrder++, "Command Bindings", BindsDialog);
            PluginBase.SetCommand(ItemOrder++, "-SEPARATOR-", null);
            PluginBase.SetCommand(ItemOrder++, "Member Listing", MemberListing);
            PluginBase.SetCommand(ItemOrder++, "Open Source Member", OpenMember, new ShortcutKey(true, false, true, Keys.A));
            //PluginBase.SetCommand(ItemOrder++, "Upload Source Member", UploadMember, new ShortcutKey(true, false, true, Keys.X));
            PluginBase.SetCommand(ItemOrder++, "Open Include/Copy", OpenInclude, new ShortcutKey(true, false, false, Keys.F12));
            PluginBase.SetCommand(ItemOrder++, "-SEPARATOR-", null);
            PluginBase.SetCommand(ItemOrder++, "Format CL file", ManageCL, new ShortcutKey(true, false, false, Keys.F4));
            PluginBase.SetCommand(ItemOrder++, "RPG Line Conversion", LaunchConversion, new ShortcutKey(true, false, false, Keys.F5));
            PluginBase.SetCommand(ItemOrder++, "RPG File Conversion", LaunchFileConversion, new ShortcutKey(true, false, false, Keys.F6));
            PluginBase.SetCommand(ItemOrder++, "-SEPARATOR-", null);
            PluginBase.SetCommand(ItemOrder++, "Display File Editor", DisplayEdit);
            if (ExperimentalFeatures)
            {
                PluginBase.SetCommand(ItemOrder++, "Refresh Extname Definitions", BuildSourceContext);
            }
            if (ExperimentalFeatures)
            {
                PluginBase.SetCommand(ItemOrder++, "Extname Content Assist", AutoComplete, new ShortcutKey(false, true, false, Keys.Space));
            }
            if (ExperimentalFeatures)
            {
                PluginBase.SetCommand(ItemOrder++, "Prompt CL Command", PromptCommand, new ShortcutKey(true, false, false, Keys.F4));
            }
        }
示例#13
0
        private static string FFDParseColumnType(string l, SourceLine srcLine)
        {
            int length = 0, ccsid = 37;

            string type = l.Substring(DSPFFD_FIELD_TYPE, DSPFFD_FIELD_TYPE_LEN);

            try
            {
                length = int.Parse(l.Substring(DSPFFD_FIELD_BYTE_SIZE, DSPFFD_FIELD_BYTE_SIZE_LEN).Replace('0', ' '));
                //ccsid = int.Parse(l.Substring(DSPFFD_FIELD_CCSID, DSPFFD_FIELD_CCSID_LEN)); TODO, how to extract packed numerics
            }
            catch (Exception e)
            {
                IBMiUtilities.Log($"Tried to parse {l.Substring(DSPFFD_FIELD_BYTE_SIZE, DSPFFD_FIELD_BYTE_SIZE_LEN)} and {l.Substring(DSPFFD_FIELD_CCSID, DSPFFD_FIELD_CCSID_LEN)} to integer. {e.ToString()}");
            }

            switch (type)
            {
            case "B":
                switch (length)
                {
                case 1:
                    return("int(3)");

                case 2:
                    return("int(5)");

                case 4:
                    return("int(10)");

                case 8:
                    return("int(20)");

                default:
                    return("binary");
                }

            case "A":
                return("char");

            case "S":
                return("zoned");

            case "P":
                return("packed");

            case "F":
                return("float");

            case "O":
                return("unknown");

            case "J":
                return("unknown");

            case "E":
                return("unknown");

            case "H":
                return("rowid");

            case "L":
                return("date");

            case "T":
                return("time");

            case "Z":
                return("timestamp");

            case "G":
                return("graphic");

            case "1":
                switch (ccsid)
                {
                case 65535:
                    return("blob");

                default:
                    return("clob");
                }

            case "2":
                return("unknown");

            case "3":
                return("dbclob");

            case "4":
                return("datalink");

            case "5":
                return("binary");

            case "6":
                return("dbclob");

            case "7":
                return("xml");

            default:
                return("unknown");
            }
        }
示例#14
0
 internal static void OpenLogFile()
 {
     NppFunctions.OpenFile(IBMiUtilities.GetLogPath(), true);
 }