/// <summary>
        /// Redirects the HTTP request from an alternate contract to a partner
        /// </summary>
        /// <param name="contract">The contract.</param>
        /// <param name="partner">The partner.</param>
        /// <param name="context">The context.</param>
        /// <param name="responsePort">The response port.</param>
        private void RedirectHttpRequest(
            string contract,
            IPort partner,
            HttpListenerContext context,
            PortSet <HttpResponseType, Fault> responsePort)
        {
            var alternate     = AlternateContractServiceInfo.Find(s => s.Contract == contract) ?? ServiceInfo;
            var basePath      = alternate.HttpServiceAlias.AbsolutePath;
            var requestedPath = context.Request.Url.PathAndQuery;
            var pathSuffix    = requestedPath.Substring(basePath.Length);

            var lookup = new DsspDefaultLookup();

            partner.PostUnknownType(lookup);
            this.Activate(
                lookup.ResponsePort.Choice(
                    svcinfo =>
            {
                var redirectPath = svcinfo.HttpServiceAlias.AbsolutePath + pathSuffix;
                context.Response.Redirect(redirectPath);
                context.Response.Close();
                responsePort.Post(new HttpResponseType());
            },
                    responsePort.Post));
        }
Exemplo n.º 2
0
 private void UnrollPartialCommit(ICollection[] results)
 {
     for (int i = 0; i < results.Length; i++)
     {
         ICollection collection = results[i];
         IPort       port       = null;
         if (collection != null)
         {
             foreach (object current in collection)
             {
                 if (port == null)
                 {
                     IPortReceive[] ports = _ports;
                     for (int j = 0; j < ports.Length; j++)
                     {
                         IPort port2 = (IPort)ports[j];
                         if (port2.TryPostUnknownType(current))
                         {
                             port = port2;
                             break;
                         }
                     }
                 }
                 else
                 {
                     port.PostUnknownType(current);
                 }
             }
         }
     }
 }
        /// <summary>
        /// Forwards a subscription to a partner
        /// </summary>
        /// <param name="partner">The partner.</param>
        /// <param name="request">The request.</param>
        /// <param name="responsePort">The response port.</param>
        private void ForwardSubscription(
            IPort partner,
            SubscribeRequestType request,
            PortSet <SubscribeResponseType, Fault> responsePort)
        {
            var lookup = new DsspDefaultLookup();

            partner.PostUnknownType(lookup);
            this.Activate(
                lookup.ResponsePort.Choice(
                    svcinfo =>
            {
                var submgrInfo = svcinfo.PartnerList.Find(p => p.Contract == submgr.Contract.Identifier);
                var subMgrOps  = ServiceForwarder <submgr.SubscriptionManagerPort>(submgrInfo.Service);
                var insert     = new submgr.InsertSubscription(request)
                {
                    ResponsePort = responsePort
                };
                subMgrOps.Post(insert);
            },
                    responsePort.Post));
        }
        /// <summary>
        /// Validate the Motor Connection
        /// Post a Fault if the Motor is not connected.
        /// When ValidateConnection returns false, 
        /// the calling handler should exit immediately
        /// without posting to the response port.
        /// </summary>
        /// <param name="state"></param>
        /// <param name="responsePort"></param>
        /// <returns></returns>
        private bool ValidateConnection(MotorState state, IPort responsePort)
        {
            if (!state.Connected)
            {
                responsePort.PostUnknownType(
                    Fault.FromException(
                        new InvalidOperationException("The LEGO NXT Motor is not connected to a brick")));

                return false;
            }
            return true;
        }