Can I return the tag and routine name? - intersystems-cache

I am working on a code "maintenance" idea where I would like to populate a global when routines are accessed and by who. I can pull the current routine name using $t(+0) or $ZNAME, but what about the current tag and/or line offset? Is there a way so I can put a standard line in the routines I want to track?

Rob, you can get these information from $STACK.
If you call your own tracking function, you get the calling stack info like this:
W $STACK($STACK(-1)-1,"PLACE")
zExecute+2^%Studio.General.1 +1
Take a look at the Caché ObjectScript Reference for $STACK for detailed description and examples.

Rob!
Maybe you just turn on Audit? It gathers logs for different users activities in InterSystems Caché database. See the documentation on Caché Audit.
Also, see this solution which will help you to examine analytics in DeepSee regarding Audit entries.

You can find the routine that's calling your label, by the following ClassMethod.
write ##class(%SYSTEM.Process).CallingRoutine()
As well as the database which is calling your label.
write ##class(%SYSTEM.Process).CallingDatabase()

Related

How can I create a services in Capella and call it in my M2DOC Word document?

How can I create a services in Capella and call it in my M2DOC Word document?
I want, for example, create a services for print a functional tree, and use this code in many different documents without re-write every time the code.
Thank you a lot.
Stefania
It seems this section of the documentation explains what you want to do: https://www.m2doc.org/ref-doc/nightly/index.html#providing-new-services

Sparx Enterprise Architect DocumentGenerator does not honour TaggedValues on Stereotype or values from SetProjectConstants and ReplaceField

