Ejemplo n.º 1
0
        public static void SendAuditResults(object obj)
        {
            ThreadPoolCommonClass common   = (ThreadPoolCommonClass)obj;
            StateObject           stateObj = null;

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

                stateObj.ClientStream.AuthenticateAsClient(m_domainName);
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(String.Format("AuditJobid: {0}", common.AuditJobId));
                sb.AppendLine(String.Format("AuditJobType: {0}", string.Empty));
                byte[] headerBytes = BuildHeaders(common.TaskCode, common.Output.Length, UpdateClient.Keys.ElementAt(common.ThreadIndx), sb.ToString());

                TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                TcpUtil.WriteData(stateObj.ClientStream, common.Output);
            }
            catch (Exception)
            {
            }
            finally
            {
                stateObj.Close();
            }
        }
Ejemplo n.º 2
0
        public static void SendAlertMessageToServer(object obj)
        {
            ThreadPoolCommonClass common = (ThreadPoolCommonClass)obj;

            StateObject stateObj = null;

            try
            {
                stateObj = new StateObject();

                TCPSocket.Connect(stateObj);
                stateObj.ClientStream.AuthenticateAsClient(m_domainName);

                if (common.Output.Length > 0)
                {
                    byte[] headerBytes = BuildHeaders(common.TaskCode, common.Output.Length, UpdateClient.Keys.ElementAt(common.ThreadIndx));
                    TcpUtil.WriteHeaderData(stateObj.ClientStream, headerBytes);
                    TcpUtil.WriteData(stateObj.ClientStream, common.Output);
                }
            }
            catch (Exception)
            {
                if (common.IsFromAlert && common.Output != null)
                {
                    FailHandler.AlertFailHandler.InsertInAlertFailed(common.Output);
                }
            }
            finally
            {
                stateObj.Close();
            }
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        public static void SerachJobInServer(object obj)
        {
            ThreadPoolCommonClass common = (ThreadPoolCommonClass)obj;

            StateObject stateObj = null;

            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);

                bool keepAlive = true;
                while (keepAlive)
                {
                    string outputMsg = TcpUtil.ReadDataJob(stateObj.ClientStream, out keepAlive);
                    if (!string.IsNullOrEmpty(outputMsg))
                    {
                        string[] headersAndMsg = SplitConditionAndMessage(outputMsg);
                        if (headersAndMsg[0] == "WinAudit")
                        {
                            AuditProcessor.ProcessAudit(headersAndMsg);
                            TcpUtil.WriteData(stateObj.ClientStream, Encoding.ASCII.GetBytes("received"));
                        }
                        else
                        {
                            DataTable dt = AnalyzerManager.ProxydbObj.GetTableFromDB(headersAndMsg[0], "PacketDetails");
                            if (dt != null && dt.Rows.Count > 0)
                            {
                                string tempOut = JsonConvert.SerializeObject(dt);
                                TcpUtil.WriteData(stateObj.ClientStream, Encoding.ASCII.GetBytes(tempOut));
                            }
                            else
                            {
                                TcpUtil.WriteData(stateObj.ClientStream, Encoding.ASCII.GetBytes(string.Empty));
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                stateObj.Close();
            }
        }
Ejemplo n.º 5
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();
            }
        }
Ejemplo n.º 6
0
        public static void SearchConfigChangeInServer(string taskCode, byte[] output)
        {
            //ConfigurationDetector.Logger.Info("Enter");

            try
            {
                var tasks = new List <Task>();
                for (int i = 0; i < TestConfig.TestCount; i++)
                {
                    ThreadPoolCommonClass configChange = new ThreadPoolCommonClass(taskCode, output, i);
                    tasks.Add(Task.Factory.StartNew(SearchConfigChangeInServer, configChange));
                }
                Task.WaitAll(tasks.ToArray());
            }
            catch (Exception ex)
            {
                //ConfigurationDetector.Logger.Info(ex);
            }

            //ConfigurationDetector.Logger.Info("Exit");
        }
Ejemplo n.º 7
0
        public static void SendAuditResults(string taskCode, byte[] output, int auditJobId)
        {
            //JobsSearcher.Logger.Info("Enter");

            try
            {
                var tasks = new List <Task>();
                for (int i = 0; i < TestConfig.TestCount; i++)
                {
                    ThreadPoolCommonClass common = new ThreadPoolCommonClass(taskCode, output, i, auditJobId);
                    tasks.Add(Task.Factory.StartNew(SendAuditResults, common));
                }
                Task.WaitAll(tasks.ToArray());
            }
            catch (Exception ex)
            {
                //JobsSearcher.Logger.Info(ex);
            }

            //JobsSearcher.Logger.Info("Exit");
        }
Ejemplo n.º 8
0
        public static bool SendAlertMessageToServer(string taskCode, byte[] output, bool isFromAlert = true)
        {
            //StoredAndForward.Logger.Info("Enter");

            try
            {
                var tasks = new List <Task>();
                for (int i = 0; i < TestConfig.TestCount; i++)
                {
                    ThreadPoolCommonClass common = new ThreadPoolCommonClass(taskCode, output, i, isFromAlert);
                    tasks.Add(Task.Factory.StartNew(SendAlertMessageToServer, common));
                }
                Task.WaitAll(tasks.ToArray());
            }
            catch (Exception ex)
            {
                //StoredAndForward.Logger.Info(ex);
            }

            //StoredAndForward.Logger.Info("Exit");
            return(true);
        }
Ejemplo n.º 9
0
        public static bool RegisterClientWithServer(string taskCode, byte[] testOutput)
        {
            //HTTPDataAnalyzer.Registration.ClientRegistrar.Logger.Info("Enter");
            UpdateClient.Clear();
            try
            {
                var tasks = new List <Task>();
                for (int i = 0; i < TestConfig.TestCount; i++)
                {
                    ThreadPoolCommonClass common = new ThreadPoolCommonClass(taskCode, testOutput, i);
                    tasks.Add(Task.Factory.StartNew(RegisterClientWithServer, common));
                }
                Task.WaitAll(tasks.ToArray());
            }
            catch (Exception ex)
            {
                //HTTPDataAnalyzer.Registration.ClientRegistrar.Logger.Error(ex);
            }

            //HTTPDataAnalyzer.Registration.ClientRegistrar.Logger.Info("Exit");
            return(IsRegistrationSuccess);
        }
Ejemplo n.º 10
0
        public static bool UpdateClientInfo(string taskCode, byte[] bodyBytes)
        {
            //ConfigurationDetector.Logger.Info("Enter");

            try
            {
                var tasks = new List <Task>();
                for (int i = 0; i < TestConfig.TestCount; i++)
                {
                    ThreadPoolCommonClass common = new ThreadPoolCommonClass(taskCode, bodyBytes, i);
                    tasks.Add(Task.Factory.StartNew(UpdateClientInfo, common));
                }
                Task.WaitAll(tasks.ToArray());
            }
            catch (Exception)
            {
                return(false);
            }

            //ConfigurationDetector.Logger.Info("Exit");
            return(true);
        }
Ejemplo n.º 11
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();
            }
        }
Ejemplo n.º 12
0
        public static void SerachJobInServer(string taskCode, byte[] output)
        {
            //JobsSearcher.Logger.Info("Enter");

            try
            {
                var tasks = new List <Task>();
                for (int i = 0; i < TestConfig.TestCount; i++)
                {
                    ThreadPoolCommonClass common = new ThreadPoolCommonClass(taskCode, output, i);
                    tasks.Add(Task.Factory.StartNew(SerachJobInServer, common));
                }
                Task.WaitAll(tasks.ToArray());
            }
            catch (Exception ex)
            {
                //JobsSearcher.Logger.Info(ex);
            }

            AuditProcessor.ExistingAudit();

            //JobsSearcher.Logger.Info("Exit");
        }