Beispiel #1
0
        private Dictionary <Guid, TripSession> ReadSessionFile()
        {
            _logger.Debug("******READING TRIP SESSION FILE**********");
            Dictionary <Guid, TripSession> result = new Dictionary <Guid, TripSession>();

            if (!File.Exists(_sessionFile))
            {
                _logger.Debug("The session file does not exist. file=" + _sessionFile);
                return(result);
            }

            string[] lines = File.ReadAllLines(_sessionFile);
            foreach (string line in lines)
            {
                TripSession tripSession = TripSession.ParseLine(line);
                if (tripSession != null && (DateTime.Now - tripSession.Expiration) < _maxAge)
                {
                    result[tripSession.Id] = tripSession;
                    _logger.Debug("ADDED---->" + line);
                }
                else
                {
                    _logger.Debug("EXPIRED-->" + line);
                }
            }
            return(result);
        }
Beispiel #2
0
        public IActionResult ToDo()
        {
            var session = new TripSession(HttpContext.Session);
            var trip    = session.GetTrip();

            return(View(trip));
        }
Beispiel #3
0
        public IActionResult ThingsToDo()
        {
            var  session = new TripSession(HttpContext.Session);
            Trip trip    = session.GetTrip();

            ViewBag.Action = "Add Things To Do in " + trip.Destination;

            return(View(trip));
        }
Beispiel #4
0
        public IActionResult Accommodation(Trip trip)
        {
            var session = new TripSession(HttpContext.Session);

            //session.ClearTrip();
            session.SetTrip(trip);

            return(RedirectToAction("ThingsToDo", "Trip"));
        }
Beispiel #5
0
        public IActionResult Accommodation()
        {
            var  session = new TripSession(HttpContext.Session);
            Trip trip    = session.GetTrip();

            ViewBag.Action = "Add Info for " + trip.Accommodation;

            return(View(trip));
        }
Beispiel #6
0
        public IActionResult Add(Trip trip)
        {
            var session = new TripSession(HttpContext.Session);
            var next    = trip.Accommodation != null ? "Accommodation" : "ThingsToDo";

            session.SetTrip(trip);

            return(RedirectToAction(next, "Trip"));
        }
 public IActionResult Add(Trip trip)
 {
     if (ModelState.IsValid)
     {
         var session = new TripSession(HttpContext.Session);
         session.SetTrip(trip);
         return(RedirectToAction("Index", "AdditionalInfo"));
     }
     return(View(trip));
 }
Beispiel #8
0
        public IActionResult ThingsToDo(Trip trip)
        {
            var session = new TripSession(HttpContext.Session);

            context.Trips.Add(trip);
            context.SaveChanges();
            TempData["message"] = "Trip to " + trip.Destination + " added.";

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #9
0
        public IActionResult Index()
        {
            var session = new TripSession(HttpContext.Session);

            session.ClearTrip();
            TempData.Clear();
            var trips = context.Trips.
                        OrderBy(t => t.StartDate).ToList();

            return(View(trips));
        }
Beispiel #10
0
        private void SaveSessionFile()
        {
            _logger.Debug("Saving trip session data to file.");
            List <string> lines = new List <string>();

            foreach (KeyValuePair <Guid, TripSession> keyValuePair in _sessions)
            {
                TripSession tripSession = keyValuePair.Value;
                lines.Add(tripSession.ToString());
            }
            File.WriteAllLines(_sessionFile, lines.ToArray());
        }
Beispiel #11
0
 public IActionResult AddInfo(Trip trip)
 {
     if (ModelState.IsValid)
     {
         var session     = new TripSession(HttpContext.Session);
         var sessionTrip = session.GetTrip();
         sessionTrip.AccomodationPhone = trip.AccomodationPhone;
         sessionTrip.AccomodationEmail = trip.AccomodationEmail;
         session.SetTrip(sessionTrip);
         return(RedirectToAction("ToDo", "ToDo"));
     }
     return(View(trip));
 }
Beispiel #12
0
 public IActionResult AddInfo(Trip trip)
 {
     if (ModelState.IsValid)
     {
         var session     = new TripSession(HttpContext.Session);
         var sessionTrip = session.GetTrip();
         sessionTrip.ThingToDo1 = trip.ThingToDo1;
         sessionTrip.ThingToDo2 = trip.ThingToDo2;
         sessionTrip.ThingToDo3 = trip.ThingToDo3;
         Context.Trips.Add(sessionTrip);
         Context.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     return(View(trip));
 }
Beispiel #13
0
 public TripSession CreateSession(string userName, int truckId)
 {
     try
     {
         TripSession tripSession = new TripSession
         {
             Id         = Guid.NewGuid(),
             Expiration = DateTime.Now + _maxAge,
             TruckId    = truckId,
             UserName   = userName
         };
         _sessions[tripSession.Id] = tripSession;
         SaveSessionFile();
         _logger.Debug("Created session for: username="******",truckid=" + truckId);
         return(tripSession);
     }
     catch (Exception ex)
     {
         _logger.Error("Failed to create session. ", ex);
     }
     return(null);
 }
Beispiel #14
0
 void socketServer_SessionClosed(TripSession session, CloseReason reason)
 {
     session.Send("see you!");
 }
Beispiel #15
0
 void socketServer_NewMessageReceived(TripSession session, string e)
 {
     session.Send("you have a new message: " + e);
 }
Beispiel #16
0
 public void socketServer_NewSessionConnected(TripSession session)
 {
     session.Send("hello, welcome to itrip!");
 }