private void DisconnectToIMService(Boolean requireIMReconnect) { if (_twitterIm != null) { //SendTwitterGatewayServerMessage("インスタントメッセージングサービスから切断します。"); _requireIMReconnect = requireIMReconnect; _twitterIm.Close(); _twitterIm = null; } }
private void DisconnectToIMService(Boolean requireIMReconnect) { if (_twitterIm != null) { //SendTwitterGatewayServerMessage("インスタントメッセージングサービスから切断します。"); _requireIMReconnect = requireIMReconnect; _twitterIm.Close(); _twitterIm = null; } }
private void ConnectToIMService(Boolean initialConnect) { DisconnectToIMService(!initialConnect); SendTwitterGatewayServerMessage(String.Format("インスタントメッセージングサービス \"{0}\" (サーバ: {1}) にユーザ \"{2}\" でログインします。", _config.IMServerName, _config.IMServiceServerName, _config.IMUserName)); _twitterIm = new TwitterIMService(_config.IMServiceServerName, _config.IMServerName, _config.IMUserName, _config.GetIMPassword(_password)); _twitterIm.StatusUpdateReceived += new EventHandler <TwitterIMService.StatusUpdateReceivedEventArgs>(twitterIm_StatusUpdateReceived); _twitterIm.Logined += new EventHandler(twitterIm_Logined); _twitterIm.AuthErrored += new EventHandler(twitterIm_AuthErrored); _twitterIm.SocketErrorHandled += new EventHandler <TwitterIMService.ErrorEventArgs>(twitterIm_SocketErrorHandled); _twitterIm.Closed += new EventHandler(twitterIm_Closed); _twitterIm.Open(); if (initialConnect) { _requireIMReconnect = true; _imReconnectCount = 0; } }
private void ConnectToIMService(Boolean initialConnect) { DisconnectToIMService(!initialConnect); SendTwitterGatewayServerMessage(String.Format("インスタントメッセージングサービス \"{0}\" (サーバ: {1}) にユーザ \"{2}\" でログインします。", _config.IMServerName, _config.IMServiceServerName, _config.IMUserName)); _twitterIm = new TwitterIMService(_config.IMServiceServerName, _config.IMServerName, _config.IMUserName, _config.GetIMPassword(_password)); _twitterIm.StatusUpdateReceived += new EventHandler<TwitterIMService.StatusUpdateReceivedEventArgs>(twitterIm_StatusUpdateReceived); _twitterIm.Logined += new EventHandler(twitterIm_Logined); _twitterIm.AuthErrored += new EventHandler(twitterIm_AuthErrored); _twitterIm.SocketErrorHandled += new EventHandler<TwitterIMService.ErrorEventArgs>(twitterIm_SocketErrorHandled); _twitterIm.Closed += new EventHandler(twitterIm_Closed); _twitterIm.Open(); if (initialConnect) { _requireIMReconnect = true; _imReconnectCount = 0; } }
void twitterIm_SocketErrorHandled(object sender, TwitterIMService.ErrorEventArgs e) { if (_requireIMReconnect && _imReconnectCount++ < 10) { SendTwitterGatewayServerMessage(String.Format("インスタントメッセージングサービスの接続でエラーが発生しました: {0} / 再接続します。({1}回目)", e.Exception.Message, _imReconnectCount)); ConnectToIMService(false); } else { SendTwitterGatewayServerMessage("インスタントメッセージングサービスの接続でエラーが発生しました: " + e.Exception.Message); } }
void twitterIm_StatusUpdateReceived(object sender, TwitterIMService.StatusUpdateReceivedEventArgs e) { _isFirstTime = false; // IMが先にきてしまったらあきらめる _twitter.ProcessStatus(e.Status, (s) => { Boolean friendsCheckRequired = false; ProcessTimelineStatus(e.Status, ref friendsCheckRequired); }); }