Пример #1
0
        public BracketedExpressionSegment(IEnumerable <IExpressionSegment> segments)
        {
            if (segments == null)
            {
                throw new ArgumentNullException("segments");
            }

            Segments = segments.ToList().AsReadOnly();
            if (Segments.Any(e => e == null))
            {
                throw new ArgumentException("Null reference encountered in segments set");
            }
            if (!Segments.Any())
            {
                throw new ArgumentException("Empty segments set specified - invalid");
            }

            // 2015-03-23 DWR: For deeply-nested bracketed segments, it can be very expensive to enumerate over their AllTokens sets repeatedly so it's worth preparing the data once and
            // avoiding doing it over and over again. This is often seen with an expression with many string concatenations - currently they are broken down into pairs of operations,
            // which results in many bracketed operations (I want to change this for concatenations going forward, since it's so common to have sets of concatenations and it would
            // be better if the CONCAT took a variable number of arguments rather than just two, but this hasn't been done yet).
            _allTokens =
                new IToken[] { new OpenBrace(Segments.First().AllTokens.First().LineIndex) }
            .Concat(Segments.SelectMany(s => s.AllTokens))
            .Concat(new[] { new CloseBrace(Segments.Last().AllTokens.Last().LineIndex) })
            .ToList()
            .AsReadOnly();
        }
Пример #2
0
 /// <summary>
 /// Extends a memory chunk references list by adding a new reference. If the new reference is contiguous to the last existing reference,
 /// then the list size remains constant.
 /// </summary>
 /// <param name="memoryChunkReferences"></param>
 /// <param name="newSegment"></param>
 public void ExtendSegments(MemoryBlockIDAndSlice blockAndSlice, bool extendEarlierReferencesForSameChunk)
 {
     if (Segments.Any())
     {
         if (extendEarlierReferencesForSameChunk)
         {
             for (int i = 0; i < Segments.Count; i++)
             {
                 var segment = Segments[i];
                 if (segment.MemoryBlockID == blockAndSlice.MemoryBlockID)
                 {
                     MemoryChunk existingChunk = GetMemoryChunkByMemoryBlockID(segment.MemoryBlockID);
                     if (existingChunk != null)
                     {
                         existingChunk.LoadingInfo.PreTruncationLength = blockAndSlice.Length;
                     }
                 }
             }
         }
         var last = Segments.Last();
         if (last.MemoryBlockID == blockAndSlice.MemoryBlockID && blockAndSlice.Offset == last.Offset + last.Length)
         {
             last = new MemoryBlockIDAndSlice(last.MemoryBlockID, last.Offset, last.Length + blockAndSlice.Length);
             Segments[Segments.Count - 1] = last;
             PatchesTotalLength          += blockAndSlice.Length;
             return;
         }
     }
     Segments.Add(new MemoryBlockIDAndSlice(blockAndSlice.MemoryBlockID, blockAndSlice.Offset, blockAndSlice.Length));
     PatchesTotalLength += blockAndSlice.Length;
 }
