Example #1
0
        /// <summary>
        /// perform the operation associated with this call
        /// </summary>
        /// <param name="initEdgeName">string:: the name of the edge</param>
        /// <exception cref="AbandonedMutexException" >thrown when the mutex is null</exception>
        /// <exception cref="InvalidOperationException" >thrown when EdgesCollection is uninitialized</exception>
        /// <exception cref="KeyNotFoundException" >thrown when the edge name does not exist.</exception>
        /// <exception cref="NullReferenceException" >thrown when the edge State is null</exception>
        /// <exception cref="TimeoutException" >thrown when obtaining the mutex times out</exception>
        public void TraverseEdgeReverse(string initEdgeName)
        {
            if (_mtxEdgesCollection == null)
            {
                string exceptionMsg = $"The edge {initEdgeName} could not be retrieved 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 retrieved because a lock could not be obtained.";
                throw new TimeoutException(exceptionMsg);
            }

            try
            {
                string scrubbedEdgeName = _stringUtility.ScrubName(initEdgeName);
                if (!EdgesCollection.ContainsKey(scrubbedEdgeName))
                {
                    throw new KeyNotFoundException($"Edge {scrubbedEdgeName} not found on Node {Name}.");
                }

                IEdge foundEdge = EdgesCollection[scrubbedEdgeName];
                foundEdge.Reverse(this);
            }
            finally
            {
                _mtxEdgesCollection.ReleaseMutex();
            }
        }
Example #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;
        }
Example #3
0
        /// <summary>
        /// accessor for the State of an edge
        /// </summary>
        /// <param name="initEdgeName">string:: edge name</param>
        /// <returns>object:: the State of an edge</returns>
        /// <exception cref="AbandonedMutexException" >thrown when the mutex is null</exception>
        /// <exception cref="ArgumentNullException" >thrown when the edge name parameter is null</exception>
        /// <exception cref="InvalidOperationException" >thrown when EdgesCollection is uninitialized</exception>
        /// <exception cref="KeyNotFoundException" >thrown when the edge name does not exist</exception>
        /// <exception cref="NullReferenceException" >thrown when the value in EdgesCollection is null</exception>
        /// <exception cref="TimeoutException" >thrown when obtaining the mutex times out</exception>
        public object GetEdgeState(string initEdgeName)
        {
            Object returnObject = null;

            if (string.IsNullOrWhiteSpace(initEdgeName))
            {
                throw new ArgumentNullException("initEdgeName");
            }

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

            CheckEdgesCollection();

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

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

                IEdge edgeComponent = EdgesCollection[scrubbedEdgeName];
                if (edgeComponent == null)
                {
                    string exceptionText = $"The edge {scrubbedEdgeName} on node {Name} is null.";
                    throw new NullReferenceException(exceptionText);
                }

                returnObject = edgeComponent.GetState();
            }
            finally
            {
                _mtxEdgesCollection.ReleaseMutex();
            }

            return(returnObject);
        }
Example #4
0
        /// <summary>
        /// INTERNAL Create an edge with specific initialization of edge state
        /// </summary>
        /// <typeparam name="TEdge">The type of edge state. constraints - where TEdge : class, IEdgeState, IDisposable, new()</typeparam>
        /// <param name="initName">string:: name of the edge</param>
        /// <param name="initState">TEdge:: the initial State</param>
        /// <param name="initTerminalNode">INode:: the terminal node</param>
        /// <param name="initIsDirected">bool:: if true, it is directed, otherwise it is bidirectional</param>
        /// <returns>IEdge:: the created edge</returns>
        /// <exception cref="AbandonedMutexException" >thrown when the mutex is null</exception>
        /// <exception cref="ApplicationException" >thrown when the Edge cannot be added to EdgesCollection</exception>
        /// <exception cref="ArgumentException" >thrown when the edge name already exists</exception>
        /// <exception cref="InvalidOperationException" >thrown when the Edges Collection is uninitialized</exception>
        /// <exception cref="TimeoutException" >thrown when obtaining the mutex times out</exception>
        /* internal */ IEdge INodeInternal.CreateEdge <TEdge>(string initName, TEdge initState, INode initTerminalNode, bool initIsDirected) /* where TEdge : class, IDisposable, new() */
        {
            IEdge returnValue = null;

            if (_mtxEdgesCollection == null)
            {
                string exceptionMsg = $"The edge {initName} could not be created 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 {initName} could not be created because a lock could not be obtained.";
                throw new TimeoutException(exceptionMsg);
            }

            try
            {
                string scrubbedName = _stringUtility.ScrubName(initName);
                if (EdgesCollection.ContainsKey(scrubbedName))
                {
                    string exceptionText = $"The edge {scrubbedName} already exists";
                    throw new ArgumentException(exceptionText);
                }

                returnValue = new Edge <TEdge>(scrubbedName, initState, initTerminalNode, initIsDirected);
                if (!EdgesCollection.TryAdd(scrubbedName, returnValue))
                {
                    string exceptionText = $"Edge {scrubbedName} could not be added to node {Name} EdgesCollection.";
                    throw new ApplicationException(exceptionText);
                }
            }
            finally
            {
                _mtxEdgesCollection.ReleaseMutex();
            }

            return(returnValue);
        }