Ejemplo n.º 1
0
        public void PathRoute()
        {
            var url = new Uri("http://163.com/News/Test/1");

            {
                var pathSegments = PathSegments.Create(url.AbsolutePath);

                var template = new RewritePathTemplate("/{path*}");
                var values   = template.GetRouteValues(pathSegments);

                Assert.AreEqual(values.Count, 1);
                Assert.AreEqual(values.Keys.First(), "path");
                Assert.AreEqual(values.Values.First(), "News/Test/1");
                Assert.AreEqual(values["path"], "News/Test/1");
            }

            {
                var template = new RewriteRequestTemplate("http://163.com/news/{path*}");
                var values   = template.GetRouteValues(new RouteRequestData(new HttpRequestMessage(HttpMethod.Get, url)));

                Assert.AreEqual(values.Count, 1);
                Assert.AreEqual(values.Keys.First(), "path");
                Assert.AreEqual(values.Values.First(), "Test/1");
                Assert.AreEqual(values["path"], "Test/1");
            }
        }
Ejemplo n.º 2
0
            public static AppPath MakePath(string path)
            {
                var words       = path.Split(_pathSeparatorChars, StringSplitOptions.RemoveEmptyEntries).ToList();
                var result      = new List <int>();
                var typeIndex   = -1;
                var actionIndex = -1;
                var isType      = false;
                var i           = 0;

                while (i < words.Count)
                {
                    var word = words[i];
                    if (isType)
                    {
                        // remove current word and insert words of type path
                        if (word != "This")
                        {
                            var ntype = Providers.Instance.StorageSchema.NodeTypes[word];
                            if (ntype == null)
                            {
                                return(null);
                            }
                            var typeNames = ntype.NodeTypePath.Split('/');
                            words.RemoveAt(i);
                            words.InsertRange(i, typeNames);
                            word        = words[i];
                            actionIndex = i + typeNames.Length;
                        }
                        else
                        {
                            actionIndex = i + 1;
                        }
                        isType = false;
                    }
                    word = word.ToLowerInvariant();
                    if (word == AppFolderName)
                    {
                        typeIndex = i;
                        isType    = true;
                        words.RemoveAt(i);
                        continue;
                    }

                    var index = PathSegments.IndexOf(word);
                    if (index < 0)
                    {
                        index = PathSegments.Count;
                        PathSegments.Add(word);
                    }
                    result.Add(index);
                    i++;
                }
                var appPath = new AppPath {
                    Indices = result.ToArray(), TypeIndex = typeIndex, ActionIndex = actionIndex
                };

                appPath.Initialize();
                return(appPath);
            }
Ejemplo n.º 3
0
        public static string InsertMachineName(this string path)
        {
            var pathSegments = new PathSegments(path);

            pathSegments.FileName = $"{pathSegments.FileName}_{Environment.MachineName.ToLower()}.dummy";

            return(pathSegments.GetFullPath());
        }
Ejemplo n.º 4
0
 protected void PushPath(params string[] segments)
 {
     foreach (var path in segments)
     {
         PathSegments.Push(path);
     }
     BuildBasePath();
 }
Ejemplo n.º 5
0
        public void EmptyPath()
        {
            var pathTemplate = new RewritePathTemplate("/{path*}");
            var values       = pathTemplate.GetRouteValues(PathSegments.Create("/"));

            Assert.IsTrue(values.ContainsKey("path"));
            Assert.AreEqual(values["path"], null);
        }
