예제 #1
0
        /// <summary>
        /// INTERNAL Deletes edges that terminate at a given node
        /// </summary>
        /// <param name="initNodeName">string:: the node name</param>
        /// <exception cref="AbandonedMutexException" >thrown when the mutex is null</exception>
        /// <exception cref="ApplicationException" >thrown when the edge cannot be removed from the EdgesCollection</exception>
        /// <exception cref="ArgumentNullException" >thrown when the node name is null</exception>
        /// <exception cref="InvalidOperationException" >thrown when EdgesCollection is uninitialized</exception>
        /// <exception cref="TimeoutException" >thrown when obtaining the mutex times out</exception>
        /* internal */ void INodeInternal.DeleteEdgesTerminatingOnNode(string initNodeName)
        {
            if (string.IsNullOrWhiteSpace(initNodeName))
            {
                throw new ArgumentNullException("initNodeName");
            }

            if (_mtxEdgesCollection == null)
            {
                string exceptionMsg = $"The edges on node {initNodeName} could not be iterated because the mutex has been abanoned.";
                throw new AbandonedMutexException(exceptionMsg);
            }

            CheckEdgesCollection();

            if (!_mtxEdgesCollection.WaitOne(_mtxTimeout))
            {
                // timed out waiting for the mutex
                string exceptionMsg = $"The edges on node {initNodeName} could not be iterated because a lock could not be obtained.";
                throw new TimeoutException(exceptionMsg);
            }

            try
            {
                string scrubbedNodeName = _stringUtility.ScrubName(initNodeName);
                // make a list of those to be removed
                List <string> nameList = new List <string>();
                foreach (string name in EdgesCollection.Keys)
                {
                    IEdge edgeComponent = EdgesCollection[name];
                    if (edgeComponent.IsTerminalNode(scrubbedNodeName))
                    {
                        nameList.Add(name);
                    }
                }

                // remove the nodes that were found
                foreach (string name in nameList)
                {
                    IEdge edgeComponent = null;
                    EdgesCollection.TryRemove(name, out edgeComponent);
                    if (edgeComponent != null)
                    {
                        edgeComponent.Dispose();
                    }
                }
            }
            finally
            {
                _mtxEdgesCollection.ReleaseMutex();
            }

            return;
        }
예제 #2
0
        /// <summary>
        /// INTERNAL deletes an edge
        /// </summary>
        /// <param name="initEdgeName">string:: the name of the edge</param>
        /// <exception cref="AbandonedMutexException" >thrown when the mutex is null</exception>
        /// <exception cref="ApplicationException" >thrown when the edge cannot be removed from EdgesCollection</exception>
        /// <exception cref="ArgumentNullException" >thrown when the edge name is null</exception>
        /// <exception cref="InvalidOperationException" >thrown when EdgesCollection is uninitialized</exception>
        /// <exception cref="TimeoutException" >thrown when obtaining the mutex times out</exception>
        /* internal */ void INodeInternal.DeleteEdge(string initEdgeName)
        {
            if (string.IsNullOrWhiteSpace(initEdgeName))
            {
                throw new ArgumentNullException("initEdgeName");
            }

            if (_mtxEdgesCollection == null)
            {
                string exceptionMsg = $"The edge {initEdgeName} could not be deleted because the mutex has been abanoned.";
                throw new AbandonedMutexException(exceptionMsg);
            }

            CheckEdgesCollection();

            if (!_mtxEdgesCollection.WaitOne(_mtxTimeout))
            {
                // timed out waiting for the mutex
                string exceptionMsg = $"The edge {initEdgeName} could not be deleted because a lock could not be obtained.";
                throw new TimeoutException(exceptionMsg);
            }

            try
            {
                string scrubbedEdgeName = _stringUtility.ScrubName(initEdgeName);
                if (!EdgesCollection.ContainsKey(scrubbedEdgeName))
                {
                    string exceptionText = $"Edge {scrubbedEdgeName} does not exist in EdgesCollection.";
                    throw new KeyNotFoundException(exceptionText);
                }

                IEdge component = null;
                if (EdgesCollection.TryRemove(scrubbedEdgeName, out component))
                {
                    if (component != null)
                    {
                        component.Dispose();
                    }
                }
                else
                {
                    string exceptionText = $"Edge {scrubbedEdgeName} could not be removed from node {Name} EdgesCollection.";
                    throw new ApplicationException(exceptionText);
                }
            }
            finally
            {
                _mtxEdgesCollection.ReleaseMutex();
            }

            return;
        }