public UpdateVersionActor() { Receive <VersionInfo>(info => { var db = new Db(); if (AppInfo.version != info.version) { logger.Info("更新数据库..."); AssetManage.LoadDatabase(info.version); logger.Info("更新完成,版本:" + info.version); } AppInfo.version = info.version; AppInfo.dateVer = info.dateVer; AppInfo.dataVer = info.version; foreach (var item in db.systemInfos) { if (item.name == "version") { item.value = info.version; } else if (item.name == "dateVer") { item.value = info.dateVer; } else if (item.name == "dataVer") { item.value = info.version; } } db.SaveChanges(); Sender.Tell(true); db.Dispose(); }); }
protected JsonResult <JsonModel> InitDatabase() { var version = db.systemInfos.Find("dataVer"); if (version == null) { return(Json(-1, "找不到版本配置信息")); } if (AssetManage.Database == null) { AssetManage.LoadDatabase(version.value); } return(Json(0, null)); }
static void Main(string[] args) { InitLog4Net(); system = ActorSystem.Create("regist"); try { var db = new Db(); admin = db.users.Where(u => u.username == "super_admin").FirstOrDefault(); var dataVer = db.GetSystemInfoById("dataVer").value; db.Dispose(); AssetManage.LoadDatabase(dataVer); logger.Info("启动成功"); } catch (Exception ex) { logger.Error(ex); CloseApp(); return; } for (int k = 0; k < taskCount; k++) { Task.Factory.StartNew(async() => { while (!registError) { await Regist(); } Interlocked.Increment(ref threadEnd); if (threadEnd == taskCount) { CloseApp(); } }); if (taskDelay > 0) { Thread.Sleep(taskDelay); } } Thread.Sleep(TimeSpan.FromHours(1)); CloseApp(); }
static void Main(string[] args) { InitLog4Net(); var config = ConfigurationFactory.ParseString(@" akka { stdout-loglevel = DEBUG loglevel = DEBUG actor { provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" } remote { helios.tcp { transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote"" applied-adapters = [] transport-protocol = tcp hostname = localhost } } }").WithFallback(ConfigurationFactory.ParseString("akka.remote.retry-gate-closed-for = 60s")); system = ActorSystem.Create("console", config); Db db = null; try { db = new Db(); admin = db.users.Where(u => u.username == "super_admin").FirstOrDefault(); } catch (Exception ex) { CloseApp(); return; } var dataVer = db.GetSystemInfoById("dataVer").value; var time = DateTime.Now.Date; var roles = db.userRoles.AsNoTracking().Where(u => !u.chaptered && ((u.user_id == 0 && u.inited == true) || (u.user_id == admin.id && u.inited == true) && db.devices.Any(d => d.id == u.device_id && d.platform_type == platform))).OrderBy(r => r.last_task_time).Take(dataCount).ToList(); var ids = roles.Select(r => r.id.ToString()).Aggregate((a, b) => a + "," + b); db.Database.ExecuteSqlCommand("update user_role set last_task_time=@p0 where id in(" + ids + ")", DateTime.Now); db.Dispose(); Console.WriteLine("加载资料库"); AssetManage.LoadDatabase(dataVer); Console.WriteLine(roles.Count + "个帐号"); int i = 0; if (roles.Count > 0) { for (int k = 0; k < taskCount; k++) { Task.Factory.StartNew(async() => { bool end = false; user_role role = null; start: Monitor.Enter(typeof(Program)); if (!registError && i < roles.Count) { role = roles[i]; i++; } else { end = true; } Monitor.Exit(typeof(Program)); if (!end) { await Battle(role); goto start; } Interlocked.Increment(ref threadEnd); logger.Info("Task" + threadEnd + " End"); if (threadEnd >= taskCount * 0.8) { CloseApp(); } }); if (taskDelay > 0) { Thread.Sleep(taskDelay); } } } else { Thread.Sleep(TimeSpan.FromMinutes(1)); CloseApp(); } Thread.Sleep(TimeSpan.FromHours(1)); CloseApp(); }
static void Main(string[] args) { if (!Process.GetProcesses().Any(p => p.ProcessName.ToLower().IndexOf("namecollect") != -1)) { var dir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); Process.Start(dir + "/Unreal.Bili.NameCollect.exe"); } InitLog4Net(); var config = ConfigurationFactory.ParseString(@" akka { stdout-loglevel = DEBUG loglevel = DEBUG actor { provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" } remote { helios.tcp { transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote"" applied-adapters = [] transport-protocol = tcp hostname = localhost port = 0 } client { reconnect-delay = 1 # in seconds (5 sec default) read-timeout = 10 # in seconds (10 sec default) reconnection-time-window = 0 # the maximum time window that a client should try to reconnect for } } }").WithFallback(ConfigurationFactory.ParseString("akka.remote.retry-gate-closed-for = 60s")); system = ActorSystem.Create("console", config); system.EventStream.Subscribe(system.ActorOf <DeadActor>(), typeof(DeadLetter)); Db db = null; try { db = new Db(); admin = db.users.Where(u => u.username == "super_admin").FirstOrDefault(); } catch (Exception ex) { CloseApp(); return; } var dataVer = db.GetSystemInfoById("dataVer").value; var time = DateTime.Now.Date; var roles = db.userRoles.AsNoTracking().Where(u => (u.user_id == 0 && u.inited == false) || (u.user_id == admin.id && u.last_update_time < time)).OrderBy(u => u.last_task_time).Take(dataCount).ToList(); if (roles.Count > 0) { var ids = roles.Select(r => r.id.ToString()).Aggregate((a, b) => a + "," + b); db.Database.ExecuteSqlCommand("update user_role set last_task_time=@p0 where id in(" + ids + ")", DateTime.Now); db.Dispose(); } Console.WriteLine("加载资料库"); AssetManage.LoadDatabase(dataVer); Console.WriteLine("需要" + roles.Count + "次初始"); int i = 0; if (roles.Count > 0) { for (int k = 0; k < taskCount; k++) { Task.Factory.StartNew(async() => { bool end = false; user_role role = null; start: Monitor.Enter(typeof(Program)); if (!registError && i < roles.Count) { role = roles[i]; i++; } else { end = true; } Monitor.Exit(typeof(Program)); if (!end) { await Init(role); goto start; } Interlocked.Increment(ref threadEnd); logger.Info("Task" + threadEnd + " End"); if (threadEnd >= taskCount) { CloseApp(); } }); if (taskDelay > 0) { Thread.Sleep(taskDelay); } } } else { Thread.Sleep(TimeSpan.FromMinutes(1)); CloseApp(); return; } Task.Factory.StartNew(async() => { await Task.Delay(TimeSpan.FromHours(1)); CloseApp(); }); while (!exit) { Thread.Sleep(TimeSpan.FromSeconds(5)); } Thread.Sleep(TimeSpan.FromSeconds(5)); }
public bool Bootstrap() { Db Db = new Db(); foreach (var item in Db.systemInfos.AsNoTracking().ToList()) { if (item.name == "version") { AppInfo.version = item.value; } else if (item.name == "dateVer") { AppInfo.dateVer = item.value; } else if (item.name == "dataVer") { AppInfo.dataVer = item.value; } else if (item.name == "appVer") { AppInfo.appVer = item.value; } } AssetManage.LoadDatabase(AppInfo.dataVer); var admin = Db.users.Where(u => u.username == "super_admin").FirstOrDefault(); Db.Dispose(); var config = ConfigurationFactory.ParseString(@" akka { actor { provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" } remote { helios.tcp { transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote"" applied-adapters = [] transport-protocol = tcp port = " + Const.TaskServiceSystemPort + @" hostname = localhost } } } "); try { system = ActorSystem.Create(Const.TaskService, config); { system.ActorOf <TaskCheckeActor>().Tell(""); system.ActorOf <Login>(Const.LoginActor); system.ActorOf <BattleSetup>(Const.BattleSetupActor); system.ActorOf <BattleResult>(Const.BattleResultActor); if (admin != null) { //system.ActorOf<AdminRoleInit>().Tell(admin.id); //system.ActorOf<AdminRoleLogin>().Tell(admin.id); } } } catch (Exception ex) { logger.Error("System Bootstrap Fail", ex); return(false); } return(true); }
public IHttpActionResult getMapData(string callback = "") { var root = System.Web.HttpContext.Current.Server.MapPath("~/"); var version = db.systemInfos.Find("dataVer"); if (version == null) { return(Json(-1, "找不到版本配置信息")); } if (!File.Exists(root + "map_" + version.value + ".json")) { AssetManage.LoadDatabase(version.value); var map = new MapData(); //map.eventQuests = AssetManage.Database.mstEventQuest; map.events = AssetManage.Database.mstEvent; map.questGroups = AssetManage.Database.mstQuestGroup; //map.messions = AssetManage.Database.mstMission; map.svtGroups = AssetManage.Database.mstSvtGroup; map.wars = new List <War>(); Mapper.Initialize((config) => { config.CreateMap <mstWar, War>(); config.CreateMap <mstQuest, Quest>(); config.CreateMap <mstSpot, Spot>(); config.CreateMap <mstSpotRoad, SpotRoad>(); }); AutoMapper.Mapper.Map(AssetManage.Database.mstWar, map.wars); foreach (var war in map.wars) { war.spots = new List <Spot>(); foreach (var spot in AssetManage.Database.mstSpot) { if (spot.warId == war.id) { var nspot = Mapper.Map <mstSpot, Spot>(spot); war.spots.Add(nspot); nspot.quests = new List <Quest>(); foreach (var quest in AssetManage.Database.mstQuest) { if (quest.spotId == spot.id) { var nquest = Mapper.Map <mstQuest, Quest>(quest); nspot.quests.Add(nquest); nquest.phases = new List <mstQuestPhase>(); nquest.releases = new List <mstQuestRelease>(); foreach (var phase in AssetManage.Database.mstQuestPhase) { if (phase.questId == quest.id) { nquest.phases.Add(phase); } } foreach (var release in AssetManage.Database.mstQuestRelease) { if (release.questId == quest.id) { nquest.releases.Add(release); } } } } } } war.spotRoads = new List <SpotRoad>(); foreach (var spotRoad in AssetManage.Database.mstSpotRoad) { if (spotRoad.warId == war.id) { war.spotRoads.Add(Mapper.Map <mstSpotRoad, SpotRoad>(spotRoad)); } } } File.WriteAllText(root + "map_" + version.value + ".json", JsonConvert.SerializeObject(map)); QiniuHelper.Upload("map_" + version.value + ".json", root + "map_" + version.value + ".json"); } var url = "http://oj3vd47gp.bkt.clouddn.com/map_" + version.value + ".json"; return(Redirect(url)); }