EBDN - Community - Question & Answers

  Wednesday, 03 July 2019
  3 Replies
  1.6K Visits
0
Votes
Undo
Hello,

I created one Macro with below code to add/update attribute to object item. It runs in loop to update many object attribute in a project. I have a test case where more then one Ebase client run from different system using this macro with there separate project. All client using one Ebase Sever and database.

The below function work fine if one client runs at a time. But when more then one client starts Macro and tried to update attribute using below code then attr = obj.Attributes.Add(id, Value, TabName); gives exception. Its means obj.Attributes.TryFindById(id, out attr) has a bug and not handle properly with multiple client and allowed to even if other client already added the same attribute. so that Attributes.Add API raised exception.

Exeption:

Server stack trace:
at Aucotec.EngineeringBase.Client.RuntimeHostAdapter.AttributeCollectionHostAdapterViewToContract.Add(AttributeId id, Object value)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Aucotec.EngineeringBase.Client.RuntimeContract.IAttributeCollection.Add(AttributeId id, Object value)
at Aucotec.EngineeringBase.Client.RuntimeAddInAdapter.AttributeCollectionAddInAdapterContractToView.Add(AttributeId id, Object value)

Below is the code of the function used in my Macro.


public static void ForceSetAttrValue(this ObjectItem obj, AttributeId id, Object Value, string TabName = "ABB System Info")
{
AttributeItem attr;
if (obj.Attributes.TryFindById(id, out attr))
{
if (!attr.IsFromCatalog)
{
if (!attr.IsSystemReadOnly)
attr.Value = Value;
else
SimpleLog.addLogMessage("Attribute is Read-only: Failed to set " + attr.Name + " " + attr.Id, MessageType.Warning);
}
else
{
//remove from Catalog flag in this case - force
attr.IsFromCatalog = false;
attr.Value = Value;
}
}
else
{
SimpleLog.addLogMessage("Add Attribute " + attr.Name + " " + attr.Id, obj.FullName, MessageType.Info_L3);
attr = obj.Attributes.Add(id, Value, TabName);
if (!obj.IsVirtual)
SimpleLog.addLogMessage("Add missing Attribute " + attr.Name + " " + attr.Id, obj.FullName, MessageType.Info_L3);
}
}



Thanks
Neeraj Kumar