maybe someone can help me on this. I am trying to generate a document via the DocumentGenerator interface. All in all this works well, except that the DocumentGenerator does not replace the Report Constants with actual values (which are defined on the report package stereotype.
This is the general flow of the document creation code (which generally works):
var gen = Repository.CreateDocumentGenerator();
gen.SetProjectConstant("ReportName", "My Project");
gen.NewDocument(string.Empty);
gen.ReplaceField("ReportName", "My Project");
gen.InsertCoverPageDocument(tags[REPORT_COVERPAGE]);
gen.InsertBreak(DocumentBreak.breakPage);
gen.InsertTOCDocument(tags[REPORT_TOC]);
gen.InsertBreak(DocumentBreak.breakPage);
gen.DocumentPackage((int)nativeId, 0, template);
gen.SaveDocument(fileName, DocumentType.dtDOCX);
I tried ReplaceField and SetProjectConstant both and one at a time before and after calls to NewDocument/InsertCoverPageDocument:
Strangely there is one constant that is being replaced: ReportSummary.
When I run the document generator via "F8" all constants are being replaced correctly.
Other project constants are being replaced correctly.
I can reproduce the behaviour on EA v14.1.1429 and v12.0.1215.
Does someone have a hint for further troubleshooting? Thanks in advance!
========== UPDATE ==========
When I use ReplaceField at the end (before the actual call to SaveDocument the following Report Constants get replaced: {ReportTitle} and {ReportName}
I discovered some workaround: when I manually remove the predefined {Report~} constants from the template and re-add them as Project Constants, their values get replaced correctly.
I will examine this further and give an update as
I did some further investigation on this and came to the following conclusion and workaround (as I have received no comments or answers on this):
I deleted all references to ReportConstants in my EA templates and replaced them by ProjectConstants with the same name.
In my code where I want to generate the documentation I (re)set all ProjectConstants with the actual values via SetProjectConstant and additionally added a call to ReplaceField to replace the constants with the actual values.
The previous mentioned calls are inserted directly before the call to SaveDocument document.
tags.ForEach(t =>
{
if (string.IsNullOrWhiteSpace(t.Key)) return;
generator.SetProjectConstant(t.Key, t.Value);
generator.ReplaceField(t.Key, t.Value);
});
generator.SaveDocument(fileName, DocumentType.dtDOCX);
If someone comes up with a better resonse or explanation for the behaviour I am happy to accept this as answer.
I have also found that when you call ReplaceField on these project constants in a CoverPage template, the formatting defined in the template is overwritten. It seems that some of the SetProjectConstant calls actually set the values as you would expect, and the rest do not.. hence the need to call both sets of APIs.

Why doesn't elapsed_time() work from log_message() even if called from post_system hook?

If I try to log benchmark->elapsed_time() in post_system hook, it just logs {elapsed_time} as if I called it from a controller.
CodeIgniter documentation says:
"post_system Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser."
It also says you are supposed to echo the elapsed_time() in a view to show it to the user, but... how is it possible that elapsed_time() is still being calculated after sending the finalized data to the browser?
I feel being lied to.
People keep saying I should use my own marks and get the difference, but that's not the same as using this...
Turns out the documentation also says:
"If the first parameter is empty this function instead returns the {elapsed_time} pseudo-variable. This permits the full system execution time to be shown in a template. The output class will swap the real value for this variable."
I went to the Output class and found the 2 marks it is using: total_execution_time_start and total_execution_time_end and I can use those in the post_system hook.

Get Status of Driver Inside Visual Basic

I'm currently trying to detect which drivers appear as "not working" in visual basic.
This unknown device is a good example of what I'm trying to grab (notice how it has the flag DN_HAS_PROBLEM).
I've tried using searches such as:
Dim searcher As New ManagementObjectSearcher( "root\CIMV2", "SELECT * FROM Win32_SystemDriver")
And running a loop in the searcher.Get() through this documentation
However, none of these seem to return what I am looking for.
Would anyone happen to know how I can get the DN_ statuses within Visual Basic?
Thanks!
The Win32_SystemDriver class documentation lists these Status properties:
OK
Error
Degraded
Unknown
Pred Fail
Starting
Stopping
Service
Stressed
NonRecover
No Contact
Lost Comm
...whereas DN_HAS_PROBLEM comes from the CM_Get_DevNode_Status function, or perhaps also from other system calls.
There may not be a way to get that specific code from the API you're using, but perhaps the existing Status properties will suffice for your needs if you don't need to know more specific failure reasons.
If you do need to know that specific status, you'll have to call other APIs, like the one I called out.

Custom Search Results in REST MarkLogic

So new to MarkLogic am stuck and not finding the documentation of use. I know what i need to do, just do not know how to do it.
I have a keyvalue? search on my REST server which returns ML's standard search results and XML snippet. I want to create my own custom search result which will output a title element for my XML files.
I am aware that i need to create an XSLT transformation document and upload that to the server but do not know how to target ML's search function or how to write this out.
I have basic knowledge of XSLT, if i just created something that targets each files title using xPath will this work, or does ML require use of their custom functions?
I know its a bit broad, but hopefully someone can point steer me.
Sounds like you are talking about the GET /v1/keyvalue endpoint of MarkLogic REST API. Unfortunately that does not allow you to choose a transform. You can probably use GET /v1/search with a transform param instead though, using a structured query for an element value query. The docs contain a good syntax reference on that.
Docs on creating and managing transforms can be found here:
http://docs.marklogic.com/guide/rest-dev/transforms#chapter
HTH!
You can use extract-metadata in your search options with search:search or the /v1/search/ REST API endpoint to include the title element in a metadata element or JSON property in your results:
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
search:search(
"my query string",
<options xmlns="http://marklogic.com/appservices/search">
<extract-metadata>
<qname elem-ns="" elem-name="title"/>
</extract-metadata>
</options>)
If you need more flexibility, you specify a custom snippet implementation or a results decorator function in your search options.
Is this key-value or full text? For key-value you could use XPath. Any XPath that starts with / or // or fn:collection() or fn:doc() will search the entire database. You can search specific document(s) or collection(s) too.
For full text you'd probably want to use https://docs.marklogic.com/search:search - or possibly https://docs.marklogic.com/cts:search for really low-level control.
There's some example code using search:search from XSL at https://github.com/marklogic/RunDMC which might help. It doesn't use the REST API: it's a traditional form-submit web page. But the view/search.xsl code might give you some idea how to call the search API from XSLT.
That RunDMC code might also help you if you need to call XSL from XQuery: take a look at controller/transform.xqy.