private void Instance_OnReceiveData(SocketManager.SocketClient sender, byte[] e)
 {
     if (e[0] == 1)
     {
         var data = FileCommunicationObject.ByteArrayToFile(e);
         if (data != null && data.ChatNum == this.ChatNum)
         {
             App.Current.Dispatcher.Invoke(new Action(() =>
             {
                 this.FileList.Add(data);
                 this.Messages.Add(data.Sender + " 님이 파일을 전송했습니다.");
             }));
         }
     }
     else
     {
         var data = CommunicationObject.Parse(Encoding.UTF8.GetString(e)) as ChatMessage;
         if (data != null && data.ChatNum == this.ChatNum)
         {
             Application.Current.Dispatcher.Invoke(new Action(() =>
             {
                 this.Messages.Add(data.Sender.UserID + " : " + data.Message);
             }));
         }
         var receiveData2 = FriendsCollection.Parse(Encoding.UTF8.GetString(e)) as FriendsCollection;
         if (receiveData2 != null)
         {
             this.Friends = receiveData2.Friends;
         }
     }
 }
        private void Instance_OnReceiveData(SocketManager.SocketClient sender, byte[] e)
        {
            if (e[0] != 1)
            {
                var data = CloudFilesCollection.Parse(Encoding.UTF8.GetString(e)) as CloudFilesCollection;
                if (data != null)
                {
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        this.FileList = data.Files;
                    }));
                }
            }
            else
            {
                int splitIdx = 0;
                int idx      = 0;
                for (int i = 1; i < e.Length; i++)
                {
                    if (e[i] == Encoding.UTF8.GetBytes("|")[0])
                    {
                        splitIdx = i;
                        break;
                    }
                }
                byte[] fileName = new byte[splitIdx];
                byte[] file     = new byte[e.Length - splitIdx];
                idx = 0;
                for (int i = 1; i < splitIdx; i++)
                {
                    fileName[idx++] = e[i];
                }
                idx = 0;
                for (int i = splitIdx + 1; i < e.Length; i++)
                {
                    file[idx++] = e[i];
                }
                string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
                              + "\\Little Cloud Download";

                bool exists = System.IO.Directory.Exists(path);

                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                System.IO.File.WriteAllBytes(path + "\\" + Encoding.UTF8.GetString(fileName, 0, fileName.Length - 1), file);
            }
        }
 private void Instance_OnReceiveData(SocketManager.SocketClient sender, byte[] data)
 {
     if (data[0] != 1)
     {
         var receiveData = ChatInfo.Parse(Encoding.UTF8.GetString(data)) as ChatInfo;
         if (receiveData != null)
         {
             if (this.OnChatStart != null)
             {
                 this.OnChatStart(this, receiveData);
             }
             return;
         }
         var receiveData2 = FriendsCollection.Parse(Encoding.UTF8.GetString(data)) as FriendsCollection;
         if (receiveData2 != null)
         {
             this.Friends = receiveData2.Friends;
         }
     }
 }
Exemple #4
0
 private void SocketClient_OnReceiveData(SocketManager.SocketClient sender, byte[] data)
 {
     if (data[0] != 1)
     {
         var message = CommunicationObject.Parse(Encoding.UTF8.GetString(data)) as SystemMessage;
         if (message.Message == "Success")
         {
             Client.Instance.Member         = this.Member;
             this.LoginResult               = "OK";
             Client.Instance.OnReceiveData -= SocketClient_OnReceiveData;
         }
         else if (message.Message == "Already Logined")
         {
             this.LoginResult = "Already Logined";
         }
         else
         {
             this.LoginResult = new string("Fail".ToCharArray());
         }
     }
 }