Example #1
0
        protected static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier sctxCarrier, PValue[] args)
        {
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");
            if (args == null)
                throw new ArgumentNullException("args");

            var sctx = sctxCarrier.StackContext;

            foreach (var arg in args)
            {
                if (arg == null)
                    throw new ArgumentException("No element in seqconcat(args...) must be null.", "args");
                var xss = Map._ToEnumerable(sctx, arg);
                if (xss == null)
                    continue;
                foreach (var xsRaw in xss)
                {
                    var xs = Map._ToEnumerable(sctx, xsRaw);
                    if(xs == null)
                        throw new ArgumentException("The elements in the sequences passed to seqconcat(..) must be sequences themselves.");
                    foreach (var x in xs)
                        yield return x;
                }
            }
        }
Example #2
0
        protected override IEnumerable<PValue> CoroutineRun(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");

            var t = new Dictionary<PValue, int>();

            var sctx = sctxCarrier.StackContext;

            foreach (var arg in args)
            {
                var xs = Map._ToEnumerable(sctx, arg);
                if (xs == null)
                    continue;
                foreach (var x in xs)
                    if (t.ContainsKey(x))
                        t[x]++;
                    else
                        t.Add(x, 1);
            }

            foreach (var pair in t)
                yield return new PValueKeyValuePair(pair.Key, pair.Value);
        }
Example #3
0
        protected override IEnumerable<PValue> CoroutineRun(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");

            var t = new Dictionary<PValue, object>();

            var sctx = sctxCarrier.StackContext;

            foreach (var arg in args)
            {
                var xs = Map._ToEnumerable(sctx, arg);
                if (xs == null)
                    continue;
                foreach (var x in xs)
                    if (!t.ContainsKey(x))
                    {
                        t.Add(x, null);
                        yield return x;
                    }
            }
        }
Example #4
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                      CancellationToken cancellationToken)
        {
            var peer           = $"{request.RequestUri.Host}:{request.RequestUri.Port}";
            var contextCarrier = new ContextCarrier();
            var span           = ContextManager.CreateExitSpan(request.RequestUri.ToString(), contextCarrier, peer);

            try
            {
                Tags.Url.Set(span, request.RequestUri.ToString());
                span.AsHttp();
                span.SetComponent(ComponentsDefine.HttpClient);
                Tags.HTTP.Method.Set(span, request.Method.ToString());
                foreach (var item in contextCarrier.Items)
                {
                    request.Headers.Add(item.HeadKey, item.HeadValue);
                }
                var response = await base.SendAsync(request, cancellationToken);

                Tags.StatusCode.Set(span, response.StatusCode.ToString());
                return(response);
            }
            catch (Exception e)
            {
                span.ErrorOccurred().Log(e);
                throw;
            }
            finally
            {
                ContextManager.StopSpan(span);
            }
        }
Example #5
0
        protected static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");
            if (args == null)
                throw new ArgumentNullException("args");
            if (args.Length < 2)
                throw new PrexoniteException("TakeWhile requires at least two arguments.");

            var sctx = sctxCarrier.StackContext;

            var f = args[0];

            var i = 0;
            for (var k = 1; k < args.Length; k++)
            {
                var arg = args[k];
                var set = Map._ToEnumerable(sctx, arg);
                if (set == null)
                    continue;
                foreach (var value in set)
                    if (
                        (bool)
                            f.IndirectCall(sctx, new[] {value, i++}).ConvertTo(sctx, PType.Bool,
                                true).Value)
                        yield return value;
            }
        }
Example #6
0
        protected static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier ctxCarrier,
            PValue[] args)
        {
            if (ctxCarrier == null)
                throw new ArgumentNullException("ctxCarrier");
            if (args == null)
                throw new ArgumentNullException("args");

            if (args.Length < 1)
                throw new PrexoniteException("Limit requires at least one argument.");

            var i = 0;
            var sctx = ctxCarrier.StackContext;
            var count = (int) args[0].ConvertTo(sctx, PType.Int, true).Value;

            for (var j = 1; j < args.Length; j++)
            {
                var arg = args[j];
                var set = Map._ToEnumerable(sctx, arg);
                if (set == null)
                    throw new PrexoniteException(arg + " is neither a list nor a coroutine.");
                using (var setEnumerator = set.GetEnumerator())
                {
                    while (i++ < count && setEnumerator.MoveNext())
                    {
                        yield return setEnumerator.Current;
                    }
                    if (i >= count)
                        yield break;
                }
            }
        }
