/// <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!");

                if (Main.CommandWindow != null)
                {
                    Main.CommandWindow.loadNewOutput();
                }
            });

            thread.Start();
        }
Example #2
0
        private static Boolean RunFTP(string FileLoc)
        {
            IBMiUtilities.DebugLog("Starting FTP of command file " + FileLoc);

            _list.Clear();
            _NotConnected = false;
            _Failed       = 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");
            return(_Failed || _NotConnected);
        }
Example #3
0
        private static void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
        {
            if (outLine.Data != null)
            {
                IBMiUtilities.Log(outLine.Data);
                if (outLine.Data.Length >= 5)
                {
                    if (outLine.Data.Trim() == "Not connected.")
                    {
                        if (!_NotConnected)
                        {
                            _output.Add("Not connected to " + _config["system"]);
                        }
                        _NotConnected = true;
                    }
                    else
                    {
                        switch (outLine.Data.Substring(0, 3))
                        {
                        case "125":
                            _getList = true;
                            break;

                        case "250":
                            _getList = false;
                            _output.Add("> " + outLine.Data.Substring(4));
                            break;

                        case "150":
                            _output.Add("> " + outLine.Data.Substring(4));
                            break;

                        case "426":
                        case "530":
                        case "550":
                            _Failed = outLine.Data.Substring(0, 3);
                            _output.Add("> " + outLine.Data.Substring(4));
                            break;

                        default:
                            if (_getList)
                            {
                                _list.Add(outLine.Data);
                            }
                            break;
                        }
                        if (GetConfig("experimental") == "true")
                        {
                            _output.Add("* " + outLine.Data);
                        }
                    }
                }
            }
        }
        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!");
        }
Example #5
0
        internal static string[] RenderRemoteInstallScript(List <string> sourceFiles, string library)
        {
            List <string> cmd = new List <string>
            {
                "ASCII",
                "QUOTE RCMD CRTPF FILE(QTEMP/IICCLSRC) RCDLEN(112) FILETYPE(*SRC) MAXMBRS(*NOMAX) TEXT('Deploy IBMiCmd plugin')",
                "QUOTE RCMD CRTPF FILE(QTEMP/IICCMDSRC) RCDLEN(112) FILETYPE(*SRC) MAXMBRS(*NOMAX) TEXT('Deploy IBMiCmd plugin')",
                "QUOTE RCMD CRTPF FILE(QTEMP/IICRPGSRC) RCDLEN(240) FILETYPE(*SRC) MAXMBRS(*NOMAX) TEXT('Deploy IBMiCmd plugin')"
            };

            foreach (string file in sourceFiles)
            {
                IBMiUtilities.DebugLog($"RenderRemoteInstallScript processsing {file}");
                string fileName = file.Substring(file.LastIndexOf("\\") + 1);
                string member = fileName.Substring(fileName.LastIndexOf("-") + 1, fileName.LastIndexOf(".") - (fileName.LastIndexOf("-") + 1));
                string sourceFile = null, crtCmd = null;

                switch (fileName.Substring(fileName.Length - 4))
                {
                case ".CLP":
                    sourceFile = "IICCLSRC";
                    crtCmd     = getCompileCommandCL(library, member);
                    break;

                case ".CMD":
                    sourceFile = "IICCMDSRC";
                    crtCmd     = getCompileCommandCmd(library, member);
                    break;

                case ".RPG":
                    sourceFile = "IICRPGSRC";
                    crtCmd     = getCompileCommandRpg(library, member);
                    break;

                default:
                    sourceFile = "IICRPGSRC";
                    break;
                }

                cmd.Add($"SEND \"{ file }\" /home/{ IBMi.GetConfig("username") }/{ fileName }");
                cmd.Add($"QUOTE RCMD CPYFRMSTMF FROMSTMF('/home/{ IBMi.GetConfig("username") }/{ fileName }') TOMBR('/QSYS.LIB/QTEMP.LIB/{ sourceFile }.FILE/{ member }.MBR')");
                cmd.Add($"QUOTE RCMD RMVLNK OBJLNK('/home/{ IBMi.GetConfig("username") }/{ fileName }')");
                if (crtCmd != null)
                {
                    cmd.Add($"QUOTE RCMD { crtCmd }");
                }
            }
            return(cmd.ToArray());
        }
Example #6
0
        internal static string[] RenderCommandDescriptionCollection(string command)
        {
            IBMiUtilities.DebugLog("RenderCommandDescriptionCollection");
            string[] cmd = new string[5];
            // Run commands on remote
            int i = 0;

            cmd[i++] = "ASCII";
            cmd[i++] = $"QUOTE RCMD CHGLIBL LIBL({ IBMi.GetConfig("datalibl").Replace(',', ' ')}) CURLIB({ IBMi.GetConfig("curlib") })";
            cmd[i++] = $"QUOTE RCMD { IBMi.GetConfig("installlib") }/IICRTVCMD {command}";
            cmd[i++] = $"RECV /home/{ IBMi.GetConfig("username") }/{ command }.cdml \"{ Main.FileCacheDirectory }{ command }.cdml\"";
            cmd[i]   = $"QUOTE RCMD RMVLNK OBJLNK('/home/{ IBMi.GetConfig("username") }/{ command }.cdml')";

            IBMiUtilities.DebugLog("RenderCommandDescriptionCollection - DONE!");
            return(cmd);
        }
Example #7
0
        public static Boolean RunCommands(string[] list)
        {
            Boolean result = true;

            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");

                lines.Add($"QUOTE RCMD CHGLIBL LIBL({ IBMi.GetConfig("datalibl").Replace(',', ' ')})  CURLIB({ IBMi.GetConfig("curlib") })");
                foreach (string cmd in list)
                {
                    if (cmd == null)
                    {
                        continue;
                    }
                    if (cmd.Trim() != "")
                    {
                        AddOutput("> " + cmd);
                        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());
                result = RunFTP(tempfile);
                File.Delete(tempfile);
            }
            catch (Exception e)
            {
                IBMiUtilities.Log(e.ToString());
                MessageBox.Show(e.ToString());
            }

            return(result);
        }
Example #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") }/IICDSPFFD { 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);
        }
Example #9
0
        private static Boolean RunFTP(string FileLoc)
        {
            IBMiUtilities.DebugLog("Starting FTP of command file " + FileLoc);

            _list.Clear();
            _NotConnected = false;
            _Failed       = "";

            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();

            IBMiUtilities.DebugLog("FTP of command file " + FileLoc + " completed");

            if (_NotConnected)
            {
                MessageBox.Show("Not able to connect to " + GetConfig("system"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (_Failed != "")
            {
                if (FTPCodeMessages.ContainsKey(_Failed))
                {
                    MessageBox.Show(FTPCodeMessages[_Failed], "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }

            return(_Failed != "" || _NotConnected);
        }