Opc.Ua.ServerTest.SubscribeTest.DoCreateItemsTest C# (CSharp) Method

DoCreateItemsTest() private method

Creates subscription, adds items and verifies that the initial update arrives.
private DoCreateItemsTest ( ) : bool
return bool
        private bool DoCreateItemsTest()
        {
            // follow tree from each starting node.
            bool success = true;
                     
            double increment = MaxProgress/AvailableNodes.Count;
            double position  = 0;

            Log("Starting CreateItemsTest for {0} Nodes ({1}% Coverage). PipelineDepth = {2}, OutstandingRequests = {3}", AvailableNodes.Values.Count, Configuration.Coverage, m_publishPipelineDepth, m_outstandingPublishRequests);

            // create subscription.
            Interlocked.Exchange(ref m_publishCount, 0);
            Interlocked.Exchange(ref m_stopped, 0);

            m_errorEvent.Reset();

            if (!CreateSubscription(1000, 100, 10, 0, true, 0))
            {
                return false;
            }

            uint[] attributeIds = Attributes.GetIdentifiers();
            
            int nodes = 0;
            int operations = 0;
            
            MonitoredItemCreateRequestCollection itemsToCreate = new MonitoredItemCreateRequestCollection();

            int counter = 0;

            foreach (Node node in AvailableNodes.Values)
            {         
                if (!CheckCoverage(ref counter))
                {
                    continue;
                }
                         
                nodes++;

                AddMonitoredItems(node, itemsToCreate, attributeIds);

                // process batch.
                if (itemsToCreate.Count > BlockSize)
                {
                    operations += itemsToCreate.Count;

                    if (!Subscribe(m_subscriptions[0], itemsToCreate))
                    {
                        Log("WARNING: CreateItemsTest failed. Trying it again do check for random timing errors.");

                        if (!Subscribe(m_subscriptions[0], itemsToCreate))
                        {
                            success = false;
                            break;
                        }
                    }

                    itemsToCreate.Clear();

                    if (nodes > AvailableNodes.Count/5)
                    {
                        Log("Subscribed to {0} attribute values for {1} nodes.", operations, nodes);
                        nodes = 0;
                        operations = 0;
                    }
                }

                position += increment;
                ReportProgress(position);
            }   
         
            // process final batch.
            if (success)
            {
                if (itemsToCreate.Count > 0)
                {
                    operations += itemsToCreate.Count;

                    if (!Subscribe(m_subscriptions[0], itemsToCreate))
                    {
                        Log("WARNING: CreateItemsTest failed. Trying it again do check for random timing errors.");

                        if (!Subscribe(m_subscriptions[0], itemsToCreate))
                        {
                            success = false;
                        }
                    }

                    if (success)
                    {
                        Log("Subscribed to {0} attribute values for {1} nodes.", operations, nodes);
                    }
                }
            }

            // delete subscriptions.
            if (!DeleteSubscriptions())
            {
                success = false;
            }

            Interlocked.CompareExchange(ref m_stopped, 1, 0);
            Log("Deleted subscriptions.");

            lock (m_subscriptions)
            {
                m_subscriptions.Clear();
            }

            return success;
        }