Пример #1
0
        internal void SendInfo(SyncFileMessageType type, object data)
        {
            var sfm = new SyncFileMessage();

            sfm.Type    = type;
            sfm.TaskID  = Task.ID;
            sfm.OwnerID = OwnerID;
            sfm.MessageRoot.Connection = Task.TargetUser.DefaultConnection;
            sfm.MessageRoot.Connector  = Task.TargetUser.DefaultConnector;
            sfm.MessageRoot.RemoteId   = Task.TargetUser.Id;
            if (data != null)
            {
                if (data is Message)
                {
                    sfm.ClientData.SetMessage(data as Message);
                }
                else if (data is ILoadSaveAble)
                {
                    sfm.ClientData.SetLoadSaveAble(data as ILoadSaveAble);
                }
                else if (data is byte[])
                {
                    sfm.ClientData.SetBinary(data as byte[]);
                }
                else
                {
                    sfm.ClientData.SetSerializeAble(data);
                }
            }
            var pm = new PrimaryMessage();

            pm.MessageType = PrimaryMessageType.SyncFile;
            pm.ClientData.SetMessage(sfm);
            Manager.Manager.SendMessage(pm);
        }
Пример #2
0
 internal void MessageReceived(SyncFileMessage message)
 {
     if (message.Type == SyncFileMessageType.Connect)
     {
         var d  = message.ClientData.GetSerializeAble <SyncFileData>();
         var sf = new SyncFile();
         sf.Task            = new FileTransportTask();
         sf.Task.ID         = message.TaskID;
         sf.Task.Size       = d.Size;
         sf.Manager         = this;
         sf.SendData        = false;
         sf.AccessID        = d.AccessID;
         sf.OwnerID         = message.OwnerID;
         sf.Task.TargetUser = Manager.Users.GetUserFromId(message.MessageRoot.RemoteId);
         Files.Add(sf);
         sf.SendInfo(SyncFileMessageType.ConnectionSuccess, null);
         if (SyncFileAdded != null)
         {
             SyncFileAdded(this, sf);
         }
     }
     else
     {
         var file = Files.Find((sf) =>
         {
             if (message.TaskID != sf.Task.ID)
             {
                 return(false);
             }
             if (message.OwnerID.Length != sf.OwnerID.Length)
             {
                 return(false);
             }
             for (int i = 0; i < message.OwnerID.Length; ++i)
             {
                 if (message.OwnerID[i] != sf.OwnerID[i])
                 {
                     return(false);
                 }
             }
             return(true);
         });
         if (message.Type == SyncFileMessageType.ConnectionSuccess)
         {
             FileTransport.StartTask(file.Task);
         }
     }
 }
Пример #3
0
 internal void ReceiveData(SyncFileMessage message)
 {
 }