DistributedFileSystem.DFS.PushItemToPeer C# (CSharp) Method

PushItemToPeer() public static method

Introduces a new item into the swarm and sends a build command to the originating requester
public static PushItemToPeer ( Connection peerConnection, DistributedItem itemToDistribute, string completedPacketType ) : void
peerConnection Connection The peer which requested the DFS item
itemToDistribute DistributedItem The item to be distributed
completedPacketType string The packet type to use once the item has been fully assembled
return void
        public static void PushItemToPeer(Connection peerConnection, DistributedItem itemToDistribute, string completedPacketType)
        {
            try
            {
                if (peerConnection.ConnectionInfo.ConnectionType != ConnectionType.TCP)
                    throw new Exception("Only able to push DFS item when the request is made via TCP.");


                if (itemToDistribute.ItemClosed)
                    throw new ArgumentException("Unable to push a closed item.");

                ItemAssemblyConfig assemblyConfig;
                lock (globalDFSLocker)
                {
                    //First double check to see if it's already in the swarm
                    if (!ItemAlreadyInLocalCache(itemToDistribute))
                        swarmedItemsDict.Add(itemToDistribute.Data.CompleteDataCheckSum, itemToDistribute);
                    else
                        itemToDistribute = swarmedItemsDict[itemToDistribute.Data.CompleteDataCheckSum];
                }

                itemToDistribute.IncrementPushCount();

                //We add the requester to the item swarm at this point
                itemToDistribute.SwarmChunkAvailability.AddOrUpdateCachedPeerChunkFlags(peerConnection.ConnectionInfo, new ChunkFlags(0));

                //There is a possibility when we create this assembly config that the peer has been removed again
                //We handle this on the peer end
                assemblyConfig = new ItemAssemblyConfig(itemToDistribute, completedPacketType);

                //Send the config information to the client that wanted the file
                peerConnection.SendObject("DFS_IncomingLocalItemBuild", assemblyConfig, nullCompressionSRO);

                if (DFS.loggingEnabled) DFS._DFSLogger.Debug("Pushed DFS item " + itemToDistribute.Data.CompleteDataCheckSum + " to peer " + peerConnection + ".");
            }
            catch (CommsException)
            {
                //LogTools.LogException(ex, "CommsError_AddItemToSwarm");
            }
            catch (Exception ex)
            {
                LogTools.LogException(ex, "Error_AddItemToSwarm");
            }

            //try { GC.Collect(); }
            //catch (Exception) { }
        }