Пример #3
0
        // Transforms query to a string.
        public string ToString(int profileCounter)
        {
            StringBuilder queryBuilder = new StringBuilder();

            queryBuilder.Append(General.GA_RequestURIs.Default.ReportFeed);
//            (Ids.Count > 1 ?  Ids.ToList().First().ToString() :
            queryBuilder.Append(Ids.Count > 0 ? Ids.ToString(profileCounter) : string.Empty);
            queryBuilder.Append(Dimensions.Count > 0 ? "&dimensions=" + string.Join(",", Dimensions.Values.ToArray()) : string.Empty);
            queryBuilder.Append(Metrics.Count > 0 ? "&metrics=" + string.Join(",", Metrics.Values.ToArray()) : string.Empty);
            if (Segments.Count > 0 && !Segments.Any(s => s.Value == ""))
            {
                queryBuilder.Append(Segments.Count > 0 ? "&segment=" + string.Join(",", Segments.Values.ToArray()) : string.Empty);
            }
            queryBuilder.Append(Filter.ToString());
            queryBuilder.Append(Sort.ToString());
            if (_selectDates.Equals(false))
            {
                queryBuilder.Append(GetQueryTimeSpan());
                TimeRange();
            }
            else
            {
                string paramContainer = "&start-date={0}&end-date={1}";
                queryBuilder.Append(string.Format(paramContainer, ToUnifiedCultureFormat(StartDate), ToUnifiedCultureFormat(EndDate)));
            }
            queryBuilder.Append(StartIndex > 0 ? "&start-index=" + StartIndex : string.Empty);
            queryBuilder.Append("&max-results=" + MaxResults);
            return(queryBuilder.ToString());
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of <see cref="ODataPath"/> class.
 /// </summary>
 /// <param name="segments">The segments.</param>
 public ODataPath(IEnumerable <ODataSegment> segments)
 {
     Segments = segments.ToList();
     if (Segments.Any(s => s == null))
     {
         throw Error.ArgumentNull("segments");
     }
 }
Пример #5
0
        private ODataPathKind CalcPathType()
        {
            if (Segments.Count == 1 && Segments.First().Kind == ODataSegmentKind.Metadata)
            {
                return(ODataPathKind.Metadata);
            }
            else if (Segments.Last().Kind == ODataSegmentKind.DollarCount)
            {
                return(ODataPathKind.DollarCount);
            }
            else if (Segments.Last().Kind == ODataSegmentKind.TypeCast)
            {
                return(ODataPathKind.TypeCast);
            }
            else if (Segments.Last().Kind == ODataSegmentKind.ComplexProperty)
            {
                return(ODataPathKind.ComplexProperty);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.StreamProperty || c.Kind == ODataSegmentKind.StreamContent))
            {
                return(ODataPathKind.MediaEntity);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.Ref))
            {
                return(ODataPathKind.Ref);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.OperationImport))
            {
                return(ODataPathKind.OperationImport);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.Operation))
            {
                return(ODataPathKind.Operation);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.NavigationProperty))
            {
                return(ODataPathKind.NavigationProperty);
            }
            else if (Segments.Count == 1 && Segments[0] is ODataNavigationSourceSegment segment)
            {
                if (segment.NavigationSource is IEdmSingleton)
                {
                    return(ODataPathKind.Singleton);
                }
                else
                {
                    return(ODataPathKind.EntitySet);
                }
            }
            else if (Segments.Count == 2 && Segments.Last().Kind == ODataSegmentKind.Key)
            {
                return(ODataPathKind.Entity);
            }

            return(ODataPathKind.Unknown);
        }
Пример #6
0
        /// <summary>
        /// Gets whether the specified offset is included in the selection.
        /// </summary>
        /// <returns>True, if the selection contains the offset (selection borders inclusive);
        /// otherwise, false.</returns>
        public virtual bool Contains(int offset)
        {
            if (IsEmpty)
            {
                return(false);
            }

            return(SurroundingSegment.Contains(offset, 0) &&
                   Segments.Any(s => s.Contains(offset, 0)));
        }
Пример #7
0
        public bool Remove(Position p)
        {
            if (Segments.Any(s => s.Position == p))
            {
                Segments.First(s => s.Position == p).RemoveElement();
                return(true);
            }

            return(false);
        }
Пример #8
0
        /// <summary>
        /// Pop the last segment.
        /// </summary>
        /// <returns>The pop last segment.</returns>
        internal ODataPath Pop()
        {
            if (!Segments.Any())
            {
                throw Error.InvalidOperation(SRResource.ODataPathPopInvalid);
            }

            _pathKind            = null;
            _defaultPathItemName = null;
            Segments.RemoveAt(Segments.Count - 1);
            return(this);
        }