Ejemplo n.º 6
0
            public static AppPath MakePath(NodeHead head, string actionName, string[] device)
            {
                var actionNameIndex = -1;
                if (actionName != null)
                {
                    actionName = actionName.ToLowerInvariant();
                    actionNameIndex = PathSegments.IndexOf(actionName);
                    if (actionNameIndex < 0)
                        return null;
                }

                var words = head.Path.Split(_pathSeparatorChars, StringSplitOptions.RemoveEmptyEntries).ToList();
                for (int i = 0; i < words.Count; i++)
                    words[i] = words[i].ToLowerInvariant();

                var result = new List<int>();
                var typeIndex = -1;
                var actionIndex = -1;
                var isTruncated = false;
                foreach (var word in words)
                {
                    var index = PathSegments.IndexOf(word);
                    if (index < 0)
                    {
                        isTruncated = true;
                        break;
                    }
                    result.Add(index);
                }
                typeIndex = result.Count;

                var ntype = ActiveSchema.NodeTypes.GetItemById(head.NodeTypeId);
                var typeNames = ntype.NodeTypePath.Split('/');
                foreach (var typeName in typeNames)
                {
                    var index = PathSegments.IndexOf(typeName.ToLowerInvariant());
                    if (index < 0)
                        break;
                    result.Add(index);
                }

                actionIndex = result.Count;
                result.Add(actionNameIndex); // can be -1
                if (device != null)
                {
                    for (int i = device.Length - 1; i >= 0; i--)
                    {
                        var index = PathSegments.IndexOf(device[i]);
                        if (index < 0)
                            break;
                        result.Add(index);
                    }
                }

                var appPath = new AppPath { Indices = result.ToArray(), TypeIndex = typeIndex, ActionIndex = actionIndex, Truncated = isTruncated };
                appPath.Initialize();
                return appPath;
            }
Ejemplo n.º 7
0
        public void PathSegmentsTest()
        {
            var segments = PathSegments.Create("/a/b/c");

            Assert.AreEqual(segments.Count, 3);
            Assert.AreEqual(segments[0], "a");
            Assert.AreEqual(segments[1], "b");
            Assert.AreEqual(segments[2], "c");
        }
Ejemplo n.º 8
0
    public MenuItemLocation GetSubMenuPath(string name)
    {
        if (name is null)
        {
            throw new ArgumentNullException(nameof(name));
        }

        return(new MenuItemLocation(PathSegments.Append(name)));
    }
Ejemplo n.º 9
0
        private void BuildBasePath()
        {
            var parts = new List <string>(new [] { Directory.GetCurrentDirectory(), AssetsFolder });

            parts.AddRange(PathSegments.Reverse());

            BasePath = Path.Combine(parts.ToArray());

            Log.Info("Asset base path: " + BasePath);
        }