Example #7
0
        public static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier getSctx,
            PValue[] args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (getSctx == null)
                throw new ArgumentNullException("getSctx");

            if (args.Length < 1)
                throw new PrexoniteException("toseq requires one argument.");

            var xsT = args[0];
            PValue xs;

            var sctx = getSctx.StackContext;

            while (!(xs = ForceCommand.Force(sctx, xsT)).IsNull)
            {
                //Accept key value pairs directly
                var kvp = xs.Value as PValueKeyValuePair;
                if (kvp != null)
                {
                    yield return kvp.Key;
                    xsT = kvp.Value;
                }
                    //Late bound
                else
                {
                    var k = xs.DynamicCall(sctx, Runtime.EmptyPValueArray, PCall.Get, "Key");
                    yield return k;
                    xsT = xs.DynamicCall(sctx, Runtime.EmptyPValueArray, PCall.Get, "Value");
                }
            }
        }
Example #8
0
        protected static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");
            if (args == null)
                throw new ArgumentNullException("args");

            var sctx = sctxCarrier.StackContext;

            var i = 0;
            if (args.Length < 1)
                throw new PrexoniteException("Skip requires at least one argument.");

            var index = (int) args[0].ConvertTo(sctx, PType.Int, true).Value;

            for (var j = 1; j < args.Length; j++)
            {
                var arg = args[j];
                var set = Map._ToEnumerable(sctx, arg);
                if (set == null)
                    throw new PrexoniteException(arg + " is neither a list nor a coroutine.");
                foreach (var value in set)
                {
                    if (i++ >= index)
                        yield return value;
                }
            }
        }
        public void OnBegRequest(HttpWebRequest request)
        {
            var trace = Filter;

            if (trace != null)
            {
                if (!trace.IsTrace(request.RequestUri.ToString()))
                {
                    return;
                }
            }
            var contextCarrier = new ContextCarrier();
            var peer           = $"{request.RequestUri.Host}:{request.RequestUri.Port}";

            try
            {
                var span = ContextManager.CreateExitSpan(request.RequestUri.ToString(), contextCarrier, peer);
                Tags.Url.Set(span, request.RequestUri.ToString());
                span.AsHttp();
                span.SetComponent(ComponentsDefine.HttpClient);
                Tags.HTTP.Method.Set(span, request.Method.ToString());
                foreach (var item in contextCarrier.Items)
                {
                    request.Headers.Add(item.HeadKey, item.HeadValue);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 private void SetRunnable(IEnumerable <string> names)
 {
     if (names == null)
     {
         throw new ArgumentNullException("names");
     }
     _contextCarrier = new ContextCarrier(names);
 }
Example #11
0
 // Bound statically by CIL compiler
 // ReSharper disable UnusedMember.Global
 public static PValue RunStatically(StackContext sctx, PValue[] args)
     // ReSharper restore UnusedMember.Global
 {
     var carrier = new ContextCarrier();
     var corctx = new CoroutineContext(sctx, CoroutineRunStatically(carrier, args));
     carrier.StackContext = corctx;
     return sctx.CreateNativePValue(new Coroutine(corctx));
 }
Example #12
0
        /// <summary>
        ///     Executes the command.
        /// </summary>
        /// <param name = "sctx">The stack context in which to execut the command.</param>
        /// <param name = "args">The arguments to be passed to the command.</param>
        /// <returns>The value returned by the command. Must not be null. (But possibly {null~Null})</returns>
        public override PValue Run(StackContext sctx, PValue[] args)
        {
            if (sctx == null)
                throw new ArgumentNullException("sctx");
            if (args == null)
                throw new ArgumentNullException("args");

            var carrier = new ContextCarrier();
            var corctx = new CoroutineContext(sctx, CoroutineRun(carrier, args));
            carrier.StackContext = corctx;
            return sctx.CreateNativePValue(new Coroutine(corctx));
        }
Example #13
0
        protected override IEnumerable<PValue> CoroutineRun(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");

            var sctx = sctxCarrier.StackContext;

            var xss = new List<IEnumerable<PValue>>();
            foreach (var arg in args)
            {
                var xs = Map._ToEnumerable(sctx, arg);
                if (xs != null)
                    xss.Add(xs);
            }

            var n = xss.Count;
            if (n < 2)
                throw new PrexoniteException("Intersect requires at least two sources.");

            var t = new Dictionary<PValue, int>();
            //All elements of the first source are considered candidates
            foreach (var x in xss[0])
                if (!t.ContainsKey(x))
                    t.Add(x, 1);

            var d = new Dictionary<PValue, object>();
            for (var i = 1; i < n - 1; i++)
            {
                foreach (var x in xss[i])
                    if ((!d.ContainsKey(x)) && t.ContainsKey(x))
                    {
                        d.Add(x, null); //only current source
                        t[x]++;
                    }
                d.Clear();
            }

            foreach (var x in xss[n - 1])
                if ((!d.ContainsKey(x)) && t.ContainsKey(x))
                {
                    d.Add(x, null); //only current source
                    var k = t[x] + 1;
                    if (k == n)
                        yield return x;
                }
        }
Example #14
0
        public void HttpRequest(HttpRequestMessage request)
        {
            var contextCarrier = new ContextCarrier();
            var peer           = $"{request.RequestUri.Host}:{request.RequestUri.Port}";
            var span           = ContextManager.CreateExitSpan(request.RequestUri.ToString(), contextCarrier, peer);

            Tags.Url.Set(span, request.RequestUri.ToString());
            span.AsHttp();
            span.SetComponent(ComponentsDefine.HttpClient);
            Tags.HTTP.Method.Set(span, request.Method.ToString());
            foreach (var item in contextCarrier.Items)
            {
                request.Headers.Add(item.HeadKey, item.HeadValue);
            }
        }
        public void HttpRequestInStart(HttpContext httpContext)
        {
            var carrier = new ContextCarrier();

            foreach (var item in carrier.Items)
            {
                item.HeadValue = httpContext.Request.Headers[item.HeadKey];
            }

            var httpRequestSpan = ContextManager.CreateEntrySpan(httpContext.Request.Path, carrier);

            httpRequestSpan.AsHttp();
            httpRequestSpan.SetComponent(ComponentsDefine.AspNetCore);
            Tags.Url.Set(httpRequestSpan, httpContext.Request.Path);
            Tags.HTTP.Method.Set(httpRequestSpan, httpContext.Request.Method);
        }
Example #16
0
        protected override IEnumerable<PValue> CoroutineRun(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");

            if (args.Length < 1)
                throw new PrexoniteException("GroupBy requires at least one argument.");

            var f = args[0];

            var sctx = sctxCarrier.StackContext;

            var groups =
                new Dictionary<PValue, List<PValue>>();

            for (var i = 1; i < args.Length; i++)
            {
                var arg = args[i];
                var xs = Map._ToEnumerable(sctx, arg);
                if (xs == null)
                    continue;
                foreach (var x in xs)
                {
                    var fx = f.IndirectCall(sctx, new[] {x});
                    if (!groups.ContainsKey(fx))
                    {
                        var lst = new List<PValue>();
                        lst.Add(x);
                        groups.Add(fx, lst);
                    }
                    else
                    {
                        groups[fx].Add(x);
                    }
                }
            }
            // DO NO CONVERT TO LINQ, dereferencing of sctx MUST be delayed!
            // ReSharper disable LoopCanBeConvertedToQuery 
            foreach (var pair in groups)
            {
                yield return new PValueKeyValuePair(pair.Key, (PValue) pair.Value);
            }
            // ReSharper restore LoopCanBeConvertedToQuery
        }
Example #17
0
        private static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier sctxCarrier,
            IEnumerable<PValue> args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");

            var sctx = sctxCarrier.StackContext;

            var lst = new List<PValue>();

            foreach (var arg in args)
                lst.AddRange(Map._ToEnumerable(sctx, arg));

            for (var i = lst.Count - 1; i >= 0; i--)
                yield return lst[i];
        }
Example #18
0
        //function range(index, count, xs) = xs >> skip(index) >> limit(count);
        private static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");
            if (args == null)
                throw new ArgumentNullException("args");
            if (args.Length < 3)
                throw new PrexoniteException(
                    "The command range requires at least 3 arguments: [index], [count] and the [list].");

            var sctx = sctxCarrier.StackContext;

            var skipCount = (int) args[0].ConvertTo(sctx, PType.Int, true).Value;
            var returnCount = (int) args[1].ConvertTo(sctx, PType.Int, true).Value;
            var index = 0;

            for (var i = 2; i < args.Length; i++)
            {
                var arg = args[i];

                var xs = Map._ToEnumerable(sctx, arg);

                foreach (var x in xs)
                {
                    if (index >= skipCount)
                    {
                        if (index == skipCount + returnCount)
                        {
                            goto breakAll; //stop processing
                        }
                        else
                        {
                            yield return x;
                        }
                    }
                    index += 1;
                }

                breakAll:
                ;
            }
        }
Example #19
0
        protected static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (args == null)
                yield break;
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");

            var sctx = sctxCarrier.StackContext;

            foreach (var arg in args)
            {
                if (arg == null)
                    throw new ArgumentException("No element in args must be null.", "args");
                var xs = Map._ToEnumerable(sctx, arg);
                if (xs == null)
                    continue;
                foreach (var x in xs)
                    yield return x;
            }
        }
        public void BeginRequest([Property] HttpContext httpContext)
        {
            var carrier = new ContextCarrier();

            foreach (var item in carrier.Items)
            {
                item.HeadValue = httpContext.Request.Headers[item.HeadKey];
            }
            var httpRequestSpan = ContextManager.CreateEntrySpan($"{Config.AgentConfig.ApplicationCode} {httpContext.Request.Path}", carrier);

            httpRequestSpan.AsHttp();
            httpRequestSpan.SetComponent(ComponentsDefine.AspNetCore);
            Tags.Url.Set(httpRequestSpan, httpContext.Request.Path);
            Tags.HTTP.Method.Set(httpRequestSpan, httpContext.Request.Method);
            httpRequestSpan.Log(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                                new Dictionary <string, object>
            {
                { "event", "AspNetCore Hosting BeginRequest" },
                { "message", $"Request starting {httpContext.Request.Protocol} {httpContext.Request.Method} {httpContext.Request.GetDisplayUrl()}" }
            });
            httpContext.Items[HttpContextDiagnosticStrings.SpanKey] = httpRequestSpan;
        }