Пример #9
0
 public void ToAml(XmlWriter writer, AmlWriterSettings settings)
 {
     writer.WriteStartElement("Item");
     writer.WriteAttributeString("type", Type);
     writer.WriteAttributeString("id", Id);
     writer.WriteAttributeString("action", "edit");
     writer.WriteAttributeString("doGetItem", "0");
     writer.WriteElementString("x", _context.Format(Position.X));
     writer.WriteElementString("y", _context.Format(Position.Y));
     if (Segments.Any())
     {
         writer.WriteElementString("segments", Segments.GroupConcat("|", p => $"{p.X},{p.Y}"));
     }
     writer.WriteEndElement();
 }
Пример #10
0
        public Subpath(Point startPoint, [NotNull] IEnumerable <SegmentBase> segments, bool isClosed)
        {
            StartPoint = startPoint;
            Segments   = segments.ToReadOnlyList();
            IsClosed   = isClosed;

            if (Segments.Any(x => x == null))
            {
                throw new ArgumentException();
            }

            if (Segments.Count > 0 && EndPoint != StartPoint)
            {
                _closingSegment = new LineSegment(StartPoint);
            }
        }
Пример #11
0
        public Expression(IEnumerable <IExpressionSegment> segments)
        {
            if (segments == null)
            {
                throw new ArgumentNullException("segments");
            }

            Segments = segments.ToList().AsReadOnly();
            if (!Segments.Any())
            {
                throw new ArgumentException("The segments set may not be empty");
            }
            if (Segments.Any(t => t == null))
            {
                throw new ArgumentException("Null reference encountered in segments set");
            }
        }
Пример #12
0
        private ODataPathKind CalcPathType()
        {
            if (Segments.Any(c => c.Kind == ODataSegmentKind.StreamProperty || c.Kind == ODataSegmentKind.StreamContent))
            {
                return(ODataPathKind.MediaEntity);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.Ref))
            {
                return(ODataPathKind.Ref);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.OperationImport))
            {
                return(ODataPathKind.OperationImport);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.Operation))
            {
                return(ODataPathKind.Operation);
            }
            else if (Segments.Any(c => c.Kind == ODataSegmentKind.NavigationProperty))
            {
                return(ODataPathKind.NavigationProperty);
            }

            if (Segments.Count == 1)
            {
                ODataNavigationSourceSegment segment = Segments[0] as ODataNavigationSourceSegment;
                if (segment != null)
                {
                    if (segment.NavigationSource is IEdmSingleton)
                    {
                        return(ODataPathKind.Singleton);
                    }
                    else
                    {
                        return(ODataPathKind.EntitySet);
                    }
                }
            }
            else if (Segments.Count == 2 && Segments.Last().Kind == ODataSegmentKind.Key)
            {
                return(ODataPathKind.Entity);
            }

            return(ODataPathKind.Unknown);
        }
Пример #13
0
        protected virtual HttpUri CreateUri()
        {
            var url = BaseUrl.CombinePath(ResourceUrl).AddQueryParams(QueryParams.Concat(SuffixQueryParams));

            if (Segments.Any())
            {
                var fullUri = url.FullUri;

                foreach (var segment in Segments)
                {
                    fullUri = fullUri.Replace(segment.Key, segment.Value);
                }

                url = new HttpUri(fullUri);
            }

            return(url);
        }
