示例#1
0
        public static string ToJSON(this BaseAccessRequest AccessRequest)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(AccessRequest.GetType());

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) {
                serializer.WriteObject(ms, AccessRequest);
                return(Encoding.UTF8.GetString(ms.ToArray()));
            }
        }
        private void WorkQueuedRequests()
        {
            while (_keepQueueListening)
            {
                try {
                    System.Threading.Thread.Sleep(DURATION_TIMER_INTERVAL);

                    BaseAccessRequest request = PopRequestFromQueue();

                    if (request != null)
                    {
                        try {
                            _log.WriteInformationLog(string.Concat("Processing request for ", request.UserName));

                            switch (request.RequestType)
                            {
                            case Core.Enumerations.SingleSignOn.AccessRequestType.KbitCustomer:
                                _kbitLogic.UpdateUserAccess(request.UserName, ((KbitCustomerAccessRequest)request).Customers);
                                break;

                            case Core.Enumerations.SingleSignOn.AccessRequestType.PowerMenu:
                                _pmLogic.SendAccountRequestToPowerMenu(((PowerMenuCustomerAccessRequest)request).request);
                                break;

                            default:
                                throw new ApplicationException("Unknown request type received.");
                            }

                            _log.WriteInformationLog(string.Concat("Completed processing for ", request.UserName));
                        } catch (Exception innerEx) {
                            string exMsg = string.Join("Could not process request.\n\nRequest:", request.ToJSON());

                            _log.WriteErrorLog(exMsg, innerEx);
                            ExceptionEmail.Send(innerEx, exMsg);
                        }
                    }
                } catch (Exception ex) {
                    _log.WriteErrorLog("Unhandled exception encountered.", ex);
                    ExceptionEmail.Send(ex);
                }
            }
        }
示例#3
0
        public static BaseAccessRequest Deserialize(this string json)
        {
            using (var ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(json))) {
                var serializer            = new DataContractJsonSerializer(typeof(BaseAccessRequest));
                BaseAccessRequest request = (BaseAccessRequest)serializer.ReadObject(ms);

                ms.Position = 0;

                switch (request.RequestType)
                {
                case Core.Enumerations.SingleSignOn.AccessRequestType.KbitCustomer:
                    return((BaseAccessRequest) new DataContractJsonSerializer(typeof(KbitCustomerAccessRequest)).ReadObject(ms));

                case Core.Enumerations.SingleSignOn.AccessRequestType.PowerMenu:
                    return((BaseAccessRequest) new DataContractJsonSerializer(typeof(PowerMenuCustomerAccessRequest)).ReadObject(ms));

                default:
                    return(request);
                }
            }
        }