Example #21
0
        private void ApplicationOnBeginRequest(object sender, EventArgs e)
        {
            var httpApplication = sender as HttpApplication;
            var httpContext     = httpApplication.Context;
            var carrier         = new ContextCarrier();

            foreach (var item in carrier.Items)
            {
                item.HeadValue = httpContext.Request.Headers[item.HeadKey];
            }
            var httpRequestSpan = ContextManager.CreateEntrySpan($"{Config.AgentConfig.ApplicationCode} {httpContext.Request.Path}", carrier);

            httpRequestSpan.AsHttp();
            httpRequestSpan.SetComponent(ComponentsDefine.AspNet);
            Tags.Url.Set(httpRequestSpan, httpContext.Request.Path);
            Tags.HTTP.Method.Set(httpRequestSpan, httpContext.Request.HttpMethod);
            httpRequestSpan.Log(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                                new Dictionary <string, object>
            {
                { "event", "AspNet BeginRequest" },
                { "message", $"Request starting {httpContext.Request.Url.Scheme} {httpContext.Request.HttpMethod} {httpContext.Request.Url.OriginalString}" }
            });
        }
        private void RequestFilters(IRequest request, IResponse response, object dto)
        {
            HttpListenerRequest req = (HttpListenerRequest)request.OriginalRequest;
            var trace = request.TryResolve <UrlTraceFilter>();

            if (trace != null)
            {
                if (!trace.IsTrace(request.AbsoluteUri))
                {
                    return;
                }
            }

            //var req = request;

            /*   if (dto == null)
             * {
             *     return;
             * }*/
            var carrier = new ContextCarrier();

            //ContextManager.Extract(carrier);
            foreach (var item in carrier.Items)
            {
                item.HeadValue = request.Headers[item.HeadKey];
            }



            var httpRequestSpan =
                ContextManager.CreateEntrySpan($"{AgentConfig.ApplicationCode} {request.AbsoluteUri}",
                                               carrier);

            httpRequestSpan.AsHttp();


            httpRequestSpan.SetComponent(ComponentsDefine.AspNetCore);
            Tags.Url.Set(httpRequestSpan, request.RawUrl);
            Tags.HTTP.Method.Set(httpRequestSpan, request.GetHttpMethodOverride());
            httpRequestSpan.Log(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                                new Dictionary <string, object>
            {
                { "event", "ServiceStack BeginRequest" },
                {
                    "message",
                    $"Request starting {req.Url.Scheme} {req.HttpMethod} {req.Url.OriginalString}"
                }
            });


            // carrier = new ContextCarrier();

            /* if (carrier.IsValid)
             * {
             *   var exitSpan =
             *       ContextManager.CreateExitSpan($"{AgentConfig.ApplicationCode} {request.AbsoluteUri}",
             *           carrier,carrier.PeerHost);
             *
             *   //  ContextManager.Inject(carrier);
             *
             *   foreach (var item in carrier.Items)
             *       request.Headers[item.HeadKey] = item.HeadKey;
             * }*/
        }
