Example #1
0
        /// <summary>
        /// method to send the carwash request to the server
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        protected virtual bool SendCarwashRequest(string request)
        {
            var returnValue = false;
            var responce    = new byte[2048];
            var xmlRenamed  = new XML(_policyManager);
            var socket      = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var ip          = _policyManager.CarwashIP;
            var port        = _policyManager.CarwashPort;

            if (ip != null)
            {
                var ipAddress      = IPAddress.Parse(ip);
                var remoteEndPoint = new IPEndPoint(ipAddress, port);
                try
                {
                    socket.Connect(remoteEndPoint);
                    if (socket.Connected)
                    {
                        var msg = Encoding.ASCII.GetBytes(request);
                        socket.Send(msg);
                        Task.Delay(500);
                        var bytesRec  = socket.Receive(responce);
                        var strBuffer = Encoding.ASCII.GetString(responce, 0, bytesRec);
                        if (_operation == 1)
                        {
                            xmlRenamed.AnalyzeCarwashCodeResponse(strBuffer, _responseArray);
                        }
                        else
                        {
                            xmlRenamed.AnalyzeCarwashResponse(strBuffer);
                            var validity = xmlRenamed.getValidity();
                            if (validity == "VALIDCODE")
                            {
                                _isCodeValid = true;
                            }
                        }
                        returnValue = true;
                    }
                    else
                    {
                        goto err1;
                    }
                }
                catch (Exception ex)
                {
                    WriteToLogFile("SendCarwashRequest method is throwing this exception" + ex.ToString());
                    goto err1;
                }
            }
            return(returnValue);

err1:
            Chaps_Main.SA.IsCarwashProcessed = false;
            return(false);
        }