예제 #1
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");
        }
예제 #2
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();
        }
예제 #3
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();
        }
예제 #4
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!");
        }
예제 #5
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);
        }
예제 #6
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());
            }
        }