Beispiel #1
0
        }// end AnnounceToServer

        /// <summary>
        /// 客户端策略加载完毕将队伍名称通知给Server服务实例
        /// </summary>
        /// <returns></returns>
        IEnumerator <ITask> AnnounceTeamNameToServer(string strTeamName)
        {
            // 使用Uri建立到Server服务实例主端口的Forwarder引用
            server.Sim2DSvrOperations serverPort = ServiceForwarder <server.Sim2DSvrOperations>(_strServerUri);
            if (serverPort == null)
            {
                yield break;
            }

            // ClientAnnounceTeamName是Server服务主端口接受的一种消息类型
            server.ClientAnnounceTeamName announce = new server.ClientAnnounceTeamName();

            // 将队伍半场和队伍名字组成“队伍半场-队伍名字”的字符串,作为要发送到Server服务实例的信息
            // 便于Server收到消息后判断该队伍名字是A队发来的还是B队发来的
            //announce.Body = new server.ClientAnnounceTeamNameRequest(ServiceInfo.Service, _halfCourt + "-" + strTeamName);
            announce.Body = new server.ClientAnnounceTeamNameRequest(AlternateContractServiceInfo[0].Service, _teamId, strTeamName);
            serverPort.Post(announce);

            // 不关心消息发出后的结果,但最好等待一下消息发送后响应端口的返回信息
            DefaultUpdateResponseType announceRsp = null;

            yield return(Arbiter.Choice(announce.ResponsePort,
                                        delegate(DefaultUpdateResponseType rsp)
            {
                announceRsp = rsp;
            },
                                        delegate(Fault f)
            {
                //LogError("Announce failed, continue announcing", f);
                Console.WriteLine("Announce failed, continue announcing team name");
                //added  20110117
                WinFormsServicePort.FormInvoke(delegate()
                {
                    _clientControlBoard.DisplayCompetitionState(string.Format("Connection failed"));
                });
                SpawnIterator <string>(_teamName, AnnounceTeamNameToServer);
            }
                                        ));

            if (announceRsp == null)
            {
                yield break;
            }
        }// end AnnounceToServer
Beispiel #2
0
        }// end AnnounceToServer

        /// <summary>
        /// 当Client用户界面的Ready按钮按下之后,通知Server服务实例该队已经准备完毕。
        /// </summary>
        /// <returns></returns>
        IEnumerator <ITask> AnnounceReadyToServer()
        {
            // 每次重新Ready的时候清除策略调用异常标志 LiYoubing 20110712
            //_strategyExceptionFlag = false;

            // 使用Uri建立到Server服务实例主端口的Forwarder引用
            server.Sim2DSvrOperations serverPort = ServiceForwarder <server.Sim2DSvrOperations>(_strServerUri);
            if (serverPort == null)
            {
                yield break;
            }

            _isReady = true;

            // ClientAnnounceReady是Server服务主端口接受的一种消息类型
            server.ClientAnnounceReady announce = new server.ClientAnnounceReady();
            announce.Body = new server.ClientAnnounceReadyRequest(_teamId);
            serverPort.Post(announce);

            // 不关心消息发出后的结果,但最好等待一下消息发送后响应端口的返回信息
            DefaultUpdateResponseType announceRsp = null;

            yield return(Arbiter.Choice(announce.ResponsePort,
                                        delegate(DefaultUpdateResponseType rsp)
            {
                announceRsp = rsp;
            },
                                        delegate(Fault f)
            {
                //LogError("Announce failed, continue announcing", f);
                Console.WriteLine("Announce failed, continue announcing ready");
                SpawnIterator(AnnounceReadyToServer);
            }
                                        ));

            if (announceRsp == null)
            {
                yield break;
            }
        }// end AnnounceReadyToServer
