示例#1
0
        public static void RegisterClientWithServer(object obj)
        {
            ThreadPoolCommonClass common = (ThreadPoolCommonClass)obj;
            SystemConfiguration   sysConfig;
            string tempConfig = Encoding.ASCII.GetString(common.Output);

            sysConfig = JsonConvert.DeserializeObject <SystemConfiguration>(tempConfig);

            sysConfig.HostName = common.ThreadIndx.ToString() + sysConfig.HostName + DateTime.Now.ToString(ConstantVariables.DATE_FORMAT);

            byte[]      configByte = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(sysConfig));
            StateObject stateObj   = null;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);
                byte[] headerBytes = BuildHeaders(common.TaskCode, configByte.Length, string.Empty);

                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                TcpUtil.WriteData(stateObj.ClientStream, configByte);

                string outputMsg = TcpUtil.ReadData(stateObj.ClientStream);
                if (outputMsg == string.Empty)
                {
                    IsRegistrationSuccess = false;
                    return;
                }
                else
                {
                    if (outputMsg == "InvalidID")
                    {
                        IsRegistrationSuccess = false;
                        return;
                    }
                }
                if (common.ThreadIndx == 0)
                {
                    ConfigHandler.HostInfoes        = new HostInfo();
                    ConfigHandler.HostInfoes.HostID = SplitHeader(outputMsg);
                    HTTPDataAnalyzer.ConfigHandler.SaveConfigFile(string.Empty);
                }
                UpdateClient.TryAdd(SplitHeader(outputMsg), sysConfig.HostName);
            }
            catch (Exception ex)
            {
                //Registration.ClientRegistrar.Logger.Error(ex);
                IsRegistrationSuccess = false;
            }
            finally
            {
                stateObj.Close();
            }
            IsRegistrationSuccess = true;
        }
示例#2
0
        public static void UpdateClientInfo(object updateGetObj)
        {
            ThreadPoolCommonClass common = (ThreadPoolCommonClass)updateGetObj;
            SystemConfiguration   sysConfig;
            string tempConfig = Encoding.ASCII.GetString(common.Output);

            sysConfig = JsonConvert.DeserializeObject <SystemConfiguration>(tempConfig);

            string tempHostName;

            UpdateClient.TryGetValue(UpdateClient.Keys.ElementAt(common.ThreadIndx), out tempHostName);
            sysConfig.HostName = tempHostName;

            byte[]      configByte = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(sysConfig));
            StateObject stateObj   = null;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);
                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                byte[] headerBytes = BuildHeaders(common.TaskCode, configByte.Length, UpdateClient.Keys.ElementAt(common.ThreadIndx));
                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);

                TcpUtil.WriteData(stateObj.ClientStream, configByte);

                string outputMsg = TcpUtil.ReadData(stateObj.ClientStream);
                if (outputMsg == string.Empty)
                {
                    return;
                }
                else
                {
                    if (outputMsg == "Invalid ID")
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                //ConfigurationDetector.Logger.Error(ex);
            }
            finally
            {
                stateObj.Close();
            }
        }
示例#3
0
        public static bool RegisterClientWithServer(string taskCode, byte[] output)
        {
            //Registration.ClientRegistrar.Logger.Info("Enter");

            StateObject stateObj = null;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                byte[] headerBytes = BuildHeaders(taskCode, output.Length);

                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);

                TcpUtil.WriteData(stateObj.ClientStream, output);

                string outputMsg = TcpUtil.ReadData(stateObj.ClientStream);
                if (outputMsg == string.Empty)
                {
                    return(false);
                }
                else
                {
                    if (outputMsg == "InvalidID")
                    {
                        return(false);
                    }
                }
                ConfigHandler.HostInfoes        = new HostInfo();
                ConfigHandler.HostInfoes.HostID = SplitHeader(outputMsg);
                HTTPDataAnalyzer.ConfigHandler.SaveConfigFile(string.Empty);
            }
            catch (Exception ex)
            {
                //Registration.ClientRegistrar.Logger.Error(ex);
                return(false);
            }
            finally
            {
                stateObj.Close();
            }

            //Registration.ClientRegistrar.Logger.Info("Exit");
            return(true);
        }
示例#4
0
        public static bool UpdateClientInfo(string taskCode, byte[] output)
        {
            //SystemInfoUpdater.Logger.Info("Enter");

            StateObject stateObj = null;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                byte[] headerBytes = BuildHeaders(taskCode, output.Length);
                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);

                TcpUtil.WriteData(stateObj.ClientStream, output);

                string outputMsg = TcpUtil.ReadData(stateObj.ClientStream);
                if (outputMsg == string.Empty)
                {
                    return(false);
                }
                else
                {
                    if (outputMsg == "Invalid ID")
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                //SystemInfoUpdater.Logger.Error(ex);
                return(false);
            }
            finally
            {
                stateObj.Close();
            }

            //SystemInfoUpdater.Logger.Info("Exit");
            return(true);
        }
示例#5
0
        public static void SearchConfigChangeInServer(string taskCode, byte[] output)
        {
            //ConfigurationDetector.Logger.Info("Enter");

            StateObject stateObj = null;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                byte[] headerBytes = BuildHeaders(taskCode, output.Length);

                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                // TcpUtil.WriteData(stateObj.ClientStream, output);

                string outputMsg = TcpUtil.ReadData(stateObj.ClientStream);
                if (outputMsg == string.Empty)
                {
                    return;
                }

                if (outputMsg == "InvalidID")
                {
                    return;
                }

                HTTPDataAnalyzer.ConfigHandler.SaveConfigFile(outputMsg);
            }
            catch (Exception ex)
            {
                //ConfigurationDetector.Logger.Error(ex);
            }
            finally
            {
                stateObj.Close();
            }

            //ConfigurationDetector.Logger.Info("Exit");
        }
示例#6
0
        public static void SearchConfigChangeInServer(object obj)
        {
            StateObject           stateObj = null;
            ThreadPoolCommonClass common   = (ThreadPoolCommonClass)obj;

            try
            {
                stateObj = new StateObject();
                TCPSocket.Connect(stateObj);

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                byte[] headerBytes = BuildHeaders(common.TaskCode, common.Output.Length, UpdateClient.Keys.ElementAt(common.ThreadIndx));

                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                TcpUtil.WriteData(stateObj.ClientStream, common.Output);

                string outputMsg = TcpUtil.ReadData(stateObj.ClientStream);
                if (outputMsg == string.Empty)
                {
                    return;
                }

                if (outputMsg == "InvalidID")
                {
                    return;
                }
                HTTPDataAnalyzer.ConfigHandler.SaveConfigFile(outputMsg);
            }
            catch (Exception ex)
            {
                //ConfigurationDetector.Logger.Error(ex);
            }
            finally
            {
                stateObj.Close();
            }
        }