public void modifyItem(DataItem aItem, string aNewNodeId, int aNewSampling) { bool lChange = false; if (aItem.mNodeId.ToString().Equals(aNewNodeId, StringComparison.Ordinal) == false) { NodeId lNewNodeId = new NodeId(aNewNodeId); if (Connected) { byte lAccess; object lValue; StatusCode lStatusCode; string lType; bool lArray; checkVariable(lNewNodeId, out lAccess, out lValue, out lStatusCode, out lType, out lArray); mItemListLock.EnterWriteLock(); //======================================== try { removeItemFromSubscription(aItem); aItem.mNodeId = lNewNodeId; addItemToSubscription(aItem); aItem.setAccess(lAccess); aItem.StatusCode = lStatusCode; if ((lAccess == AccessLevels.CurrentRead || lAccess == AccessLevels.CurrentReadOrWrite) && StatusCode.IsGood(lStatusCode) && lValue != null) { aItem.mValue = lValue; } else { aItem.initValue(lType, lArray); } } finally { //======================================== mItemListLock.ExitWriteLock(); } } else { aItem.mNodeId = lNewNodeId; } lChange = true; } if (aItem.mSampling != aNewSampling) { aItem.mSampling = aNewSampling; mSubscription.FindItemByClientHandle(aItem.mClientHandle).SamplingInterval = aNewSampling; mSubscription.ApplyChanges(); lChange = true; } if (lChange) { aItem.raisePropertiesChanged(); if (aItem.Access.HasFlag(EAccess.READ)) { aItem.raiseValueChanged(); } } }
public DataItem addItem(string aNodeId, int aSampling) { if (String.IsNullOrWhiteSpace(aNodeId)) { throw new ArgumentException("Item NodeId is empty. "); } DataItem lItem = new DataItem(); lItem.mConnection = this; lItem.mSampling = aSampling; lItem.mNodeId = new NodeId(aNodeId); if (mConnected) { byte lAccess; object lValue; StatusCode lStatusCode; string lType; bool lArray; checkVariable(lItem.mNodeId, out lAccess, out lValue, out lStatusCode, out lType, out lArray); lItem.setAccess(lAccess); lItem.StatusCode = lStatusCode; if ((lAccess == AccessLevels.CurrentRead || lAccess == AccessLevels.CurrentReadOrWrite) && StatusCode.IsGood(lStatusCode) && lValue != null) { lItem.mValue = lValue; } else { lItem.initValue(lType, lArray); } } mItemListLock.EnterWriteLock(); //======================================== try { if (mConnected) { addItemToSubscription(lItem); } mItemList.Add(lItem); } finally { //======================================== mItemListLock.ExitWriteLock(); } lItem.raisePropertiesChanged(); if (lItem.Access.HasFlag(EAccess.READ)) { lItem.raiseValueChanged(); } ConnectionState += new EventHandler(lItem.onConnectionStateChanged); return(lItem); }