Is there a DXL API to get the reference count of opened modules? - ibm-doors

The "Manage Open Modules" dialog of DOORS 8.3 lists all open modules, their mode, if visible, etc. and the number of references. I want to use that reference count to decide if my script can securely close the module and to avoid closing if it is currently in use. I'm not sure what the "References" column displays exactly. I didn't find a description of it in the help or corresponding informations on the internet. Does anybody know if there is some undocumented DXL API which gives me access to that information?
Edit: I found the function refcount_ which returns an integer. But I have no idea what the return value means.

It looks like References refers to the number of open modules currently referencing that module. For example: when you open a module that has links, DOORS also opens in the background all of the Link Modules that the links use. So if I open a document that has links through LINKMOD_A, LINKMOD_A will show 1 reference. If I then open another document that has links through that same LINKMOD_A the number of references will increase to 2. I do not see the number of references ever higher than 1 on a Formal Module. Try this on some of your modules and see when you get more than one reference on a link module, then run your refcount_ function against that link module and see if you get the same number. I am not sure if that is the function you are looking for but it is certainly possible. Good Luck!

I assume your script is opening the modules, so all you need to do is check if it is already open first.
string sModuleFullName = "/Some/Module/Path"
Module oModule = module(sModuleFullName)
bool bClose = null(oModule)
if(null(oModule)) {
oModule = read(sModuleFullName, true,true)
}
// do stuff
if(bClose) {
close(oModule)
}
Edit:
Alternative method for closing modules opened by triggers, attribute or layout dxl
// Save currently open Modules to a Skip
Skip oOpenModulesSkip = createString()
Module oModule
for oModule in database do {
put(oOpenModulesSkip, fullName(oModule), fullName(oModule))
}
// do stuff
// Close Modules not in the Skip
for oModule in database do {
if(!find(oOpenModulesSkip, fullName(oModule))) {
close(oModule, false)
}
}
delete(oOpenModulesSkip)

Related

How to prevent automatic hyperlink detection in the console of Firefox/Chrome developer tools?