Пример #14
0
        public string this[string propertyName]
        {
            get
            {
                try
                {
                    string validationResult = String.Empty;
                    if (ValidationEnabled)
                    {
                        switch (propertyName)
                        {
                        case "TaskSegment":
                            if (TaskSegment < EnumSimpleCommandSegmentTask.Reset)
                            {
                                validationResult = ResourceReader.GetString("ERR_TASK");
                            }
                            break;

                        case "Segment":
                            if (!Segments.Any(p => p == Segment))
                            {
                                validationResult = ResourceReader.GetString("ERR_SEGMENT");
                            }
                            break;
                        }
                    }
                    Validator.AddOrUpdate(propertyName, validationResult == String.Empty);
                    AllPropertiesValid = Validator.IsValid();
                    return(validationResult);
                }
                catch (Exception e)
                {
                    _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception,
                                        string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
                    Validator.AddOrUpdate(propertyName, false);
                    AllPropertiesValid = Validator.IsValid();
                    return(ResourceReader.GetString("ERR_EXCEPTION"));
                }
            }
        }
        private Segment[] JoinInternal(NodeEndpoint endpoint)
        {
            log.DebugFormat("Endpoint {0} joining", endpoint.Sync);
            endpoints.Add(endpoint);
            if (Segments.Any(x => x.BelongsTo(endpoint)))
            {
                log.DebugFormat("Endpoint {0} is already registered, probably an end point restart, ignoring", endpoint.Sync);
                return(Segments.Where(x => x.BelongsTo(endpoint)).ToArray());
            }

            var thereAreSegementsWithNoowners = Segments
                                                .Any(x => x.AssignedEndpoint == null);

            if (thereAreSegementsWithNoowners)
            {
                Topology = new Topology(Segments
                                        .Where(x => x.AssignedEndpoint == null)
                                        .Select(x => new Segment
                {
                    AssignedEndpoint            = endpoint,
                    Backups                     = x.Backups,
                    Index                       = x.Index,
                    InProcessOfMovingToEndpoint = x.InProcessOfMovingToEndpoint,
                    PendingBackups              = x.PendingBackups
                }).ToArray(),
                                        Topology.Version + 1
                                        );
                TopologyChanged();
                log.DebugFormat("Endpoint {0} was assigned all segments without owners", endpoint.Sync);
                return(Segments.Where(x => x.AssignedEndpoint == endpoint).ToArray());
            }

            log.DebugFormat("New endpoint {0}, allocating segments for it", endpoint.Sync);

            return(RestructureSegmentsFairly(endpoint));
        }
Пример #16
0
        //--------------------------------------------------------------------------------------------------

        protected override bool MakeInternal(MakeFlags flags)
        {
            if (!Segments.Any() || !Points.Any())
            {
                var makeVertex = new BRepBuilderAPI_MakeVertex(Pnt.Origin);
                BRep      = makeVertex.Vertex();
                HasErrors = false;
                return(base.MakeInternal(flags));
            }

            // Create edges
            var freeSegmentEdges = new Dictionary <SketchSegment, TopoDS_Edge>();

            foreach (var segmentKvp in _Segments)
            {
                var segment = segmentKvp.Value;
                if (segment.IsAuxilliary)
                {
                    continue;
                }

                var segEdge = segment.MakeEdge(_Points);
                if (segEdge == null)
                {
                    Messages.Warning($"The segment {segmentKvp.Key} of type {segment.GetType().Name} failed creating an edge.");
                    continue;
                }
                freeSegmentEdges.Add(segment, segEdge);
                AddNamedSubshape("seg", segEdge, segmentKvp.Key);
            }

            // Create wires
            var wires = new List <TopoDS_Wire>();

            while (freeSegmentEdges.Any())
            {
                var nextSegmentEdge = freeSegmentEdges.First();
                var frontSegment    = nextSegmentEdge.Key;
                freeSegmentEdges.Remove(nextSegmentEdge.Key);

                var makeWire = new BRepBuilderAPI_MakeWire(nextSegmentEdge.Value);

                if ((frontSegment.StartPoint != -1) || (frontSegment.EndPoint != -1))
                {
                    var backSegment = frontSegment;
                    while (freeSegmentEdges.Any())
                    {
                        nextSegmentEdge = freeSegmentEdges.FirstOrDefault(kvp => kvp.Key.IsConnected(frontSegment));
                        if (nextSegmentEdge.Value != null)
                        {
                            frontSegment = nextSegmentEdge.Key;
                        }
                        else
                        {
                            nextSegmentEdge = freeSegmentEdges.FirstOrDefault(kvp => kvp.Key.IsConnected(backSegment));
                            if (nextSegmentEdge.Value != null)
                            {
                                backSegment = nextSegmentEdge.Key;
                            }
                            else
                            {
                                // disconnected segment
                                break;
                            }
                        }

                        makeWire.Add(nextSegmentEdge.Value);
                        freeSegmentEdges.Remove(nextSegmentEdge.Key);
                    }
                }

                // Get wire shape
                var wire = makeWire.Wire();
                if (wire == null)
                {
                    Messages.Error("Error when creating a wire.");
                    return(false);
                }

                wires.Add(wire);
            }

            // Create resulting shape
            var builder = new TopoDS_Builder();
            var shape   = new TopoDS_Compound();

            builder.MakeCompound(shape);

            foreach (var wire in wires)
            {
                builder.Add(shape, wire);
            }

            BRep = shape;

            return(base.MakeInternal(flags));
        }
