GetService<IWindowManager>() returns null

Discussions related to order tracking development with the ProForm module.

Moderator: Phil Barton

Post Reply
KPChow
Posts: 23
Joined: Fri May 27, 2016 1:18 pm

GetService<IWindowManager>() returns null

Post by KPChow »

I am trying to get the active order, but my windowsmanager is null. Am I missing something?


private IOrder GetActiveOrder()
{
// Open connection to server.
NetworkCredential creds = new NetworkCredential("<Username>", "<password>", "[SERVER]");
SelectServer sps = new SelectServer("http://SP-APP-TEST:8080", creds);

string reason;
if (!sps.TryAuthenticate(out reason))
{
Console.WriteLine(reason);
return null;
}

//Authentication passes

SoftPro.Select.Shell.IWindowManager windowManager = sps.GetService<IWindowManager>();
if (windowManager == null) return null; //but, windowManager is null

SoftPro.Select.Shell.IWindowFrame activeDocument = windowManager.ActiveDocument;
if (activeDocument == null) return null;

SoftPro.Select.Shell.IRunningDocumentsManager runningDocumentsManager =
sps.GetService<IRunningDocumentsManager>();
if (runningDocumentsManager == null) return null;

SoftPro.Select.Shell.IRunningDocumentInformation runningDocumentInformation =
runningDocumentsManager.FindDocument(activeDocument.DocumentHandle);
if (runningDocumentInformation == null) return null;

SoftPro.Select.Shell.EditorPane p = runningDocumentInformation.Data as EditorPane;
if (p == null) return null;

return p.GetProperty("Order") as SoftPro.OrderTracking.Client.Orders.IOrder;
}
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: GetService<IWindowManager>() returns null

Post by BobRichards »

I'm not sure what you are trying to achieve. Can you provide more details?

You have gotten your own connection to the mid-tier (SelectServer sps = new SelectServer(...)) so you are an independent stand-alone client - not an instance of Select client (where the IWindowManager exists).

Select clients have an active window that only it knows about. The Select mid-tier does not have an IWindowManager because it does not have any GUI elements that Select clients have.
Bob Richards, Senior Software Developer, SoftPro
KPChow
Posts: 23
Joined: Fri May 27, 2016 1:18 pm

Re: GetService<IWindowManager>() returns null

Post by KPChow »

Thanks for the response Bob,

I am trying to retrieve the active order's attachments and pass them to an e-recording client.
BobRichards wrote:You have gotten your own connection to the mid-tier (SelectServer sps = new SelectServer(...)) so you are an independent stand-alone client - not an instance of Select client (where the IWindowManager exists).
I have established my connection to the mid-tier as.

NetworkCredential creds = new NetworkCredential("<username>", "<password>", "[SERVER]");
SelectServer sps = new SelectServer("http://SP-APP-TEST:8080", creds);

string reason;
if (!sps.TryAuthenticate(out reason))
{
Console.WriteLine(reason);
return null;
}

sps.TryAuthenticate is successful, but the next line returns a null in place of windowManager.

IWindowManager windowManager = sps.GetService<IWindowManager>();
KPChow
Posts: 23
Joined: Fri May 27, 2016 1:18 pm

Re: GetService<IWindowManager>() returns null

Post by KPChow »

I can do something like this to get an iorder:

IOrderStore os = sps.GetService<IOrderStore>();
IOrderInfo search = os.Orders.Where(t => t.Number == "600-62602").FirstOrDefault();

if (search != null)
{
// Open found order.
IOrder order = os.OpenOrder(search, true);
return order;
}

Is there a way just to get the order number of the active order so that I can use it in this linq query?

IOrderInfo search = os.Orders.Where(t => t.Number == "<active order number>").FirstOrDefault();
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: GetService<IWindowManager>() returns null

Post by BobRichards »

But you are a separate client instance - possibly one of hundreds - with no connection to any Select client GUI. There is no Active Window to get. What you have done is spin up a totally separate client connection to the server that can have no knowledge of any clients.

If you are running on a machine where the Select client GUI is running and you want to get the current user's Active Window, you need to be a Shell package running in the user's process. You should refer to the SDK topics in How-To/Shell Package Development to create a shell package that runs at each client location. If you need some one-on-one design assistance, perhaps you should contact your Select Customer Representative to inquire about help from R&D.
Bob Richards, Senior Software Developer, SoftPro
KPChow
Posts: 23
Joined: Fri May 27, 2016 1:18 pm

Re: GetService<IWindowManager>() returns null

Post by KPChow »

I got this working:

private IOrder GetActiveOrder()
{
IWindowManager windowManager = this.GetService<IWindowManager>();
if (windowManager == null) return null;
IWindowFrame activeDocument = windowManager.ActiveDocument;
if (activeDocument == null) return null;
return activeDocument.GetProperty("Order") as IOrder;
}

where "this" is a child class of SoftPro.Select.Shell.Package
Post Reply