I am looking for a solution which helps to import a text file in the code, I am doing this to remove the hard coded values which do the mapping . Instead, I would want to call a text file and read values, which does the mapping. Making the code independent of projects. Any Idea how to do it ? I want to remove the mechanism of hard coding and substitute it with reading values from a text file.
I have read a thread which helps in reading a file, but i am completely new to DXL and do not know what that question tries to explain. struggleisreal - Mon Apr 10 09:26:00 EDT 2017 |
Re: Importing/Reading text file in DXL script? The code you posted is the part, where you want to remove the hardcoded values? You need to perform the following steps: 1. Read a file line by line (see DXL manual "Files and Streams" in the example of the end(Stream) function 2. Split the String using a separator -> There are multiple split implementations on the forum use the search 3. Build a Skip list containing the mapped values 4 Use the skip list inside your OLE code in a loop. Regards, Mathias
|
Re: Importing/Reading text file in DXL script? Mathias Mamsch - Mon Apr 10 16:11:25 EDT 2017 The code you posted is the part, where you want to remove the hardcoded values? You need to perform the following steps: 1. Read a file line by line (see DXL manual "Files and Streams" in the example of the end(Stream) function 2. Split the String using a separator -> There are multiple split implementations on the forum use the search 3. Build a Skip list containing the mapped values 4 Use the skip list inside your OLE code in a loop. Regards, Mathias
Thank you for your answer :)
OleAutoObj createWrapperObj(Object obj) {
OleAutoArgs args = create
OleAutoObj wrapper = null
print oleMethod(d2e, "CreateObjectWrapper", args, wrapper)
string myFileName = get fieldFilePath
Stream input = null
Buffer oneLine = create
string attributes[] = {"A", "B", "C"}
int index = 1
int iLine = 0
if (canOpenFile(myFileName, false))
{
// print "open file: \"" myFileName "\" was successul \n"
// Valid filename
input = read(myFileName)
olePut(wrapper, attributes[0], name(m))
index = 1
while (!end input)
{
// Read file line by line
input >= oneLine
// print "\n" (++iLine) ": " (tempStringOf oneLine)
string attributeName = tempStringOf(oneLine)
if (exists(attribute(attributeName)))
{
string value = obj.attributeName
//print "attribute name: " attributeName ", Value: " value "\n"
string attrList = attributes[index]
olePut(wrapper, attrList, (value))
index++
}
else
{
string attrList = attributes[index]
olePut(wrapper, attrList, (""))
index++
}
}
if (index > 5)
{
break
}
}
// Read file line by line
close input
}
// Valid filename
else
{
string buttons[] = {"OK"}
messageBox("Unable to read file", buttons, msgError)
}
delete oneLine
return wrapper
}
Now I have another problem, I have nothing static in my code now (i.e string attributes[] is null ). My problem now is to map dynamically. Example: My Current text file looks like this:
Previous Text file looked like this:
I want to modify the current script such that ID is mapped to RequirementID (ID is the attribute from some other tool, RequirementID is the attribute name from DOORS) Is there any simple method I can do this with ? Regards, StruggleisReal :) |
Re: Importing/Reading text file in DXL script? struggleisreal - Mon Apr 24 05:58:02 EDT 2017
Thank you for your answer :)
OleAutoObj createWrapperObj(Object obj) {
OleAutoArgs args = create
OleAutoObj wrapper = null
print oleMethod(d2e, "CreateObjectWrapper", args, wrapper)
string myFileName = get fieldFilePath
Stream input = null
Buffer oneLine = create
string attributes[] = {"A", "B", "C"}
int index = 1
int iLine = 0
if (canOpenFile(myFileName, false))
{
// print "open file: \"" myFileName "\" was successul \n"
// Valid filename
input = read(myFileName)
olePut(wrapper, attributes[0], name(m))
index = 1
while (!end input)
{
// Read file line by line
input >= oneLine
// print "\n" (++iLine) ": " (tempStringOf oneLine)
string attributeName = tempStringOf(oneLine)
if (exists(attribute(attributeName)))
{
string value = obj.attributeName
//print "attribute name: " attributeName ", Value: " value "\n"
string attrList = attributes[index]
olePut(wrapper, attrList, (value))
index++
}
else
{
string attrList = attributes[index]
olePut(wrapper, attrList, (""))
index++
}
}
if (index > 5)
{
break
}
}
// Read file line by line
close input
}
// Valid filename
else
{
string buttons[] = {"OK"}
messageBox("Unable to read file", buttons, msgError)
}
delete oneLine
return wrapper
}
Now I have another problem, I have nothing static in my code now (i.e string attributes[] is null ). My problem now is to map dynamically. Example: My Current text file looks like this:
Previous Text file looked like this:
I want to modify the current script such that ID is mapped to RequirementID (ID is the attribute from some other tool, RequirementID is the attribute name from DOORS) Is there any simple method I can do this with ? Regards, StruggleisReal :) As I said, find yourself a "split" function implementation (on the forum). Put in your textfile stuff like this: ID->Requirement ID Attr->My Attr Read the file, line by line, split the line by the separator to get both values. Regards, Mathias |