Beispiel #1
0
        public void AddPowerLine(Line line)
        {
            //todo use one func
            if (PowerLines.Any(l => l.Input == line.Input &&
                               l.Output == line.Output &&
                               l.InputMarker == line.InputMarker &&
                               l.OutputMarker == line.OutputMarker))
            {
                return;
            }

            var s1 = Segments.FirstOrDefault(s => s.Position == line.Input);
            var s2 = Segments.FirstOrDefault(s => s.Position == line.Output);

            if (s1 != null)
            {
                var m1 = s1.Connectors.FirstOrDefault(p => p.Marker == line.InputMarker);
                if (s2 != null)
                {
                    var m2 = s2.Connectors.FirstOrDefault(p => p.Marker == line.OutputMarker);

                    if (m1 != null && m2 != null)
                    {
                        m1.ConnectedTo.Add(s2.Identifier.ToString());
                        m2.ConnectedTo.Add(s1.Identifier.ToString());
                        PowerLines.Add(line);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Loads the dynamic segment of the executable.
        /// </summary>
        /// <remarks>
        /// The ELF standard specifies that there will be at most 1 dynamic segment
        /// in an executable binary.
        /// </remarks>
        public void LoadDynamicSegment()
        {
            var dynSeg = Segments.FirstOrDefault(p => p.p_type == ProgramHeaderType.PT_DYNAMIC);

            if (dynSeg == null)
            {
                return;
            }
            var dynEntries = GetDynamicEntries(dynSeg.p_offset).ToList();
            var deStrTab   = dynEntries.FirstOrDefault(de => de.Tag == ElfDynamicEntry.DT_STRTAB);

            if (deStrTab == null)
            {
                //$REVIEW: is missing a string table worth a warning?
                return;
            }
            var offStrtab = AddressToFileOffset(deStrTab.UValue);

            foreach (var de in dynEntries)
            {
                if (de.Tag == ElfDynamicEntry.DT_NEEDED)
                {
                    Dependencies.Add(ReadAsciiString(offStrtab + de.UValue));
                }
                else
                {
                    DynamicEntries[de.Tag] = de;
                }
            }
        }
Beispiel #3
0
        public int GetSegmentFromRawValue(int value)
        {
            var segmentRange = Segments.FirstOrDefault(r => value <= r.Value);

            if (segmentRange == null)
            {
                return(0);
            }
            return(segmentRange.Id);
        }
Beispiel #4
0
        /// ------------------------------------------------------------------------------------
        public BoundaryModificationResult InsertSegmentBoundary(float newBoundary,
                                                                Func <AnnotationSegment, bool, bool, bool> allowDeletionOfOralAnnotations = null)
        {
            float newSegStart   = 0f;
            var   segBeingSplit = Segments.FirstOrDefault(
                seg => seg.TimeRange.Contains(TimeSpan.FromSeconds(newBoundary), true));

            if (segBeingSplit == null)
            {
                if (Segments.GetLast() != null)
                {
                    newSegStart = Segments.GetLast().End;
                }

                if (!GetIsAcceptableSegmentLength(newSegStart, newBoundary))
                {
                    return(BoundaryModificationResult.SegmentWillBeTooShort);
                }

                AddSegment(newSegStart, newBoundary);
                return(BoundaryModificationResult.Success);
            }

            if (!GetIsAcceptableSegmentLength(segBeingSplit.Start, newBoundary))
            {
                return(BoundaryModificationResult.SegmentWillBeTooShort);
            }

            if (!GetIsAcceptableSegmentLength(newBoundary, segBeingSplit.End))
            {
                return(BoundaryModificationResult.NextSegmentWillBeTooShort);
            }

            if (segBeingSplit.TimeRange.EndSeconds > newBoundary)
            {
                var hasCarefulSpeech   = segBeingSplit.GetHasOralAnnotation(OralAnnotationType.CarefulSpeech);
                var hasOralTranslation = segBeingSplit.GetHasOralAnnotation(OralAnnotationType.Translation);
                if ((hasCarefulSpeech || hasOralTranslation) && (allowDeletionOfOralAnnotations == null ||
                                                                 !allowDeletionOfOralAnnotations(segBeingSplit, hasCarefulSpeech, hasOralTranslation)))
                {
                    return(BoundaryModificationResult.BlockedByOralAnnotations);
                }
            }

            float newSegEnd = segBeingSplit.End;

            segBeingSplit.End = newBoundary;
            var newSegment = new AnnotationSegment(segBeingSplit.Tier, newBoundary, newSegEnd);

            Segments.Insert(GetIndexOfSegment(segBeingSplit) + 1, newSegment);

            return(BoundaryModificationResult.Success);
        }
Beispiel #5
0
        public Segment Add(DrawingElement el, Position p)
        {
            Remove(p);

            var seg = Segments.FirstOrDefault(s => s.Position == p);

            if (seg != null)
            {
                seg.AddPrimitives(el.Primitives);
            }
            else
            {
                seg = new Segment(p, el.Primitives, this)
                {
                    IsPalette = IsPalette
                };
                Segments.Add(seg);
            }
            seg.Type = el.Type;
            CalculateSize();


            //join latch

            if (el.Primitives.Any(pr => pr is LineElement && ((pr as LineElement).End.Y > 1)))
            {
                var pos2 = new Position(seg.Position.X, seg.Position.Y + 1);
                var seg2 = Segments.FirstOrDefault(s => s.Position == pos2);
                if (seg2 != null)
                {
                    seg2.Join.Add(seg);
                    seg.Join.Add(seg2);

                    var conR = el
                               .Primitives
                               .Where(p1 => p1 is Connector)
                               .Cast <Connector> ()
                               .Where(c => c.Center.Y > 1);

                    seg2.Connectors.AddRange(conR);

                    if (seg.Selected)
                    {
                        seg2.Selected = true;
                    }
                }
            }

            return(seg);
        }
Beispiel #6
0
        private void validateSegments()
        {
            if (Segments.FirstOrDefault() is Spread)
            {
                throw new InvalidOperationException(
                          $"'{Pattern}' is an invalid route. Cannot use a spread argument as the first segment");
            }

            if (Segments.FirstOrDefault() is RouteArgument)
            {
                throw new InvalidOperationException(
                          $"'{Pattern}' is an invalid route. Cannot use a route argument as the first segment");
            }
        }
Beispiel #7
0
        public void RemovePowerLine(Line line)
        {
            //todo use one func

            var found = PowerLines.FirstOrDefault(l => l.Input == line.Input &&
                                                  l.Output == line.Output &&
                                                  l.InputMarker == line.InputMarker &&
                                                  l.OutputMarker == line.OutputMarker);

            if (found == null)
            {
                return;
            }

            var s1 = Segments.FirstOrDefault(s => s.Position == line.Input);
            var s2 = Segments.FirstOrDefault(s => s.Position == line.Output);

            if (s1 != null && s2 != null)
            {
                var toRemove = new List <Connector> ();
                s1.Connectors.Where(p => p.Marker == line.InputMarker)
                .ToList().ForEach(m => {
                    m.ConnectedTo.Remove(s2.Identifier.ToString());
                    if (m.Marker == AppController.Instance.Config.LeftPower ||
                        m.Marker == AppController.Instance.Config.RightPower)
                    {
                        toRemove.Add(m);
                    }
                });

                toRemove.ForEach(c => s1.Connectors.Remove(c));
                toRemove.Clear();

                s2.Connectors.Where(p => p.Marker == line.OutputMarker)
                .ToList().ForEach(m =>
                {
                    m.ConnectedTo.Remove(s1.Identifier.ToString());
                    if (m.Marker == AppController.Instance.Config.LeftPower ||
                        m.Marker == AppController.Instance.Config.RightPower)
                    {
                        toRemove.Add(m);
                    }
                });

                toRemove.ForEach(c => s2.Connectors.Remove(c));
            }

            PowerLines.Remove(found);
        }
Beispiel #8
0
        public override void RegisterDart(int segment, int multiplier)
        {
            var dart = new CricketDart(CurrentPlayer, segment, multiplier);

            //if the player hit a segment that matters
            var cricketSegment = Segments.FirstOrDefault(s => s.Segment == segment && s.IsOpen);

            if (cricketSegment != null)
            {
                dart.ScoredMarks = multiplier;
                cricketSegment.RegisterDart(dart);
            }

            CurrentPlayerRound.Darts.Add(dart);
        }
Beispiel #9
0
        public Segment Add(Position p)
        {
            var seg = Segments.FirstOrDefault(s => s.Position == p);

            if (seg == null)
            {
                seg = new Segment(p, this)
                {
                    IsPalette = IsPalette
                };
                Segments.Add(seg);
                CalculateSize();
            }

            return(seg);
        }
Beispiel #10
0
        protected override void RemoveDart()
        {
            if (CurrentPlayerRound.Darts.Count > 0)
            {
                var dart = CurrentPlayerRound.Darts.Last();

                CurrentPlayerRound.Darts.Remove(dart);

                var segment = Segments.FirstOrDefault(s => s.Segment == dart.Segment);

                if (segment != null)
                {
                    segment.RemoveDart((CricketDart)dart);
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Loads the dynamic segment of the executable.
        /// </summary>
        /// <remarks>
        /// The ELF standard specifies that there will be at most 1 dynamic segment
        /// in an executable binary.
        /// </remarks>
        public void LoadDynamicSegment()
        {
            var dynSeg = Segments.FirstOrDefault(p => p.p_type == ProgramHeaderType.PT_DYNAMIC);

            if (dynSeg == null)
            {
                return;
            }
            var rdr = this.endianness.CreateImageReader(rawImage, (long)dynSeg.p_offset);

            var(deps, entries) = LoadDynamicSegment(rdr);
            this.Dependencies.AddRange(deps);
            foreach (var de in entries)
            {
                this.DynamicEntries[de.Tag] = de;
            }
        }
Beispiel #12
0
 public ElfSegment GetSegmentByAddress(ulong uAddr)
 {
     return(Segments.FirstOrDefault(s => s.IsValidAddress(uAddr)));
 }
Beispiel #13
0
 /// ------------------------------------------------------------------------------------
 public AnnotationSegment GetSegmentEnclosingTime(float time)
 {
     return(Segments.FirstOrDefault(s => s.TimeRange.GetIsTimeInRange(time, false, true)));
 }
Beispiel #14
0
 /// ------------------------------------------------------------------------------------
 public AnnotationSegment GetSegmentHavingStartBoundary(float startBoundary)
 {
     return(Segments.FirstOrDefault(s => s.StartsAt(startBoundary)));
 }
Beispiel #15
0
 /// ------------------------------------------------------------------------------------
 public AnnotationSegment GetSegmentHavingEndBoundary(float endBoundary)
 {
     return(Segments.FirstOrDefault(s => s.EndsAt(endBoundary)));
 }