public ActionResult Details(int id)
        {
            GameEntities ent   = new GameEntities();
            KingdomModel model = ent.Kingdoms.Where(x => x.Id == id).FirstOrDefault().ToKingdomViewModel();

            return(View(model));
        }
        // GET: api/Game
        // >Tyler Lancaster, 1/25/18
        /// <summary>
        /// Retrieves the latest game state for the game whose ID was provided.
        /// </summary>
        /// <param name="id">The ID of the game whose latest state should be returned.</param>
        /// <returns>The latest GameState object for the specified game. If no game states exist, the response will be empty.</returns>
        public IHttpActionResult GetGame(int id)
        {
            try
            {
                using (var db = new GameEntities())
                {
                    //Get the list of game states for the id provided and order them by descending.
                    IQueryable <GameState> gameStatesDesc = db.GameStates.Where(x => x.GameID == id).OrderByDescending(x => x.TimeStamp);

                    //If game states were found, return the latest one. Otherwise, return an empty list.
                    if (gameStatesDesc.Any())
                    {
                        return(Ok(gameStatesDesc.First()));
                    }
                    else
                    {
                        return(Ok());
                    }
                }
            }
            catch (ArgumentNullException e)
            {
                return(Content(HttpStatusCode.NotFound, "Requested data not found."));
            }
            catch (InvalidOperationException e)
            {
                return(Content(HttpStatusCode.BadRequest, "Unabble to process request."));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.InternalServerError, "The server encountered an error when attempting to retrieve the game history. Please inform the development team."));
            }
        }
        public ActionResult Create(ArmyModel a)
        {
            if (ModelState.IsValid)
            {
                GameEntities ent  = new GameEntities();
                Army         unit = new Army();

                unit.Name        = a.Name;
                unit.Attack      = a.Attack;
                unit.Defence     = a.Defence;
                unit.KingdomId   = a.KingdomId;
                unit.Knowledge   = a.Knowledge;
                unit.MagicResist = a.MagicResist;
                unit.Quantity    = a.Quantity;

                ent.Armies.Add(unit);
                ent.SaveChanges();


                return(RedirectToAction("Index"));
            }
            else
            {
                GameEntities ent = new GameEntities();

                ViewData["Kingdom"] = ent.Kingdoms.Select(x => new SelectListItem()
                {
                    Value = x.Id.ToString(), Text = x.Name
                }).ToList();

                return(View(a));
            }
        }
        public ActionResult Edit(int Id)
        {
            GameEntities ent     = new GameEntities();
            KingdomModel kingdom = ent.Kingdoms.Where(x => x.Id == Id).FirstOrDefault().ToKingdomViewModel();

            return(View(kingdom));
        }
예제 #5
0
        public IHttpActionResult GetMyGames(int gameStatus = -1) // string? Gamestatus to check for active vs inactive games
        {
            try
            {
                using (var db = new GameEntities())
                {
                    IQueryable <Game> myGames = db.GameUsers.Where(gu => gu.AspNetUser.UserName == User.Identity.Name).Select(g => g.Game);

                    if (gameStatus != -1)
                    {
                        myGames = myGames.Where(x => x.Status == gameStatus);
                    }

                    ////May not be neccessary:
                    ////In the case that the user exists but does not have any games, return OK with an empty result.
                    //if (!myGames.Any())
                    //{
                    //    return Ok();
                    //}

                    return(Ok(myGames.ToList()));
                }
            }
            catch (ArgumentNullException e)
            {
                return(Content(System.Net.HttpStatusCode.NotFound, "The user who made the call could not be found in the database."));
            }
            catch (Exception e)
            {
                return(Content(System.Net.HttpStatusCode.InternalServerError, "The server encountered an error retrieving the list of games. Please inform the development team."));
            }
        }
