Beispiel #1
0
        public static List <ReportFieldNode> ExtractNodePath(string path)
        {
            string[] parts = path.Split('.');
            List <ReportFieldNode> nodes       = new List <ReportFieldNode>();
            ReportFieldNode        currentNode = Root;

            foreach (string part in parts)
            {
                string part1 = part;
                currentNode = currentNode.Nodes.FirstOrDefault(x => String.Equals(x.Name, part1, StringComparison.InvariantCultureIgnoreCase));

                if (currentNode == null)
                {
                    return(null);
                }

                nodes.Add(currentNode);
            }

            return(nodes);
        }
Beispiel #2
0
        private static ReportFieldNode CreateAlias <TSource, T>(string name, Func <TSource, T> extractor, ReportFieldNode target)
        {
            return(new ReportFieldNode(typeof(T), name, x =>
            {
                if (x == null || x.Values.Length == 0)
                {
                    return null;
                }

                List <object> results = new List <object>();
                foreach (object result in x.Values.OfType <TSource>().Select(y => (object)extractor(y)))
                {
                    var array = result as ReportArray;
                    if (array != null)
                    {
                        results.AddRange(array.Values);
                    }
                    else
                    {
                        results.Add(result);
                    }
                }

                return new ReportArray(results.ToArray());
            }, target.Nodes));
        }
