示例#1
0
        public void Question_4_1_BasicCases()
        {
            var node1 = new GraphNode <int>(0);
            var node2 = new GraphNode <int>(0);

            this.Validate(node1, node2, true, true);

            node2 = new GraphNode <int>(2);
            this.Validate(node1, node2, false, false);

            var root1 = GraphHelpers.CreateGraph(0, 1, 2, 3);
            var root2 = GraphHelpers.CreateGraph(4, 5, 6, 7);
            var root3 = GraphHelpers.CreateGraph(8, root1, root2);

            this.Validate(root1, root2, false, false);
            this.Validate(root1, root3, false, true);

            var root4 = GraphHelpers.CreateGraph(9, root1, root3);

            this.Validate(root4, root3, true, true);
            this.Validate(root1, root4, false, true);
            this.Validate(root1, root3, false, true);
            this.Validate(root3, root1, true, true);
            this.Validate(root2, root1, false, false);
        }
示例#2
0
        public override StorageContent CreateContent(CatalogContext context)
        {
            IGraph catalogEntry = new Graph();

            INode catalogEntrySubject = catalogEntry.CreateUriNode(GetItemAddress());

            //  catalog infrastructure fields

            catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Type), catalogEntry.CreateUriNode(GetItemType()));
            catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Type), catalogEntry.CreateUriNode(_itemType));
            catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Type), catalogEntry.CreateUriNode(Schema.DataTypes.Permalink));
            catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.CatalogTimeStamp), catalogEntry.CreateLiteralNode(TimeStamp.ToString("O"), Schema.DataTypes.DateTime));
            catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.CatalogCommitId), catalogEntry.CreateLiteralNode(CommitId.ToString()));

            catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Published), catalogEntry.CreateLiteralNode(_publicationDetails.Published.ToString("O"), Schema.DataTypes.DateTime));

            catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.TenantId), catalogEntry.CreateLiteralNode(_publicationDetails.TenantId));
            catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Tenant), catalogEntry.CreateLiteralNode(_publicationDetails.TenantName));

            Uri   ownerUri     = _publicationDetails.Owner.GetUri(GetItemAddress());
            INode ownerSubject = catalogEntry.CreateUriNode(ownerUri);

            catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.NameIdentifier), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.NameIdentifier));
            catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.Name), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.Name));
            catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.GivenName), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.GivenName));
            catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.Surname), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.Surname));
            catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.Iss), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.Iss));

            catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Owner), ownerSubject);

            //  visibility

            catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Visibility), catalogEntry.CreateLiteralNode(_publicationDetails.Visibility.Visibility.ToString()));

            switch (_publicationDetails.Visibility.Visibility)
            {
            case PublicationVisibility.VisibilityScope.Organization:
                catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Organization), catalogEntry.CreateLiteralNode(_publicationDetails.Visibility.Organization));
                break;

            case PublicationVisibility.VisibilityScope.Subscription:
                catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Subscription), catalogEntry.CreateLiteralNode(_publicationDetails.Visibility.Subscription));
                break;
            }

            //  listed

            catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Listed), catalogEntry.CreateLiteralNode(_isListed.ToString(), Schema.DataTypes.Boolean));

            //  add the nuspec metadata

            Uri    nuspecSubject = _nuspec["@id"].ToObject <Uri>();
            IGraph nuspecGraph   = Utils.CreateGraph(_nuspec);

            //  Any statements made about this @id in the nuspec we want to make about the catalog items @id
            //  - catalog readers can then apply this logic in reverse
            //  - by so doing the catalog entry becomes an audit entry for the data

            catalogEntry.Merge(nuspecGraph, false);

            foreach (Triple triple in catalogEntry.GetTriplesWithSubject(catalogEntry.CreateUriNode(nuspecSubject)))
            {
                catalogEntry.Assert(catalogEntrySubject, triple.Predicate.CopyNode(catalogEntry), triple.Object.CopyNode(catalogEntry));
            }

            GraphHelpers.MaterializeInference(catalogEntry);

            SetIdVersionFromGraph(catalogEntry);

            //  create JSON content

            string json = Utils.CreateJson(catalogEntry, _context);

            StorageContent content = new StringStorageContent(json, "application/json", "no-store");

            return(content);
        }
