public void extractStringTest() { string testResult = null; string testInput = null; // Null testResult = IBMiUtilities.ExtractString(testInput, null, "^"); Assert.IsTrue(testResult == ""); testInput = ""; // Empty testResult = IBMiUtilities.ExtractString(testInput, "123", "^"); Assert.IsTrue(testResult == ""); testInput = "dcl-ds "; // search arg too big testResult = IBMiUtilities.ExtractString(testInput, "too long search", " like"); Assert.IsTrue(testResult == ""); testInput = "dcl-ds myDS likeDS(T_TABLE);"; // Extract part blanks testResult = IBMiUtilities.ExtractString(testInput, "dcl-ds ", " like"); Assert.IsTrue(testResult == "myDS"); testInput = "dcl-ds myDS EXTNAME('MYTABLE') qualified alias"; // Extract part testResult = IBMiUtilities.ExtractString(testInput, "EXTNAME('", "')"); Assert.IsTrue(testResult == "MYTABLE"); testInput = "dcl-ds myDS EXTNAME('MYTABLE') qualified alias"; // Extract no limit testResult = IBMiUtilities.ExtractString(testInput, "EXTNAME('"); Assert.IsTrue(testResult == "MYTABLE') qualified alias"); testInput = " <column type=\"int(10)\" length=\"4\">AMEOFLONGFIELDTWO</column>"; // Extract no limit testResult = IBMiUtilities.ExtractString(testInput, "type=\"", "\""); Assert.IsTrue(testResult == "int(10)"); }
public void isValidQSYSObjectNameTest() { string testInput = null; // null Assert.IsFalse(IBMiUtilities.IsValidQSYSObjectName(testInput)); testInput = ""; // empty Assert.IsFalse(IBMiUtilities.IsValidQSYSObjectName(testInput)); testInput = "1asd"; // begins with # Assert.IsFalse(IBMiUtilities.IsValidQSYSObjectName(testInput)); testInput = "abcdefghjklmno"; // too long Assert.IsFalse(IBMiUtilities.IsValidQSYSObjectName(testInput)); testInput = "a"; // Valid Assert.IsTrue(IBMiUtilities.IsValidQSYSObjectName(testInput)); testInput = "abc123"; // Valid Assert.IsTrue(IBMiUtilities.IsValidQSYSObjectName(testInput)); testInput = "abc_123"; // Valid Assert.IsTrue(IBMiUtilities.IsValidQSYSObjectName(testInput)); testInput = "abc_123_zz"; // Valid Assert.IsTrue(IBMiUtilities.IsValidQSYSObjectName(testInput)); }
private void OpenMember(string Lib, string Obj, string Mbr, Boolean Editing) { Thread gothread = new Thread((ThreadStart) delegate { string resultFile = IBMiUtilities.DownloadMember(Lib, Obj, Mbr); if (Main.CommandWindow != null) { Main.CommandWindow.loadNewOutput(); } if (resultFile != "") { NppFunctions.OpenFile(resultFile, !Editing); if (Editing) { OpenMembers.AddMember(IBMi.GetConfig("system"), resultFile, Lib, Obj, Mbr); } } else { MessageBox.Show("Unable to download member " + Lib + "/" + Obj + "." + Mbr + ". Please check it exists and that you have access to the remote system."); } }); gothread.Start(); }
public static void HandleTrigger(SCNotification Notification) { Thread gothread; string path = GetCurrentFileName(); OpenMember member; switch (Notification.nmhdr.code) { case (uint)NppMsg.NPPN_READY: break; case (uint)SciMsg.SCN_MODIFIED: break; case (uint)NppMsg.NPPN_FILEBEFOREOPEN: break; case (uint)NppMsg.NPPN_FILEOPENED: break; case (uint)NppMsg.NPPN_FILESAVED: member = OpenMembers.GetMember(path); if (member != null) { gothread = new Thread((ThreadStart) delegate { if (member.IsEditable()) { if (member.GetSystemName() == IBMi.GetConfig("system")) { bool UploadResult = IBMiUtilities.UploadMember(member.GetLocalFile(), member.GetLibrary(), member.GetObject(), member.GetMember()); if (UploadResult == false) { System.Windows.Forms.MessageBox.Show("Failed to upload to " + member.GetMember() + " on " + member.GetSystemName() + "."); } } else { System.Windows.Forms.MessageBox.Show("Unable to upload to " + member.GetMember() + ". You must be connected to " + member.GetSystemName() + " in order to save this file."); } if (Main.CommandWindow != null) { Main.CommandWindow.loadNewOutput(); } } }); gothread.Start(); } break; case (uint)NppMsg.NPPN_FILEBEFORECLOSE: if (OpenMembers.Contains(path)) { OpenMembers.RemoveMember(path); File.Delete(path); } break; } }
private void button2_Click(object sender, EventArgs e) { label2.Text = ""; label2.Update(); //Add a default library if (listBox1.Items.Count == 0) { listBox1.Items.Add("SYSTOOLS"); } string s = ""; foreach (string item in listBox1.Items) { if (IBMiUtilities.IsValidQSYSObjectName(item.Trim())) { s += item.Trim() + ','; } else { label2.Text = "Invalid library: " + item.Trim(); label2.Update(); return; } } if (!IBMiUtilities.IsValidQSYSObjectName(textBox2.Text.Trim())) { label2.Text = "Invalid current library."; label2.Update(); return; } string origLibl = IBMi.GetConfig("datalibl"); string origCur = IBMi.GetConfig("curlib"); IBMi.SetConfig("datalibl", s.Remove(s.Length - 1, 1)); //Remove last comma IBMi.SetConfig("curlib", textBox2.Text.Trim()); //Remove last comma Boolean hasFailed = IBMi.RunCommands(new string[0]); if (hasFailed) { IBMi.SetConfig("datalibl", origLibl); IBMi.SetConfig("curlib", origCur); MessageBox.Show("Library list contains invalid libraries.", "Library list", MessageBoxButtons.OK, MessageBoxIcon.Error); if (Main.CommandWindow != null) { Main.CommandWindow.loadNewOutput(); } } else { this.Close(); } }
private static OpenMember HandleRPG(string Copy) { if (Copy.StartsWith("/COPY") || Copy.StartsWith("/INCLUDE")) { string lib, obj, mbr; string[] data = Copy.Split(' '); string[] pieces; if (data.Length != 2) { return(null); } data[1] = data[1].Trim(); pieces = data[1].Split(','); if (pieces.Length == 2) { mbr = pieces[1]; obj = pieces[0]; pieces = pieces[0].Split('/'); if (pieces.Length == 2) { obj = pieces[1]; lib = pieces[0]; } else { lib = "*CURLIB"; } } else { mbr = data[1]; obj = "QRPGLESRC"; lib = "*CURLIB"; } if (lib == "*CURLIB") { lib = IBMi.GetConfig("curlib"); } if (IBMiUtilities.IsValidQSYSObjectName(lib) && IBMiUtilities.IsValidQSYSObjectName(obj) && IBMiUtilities.IsValidQSYSObjectName(mbr)) { return(new OpenMember("", "", lib, obj, mbr)); } else { return(null); } } else { return(null); } }
internal static void FetchCommandDefinition(string command) { // Receive command description via IICRTVCMD IBMi.RunCommands(IBMiCommandRender.RenderCommandDescriptionCollection(command)); try { CLParser.LoadCMD(command); } catch (Exception e) { IBMiUtilities.Log(e.ToString()); // TODO: Show error? } }
private void toolStripButton1_Click(object sender, EventArgs e) { if (!IBMiUtilities.IsValidQSYSObjectName(toolStripTextBox1.Text)) { MessageBox.Show("Library name is not valid."); return; } if (!IBMiUtilities.IsValidQSYSObjectName(toolStripTextBox2.Text)) { MessageBox.Show("Object name is not valid."); return; } UpdateListing(toolStripTextBox1.Text, toolStripTextBox2.Text); }
private void button2_Click(object sender, EventArgs e) { string installLibrary = ""; if (IBMiUtilities.IsValidQSYSObjectName(textBox1.Text.Trim())) { installLibrary += textBox1.Text.Trim(); } else { label1.Text += " - Invalid Library Specified"; label1.Update(); return; } IBMiNPPInstaller.InstallRemoteLib(installLibrary); this.Close(); }
private void button1_Click(object sender, EventArgs e) { this.isReadonly = checkBox1.Checked; textBox1.Text = textBox1.Text.ToUpper(); textBox2.Text = textBox2.Text.ToUpper(); textBox3.Text = textBox3.Text.ToUpper(); if (!IBMiUtilities.IsValidQSYSObjectName(textBox1.Text)) { MessageBox.Show("Library name is not valid."); return; } if (!IBMiUtilities.IsValidQSYSObjectName(textBox2.Text)) { MessageBox.Show("Object name is not valid."); return; } if (!IBMiUtilities.IsValidQSYSObjectName(textBox3.Text)) { MessageBox.Show("Member name is not valid."); return; } string resultFile = IBMiUtilities.DownloadMember(textBox1.Text, textBox2.Text, textBox3.Text); if (Main.CommandWindow != null) { Main.CommandWindow.loadNewOutput(); } if (resultFile != "") { //Open File NppFunctions.OpenFile(resultFile, this.isReadonly); OpenMembers.AddMember(textBox4.Text, resultFile, textBox1.Text, textBox2.Text, textBox3.Text, !this.isReadonly); this.Close(); } else { MessageBox.Show("Unable to download member " + textBox1.Text + "/" + textBox2.Text + "." + textBox3.Text + ". Please check it exists and that you have access to the remote system."); } }
public void UpdateListing(string Lib, string Obj) { Thread gothread = new Thread((ThreadStart) delegate { string[] members; ListViewItem curItem; curItems.Clear(); listView1.Items.Clear(); listView1.Items.Add(new ListViewItem("Loading...", 2)); members = IBMiUtilities.GetMemberList(Lib, Obj); listView1.Items.Clear(); if (members != null) { foreach (string member in members) { curItem = new ListViewItem(Path.GetFileNameWithoutExtension(member), 0); curItem.Tag = Lib + '|' + Obj; curItems.Add(curItem); } listView1.Items.AddRange(curItems.ToArray()); toolStripLabel2.Text = members.Length.ToString() + " member" + (members.Length == 1 ? "" : "s"); } else { listView1.Items.Add(new ListViewItem("No members found!", 1)); if (Main.CommandWindow != null) { Main.CommandWindow.loadNewOutput(); } toolStripLabel2.Text = "0 members"; } }); gothread.Start(); }
private void button1_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Please note that saving to the member will overwrite any changes that you have not picked up since you last opened the member.", "Notice", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (result == DialogResult.OK) { bool UploadResult = IBMiUtilities.UploadMember(this._Member.GetLocalFile(), this._Member.GetLibrary(), this._Member.GetObject(), this._Member.GetMember()); if (UploadResult) { this.Close(); } else { if (Main.CommandWindow != null) { Main.CommandWindow.loadNewOutput(); } MessageBox.Show("Failed to save " + this._Member.GetMember() + ". Please check the Command Entry output."); } } }
private void button2_Click(object sender, EventArgs e) { label2.Text = ""; label2.Update(); string s = ""; foreach (string item in textBox1.Text.Trim().Split(',')) { if (IBMiUtilities.IsValidQSYSObjectName(item.Trim())) { s += item.Trim() + ','; } else { label2.Text = "Invalid Library List Syntax. Valid syntax is < LIB,LIB,LIB >"; label2.Update(); return; } } if (IBMiUtilities.IsValidQSYSObjectName(textBox2.Text.Trim())) { IBMi.SetConfig("curlib", textBox2.Text.Trim()); //Remove last comma } else { label2.Text = "Invalid Current Library Syntax. Valid syntax is < LIB >"; label2.Update(); return; } IBMi.SetConfig("datalibl", s.Remove(s.Length - 1, 1)); //Remove last comma this.Close(); }
public static string GetCommandAtColumn(string curLine, int curPos) { if (curPos > curLine.Length) { return(""); } StringBuilder sb = new StringBuilder(); // Scan Backwards for (int i = curPos; i >= 0; i--) { if (i == curPos && curLine[i] == ' ') { return(""); } else { if (curLine[i] == ' ' || curLine[i] == '\'') { break; } else { sb.Append(curLine[i]); } } } // Scan Forward for (int i = curPos + 1; i < curLine.Length; i++) { if (i == curPos && curLine[i] == ' ') { break; } else { if (curLine[i] == ' ' || curLine[i] == '\'') { break; } else { sb.Insert(0, curLine[i]); } } } char[] buffer = sb.ToString().ToCharArray(); Array.Reverse(buffer); string command = new string(buffer); if (IBMiUtilities.IsValidQSYSObjectName(command)) { return(command); } else { return(""); } }