Example #23
0
 protected override IEnumerable<PValue> CoroutineRun(ContextCarrier sctxCarrier,
     PValue[] args)
 {
     return CoroutineRunStatically(sctxCarrier, args);
 }
Example #24
0
 public static PValue RunStatically(StackContext sctx, PValue[] args)
 {
     var carrier = new ContextCarrier();
     var corctx = new CoroutineContext(sctx, CoroutineRunStatically(carrier, args));
     carrier.StackContext = corctx;
     return sctx.CreateNativePValue(new Coroutine(corctx));
 }
Example #25
0
 protected abstract IEnumerable<PValue> CoroutineRun(ContextCarrier sctxCarrier,
     PValue[] args);
Example #26
0
File: Map.cs Project: SealedSun/prx
        protected static IEnumerable<PValue> CoroutineRun(ContextCarrier sctxCarrier,
            IIndirectCall f, IEnumerable<PValue> source)
        {
            var sctx = sctxCarrier.StackContext;

            foreach (var x in source)
                yield return f != null ? f.IndirectCall(sctx, new[] {x}) : x;
        }
Example #27
0
File: Map.cs Project: SealedSun/prx
        protected static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");
            if (args == null)
                throw new ArgumentNullException("args");

            var sctx = sctxCarrier.StackContext;

            //Get f
            IIndirectCall f;
            if (args.Length < 1)
                f = null;
            else
                f = args[0];

            //Get the source
            IEnumerable<PValue> source;
            if (args.Length == 2)
            {
                var psource = args[1];
                source = _ToEnumerable(sctx, psource) ?? new[] {psource};
            }
            else
            {
                var lstsource = new List<PValue>();
                for (var i = 1; i < args.Length; i++)
                {
                    var multiple = _ToEnumerable(sctx, args[i]);
                    if (multiple != null)
                        lstsource.AddRange(multiple);
                    else
                        lstsource.Add(args[i]);
                }
                source = lstsource;
            }

            //Note: need to forward element because this method must remain lazy.
            foreach (var value in CoroutineRun(sctxCarrier, f, source))
            {
                yield return value;
            }
        }