Inheritance: MonoBehaviour
コード例 #1
0
        public void UploadFPSDataPage(PageMetaData pageMetaData, LogData logData, string logfilepath)
        {
            FPSBucketsRemotePage page = CreateFPSBucketsPage(pageMetaData, logData);

            page.AddHeading("Framerate Data");
            page.AddBucketsTable("Overall fps");
            page.StartCanvasSection();
            {
                page.AddHistogram("Overall fps");
                string[] stats = { "/frameLengthMAInMS", "/Graphics/GPUFrameLengthInMS" };
                page.AddTimeLineGraph(stats);
            }
            page.EndCanvasSection();

            StorePage(page.m_page);
            AddAttachment(Compress(logfilepath), pageMetaData.m_title, pageMetaData.m_parentTitle, pageMetaData.m_space, "FPS Statoscope Log");
        }
コード例 #2
0
        public PostData?Convert(MarkdownFile file)
        {
            var helper = new MarkdownFileHelper(file, _logger);

            var title       = helper.GetRequiredString("title");
            var author      = helper.GetRequiredString("author");
            var email       = helper.GetOptionalString("email");
            var publishedOn = helper.GetRequiredDate("date");
            var isPublished = helper.GetOptionalBoolean("published") ?? true;
            var isListed    = helper.GetOptionalBoolean("listed") ?? true;

            var metaAuthor      = helper.GetOptionalString("meta-author");
            var metaDescription = helper.GetOptionalString("meta-description");
            var metaKeywords    = helper.GetOptionalString("meta-keywords");

            if (!helper.IsValid)
            {
                return(null);
            }

            var metaData = new PageMetaData(
                metaAuthor ?? author,
                metaDescription,
                metaKeywords);

            var result = new PostData(
                file.Name,
                title,
                author,
                email,
                publishedOn,
                isPublished,
                isListed,
                file.Markdown,
                metaData);

            return(result);
        }
コード例 #3
0
        public StaticPageData?Convert(MarkdownFile file)
        {
            var helper = new MarkdownFileHelper(file, _logger);

            var title        = helper.GetRequiredString("title");
            var uriSegment   = helper.GetRequiredString("uri-segment");
            var isPublished  = helper.GetOptionalBoolean("published") ?? true;
            var menuIcon     = helper.GetOptionalString("menu-icon");
            var menuText     = helper.GetOptionalString("menu-text");
            var menuSequence = helper.GetOptionalInt32("menu-sequence");

            var metaAuthor      = helper.GetOptionalString("meta-author");
            var metaDescription = helper.GetOptionalString("meta-description");
            var metaKeywords    = helper.GetOptionalString("meta-keywords");

            if (!helper.IsValid)
            {
                return(null);
            }

            var metaData = new PageMetaData(
                metaAuthor,
                metaDescription,
                metaKeywords);

            var result = new StaticPageData(
                file.Name,
                title,
                uriSegment,
                isPublished,
                menuSequence,
                menuIcon,
                menuText,
                file.Markdown,
                metaData);

            return(result);
        }
コード例 #4
0
        StatisticsRemotePage CreateStatisticsPage(PageMetaData pageMetaData, LogData logData, string [] groups)
        {
            RemotePage page = GetPage(pageMetaData.m_title, pageMetaData.m_parentTitle, pageMetaData.m_space);

            return(new StatisticsRemotePage(page, logData, pageMetaData.m_contentMetaData, groups));
        }
コード例 #5
0
        FPSBucketsRemotePage CreateFPSBucketsPage(PageMetaData pageMetaData, LogData logData)
        {
            RemotePage page = GetPage(pageMetaData.m_title, pageMetaData.m_parentTitle, pageMetaData.m_space);

            return(new FPSBucketsRemotePage(page, logData, pageMetaData.m_contentMetaData));
        }
