Exemplo n.º 1
0
        /// <summary>
        /// 创建Server服务器,地址绑定成功后,使用PubSocket发布出去ServerReady信息,
        /// 客户端的SubSocket接收到信息后,开始链接Server服务器
        ///
        /// </summary>
        void WarBegin()
        {
            //War Data Model is passed by Lua(what ever)
            IWarModel warModel = new DebugModel();

            warInfo = new WarInfo()
            {
                warMo = WarMode.NativeWar,
                                #if Server
                Side = WarSide.ServerAndClient,
                RequiredClientCount = 2,

                Map       = warModel.getMap(),
                Charactor = warModel.getCharactor(WarCamp.FirstCamp),

                ServerIp = "127.0.0.1",
                                #else
                Side      = WarSide.OnlyClient,
                Charactor = warModel.getCharactor(WarCamp.SecondCamp),
                ServerIp  = "192.168.1.176",               //TODO : real ip (not loopback)
                                #endif
            };

            if (warInfo.Side == WarSide.ServerAndClient)            //启动server
            {
                Server = new RealServer(warInfo, ServerRepOk, ServerPubOK);
            }
            else             //启动client , 这个client不和服务器端在一个物理设备上
            {
                Client = new RealClient(warInfo);
            }
        }
Exemplo n.º 2
0
        public void RealServer_DisplayResult_ShouldReturn_SearchDetails(string search)
        {
            RealServer real = new RealServer(search);
            string     str  = "Displaying  Result From Real Server : " + search;

            Assert.Equal(real.DisplayResult(), str);
        }
        public async Task <IActionResult> PutRealServer([FromRoute] int id, [FromBody] RealServer realServer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != realServer.server_ID)
            {
                return(BadRequest());
            }

            _context.Entry(realServer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RealServerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        /// <summary>
        /// The process record.
        /// </summary>
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            try
            {
                Status status = Connection.ApiClient.CreateRealServer(Network.id, Name, Server.id, InService).Result;
                if (status != null && PassThru.IsPresent)
                {
                    // Regex to extract the Id from the status result detail: Real-Server (id:b1a3aea6-37) created
                    var   regexObj = new Regex(@"\x28id\x3A([-\w]*)\x29");
                    Match match    = regexObj.Match(status.resultDetail);
                    if (match.Success && match.Groups.Count > 1)
                    {
                        var rserver = new RealServer
                        {
                            id         = match.Groups[1].Value,
                            name       = Name,
                            inService  = InService.ToString().ToLower(),
                            serverName = Server.name,
                            serverId   = Server.id,
                            serverIp   = Server.privateIp
                        };
                        WriteObject(rserver);
                    }
                    else
                    {
                        WriteError(new ErrorRecord(new CloudComputePsException("object Id not returned from API"), "-1",
                                                   ErrorCategory.InvalidData, status));
                    }
                }

                WriteDebug(
                    string.Format(
                        "{0} resulted in {1} ({2}): {3}",
                        status.operation,
                        status.result,
                        status.resultCode,
                        status.resultDetail));
            }
            catch (AggregateException ae)
            {
                ae.Handle(
                    e =>
                {
                    if (e is ComputeApiException)
                    {
                        WriteError(new ErrorRecord(e, "-2", ErrorCategory.InvalidOperation, Connection));
                    }
                    else
                    {
// if (e is HttpRequestException)
                        ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection));
                    }

                    return(true);
                });
            }
        }
        public async Task <IActionResult> PostRealServer([FromBody] RealServer realServer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Servers.Add(realServer);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRealServer", new { id = realServer.server_ID }, realServer));
        }