JScript handling COM events - events

I'm trying to figure out how I can add a JScript event handler to a COM interface. In this API
http://helpnet.installshield.com/installshield17helplib/IHelpAutoISWiRelease.htm
there are 3 Build Status Events I want to observe. Reading Microsofts documentation
http://msdn.microsoft.com/en-us/library/vstudio/06t47502(v=vs.100).aspx
leads me to believe I need to use a ISWiRelease.add_XXXXX(event_function) approach. But the ISWiRelease documentation does not list the "add event handler" methods.
Figuring this out seems like it should be simple. But I'm banging my head against a wall. There is an example for detecting the events with Visual Basic here
http://helpnet.flexerasoftware.com/installshield21helplib/helplibrary/AutomationBuildStatEv.htm
but that is of little help to me.
I tried to list the functions/methods using these approaches
How to display all methods of an object in Javascript?
How to list the functions/methods of a javascript object? (Is it even possible?)
but when I loop over the ISWiRelease object it acts as if it is empty.
How can I figure out the names of the addXXXX(..) event functions?
Additional Info:
I'm a JScript/wsf noob
The JScript is called via a .wsf file and cscript
I tried to add a basic import System; to the .js file which gave a syntax error (not sure why)
I'm only lightly scratching this project. I did not set it up, choose to use cscript or the Automation Interface, and would be much happier with calling the command line tool instead but I'm not in a position to make that sizeable a change.
This is a follow up to Redirecting the InstallShield log to console

Is your JScript code inside the WSF file? If so, you can add an <object> reference with events="true". Then you can define event handler functions using the objectName::eventName syntax. For example:
<job>
<object id="oWord" progid="Word.Application" events="true"/>
<script language="JScript">
function oWord::NewDocument(oDoc) {
WScript.Echo("New document: " + oDoc.Name);
}
oWord.Visible = true;
oWord.Documents.Add(); // fires the event handler
oWord.Documents.Add(); // fires the event handler again
WScript.Sleep(2000);
oWord.Quit();
</script>
</job>
(The MSDN article you linked to is about JScript.NET, which is separate from Windows Script Host.)

Related

Typescript syntax - How to spy on an Ajax request?