예제 #6
0
        // GET: api/Game
        // >Tyler Lancaster, 1/25/18
        /// <summary>
        /// Retrieves the latest game state for the game whose ID was provided.
        /// </summary>
        /// <param name="id">The ID of the game whose latest state should be returned.</param>
        /// <returns>The latest GameState object for the specified game. If no game states exist, the response will be empty.</returns>
        public IHttpActionResult GetGame(int id)
        {
            try
            {
                using (var db = new GameEntities())
                {
                    //Note: The database is ordered by timestampt descending, we can use the first record.

                    //Cameron: ^This is not true. We have an index which makes sorting by timestamp descending extremely fast,
                    //  but that does not mean it is sorting by timestamp descending by default.


                    //Get the list of game states for the id provided and order them by descending.
                    IQueryable <GameState> gameStatesDesc = db.GameStates.Where(x => x.GameID == id).OrderByDescending(x => x.TimeStamp);

                    //If game states were found, return the latest one. Otherwise, return an empty list.
                    if (gameStatesDesc.Any())
                    {
                        return(Ok(gameStatesDesc.First()));
                    }
                    else
                    {
                        return(Ok());
                    }
                }
            }
            catch (Exception e)
            {
                return(Content(System.Net.HttpStatusCode.InternalServerError, "The server encountered an error when attempting to retrieve the latest game state. Please inform the development team."));
            }
        }
        public ActionResult Details(int Id)
        {
            GameEntities ent  = new GameEntities();
            ArmyModel    unit = ent.Armies.Where(x => x.Id == Id).FirstOrDefault().ToArmyViewModel();

            return(View(unit));
        }
        public ActionResult Edit(ArmyModel a)
        {
            if (ModelState.IsValid) // jezeli spelnia atrybuty, walidatory
            {
                GameEntities ent = new GameEntities();
                Army         unit;// = new Army();
                unit             = ent.Armies.Where(x => x.Id == a.UnitId).FirstOrDefault();
                unit.Name        = a.Name;
                unit.Attack      = a.Attack;
                unit.Defence     = a.Defence;
                unit.KingdomId   = a.KingdomId;
                unit.Knowledge   = a.Knowledge;
                unit.MagicResist = a.MagicResist;
                unit.Quantity    = a.Quantity;
                ent.Entry(ent.Armies.Where(x => x.Id == a.UnitId).First()).CurrentValues.SetValues(unit);
                ent.SaveChanges();
                return(RedirectToAction("Index"));
            }

            else
            {
                GameEntities ent = new GameEntities();
                ViewData["Kingdom"] = ent.Kingdoms.Select(x => new SelectListItem()
                {
                    Value = x.Id.ToString(), Text = x.Name
                }).ToList();
                return(View(a));
            }
        }
        public IHttpActionResult GetMyGames(int gameStatus = -1) // string? Gamestatus to check for active vs inactive games
        {
            try
            {
                using (var db = new GameEntities())
                {
                    IQueryable <Game> gameQueryable = db.GameUsers
                                                      .Where(gu => gu.AspNetUser.UserName == User.Identity.Name)
                                                      .Select(g => g.Game)
                                                      .Include(x => x.GameUsers.Select(y => y.AspNetUser));

                    if (gameStatus != -1)
                    {
                        gameQueryable = gameQueryable.Where(x => x.Status == gameStatus);
                    }

                    List <GameDetails> gameList = gameQueryable.ToList().Select(x => new GameDetails(x)).ToList();

                    return(Ok(gameList));
                }
            }
            catch (ArgumentNullException e)
            {
                return(Content(HttpStatusCode.NotFound, "The user who made the call could not be found in the database."));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.InternalServerError, "The server encountered an error retrieving the list of games. Please inform the development team."));
            }
        }
