Esempio n. 1
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());
                    }
                }
            }
        }
Esempio n. 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();
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        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());
            }
        }
Esempio n. 5
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");
            }
        }