DistributedFileSystem.DFS.DFSConnectionShutdown C# (CSharp) Method

DFSConnectionShutdown() private static method

If a connection is disconnected we want to make sure we handle it within the DFS
private static DFSConnectionShutdown ( Connection connection ) : void
connection Connection
return void
        private static void DFSConnectionShutdown(Connection connection)
        {
            try
            {
                //We can only rely on the network identifier if this is a TCP connection shutting down
                if (connection.ConnectionInfo.ConnectionType == ConnectionType.TCP && connection.ConnectionInfo.NetworkIdentifier != ShortGuid.Empty)
                {
                    List<DistributedItem> allItems;
                    lock (globalDFSLocker)
                        allItems = swarmedItemsDict.Values.ToList();

                    //Remove peer from any items
                    foreach (var item in allItems)
                        item.SwarmChunkAvailability.RemovePeerIPEndPointFromSwarm(connection.ConnectionInfo.NetworkIdentifier, (IPEndPoint)connection.ConnectionInfo.RemoteEndPoint);

                    //Remove any outstanding chunk requests for this peer
                    lock (chunkDataCacheLocker)
                        chunkDataCache.Remove(connection.ConnectionInfo.NetworkIdentifier);

                    if (loggingEnabled) DFS._DFSLogger.Debug("DFSConnectionShutdown Global - Removed peer from all items - " + connection + ".");
                }
                else
                    if (loggingEnabled) DFS._DFSLogger.Trace("DFSConnectionShutdown Global - Disconnection ignored - " + connection + ".");
            }
            catch (CommsException e)
            {
                LogTools.LogException(e, "CommsError_DFSConnectionShutdown");
            }
            catch (Exception e)
            {
                LogTools.LogException(e, "Error_DFSConnectionShutdown");
            }
        }