Exemplo n.º 1
0
        //public Response ChangeContext(string context, string rpcName, string rpcVersion, object[] args)
        public RpcResponse CreateContext(string context)
        {
            RpcResponse returnVal = null;

            returnVal = this.CallRpcInCurrentContext("XWB CREATE CONTEXT", "0", new string [] { VistAHash.Encrypt(context) });

            object[] args = new object[] { string.Format("(hashed){0}", context) };

            VistaLogger.Log("XWB CREATE CONTEXT", returnVal.ExecutionTime, returnVal.Data.Length, args, returnVal.Status.ToString());

            // *** Check returnVal status first ***
            if (returnVal.Status == RpcResponseStatus.Success)
            {
                if (returnVal.Data == "1")
                {
                    returnVal.Status    = RpcResponseStatus.Success;
                    this.CurrentContext = context;
                }
                else
                {
                    returnVal.Status               = RpcResponseStatus.Fail;
                    returnVal.FailType             = RpcResponseFailType.InvalidContext;
                    returnVal.InformationalMessage = "Could not change context";
                    this.CurrentContext            = "";
                }
            }

            return(returnVal);
        }
Exemplo n.º 2
0
        private bool SendConnectionDisconnect()
        {
            // *** Send the disconnect message ***

            bool returnVal = false;

            if (this.vistaSocket != null)
            {
                if (this.vistaSocket.Connected())
                {
                    // *** Create a BYE message ***
                    RpcMessage rpcMessage = RpcMessage.CreateCloseMessage();

                    // *** Check if message was successful, and send ***
                    if (rpcMessage.Status == RpcMessageStatus.Ready)
                    {
                        RpcResponse response = this.vistaSocket.SendMessage(rpcMessage.Data);

                        if (response.Data == "#BYE#")
                        {
                            returnVal = true;
                        }

                        VistaLogger.Log("Disconnect", "", -1, null, "");
                    }
                }
            }

            return(returnVal);
        }
        public ActionResult Login()
        {
            // *** Begin login process ***

            ActionResult returnResult = null;

            // *** Prepare parameters ***
            string returnUrl            = Request.QueryString["ReturnUrl"];
            bool   alreadyAuthenticated = this.UserIsAuthenticated();
            int    timeout = 2;

            // *** Process the request ***
            returnResult = ProcessLoginGet(alreadyAuthenticated, returnUrl, out timeout);

            // *** Set timeout ***
            if (timeout > 525600)
            {
                timeout = 525600;
            }

            // *** Set timeout ***
            VistaLogger.Log(string.Format("Setting Session Timeout to {0} minutes", timeout), "", -1, null, "");
            Session.Timeout = timeout;

            // TODO: Remove AUTO LOGIN ! ...
            //returnResult = AutoLogin();

            // *** Return
            return(returnResult);
        }
        public ActionResult Login(Login loginModel)
        {
            // *** Login Post Action ***

            ActionResult returnResult = null;

            // *** Prepare parameters for processing ***
            bool               modelStateValid = ModelState.IsValid;
            int                timeout         = 0;
            string             authorizedUser  = "";
            List <XusDivision> divisions;

            // *** Process the request ***
            returnResult = ProcessLoginPost(modelStateValid, loginModel, out timeout, out authorizedUser, out divisions);

            // *** Set authorized user ***
            if (!string.IsNullOrWhiteSpace(authorizedUser))
            {
                FormsAuthentication.SetAuthCookie(authorizedUser, false);
            }

            VistaLogger.Log(string.Format("Setting Session Timeout to {0} minutes", timeout), "", -1, null, "");
            Session.Timeout = timeout;

            // TODO: Timeout testing...
            //Session.Timeout = 1;

            // *** Place divisions in session ***
            if (divisions != null)
            {
                TempData[DivisionDataKey] = divisions; // Session["DivisionData"] = divisions;
            }
            return(returnResult);
        }
Exemplo n.º 5
0
        private void LogIt()
        {
            object[] logArgs = (this.Sensitive) ? null : this.CommandArgs;

            if (this.Response != null)
            {
                VistaLogger.Log(this.RpcName, this.Response.ExecutionTime, this.Response.Size, logArgs, this.Response.Status.ToString());
            }
            else
            {
                VistaLogger.Log(this.RpcName, "-1", -1, logArgs, RpcResponseStatus.Unknown.ToString());
            }
        }