예제 #10
0
        public void AttachToControl(CanvasAnimatedControl canvas)
        {
            _canvas         = canvas;
            _canvas.Draw   += _canvas_Draw;
            _canvas.Update += _canvas_Update;

            GameEntities.Add(new Player(this, GameSize));
            Invader.CreateInvaders(this, 24);
        }
        public ActionResult Delete(int id)
        {
            GameEntities ent = new GameEntities();

            Army army = ent.Armies.Where(x => x.Id == id).First();

            ent.Armies.Remove(army);
            ent.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public IHttpActionResult CreateGame([FromBody] List <string> players)
        {
            try
            {
                using (var db = new GameEntities())
                {
                    //Add the user who made the call to the list of game participants.
                    if (!players.Contains(User.Identity.Name))
                    {
                        players.Add(User.Identity.Name);
                    }

                    //Get the ID and username for each participant.
                    var participants = db.AspNetUsers.Where(x => players.Contains(x.UserName)).Select(x => new { x.Id, x.UserName }).ToList();

                    //Create a list of GameUser objects using the participants. The user who made the call will have a status of 2 (active), while all others will be 1 (pending).
                    var newGameUsers = participants.Select(x => new GameUser
                    {
                        UserID = x.Id,
                        Status = (x.UserName == User.Identity.Name) ? 2 : 1
                    }).ToList();

                    //Check that all game participants have accounts (and were found) in the database. If not, return an error.
                    if (newGameUsers.Count() != players.Count())
                    {
                        return(Content(HttpStatusCode.NotFound, "One or more of the game participants were not found in the database."));
                    }

                    string createGameMessage = null;
                    if (!logic.TryCreateGame(ref createGameMessage, participants.Select(x => x.UserName).ToList()))
                    {
                        return(Content(HttpStatusCode.BadRequest, createGameMessage));
                    }

                    Game g = new Game()
                    {
                        Start     = DateTime.Now,
                        GameUsers = newGameUsers
                    };

                    db.Games.Add(g);
                    db.SaveChanges();

                    return(Ok(g.ID));
                }
            }
            catch (ArgumentNullException e)
            {
                return(Content(HttpStatusCode.InternalServerError, "The database encountered an error while attempting to retrieve information about the participants."));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.InternalServerError, "The server encountered an error and was unable to create the game. Please inform the development team."));
            }
        }
        public ActionResult Create()
        {
            ArmyModel    a   = new ArmyModel();
            GameEntities ent = new GameEntities();

            ViewData["Kingdom"] = ent.Kingdoms.Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(), Text = x.Name
            }).ToList();

            return(View("Create", a));
        }
        public ActionResult Edit(int Id)
        {
            GameEntities ent = new GameEntities();

            ViewData["Kingdom"] = ent.Kingdoms.Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(), Text = x.Name
            }).ToList();
            ArmyModel model = ent.Armies.Where(x => x.Id == Id).FirstOrDefault().ToArmyViewModel();

            return(View(model));
        }
예제 #15
0
파일: Form1.cs 프로젝트: indij/KatanaMUD
        private void Form1_Load(object sender, EventArgs e)
        {
            var context = new GameEntities("Server=KATANAMUD\\SQLEXPRESS;Database=KatanaMUD;integrated security=True;");

            context.LoadFromDatabase();

            //var races = Btrieve.GetAllRaces(new FileInfo(@"C:\Users\spsadmin\Documents\MMUDDats\wccrace2.dat").FullName, context.RaceTemplates);
            //var classes = Btrieve.GetAllClasses(new FileInfo(@"C:\Users\spsadmin\Documents\MMUDDats\wccclas2.dat").FullName, context.ClassTemplates);
            var items = Btrieve.GetAllItems(new FileInfo(@"C:\CleanP\wccitem2.dat").FullName, context.ItemTemplates);


            //var rooms = Btrieve.GetAllRooms(new FileInfo(@"C:\CleanP\wccmp002.dat").FullName);

            //Regex r = new Regex("\\s+");
            //var descriptions = rooms.GroupBy(x => x.Description).ToList();//.OrderBy(x => x.Key).ToList();

            //foreach (var group in descriptions)
            //{
            //    var textBlock = context.TextBlocks.New();
            //    textBlock.Text = group.Key;

            //    foreach (var room in group)
            //    {
            //        var dbRoom = room.ToRoom(null);
            //        dbRoom.TextBlock = textBlock;
            //        context.Rooms.Add(dbRoom, false);
            //    }
            //}

            //foreach (var room in rooms)
            //{
            //	var dbRoom = room.ToRoom(context.Rooms.SingleOrDefault(x => x.Id == RoomBuffer.GetRoomNumber(room.MapNumber, room.RoomNumber)));
            //}



            //var notdrop = items.Where(x => x.NotDroppable != 0).ToList();
            //var retain = items.Where(x => x.RetainAfterUses != 0).ToList();
            //var destroy = items.Where(x => x.DestroyOnDeath != 0).ToList();



            //context.RaceTemplates.AddRange(races, true);
            //context.ClassTemplates.AddRange(classes, true);
            //context.ItemTemplates.AddRange(items, true);
            context.SaveChanges();
        }
