List of Blogs
Search Blogs
Blog Archive

Most recent blog entries

 

Sep24

Written by:Martin
24.09.2007 08:33 

Some days ago somebody asked via a comment to my blog entry about SwyxIt API and Powershell if it is possible to consume events from the API, e.g. to run a Powershell script when a call comes in. I tried it using the RCW interop.clmgrlib.dll which exposes the SwyxIt COM API as .Net Types. However, Powershell only supports a specific kind of delegates. A small script from the Powershell blog (get-delegate.ps1) seemed to help.

PS> [System.Reflection.Assembly]::LoadFrom("Interop.CLMGRLib.dll")
PS> $clmgr = new-object clmgrlib.clientlinemgrclass
PS> $cb = get-delegate clmgrlib.IClientLineMgrEventsDisp_DispOnLineMgrNotificationEventHandler {write-host $args }
PS> $clmgr.add_disponlinemgrnotification($cb)

That gives no error, but the {write-host $args} script block is never called. I suppose it has something to do with different threads. Notifications are sent on separate threads and Powershell can't handle that.

Next I tried the PSEventing Powershell snapin. That seemed to work a little better, I could at least see that an event has been received. But Powershell crashes immediately after that. I don't know if it's PSEventing or the SwyxIt API wrapper.

There another approach I havn't tried yet: Host Powershell in an own application. A small program  written in C# would use the SwyxIt API in the same way as IpPbxController (see download section) does. That program would host Powershell and execute the script.

Tags:

3 comment(s) so far...

Re: SwyxIt! API and Powershell again

Hi Martin,

I'm the author of the PSEventing snapin for powershell; it was really only designed for sync/async _managed_ (e.g. pure .net) events, not COM. While it will work with COM proxies generated by .NET, there are all sorts of problems that can occur as you have noticed; mostly these are related to the fact that Powershell's worker threads are in an MTA, and most likely your $clmgr object is constructed in an STA by new-object. COM "events" can also require window messages to be pumped; a console application such as powershell does not have a message pump per-se, and this can lead to all sorts of problems.

This said, I'm working on enhancements to PSEventing 1.0 (for a 1.1 release) that will help enable this scenario. I'd be interested in getting some reproduction steps for the powershell crash you're experiencing in order to test my work in progress further. Post some info on the issue tracker or discussions on codeplex and I'll take a look into it.

Cheers!

- Oisin
http://www.nivot.org/

By Oisin Grehan on  30.09.2007 23:05

Re: SwyxIt! API and Powershell again

ok, try again with:

http://www.codeplex.com/PSEventing/Release/ProjectReleases.aspx?ReleaseId=7408

Please let me know how you get on.

- Oisin

By Oisin Grehan on  30.09.2007 23:05

Re: SwyxIt! API and Powershell again

Thanks. I'll give it a try. Will take a couple of days until I'll have the time.

By Martin on  01.10.2007 21:00

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment  Cancel 
Blog Help
Sponsors
bluvo AG
logic-base GmbH
Swyx Solutions AG, Germany

 

Charity

German Aid for Afghan Children

Swyx Forum supports the German Aid for Afghan Children (Kinderhilfe Afghanistan)