Ejemplo n.º 1
0
        private IEnumerator <ITask> OnStartup()
        {
            #region CODECLIP 02-3
            PartnerType      remote    = FindPartner("Remote");
            ds.DirectoryPort remoteDir = DirectoryPort;

            if (remote != null && !string.IsNullOrEmpty(remote.Service))
            {
                remoteDir = ServiceForwarder <ds.DirectoryPort>(remote.Service);
            }
            #endregion

            #region CODECLIP 02-4
            cs.ConstructorPort remoteConstructor = ConstructorPort;
            ds.Query           query             = new ds.Query(
                new ds.QueryRequestType(
                    new ServiceInfoType(cs.Contract.Identifier)
                    )
                );

            remoteDir.Post(query);
            yield return((Choice)query.ResponsePort);

            ds.QueryResponseType queryRsp = query.ResponsePort;
            if (queryRsp != null)
            {
                remoteConstructor = ServiceForwarder <cs.ConstructorPort>(queryRsp.RecordList[0].Service);
            }
            #endregion

            #region CODECLIP 02-5
            string    clockService = null;
            cs.Create create       = new cs.Create(new ServiceInfoType(rst4.Contract.Identifier));
            remoteConstructor.Post(create);
            yield return((Choice)create.ResponsePort);

            CreateResponse createRsp = create.ResponsePort;
            if (createRsp != null)
            {
                clockService = createRsp.Service;
            }
            else
            {
                LogError((Fault)create.ResponsePort);
                yield break;
            }

            _clockPort = ServiceForwarder <rst4.ServiceTutorial4Operations>(clockService);
            #endregion

            rst4.Get get;
            yield return(_clockPort.Get(GetRequestType.Instance, out get));

            rst4.ServiceTutorial4State state = get.ResponsePort;

            if (state != null)
            {
                ServiceTutorial7State initState = new ServiceTutorial7State();

                PartnerType partner = FindPartner("Local");
                if (partner != null)
                {
                    initState.Clocks.Add(partner.Service);
                }
                initState.Clocks.Add(clockService);

                Replace replace = new Replace();
                replace.Body = initState;

                _mainPort.Post(replace);
            }
            else
            {
                LogError("Unable to Get state from ServiceTutorial4", (Fault)get.ResponsePort);
                yield break;
            }

            rst4.Subscribe subscribe;
            yield return(_clockPort.Subscribe(_clockNotify, out subscribe));

            if ((Fault)subscribe.ResponsePort != null)
            {
                LogError("Unable to subscribe to remote ServiceTutorial4", (Fault)subscribe.ResponsePort);
            }

            yield return(_localClockPort.Subscribe(_localClockNotify, out subscribe));

            if ((Fault)subscribe.ResponsePort != null)
            {
                LogError("Unable to subscribe to local ServiceTutorial4", (Fault)subscribe.ResponsePort);
            }
        }
Ejemplo n.º 2
0
 public IEnumerator <ITask> ReplaceHandler(Replace replace)
 {
     _state = replace.Body;
     replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
     yield break;
 }