Beispiel #3
0
        /// <summary>
        /// Service start
        /// </summary>
        protected override void Start()
        {
            base.Start();

            //_serverNotificationPort = ServiceForwarder<server.Sim2DSvrOperations>(_strServerUri);

            // combine with our main coordination
            MainPortInterleave.CombineWith(
                Arbiter.Interleave(
                    new TeardownReceiverGroup(),
                    new ExclusiveReceiverGroup(
                        Arbiter.Receive <FromClientUiMsg>(true, _fromClientUiPort, OnClientUiMessageHandler)
                        ),
                    new ConcurrentReceiverGroup(
                        Arbiter.Receive <server.CompetitionTypeChanged>(true, _serverNotificationNotify, NotifyCompetitionTypeHandler),
                        Arbiter.Receive <server.CompetitionControlButton>(true, _serverNotificationNotify, CompetitionControlButtonNotificationHandler),
                        Arbiter.Receive <server.MissionPara>(true, _serverNotificationNotify, MissionParaNotificationHandler),
                        Arbiter.Receive <client.HeartBeat>(true, _clientBasePort, HeartBeatAnnounceHandler),
                        Arbiter.Receive <client.TeamIdChanged>(true, _clientBasePort, TeamIdChangedAnnounceHandler)
                        )
                    )
                );

            WinFormsServicePort.Post(new RunForm(CreateForm)); // 显示客户端界面

            // 从Manifest文件获取Server服务实例的Uri
            PartnerType partnerTypeServer = FindPartner("Server");

            if (partnerTypeServer != null)
            {
                _strServerUri           = partnerTypeServer.Service;
                _serverNotificationPort = ServiceForwarder <server.Sim2DSvrOperations>(_strServerUri);
            }

            //server.Subscribe subscribe;
            //_serverNotificationPort.Subscribe(_serverNotificationNotify, out subscribe);
        }
Beispiel #4
0
        }// end OnWinformMessageHandler...

        /// <summary>
        /// Client服务实例初始化完毕将ServiceUri通知给Server服务实例
        /// </summary>
        /// <returns></returns>
        IEnumerator <ITask> AnnounceUriToServer()
        {
            // 使用Uri建立到Server服务实例主端口的Forwarder引用
            server.Sim2DSvrOperations serverPort = ServiceForwarder <server.Sim2DSvrOperations>(_strServerUri);
            if (serverPort == null)
            {
                yield break;
            }

            // ClientAnnounce类必须先作为UnderwaterRobotOperations对应的PortSet的一个类型参数
            server.ClientAnnounceUri announce = new server.ClientAnnounceUri();
            //announce.Body = new server.ClientAnnounceUriRequest(ServiceInfo.Service);
            announce.Body = new server.ClientAnnounceUriRequest(AlternateContractServiceInfo[0].Service);//20101209
            serverPort.Post(announce);

            server.ClientAnnounceUriResponse announceRsp = null;
            yield return(Arbiter.Choice(announce.ResponsePort,
                                        delegate(server.ClientAnnounceUriResponse rsp)
            {
                announceRsp = rsp;

                //与Server建立Subscribe关系
                server.Subscribe subscribe;
                _serverNotificationPort.Subscribe(_serverNotificationNotify, out subscribe);
            },
                                        delegate(Fault f)
            {
                //LogError("Announce failed, continue announcing", f);
                Console.WriteLine("Announce failed, continue announcing uri");
                SpawnIterator(AnnounceUriToServer);
            }
                                        ));

            if (announceRsp == null)
            {
                yield break;
            }

            _teamCount = announceRsp.TeamCount;
            _teamId    = announceRsp.TeamId;
            _alternateServerPortUri = announceRsp.AlternateServerPortUri;

            if (_teamId < 0)
            {
                WinFormsServicePort.FormInvoke(delegate()
                {
                    _clientControlBoard.SetCompetitionType(announceRsp.MissionName);
                    _clientControlBoard.DisplayCompetitionState(string.Format("Connection rejected. Only {0} teams are allowed.", _teamCount));
                });

                //SpawnIterator(AnnounceUriToServer);
                yield break;
            }

            if (announceRsp.TeamCount == 2)
            {// 当前使命为对抗性比赛时才设置左右半场
                if (announceRsp.TeamId == 0)
                {
                    WinFormsServicePort.FormInvoke(delegate() { _clientControlBoard.SetRadioTeamState(true, false); });
                }
                else if (announceRsp.TeamId == 1)
                {
                    WinFormsServicePort.FormInvoke(delegate() { _clientControlBoard.SetRadioTeamState(false, true); });
                }
            }
            WinFormsServicePort.FormInvoke(delegate() {
                _clientControlBoard.SetTeamId(announceRsp.TeamId);
                //_clientControlBoard.SetCompetitionType(announceRsp.MissionName);
                //_clientControlBoard.SetBtnStrategyBrowseEnabledState(true);
                _clientControlBoard.OnCompetitionTypeChanged(announceRsp.MissionName);
            });
        }// end AnnounceToServer