コード例 #6
0
        public void UploadStatsDataPage(PageMetaData pageMetaData, LogData logData, string [] groups, XmlNodeList metrics, bool upload)
        {
            StatisticsRemotePage page = CreateStatisticsPage(pageMetaData, logData, groups);

            if (upload)
            {
                GroupsStats stats = new GroupsStats();
                logData.GetFrameGroupData(0, logData.FrameRecords.Count - 1, groups, stats);
                Random random = new Random();
                foreach (string group in stats.m_groupStats.Keys)
                {
                    page.m_page.content += "\n\n";
                    GroupItemStats groupsStats = stats.GetGroupItemsStats(group);
                    foreach (string item in groupsStats.m_groupItemStats.Keys)
                    {
                        float  target = 0.0f;
                        float  max    = 0.0f;
                        float  min    = 0.0f;
                        float  fail   = 0.0f;
                        string path   = "/" + group + "/" + item;
                        string units  = "";                        // logData.FrameRecords[0].m_units[path];

                        foreach (XmlNode node in metrics)
                        {
                            XmlNode attribute = node.Attributes.GetNamedItem("name");
                            if (attribute.Value == item)
                            {
                                XmlNode metricNode = node.ChildNodes.Item(0);
                                if (metricNode != null)
                                {
                                    if (metricNode.Attributes.GetNamedItem("target") != null)
                                    {
                                        target = (float)int.Parse(metricNode.Attributes.GetNamedItem("target").Value);
                                    }
                                    if (metricNode.Attributes.GetNamedItem("heatMax") != null)
                                    {
                                        max = (float)int.Parse(metricNode.Attributes.GetNamedItem("heatMax").Value) + target;
                                    }
                                    if (metricNode.Attributes.GetNamedItem("heatMin") != null)
                                    {
                                        min = (float)int.Parse(metricNode.Attributes.GetNamedItem("heatMin").Value);
                                    }
                                    if (metricNode.Attributes.GetNamedItem("failure") != null)
                                    {
                                        fail = (float)int.Parse(metricNode.Attributes.GetNamedItem("failure").Value) + target;
                                    }
                                    break;
                                }
                            }
                        }

                        Stats statitem = groupsStats.GetItemStats(item);
                        page.m_page.content += "+*Statistic*: {color:blue}" + group + " - " + item + "{color}+\n\n";
                        page.AddStatOverview(Math.Max(0.0f, statitem.m_min), Math.Max(0.0f, statitem.m_max), Math.Max(0.0f, statitem.m_avg), max, target);
                        page.StartCanvasSection(random.Next());
                        page.AddTimeLineGraph(group, item, statitem, max, target, units);
                        page.EndCanvasSection();
                    }
                }
            }

            StorePage(page.m_page);
            AddAttachment(Compress(pageMetaData.m_contentMetaData.m_logFilename), pageMetaData.m_title, pageMetaData.m_parentTitle, pageMetaData.m_space, "Statoscope Log");
        }
コード例 #7
0
 public PageMetadata Build(PageMetaData data)
 => new PageMetadata(data.Author, data.Description, data.Keywords);