Something that drives me nuts in the developper tools of Chrome (106) and Firefox (105) is the fact that whenever some text logged to the console via console.log(text) happens to contain a hyperlink, this link is not only turned clickable (I can live with it even when I usually prefer to have just plain text) but is abbreviated, if it is a long link. So when I want to control what precise link is in some variable, I cannot just write e.g. console.log(img.src), because some of the interesting information of the link is hidden.
You can try yourself with
var href = 'https://stackoverflow.com/search?q=%5Bgoogle-chrome-devtools%5D+%5Bconsole.log%5D+%5Bfirefox-developer-tools%5D+%5Bhyperlink%5D+automatic+detection&someMoreStuffTomakeTheLinkLonger';
console.log(href);
In both, Firefox and Chrome, the output for me contains some '...', e.g. in Firefox I obtain as output:
https://stackoverflow.com/search?q=%5Bgoogle-chrome-devtools…link%5D+automatic+detection&someMoreStuffTomakeTheLinkLonger
thus hiding the part after "-devtools". (Chrome hides a slightly different part). The console is mostly a debugging tool. I log things because I want to see them, not hide them. I always need to either hover with the mouse and wait for the tooltip (doesn't allow me to copy fractions of the link) or to right click copy the link and paste it somewhere where I can see it completely. Or take a substring to remove the "https://" in the front. But note that the variable isn't necessarily a single hyperlink, but can be any text containing several such hyperlinks. I didn't find a way to force console.log to just print plain text all content. Did anybody meet this problem as well and find a workaround?
I made this a community wiki answer, because the main insight is not from myself but from the comments. Feel free to improve.
The console.log() function allows several arguments, which allows also a formatted output similar to printf in some languages. The possibilities of formatting can be found in the documentation of console.log() on MDN. In any case, this formatted output provides a solution at least for Chrome, as #wOxxOm pointed out in the comments:
console.log('%O', href) // works in Chrome
This is rather surprising, because %O is described at MDN as
"Outputs a JavaScript object. Clicking the object name opens more information about it in the inspector".
It seems there is no 'clicking' in Chrome when the object is a string.
There is also %s for string output, but this just gives the standard behavior of replacing links in both browsers. And for Firefox none of the above two formatting options works. There one really has to replace the protocol "https://" by something that is not recognized as link. A space behind ':' seems enough, so "https: //". It turns out, that one can also insert a formatting string "https:%c//", which can even be empty, and thus yield an output which is the complete link and can be copied as well:
console.log(href.replace(/(https?:)/, "$1%c"), ""); // works in Firefox
In particular the FF solution is cumbersome, and there might also be several links within one console-output. So it is useful to define one's own log-function (or if one prefers, redefine console.log, but note the remark at the end)
function isChrome() {...} // use your favorite Chrome detection here
function isFirefox() {...} // use your favorite Firefox detection here
function plainLog() {
const msg = arguments[0];
if (isChrome() && arguments.length == 1 && typeof msg == "string") {
return console.log("%O", msg);
}
if (isFirefox() && arguments.length == 1 && typeof msg == "string") {
const emptyStyle = ""; // serves only as a separator, such that FF doesn't recognize the link anymore
const reg = /(https?:)\/\//g;
const emptyStyles = []; // we need to insert one empty Style for every found link
const matches = msg.matchAll(reg);
for (let match of matches) {
emptyStyles.push(emptyStyle);
}
return console.log(msg.replace(reg, '$1%c//'), ...emptyStyles);
}
return console.log(...arguments);
}
For browser detection isChrome() and isFirefox() see e.g. here on SO.
One can of course extend the redefinition also to the other console functions (console.info, console.warn, etc.)
The downside of the redefinition of console.log is that usually every output of the console shows also the last entry of the call stack as a practical link to the source of the logging. But due to the redefintion, this link is now always to the same place, namely the file and line number where plainLog() is defined and calls console.log(), instead of the place where the new log command plainLog() was called. This new problem is described on SO here, but the solution (see comment) is again a bit involved and also not completely satisfying to serve as a replacement for the built-in console.log . So if links appear only rarely in the logging, it's probably better to switch to the redefined plainLog() only for these links.

How to reflect Dart library name?

Is there a way to reflect specific library properties (like the library name) in Dart?
How do you get the library object reference?
First of all, not all Dart libraries have names. In fact, most don't. They used to, but the name isn't used for anything any more, so most library authors don't bother adding a name.
To do reflection on anything, including libraries, you need to use the dart:mirrors library, which does not exist on most platforms, including the web and Flutter.
If you are not running the stand-alone VM, you probably don't have dart:mirrors.
With dart:mirrors, you can get the program's libraries in various ways.
library my.library.name;
import "dart:mirrors";
final List<LibraryMirror> allLibraries =
[...currentMirrorSystem().libraries.values];
void main() {
// Recognize the library's mirror in *some* way.
var someLibrary = allLibraries.firstWhere((LibraryMirror library) =>
library.simpleName.toString().contains("name"));
// Find the library mirror by its name.
// Not great if you don't know the name and want to find it.
var currentLibrary = currentMirrorSystem().findLibrary(#my.library.name);
print(currentLibrary.simpleName);
// Find a declaration in the current library, and start from there.
var mainFunction = reflect(main) as ClosureMirror;
var alsoCurrentLibrary = mainFunction.function.owner as LibraryMirror;
print(alsoCurrentLibrary.simpleName);
}
What are you trying to do, which requires doing reflection?

VCLua library fault to load

I have downloaded VCLua library here. I created new file named program.lua and typed there code that is in tutorial:
require "vcl"
mainForm = VCL.Form("mainForm")
mainForm.Caption = "My first VCLua application"
mainForm._= { position="podesktopcenter", height=400, width=600}
mainForm.onclosequery = "onCloseQueryEventHandler"
function onCloseQueryEventHandler(Sender)
return true -- the form can be closed
end
mainMenu = VCL.MainMenu(mainForm,"mainMenu")
mainMenu:LoadFromTable({
{name="mmfile", caption="&File",
submenu={
{name="mmOpen", caption="Open...", onclick="onMenuOpenClick", shortcut="Ctrl+O"},
{caption="-",},
{caption="Exit", onclick="onMenuExitClick", shortcut="Alt+F4"},
}
},
{name="mmhelp", caption="&Help", RightJustify=true,
submenu = {
{caption="Help", shortcut="F1", checked=true},
{caption="-",},
}
}
})
mainMenu:Find("mmhelp"):Add("mmAbout")._= {caption="About", onclick="onMenuAboutClick", enabled=false}
function onMenuExitClick()
mainForm:Close()
end
mainToolbar = VCL.ToolBar(mainForm,"mainToolbar")
mainToolbar:LoadFromTable({
{name="mtbOpen", onclick="onMenuOpenClick"},
{name="mtbExit", onclick="onMenuExitClick"},
})
mainToolbar:Find("mtbOpen").enabled=false
mainForm:ShowModal()
mainForm:Free()
But when i want to run it (i have both vcl.dll and vcl.so files in directory where lua interpreter is), it writes lua: error loading module 'vcl' from file 'C:\Users\Admin\Desktop\Programs\lua\vcl.dll':. Stack trace dont say anything useful. So can anyone tell me, how to solve my problem?
Dynamic libraries for Lua are usually compiled against Lua DLLs; you may get this error in a case when the dynamic library can't find the Lua DLLs it's linked against. You can see why/how it fails using a tool like dependency walker, which can show you both what other DLLs your library depends on and also what run-time error you get when you load it (you can use "Profile" mode to see that).

"document" in mozilla extension js modules?

I am building Firefox extension, that creates single XMPP chat connection, that can be accessed from all tabs and windows, so I figured, that only way to to this, is to create connection in javascript module and include it on every browser window. Correct me if I am wrong...
EDIT: I am building traditional extension with xul overlays, not using sdk, and talking about those modules: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules
So I copied Strophe.js into js module. Strophe.js uses code like this:
/*_Private_ function that creates a dummy XML DOM document to serve as
* an element and text node generator.
*/
[---]
if (document.implementation.createDocument === undefined) {
doc = this._getIEXmlDom();
doc.appendChild(doc.createElement('strophe'));
} else {
doc = document.implementation
.createDocument('jabber:client', 'strophe', null);
}
and later uses doc.createElement() to create xml(or html?) nodes.
All worked fine, but in module I got error "Error: ReferenceError: document is not defined".
How to get around this?
(Larger piece of exact code: http://pastebin.com/R64gYiKC )
Use the hiddenDOMwindow
Cu.import("resource://gre/modules/Services.jsm");
var doc = Services.appShell.hiddenDOMWindow.document;
It sounds like you might not be correctly attaching your content script to the worker page. Make sure that you're using something like tabs.attach() to attach one or more content scripts to the worker page (see documentation here).
Otherwise you may need to wait for the DOM to load, waiting for the entire page to load
window.onload = function ()
{
Javascript code goes here
}
Should take at least diagnose that issue (even if the above isn't the best method to use in production). But if I had to wager, I'd say that you're not attaching the content script.

Visual Studio macro to navigate to T4MVC link

I use T4MVC and I'm happy with it and want to keep it - it keeps down run time defects. Unfortunately, it makes it harder to navigate to views and content (a.k.a. Views and Links in T4MVC) though. Even using Resharper, I can't navigate to the referenced item:
T4MVC and Resharper Navigation
Can I get a hand building a macro to do this? Never having built a VS IDE macro before, I don't have a grasp on how to get at some things, like the internal results of the "Go To Definition" process, if that's even possible.
If you aren't familiar with T4MVC, here's generally what the macro might do to help:
Given the token: Links.Content.Scripts.jQuery_js in the file MyView.cshtml, '(F12) Go To Definition'. This behaves properly.
Having arrived at the the related assignment:
public readonly string jQuery_js = "~/Content/Scripts/jQuery.js"; in a file generated by T4MVC (which is very nice, thank you David, but we really don't ever need to see), capture the string assigned and close the file.
Navigate in Solution Explorer to the PhysicalPath represented by the captured string.
This process would also work for views/layouts/master-pages/partials, etc.
If you provide a macro or link to a macro to do this, or have another solution, wonderful. Otherwise, hints on how to do step 3 simply in a VS macro would be especially appreciated and receive upvote from me. I'd post the macro back here as an answer when done.
Thanks!
Here's a Visual Studio macro to help.
What it does
Now you probably use T4MVC references in places like this:
Layout = MVC.Shared.Views.MasterSiteTheme;
ScriptManager.AddResource(Links.Content.Script.jQueryXYZ_js);
<link type="text/css" href="#Links.Content.Style.SiteTheme_css" />
return View(MVC.Account.Views.SignIn);
#Html.Partial(MVC.Common.Views.ContextNavigationTree)
#Html.ActionLink("Sign in / Register", MVC.Account.SignIn())
F12 (Go to Definition) already works for the last bullet (actions), but this hack is intended to cover the other scenarios (resources).
Macro
Imports EnvDTE
Imports System.IO
Public Module NavT4Link
Sub NavigateToLink()
DTE.ExecuteCommand("Edit.GoToDefinition")
Dim navpath As String = Path.GetFileName(DTE.ActiveDocument.FullName)
Dim isContentLink As Boolean = navpath.Equals("T4MVC.cs")
If (isContentLink Or navpath.EndsWith("Controller.generated.cs")) Then
Dim t4doc As TextDocument = DTE.ActiveDocument.Object()
navpath = CurrentLinePathConstant(t4doc)
If isContentLink Then
t4doc.Selection.MoveToPoint(t4doc.Selection.ActivePoint.CodeElement(vsCMElement.vsCMElementClass).StartPoint)
t4doc.Selection.FindText("URLPATH")
navpath = Path.Combine(CurrentLinePathConstant(t4doc), navpath)
End If
If navpath.StartsWith("~") Then
DTE.ActiveDocument.Close(vsSaveChanges.vsSaveChangesPrompt)
Dim proj As Object = DTE.Solution.FindProjectItem(DTE.ActiveDocument.FullName).ContainingProject
navpath = Path.GetDirectoryName(proj.Fullname()) + navpath.TrimStart("~")
DTE.ItemOperations.OpenFile(navpath)
End If
End If
End Sub
Function CurrentLinePathConstant(ByVal t4doc As TextDocument) As String
t4doc.Selection.SelectLine()
Dim sa() As String = t4doc.Selection.Text().Split("""")
If sa.Length > 1 Then Return sa(sa.Length - 2) Else Return ""
End Function
End Module
Installation
In Visual Studio, press "Alt-F8" to open Macro Explorer.
Right-Click "My Macros", select "New Module...", and click "Add".
Replace all the text with the code shown here.
Save and exit the Macro Editor.
Open "Tools : Options".
In the left pane, select "Environment : Keyboard".
In the "Show commands containing" text field enter "T4".
In the "Press shortcut keys:" field press the "F12" key.
Click "Assign" and "OK".
On un-patched VS, this installation process doesn't result in a 'bindable' macro. A workaround was to (CTRL-SHIFT-R-R) to record an empty macro, and paste the code into it without renaming it. If someone knows of a more documentable approach to install a macro in VS, please comment.
Notes/Caveats
It's meant to replace the current F12 functionality, so if it isn't a T4MVC link, it will do the usual, otherwise it continues on to open the resource. It handles the majority of cases, but not T4MVC-generated empty controller methods. Those you get dumped off at the same place you did before.
For Content/Asset/Link resources, navigating to it in Solution Explorer would probably be in order, for image files for example, but I didn't see that functionality in the Visual Studio docs.

Resources