예제 #1
0
 public ServerBase[] GetServers()
 {
     using (var dc = new Arma3BeServiceContext())
     {
         return dc.ServerInfo.OrderBy(x => x.Name).ToArray().Select(x => x.Map<ServerBase>()).ToArray();
     }
 }
예제 #2
0
        public ServerBase AddOrUpdateServer(Server server)
        {
            if (server.Id == Guid.Empty)
            {
                server.Id = Guid.NewGuid();

                using (var dc = new Arma3BeServiceContext())
                {
                    var res = dc.ServerInfo.Add(server.Map<ServerInfo>()).Map<ServerBase>();
                    dc.SaveChanges();
                    return res;
                }
            }
            else
            {
                using (var dc = new Arma3BeServiceContext())
                {
                    var s = dc.ServerInfo.Single(x => x.Id == server.Id);
                    s.Host = server.Host;
                    s.Name = server.Name;
                    s.Password = server.Password;
                    s.Active = server.Active;
                    s.Port = server.Port;
                    dc.SaveChanges();
                    return s.Map<ServerBase>();
                }
            }
        }
예제 #3
0
        public void Run()
        {
            using (var dc = new Arma3BeServiceContext())
            {
                foreach (var serverInfo in dc.ServerInfo)
                {
                    var model = new ServerWorker(serverInfo, _log);
                    var thread = new Thread(x => { model.Run(); });

                    _models.Add(serverInfo.Id, new Tuple<Thread, ServerWorker>(thread, model));
                    thread.Start();
                }
            }
        }
예제 #4
0
 static Arma3BeServiceContext()
 {
     Database.SetInitializer(new DbInitializer());
     using (var db = new Arma3BeServiceContext())
         db.Database.Initialize(false);
 }