コード例 #8
0
        public async Task <ResourceResults> GetAll(
            [FromQuery(Name = "q")] string keyword                     = null,
            [FromQuery(Name = "toolTypes")] string[] toolTypes         = null,
            [FromQuery(Name = "toolSubtypes")] string[] subTypes       = null,
            [FromQuery(Name = "researchAreas")] string[] researchAreas = null,
            [FromQuery(Name = "researchTypes")] string[] researchTypes = null,
            [FromQuery(Name = "docs")] string[] docs                   = null,
            [FromQuery(Name = "include")] string[] includeFields       = null,
            [FromQuery(Name = "includeFacets")] string[] includeFacets = null,
            [FromQuery(Name = "size")] string strSize                  = null,
            [FromQuery(Name = "from")] string strFrom                  = null
            )
        {
            // Validate query params here

            // 1. Throw error if subToolType exists, but no toolType
            if (IsNullOrEmpty(toolTypes) && !IsNullOrEmpty(subTypes))
            {
                _logger.LogError("Cannot have subtype without tooltype.", subTypes);
                throw new ArgumentException("Cannot have subtype without tooltype.");
            }

            // 2. Throw error if multiple toolTypes exist
            if (toolTypes != null && toolTypes.Length > 1)
            {
                _logger.LogError("Cannot have multiple tooltypes.", toolTypes);
                throw new ArgumentException("Cannot have multiple tooltypes.");
            }

            // 3. Throw error if size is invalid int
            int size;

            if (string.IsNullOrWhiteSpace(strSize))
            {
                size = 20;
            }
            else
            {
                int tmpInt = -1;
                if (int.TryParse(strSize.Trim(), out tmpInt))
                {
                    if (tmpInt < 0)
                    {
                        _logger.LogError($"Invalid size parameter: {strSize}.");
                        throw new APIErrorException(400, $"Bad request: Invalid size parameter {strSize}.");
                    }

                    size = tmpInt;
                }
                else
                {
                    _logger.LogError($"Invalid size parameter: {strSize}.");
                    throw new APIErrorException(400, $"Bad request: Invalid size parameter {strSize}.");
                }
            }

            // 4. Throw error if from is invalid int
            int from;

            if (string.IsNullOrWhiteSpace(strFrom))
            {
                from = 0;
            }
            else
            {
                int tmpInt = -1;
                if (int.TryParse(strFrom.Trim(), out tmpInt))
                {
                    if (tmpInt < 0)
                    {
                        _logger.LogError($"Invalid from parameter: {strFrom}.");
                        throw new APIErrorException(400, $"Bad request: Invalid from parameter {strFrom}.");
                    }

                    from = tmpInt;
                }
                else
                {
                    _logger.LogError($"Invalid from parameter: {strFrom}.");
                    throw new APIErrorException(400, $"Bad request: Invalid from parameter {strFrom}.");
                }
            }

            // Build resource query object using params
            ResourceQuery resourceQuery = new ResourceQuery();

            // Add keyword, if included in params
            if (!string.IsNullOrWhiteSpace(keyword))
            {
                resourceQuery.Keyword = keyword;
            }

            // Add tool types, if included in params
            if (!IsNullOrEmpty(toolTypes))
            {
                resourceQuery.Filters.Add("toolTypes", toolTypes);
            }

            // Add tool subtypes, if included in params
            if (!IsNullOrEmpty(subTypes))
            {
                resourceQuery.Filters.Add("toolSubtypes", subTypes);
            }

            // Add research areas, if included in params
            if (!IsNullOrEmpty(researchAreas))
            {
                resourceQuery.Filters.Add("researchAreas", researchAreas);
            }

            // Add research types, if included in params
            if (!IsNullOrEmpty(researchTypes))
            {
                resourceQuery.Filters.Add("researchTypes", researchTypes);
            }

            // Add docs, if included in params
            if (!IsNullOrEmpty(docs))
            {
                resourceQuery.Filters.Add("docs", docs);
            }

            // Set default values for params
            //facetsBeingRequest is used because if we modify the original params
            //then the OriginalString of the response will show the default
            //include facets.
            string[] facetsBeingRequested = new string[] { };
            if (IsNullOrEmpty(includeFacets))
            {
                facetsBeingRequested = GetDefaultIncludeFacets();
            }
            else if (!ValidateFacetList(includeFacets))
            {
                //TODO: Actually list the invalid facets
                _logger.LogError("Included facets in query are not valid.");
                throw new APIErrorException(400, "Included facets in query are not valid.");
            }
            else
            {
                facetsBeingRequested = includeFacets;
            }

            string[] fieldsBeingRequested = new string[] { };
            if (IsNullOrEmpty(includeFields))
            {
                fieldsBeingRequested = GetDefaultIncludeFields();
            }
            else if (!ValidateFieldList(includeFields))
            {
                //TODO: Actually list the invalid fields
                _logger.LogError("Included fields in query are not valid.");
                throw new APIErrorException(400, "Included fields in query are not valid.");
            }
            else
            {
                fieldsBeingRequested = includeFields;
            }

            //Create the results object
            ResourceResults results          = new ResourceResults();
            bool            noMatchedResults = true;

            //Now call query results & get aggs at the same time.
            await Task.WhenAll(
                Task.Run(async() =>
            {
                // Perform query for resources (using params if they're given)
                ResourceQueryResult queryResults = await _queryService.QueryResourcesAsync(resourceQuery, size, from, fieldsBeingRequested);

                // Convert query results into ResourceResults
                PageMetaData meta = new PageMetaData
                {
                    TotalResults  = queryResults.TotalResults,
                    From          = queryResults.From,
                    OriginalQuery = _urlHelper.RouteUrl(new
                    {
                        size,
                        from,
                        q = keyword,
                        toolTypes,
                        toolSubtypes = subTypes,
                        researchAreas,
                        researchTypes,
                        docs,
                        //DO NOT USE fieldsBeingRequested or facetsBeingRequested HERE. These are the original lists provided by the user.
                        include = includeFields,
                        includeFacets
                    })
                };
                results.Meta    = meta;
                results.Results = queryResults.Results;

                //While we may have asked for size 0, this will still tell us if the full query has results.
                noMatchedResults = queryResults.TotalResults == 0;

                if (from > queryResults.TotalResults)
                {
                    throw new APIErrorException(400, $"Offset (from) value of {queryResults.TotalResults} is greater than the number of results.");
                }
            }),
                Task.Run(async() =>
            {
                // Perform query for facet aggregations (using includeFacets param if it's given, otherwise default facets to include from options)
                results.Facets = await GetFacets(facetsBeingRequested, resourceQuery); //Go back to sync now.
            })
                );

            //Multiselect facets will query all filters except thier own.  So,
            //you can have no search results returned, but still get a facet.
            //For example, /resources?researchAreas=chicken will actually return
            //all the facet items for researchAreas.  This code below removes
            //all facets when there are 0 results, unless the user has asked for
            //a query size of 0;
            if (noMatchedResults)
            {
                results.Facets = new Facet[] { };
            }

            return(results);
        }
