public bool RemoveItems(params ITag[] items) { int count = items.Length; int[] arrSvr = new int[count]; for (int i = 0; i < count; i++) { ITag item = items[i]; //if (item == null) // return false; arrSvr[i] = item.Address.Start; _server.RemoveItemIndex(item.GetTagName()); _items.Remove(item); } IntPtr ptrErr; int result = _itemMgt.RemoveItems(count, arrSvr, out ptrErr); Marshal.FreeCoTaskMem(ptrErr); return(HRESULTS.Succeeded(result)); }
public bool RemoveItems(int[] arrHSrv, out int[] arrErr) { arrErr = null; int count = arrHSrv.Length; IntPtr ptrErr; int hresult = ifItems.RemoveItems(count, arrHSrv, out ptrErr); if (HRESULTS.Failed(hresult)) { Marshal.ThrowExceptionForHR(hresult); } arrErr = new int[count]; Marshal.Copy(ptrErr, arrErr, 0, count); Marshal.FreeCoTaskMem(ptrErr); return(hresult == HRESULTS.S_OK); }
/// <summary> removes all OPC-Items from this group </summary> /// <exception cref="Exception">throws and forwards any exception (with short error description)</exception> private void removeItems() { IntPtr pErrors = IntPtr.Zero; if (m_itmServerHandles != null) { try { int[] pItems; int[] errors; int numberOfItems = m_itmServerHandles.Length; // Removes items pItems = new int[numberOfItems]; errors = new int[numberOfItems]; pItems = (int[])(m_itmServerHandles.Clone()); m_OPCItem.RemoveItems(numberOfItems, pItems, out pErrors); //Evaluating Return ErrorCodes to exclude possible Errors Marshal.Copy(pErrors, errors, 0, numberOfItems); for (int xCount = 0; xCount < numberOfItems; xCount++) { // Data has been received if (errors[xCount] != 0) { throw new Exception("At least one item is not removed."); } } // Delete item server handles for (int idx = 0; idx < numberOfItems; idx++) { m_itmServerHandles[idx] = 0; } Marshal.FreeCoTaskMem(pErrors); } catch (Exception) { throw; } } }
public bool RemoveItems(int[] p_ArrHSrv, out int[] p_ArrErr) { p_ArrErr = null; int l_Count = p_ArrHSrv.Length; IntPtr l_PtrErr; int l_HResult = m_IfItems.RemoveItems(l_Count, p_ArrHSrv, out l_PtrErr); if (HResults.Failed(l_HResult)) { Marshal.ThrowExceptionForHR(l_HResult); } p_ArrErr = new int[l_Count]; Marshal.Copy(l_PtrErr, p_ArrErr, 0, l_Count); Marshal.FreeCoTaskMem(l_PtrErr); return(l_HResult == HResults.S_OK); }
public void DeleteItems(string[] id, int[] ItemHANDLES) { int m_Res = 0; try { int dwCount = ItemHANDLES.Length; IntPtr pErrors; IOPCItemMgt m_pIItemMgt = (IOPCItemMgt)pUnknown; //add item m_Res = m_pIItemMgt.RemoveItems(dwCount, ItemHANDLES, out pErrors); if (m_Res < 0) { throw new Exception("Server: Delete Items failed hr= " + m_Res.ToString()); } int runErr = (int)pErrors; if (runErr == 0) { throw new Exception("Server: Delete Items failed hr= " + unchecked ((int)0x80004004).ToString()); } int error; for (int i = 0; i < dwCount; i++) { error = Marshal.ReadInt32((IntPtr)runErr); if (error < 0) { //parent.PrintMessage("Server: Delete Item " + id[i] + " is failed hr =" + error.ToString(), MessageStyl.error); runErr += 4; } } Marshal.FreeCoTaskMem(pErrors); } catch (Exception e) { //parent.PrintMessage(e.Message, MessageStyl.error); throw e; } }
/// <summary> /// Removes the items from the group that have been marked as deleted. /// </summary> public void RemoveItems() { // count the number of items to remove. List <GroupItem> itemsToRemove = new List <GroupItem>(); lock (Lock) { List <GroupItem> itemsToKeep = new List <GroupItem>(); for (int ii = 0; ii < m_items.Count; ii++) { if (m_items[ii].Deleted && m_items[ii].Created) { itemsToRemove.Add(m_items[ii]); continue; } itemsToKeep.Add(m_items[ii]); } m_items = itemsToKeep; } // check if nothing to do. if (itemsToRemove.Count == 0) { return; } // build list of items to remove. int count = itemsToRemove.Count; int[] serverHandles = new int[count]; for (int ii = 0; ii < itemsToRemove.Count; ii++) { serverHandles[ii] = itemsToRemove[ii].ServerHandle; // remove the associated monitored items. if (m_monitoredItems != null) { lock (m_monitoredItems) { m_monitoredItems.Remove(itemsToRemove[ii].ClientHandle); } } } IntPtr pErrors = IntPtr.Zero; string methodName = "IOPCItemMgt.RemoveItems"; try { IOPCItemMgt server = BeginComCall <IOPCItemMgt>(methodName, true); // remove items. server.RemoveItems( count, serverHandles, out pErrors); } catch (Exception e) { ComUtils.TraceComError(e, methodName); for (int ii = 0; ii < itemsToRemove.Count; ii++) { itemsToRemove[ii].Created = false; itemsToRemove[ii].ErrorId = Marshal.GetHRForException(e); } return; } finally { EndComCall(methodName); } // free returned error array. int[] errors = ComUtils.GetInt32s(ref pErrors, count, true); // save error codes. for (int ii = 0; ii < count; ii++) { itemsToRemove[ii].Created = false; itemsToRemove[ii].ErrorId = errors[ii]; } /* * Utils.Trace( * "Group {0} RemoveItems({4}/{5}) {1}/{2}ms {3}%", * m_clientHandle, * m_samplingInterval, * m_actualSamplingInterval, * m_deadband, * itemsToRemove.Count, * m_items.Count); */ }