예제 #16
0
        public IHttpActionResult GetActive()
        {
            try
            {
                using (var db = new GameEntities())
                {
                    //Get all users whose status is active.
                    List <AspNetUser> activeUsers = db.AspNetUsers.Where(au => au.Active).ToList();

                    return(Ok(activeUsers));
                }
            }
            catch (Exception e)
            {
                return(Content(System.Net.HttpStatusCode.InternalServerError, "The server encountered an error. Please inform the development team."));
            }
        }
        public ActionResult Delete(int id)
        {
            GameEntities ent = new GameEntities();

            List <Army> army = ent.Armies.Where(x => x.KingdomId == id).ToList();

            foreach (Army a in army)
            {
                ent.Armies.Remove(a);
            }


            Kingdom kingdom = ent.Kingdoms.Where(x => x.Id == id).First();

            ent.Kingdoms.Remove(kingdom);
            ent.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #18
0
 public IHttpActionResult GetAll()
 {
     try
     {
         using (var db = new GameEntities())
         {
             var users = db.AspNetUsers.Where(u => u.Active == true).Select(x => new { x.Id, x.UserName }).ToList();
             return(Ok(users));
         }
     }
     catch (ArgumentNullException e)
     {
         return(NotFound());
     }
     catch (Exception e)
     {
         return(Content(System.Net.HttpStatusCode.InternalServerError, "The server was unable to retrieve the list of users. Please inform the development team."));
     }
 }
        public ActionResult Edit(KingdomModel kingdom)
        {
            if (ModelState.IsValid) // jezeli spelnia atrybuty, walidatory np. Required
            {
                GameEntities ent = new GameEntities();
                Kingdom      k   = ent.Kingdoms.Where(x => x.Id == kingdom.Id).FirstOrDefault();
                k.Name       = kingdom.Name;
                k.Place      = kingdom.Place;
                k.Population = kingdom.Population;

                ent.Entry(ent.Kingdoms.Where(x => x.Id == k.Id).First()).CurrentValues.SetValues(k);
                ent.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(kingdom));
            }
        }
예제 #20
0
        public IHttpActionResult UpdatePersonalDetails(AspNetUser user)
        {
            try
            {
                using (var db = new GameEntities())
                {
                    AspNetUser u = db.AspNetUsers.Single(us => us.Id == user.Id);

                    if (user.LastName != null)
                    {
                        u.LastName = user.LastName;
                    }

                    if (user.FirstName != null)
                    {
                        u.FirstName = user.FirstName;
                    }

                    if (user.Email != null && ValidEmailCheck(user.Email))
                    {
                        u.Email = user.Email;
                    }

                    if (user.PhoneNumber != null && ValidPhoneNumCheck(user.PhoneNumber))
                    {
                        u.PhoneNumber = user.PhoneNumber;
                    }

                    db.SaveChanges();

                    return(Ok());
                }
            }
            catch (ArgumentNullException e)
            {
                return(Content(System.Net.HttpStatusCode.BadRequest, "No data found."));
            }
            catch (Exception e)
            {
                return(Content(System.Net.HttpStatusCode.InternalServerError, "The server encountered an error and was unable to create the game. Please inform the development team."));
            }
        }
예제 #21
0
 public IHttpActionResult DeleteUser()
 {
     try
     {
         using (var db = new GameEntities())
         {
             db.AspNetUsers.Single(x => x.UserName == User.Identity.Name).Active = false; // set active to false
             db.SaveChanges();
         }
         return(Ok("The user account has been successfully deactivated."));
     }
     catch (ArgumentNullException e)
     {
         return(Content(System.Net.HttpStatusCode.InternalServerError, "The user account could not be deleted because it does not exist in the database."));
     }
     catch (Exception e)
     {
         return(Content(System.Net.HttpStatusCode.InternalServerError, "The server encountered an error while attempting to deactive the account. Please inform the development team."));
     }
 }
예제 #22
0
        public void Update(CanvasTimingInformation timing)
        {
            Debug.WriteLine("Canvas Update {0}", timing.UpdateCount);

            if (NewGameEntities.Count > 0)
            {
                GameEntities.AddRange(NewGameEntities);
                NewGameEntities.Clear();
            }


            // Collidings ?
            GameEntities = new List <GameEntity>(GameEntities.Where(gameEntity => gameEntity.NotCollidingWith(GameEntities)).ToList());


            foreach (GameEntity gameEntity in GameEntities)
            {
                gameEntity.Update(timing);
            }
        }