コード例 #9
0
        private async Task LoadAndParse(string Url)
        {
            using (HttpClient Client = new HttpClient())
            {
                Client.Timeout = TimeSpan.FromMilliseconds(30000);
                Client.DefaultRequestHeaders.ExpectContinue = false;

                HttpResponseMessage Response = await Client.GetAsync(Url);

                Response.EnsureSuccessStatusCode();

                byte[] Data = await Response.Content.ReadAsByteArrayAsync();

                string ContentType = Response.Content.Headers.ContentType.ToString();

                HtmlDocument Doc = InternetContent.Decode(ContentType, Data, new Uri(Url)) as HtmlDocument;
                Assert.IsNotNull(Doc);

                Assert.IsNotNull(Doc.Root);
                Assert.IsNotNull(Doc.Html);
                Assert.IsNotNull(Doc.Head);
                Assert.IsNotNull(Doc.Body);
                Assert.IsNotNull(Doc.Title);

                List <HtmlNode> Todo = new List <HtmlNode>()
                {
                    Doc.Root
                };

                string   s;
                HtmlNode N;
                int      i    = 0;
                int      Last = -1;

                while (i < Todo.Count)
                {
                    N = Todo[i++];

                    if (Last >= 0)
                    {
                        s = "\r\n\r\n" + Doc.HtmlText.Substring(Last + 1);
                    }
                    else
                    {
                        s = string.Empty;
                    }

                    Assert.IsTrue(N.StartPosition > Last, "Start position not set properly. Start=" + N.StartPosition.ToString() + ", Last=" + Last.ToString() + s);
                    Assert.IsTrue(N.EndPosition >= N.StartPosition, "End position not set.\r\n\r\n" + Doc.HtmlText.Substring(N.StartPosition));
                    Assert.IsTrue(!string.IsNullOrEmpty(N.OuterHtml), "OuterHTML not set properly.\r\n\r\n" + Doc.HtmlText.Substring(N.StartPosition));

                    if (N is HtmlElement E)
                    {
                        Last = E.EndPositionOfStartTag;

                        if (E.HasChildren)
                        {
                            Todo.InsertRange(i, E.Children);
                        }

                        Assert.IsTrue(E.InnerHtml != null, "InnerHTML not set properly.\r\n\r\n" + Doc.HtmlText.Substring(N.StartPosition));
                    }
                    else
                    {
                        Last = N.EndPosition;
                    }
                }

                PageMetaData MetaData = Doc.GetMetaData();

                if (Doc.Meta != null)
                {
                    foreach (Meta Meta in Doc.Meta)
                    {
                        Console.Out.WriteLine(Meta.OuterHtml);
                    }
                }

                XmlWriterSettings Settings = XML.WriterSettings(true, true);
                using (XmlWriter Output = XmlWriter.Create(Console.Out, Settings))
                {
                    Doc.Export(Output);
                    Output.Flush();
                }
            }
        }