示例#1
0
 public ServerThread(ref ServerNewConnInfo info, ref DataServer server, ref CPU_Timer cpuTimer, ref ConnectionMonitor con, ref StreamWriter stream, int max_packet_size, ref CtrlStation ctrl, ref CustomRecept recept, ref Translator translator, ref ArrayList lstClients)
 {
     this.i_ConnInfo        = info;
     this.i_DataServer      = server;
     this.i_monCpu          = cpuTimer;
     this.i_monConnections  = con;
     this.i_ctrl            = ctrl;
     this.m_max_packet_size = max_packet_size;
     this.logStream         = stream;
     this.var_recept        = recept;
     this.var_translator    = translator;
     this.var_lstClients    = lstClients;
     this.StandByTimer      = DateTime.Now;
 }
示例#2
0
        public void ReceiveAndProcessData(ref Translator var_Translator, ref CustomRecept recept, string buffer, int iPid, string session, ref bool IsHandled, ref bool IsTerm)
        {
            this.i_monDataLoad.NewInputData(buffer.Length);
            Transaction trans = new Transaction();

            trans.var_iPid       = iPid;
            trans.var_Translator = var_Translator;
            trans.var_disp       = this.i_Disp;
            trans.SetSessionKey(session);
            trans.SetCommunication(ref this.i_Comm);
            trans.SetLogAccess(ref this.logStream);
            trans.SetAccess(ref this.dbAccess);
            this.i_Disp.var_Translator = var_Translator;
            try
            {
                IsHandled = recept.ProcessRequest(buffer, ref trans, ref IsTerm);
            }
            catch (Exception ex)
            {
                this.logStream.WriteLine(ex.ToString());
                return;
            }
            if (IsTerm)
            {
                this.logStream.WriteLine(new StringBuilder().Append("DataServer  ").Append(this.GetCurrentTime()).Append(" Requested termination").ToString());
                this.bDisconnected = true;
            }
            else
            {
                if (IsHandled)
                {
                    return;
                }
                if (buffer.StartsWith("SYCRAF"))
                {
                    this.i_Comm.Clear();
                    this.i_Comm.ImportCommunicationBuffer(buffer);
                    this.i_Disp.ExecuteTransaction(this.i_Comm.s_transaction, iPid, ref this.logStream, ref this.i_Comm, ref this.dbAccess, session);
                }
                else
                {
                    this.bDisconnected = true;
                }
            }
        }
示例#3
0
        public void ProcessIncomingData(ref Translator var_translator, ref string buffer, int iPid, ref string session)
        {
            string buffer_response = "";

            if (this.i_ctrl.ServingStandBy)
            {
                this.ProcessStandByMessaging(ref buffer);
            }
            else
            {
                if (this.ProcessClientExceptions(ref buffer))
                {
                    return;
                }
                this.nu_heartBeatCounter = 0;
                bool         IsHandled = false;
                bool         IsTerm    = false;
                CustomRecept recept    = this.var_recept.getNew();
                this.i_DataServer.ReceiveAndProcessData(ref var_translator, ref recept, buffer, iPid, session, ref IsHandled, ref IsTerm);
                if (!IsHandled)
                {
                    if (buffer.StartsWith("SYCRAF"))
                    {
                        this.i_DataServer.ConvertData(ref buffer_response, iPid);
                    }
                    else
                    {
                        this.logStream.WriteLine(new StringBuilder().Append("DataServer  ").Append(this.GetCurrentTime()).Append(" TCP Packet Rejected").ToString());
                        this.logStream.Flush();
                        buffer_response = "0";
                        IsTerm          = true;
                    }
                }
                else
                {
                    buffer_response = recept.buffer_response;
                    this.i_DataServer.i_monDataLoad.NewOutputData(buffer_response.Length);
                    this.logStream.WriteLine(new StringBuilder().Append("DataServer  ").Append(this.GetCurrentTime()).Append(" SendData <").Append(buffer_response).Append(">").ToString() + " length:" + (object)buffer_response.Length);
                    this.logStream.Flush();
                }
                if (buffer_response.Length > this.m_max_packet_size)
                {
                    this.i_DataServer.i_Comm.Clear();
                    this.i_DataServer.i_Comm.AddObjection("Maximum Output reached.");
                    this.i_DataServer.i_Comm.ExportCommunicationBuffer(ref buffer_response, false, true);
                }
                if (!this.WriteMsgToClient(ref this.i_ConnInfo.serverSockStream, buffer_response))
                {
                    this.logStream.WriteLine("DataServer  " + this.GetCurrentTime() + "##### CLIENT CLOSED");
                    IsTerm = true;
                }
                this.nu_heartBeatCounter = 0;
                if (!IsTerm)
                {
                    return;
                }
                this.logStream.WriteLine("DataServer  " + this.GetCurrentTime() + "##### TERMINATE");
                this.i_monConnections.TerminateConnection();
                this.i_DataServer.bDisconnected = true;
            }
        }