Exemplo n.º 6
0
        private void SetSocketTimeout()
        {
            RpcResponse response = this.CallRpcInCurrentContext("XWB GET BROKER INFO", "0", null);

            VistaLogger.Log("XWB GET BROKER INFO", response.ExecutionTime, response.Data.Length, new object[] { "" }, response.Status.ToString());

            int timeout;

            if (int.TryParse(response.Data, out timeout))
            {
                // *** Value is in seconds, convert to milliseconds ***
                this.vistaSocket.InactivityTimeout = timeout * 1000;
            }
        }
Exemplo n.º 7
0
        public bool Connect()
        {
            bool returnVal = false;

            DateTime start = DateTime.Now;

            if (this.vistaSocket != null)
            {
                bool ok = this.vistaSocket.Connected();

                // *** Make the connection ***
                if (!ok)
                {
                    ok = this.vistaSocket.Connect();

                    // *** Log successful connection ***
                    DateTime end       = DateTime.Now;
                    string   elapsed   = (end - start).TotalSeconds.ToString("######0.###");
                    string   resultMsg = (ok) ? "Success" : "Fail";
                    VistaLogger.Log("Connect", elapsed, -1, null, resultMsg);
                }

                if (ok)
                {
                    ok = this.initialized;

                    // *** Send the connection initialization ***
                    if (!ok)
                    {
                        this.initialized = SendConnectionInitialization();
                        ok = this.initialized;

                        // *** Set the timeout ***
                        this.SetSocketTimeout();
                    }

                    if (ok)
                    {
                        returnVal = true;
                    }
                }
            }

            return(returnVal);
        }
Exemplo n.º 8
0
        public void Disconnect()
        {
            DateTime start = DateTime.Now;

            if (this.vistaSocket != null)
            {
                // *** Send the connection disconnect message ***
                if (this.SendConnectionDisconnect())
                {
                    this.initialized = false;
                }

                // *** Disconnect ***
                this.vistaSocket.Disconnect();

                DateTime end = DateTime.Now;

                string elapsed = (end - start).TotalSeconds.ToString("######0.###");

                VistaLogger.Log("Disconnect", elapsed, -1, null, "Success");
            }
        }
        public ActionResult ChangeVerifyCode(ChangeVerifyCode changeVerifyCodeData)
        {
            // *** Change Verify Code Post Action ***

            ActionResult returnResult = null;

            // *** Prepare the data needed for processing ***
            bool   modelStateValid = this.ModelState.IsValid;
            bool   isAuthenticated = this.User.Identity.IsAuthenticated;
            int    timeout         = 0;
            string authorizedUser  = "";

            // *** Process the request ***
            returnResult = ProcessChangeVerifyCodePost(changeVerifyCodeData, modelStateValid, isAuthenticated, out timeout, out authorizedUser);

            // *** Set timeout ***
            if (timeout > 525600)
            {
                timeout = 525600;
            }

            // *** Set timeout ***
            if (timeout > 0)
            {
                VistaLogger.Log(string.Format("Setting Session Timeout to {0} minutes", timeout), "", -1, null, "");
                Session.Timeout = timeout;
            }

            // *** Set authorized user ***
            if (!string.IsNullOrWhiteSpace(authorizedUser))
            {
                FormsAuthentication.SetAuthCookie(authorizedUser, false);
            }

            return(returnResult);
        }
