コード例 #1
0
 public void TestSetup()
 {
     _serverModificationMessage = null;
     _serverMessage = null;
 }
コード例 #2
0
 void server_MessageReceived(object sender, ObviousCode.Interlace.BitTunnelLibrary.Events.MessageEventArgs e)
 {
     _serverMessage = e.Message;
     if (_serverMessage is FileModificationMessage)
     {
         _serverModificationMessage = _serverMessage as FileModificationMessage;
     }
 }
コード例 #3
0
        //Send modifications where they appeared to have been valid
        //i.e Remove has fully removed all instances, or New where file is available on a client.
        //Functionality is, therefore, subtlety different for
        //
        //  * Remove (will be used in the message ONLY when all files are removed) and
        //  * New (will be added in the message whilst the uniquely hashed file is available each time an instance is added).
        //
        //As multiple of the same file (in different locations on the client) can be added at once,
        //it is not so easy to differentiate a 'first addition' of a file to only use those here as
        //
        //Currently up to clients as to whether to store the added files (with the limitToUniquelyHashedFilesOnly
        //flag on the FileDescriptorLookup).
        //
        //Sure I can come up with a nicer solution, but, until then, this is functionally accurate
        internal void BroadcastFileListModifications(List<FileModificationDescriptor> list)
        {
            if (ProtocolList.Count == 0) return;

            List<FileDescriptor> availableFiles = CurrentlyAvailableFiles as List<FileDescriptor>;

            using (FileModificationMessage message = new FileModificationMessage())
            {
                foreach(FileModificationDescriptor modification in list)
                {
                    bool available = availableFiles.Exists(f => f.Hash == modification.Hash);

                    if (
                        (modification.Mode == FileModificationMode.New && available) ||
                        (modification.Mode == FileModificationMode.Remove && !available) ||
                        (modification.Mode == FileModificationMode.Renamed)
                        )
                    {
                        ProtocolList[0].AddValueToMessage(message, modification);
                    }
                }

                Broadcast(message);
            }
        }
コード例 #4
0
        public void WhenFileModificationMessages_ModeRemoved_AreSentByClient_TheyShouldBeFullyReceivedByServer()
        {
            _serverMessage = null;

            FileDescriptor[] descriptors = null;

            string originId = "Not Set";

            using (ServerInstance server = new ServerInstance(_settings))
            {
                server.MessageReceived += new EventHandler<ObviousCode.Interlace.BitTunnelLibrary.Events.MessageEventArgs>(server_MessageReceived);

                server.Connect();

                while (!server.IsConnected) ;

                using (ClientInstance client = new ClientInstance(_settings))
                {
                    client.Connect();

                    originId = client.ConnectionDetails.InstanceId;

                    descriptors = new List<FileDescriptor>()
                    {
                        FileDescriptor.Create(_existingFile1, true),
                        FileDescriptor.Create(_existingFile2, true),
                        FileDescriptor.Create(_existingFile3, true)
                    }.ToArray();

                    _serverModificationMessage = null;

                    client.RemoveFiles(descriptors);

                    DateTime then = DateTime.Now;

                    while (_serverModificationMessage == null && (DateTime.Now - then).TotalSeconds < 1) ;

                    Assert.IsNotNull(_serverModificationMessage);

                    Assert.AreEqual(descriptors[0].FileFullName, _serverModificationMessage.Modifications[0].FileFullName);
                    Assert.AreEqual(descriptors[1].FileFullName, _serverModificationMessage.Modifications[1].FileFullName);
                    Assert.AreEqual(descriptors[2].FileFullName, _serverModificationMessage.Modifications[2].FileFullName);

                    //Assert.AreEqual(descriptors[0].FileId, _serverModificationMessage.Modifications[0].FileId);
                    //Assert.AreEqual(descriptors[1].FileId, _serverModificationMessage.Modifications[1].FileId);
                    //Assert.AreEqual(descriptors[2].FileId, _serverModificationMessage.Modifications[2].FileId);

                    Assert.AreEqual(originId, _serverModificationMessage.Modifications[0].OriginId);
                    Assert.AreEqual(originId, _serverModificationMessage.Modifications[1].OriginId);
                    Assert.AreEqual(originId, _serverModificationMessage.Modifications[2].OriginId);

                    Assert.AreEqual(FileModificationMode.Remove, _serverModificationMessage.Modifications[0].Mode);
                    Assert.AreEqual(FileModificationMode.Remove, _serverModificationMessage.Modifications[1].Mode);
                    Assert.AreEqual(FileModificationMode.Remove, _serverModificationMessage.Modifications[2].Mode);
                }
            }
        }
コード例 #5
0
        internal void SendFileListModifications(IList<FileModificationDescriptor> modifications)
        {
            using (FileModificationMessage message = new FileModificationMessage())
            {
                foreach (FileModificationDescriptor descriptor in modifications)
                {
                    ClientProtocol.AddValueToMessage(message, descriptor);
                }

                ClientProtocol.SendMessage(message);
            }
        }