Ejemplo n.º 10
0
 public RoundedRectangleGeometry(Rect bounds, double radius)
 {
   var segments = new PathSegments();
   segments.AddRange(CreateRoundedRectangle(bounds, radius));
   Figures = new PathFigures {
     new PathFigure {
       StartPoint = bounds.TopLeft + new Point(radius,0),
       Segments = segments
     }
   };
 }
        public PathFigure Convert(Microsoft.Msagl.Core.Geometry.Curves.ICurve curve)
        {
            var segments = new PathSegments();

            segments.AddRange(Flatten(curve).Select(s => TransformSegment(s)));
            return(new PathFigure
            {
                StartPoint = Convert(curve.Start),
                Segments = segments,
                IsClosed = false,
                IsFilled = false
            });
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Retrieves the next path segment from the stack as a string.
        /// Returns null if none exist.
        /// </summary>
        /// <returns></returns>
        public List <string> GetPathSegments()
        {
            if (Path != null)
            {
                PathSegments.Add(Path.ToString());
            }

            if (MemoryMappedFileManager != null)
            {
                PathSegments.AddRange(MemoryMappedFileManager.GetFileContent());
            }

            return(PathSegments);
        }
Ejemplo n.º 13
0
        public RoutePattern Build()
        {
            var parameters = new List <RoutePatternParameter>();

            for (var i = 0; i < PathSegments.Count; i++)
            {
                var segment = PathSegments[i];
                for (var j = 0; j < segment.Parts.Count; j++)
                {
                    if (segment.Parts[j] is RoutePatternParameter parameter)
                    {
                        parameters.Add(parameter);
                    }
                }
            }

            return(new RoutePattern(RawText, parameters.ToArray(), PathSegments.ToArray()));
        }
Ejemplo n.º 14
0
        public RoutePatternBuilder AddPathSegmentFromText(string text, params RoutePatternPart[] parts)
        {
            if (parts == null)
            {
                throw new ArgumentNullException(nameof(parts));
            }

            if (parts.Length == 0)
            {
                throw new ArgumentException(Resources.RoutePatternBuilder_CollectionCannotBeEmpty, nameof(parts));
            }

            var segment = new RoutePatternPathSegment(text, parts.ToArray());

            PathSegments.Add(segment);

            return(this);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PathFigure"/> class.
 /// </summary>
 public PathFigure()
 {
     Segments = new PathSegments();
 }
Ejemplo n.º 16
0
 protected void UsePath(params string[] segments)
 {
     PathSegments.Clear();
     PushPath(segments);
     BuildBasePath();
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PathFigure"/> class.
 /// </summary>
 public PathFigure()
 {
     Segments = new PathSegments();
 }
Ejemplo n.º 18
0
 public void Path()
 {
     var result = PathSegments.Create("/favicon.ico");
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Create a border geometry with a 'pointer'.
        /// </summary>
        /// <param name="ha">The horizontal alignment.</param>
        /// <param name="va">The vertical alignment.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="margin">The margin.</param>
        /// <returns>The border geometry.</returns>
        private Geometry CreatePointerBorderGeometry(
            HorizontalAlignment ha, VerticalAlignment va, double width, double height, out Thickness margin)
        {
            Point[] points = null;
            var     m      = Distance;

            margin = new Thickness();

            if (ha == HorizontalAlignment.Center && va == VerticalAlignment.Bottom)
            {
                var x1 = width;
                var x2 = x1 / 2;
                var y1 = height;
                margin = new Thickness(0, 0, 0, m);
                points = new[]
                {
                    new Point(0, 0), new Point(x1, 0), new Point(x1, y1), new Point(x2 + (m / 2), y1),
                    new Point(x2, y1 + m), new Point(x2 - (m / 2), y1), new Point(0, y1)
                };
            }
            else if (ha == HorizontalAlignment.Center && va == VerticalAlignment.Top)
            {
                var x1 = width;
                var x2 = x1 / 2;
                var y0 = m;
                var y1 = m + height;
                margin = new Thickness(0, m, 0, 0);
                points = new[]
                {
                    new Point(0, y0), new Point(x2 - (m / 2), y0), new Point(x2, 0), new Point(x2 + (m / 2), y0),
                    new Point(x1, y0), new Point(x1, y1), new Point(0, y1)
                };
            }
            else if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Center)
            {
                var x0 = m;
                var x1 = m + width;
                var y1 = height;
                var y2 = y1 / 2;
                margin = new Thickness(m, 0, 0, 0);
                points = new[]
                {
                    new Point(0, y2), new Point(x0, y2 - (m / 2)), new Point(x0, 0), new Point(x1, 0),
                    new Point(x1, y1), new Point(x0, y1), new Point(x0, y2 + (m / 2))
                };
            }
            else if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Center)
            {
                var x1 = width;
                var y1 = height;
                var y2 = y1 / 2;
                margin = new Thickness(0, 0, m, 0);
                points = new[]
                {
                    new Point(x1 + m, y2), new Point(x1, y2 + (m / 2)), new Point(x1, y1), new Point(0, y1),
                    new Point(0, 0), new Point(x1, 0), new Point(x1, y2 - (m / 2))
                };
            }
            else if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Top)
            {
                m *= 0.67;
                var x0 = m;
                var x1 = m + width;
                var y0 = m;
                var y1 = m + height;
                margin = new Thickness(m, m, 0, 0);
                points = new[]
                {
                    new Point(0, 0), new Point(m * 2, y0), new Point(x1, y0), new Point(x1, y1), new Point(x0, y1),
                    new Point(x0, m * 2)
                };
            }
            else if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Top)
            {
                m *= 0.67;
                var x1 = width;
                var y0 = m;
                var y1 = m + height;
                margin = new Thickness(0, m, m, 0);
                points = new[]
                {
                    new Point(x1 + m, 0), new Point(x1, y0 + m), new Point(x1, y1), new Point(0, y1),
                    new Point(0, y0), new Point(x1 - m, y0)
                };
            }
            else if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Bottom)
            {
                m *= 0.67;
                var x0 = m;
                var x1 = m + width;
                var y1 = height;
                margin = new Thickness(m, 0, 0, m);
                points = new[]
                {
                    new Point(0, y1 + m), new Point(x0, y1 - m), new Point(x0, 0), new Point(x1, 0),
                    new Point(x1, y1), new Point(x0 + m, y1)
                };
            }
            else if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Bottom)
            {
                m *= 0.67;
                var x1 = width;
                var y1 = height;
                margin = new Thickness(0, 0, m, m);
                points = new[]
                {
                    new Point(x1 + m, y1 + m), new Point(x1 - m, y1), new Point(0, y1), new Point(0, 0),
                    new Point(x1, 0), new Point(x1, y1 - m)
                };
            }

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

            var pc = new List <Point>(points.Length);

            foreach (var p in points)
            {
                pc.Add(p);
            }
            var segments = new PathSegments();

            segments.AddRange(pc.Select(p => new LineSegment {
                Point = p
            }));
            var pf = new PathFigure {
                StartPoint = points[0], Segments = segments, IsClosed = true
            };

            return(new PathGeometry {
                Figures = new PathFigures {
                    pf
                }
            });
        }