示例#3
0
        /// <summary>
        /// The override for the Paint method. This method paints the graph onto the canvas.
        /// </summary>
        private void Construct()
        {
            Graphics.CompositingQuality = CompositingQuality.HighQuality;
            Graphics.CompositingMode    = CompositingMode.SourceOver;
            Graphics.TextRenderingHint  = TextRenderingHint.SingleBitPerPixelGridFit;

            ImageAttributes ia = new ImageAttributes();

            ia.SetGamma(50, ColorAdjustType.Brush);

            DrawingElements.Add(new DrawBackGround(Color.White, GraphCanvasRectangle));

            Pen outline = new Pen(new SolidBrush(Color.DarkGray));

            //DrawingElements.Add(new DrawRectangle(outline, 0, 0, Bitmap.Width - 1, Bitmap.Height - 1));

#if GRAPHDEBUG
            DrawingElements.Add(new DrawRectangle(debugPen, TitleRectangle));
            DrawingElements.Add(new DrawRectangle(debugPen, LegendRectangle));
            DrawingElements.Add(new DrawRectangle(debugPen, GraphRectangle));
#endif

            //graph
            Graphics.Clip = new Region(GraphRectangle);

            //adjuct the rectangle to be square
            if (GraphRectangle.Width > GraphRectangle.Height)
            {
                GraphRectangle =
                    new RectangleF(GraphRectangle.X + ((GraphRectangle.Width - GraphRectangle.Height)) / 2,
                                   GraphRectangle.Y, GraphRectangle.Height, GraphRectangle.Height);
            }
            else
            {
                GraphRectangle =
                    new RectangleF(GraphRectangle.X, GraphRectangle.Y, GraphRectangle.Width, GraphRectangle.Width);
            }

#if GRAPHDEBUG
            DrawingElements.Add(
                new DrawString(string.Format("Width={0}, Height={1}", GraphRectangle.Width, GraphRectangle.Height),
                               LegendFont, debugBrush, GraphRectangle, LegendStringFormat));
            DrawingElements.Add(new DrawEllipse(debugPen, GraphRectangle));
#endif

            float total = 0;
            foreach (GraphRange gr in GraphData.Ranges)
            {
                total += (float)gr.SumOfValues;
            }

            float start = 0;
            float end   = 0;
            float step  = (360 / total);

            RectangleF labelRectangle =
                new RectangleF(GraphRectangle.X + (GraphRectangle.Width / 100 * 10),
                               GraphRectangle.Y + (GraphRectangle.Height / 100 * 10),
                               GraphRectangle.Width - (GraphRectangle.Width / 100 * 20),
                               GraphRectangle.Height - (GraphRectangle.Height / 100 * 20));
            RectangleF pieRectangle =
                new RectangleF(GraphRectangle.X + (GraphRectangle.Width / 100 * 20),
                               GraphRectangle.Y + (GraphRectangle.Height / 100 * 20),
                               GraphRectangle.Width - (GraphRectangle.Width / 100 * 40),
                               GraphRectangle.Height - (GraphRectangle.Height / 100 * 40));
            PointF centrePie =
                new PointF(pieRectangle.X + (pieRectangle.Width / 2), pieRectangle.Y + (pieRectangle.Height / 2));

            ArrayList differedLabelDraw = new ArrayList();

            foreach (GraphRange gr in GraphData.Ranges)
            {
                end = step * (float)gr.SumOfValues;
                PointF centreLabel = GraphMaths.PointOnCircleF(Convert.ToInt32(start + (end / 2)), labelRectangle);
                PointF edgeOfPie   = GraphMaths.PointOnCircleF(Convert.ToInt32(start + (end / 2)), pieRectangle);

#if GRAPHDEBUG
                DrawingElements.Add(new DrawLine(debugPen, centreLabel, centrePie));
                DrawingElements.Add(new DrawPie(debugPen, pieRectangle, start - 90, end));
#endif
                DrawingElements.Add(new DrawLine(outline, centreLabel, edgeOfPie));
                DrawingElements.Add(
                    new FillPie(
                        new LinearGradientBrush(pieRectangle, gr.PrimaryColor, gr.SecondaryColor,
                                                LinearGradientMode.ForwardDiagonal), pieRectangle, start - 90, end));
                if (_textLabels == true)
                {
                    DrawingElements.Add(new FillRectangle(new SolidBrush(Color.White),
                                                          GraphHelpers.TextRectangleFromCentre(Graphics, gr.Label,
                                                                                               LegendFont,
                                                                                               centreLabel)));
                    DrawingElements.Add(
                        new DrawString(gr.Label, LegendFont, new SolidBrush(Color.Black),
                                       GraphHelpers.TextRectangleFromCentre(Graphics, gr.Label, LegendFont,
                                                                            centreLabel), null));
                }
                else
                {
                    DrawingElements.Add(new FillRectangle(new SolidBrush(Color.White),
                                                          GraphHelpers.TextRectangleFromCentre(Graphics,
                                                                                               gr.SumOfValues.
                                                                                               ToString("F"),
                                                                                               LegendFont,
                                                                                               centreLabel)));
                    DrawingElements.Add(
                        new DrawString(gr.SumOfValues.ToString("F"), LegendFont, new SolidBrush(Color.Black),
                                       GraphHelpers.TextRectangleFromCentre(Graphics, gr.SumOfValues.ToString("F"),
                                                                            LegendFont, centreLabel), null));
                }
                differedLabelDraw.Add(centreLabel);


                start = start + end;
            }

            Graphics.ResetClip();

            //title
            if (DrawTitle == true)
            {
#if GRAPHDEBUG
                DrawingElements.Add(new DrawRectangle(debugPen, TitleRectangle));
#endif
                DrawingElements.Add(
                    new DrawString(GraphData.Title, TitleFont, new SolidBrush(TitleColor), TitleRectangle,
                                   TitleStringFormat));
            }

            //legend
            if (DrawLegend == true)
            {
                //work out text height
                int textHeight = (int)((Graphics.MeasureString("X", LegendFont).Height) / 100 * 120);

#if GRAPHDEBUG
                DrawingElements.Add(
                    new DrawRectangle(debugPen, LegendRectangle.X, LegendRectangle.Y, LegendRectangle.Width - 1,
                                      GraphData.Ranges.Count * textHeight));
#endif

                DrawingElements.Add(new FillRectangle(new SolidBrush(Color.White),
                                                      LegendRectangle.X, LegendRectangle.Y,
                                                      LegendRectangle.Width - 1,
                                                      GraphData.Ranges.Count * textHeight));

                int lentry = 0;
                foreach (GraphRange gr in GraphData.Ranges)
                {
                    RectangleF currentRectangle = new RectangleF(LegendRectangle.X + 20,
                                                                 (textHeight * lentry++) + LegendRectangle.Y,
                                                                 LegendRectangle.Width - 20,
                                                                 textHeight);

                    RectangleF colorRectangle = currentRectangle;
                    colorRectangle.Offset(-20, 0);
                    colorRectangle.Width = 20;

#if GRAPHDEBUG
                    DrawingElements.Add(new DrawRectangle(debugPen, currentRectangle));
                    DrawingElements.Add(new DrawRectangle(debugPen, colorRectangle));
#endif
                    string lable = gr.Label;
                    if (lable.Length > 26)
                    {
                        lable = lable.Substring(0, 26);
                    }

                    string val = gr.SumOfValues.ToString("F");
                    DrawingElements.Add(new DrawString(
                                            string.Format("{0} = {1}", lable, val),
                                            LegendFont,
                                            new SolidBrush(Color.Black),
                                            currentRectangle,
                                            LegendStringFormat));

                    char symbol = (char)162;
                    DrawingElements.Add(new DrawString(
                                            symbol.ToString(),
                                            new Font("Wingdings 2", 12),
                                            new SolidBrush(gr.PrimaryColor),
                                            colorRectangle,
                                            LegendStringFormat));
                }
                DrawingElements.Add(
                    new DrawRectangle(outline, LegendRectangle.X, LegendRectangle.Y, LegendRectangle.Width - 1,
                                      GraphData.Ranges.Count * textHeight));
            }
        }
示例#4
0
        public async Task <Responce> PostGraphAsync([FromBody] InputGraph input)
        {
            var converted = await GraphHelpers.GraphToMatrixAsync(input);

            return(await PostAsync(converted));
        }
示例#5
0
        public async Task <Responce> GlrTestGraphAsync([FromBody] InputGraph input, int maxSubNodesCount = 3, int maxTreeDepth = 5)
        {
            var converted = await GraphHelpers.GraphToMatrixAsync(input);

            return(await GlrTestAsync(converted, maxSubNodesCount, maxTreeDepth));
        }
示例#6
0
 ModularitySearchService(GraphHelpers helpers)
 {
     _helpers = helpers;
 }
示例#7
0
 public override bool Contains(PointF point)
 {
     return(GraphHelpers.Length(point) <= this.mRadius);
 }