Пример #1
0
        static void ServerEvent(object pObject)
        {
            if (pObject.GetType() == typeof(SocketEventArgs))
            {
                SocketEventArgs pSocketEvent = (SocketEventArgs)pObject;
                #region
                if (pSocketEvent.Link)
                {
                    Console.Write("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※");
                    Console.WriteLine("Client [{0}] Connected!", pSocketEvent.Connection.SocketEndPoint.Address.ToString());
                }
                else
                {
                    string        strProcParams = "SP_VERIFY_LOGOUT";
                    DbParameter[] paramCache    = DataUtilities.GetParameters(strProcParams);

                    if (paramCache == null)
                    {
                        paramCache = new SqlParameter[] {
                            new SqlParameter("@strSession", SqlDbType.VarChar, 50)
                        };
                        DataUtilities.SetParameters(strProcParams, paramCache);
                    }

                    paramCache[0].Value = pSocketEvent.Connection.Session;

                    MSSQLOperate pLogout = new MSSQLOperate(strAnalyse);
                    pLogout.Connect(false);
                    pLogout.ExecuteQuery(false, strProcParams, paramCache);
                    pLogout.GetResult(RecordStyle.NONE);

                    Console.WriteLine("Client [{0}, {1}] Disconnected!", pSocketEvent.Connection.SocketEndPoint.Address.ToString(), pSocketEvent.Connection.Session);

                    if (null != pSocketEvent.SocketException)
                    {
                        Console.WriteLine("Socket Exception : {0}", pSocketEvent.SocketException.Message);
                    }

                    Console.Write("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※");
                }
                #endregion
                ((SocketEventArgs)pObject).Connection.OnRecive();
            }
            else if (pObject.GetType() == typeof(MessageEventArgs))
            {
                DateTime tStartTime = DateTime.Now;

                TaskParser pTaskParser = new TaskParser(pNotesSession, (MessageEventArgs)pObject, strAnalyse, strOnline, strAccess);

                if (!pTaskParser.Parser())
                {
                    Console.WriteLine(pTaskParser.Error);
                }

                pTaskParser.Dispose();

                #region 发送/保存消息

                /*TaskService pMessageID = pTaskParser.SocketMessage;
                 *
                 * MSSQLOperate pMessageADO = new MSSQLOperate(strMessage);
                 *
                 * if (pMessageADO.Connect(false))
                 * {
                 *  string strProcParams = "SP_SEND_INSTANTMESSAGE";
                 *  DbParameter[] paramCache = DataUtilities.GetParameters(strProcParams);
                 *
                 *  if (paramCache == null)
                 *  {
                 *      paramCache = new SqlParameter[]{
                 *                                 new SqlParameter("@strCommand",SqlDbType.VarChar, 50),
                 *                                 new SqlParameter("@strSession",SqlDbType.VarChar, 50)
                 *                             };
                 *      DataUtilities.SetParameters(strProcParams, paramCache);
                 *  }
                 *
                 *  paramCache[0].Value = pMessageID.ToString();
                 *  paramCache[1].Value = ((MessageEventArgs)pObject).Connection.Session;
                 *
                 *  pMessageADO.ExecuteQuery(false, strProcParams, paramCache);
                 *  pMessageADO.GetResult(RecordStyle.DATASET);
                 *  DataSet pMessageData = (DataSet)pMessageADO.RecordData;
                 *
                 *  if (pMessageADO.AffectRow > 0)
                 *  {
                 *      for (int i = 0; i < pMessageData.Tables[0].Rows.Count; i++)
                 *      {
                 *          if (pMessageData.Tables[0].Rows[i][1].ToString() != "")
                 *          {
                 *              //离线消息
                 *              if (pMessageData.Tables[0].Rows[i][3].ToString() == "N/A")
                 *              {
                 *                  string strInput = @"INSERT INTO Message_Content(Content_Message, Content_Sender, Content_Recive, Content_Desc)
                 *                      VALUES(" + pMessageData.Tables[0].Rows[i][0].ToString() + "," + pMessageData.Tables[0].Rows[i][1].ToString()
                 + "," + pMessageData.Tables[0].Rows[i][2].ToString();
                 +
                 +                  pMessageADO.ExecuteQuery(strInput);
                 +                  pMessageADO.GetResult(RecordStyle.NONE);
                 +              }
                 +              //及时消息
                 +              else
                 +              {
                 +                  CustomDataCollection mSendContent = new CustomDataCollection(StructType.CUSTOMDATA);
                 +
                 +                  mSendContent.Add("用户:" + pMessageData.Tables[0].Rows[i][4].ToString() + "触发了命令:" + pMessageData.Tables[0].Rows[i][5].ToString() + "内容为:");
                 +
                 +                  SocketPacket pSourcePacket = new SocketPacket(pMessageID, mSendContent);
                 +                  byte[] pSendBuffer = pSourcePacket.CoalitionInfo();
                 +
                 +                  //byte[] pSendBuffer = mSocketDate.setSocketData(CEnum.ServiceKey.INSTANT_CONTENT_RECIVE, CEnum.Msg_Category.INSTANT, mSendContent).bMsgBuffer;
                 +
                 +                  //((MessageEventArgs)pObject).SocketConnection.OnSend(pMessageData.Tables[0].Rows[i][3].ToString(), pSendBuffer);
                 +              }
                 +          }
                 +      }
                 +  }
                 +  pMessageADO.DisConnected();
                 + }
                 + else
                 + {
                 +  Console.ForegroundColor = ConsoleColor.Red;
                 +  Console.WriteLine(String.Format("      DB Connect Error!"));
                 +  Console.ForegroundColor = ConsoleColor.Gray;
                 +  Console.WriteLine();
                 + }*/
                #endregion

                ((MessageEventArgs)pObject).Connection.OnRecive();

                //Print Message
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(String.Format("      Total Times : {0}", DateTime.Now.Subtract(tStartTime)));
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine();
            }
        }