Пример #17
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Returns true if all the segments in the tier are not empty.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public bool GetIsComplete()
 {
     return(Segments.Count > 0 && !Segments.Any(s => string.IsNullOrEmpty(s.Text)));
 }
Пример #18
0
        public void ComputeFretShape()
        {
            VerifyIsStraight();
            //if (!IsStraight && !Layout.CompensateFretPositions && Layout.FretsTemperament == Physics.Temperament.Equal && CheckForHardBreak())
            //    return;

            var layout = Segments[0].String.Layout;

            if (Segments.Any(s => s.IsNut && !s.IsVirtual) && !Segments.All(s => s.IsNut || s.IsVirtual))
            {
                SeparateNutFromFrets();
                return;
            }

            if (IsStraight && Segments.Count > 1)
            {
                var leftBound  = layout.GetStringBoundaryLine(Segments.Last(fs => !fs.IsVirtual).String, FingerboardSide.Bass);
                var rightBound = layout.GetStringBoundaryLine(Segments.First(fs => !fs.IsVirtual).String, FingerboardSide.Treble);

                var line = Line.FromPoints(Segments.First().PointOnString.ToVector(), Segments.Last().PointOnString.ToVector());
                Points.Add(PointM.FromVector(line.GetIntersection(leftBound.Equation), UnitOfMeasure.Centimeters));
                Points.Add(PointM.FromVector(line.GetIntersection(rightBound.Equation), UnitOfMeasure.Centimeters));
            }
            else
            {
                if (Layout.FretInterpolation == FretInterpolationMethod.Spline && StringCount >= 2)
                {
                    foreach (var seg in Segments.Where(s => !s.IsVirtual || s.String.HasFret(s.FretIndex)))
                    {
                        Points.Add(seg.PointOnString);
                    }

                    InterpolateSplineV2(1d / (Segments.Count * 2.2));

                    ExtendToBorders();
                }
                else if (Layout.FretInterpolation == FretInterpolationMethod.NotchedSpline && StringCount >= 2)
                {
                    foreach (var seg in Segments.Where(s => !s.IsVirtual || s.String.HasFret(s.FretIndex)))
                    {
                        //Points.Add(seg.PointOnString + (seg.Direction * Measure.Mm(1.5)));
                        Points.Add(PointM.Average(seg.P2, seg.PointOnString));
                        //Points.Add(seg.PointOnString);
                        Points.Add(PointM.Average(seg.P1, seg.PointOnString));
                        //Points.Add(seg.PointOnString + (seg.Direction * -1 * Measure.Mm(1.5)));
                    }

                    InterpolateSpline(0.33, 0.4);

                    ExtendToBorders();
                }
                else
                {
                    foreach (var seg in Segments.Where(s => !s.IsVirtual))
                    {
                        Points.Add(seg.PointOnString);
                    }
                    ExtendToBorders();
                }

                (Points as ObservableCollectionEx <PointM>).Reverse();

                if (Points.Count == 2)
                {
                    _IsStraight = true;
                }
            }
        }
