Exemple #1
0
        /// <summary>
        /// 通信部を初期化する。
        /// </summary>
        /// <param name="client">PhotoChatClientインスタンス</param>
        public ConnectionManager(PhotoChatClient client)
        {
            this.client = client;

            udpConnection = new UdpConnection(
                new UdpConnection.ReceiveSignalDelegate(ReceiveSignal),
                new UdpConnection.SendIPListDeligate(SendIPList),
                new UdpConnection.ADDIPListDeligate(AddIPList));

            //#acceptCallback = new AsyncCallback(AcceptCallback);

            tcpListener = new TcpListener(IPAddress.Any, PhotoChat.TcpPort);


            receiveThread = new Thread(new ThreadStart(ProcessReceivedData));
            receiveThread.IsBackground = true;

            ipDictionary = new Dictionary <string, string>();
            addIPDictionary(PhotoChatClient.MyIPAddress, client.ID);

            tcpConnectionDictionary  = new Dictionary <string, TcpConnection>();
            numberDictionary         = new Dictionary <string, NumberManager>();
            lastSelectTimeDictionary = new Dictionary <string, DateTime>();


            receiveQueue      = new Queue <ISendable>();
            receiveWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
            isAlive           = true;
            connectionThread  = new Thread(new ThreadStart(connect));
            connectionThread.Start();
        }
Exemple #2
0
        static void Main()
        {
            try
            {
                // 多重起動を防ぐ
                bool createdNew;
                mutex = new Mutex(true, "PhotoChatMutex", out createdNew);
                if (!createdNew)
                {
                    MessageBox.Show("PhotoChatはすでに起動しています。");
                    return;
                }

                // データ保存ディレクトリの作成
                CreateDirectories();

                // 起動する
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Thread.CurrentThread.Priority = ThreadPriority.Highest;
                PhotoChatClient client = PhotoChatClient.CreateInstance();
                Application.Run(client.Form);

                // 終了前にMutexを解放
                mutex.ReleaseMutex();
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
                Application.Exit();
            }
        }
        /// <summary>
        /// 指定したタグの付いたサムネイルの一覧を表示する。
        /// </summary>
        /// <param name="tag">タグ文字列</param>
        /// <param name="itemWidth">項目の幅</param>
        /// <param name="itemHeight">項目の高さ</param>
        public void SetPhotoList(string tag, int itemWidth, int itemHeight)
        {
            try
            {
                // サムネイルリスト作成
                //string[] photoArray = PhotoChatClient.SearchTaggedPhoto(tag);
                string[] photoArray = PhotoChatClient.SearchTaggedPhoto(
                    new string[] { tag, form.Client.CurrentSessionName }, true);
                List <Thumbnail> thumbnailList = new List <Thumbnail>(photoArray.Length);
                foreach (string photoName in photoArray)
                {
                    Thumbnail thumbnail = form.GetThumbnail(photoName);
                    if (thumbnail != null)
                    {
                        thumbnailList.Add(thumbnail);
                    }
                }
                thumbnailList.Sort();

                // 一覧への挿入
                photoListBox.BeginUpdate();
                selectedIndex = -1;
                if (selectedImage != null)
                {
                    selectedImage.Dispose();
                    selectedImage = null;
                }
                ShowUp();
                photoListBox.Items.Clear();
                this.Text = "タグ: " + tag;
                photoListBox.Focus();
                foreach (Thumbnail thumbnail in thumbnailList)
                {
                    photoListBox.Items.Add(thumbnail);
                }
                photoListBox.ColumnWidth = itemWidth;
                photoListBox.ItemHeight  = itemHeight;
                photoListBox.EndUpdate();

                // 現在のセッションで使用されたタグ一覧の作成
                SetTagPanel();
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
            }
        }
Exemple #4
0
        /// <summary>
        /// 通信を開始する。
        /// </summary>
        /// <param name="client">PhotoChatClientインスタンス</param>
        public void Start(PhotoChatClient client)
        {
            try
            {
                this.client = client;

                //ネットワーク上のホスト探索のためにメッセージを送る
                Broadcast("JOIN" + PhotoChat.Delimiter + client.ID);

                // 受信開始
                receiveClient.BeginReceive(receiveCallback, null);

                requireSessionThread = new Thread(new ThreadStart(requireSession));
                requireSessionThread.Start();
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
            }
        }
        private void ServerUpload()
        {
            try
            {
                // 進行状況表示ウィンドウ
                int count = 0;
                foreach (Control control in uploadPanel.Controls)
                {
                    if (((UploadSessionPanel)control).DoUpload)
                    {
                        count++;
                    }
                }
                ProgressWindow progressWindow = new ProgressWindow(
                    count, "PhotoChatサーバにアップロードしています");
                count = 0;
                progressWindow.Show(this);

                // サーバにログイン
                PhotoChatClient  client = PhotoChatClient.Instance;
                Command          command;
                ServerConnection connection = new ServerConnection();
                if (connection.IsConnecting)
                {
                    connection.Send(Command.CreateLoginCommand(
                                        client.ID, mailTextBox.Text, passwordTextBox.Text, client.UserName));
                    command = connection.Receive();
                    if (command == null || !bool.Parse(command.UserName))
                    {
                        MessageBox.Show("メールアドレスまたはパスワードが間違っています");
                        connection.Close();
                        progressWindow.Dispose();
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("PhotoChatサーバに接続できませんでした");
                    connection.Close();
                    progressWindow.Dispose();
                    return;
                }

                // セッションごとにアップロード
                foreach (Control control in uploadPanel.Controls)
                {
                    UploadSessionPanel panel = (UploadSessionPanel)control;
                    if (panel.DoUpload)
                    {
                        // セッションデータのアップロード開始
                        SessionManager.SessionInfo info = panel.SessionInfo;
                        connection.Send(Command.CreateSessionCommand(
                                            client.ID, info.ID, info.Name, panel.IsPublic));
                        command = connection.Receive();
                        if (command != null && command.Type == Command.TypeSession)
                        {
                            // 端末ごとのデータをアップロード
                            foreach (string directory in Directory.GetDirectories(PhotoChat.UserIndexDirectory))
                            {
                                string filePath = Path.Combine(directory, info.ID + ".dat");
                                if (File.Exists(filePath))
                                {
                                    UploadIndexData(connection, filePath);
                                }
                            }
                            // セッションデータのアップロード完了
                            uploadedSessionList.Add(info);
                        }
                        progressWindow.SetCount(++count);
                    }
                }
                // アップロード終了
                connection.Send(Command.CreateDisconnectCommand(client.ID, client.ID));
                command = connection.Receive();
                if (command != null && command.Type == Command.TypeDisconnect)
                {
                    uploadComplete = true;
                }

                // アカウント情報保存
                if (savePasswordCheckBox.Checked)
                {
                    SaveAccount();
                }

                progressWindow.Dispose();
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception e)
            {
                PhotoChat.WriteErrorLog(e.ToString());
            }
        }