Axaptapedia is now maintained by AgileCadence For more information please click here.
AOT Search Results Save/Load
So, this might not interest a lot of people... But, then again...
It takes me on average about 45 Minutes to do a full scan of the AOT when I'm looking at all levels. That's a lot of time when you're analysing a system and I don't like repeating the search, because it's the end of the day or someone wants to restart the AOS or some such.
So I came up with a way of saving and loading search results.
Here are the Methods for accomplishing this.
I'll leave setting up the Buttons on the Form SysAOTFind, getting the Filename and calling the Methods up to You!
Have fun and I hope that it helps you out!
<xpp> void SaveResults(Filename _file) {
FormListColumn formListColumn; FormListItem formListItem; AsciiIo asciiIo = new AsciiIo(_file, 'w'); int columns = resultListView.getColumnCount(); int rows = resultListView.getCount(); int i; int j; str text; str productName; str licenceHolder; str applicationDirectory; anytype data; int image, overlay, indent; boolean foundProperties; ;
productName = xInfo::productName() + ' ' + xInfo::releaseVersion() + ' Build #' + xInfo::buildNo() + '/' + ApplicationVersion::buildNo(); licenceHolder = xInfo::licenseName() ? xInfo::licenseName() : 'Internal'; applicationDirectory = xInfo::directory(DirectoryType::Appl);
asciiIo.inRecordDelimiter('\n');
asciiIo.write("***Element: System"); asciiIo.write(" "); asciiIo.write(strfmt(" ProductName: %1", productName)); asciiIo.write(strfmt(" LicenseHolder: %1", licenceHolder)); asciiIo.write(strfmt(" ApplicationDirectory: %1", applicationDirectory)); asciiIo.write(" "); asciiIo.write("***Element: Search Definition"); asciiIo.write(" "); asciiIo.write(strfmt(" Search: %1", search.selection())); asciiIo.write(strfmt(" Named: %1", Named.text())); asciiIo.write(strfmt(" ContainingText: %1", ContainingText.text())); asciiIo.write(strfmt(" LookInRange: %1", LookInRange.text())); asciiIo.write(strfmt(" ShowSource: %1", ShowSource.checked())); asciiIo.write(strfmt(" UseTreeSelection: %1", UseTreeSelection.checked())); asciiIo.write(strfmt(" DateRange: %1", DateRange.text())); asciiIo.write(strfmt(" ByRange: %1", ByRange.text())); asciiIo.write(strfmt(" IncludeEmpty: %1", IncludeEmpty.checked())); asciiIo.write(strfmt(" ApplObjectTypeRange: %1", ApplObjectTypeRange.text())); asciiIo.write(strfmt(" SizeRange: %1", SizeRange.text())); asciiIo.write(strfmt(" applObjectLayerRange: %1", applObjectLayerRange.text())); asciiIo.write(strfmt(" RunModeRange: %1", RunModeRange.text())); asciiIo.write(strfmt(" FilterMethod: %1", FilterMethod.text())); if (search.selection() == 0) { while select tmpPropertySelection index Selected where tmpPropertySelection.Selected == true || tmpPropertySelection.Criteria != { if (!foundProperties) { asciiIo.write(" Properties: "); foundProperties = true; } asciiIo.write(strfmt(" Property: %1", tmpPropertySelection.Property)); asciiIo.write(strfmt(" Selected: %1", tmpPropertySelection.Selected)); asciiIo.write(strfmt(" Criteria: %1", tmpPropertySelection.Criteria)); } if (foundProperties) asciiIo.write(" EndProperties:"); }
asciiIo.write(" "); asciiIo.write("***Element: Result Count"); asciiIo.write(" "); asciiIo.write(strfmt(" Count: %1", counterHits));
asciiIo.write(" "); asciiIo.write("***Element: Result Definition"); asciiIo.write(" ");
for (i = 0; i <= columns; i++) { formListColumn = resultListView.getColumn(i); if (formListColumn) { asciiIo.write(strfmt(" Column: %1", i)); asciiIo.write(strfmt(" Text: %1", formListColumn.text())); asciiIo.write(strfmt(" Width: %1", formListColumn.width())); asciiIo.write(strfmt(" Format: %1", formListColumn.format())); asciiIo.write(" EndColumn:"); } }
asciiIo.write(" "); asciiIo.write("***Element: Results"); asciiIo.write(" ");
for (i = 0; i < rows; i++) { asciiIo.write(strfmt(" Row: %1", i)); for (j = 0; j < columns; j++) { if (j) formListItem = resultListView.getItem(i, j); else { formListItem = resultListView.getItem(i); data = formListItem.data(); } if (formListItem) { text = formListItem.text(); image = formListItem.image(); overlay = formListItem.overlayImage(); indent = formListItem.indent(); asciiIo.write(strfmt(" Column: %1", j)); asciiIo.write(strfmt(" Text: %1", text)); asciiIo.write(strfmt(" Image: %1", image)); asciiIo.write(strfmt(" Overlay: %1", overlay)); asciiIo.write(strfmt(" Indent: %1", indent)); if (!j) { asciiIo.write(strfmt(" Data: %1", data)); } asciiIo.write(" EndColumn:"); } } asciiIo.write(" EndRow:"); }
} </xpp> <xpp> void LoadResults(Filename _file) {
#AviFiles #File #define.expEndRecord('***' + 'Element') #define.recordDelimit(' Row:') #define.delimiterCRLF('\r\n')
SysOperationProgress progress; int total; int counter = 0; int tcBegin, tcNow;
AsciiIo asciiIo = new AsciiIo(_file, #io_read); container record; str line; str elementName; boolean isFirstRecord = true; boolean foundSystem; boolean foundSearchDefinition; boolean foundResultDefinition; boolean foundResultCount;
str strRemoveCr(str s) { return strReplace(s, '\n', ' '); } ;
startLengthyOperation(); element.lock();
resultListView.deleteAll();
asciiIo.inFieldDelimiter(#delimiterCRLF); asciiIo.inRecordDelimiter('\n' + #expEndRecord);
try { while (asciiIo.status() == IO_Status::Ok) { record = asciiIo.read();
if (asciiIo.status() == IO_Status::Ok) { line = strLTrim(conpeek(record, 1)); if (!line) continue; elementName = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line)))); switch (elementName) { case 'System' : foundSystem = true; if (!element.CheckIsSystemOkay(record)) throw error("This is not the same Axapta System as defined in the Import File!"); break; case 'Search Definition' : if (!foundSystem) throw error("Import File corrupt! No System Section."); foundSearchDefinition = true; element.LoadSearchDefinition(record); break; case 'Result Definition' : if (!foundSystem) throw error("Import File corrupt! No System Section."); if (!foundSearchDefinition) throw error("Import File corrupt! No Search Definition Section."); foundResultDefinition = true; element.LoadResultDefinition(record); break; case 'Result Count' : total = str2int(strKeep(conpeek(record, 3), '0123456789')); foundResultCount = true; break; } } if (foundSystem && foundSearchDefinition && foundResultDefinition) break; } if (foundSystem && foundSearchDefinition && foundResultDefinition) { tcBegin = WinAPI::getTickCount(); progress = new SysOperationProgress(); progress.setCaption("Loading"); if (foundResultCount && total) { progress.setAnimation(#AviUpdate); progress.setTotal(total); } else { progress.setAnimation(#AviStopwatch); } asciiIo = new AsciiIo(_file, #io_read); asciiIo.inFieldDelimiter(#delimiterCRLF); asciiIo.inRecordDelimiter('\n' + #recordDelimit); while (asciiIo.status() == IO_Status::Ok) { record = asciiIo.read(); if (isFirstRecord) { isFirstRecord = false; continue; }
counter++; tcNow = WinAPI::getTickCount(); if (foundResultCount && total) { progress.setText(strfmt("Record... %1 of %2 in %3 Minutes", counter, total, ((tcNow - tcBegin) / 60000))); } else { progress.setText(strfmt("Records... %1 in %2 Minutes", counter, ((tcNow - tcBegin) / 60000))); } progress.setCount(counter);
line = conPeek(record, 1); line = ' Row:' + line; record = conPoke(record, 1, line); element.LoadResultItems(record); } if (counter > 0) hitsText.text(strFmt("@SYS26824", counter)); } } catch { element.unLock(); endLengthyOperation(); throw error("@SYS79625"); }
element.resetSize(); element.unLock(); endLengthyOperation();
} </xpp> <xpp> boolean CheckIsSystemOkay(container _data) {
str line; str token, value; str productName; str licenseHolder; str applicationDirectory; int i; int lines = conlen(_data); boolean foundProdName; boolean foundLicHolder; boolean foundAppDir; boolean ok = true; boolean ret; ;
productName = xInfo::productName() + ' ' + xInfo::releaseVersion() + ' Build #' + xInfo::buildNo() + '/' + ApplicationVersion::buildNo(); licenseHolder = xInfo::licenseName() ? xInfo::licenseName() : 'Internal'; applicationDirectory = xInfo::directory(DirectoryType::Appl);
for (i = 2; i <= lines; i++) { line = strLTrim(conpeek(_data, i)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line))));
switch (token) { case 'ProductName' : foundProdName = true; ok = ok && (value == productName); break; case 'LicenseHolder' : foundLicHolder = true; ok = ok && (value == licenseHolder); break; case 'ApplicationDirectory' : foundAppDir = true; ok = ok && (value == applicationDirectory); break; } } if (foundProdName && foundLicHolder && foundAppDir) ret = ok;
return ret;
} </xpp> <xpp> void LoadSearchDefinition(container _data) {
FormControl formControl; Object formControlObject; TmpPropertySelection propertySelection; str line; str token, value; int i; int j; int lines = conlen(_data); str propVal, critVal; int selVal;
str propVal() { return propVal; }
void selectionChange() { if (search.selection() == 0) // Nodes { includeEmpty.enabled(false); propertySelection.setTmpData(tmpPropertySelection); select firstonly propertySelection; if (!propertySelection) { element.fillPropertyTable(); } tabPagePropertySelection.visible(true); } else { includeEmpty.enabled(true); tabPagePropertySelection.visible(false); } }
void LoadProperties() { int k; int m = j; ;
for (k = i + 1; k < m; k += 3) { line = strLTrim(conpeek(_data, k)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line)))); if (token) { propVal = value; } line = strLTrim(conpeek(_data, k + 1)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line)))); if (token) { selVal = ((value == 'true' || value == 'ja') ? 1 : 0); } line = strLTrim(conpeek(_data, k + 2)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line)))); if (token) { critVal = value; } while select tmpPropertySelection where tmpPropertySelection.Property == propVal() { tmpPropertySelection.Selected = selVal; tmpPropertySelection.Criteria = critVal; tmpPropertySelection.update(); } } } ;
for (i = 2; i <= lines; i++) { line = strLTrim(conpeek(_data, i)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line))));
if (token) { formControl = element.design().controlName(token); if (formControl || token == 'Properties') { formControlObject = formControl; switch (token) { case 'Search' : formControlObject.selection(str2int(value)); selectionChange(); break; case 'Named' : formControlObject.text(value); break; case 'ContainingText' : formControlObject.text(value); break; case 'LookInRange' : formControlObject.text(value); break; case 'ShowSource' : formControlObject.checked((value == 'true' ? true : false)); break; case 'UseTreeSelection' : formControlObject.checked((value == 'true' ? true : false)); break; case 'DateRange' : formControlObject.text(value); break; case 'ByRange' : formControlObject.text(value); break; case 'IncludeEmpty' : formControlObject.checked((value == 'true' ? true : false)); break; case 'ApplObjectTypeRange' : formControlObject.text(value); break; case 'SizeRange' : formControlObject.text(value); break; case 'applObjectLayerRange' : formControlObject.text(value); break; case 'RunModeRange' : formControlObject.text(value); break; case 'FilterMethod' : formControlObject.text(value); break; case 'Properties' : j = conFind(_data, ' EndProperties:'); if (j && j > i) { LoadProperties(); tmpPropertySelection_ds.executeQuery(); i = j; } break; } } } }
} </xpp> <xpp> void LoadResultDefinition(container _data) {
FormListColumn formListColumn; FormListFormat format; str line; str token, value; int i; int j; int lines = conlen(_data); str textVal, formatVal; int widthVal;
int conFindStartAt(container _con, int _startAt, str _searchText) { int k = _startAt; int length = conlen(_con); boolean found; ;
while (k <= length) { if (conPeek(_con, k) == _searchText) { found = true; break; } k++; } if (!found) k = 0; return k; }
void loadColumn(int _col) { int k; int m = j; ;
for (k = i + 1; k < m; k += 3) { line = strLTrim(conpeek(_data, k)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line)))); if (token) { textVal = value; } line = strLTrim(conpeek(_data, k + 1)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line)))); if (token) { widthVal = str2int(value); } line = strLTrim(conpeek(_data, k + 2)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line)))); if (token) { switch (value) { case 'Center' : format = FormListFormat::Center; break; case 'Right' : format = FormListFormat::Right; break; default : format = FormListFormat::Left; break; } } formListColumn = new FormListColumn(textVal, _col, widthVal); resultListView.addColumn(_col, formListColumn); } }
void deleteAllColumns() { int columns = resultListView.getColumnCount(); int k; ; for (k = columns; k > 0; k--) { resultListView.deleteColumn(k); } } ;
resultListView.visible(false);
deleteAllColumns();
for (i = 2; i <= lines; i++) { line = strLTrim(conpeek(_data, i)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line))));
if (token && token == 'Column') { j = conFindStartAt(_data, i + 1, ' EndColumn:'); if (j && j > i) { loadColumn(str2int(value)); i = j; } } }
resultListView.visible(true);
} </xpp> <xpp> void LoadResultItems(container _data) {
FormListItem formListItem; str line; str token, value; str crlf = '\r\n'; int i, j, r, t, u, v; int headerIdx; int subItem; int lines = conlen(_data); container row; container column;
str strRemoveCr(str s) { return strReplace(s, '\n', ' '); }
int conFindStartAt(container _con, int _startAt, str _searchText) { int k = _startAt; int length = conlen(_con); str comp; str searchText = strRem(strLRTrim(_searchText), crlf); boolean found; ;
while (k <= length) { comp = strRem(strLRTrim(conPeek(_con, k)), crlf); if (strcmp(comp, searchText) == 0) { found = true; break; } k++; } if (!found) k = 0; return k; }
void loadColumn(int _row, int _col, boolean _first) { int k; int m; int _lines = conlen(column); boolean _indent; ;
formListItem = new FormListItem();
for (k = 2; k < _lines; k++) { line = strLTrim(conpeek(column, k)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line))));
switch (token) { case 'Text' : formListItem.text(value); break; case 'Image' : if (str2int(value)) { formListItem.image(str2int(value)); if (str2int(value) == 6) _indent = true; } break; case 'Overlay' : if (str2int(value)) formListItem.overlayImage(str2int(value)); break; case 'Indent' : if (str2int(value)) formListItem.indent(str2int(value)); else if (_indent) formListItem.indent(1); break; case 'Data' : formListItem.data(value); break; } } if (_first) { formListItem.idx(idx+1); idx = resultListView.addItem(formListItem); headerIdx = idx; subItem = 0; } else { formListItem.idx(headerIdx); subItem++; formListItem.subItem(subItem); resultListView.setItem(formListItem); } }
void loadRow(int _row) { int k, m; int _lines = conlen(row); ;
for (k = 2; k < _lines; k++) { line = strLTrim(conpeek(row, k)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line))));
if (token && token == 'Column') { m = conFindStartAt(row, k + 1, ' EndColumn:'); if (m && m > k) { v = 1; for (u = k; u <= m; u++) { column = conPoke(column, v, conPeek(row, u)); v++; } loadColumn(_row, str2int(value), str2int(value) == 0); k = m; } } } } ;
idx = 0;
for (i = 1; i <= lines; i++) { line = strLTrim(conpeek(_data, i)); token = strLRTrim(substr(line, 1, strscan(line, ': ', 1, maxint()) - 1)); value = strLRTrim(strRemoveCr(substr(line, strscan(line, ': ', 1, maxint()) + 2, strlen(line))));
if (token && token == 'Row') { j = conFindStartAt(_data, i + 1, ' EndRow:'); if (j && j > i) { t = 1; for (r = i; r <= j; r++) { row = conPoke(row, t, conPeek(_data, r)); t++; } idx = str2int(value); loadRow(idx); i = j; } } }
} </xpp>