예제 #23
0
        public IHttpActionResult GetGameHistory(int id)
        {
            try
            {
                using (var db = new GameEntities())
                {
                    List <GameState> myGames = db.Games.Single(g => g.ID == id).GameStates.ToList();

                    return(Ok(myGames));
                }
            }
            catch (ArgumentNullException e)
            {
                return(Content(System.Net.HttpStatusCode.NotFound, "No game with the ID specified was found in the database."));
            }
            catch (Exception e)
            {
                return(Content(System.Net.HttpStatusCode.InternalServerError, "The server encountered an error when attempting to retrieve the game history. Please inform the development team."));
            }
        }
예제 #24
0
 public IHttpActionResult GetPersonalDetails()
 {
     try
     {
         using (var db = new GameEntities())
         {
             AspNetUser           u      = db.AspNetUsers.Single(x => x.UserName == User.Identity.Name);
             UserDetailsViewModel holder = new UserDetailsViewModel(u);
             return(Ok(holder));
         }
     }
     catch (ArgumentNullException e)
     {
         return(Content(System.Net.HttpStatusCode.InternalServerError, "The user account could not be found in the database."));
     }
     catch (Exception e)
     {
         return(Content(System.Net.HttpStatusCode.InternalServerError, "The server encountered an error while attempting to deactive the account. Please inform the development team."));
     }
 }
        public ActionResult Index()
        {
            GameEntities ent = new GameEntities();

            List <KingdomModel> kingdom = new List <KingdomModel>();

            foreach (Kingdom k in ent.Kingdoms.ToList())
            {
                KingdomModel king = new KingdomModel();
                king.Id         = k.Id;
                king.Name       = k.Name;
                king.Place      = k.Place;
                king.Population = k.Population;

                kingdom.Add(king);
            }


            return(View(kingdom));
        }
        public ActionResult Create(KingdomModel k)
        {
            if (ModelState.IsValid)
            {
                GameEntities ent  = new GameEntities();
                Kingdom      king = new Kingdom();
                king.Name       = k.Name;
                king.Place      = k.Place;
                king.Population = k.Population;

                ent.Kingdoms.Add(king);
                ent.SaveChanges();


                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(k));
            }
        }
예제 #27
0
        public IHttpActionResult GetByUserID(string id)
        {
            try
            {
                using (var db = new GameEntities())
                {
                    // Populates and returns a user view model
                    AspNetUser    user       = db.AspNetUsers.Single(u => u.Id.Equals(id));
                    UserViewModel uViewModel = new UserViewModel(user);

                    return(Ok(uViewModel));
                }
            }
            catch (ArgumentNullException e)
            {
                return(Content(System.Net.HttpStatusCode.NotFound, "The user requested does not exist."));
            }
            catch (InvalidOperationException e)
            {
                return(Content(System.Net.HttpStatusCode.InternalServerError, "The server encountered an error attempting to retrieve the user details. Please inform the development team."));
            }
        }
        public ActionResult Index()
        {
            GameEntities ent = new GameEntities();

            List <ArmyModel> army = new List <ArmyModel>();

            foreach (Army a in ent.Armies.ToList())
            {
                ArmyModel unit = new ArmyModel();
                unit.UnitId      = a.Id;
                unit.Attack      = a.Attack;
                unit.Defence     = a.Defence;
                unit.KingdomId   = a.KingdomId;
                unit.Knowledge   = a.Knowledge;
                unit.MagicResist = a.MagicResist;
                unit.Name        = a.Name;
                unit.Quantity    = a.Quantity;

                army.Add(unit);
            }


            return(View(army));
        }
예제 #29
0
 //adding game entities to list
 public void AddEntity(GameEntity entity)
 {
     GameEntities.Add(entity);
 }
예제 #30
0
 public Terminal_Welcome1( GameEntities.GameGuiObject ownerEntity )
     : base(ownerEntity)
 {
     this.__ownerEntity = ownerEntity;
     ownerEntity.PostCreated += delegate( Engine.EntitySystem.Entity __entity, System.Boolean loaded ) { if( Engine.EntitySystem.LogicSystemManager.Instance != null )PostCreated( loaded ); };
 }
