创建新话题
已回答

Issue with retrieving changes on an item

I have problems with retrieving changes made on an item. I have an application that utilizes the SystemWeaverClientAPI.dll and after establishing a connection I retrieve an item. Then I change the status of the item by using swExplorer.exe. Once this is done I want to retrieve the same item once again with the updated status, but this doesn't work. I still retrieve the initial status Work when I expect to retrieve status Released. In both cases I retrieve the item by using IswBroker and the method GetItem, which describes that it is not using the cache, see attachment.


Steps to reproduce

1. Create a new item by using swExplorer.exe

2. Retrieve the newly created item by using SystemWeaverClientApi and SWConnection -> ISwBroker -> GetItem

3. Change the status of the item to Released by using swExplorer.exe

4. Retrieve the item once again by using SystemWeaverClientApi and SWConnection -> ISwBroker -> GetItem

Actual result: Status of the IswItem is Work

Expected result: Status of the IswItem is Released


Is this case not supported or what am I doing wrong?


最佳答案

Hello! 


The items are indeed cached in the Client API, but the responses are not. So if you for example try to ask for an item that doesn’t exist over and over it will keep asking the server for it.

There are two solutions to this problem that I know of and I strongly recommend the first one if it works in your case.

 

This first solution is to use events which works especially well in a WPF application for example:

 

public MainWindow()
{
    SWConnection.Instance.LoginName = "admin";
<span class="fr-marker" data-id="0" data-type="true" style="display: none; line-height: 0;"></span>
    SWConnectio<span class="fr-marker" data-id="0" data-type="false" style="display: none; line-height: 0;"></span>n.Instance.Password = "yourpassword";
    SWConnection.Instance.ServerMachineName = "sys7";
    SWConnection.Instance.ServerPort = 1355;

    //Use the current synchronization context to get the events
    SWConnection.Instance.Login(EventSynchronization.SynchronizationContext);

    //Subscribe to the event
    SWConnection.Instance.EventManager.Item_SetStatus += EventManager_Item_SetStatus;

    //Get an item so you receive its events
    var item = SWConnection.Instance.Broker.GetItem(SWHandleUtility.ToHandle("x040000000001CBD9"));
    InitializeComponent();
}

private void EventManager_Item_SetStatus(IswItem item)
{
    //TODO: check if you care about the item that was changed and do something with it
    throw new NotImplementedException();
}

The other solution can potentially slow down the server if overused. I wouldn’t recommend doing it in a loop for example, but if it’s just a one time operation in a console application for example you could do it as follows:

static void Main(string[] args)
{

    var instance = SWConnection.Instance;
    instance.LoginName = "admin";
    instance.Password = "yourpassword";
    instance.ServerMachineName = "sys7";
    instance.ServerPort = 1355;
    instance.Login();

    var item = instance.Broker.GetItem(SWHandleUtility.ToHandle("x040000000001CBD9"));
    Console.WriteLine(item.Status); //Output: Work
    Console.WriteLine("Press any key to ping and print the status again");
    Console.ReadKey();
    instance.Ping();
    Console.WriteLine(item.Status); //Output: Frozen
    Console.ReadKey();
}


Hope that answers your question!

SystemWeaver Support

1 Comment

回答

Hello! 


The items are indeed cached in the Client API, but the responses are not. So if you for example try to ask for an item that doesn’t exist over and over it will keep asking the server for it.

There are two solutions to this problem that I know of and I strongly recommend the first one if it works in your case.

 

This first solution is to use events which works especially well in a WPF application for example:

 

public MainWindow()
{
    SWConnection.Instance.LoginName = "admin";
<span class="fr-marker" data-id="0" data-type="true" style="display: none; line-height: 0;"></span>
    SWConnectio<span class="fr-marker" data-id="0" data-type="false" style="display: none; line-height: 0;"></span>n.Instance.Password = "yourpassword";
    SWConnection.Instance.ServerMachineName = "sys7";
    SWConnection.Instance.ServerPort = 1355;

    //Use the current synchronization context to get the events
    SWConnection.Instance.Login(EventSynchronization.SynchronizationContext);

    //Subscribe to the event
    SWConnection.Instance.EventManager.Item_SetStatus += EventManager_Item_SetStatus;

    //Get an item so you receive its events
    var item = SWConnection.Instance.Broker.GetItem(SWHandleUtility.ToHandle("x040000000001CBD9"));
    InitializeComponent();
}

private void EventManager_Item_SetStatus(IswItem item)
{
    //TODO: check if you care about the item that was changed and do something with it
    throw new NotImplementedException();
}

The other solution can potentially slow down the server if overused. I wouldn’t recommend doing it in a loop for example, but if it’s just a one time operation in a console application for example you could do it as follows:

static void Main(string[] args)
{

    var instance = SWConnection.Instance;
    instance.LoginName = "admin";
    instance.Password = "yourpassword";
    instance.ServerMachineName = "sys7";
    instance.ServerPort = 1355;
    instance.Login();

    var item = instance.Broker.GetItem(SWHandleUtility.ToHandle("x040000000001CBD9"));
    Console.WriteLine(item.Status); //Output: Work
    Console.WriteLine("Press any key to ping and print the status again");
    Console.ReadKey();
    instance.Ping();
    Console.WriteLine(item.Status); //Output: Frozen
    Console.ReadKey();
}


Hope that answers your question!

SystemWeaver Support

登录 发表评论