Ejemplo n.º 1
0
        public void TestingAdd()
        {
            var start  = new Start();
            var actual = start.Add(1, 2);

            Assert.Equal(3, actual);
        }
Ejemplo n.º 2
0
 public void AddRange(double start, double end)
 {
     for (int i = 0; i < Start.Count;)
     {
         if (start > End[i] + _minLineSeparation)
         {
             i++;
         }
         else if (end + _minLineSeparation < Start[i])
         {
             Start.Insert(i, start);
             End.Insert(i, end);
             return;
         }
         else
         {
             // overlap !!
             if (Start[i] < start)
             {
                 start = Start[i];
             }
             if (End[i] > end)
             {
                 end = End[i];
             }
             Start.RemoveAt(i);
             End.RemoveAt(i);
         }
     }
     Start.Add(start);
     End.Add(end);
 }
Ejemplo n.º 3
0
        public void Shift(int shift)
        {
            var seconds = new TimeSpan(0, 0, shift);

            Start = Start.Add(seconds);
            End   = End.Add(seconds);
        }
Ejemplo n.º 4
0
        public void Update()
        {
            Active = Start <DateTime.Now && Start.Add(Duration)> DateTime.Now;
            if (RepeatType != GERepeatType.None && Start.Add(Duration) < DateTime.Now)
            {
updateCondition:
                switch (RepeatType)
                {
                case GERepeatType.Annually:
                    Start = Start.AddYears(1);
                    break;

                case GERepeatType.Monthly:
                    Start = Start.AddMonths(1);
                    break;

                case GERepeatType.Weekly:
                    Start = Start.AddDays(7);
                    break;

                case GERepeatType.Daily:
                    Start = Start.AddDays(1);
                    break;
                }
                if (Start.Add(Duration) < DateTime.Now)
                {
                    goto updateCondition;
                }

                Logger
                .ForContext(Constants.SourceContextPropertyName, Name)
                .Information("Updated active period, Start {0} - End {1}", Start, Start.Add(Duration));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 시작시각(<see cref="ITimeBlock.Start"/>)은 고정, 기간(duration)으로 완료시각(<see cref="ITimeBlock.End"/>)를 재설정
        /// </summary>
        /// <param name="newDuration"></param>
        public virtual void DurationFromStart(TimeSpan newDuration)
        {
            AssertMutable();
            AssertValidDuration(newDuration);

            _duration = newDuration;
            _end      = Start.Add(_duration);
        }
Ejemplo n.º 6
0
 public void ToLocalTime()
 {
     Start = Start.Add(Start - Start.ToUniversalTime());
     End   = End.Add(End - End.ToUniversalTime());
     if (Finish.HasValue)
     {
         Finish = Finish.Value.Add(Finish.Value - Finish.Value.ToUniversalTime());
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Factory method which creates the 'next' logical fetch request using the request's chunk period
        /// </summary>
        /// <returns></returns>
        public ICacheFetchRequest GetNext()
        {
            var nextStart = Start.Add(ChunkPeriod);

            return(new CacheFetchRequest(Repository, nextStart)
            {
                CacheProgress = CacheProgress,
                PermissionWindow = PermissionWindow,
                ChunkPeriod = ChunkPeriod
            });
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 지정된 Offset만큼 기간이 이전 시간으로 이동한 TimeBlock을 반환한다.
        /// </summary>
        /// <param name="offset"></param>
        /// <returns></returns>
        public virtual ITimeBlock GetPreviousBlock(TimeSpan offset)
        {
            var endOff = (offset > TimeSpan.Zero) ? offset.Negate() : offset;
            var result = new TimeBlock(Duration, Start.Add(endOff), IsReadOnly);

            if (IsDebugEnabled)
            {
                log.Debug("이전 Block을 구합니다. offset=[{0}], PreviousBlock=[{1}]", offset, result);
            }

            return(result);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// This is used to build the attributes that are to be used to
 /// populate the start event. Populating the start event with the
 /// attributes it contains is required so that each element will
 /// contain its associated attributes. Only attributes that are
 /// not reserved will be added to the start event.
 /// </summary>
 /// <returns>
 /// this returns a start event with its attributes
 /// </returns>
 public Start Build(Start node)
 {
     if (reader.HasAttributes)
     {
         while (reader.MoveToNextAttribute())
         {
             Entry entry = Attribute();
             node.Add(entry);
         }
     }
     return(node);
 }
Ejemplo n.º 10
0
        protected override DateTime GetEndAtSpan(TimeSpan span)
        {
            if (span <= (DateTime.MaxValue - DateTime.MinValue))
            {
                DateTime maxStart = DateTime.MaxValue - span;
                if (Start <= maxStart)
                {
                    return(Start.Add(span));
                }
            }

            return(DateTime.MaxValue);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 현 TimeBlock에서 오프셋만큼 Shift 한 <see cref="TimeBlock"/> 반환합니다.
        /// </summary>
        /// <param name="offset"></param>
        /// <returns></returns>
        public new TimeBlock Copy(TimeSpan offset)
        {
            if (IsDebugEnabled)
            {
                log.Debug("[{0}] 를 offset[{1}] 을 주어 복사한 객체를 반환합니다...", GetType().Name, offset);
            }

            if (offset == TimeSpan.Zero)
            {
                return(new TimeBlock(this));
            }

            return(new TimeBlock(HasStart ? Start.Add(offset) : _start,
                                 HasEnd ? End.Add(offset) : _end,
                                 IsReadOnly));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This is used to build the attributes that are to be used to
        /// populate the start event. Populating the start event with the
        /// attributes it contains is required so that each element will
        /// contain its associated attributes. Only attributes that are
        /// not reserved will be added to the start event.
        /// </summary>
        /// <returns>
        /// This returns a start event with its attributes.
        /// </returns>
        private Start Build(Start node)
        {
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    Entry entry = Attribute();

                    if (entry != null)
                    {
                        node.Add(entry);
                    }
                }
            }
            return(node);
        }
Ejemplo n.º 13
0
        public void MoveRight(int value)
        {
            if (value == 5)
            {
                Start = Start.Add(BigStep);
                End   = End.Add(BigStep);
            }

            else
            {
                Start = Start.Add(SmallStep);
                End   = End.Add(SmallStep);
            }

            OnTimeLineChanged(Start, End);
            //Recreate();
        }
Ejemplo n.º 14
0
        public TimeSpan GetTimeout(DateTimeOffset now)
        {
            if (Sleep == null)
            {
                return(TimeSpan.MaxValue);
            }

            if (Start == null)
            {
                Start = now;
            }

            var totalMillis    = (long)now.Subtract(Start.Value).TotalMilliseconds;
            var wholeIntervals = totalMillis / (long)Sleep?.TotalMilliseconds;
            var nextRun        = Start?.Add(TimeSpan.FromMilliseconds((wholeIntervals + 1) * (long)Sleep?.TotalMilliseconds));

            return(nextRun.Value.Subtract(now));
        }
Ejemplo n.º 15
0
 public void MouseMove(object obj)
 {
     if (obj is MouseEventArgs)
     {
         var e       = obj as MouseEventArgs;
         var element = e.Source;
         if (Mouse.LeftButton == MouseButtonState.Pressed)
         {
             if ((Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
             {
                 if (element is System.Windows.Shapes.Rectangle)
                 {
                     var rectangle = element as System.Windows.Shapes.Rectangle;
                     element = HelperStaticFunctions.FindParentOfType <System.Windows.Controls.Grid>(rectangle);
                 }
                 if (element is System.Windows.Controls.Grid)
                 {
                     var grid  = element as System.Windows.Controls.Grid;
                     var delta = this.Duration.Divide(100);
                     currentPoint = e.GetPosition(grid);
                     if (isFirstMove)
                     {
                         isFirstMove   = false;
                         previousPoint = currentPoint;
                     }
                     else
                     {
                         if (currentPoint.X > previousPoint.X)
                         {
                             Start = Start.Subtract(delta);
                             End   = End.Subtract(delta);
                         }
                         else
                         {
                             Start = Start.Add(delta);
                             End   = End.Add(delta);
                         }
                         previousPoint = currentPoint;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 16
0
        public DailyEvent(string name, double startHour, double startMin, double durationOrEndHour, string color = "30afff", bool isDuration = true)
        {
            Dispatcher = Dispatcher.CurrentDispatcher;
            //var m = startHour % 1;
            //var h = startHour - m;
            Start = DateTime.Parse(startHour + ":" + startMin);
            var d = isDuration ? durationOrEndHour : durationOrEndHour - startHour;

            Duration      = TimeSpan.FromHours(d);
            _realDuration = Duration;
            var dayend = DateTime.Parse("00:00").AddDays(1);

            if (Start.Add(Duration) > dayend)
            {
                Duration = dayend - Start;
            }
            Name  = name;
            Color = color;
        }
        public Transfer(XmlNode root, Condition owner)
        {
            Init();
            Expression  = root.SelectSingleNode("Expression").InnerText;
            Probability = double.Parse(root.Attributes["probability"].Value);
            Name        = root.Attributes["name"].Value;
            if (root.Attributes["allTransfers"] != null)
            {
                AllTransfers = bool.Parse(root.Attributes["allTransfers"].Value);
            }
            foreach (XmlNode startXML in root.SelectNodes("Start"))
            {
                string nameStart = startXML.Attributes["name"].Value;

                foreach (Condition conditions in owner.Conditions)
                {
                    if (conditions.Name == nameStart)
                    {
                        Start.Add(conditions);
                        conditions.Outputs.Add(this);
                        break;
                    }
                }
            }
            foreach (XmlNode startXML in root.SelectNodes("End"))
            {
                string nameStart = startXML.Attributes["name"].Value;
                foreach (Condition conditions in owner.Conditions)
                {
                    if (conditions.Name == nameStart)
                    {
                        End.Add(conditions);
                        conditions.Inputs.Add(this);
                        break;
                    }
                }
            }
            owner.Transfers.Add(this);
        }
Ejemplo n.º 18
0
        public SnapshotPoint?GetBufferPositionFromXCoordinate(double xCoordinate, bool textOnly)
        {
            this.ThrowIfInvalid();
            if (double.IsNaN(xCoordinate))
            {
                throw new ArgumentOutOfRangeException("xCoordinate");
            }

            if ((xCoordinate < TextLeft) || (xCoordinate >= Width + TextLeft))
            {
                return(null);
            }

            if (xCoordinate >= TextRight)
            {
                //A pick over the end of line character
                return(_extentIncludingLineBreak.End - _lineBreakLength);
            }

            if (xCoordinate < Right)
            {
                int bufferPosition = 0;
                foreach (var render in RenderList.SelectMany(r => r.Text.Points))
                {
                    bufferPosition++;
                    if (render.X > xCoordinate)
                    {
                        break;
                    }
                }
                return(Start.Add(bufferPosition - 1));
            }

            //TODO verify this is the appropriate return (rather than _extentIncludingLineBreak.End - _lineBreakLength).
            return(null);
        }
Ejemplo n.º 19
0
 public DateRange Expand(TimeSpan margin) => new DateRange(Start.Add(-margin), Stop.Add(margin));
Ejemplo n.º 20
0
 /// <summary>
 /// This is used to build the attributes that are to be used to
 /// populate the start event. Populating the start event with the
 /// attributes it contains is required so that each element will
 /// contain its associated attributes. Only attributes that are
 /// not reserved will be added to the start event.
 /// </summary>
 /// <returns>
 /// this returns a start event with its attributes
 /// </returns>
 public Start Build(Start node) {
    if(reader.HasAttributes) {
       while (reader.MoveToNextAttribute()) {
          Entry entry = Attribute();
          node.Add(entry);
       }
    }
    return node;
 }
Ejemplo n.º 21
0
        public DateTime GetMedian()
        {
            var d = (End - Start).TotalSeconds / 2;

            return(Start.Add(TimeSpan.FromSeconds(d)));
        }
Ejemplo n.º 22
0
      /// <summary>
      /// This is used to build the attributes that are to be used to
      /// populate the start event. Populating the start event with the
      /// attributes it contains is required so that each element will
      /// contain its associated attributes. Only attributes that are
      /// not reserved will be added to the start event.
      /// </summary>
      /// <returns>
      /// This returns a start event with its attributes.
      /// </returns>
      private Start Build(Start node) {
         if(reader.HasAttributes) {
            while(reader.MoveToNextAttribute()) {
               Entry entry = Attribute();

               if(entry != null) {
                  node.Add(entry);
               }
            }
         }
         return node;
      }
Ejemplo n.º 23
0
        //public PlanElement(int orderNo, DateTime start, DateTime end)
        //{
        //    OrderNo = orderNo;
        //    Start = start;
        //    End = end;
        //}

        //public PlanElement(string placeName, string placeId,  double lat, double lng, int orderNo, DateTime start, DateTime end, PlanElementType elementType, double? rating=null)
        //{
        //    PlaceName = placeName;
        //    PlaceId = placeId;
        //    Lat = lat;
        //    Lng = lng;
        //    OrderNo = orderNo;
        //    Start = start;
        //    End = end;
        //    //ElementType = elementType;
        //   // Rating = rating;
        //}

        //public PlanElement(string placeName, string placeId, double lat, double lng, int orderNo, PlanElementType elementType, double? rating = null)
        //{
        //    PlaceName = placeName;
        //    PlaceId = placeId;
        //    Lat = lat;
        //    Lng = lng;
        //    OrderNo = orderNo;
        //    ElementType = elementType;
        //    Rating = rating;
        //    Start = new DateTime();
        //    End = new DateTime();
        //}



        public void UpdateDateTimeWithRouteDuration(TimeSpan routeDuration)
        {
            Start = Start.Add(routeDuration);
            End   = End.Add(routeDuration);
        }
Ejemplo n.º 24
0
        public RestrictionProfile getRestriction(TimeSpan TimeDiff)
        {
            RestrictionProfile RetValue = null;
            bool Enabled = false;

            if (Boolean.TryParse(isEnabled, out Enabled))
            {
                if (Enabled)
                {
                    List <DayOfWeek>           myDays = new List <DayOfWeek>();
                    List <RestrictionTimeLine> RestrictingTimeLines = new List <RestrictionTimeLine>();
                    foreach (WeekDays eachWeekDays in WeekDayOption)
                    {
                        DateTimeOffset Start;
                        bool           parseCheck = DateTimeOffset.TryParse(eachWeekDays.Start, out Start);
                        if (!parseCheck)
                        {
                            throw new Exception("Error parsing one of your Start times in restrictive week data");
                        }


                        DateTimeOffset revisedStart           = Start.Add(-TimeDiff);
                        int            startDayIndexIncrement = revisedStart.DayOfYear - Start.DayOfYear;
                        Start = revisedStart;


                        DateTimeOffset End;
                        parseCheck = DateTimeOffset.TryParse(eachWeekDays.End, out End);
                        if (!parseCheck)
                        {
                            throw new Exception("Error parsing one of your End times in restrictive week data");
                        }

                        DateTimeOffset revisedEnd           = End.Add(-TimeDiff);
                        int            endDayIndexIncrement = revisedEnd.DayOfYear - End.DayOfYear;
                        End = revisedEnd;


                        int DayIndex;
                        parseCheck = int.TryParse(eachWeekDays.Index, out DayIndex);
                        if (!parseCheck)
                        {
                            throw new Exception("Invalid day index provided in restrictive week data");
                        }



                        DayOfWeek myDay;
                        try
                        {
                            myDay = (DayOfWeek)((DayIndex + startDayIndexIncrement) % Utility.daysInAWeek);
                        }
                        catch (Exception e)
                        {
                            throw new Exception("Invalid day index provided in restrictive week data");
                        }

                        RestrictionTimeLine restrictingFrame = new RestrictionTimeLine(Start, End);

                        myDays.Add(myDay);
                        RestrictingTimeLines.Add(restrictingFrame);
                    }

                    RetValue = new RestrictionProfile(myDays, RestrictingTimeLines);
                }
            }
            return(RetValue);;
        }
Ejemplo n.º 25
0
        } // GetPreviousPeriod

        // ----------------------------------------------------------------------
        public virtual TimeSlot GetPreviousPeriod(TimeSpan offset)
        {
            return(new TimeSlot(Duration, Start.Add(offset), IsReadOnly));
        } // GetPreviousPeriod
Ejemplo n.º 26
0
 public void Shift(TimeSpan ts)
 {
     Start = Start.Add(ts);
     End   = End.Add(ts);
 }