예제 #1
0
        /// <summary>
        /// 受信データをインスタンス化する。
        /// 端末時間差からデータ時刻の修正も行う。
        ///  </summary>
        /// <param name="type">データのタイプ</param>
        /// <param name="data">データのバイト列</param>
        /// <returns>作成したインスタンス。作成できなかったときはnull</returns>
        private ISendable CreateInstance(int type, byte[] data)
        {
            try
            {
                // データタイプに応じてインスタンス化(データ時刻修正)
                switch (type)
                {
                case PhotoChatImage.TypePhoto:
                    PhotoChatImage image = PhotoChatImage.CreateInstance(type, data);
                    if (image != null)
                    {
                        image.Date = image.Date.AddTicks(-timeDifference);
                    }
                    return(image);

                case PhotoChatNote.TypeHyperlink:
                case PhotoChatNote.TypeRemoval:
                case PhotoChatNote.TypeStroke:
                case PhotoChatNote.TypeTag:
                case PhotoChatNote.TypeText:
                case PhotoChatNote.TypeSound:
                    PhotoChatNote note = PhotoChatNote.CreateInstance(type, data);
                    if (note != null)
                    {
                        note.Date = note.Date.AddTicks(-timeDifference);
                    }
                    return(note);

                case Command.TypeRequest:
                case Command.TypeInform:
                case Command.TypeTransfer:
                case Command.TypeSelect:
                case Command.TypeConnect:
                case Command.TypeDisconnect:
                    return(new Command(type, data));

                case SharedFile.TypeSoundFile:
                    return(new SharedFile(type, data));
                }
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
            }
            return(null);
        }
예제 #2
0
 /// <summary>
 /// 書き込みデータを読み込む
 /// </summary>
 /// <param name="sr"></param>
 private void ReadNotes(StreamReader sr)
 {
     try
     {
         string line, dataString;
         int    type, index;
         while ((line = sr.ReadLine()) != null)
         {
             index      = line.IndexOf(PhotoChat.Delimiter);
             type       = int.Parse(line.Substring(0, index));
             dataString = line.Substring(index + 1);
             AddNote(PhotoChatNote.CreateInstance(type, dataString));
         }
     }
     catch (Exception e)
     {
         PhotoChat.WriteErrorLog(e.ToString());
     }
 }
예제 #3
0
        /// <summary>
        /// ユーザIndexファイルのデータをアップロードする。
        /// </summary>
        /// <param name="connection">サーバ接続</param>
        /// <param name="filePath">ファイルパス</param>
        private void UploadIndexData(ServerConnection connection, string filePath)
        {
            try
            {
                using (StreamReader sr = new StreamReader(filePath))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        try
                        {
                            int index1 = line.IndexOf(PhotoChat.Delimiter) + 1;
                            int index2 = line.IndexOf(PhotoChat.Delimiter, index1);
                            int type   = int.Parse(line.Substring(index1, index2 - index1));
                            switch (type)
                            {
                            case PhotoChatImage.TypePhoto:
                                connection.Send(new Photo(line.Substring(index2 + 1)));
                                break;

                            case PhotoChatNote.TypeHyperlink:
                            case PhotoChatNote.TypeRemoval:
                            case PhotoChatNote.TypeStroke:
                            case PhotoChatNote.TypeTag:
                            case PhotoChatNote.TypeText:
                                connection.Send(PhotoChatNote.CreateInstance(
                                                    type, line.Substring(index2 + 1)));
                                break;
                            }
                        }
                        catch (UnsupportedDataException) { }
                    }
                }
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
            }
        }