Example #1
0
        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            IStardustContext ctx = null;

            try
            {
                ctx = ContextScopeExtensions.CreateScope();
                if (request.Version.Envelope == EnvelopeVersion.None)
                {
                    runtime = RuntimeFactory.CreateRuntime();
                    runtime.GetStateStorageContainer().TryAddStorageItem((ThreadSynchronizationContext)ctx, Synccontext);
                    var httpRequest = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
                    if (httpRequest != null)
                    {
                        var msg = httpRequest.Headers["X-Stardust-Meta"];
                        if (msg.ContainsCharacters())
                        {
                            try
                            {
                                var item = Resolver.Activate <IReplaceableSerializer>().Deserialize <RequestHeader>(Convert.FromBase64String(msg).GetStringFromArray());
                                request.Properties.Add("autoHeader", item);
                                runtime.GetStateStorageContainer().TryAddStorageItem(true, "isRest");
                            }
                            catch
                            {
                            }
                        }
                    }

                    return(ctx);
                }
                if (request.Headers.Any(messageHeader => messageHeader.Name == "HeaderInfoIncluded"))
                {
                    runtime = RuntimeFactory.CreateRuntime();
                    runtime.GetStateStorageContainer().TryAddStorageItem((ThreadSynchronizationContext)ctx, Synccontext);
                    return(ctx);
                }
                ;
                var header = request.Headers.GetHeader <RequestHeader>("RequestHeader", RequestHeader.NS);
                request.Properties.Add("autoHeader", header);
                runtime = RuntimeFactory.CreateRuntime();
                runtime.GetStateStorageContainer().TryAddStorageItem((ThreadSynchronizationContext)ctx, Synccontext);
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            return(ctx);
        }
 public static IStardustContext CreateScope()
 {
     return(ContextScopeExtensions.CreateScope());
 }