Ejemplo n.º 20
0
        /// <summary>
        /// sets the tick values
        /// </summary>
        /// <param name="dc"></param>
        public override void Render(DrawingContext dc)
        {
            if (DoubleUtil.IsDoubleFinite(Width) == false)
            {
                this.Width = controlSize.Width;
                //base.Render(dc);
                //return;
            }

            Size   size    = new Size(Width, Height);
            double range   = Maximum - Minimum;
            double tickLen = 0.0d;  // Height for Primary Tick (for Mininum and Maximum value)
            double tickLen2;        // Height for Secondary Tick
            double logicalToPhysical = 1.0;
            double progression       = 1.0d;
            Point  startPoint        = new Point(0d, 0d);
            Point  endPoint          = new Point(0d, 0d);

            // Take Thumb size in to account
            double halfReservedSpace = ReservedSpace * 0.5;

            switch (Placement)
            {
            case TickBarPlacement.Top:
                if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Width))
                {
                    return;
                }
                size              = new Size(size.Width - ReservedSpace, size.Height);
                tickLen           = -size.Height;
                startPoint        = new Point(halfReservedSpace, size.Height);
                endPoint          = new Point(halfReservedSpace + size.Width, size.Height);
                logicalToPhysical = size.Width / range;
                progression       = 1;
                break;

            case TickBarPlacement.Bottom:
                if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Width))
                {
                    return;
                }
                size              = new Size(size.Width - ReservedSpace, size.Height);
                tickLen           = size.Height;
                startPoint        = new Point(halfReservedSpace, 0d);
                endPoint          = new Point(halfReservedSpace + size.Width, 0d);
                logicalToPhysical = size.Width / range;
                progression       = 1;
                break;

            case TickBarPlacement.Left:
                if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Height))
                {
                    return;
                }
                size              = new Size(size.Width, size.Height - ReservedSpace);
                tickLen           = -size.Width;
                startPoint        = new Point(size.Width, size.Height + halfReservedSpace);
                endPoint          = new Point(size.Width, halfReservedSpace);
                logicalToPhysical = size.Height / range * -1;
                progression       = -1;
                break;

            case TickBarPlacement.Right:
                if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Height))
                {
                    return;
                }
                size              = new Size(size.Width, size.Height - ReservedSpace);
                tickLen           = size.Width;
                startPoint        = new Point(0d, size.Height + halfReservedSpace);
                endPoint          = new Point(0d, halfReservedSpace);
                logicalToPhysical = size.Height / range * -1;
                progression       = -1;
                break;
            }
            ;

            tickLen2 = tickLen * 0.75;

            // Invert direciton of the ticks
            if (IsDirectionReversed)
            {
                progression        = -progression;
                logicalToPhysical *= -1;

                // swap startPoint & endPoint
                Point pt = startPoint;
                startPoint = endPoint;
                endPoint   = pt;
            }

            Pen pen = new Pen(Fill, 1.0d);

            bool             snapsToDevicePixels = false;//SnapsToDevicePixels
            DoubleCollection xLines = snapsToDevicePixels ? new DoubleCollection() : null;
            DoubleCollection yLines = snapsToDevicePixels ? new DoubleCollection() : null;

            // Is it Vertical?
            if ((Placement == TickBarPlacement.Left) || (Placement == TickBarPlacement.Right))
            {
                // Reduce tick interval if it is more than would be visible on the screen
                double interval = TickFrequency;
                if (interval > 0.0)
                {
                    double minInterval = (Maximum - Minimum) / size.Height;
                    if (interval < minInterval)
                    {
                        interval = minInterval;
                    }
                }

                // Draw Min & Max tick
                dc.DrawLine(pen, startPoint, new Point(startPoint.X + tickLen, startPoint.Y));
                dc.DrawLine(pen, new Point(startPoint.X, endPoint.Y),
                            new Point(startPoint.X + tickLen, endPoint.Y));

                if (snapsToDevicePixels)
                {
                    xLines.Add(startPoint.X);
                    yLines.Add(startPoint.Y - 0.5);
                    xLines.Add(startPoint.X + tickLen);
                    yLines.Add(endPoint.Y - 0.5);
                    xLines.Add(startPoint.X + tickLen2);
                }

                // This property is rarely set so let's try to avoid the GetValue
                // caching of the mutable default value
                DoubleCollection ticks = null;

                if (GetValue(TicksProperty)
                    != null)
                {
                    ticks = Ticks;
                }

                // Draw ticks using specified Ticks collection
                if ((ticks != null) && (ticks.Count > 0))
                {
                    for (int i = 0; i < ticks.Count; i++)
                    {
                        if (DoubleUtil.LessThanOrClose(ticks[i], Minimum) || DoubleUtil.GreaterThanOrClose(ticks[i], Maximum))
                        {
                            continue;
                        }

                        double adjustedTick = ticks[i] - Minimum;

                        double y = adjustedTick * logicalToPhysical + startPoint.Y;
                        dc.DrawLine(pen,
                                    new Point(startPoint.X, y),
                                    new Point(startPoint.X + tickLen2, y));

                        if (snapsToDevicePixels)
                        {
                            yLines.Add(y - 0.5);
                        }
                    }
                }
                // Draw ticks using specified TickFrequency
                else if (interval > 0.0)
                {
                    for (double i = interval; i < range; i += interval)
                    {
                        double y = i * logicalToPhysical + startPoint.Y;

                        dc.DrawLine(pen,
                                    new Point(startPoint.X, y),
                                    new Point(startPoint.X + tickLen2, y));

                        if (snapsToDevicePixels)
                        {
                            yLines.Add(y - 0.5);
                        }
                    }
                }

                // Draw Selection Ticks
                if (IsSelectionRangeEnabled)
                {
                    double y0  = (SelectionStart - Minimum) * logicalToPhysical + startPoint.Y;
                    Point  pt0 = new Point(startPoint.X, y0);
                    Point  pt1 = new Point(startPoint.X + tickLen2, y0);
                    Point  pt2 = new Point(startPoint.X + tickLen2, y0 + Math.Abs(tickLen2) * progression);

                    //PathSegment[] segments = new PathSegment[] {
                    //    //new LineSegment(pt2, true),
                    //    //new LineSegment(pt0, true),
                    //    new LineSegment{Point=pt2 },
                    //    new LineSegment{Point=pt0 },
                    //};

                    PathSegments segments = new PathSegments();
                    segments.Add(new LineSegment {
                        Point = pt2
                    });
                    segments.Add(new LineSegment {
                        Point = pt0
                    });

                    PathGeometry geo = new PathGeometry {
                        Figures = new PathFigures {
                            new PathFigure {
                                StartPoint = pt1, Segments = segments, IsClosed = true
                            }
                        }
                    };

                    dc.DrawGeometry(Fill, pen, geo);

                    y0  = (SelectionEnd - Minimum) * logicalToPhysical + startPoint.Y;
                    pt0 = new Point(startPoint.X, y0);
                    pt1 = new Point(startPoint.X + tickLen2, y0);
                    pt2 = new Point(startPoint.X + tickLen2, y0 - Math.Abs(tickLen2) * progression);

                    segments = new PathSegments();
                    segments.Add(new LineSegment {
                        Point = pt2
                    });
                    segments.Add(new LineSegment {
                        Point = pt0
                    });

                    geo = new PathGeometry {
                        Figures = new PathFigures {
                            new PathFigure {
                                StartPoint = pt1, Segments = segments, IsClosed = true
                            }
                        }
                    };
                    dc.DrawGeometry(Fill, pen, geo);
                }
            }
            else  // Placement == Top || Placement == Bottom
            {
                // Reduce tick interval if it is more than would be visible on the screen
                double interval = TickFrequency;
                if (interval > 0.0)
                {
                    double minInterval = (Maximum - Minimum) / size.Width;
                    if (interval < minInterval)
                    {
                        interval = minInterval;
                    }
                }

                // Draw Min & Max tick
                dc.DrawLine(pen, startPoint, new Point(startPoint.X, startPoint.Y + tickLen));
                dc.DrawLine(pen, new Point(endPoint.X, startPoint.Y),
                            new Point(endPoint.X, startPoint.Y + tickLen));

                if (snapsToDevicePixels)
                {
                    xLines.Add(startPoint.X - 0.5);
                    yLines.Add(startPoint.Y);
                    xLines.Add(startPoint.X - 0.5);
                    yLines.Add(endPoint.Y + tickLen);
                    yLines.Add(endPoint.Y + tickLen2);
                }

                // This property is rarely set so let's try to avoid the GetValue
                // caching of the mutable default value
                DoubleCollection ticks = null;

                if (GetValue(TicksProperty)
                    != null)
                {
                    ticks = Ticks;
                }

                // Draw ticks using specified Ticks collection
                if ((ticks != null) && (ticks.Count > 0))
                {
                    for (int i = 0; i < ticks.Count; i++)
                    {
                        if (DoubleUtil.LessThanOrClose(ticks[i], Minimum) || DoubleUtil.GreaterThanOrClose(ticks[i], Maximum))
                        {
                            continue;
                        }
                        double adjustedTick = ticks[i] - Minimum;

                        double x = adjustedTick * logicalToPhysical + startPoint.X;
                        dc.DrawLine(pen,
                                    new Point(x, startPoint.Y),
                                    new Point(x, startPoint.Y + tickLen2));

                        if (snapsToDevicePixels)
                        {
                            xLines.Add(x - 0.5);
                        }
                    }
                }
                // Draw ticks using specified TickFrequency
                else if (interval > 0.0)
                {
                    for (double i = interval; i < range; i += interval)
                    {
                        double x = i * logicalToPhysical + startPoint.X;
                        dc.DrawLine(pen,
                                    new Point(x, startPoint.Y),
                                    new Point(x, startPoint.Y + tickLen2));

                        if (snapsToDevicePixels)
                        {
                            xLines.Add(x - 0.5);
                        }
                    }
                }

                // Draw Selection Ticks
                if (IsSelectionRangeEnabled)
                {
                    double x0  = (SelectionStart - Minimum) * logicalToPhysical + startPoint.X;
                    Point  pt0 = new Point(x0, startPoint.Y);
                    Point  pt1 = new Point(x0, startPoint.Y + tickLen2);
                    Point  pt2 = new Point(x0 + Math.Abs(tickLen2) * progression, startPoint.Y + tickLen2);

                    //PathSegment[] segments = new PathSegment[] {
                    //    new LineSegment(pt2, true),
                    //    new LineSegment(pt0, true),
                    //};

                    PathSegments segments = new PathSegments();
                    segments.Add(new LineSegment {
                        Point = pt2
                    });
                    segments.Add(new LineSegment {
                        Point = pt0
                    });

                    PathGeometry geo = new PathGeometry {
                        Figures = new PathFigures {
                            new PathFigure {
                                StartPoint = pt1, Segments = segments, IsClosed = true
                            }
                        }
                    };

                    dc.DrawGeometry(Fill, pen, geo);

                    x0  = (SelectionEnd - Minimum) * logicalToPhysical + startPoint.X;
                    pt0 = new Point(x0, startPoint.Y);
                    pt1 = new Point(x0, startPoint.Y + tickLen2);
                    pt2 = new Point(x0 - Math.Abs(tickLen2) * progression, startPoint.Y + tickLen2);

                    segments = new PathSegments();
                    segments.Add(new LineSegment {
                        Point = pt2
                    });
                    segments.Add(new LineSegment {
                        Point = pt0
                    });

                    geo = new PathGeometry {
                        Figures = new PathFigures {
                            new PathFigure {
                                StartPoint = pt1, Segments = segments, IsClosed = true
                            }
                        }
                    };
                    dc.DrawGeometry(Fill, pen, geo);
                }
            }

            if (snapsToDevicePixels)
            {
                xLines.Add(Width);
                yLines.Add(Height);
                VisualXSnappingGuidelines = xLines;
                VisualYSnappingGuidelines = yLines;
            }
            return;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Execute the query represented by an OData URI against an <c>IQueryable</c> data source
        /// </summary>
        /// <param name="query"><c>IQueryable</c> data source</param>
        /// <param name="inputType">Model data type</param>
        /// <param name="dynamicAccessor">Expression for accessing fields on dynamic model objects</param>
        public ODataQueryable <object> Execute(IQueryable query, ExecutionSettings settings = null)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query", "Query cannot be null");
            }

            settings = settings ?? ExecutionSettings.Empty;
            var queryResult      = query;
            var constrainedQuery = query;
            var path             = settings.GetEdmSource(this);
            var inputType        = settings.GetInputType(query);
            var dynamicAccessor  = settings.GetDynamicAccessor();
            var lookupByKey      = false;

            var children = this.QueryOption.Where(n => !(n is IgnoredNode) && !(n is AliasNode)).ToList();

            // Try and do an ID lookup if applicable
            var segments     = PathSegments.ToArray();
            var functionNode = segments.FirstOrDefault() as CallNode;

            if (functionNode != null && segments.Length == 1)
            {
                var entity = ((IEdmCollectionType)path.Type).ElementType.ToStructuredType() as IEdmEntityType;
                if (entity != null && entity.Key().Count() == functionNode.Arguments.Count)
                {
                    var keys = entity.Key().ToArray();
                    var root = default(ODataNode);
                    for (var i = 0; i < keys.Length; i++)
                    {
                        var newNode = ODataNode.Equals(ODataNode.Identifier(keys[i].Name), functionNode.Arguments[i]);
                        if (root == null)
                        {
                            root = newNode;
                        }
                        else
                        {
                            newNode = ODataNode.And(root, newNode);
                        }
                    }

                    children.RemoveByFilter(n => n is FilterNode);
                    children.Add(ODataNode.Filter(root));
                    lookupByKey = true;
                }
            }

            var maxPageSize = settings.GetMaxPageSize();

            if (maxPageSize.HasValue && (!QueryOption.Top.HasValue || maxPageSize.Value < QueryOption.Top.Value))
            {
                children.RemoveByFilter(n => n is TopNode);
                children.Add(ODataNode.Top(ODataNode.Literal(maxPageSize.Value)));
            }
            children.Sort();

            // These should always come first
            foreach (var node in children.Where(o => !(o is SelectNode)))
            {
                BuildQuery(node, inputType, dynamicAccessor, ref queryResult, ref constrainedQuery);
            }

            var selectNode = children.FirstOrDefault(o => o is SelectNode);

            if (selectNode != null)
            {
                constrainedQuery = ProjectQuery(constrainedQuery, selectNode, inputType, dynamicAccessor);
            }

            return(new ODataQueryable <object>(constrainedQuery, this)
            {
                LookupByKey = lookupByKey
            });
        }