Example #1
0
        /// <summary>
        /// 新しいNoteGroupを作成してlistが昇順を保つように挿入する。
        /// </summary>
        /// <param name="note">新しいPhotoChatNote</param>
        /// <param name="list">NoteGroupが昇順に格納されているLinkedList</param>
        private static void InsertInGroupList(PhotoChatNote note,
                                              LinkedList <NoteGroup> list)
        {
            try
            {
                // 後ろから挿入箇所を探す
                LinkedListNode <NoteGroup> node;
                for (node = list.Last; node != null; node = node.Previous)
                {
                    if (note.CompareTo(node.Value.First) > 0)
                    {
                        break;
                    }
                }

                // 挿入
                if (node == null)
                {
                    list.AddFirst(new NoteGroup(note));
                }
                else
                {
                    list.AddAfter(node, new NoteGroup(note));
                }
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
            }
        }
Example #2
0
        /// <summary>
        /// 書き込みファイルを読み込む。
        /// </summary>
        /// <param name="photoName">写真名</param>
        private void ReadNotesFile(string photoName)
        {
            try
            {
                string filePath = PhotoChatNote.GetNotesFilePath(photoName);
                using (StreamReader sr = new StreamReader(filePath))
                {
                    // プロパティの読み込み
                    string line = sr.ReadLine();
                    if (line == null || line != Properties)
                    {
                        throw new UnsupportedDataException("不正な書き込みファイル");
                    }
                    if ((line = sr.ReadLine()) != null)
                    {
                        InterpretDataString(line);
                    }

                    // 書き込みデータの読み込み
                    ReadNotes(sr);
                }
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
                throw new UnsupportedDataException(e.Message);
            }
        }
Example #3
0
 /// <summary>
 /// 書き込みをグループ化する。
 /// </summary>
 /// <param name="note">新しい書き込み</param>
 private void Grouping(PhotoChatNote note)
 {
     try
     {
         if (note.Type == PhotoChatNote.TypeStroke)
         {
             // ストロークの場合はグループ化できるものがないか調べる
             foreach (NoteGroup group in groupList)
             {
                 // 同じユーザ名の書き込みグループを調べる
                 if (!group.IsFixed && group.First.Author == note.Author)
                 {
                     if (group.AddNote(note))
                     {
                         return;
                     }
                     else
                     {
                         break;
                     }
                 }
             }
         }
         // グループ化できないものは新しい書き込みグループ
         InsertInGroupList(note, groupList);
     }
     catch (Exception e)
     {
         PhotoChat.WriteErrorLog(e.ToString());
     }
 }
Example #4
0
            /// <summary>
            /// 書き込みをグループに追加する。
            /// 追加すべきかの確認を行い、追加しない場合はグループを固定する。
            /// </summary>
            /// <param name="note">追加する書き込み</param>
            /// <returns>追加した場合はtrue</returns>
            public bool AddNote(PhotoChatNote note)
            {
                try
                {
                    // 前回の書き込みからの時間間隔を確認
                    long span = note.Date.Ticks - lastTime;
                    if (span > TimeSpan.TicksPerSecond * PhotoChat.GroupingSpan)
                    {
                        isFixed = true;
                        return(false);
                    }

                    // グループの書き込み領域との位置間隔を確認
                    int       space         = PhotoChat.GroupingSpace;
                    Rectangle inflatedRange = Rectangle.Inflate(range, space, space);
                    if (!inflatedRange.IntersectsWith(note.Range))
                    {
                        isFixed = true;
                        return(false);
                    }

                    // 書き込みをグループに追加
                    InsertInSortedList(note, myNoteList);
                    lastTime = note.Date.Ticks;
                    range    = Rectangle.Union(range, note.Range);
                    return(true);
                }
                catch (Exception e)
                {
                    PhotoChat.WriteErrorLog(e.ToString());
                    return(false);
                }
            }
Example #5
0
 /// <summary>
 /// 新着データ通知コマンドをコマンドを作成する。
 /// </summary>
 /// <param name="note">新着書き込みデータ</param>
 /// <param name="sourceID">コマンド発信元のID</param>
 /// <returns>新着データ通知コマンド</returns>
 public static Command CreateInformCommand(PhotoChatNote note, string sourceID)
 {
     try
     {
         return(new Command(TypeInform, note.SerialNumber,
                            DateTime.Now, note.ID, sourceID, note.Author, note.PhotoName));
     }
     catch (Exception e)
     {
         PhotoChat.WriteErrorLog(e.ToString());
         return(null);
     }
 }
Example #6
0
 /// <summary>
 /// イメージにnoteを描画して更新する。
 /// noteのデータ時刻が最新でなければレイヤーの順序がおかしくなる。
 /// またStrokeなどのグループ化を行う書き込みの場合は引数を取らないものを使う。
 /// </summary>
 /// <param name="note">描画する書き込み</param>
 private void UpdateImageBox(PhotoChatNote note)
 {
     try
     {
         lock (imageBox.Image)
         {
             using (Graphics g = Graphics.FromImage(imageBox.Image))
             {
                 note.Paint(g);
             }
         }
     }
     catch (Exception e)
     {
         PhotoChat.WriteErrorLog(e.ToString());
     }
 }
