Opc.Ua.Server.CoreNodeManager.HistoryUpdate C# (CSharp) Method

HistoryUpdate() private method

private HistoryUpdate ( OperationContext context, Type detailsType, IList nodesToUpdate, IList results, IList errors ) : void
context OperationContext
detailsType System.Type
nodesToUpdate IList
results IList
errors IList
return void
        public void HistoryUpdate(
            OperationContext            context,
            Type                        detailsType,
            IList<HistoryUpdateDetails> nodesToUpdate, 
            IList<HistoryUpdateResult>  results, 
            IList<ServiceResult>        errors) 
        {
            if (context == null)       throw new ArgumentNullException("context");
            if (nodesToUpdate == null) throw new ArgumentNullException("nodesToUpdate");
            if (results == null)       throw new ArgumentNullException("results");
            if (errors == null)        throw new ArgumentNullException("errors");
            
            #if LEGACY_CORENODEMANAGER
            Dictionary<object,List<RequestHandle>> historians = new Dictionary<object,List<RequestHandle>>();
            #endif
            
            try
            {
                m_lock.Enter();
 
                #if LEGACY_CORENODEMANAGER 
                Type sourceType = typeof(IDataHistoryProducer);

                if (detailsType == typeof(UpdateEventDetails) || detailsType == typeof(DeleteEventDetails))
                {
                    sourceType = typeof(IEventHistoryProducer);
                }
                #endif

                for (int ii = 0; ii < nodesToUpdate.Count; ii++)
                {
                    HistoryUpdateDetails nodeToUpdate = nodesToUpdate[ii];

                    // skip items that have already been processed.
                    if (nodeToUpdate.Processed)
                    {
                        continue;
                    }
                    
                    // look up the node.
                    ILocalNode node = GetLocalNode(nodeToUpdate.NodeId) as ILocalNode;

                    if (node == null)
                    {
                        continue;
                    }
                    
                    // owned by this node manager.
                    nodeToUpdate.Processed = true;
                    
                    #if LEGACY_CORENODEMANAGER 
                    // find the historian.
                    if (!CheckSourceHandle(node, sourceType, ii, historians))
                    {
                        errors[ii] = StatusCodes.BadNotWritable;
                        continue;
                    }
                    #else
                    errors[ii] = StatusCodes.BadNotWritable;
                    #endif
                }
            }
            finally
            {
                m_lock.Exit();
            }
                
            #if LEGACY_CORENODEMANAGER 
            // check if nothing to do.
            if (historians.Count == 0)
            {
                return;
            }

            // call the historians.
            foreach (KeyValuePair<object,List<RequestHandle>> entry in historians)
            {
                if (detailsType == typeof(UpdateDataDetails))
                {
                    List<UpdateDataDetails> typedList = new List<UpdateDataDetails>(nodesToUpdate.Count);

                    foreach (UpdateDataDetails nodeToUpdate in nodesToUpdate)
                    {
                        typedList.Add(nodeToUpdate);
                    }

                    ((IDataHistoryProducer)entry.Key).UpdateRaw(
                        context,
                        entry.Value,
                        typedList,
                        results,
                        errors);                            
                }

                else if (detailsType == typeof(DeleteRawModifiedDetails))
                {
                    List<DeleteRawModifiedDetails> typedList = new List<DeleteRawModifiedDetails>(nodesToUpdate.Count);

                    foreach (DeleteRawModifiedDetails nodeToUpdate in nodesToUpdate)
                    {
                        typedList.Add(nodeToUpdate);
                    }

                    ((IDataHistoryProducer)entry.Key).DeleteRaw(
                        context,
                        entry.Value,
                        typedList,
                        results,
                        errors);                          
                }

                else if (detailsType == typeof(DeleteAtTimeDetails))
                {
                    List<DeleteAtTimeDetails> typedList = new List<DeleteAtTimeDetails>(nodesToUpdate.Count);

                    foreach (DeleteAtTimeDetails nodeToUpdate in nodesToUpdate)
                    {
                        typedList.Add(nodeToUpdate);
                    }

                    ((IDataHistoryProducer)entry.Key).DeleteAtTime(
                        context,
                        entry.Value,
                        typedList,
                        results,
                        errors);                          
                }                        

                else if (detailsType == typeof(UpdateEventDetails))
                {
                    List<UpdateEventDetails> typedList = new List<UpdateEventDetails>(nodesToUpdate.Count);

                    foreach (UpdateEventDetails nodeToUpdate in nodesToUpdate)
                    {
                        typedList.Add(nodeToUpdate);
                    }

                    ((IEventHistoryProducer)entry.Key).UpdateEvents(
                        context,
                        entry.Value,
                        typedList,
                        results,
                        errors);                          
                }                  

                else if (detailsType == typeof(DeleteEventDetails))
                {
                    List<DeleteEventDetails> typedList = new List<DeleteEventDetails>(nodesToUpdate.Count);

                    foreach (DeleteEventDetails nodeToUpdate in nodesToUpdate)
                    {
                        typedList.Add(nodeToUpdate);
                    }

                    ((IEventHistoryProducer)entry.Key).DeleteEvents(
                        context,
                        entry.Value,
                        typedList,
                        results,
                        errors);                          
                }
            }
            #endif
        }