示例#4
0
 public MainServer(string engineVersion, string master_server, string master_server_port, string connectionString, string DB_Machine, string language, string schema, int clientServerPort, int max_packet_size, ref ConnectionMonitor mon, ref LoadMonitor ldl, ref CPU_Monitor cpu, ref CtrlStation ctrl, Dispatcher transDisp, string db, string var_path, CustomRecept var_recept, ref Translator translator, string standby_server, string standby_server_web, string standby_server_port, string fail_fs, bool master_srv)
 {
     this.MasterMode       = master_srv;
     this.i_monConnections = mon;
     this.i_monDataLoad    = ldl;
     this.i_monCpu         = cpu;
     this.i_ctrl           = ctrl;
     this.var_translator   = translator;
     this.recept           = var_recept;
     if (!Directory.Exists(var_path + "\\LOG"))
     {
         Directory.CreateDirectory(var_path + "\\LOG");
     }
     this.m_var_path            = var_path;
     this.transactionDispatcher = transDisp;
     this.transactionDispatcher.language_default_index = language;
     this.m_engineVersion      = engineVersion;
     this.m_master_server      = master_server;
     this.m_master_server_port = master_server_port;
     this.m_connectionString   = connectionString;
     this.m_db_machine         = DB_Machine;
     this.m_schema             = schema;
     this.m_clientServerPort   = clientServerPort;
     this.m_max_packet_size    = max_packet_size;
     this.my_db     = db;
     this.m_fail_fs = fail_fs;
     if (this.m_fail_fs == "")
     {
         this.m_fail_fs = var_path + "\\failSafe.SQL";
     }
     else if ((int)this.m_fail_fs[this.m_fail_fs.Length - 1] != 92)
     {
         this.m_fail_fs += "\\failSafe.SQL";
     }
     else
     {
         this.m_fail_fs += "failSafe.SQL";
     }
     this.failSafeFile       = !File.Exists(this.m_fail_fs) ? new FileStream(this.m_fail_fs, FileMode.Create, FileAccess.Write) : new FileStream(this.m_fail_fs, FileMode.Truncate, FileAccess.Write);
     this.failSafe           = new StreamWriter((Stream)this.failSafeFile);
     this.failSafe.AutoFlush = true;
     if (this.MasterMode && standby_server.Length > 0)
     {
         this.i_ctrl.standby_server      = standby_server;
         this.i_ctrl.standby_server_web  = standby_server_web;
         this.i_ctrl.standby_server_port = Convert.ToInt32(standby_server_port);
         try
         {
             this.tcpClientStandBy = new TcpClient(standby_server, Convert.ToInt32(standby_server_port));
             this.netStreamStandBy = this.tcpClientStandBy.GetStream();
             if (this.WriteMsgToClient(ref this.netStreamStandBy, "STANDBYSQL_ALIVE"))
             {
                 if (this.ReceiveMsgFromClient(ref this.netStreamStandBy, this.m_max_packet_size) != "STANDBYSQL_ACCEPTED")
                 {
                     this.tcpClientStandBy.Close();
                     this.netStreamStandBy.Close();
                 }
                 else
                 {
                     ctrl.StandByAlive = true;
                 }
             }
         }
         catch (ArgumentNullException ex)
         {
             ex.ToString();
         }
         catch (ArgumentOutOfRangeException ex)
         {
             ex.ToString();
         }
         catch (SocketException ex)
         {
             ex.ToString();
         }
         catch (Exception ex)
         {
             ex.ToString();
         }
     }
     this.lockArea   = new LockArea();
     this.lstClients = new ArrayList();
     if (this.MasterMode)
     {
         this.createScheduler();
     }
     this.StartServer();
 }