Beispiel #3
0
        static ReportFieldNodes()
        {
            var nodeUrl = Create("Uri", (Uri uri) => uri,
                                 Create("AbsolutePath", (Uri uri) => uri.AbsolutePath),
                                 Create("AbsoluteUri", (Uri uri) => uri.AbsoluteUri),
                                 Create("Authority", (Uri uri) => uri.Authority),
                                 Create("Fragment", (Uri uri) => uri.Fragment),
                                 Create("Host", (Uri uri) => uri.Host),
                                 Create("PathAndQuery", (Uri uri) => uri.PathAndQuery),
                                 Create("Query", (Uri uri) => uri.Query),
                                 Create("Scheme", (Uri uri) => uri.Scheme));

            var nodeReference =
                Create("References", (ResourceReferenceCollection r) => r,
                       Create("First", (IEnumerable <ResourceReference> lst) => lst.FirstOrDefault()),
                       Create("Count", (IEnumerable <ResourceReference> lst) => lst.Count()));

            NodeResource  = Create("Resource", (ReportNodeInfos i) => i.Resource);
            NodeReference = Create("Reference", (ReportNodeInfos i) => i.Reference);
            NodeContent   = Create("Content", (ReportNodeInfos i) => i.Content);
            NodeError     = Create("Error", (ReportNodeInfos i) => i.Error);

            var referenceCollection = Create("ReferenceCollection", (IEnumerable <ResourceReference> coll) => coll,
                                             Create("Count", (IEnumerable <ResourceReference> coll) => coll.Count()),
                                             Create("First", (IEnumerable <ResourceReference> coll) => coll.FirstOrDefault()),
                                             Create("First5", (IEnumerable <ResourceReference> coll) => new ReportArray(coll.Take(5).ToArray <object>())),
                                             Create("First10", (IEnumerable <ResourceReference> coll) => new ReportArray(coll.Take(10).ToArray <object>())),
                                             CreateAlias("Items", (IEnumerable <ResourceReference> coll) => new ReportArray(coll.ToArray <object>()), NodeReference));

            NodeResource.AddNodes(
                Create("ProcessingStatus", (Resource res) => res.Status),
                Create("Status", (Resource res) => DescriptionExtractor.GetDescription(res.Status == ResourceStatus.Processed ? (object)res.HttpStatus : res.Status)),
                Create("Content", (Resource res) => res.Content),
                Create("Errors", (Resource res) => res.Errors),
                Create("Redirections", (Resource res) => res,
                       CreateAlias("First", (Resource res) => res.References.FirstOrDefault(x => x.Type == ResourceReferenceTypes.Redirection), NodeReference),
                       Create <Resource, int>("Count", CountRedirections),
                       CreateAlias <Resource, Resource>("Final", FollowRedirections, NodeResource)),
                Create("References", (Resource res) => res.References,
                       CreateAlias("All", (ResourceReferenceCollection res) => res, referenceCollection),
                       CreateAlias("Anchors", (ResourceReferenceCollection res) => res.Where(x => x.Type == ResourceReferenceTypes.Anchor), referenceCollection),
                       CreateAlias("Images", (ResourceReferenceCollection res) => res.Where(x => x.Type == ResourceReferenceTypes.Image), referenceCollection),
                       Create("Links", (ResourceReferenceCollection res) => res,
                              CreateAlias("Canonicals", (ResourceReferenceCollection res) => res.Where(x => x.SubType == ReferenceSubType.Canonical), referenceCollection),
                              CreateAlias("ShortcutIcons", (ResourceReferenceCollection res) => res.Where(x => x.SubType == ReferenceSubType.ShortcutIcon), referenceCollection),
                              CreateAlias("StyleSheets", (ResourceReferenceCollection res) => res.Where(x => x.SubType == ReferenceSubType.StyleSheet), referenceCollection)),
                       CreateAlias("Scripts", (ResourceReferenceCollection res) => res.Where(x => x.Type == ResourceReferenceTypes.Script), referenceCollection)),
                CreateAlias("Referers", (Resource res) => res.ReferencedBy, referenceCollection),
                Create("Request", (Resource res) => res,
                       Create("Behavior", (Resource res) => res.Behavior),
                       Create("TimeStart", (Resource res) => res.TimeStart),
                       CreateAlias("Url", (Resource res) => res.Url, nodeUrl)),
                Create("Response", (Resource res) => res,
                       Create("CompressedSize", (Resource res) => res.CompressedSize),
                       Create("ContentType", (Resource res) => res.ContentType),
                       Create("Headers", (Resource res) => res.Headers,
                              Create("ContentEncoding", (ResourceHeaders h) => h.TryGetValue("content-encoding")),
                              Create("ContentType", (ResourceHeaders h) => h.TryGetValue("content-type")),
                              Create("CacheControl", (ResourceHeaders h) => h.TryGetValue("cache-control")),
                              Create("HasETAG", (ResourceHeaders h) => !String.IsNullOrWhiteSpace(h.TryGetValue("ETag"))),
                              Create("LastModified", (ResourceHeaders h) => TryParseDate(h.TryGetValue("last-modified"))),
                              Create("Expires", (ResourceHeaders h) => TryParseDate(h.TryGetValue("expires")))),
                       Create("HttpStatus", (Resource res) => res.HttpStatus),
                       Create("Size", (Resource res) => res.Size),
                       Create("CompressedSize", (Resource res) => res.CompressedSize),
                       Create("TimeLoading", (Resource res) => res.TimeLoading),
                       Create("TimeProcessing", (Resource res) => res.TimeProcessing),
                       Create("ViewStateSize", (Resource res) => res.ViewStateSize ?? 0)));

            NodeReference.AddNodes(
                CreateAlias("Source", (ResourceReference r) => r.Source, NodeResource),
                CreateAlias("Target", (ResourceReference r) => r.Target, NodeResource),
                Create("Type", (ResourceReference r) => r.Type),
                Create("SubType", (ResourceReference r) => r.SubType),
                Create("RawUrl", (ResourceReference r) => r.Url.OriginalString),
                Create("Count", (ResourceReference r) => r.Count),
                Create("IsRecursive", (ResourceReference r) => r.Source == r.Target || r.Source == FollowRedirections(r.Target)));

            NodeContent.AddNodes(
                Create("Key", (ResourceContent c) => c.Key),
                Create("Value", (ResourceContent c) => c.Value));

            NodeError.AddNodes(
                Create("Type", (ResourceError e) => e.Type),
                Create("Message", (ResourceError e) => e.Message),
                Create("Value", (ResourceError e) => e.Value),
                Create("Line", (ResourceError e) => e.Line));

            Root = Create("Root", (ReportNodeInfos i) => i, NodeResource, NodeReference, NodeContent, NodeError);
        }