Exemplo n.º 10
0
        public RpcResponse SendMessage(string msg)
        {
            // *** Send RPC as bytes on socket and receive bytes back ***

            RpcResponseBuilder returnBuilder = new RpcResponseBuilder();

            //TraceLogger.Log(string.Format("RpcSocket.SendMessage - TimedOut={0}", this.TimedOut));

            lock (this.currentSocket)
            {
                // *** Convert to bytes ***
                byte[] bytes = Encoding.ASCII.GetBytes(msg);

                try
                {
                    // *** Send bytes to socket ***
                    this.currentSocket.Send(bytes);

                    // *** Set last operation ***
                    this.lastOperation = DateTime.Now;

                    // *** Get server packet bytes ***
                    byte[] packetBytes = GetServerPacket();

                    // *** Add to result ***
                    returnBuilder.SetSecuritySegment(packetBytes);

                    // *** Get application packet bytes ***
                    packetBytes = GetServerPacket();

                    // *** Add to result ***
                    returnBuilder.SetApplicationSegment(packetBytes);

                    byte[] socketBuffer = new byte[1024];
                    int    retries      = 0;
                    bool   keepGoing    = true;

                    // *** Receive bytes from socket in a loop ***
                    while (keepGoing)
                    {
                        // *** Receive bytes ***
                        int bytesRead = this.currentSocket.Receive(socketBuffer);

                        // *** Check number of bytes read ***
                        if (bytesRead > 0)
                        {
                            byte[] actualBytes = new byte[bytesRead];

                            Array.Copy(socketBuffer, actualBytes, bytesRead);

                            // *** Append bytes to the result ***
                            bool reachedEnd = returnBuilder.AppendData(actualBytes);

                            // *** Check if end reached ***
                            if (reachedEnd)
                            {
                                keepGoing = false; // *** Done ***
                            }
                        }
                        else
                        {
                            // *** No bytes read, retry ***
                            if (retries < 3)
                            {
                                // *** Ok to retry, sleep 1/2 sec ***
                                retries++;
                                Thread.Sleep(500);
                            }
                            else
                            {
                                // *** Too many retries ***
                                returnBuilder.SetInformationalMessage("Data could not be received from socket");
                                returnBuilder.SetFailType(RpcResponseFailType.Retries);

                                // *** Stop looping ***
                                keepGoing = false;
                            }
                        }
                    }
                }
                catch (SocketException sockEx)
                {
                    string timeoutMsg = string.Format("(TimedOut={0})", this.TimedOut);
                    VistaLogger.Log(timeoutMsg, "", -1, null, "");
                    ErrorLogger.Log(sockEx, "A problem occurred communicating with the socket. " + timeoutMsg);
                    returnBuilder.SetInformationalMessage("A problem occurred communicating with the socket.");
                    returnBuilder.SetFailType(RpcResponseFailType.SocketError);
                }
            }

            return(returnBuilder.ToResponse());
        }
Exemplo n.º 11
0
        public ActionResult Select(FormCollection formCollection)
        {
            // *** Select the division ***
            ActionResult returnResult;

            if (formCollection.Get("division.IsDefault") != null)
            {
                // *** Get the division id ***
                string selectedDivId = formCollection["division.IsDefault"].ToString();

                // *** Attempt to select ***

                BrokerOperationResult opResult = this.DashboardRepository.Divisions.Select(selectedDivId);

                if (opResult.Success)
                {
                    // *** Indicate success to user ***
                    // TODO: Show actual division that was selected...
                    //this.Information("Division Selected");

                    // *** Check that user has the proper context ***
                    BrokerOperationResult result = this.DashboardRepository.Accounts.CreateContext();

                    if (!result.Success)
                    {
                        returnResult = RedirectToAction("NoContext", "Account");
                    }
                    else
                    {
                        // *** Set the session timeout based on value in vista ***
                        int timeoutInSeconds = this.DashboardRepository.Accounts.GetUserTimeout();

                        // TODO: Used for testing...
                        //timeout = 1;

                        // *** Set timeout ***
                        if (timeoutInSeconds > 525600)
                        {
                            timeoutInSeconds = 525600;
                        }

                        // *** Convert timeout to minutes ***
                        int timeout = timeoutInSeconds / 60;

                        if (timeout >= 1)
                        {
                            VistaLogger.Log(string.Format("Setting Session Timeout to {0} minutes", timeout), "", -1, null, "");
                            Session.Timeout = timeout;
                        }

                        // *** Redirect ***
                        returnResult = RedirectToAction("Dashboard", "PatientList");
                    }

                    TempData.Remove("DivSelectPending");
                }
                else
                {
                    this.Error("Division selection failed");
                    returnResult = RedirectToAction("Select");
                }
            }
            else
            {
                this.Error("Division selection failed");
                returnResult = RedirectToAction("Select");
            }

            return(returnResult);
        }