예제 #31
0
 public Door_Welcome( GameEntities.AutomaticOpenDoor ownerEntity )
     : base(ownerEntity)
 {
     this.__ownerEntity = ownerEntity;
     ownerEntity.PostCreated += delegate( Engine.EntitySystem.Entity __entity, System.Boolean loaded ) { if( Engine.EntitySystem.LogicSystemManager.Instance != null )PostCreated( loaded ); };
 }
예제 #32
0
파일: Game.cs 프로젝트: indij/KatanaMUD
        async public static void Run()
        {
            ScriptManager.LoadScripts();
            Data = new GameEntities("Server=KATANAMUD\\SQLEXPRESS;Database=KatanaMUD;integrated security=True;");
            Data.LoadFromDatabase();

            var gameTime = Data.Settings.Find("GameTime");

            if (gameTime == null)
            {
                GameTime       = new TimeSpan(0);
                gameTime       = Data.Settings.New("GameTime");
                gameTime.Value = 0.ToString();
            }
            else
            {
                GameTime = new TimeSpan(long.Parse(gameTime.Value));
            }

            DateTime lastTime = DateTime.UtcNow;
            var      saveTime = lastTime.AddMinutes(1);

            Console.WriteLine("KatanaMUD 0.2 Server Started");
            while (true)
            {
                try
                {
                    var newTime        = DateTime.UtcNow;
                    var timeDifference = newTime.Subtract(lastTime);
                    GameTime       = GameTime.Add(timeDifference);
                    gameTime.Value = GameTime.Ticks.ToString();

                    // handle connections/disconnections
                    Connections.HandleConnectsAndDisconnects();

                    // Handle all timed events.
                    while (_eventQueue.Count > 0 && _eventQueue.FindMin().ExecutionTime < GameTime)
                    {
                        var ev = _eventQueue.DeleteMin();
                        ev.Execute();
                    }

                    // Grab a snapshot of all active actors (will clear the active list)
                    var actors = ActiveActors.Snapshot();

                    // Extract the messages from the actors, and order them by time.
                    var messages = actors.Select(x =>
                    {
                        bool remaining;
                        var message = x.GetNextMessage(out remaining);
                        return(Tuple.Create(x, message, remaining));
                    }).OrderBy(x => x.Item2?.MessageTime).ToList();

                    // If any actors have more messages, re-add them to the active list.
                    // we only grab the top message from each actor because each action may have a time component to it,
                    // so that if the action causes the user to pause, we cannot process the second message yet.
                    // We'll grab the next message on the next game loop. It's not the best system, but it's
                    // workable, and it serves to effectively limit messages to 1 per loop, or about 10-20 per second
                    // depending on how long the loop sleep period is. I don't believe this will be a problem in practice,
                    // though I suppose there's always the possibility of a timing exploit somewhere.
                    foreach (var message in messages.Where(x => x.Item3 == true))
                    {
                        ActiveActors.Add(message.Item1);
                    }

                    foreach (var message in messages.Where(x => x.Item2 != null))
                    {
                        message.Item2.Process(message.Item1);
                    }

                    //TODO: This could really be done in parallel, or even on separate threads.
                    // I figure this should be addressed sooner rather than later, since once combat is enabled, output messages could get
                    // laggy if we simply perform awaits on each one instead of letting the hardware do its thing and go on to the next.
                    foreach (var connection in Connections.GetConnections())
                    {
                        var handler = connection?.Actor?.MessageHandler as ConnectionMessageHandler;
                        if (handler != null)
                        {
                            await handler.SendMessages();
                        }
                    }


                    lastTime = newTime;

                    // Save changes to the database.
                    if (Data.ForceSave || saveTime < newTime)
                    {
                        Data.ForceSave = false;
                        // TODO: Make the save time configurable eventually.
                        saveTime = newTime.AddMinutes(1);
                        Data.SaveChanges();
                    }

                    Thread.Sleep(50);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(String.Format("[{0}] Exception: {1}", DateTime.Now.ToShortTimeString(), ex.ToString()));
                }
            }
        }