//public async Task<bool> AddServerRole(ServerRoleEnum serverRoleEnum)
        //{
        //    if (DatabaseHelper.Instance.Status == DatabaseHelperStatusEnum.CelsusDatabaseVersionOk)
        //    {

        //    }
        //    else
        //    {
        //        return false;
        //    }

        //    var serverRoleDto = new ServerRoleDto
        //    {
        //        ServerId = ComputerHelper.Instance.ServerId,
        //        ServerIP = ComputerHelper.Instance.IPAddress,
        //        ServerName = Environment.MachineName,
        //        ServerRoleEnum = serverRoleEnum,
        //        IsActive = true
        //    };

        //    return await AddServerRoleInner(serverRoleEnum, serverRoleDto);

        //}

        private async Task <bool> AddServerRoleInnerAllowOne(ServerRoleEnum serverRoleEnum, ServerRoleDto serverRoleDto)
        {
            try
            {
                using (var context = new SqlDbContext(DatabaseHelper.Instance.ConnectionInfo.ConnectionString))
                {
                    var oldRoles = await context.ServerRoles.Where(x => x.ServerRoleEnum == serverRoleEnum && x.IsActive == true).ToListAsync();

                    if (oldRoles.Count == 0)
                    {
                        context.ServerRoles.Add(serverRoleDto);
                        await context.SaveChangesAsync();
                    }
                    else if (oldRoles.Count == 1)
                    {
                        oldRoles.First().IsActive = false;
                        context.Entry(oldRoles.First()).State = System.Data.Entity.EntityState.Modified;

                        context.ServerRoles.Add(serverRoleDto);

                        await context.SaveChangesAsync();
                    }
                    else if (oldRoles.Count > 1)
                    {
                        var toDelete = oldRoles.Take(oldRoles.Count - 1).ToList();
                        foreach (var item in toDelete)
                        {
                            item.IsActive             = false;
                            context.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        }

                        oldRoles.Last().ServerId       = serverRoleDto.ServerId;
                        oldRoles.Last().ServerIP       = serverRoleDto.ServerIP;
                        oldRoles.Last().ServerName     = serverRoleDto.ServerName;
                        oldRoles.Last().ServerRoleEnum = serverRoleDto.ServerRoleEnum;
                        context.Entry(oldRoles.Last()).State = System.Data.Entity.EntityState.Modified;

                        await context.SaveChangesAsync();
                    }

                    await GetRoles();

                    NotifyPropertyChanged("");

                    return(true);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"Error occured EnsureDatabase.");
            }

            return(false);
        }
        private async Task <bool> AddServerRoleInner(ServerRoleEnum serverRoleEnum, ServerRoleDto serverRoleDto)
        {
            try
            {
                using (var context = new SqlDbContext(DatabaseHelper.Instance.ConnectionInfo.ConnectionString))
                {
                    var oldRoles = await context.ServerRoles.Where(x => x.ServerRoleEnum == serverRoleEnum && x.IsActive == true).ToListAsync();

                    if (oldRoles.Count == 0)
                    {
                        context.ServerRoles.Add(serverRoleDto);
                        await context.SaveChangesAsync();
                    }
                    else
                    {
                        if (oldRoles.Count(x => x.ServerId == serverRoleDto.ServerId && x.ServerRoleEnum == serverRoleEnum) > 0)
                        {
                            return(false);
                        }
                        else
                        {
                            context.ServerRoles.Add(serverRoleDto);
                            await context.SaveChangesAsync();
                        }
                    }

                    await GetRoles();

                    NotifyPropertyChanged("");

                    return(true);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"Error occured EnsureDatabase.");
            }

            return(false);
        }
Exemple #3
0
 public Command(string value, ServerRoleEnum role)
 {
     this.Value = value;
     this.MinimumRoleRequired = role;
 }
 public InGameCommand(string name, ServerRoleEnum role)
 {
     this.Name = name;
     this.Role = role;
 }
 public Command(string value, ServerRoleEnum role)
 {
     this.Value = value;
     this.MinimumRoleRequired = role;
 }
 internal void SetServerRole(ServerRoleEnum serverRole)
 {
     _serverRole = serverRole;
 }
 public ChatCommand(string name, ServerRoleEnum role)
 {
     this.Name = name;
     this.Role = role;
 }
Exemple #8
0
        private localRunServer()
        {
            try
            {
                localIP            = new List <string>();
                messagesNeedAction = new List <actionMessage>();
                hclient            = new HttpHelper(new TimeSpan(0, 0, 5)); //设置5秒的超时
                string AddressIP = string.Empty;
                foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                {
                    if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
                    {
                        string ipstr = _IPAddress.ToString();
                        Console.WriteLine("ip:" + ipstr);
                        localIP.Add(ipstr);
                    }
                }
                this.zoneUrls   = new List <string>();
                this.regionUrls = new List <string>();
                this.protocol   = commSetting.Configuration["urls:protocol"];
                this.ownHost    = commSetting.Configuration["urls:host"];
                this.lPort      = commSetting.Configuration["urls:port"];
                this.regionRole = ServerRoleEnum.unkown;
                this.zoneRole   = ServerRoleEnum.unkown;
                commSetting.Configuration.GetSection("gateServer:regionUrls").Bind(this.regionUrls);
                commSetting.Configuration.GetSection("gateServer:zoneUrls").Bind(this.zoneUrls);

                this.maxPerfDataCount    = int.Parse(commSetting.Configuration["gateServer:maxPerfDataCount"]);
                this.serverFailTimes     = int.Parse(commSetting.Configuration["gateServer:serverFailTimes"]);
                this.sayAliveTime        = int.Parse(commSetting.Configuration["gateServer:sayAliveTime"]);
                this.serverRemoveTimes   = int.Parse(commSetting.Configuration["gateServer:serverRemoveTimes"]);
                this.regionBroadcastTime = int.Parse(commSetting.Configuration["gateServer:regionBroadcastTime"]);
                this.region = commSetting.Configuration["gateServer:region"];
                if (string.IsNullOrEmpty(region))
                {
                    this.region = "*";//没有配置region时的默认名称
                }
                this.zone = commSetting.Configuration["gateServer:zone"];
                if (string.IsNullOrEmpty(zone))
                {
                    throw new Exception("zone is not allow null");
                }
                this.zoneclusterId = string.Format("{0}:{1}", region, zone).ToMD5();
                sayAliveTimer      = new System.Timers.Timer(sayAliveTime);
                sayAliveTimer.Stop();
                RegionBroadCastTimer = new System.Timers.Timer(regionBroadcastTime);
                RegionBroadCastTimer.Stop();

                actionDoTimer           = new Timer(actionProcessTime);
                actionDoTimer.Elapsed  += new System.Timers.ElapsedEventHandler(triggerActionMessageProcesser);
                actionDoTimer.AutoReset = true;

                checkAliveTimer           = new Timer(sayAliveTime);
                checkAliveTimer.Elapsed  += new ElapsedEventHandler(triggerCheckAlive);
                checkAliveTimer.AutoReset = true;

                this.httpProxyPort = (commSetting.Configuration["gateServer:httpProxyPort"]);


                perfCounters = new List <pCounter>();
                region_dic   = new Dictionary <string, regionZoneServer>(StringComparer.CurrentCultureIgnoreCase);
            }
            catch (Exception e)
            {
                runlog.Fatal("init system error;" + System.Environment.NewLine + e.Message);
                throw new Exception("init system error");
            }
        }