Example #7
0
            /// <summary>
            /// 新たな書き込みグループを作成する。
            /// </summary>
            /// <param name="note">最初の書き込み</param>
            public NoteGroup(PhotoChatNote note)
            {
                this.range      = note.Range;
                this.lastTime   = note.Date.Ticks;
                this.myNoteList = new LinkedList <PhotoChatNote>();
                myNoteList.AddFirst(note);

                // 書き込みがストローク以外であれば固定
                if (note.Type == PhotoChatNote.TypeStroke)
                {
                    isFixed = false;
                }
                else
                {
                    isFixed = true;
                }
            }
Example #8
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);
        }
Example #9
0
        private void imageBox_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                if (currentPhoto == null)
                {
                    return;
                }

                switch (reviewMode)
                {
                case ReviewModes.Review:
                    pressedLink = currentPhoto.GetPointedLink(e.Location);
                    if (pressedLink != null)
                    {
                        // リンク書き込み上で押された場合はリンク処理の準備
                        reviewMode = ReviewModes.Link;
                    }
                    else if (e.Button == MouseButtons.Left)
                    {
                        // 左ボタンの場合はストローク開始
                        StartStroke(e.Location);
                        reviewMode = ReviewModes.Stroke;
                    }
                    break;

                case ReviewModes.Remove:
                    // 削除開始
                    reviewMode = ReviewModes.Removing;
                    break;

                case ReviewModes.Replay:
                    // 再生中止
                    QuitReplay();
                    reviewMode = ReviewModes.Review;
                    break;
                }
            }
            catch (Exception ex)
            {
                PhotoChat.WriteErrorLog(ex.ToString());
            }
        }
Example #10
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());
     }
 }
Example #11
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());
            }
        }
Example #12
0
        /// <summary>
        /// 書き込みを削除する。
        /// </summary>
        /// <param name="note">削除する書き込み</param>
        private void RemoveNote(PhotoChatNote note)
        {
            try
            {
                if (note == null)
                {
                    return;
                }

                Removal removal = new Removal(
                    form.Client.UserName, form.Client.GetNewSerialNumber(),
                    note.PhotoName, note.ID, note.SerialNumber);
                form.NewData(removal);
                UpdateImageBox();
                imageBox.Invalidate();
                Update();
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
            }
        }
Example #13
0
        /// <summary>
        /// 写真より先に受信した書き込みデータがあれば読み込む。
        /// </summary>
        private void ReadEarlyNotes()
        {
            try
            {
                // 書き込みファイルが作成されていなければ何もしない
                string filePath = PhotoChatNote.GetNotesFilePath(photoName);
                if (!File.Exists(filePath))
                {
                    return;
                }

                // 先行した書き込みデータを読み込む
                using (StreamReader sr = new StreamReader(filePath))
                {
                    ReadNotes(sr);
                }
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
            }
        }
Example #14
0
        /// <summary>
        /// 書き込みリストへの追加
        /// </summary>
        /// <param name="note">追加する書き込みオブジェクト</param>
        public void AddNote(PhotoChatNote note)
        {
            try
            {
                if (note == null)
                {
                    return;
                }

                lock (noteList)
                {
                    // noteListへの追加
                    InsertInSortedList(note, noteList);
                }

                // 書き込みの種類に応じた処理
                switch (note.Type)
                {
                case PhotoChatNote.TypeRemoval:
                    Removal removal = (Removal)note;
                    RemoveNote(removal.TargetID, removal.TargetSerialNumber);
                    break;

                case PhotoChatNote.TypeTag:
                    AddTag((Tag)note);
                    break;

                default:
                    noteCount++;
                    Grouping(note);
                    break;
                }
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
            }
        }
Example #15
0
        /// <summary>
        /// 受信したPhotoChatNoteを処理する。
        /// </summary>
        /// <param name="note">受信したPhotoChatNote</param>
        private void Receive(PhotoChatNote note)
        {
            try
            {
                // 受信データの通し番号をNumberManagerに通知
                bool isLatest =
                    GetNumberManager(note.ID).PutReceivedNumber(note.SerialNumber);

                // 最新のデータかどうかも含めてclientにデータを渡し、
                // 新着データであれば接続中の端末にこのデータが必要かコマンドを送る
                if (client.NewData(note, isLatest))
                {
                    SendAll(Command.CreateInformCommand(note, client.ID));
                }

                // 書き込み受信ログ
                PhotoChat.WriteLog("Receive Note", note.Author + note.SerialNumber, note.PhotoName);
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
            }
        }
Example #16
0
        /// <summary>
        /// 書き込みファイルを作成する。
        /// </summary>
        private void CreateNotesFile()
        {
            try
            {
                string filePath = PhotoChatNote.GetNotesFilePath(photoName);
                using (StreamWriter sw = new StreamWriter(filePath))
                {
                    // プロパティの保存
                    sw.WriteLine(Properties);
                    sw.WriteLine(GetDataString());

                    // 書き込みデータの保存
                    foreach (PhotoChatNote note in noteList)
                    {
                        sw.WriteLine(note.GetSaveString());
                    }
                    sw.Flush();
                }
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
            }
        }