I am trying to write a unit test where I want to verify that a ajax call has been made.
The code is simple :
it('test spycall',()=>{
spyOn($,"ajax");
//my method call which in turns use ajax
MyFunc();
expect($.ajax.calls.mostRecent().args[0]["url"].toEqual("myurl");
});
The error that I get :
Property 'calls' doesn't exist on type '{settings:jqueryAjaxSettings):jQueryXHR;(url:string, settings?:JQueryAjaxSettings}
$.ajax.calls, among others, is part of the Jasmine testing framework, not JQuery itself (As you know, Jasmine (or rather, Jasmine-Jquery, the plugin you're using) is adding certain debugging functions to JQuery's prototype in order to, well, be able to test ajax calls).
The bad part is that your .d.ts typescript definition file, the file that acts as an interface between typescript and pure JS libraries isn't aware of Jasmine's functions.
There are several ways you could approach fixing this, like
looking if someone has adjusted the JQuery .d.ts file for Jasmine's functions or
creating the new .d.ts file yourself by modifying the original one or, (what I would be doing)
overwriting the typescript definition by declaring $.ajax as any, or not including the typescript definition at all in your testing codebase and declaring $ as any.
There are 2 ways to get rid of the error:
// 1
expect(($.ajax as any).calls.mostRecent().args[0].url).toEqual("myurl");
// 2
let ajaxSpy = spyOn($,"ajax");
expect(ajaxSpy.calls.mostRecent().args[0].url).toEqual("myurl");
You can also use partial matching:
expect(($.ajax as any).calls.mostRecent().args).toEqual([
jasmine.objectContaining({url: "myurl"})
]);

How to run-time click an arrayed command-button (by another arrayed or similar one) in vb6?

Run-time sending click command to a similar command-button named cmd1 is so easy from another control:
cmd1_Click
But this similar type not works when we're going to send this command from another form, there. For example by:
Form2.cmd1_Click
Then for this time we used to write:
Form2.cmd1.value = True
But now my question is for when this command-button is an array of controls. How we can code this doing one?
Comment turned to a an answer as the OP is happy with the response.
Equivalent for an array of controls is:
Form2.cmd1(0).value = True.
Or move your code from out of the event handler into a Public Sub and call the code from both your other form and the event handler

Invoke Method with client.soda ( Statement Object Model )

I am trying to build Esper EPL statements in Java.
I use the com.espertech.esper.client.soda lib for this, but I can't find
a tutorial to help me.
The PatternExpressions are the only part that I need as of now.
As an example let's use the EPL:
every a=Event((a).getEventTypeCode()='E00001')
So he should trigger on every Event with the event type code E00001, we get the code by
calling the getEventTypeCode Method.
How do I project this to SOM?
With:
PatternExpr pattern = Patterns.everyFilter("Event","a");
I only get:
every a=Event
(of course)
I know there is a class called "MethodInvocationStream" but I don't know how to use it.
And I cannot find examples for its use.
Thanks to user650839 I found out how to add Methods via SOM.
Here is a simple EPL as an SOM Object: http://imgur.com/SDrTsa7
One source of info is the javadoc.
You could simply do the reverse and compile EPL text to a model object and inspect that. Use "epAdmin.compileEPL", the output is the same object you want to build via API.\

Microsoft AJAX: Unable to get property 'x' of undefined or null reference

How do I troubleshoot the following error being thrown by a Microsoft AJAX JavaScript framework method? It is an automatically generated line of JavaScript from a custom User Control in a Web Forms App (Sitefinity 5 CMS)
Error Message:
Unable to get property 'FancyBlockDesigner' of undefined or null reference
Here is the JavaScript that is throwing the error:
Sys.Application.add_init(function() {
$create(SitefinityWebApp.Esd.TheLab.SampleHtmlEditor.FancyBlockDesigner, null, null, {"Editor":"propertyEditor_ctl00_ctl00_ctl00_ctl00_ctl00_Editor","propertyEditor":"propertyEditor"}, $get("propertyEditor_ctl00_ctl00_ctl00"));
});
Rather than discuss the ascx and cs files that try to abstract this detail away from me, I want to know what this error means. If I understand the detail, the abstraction might make more sense.
"$create" function in ASP.NET Ajax creates an instance of JavaScript class. Microsoft had their own opinion on how to make JavaScript object orientated and as time had shown, their approach wasn't exactly perfect.
Anyhow, to try to explain what is happening, let me give a bit of an overview oh how it works. We start by a server side control which implements IScriptControl interface which mandates two members: GetScriptDescriptors and GetScriptReferences. The second one is pretty straightforward - it lets you register references to all JavaScript files that you control will require. The GetScriptDescriptors, on the other hand, let's you define all the instances of JavaScript classes you want to use as well as it lets you set their properties - initialize them, if you will.
What the autogenerated JavaScript code you've pasted says is basically that you have defined in GetScriptDescriptors that you will need an instance of type "SitefinityWebApp.Esd.TheLab.SampleHtmlEditor.FancyBlockDesigner" where you want Editor property to be initialized. This code will go and look for a JavaScript constructor that looks like this:
function SitefinityWebApp.Esd.TheLab.SampleHtmlEditor.FancyBlockDesigner(element) {
}
that most probably also has a prototype defined, something like:
SitefinityWebApp.Esd.TheLab.SampleHtmlEditor.FancyBlockDesigner.prototype = {
}
Now, since the error you have posted states: "Unable to get property 'FancyBlockDesigner' of undefined or null reference", most probably one of the following is the problem:
You have not included the JavaScript file which contains the class (constructor + prototype) that I've talked about above
You have forgot to add the "FancyBlockDesigner" to the constructor (it seems that you do have other object, perhaps through MS Ajax namespaces - "SitefinityWebApp.Esd.TheLab"
You have not registerd the "SampleHtmlEditor" namespace. Make sure at the top of your JS file you have this: Type.registerNamespace("SitefinityWebApp.Esd.TheLab.SampleHtmlEditor");
So, short story long, the function with name "SitefinityWebApp.Esd.TheLab.SampleHtmlEditor.FancyBlockDesigner" cannot be found.
Hope this helps,
Ivan

Using callback functions in vbscript

I'm trying to make an update script for windows7 in vbscript
when invoking IUpdateSearcher::BeginSearch how do I pass the callback to ISearchCompletedCallback::Invoke Method?
I'm just clueless on this points:
do I need an function or sub or does this a custom object with an invoke method(and how to create)
how I need to pass the callback
is it even possible in vbscript (if not what is a good next step?)
Thanks
I've never tried it, but I'd look at the ConnectObject Method.
This article about scripting events might also be useful.
So maybe something like this (complete guess):
Set objSession = CreateObject("Microsoft.Update.Session")
Set objSearcher = objSession.CreateUpdateSearcher
WScript.ConnectObject objSearcher, "searcherCallBack_"
objSearcher.BeginSearch ...
sub searcherCallBack_Invoke()
' handle the callback
end sub
I'd also suggest reading Guidelines for Asynchronous WUA Operations to make sure that you clean up after yourself.
that link also mentions using Windows Script Host, so it should definitely be possible to do this, though unless you need it to be asynchronous, the synchronous methods wouls probably be a easier.

Resources