public void RecordSessionCookie(string userName, IRequestCookieCollection cookies)
        {
            _logger.LogDebug("[SessionCookieService][RecordSessionCookie] =>");

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                foreach (var cookieKey in cookies.Keys)
                {
                    _logger.LogDebug("[SessionCookieService][RecordSessionCookie] => cookieKey: '" + cookieKey + "'");
                }
            }

            SessionCookie oldCookie = _sessionCookieRepo.Retrieve(userName, MiscConstants.SESSION_COOKIE_NAME);

            if (oldCookie != null)
            {
                _logger.LogDebug("[SessionCookieService][RecordSessionCookie] => Deleting oldCookie");
                _sessionCookieRepo.Delete(oldCookie);
            }

            if (cookies[MiscConstants.SESSION_COOKIE_NAME] == null)
            {
                StringBuilder sb = new StringBuilder("[SessionCookieService][RecordSessionCookie] => Session cookie '");
                sb.Append(MiscConstants.SESSION_COOKIE_NAME);
                sb.Append("' for User '");
                sb.Append(userName);
                sb.Append("' NOT FOUND!");
                string errMsg = sb.ToString();

                _logger.LogError(errMsg);
                throw new ApplicationException(errMsg);
            }

            SessionCookie newCookie = new SessionCookie
            {
                UserName       = userName,
                CookieName     = MiscConstants.SESSION_COOKIE_NAME,
                CookieValue    = cookies[MiscConstants.SESSION_COOKIE_NAME],
                LastAccessedOn = DateTime.Now
            };

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("[SessionCookieService][RecordSessionCookie]=> Saving new SessionCookie to the database: ");
                _logger.LogDebug(newCookie.ToString());
            }

            _sessionCookieRepo.Create(newCookie);

            _logger.LogDebug("<= [SessionCookieService][RecordSessionCookie]");
        }
Example #2
0
 public void GetCountersFromPrinter(Uri printerCounterUri)
 {
     try
     {
         Task.Delay(1000);
         HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(printerCounterUri);
         myRequest.Method = "GET";
         myRequest.Headers.Add(HttpRequestHeader.Cookie, SessionCookie.ToString());
         WebResponse  myResponse = myRequest.GetResponse();
         StreamReader sr         = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
         // this.PrinterResponse = sr.ReadToEnd();
         this.PrinterResponseParser.PrinterResponse = sr.ReadToEnd();
         sr.Close();
         myResponse.Close();
     }
     catch (Exception e)
     {
         Console.WriteLine("Couldn't get response from printer " + printerCounterUri);
     }
 }
 public override string ToString()
 {
     return($"{ClientSessionInfo.ToString()}::SessionCookie={SessionCookie.ToString()};SessionKey=XXX;SessionIV=XXX");
 }