Пример #19
0
        public void WriteTo(BinaryWriter writer)
        {
            writer.Write(SRID);

            if (SRID == -1)
            {
                return;
            }

            writer.Write(Version);

            var properties = SerializationProperties.None;

            if (ZValues.Any())
            {
                properties |= SerializationProperties.HasZValues;
            }
            if (MValues.Any())
            {
                properties |= SerializationProperties.HasMValues;
            }
            if (IsValid)
            {
                properties |= SerializationProperties.IsValid;
            }
            if (Shapes.First().Type == OpenGisType.Point && Points.Any())
            {
                properties |= SerializationProperties.IsSinglePoint;
            }
            if (Shapes.First().Type == OpenGisType.LineString && Points.Count == 2)
            {
                properties |= SerializationProperties.IsSingleLineSegment;
            }
            if (IsLargerThanAHemisphere)
            {
                properties |= SerializationProperties.IsLargerThanAHemisphere;
            }
            writer.Write((byte)properties);

            if (!properties.HasFlag(SerializationProperties.IsSinglePoint) &&
                !properties.HasFlag(SerializationProperties.IsSingleLineSegment))
            {
                writer.Write(Points.Count);
            }

            foreach (var point in Points)
            {
                point.WriteTo(writer);
            }

            foreach (var z in ZValues)
            {
                writer.Write(z);
            }

            foreach (var m in MValues)
            {
                writer.Write(m);
            }

            if (properties.HasFlag(SerializationProperties.IsSinglePoint) ||
                properties.HasFlag(SerializationProperties.IsSingleLineSegment))
            {
                return;
            }

            writer.Write(Figures.Count);

            if (Version == 1)
            {
                for (var shapeIndex = 0; shapeIndex < Shapes.Count; shapeIndex++)
                {
                    var shape = Shapes[shapeIndex];
                    if (shape.FigureOffset == -1 || shape.IsCollection())
                    {
                        continue;
                    }

                    var nextShapeIndex = shapeIndex + 1;
                    while (nextShapeIndex < Shapes.Count && Shapes[nextShapeIndex].FigureOffset == -1)
                    {
                        nextShapeIndex++;
                    }

                    var lastFigureIndex = nextShapeIndex >= Shapes.Count
                        ? Figures.Count - 1
                        : Shapes[nextShapeIndex].FigureOffset - 1;

                    if (Shapes[shapeIndex].Type == OpenGisType.Polygon)
                    {
                        // NB: Although never mentioned in MS-SSCLRT (v20170816), exterior rings must be first
                        writer.Write((byte)LegacyFigureAttribute.ExteriorRing);
                        writer.Write(Figures[shape.FigureOffset].PointOffset);

                        for (var figureIndex = shape.FigureOffset + 1; figureIndex <= lastFigureIndex; figureIndex++)
                        {
                            writer.Write((byte)LegacyFigureAttribute.InteriorRing);
                            writer.Write(Figures[figureIndex].PointOffset);
                        }

                        continue;
                    }

                    for (var figureIndex = shape.FigureOffset; figureIndex <= lastFigureIndex; figureIndex++)
                    {
                        writer.Write((byte)LegacyFigureAttribute.Stroke);
                        writer.Write(Figures[figureIndex].PointOffset);
                    }
                }
            }
            else
            {
                foreach (var figure in Figures)
                {
                    figure.WriteTo(writer);
                }
            }

            writer.Write(Shapes.Count);

            foreach (var shape in Shapes)
            {
                shape.WriteTo(writer);
            }

            if (Segments.Any())
            {
                writer.Write(Segments.Count);

                foreach (var segment in Segments)
                {
                    segment.WriteTo(writer);
                }
            }
        }
Пример #20
0
 private bool _anySegmentHit(Coordinates hitCoordinates) => Segments.Any(x => x.Coordinates.Equals(hitCoordinates));