Exemplo n.º 1
0
        public void HasStartTest() {
            // 현재부터 ~ 쭉
            //
            var timeRange = new TimeBlock(ClockProxy.Clock.Now, null);

            timeRange.HasStart.Should().Be.True();
            timeRange.HasEnd.Should().Be.False();
        }
Exemplo n.º 2
0
        public void MomentTest() {
            var moment = ClockProxy.Clock.Now;
            var timeBlock = new TimeBlock(moment);

            timeBlock.Start.Should().Be(moment);
            timeBlock.End.Should().Be(moment);
            timeBlock.Duration.Should().Be(TimeSpec.MinPeriodDuration);

            timeBlock.IsAnytime.Should().Be.False();
            timeBlock.IsMoment.Should().Be.True();
            timeBlock.HasPeriod.Should().Be.True();
        }
Exemplo n.º 3
0
        public void DefaultTest() {
            var timeBlock = new TimeBlock();

            timeBlock.Should().Not.Be.EqualTo(TimeBlock.Anytime); // not readonly .vs. readonly
            timeBlock.GetRelation(TimeBlock.Anytime).Should().Be(PeriodRelation.ExactMatch);

            TimeBlock.Anytime.IsAnytime.Should().Be.True();
            TimeBlock.Anytime.IsMoment.Should().Be.False();
            TimeBlock.Anytime.IsReadOnly.Should().Be.True();

            TimeBlock.Anytime.HasStart.Should().Be.False();
            TimeBlock.Anytime.HasEnd.Should().Be.False();
            TimeBlock.Anytime.HasPeriod.Should().Be.False();
        }
Exemplo n.º 4
0
        public void CopyTest() {
            TimeBlock readOnlyTimeBlock = new TimeBlock(_start, _duration);
            Assert.AreEqual(readOnlyTimeBlock.Copy(TimeSpan.Zero), readOnlyTimeBlock);

            TimeBlock timeBlock = new TimeBlock(_start, _duration);
            Assert.AreEqual(timeBlock.Start, _start);
            Assert.AreEqual(timeBlock.End, _end);
            Assert.AreEqual(timeBlock.Duration, _duration);

            ITimeBlock noMoveTimeBlock = timeBlock.Copy(TimeSpan.Zero);
            Assert.AreEqual(noMoveTimeBlock.Start, _start);
            Assert.AreEqual(noMoveTimeBlock.End, _end);
            Assert.AreEqual(noMoveTimeBlock.Duration, _duration);

            TimeSpan forwardOffset = new TimeSpan(2, 30, 15);
            ITimeBlock forwardTimeBlock = timeBlock.Copy(forwardOffset);
            Assert.AreEqual(forwardTimeBlock.Start, _start.Add(forwardOffset));
            Assert.AreEqual(forwardTimeBlock.End, _end.Add(forwardOffset));
            Assert.AreEqual(forwardTimeBlock.Duration, _duration);

            TimeSpan backwardOffset = new TimeSpan(-1, 10, 30);
            ITimeBlock backwardTimeBlock = timeBlock.Copy(backwardOffset);
            Assert.AreEqual(backwardTimeBlock.Start, _start.Add(backwardOffset));
            Assert.AreEqual(backwardTimeBlock.End, _end.Add(backwardOffset));
            Assert.AreEqual(backwardTimeBlock.Duration, _duration);
        }
Exemplo n.º 5
0
        public void HasInsideDateTimeTest() {
            TimeBlock timeBlock = new TimeBlock(_start, _duration);
            Assert.AreEqual(timeBlock.Duration, _duration);

            // start
            Assert.IsFalse(timeBlock.HasInside(_start.AddMilliseconds(-1)));
            Assert.IsTrue(timeBlock.HasInside(_start));
            Assert.IsTrue(timeBlock.HasInside(_start.AddMilliseconds(1)));

            // end
            Assert.IsTrue(timeBlock.HasInside(_end.AddMilliseconds(-1)));
            Assert.IsTrue(timeBlock.HasInside(_end));
            Assert.IsFalse(timeBlock.HasInside(_end.AddMilliseconds(1)));
        }
Exemplo n.º 6
0
 public void DurationOutOfRangeTest() {
     TimeBlock timeBlock = new TimeBlock(_start, _duration);
     Assert.Throws<InvalidOperationException>(() => timeBlock.Duration = TimeSpan.FromMilliseconds(1).Negate());
 }
Exemplo n.º 7
0
 public void EndReadOnlyTest() {
     var timeBlock = new TimeBlock(ClockProxy.Clock.Now.AddHours(-1), ClockProxy.Clock.Now, true);
     Assert.Throws<InvalidOperationException>(() => timeBlock.End = timeBlock.End.AddHours(1));
 }
Exemplo n.º 8
0
        public void StartTest() {
            var timeBlock = new TimeBlock(_start, _duration);

            timeBlock.Start.Should().Be(_start);
            timeBlock.Duration.Should().Be(_duration);

            var changedStart = _start.AddHours(-1);
            timeBlock.Start = changedStart;

            timeBlock.Start.Should().Be(changedStart);
            timeBlock.Duration.Should().Be(_duration);
        }
        private void OnAddTimeBlock(object sender, RoutedEventArgs e)
        {
            TimeBlock tb = new TimeBlock();

            Data.TimeBlocks.Add(tb);
        }
Exemplo n.º 10
0
        public void GetIntersectionTest() {
            TimeBlock readOnlyTimeBlock = new TimeBlock(_start, _duration);
            Assert.AreEqual(readOnlyTimeBlock.GetIntersectionBlock(readOnlyTimeBlock), new TimeBlock(readOnlyTimeBlock));

            TimeBlock timeBlock = new TimeBlock(_start, _duration);

            // before
            ITimeBlock before1 = timeBlock.GetIntersectionBlock(new TimeBlock(_start.AddHours(-2), _start.AddHours(-1)));
            Assert.AreEqual(before1, null);
            ITimeBlock before2 = timeBlock.GetIntersectionBlock(new TimeBlock(_start.AddMilliseconds(-1), _start));
            Assert.AreEqual(before2, new TimeBlock(_start));
            ITimeBlock before3 = timeBlock.GetIntersectionBlock(new TimeBlock(_start.AddMilliseconds(-1), _start.AddMilliseconds(1)));
            Assert.AreEqual(before3, new TimeBlock(_start, _start.AddMilliseconds(1)));

            // after
            ITimeBlock after1 = timeBlock.GetIntersectionBlock(new TimeBlock(_end.AddHours(1), _end.AddHours(2)));
            Assert.AreEqual(after1, null);
            ITimeBlock after2 = timeBlock.GetIntersectionBlock(new TimeBlock(_end, _end.AddMilliseconds(1)));
            Assert.AreEqual(after2, new TimeBlock(_end));
            ITimeBlock after3 = timeBlock.GetIntersectionBlock(new TimeBlock(_end.AddMilliseconds(-1), _end.AddMilliseconds(1)));
            Assert.AreEqual(after3, new TimeBlock(_end.AddMilliseconds(-1), _end));

            // intersect
            Assert.AreEqual(timeBlock.GetIntersectionBlock(timeBlock), timeBlock);
            ITimeBlock itersect1 = timeBlock.GetIntersectionBlock(new TimeBlock(_start.AddMilliseconds(-1), _end.AddMilliseconds(1)));
            Assert.AreEqual(itersect1, timeBlock);
            ITimeBlock itersect2 = timeBlock.GetIntersectionBlock(new TimeBlock(_start.AddMilliseconds(1), _end.AddMilliseconds(-1)));
            Assert.AreEqual(itersect2, new TimeBlock(_start.AddMilliseconds(1), _end.AddMilliseconds(-1)));
        }
Exemplo n.º 11
0
 public void Update(TimeBlock timeBlock)
 {
     this.timeBlock = timeBlock;
     RaisePropertyChanged(() => Date);
     RaisePropertyChanged(() => Time);
 }
Exemplo n.º 12
0
 public TimeBlockListItemViewModel(TimeBlock timeBlock)
 {
     this.timeBlock = timeBlock;
 }
Exemplo n.º 13
0
 public AverageShareOfBlockRewardDT(TimeBlock averageBlockCreationSpan, double blockRewardPerBlock, TimeBlock duration, IHashRate minerHashRate, IHashRate networkHashRate)
 {
     AverageBlockCreationSpan = averageBlockCreationSpan ?? throw new ArgumentNullException(nameof(averageBlockCreationSpan));
     BlockRewardPerBlock      = blockRewardPerBlock;
     Duration        = duration ?? throw new ArgumentNullException(nameof(duration));
     MinerHashRate   = minerHashRate ?? throw new ArgumentNullException(nameof(minerHashRate));
     NetworkHashRate = networkHashRate ?? throw new ArgumentNullException(nameof(networkHashRate));
 }
Exemplo n.º 14
0
 bool BlockIsToday(TimeBlock timeBlock)
 {
     return(timeBlock.Start.Date == DateTime.Today);
 }
 /// <summary>
 /// This method is here to add and position existing time blocks.
 /// Assume this method is called by the engine, and links to the
 /// NodeEditor.DialogueBlockNode.LinkedTimeblock
 /// </summary>
 /// <param name="timeBlock"></param>
 public void AddExistingTimeblockToTimeline(TimeBlock timeBlock, int timelineIndex)
 {
     timelines[timelineIndex].AddTimeBlock(timeBlock, TimeWidth);
 }
 private void SetSnapLocation(List <Timeline> timelines, TimeBlock desiredsnapper, int timeline)
 {
 }
Exemplo n.º 17
0
        public void GetPreviousPeriodTest() {
            var readOnlyTimeBlock = new TimeBlock(_start, _duration, true);
            Assert.IsTrue(readOnlyTimeBlock.GetPreviousBlock().IsReadOnly);

            var timeBlock = new TimeBlock(_start, _duration);

            Assert.AreEqual(timeBlock.Start, _start);
            Assert.AreEqual(timeBlock.End, _end);
            Assert.AreEqual(timeBlock.Duration, _duration);

            var previousTimeBlock = timeBlock.GetPreviousBlock();
            Assert.AreEqual(previousTimeBlock.Start, _start.Subtract(_duration));
            Assert.AreEqual(previousTimeBlock.End, _start);
            Assert.AreEqual(previousTimeBlock.Duration, _duration);

            var previousOffset = TimeSpan.FromHours(1).Negate();
            var previousOffsetTimeBlock = timeBlock.GetPreviousBlock(previousOffset);

            previousOffsetTimeBlock.Start.Should().Be(_start.Subtract(_duration).Add(previousOffset));
            previousOffsetTimeBlock.End.Should().Be(_end.Subtract(_duration).Add(previousOffset));
            previousOffsetTimeBlock.Duration.Should().Be(_duration);
        }
Exemplo n.º 18
0
        public void EqualsTest() {
            var timeBlock1 = new TimeBlock(_start, _duration);
            var timeBlock2 = new TimeBlock(_start, _duration);

            timeBlock1.Should().Be(timeBlock2);

            var timeBlock3 = new TimeBlock(_start.AddMilliseconds(-1), _end.AddMilliseconds(1));

            timeBlock1.Should().Not.Be(timeBlock3);
        }
Exemplo n.º 19
0
        public void HasEndTest() {
            // 현재까지
            var timeBlock = new TimeBlock(null, ClockProxy.Clock.Now);

            timeBlock.HasStart.Should().Be.False();
            timeBlock.HasEnd.Should().Be.True();
        }
Exemplo n.º 20
0
        public async Task Init(Guid roomId, DateTime dateTime)
        {
            _roomId   = roomId;
            _dateTime = dateTime;

            try
            {
                var roomModel = await _bookingService.GetRoomAsync(ApiPriority.UserInitiated, roomId);

                var roomReservationsForToday = await _bookingService.GetAllReservationsForDayAsync(ApiPriority.UserInitiated, _dateTime.Year, _dateTime.DayOfYear);

                roomReservationsForToday = roomReservationsForToday.Where(r => r.RoomId == roomId).ToList();
                _allMembers = await _userService.GetAllPublicUsersAsync(ApiPriority.UserInitiated);

                var startHour = 6;
                var endHour   = 24;

                if (roomModel?.OpeningInformation != null)
                {
                    // Check opening hours
                    var openingDay = GetOpeningInfo(roomModel.OpeningInformation, dateTime.DayOfWeek);

                    startHour = openingDay.HourOpen;
                    endHour   = openingDay.HourClose;
                }

                //if (dateTime.Year == DateTime.Now.Year && dateTime.DayOfYear == DateTime.Now.DayOfYear)
                //{
                //    // Is today check current hour
                //    if (DateTime.Now.Hour > startHour)
                //    {
                //        // Later then opening hour
                //        startHour = DateTime.Now.Hour;
                //    }
                //    else if (DateTime.Now.Hour > endHour)
                //    {
                //        // Already closed
                //        startHour = 24;
                //    }

                //    // Remove reservations that have already passed
                //    roomReservationsForToday = roomReservationsForToday.Where(r => r.ReservationEnd.Hour < startHour).ToList();

                //    //foreach (var roomReservationModel in roomReservationsForToday.wh)
                //    //{
                //    //    // Change start date to start of reservation possibilities
                //    //    roomReservationModel.ReservationStart = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, startHour, 0, 0);
                //    //}
                //}

                if (startHour != 24)
                {
                    var startTime = new TimePickerData(startHour, 0);
                    var endTime   = new TimePickerData(endHour, 0);
                    StartEndTime = new TimeBlock(startTime, endTime);

                    UpdateReservations(roomReservationsForToday);
                }
            }
            catch (Exception ex)
            {
                ExceptionService.HandleException(ex);
            }
        }
Exemplo n.º 21
0
        public override ITimePeriod GetTimePeriod(DateTime baseDate)
        {
            ITimePeriod result = null;

            if (NumericDate.IsMatch(Text))
            {
                DateTime pointInTime;
                var      dateParts  = Text.Split('-', '/');
                var      commonDate = string.Join("-", dateParts);
                var      formats    = new string[]
                {
                    "yyyy-MM-dd",
                    "d-M-yyyy",
                    "M-d-yyyy"
                };

                if (!DateTime.TryParseExact(commonDate, formats, null, System.Globalization.DateTimeStyles.None, out pointInTime))
                {
                    return(null);
                }

                result = new Day(pointInTime);
            }
            else if (LongFormatDate.IsMatch(Text))
            {
                var retrievedDay = LongFormatRetrieveDay.Match(Text).Value;
                var parsedDay    = 1;
                if (retrievedDay.Length > 0)
                {
                    //Apply date rule if value contains a date
                    parsedDay = int.Parse(retrievedDay);
                }

                //Enforce valid date
                if (parsedDay > 31)
                {
                    return(null);
                }

                var retrievedMonth = "";
                var parsedMonth    = 1;
                var matchedNames   = NameRetrieve.Matches(Text).Cast <Match>();
                foreach (var match in matchedNames)
                {
                    if (match.Value.Length > 2)
                    {
                        //Apply next weekday rule if value looks like it has weekday details
                        //Note: This makes the assumption that the sentence infers a future date
                        var weekDay = GetNextDateFromWeekDay(match.Value, baseDate);
                        if (weekDay > baseDate)
                        {
                            parsedDay = weekDay.Day;
                            continue;
                        }

                        //Apply month rule if value looks like it has month details
                        var month = GetMonthFromName(match.Value);
                        if (month != -1)
                        {
                            retrievedMonth = match.Value;
                            parsedMonth    = month;
                            continue;
                        }
                    }
                }

                var retrievedYear = LongFormatRetrieveYear.Match(Text).Value;
                var parsedYear    = baseDate.Year;
                if (retrievedYear.Length > 0)
                {
                    //Apply year rule if the value contains a year
                    parsedYear = int.Parse(retrievedYear);
                }

                //Apply base month if no month or year details were found
                if (retrievedMonth.Length == 0 && retrievedYear.Length == 0)
                {
                    parsedMonth = baseDate.Month;
                }

                //Handle that the parsed date is allowed for the given month
                var lastDayOfMonth = new Month(parsedYear, (YearMonth)parsedMonth).End;
                if (parsedDay > lastDayOfMonth.Day)
                {
                    return(null);
                }

                var leadingDate  = new DateTime(parsedYear, parsedMonth, parsedDay);
                var trailingDate = leadingDate;

                //When value is specific to the...
                if (retrievedDay.Length > 0)
                {
                    //Day
                    trailingDate = new Day(trailingDate).End;
                }
                else if (retrievedMonth.Length > 0)
                {
                    //Month
                    trailingDate = new Month(trailingDate).End;
                }
                else if (retrievedYear.Length > 0)
                {
                    //Year
                    trailingDate = new Year(trailingDate).End;
                }

                //Apply rules for open-ended date
                if (Text.ToLower().StartsWith("before"))
                {
                    result = new TimeRange(TimeSpec.MinPeriodDate, leadingDate);
                }
                else if (Text.ToLower().StartsWith("after"))
                {
                    result = new TimeRange(trailingDate, TimeSpec.MaxPeriodDate);
                }
                else
                {
                    result = new TimeRange(leadingDate, trailingDate);
                }
            }
            else if (FormalDayFirstDate.IsMatch(Text) || FormalMonthFirstDate.IsMatch(Text))
            {
                var dateParts      = Text.Split(new[] { ", ", " " }, StringSplitOptions.RemoveEmptyEntries);
                var retrievedDay   = "";
                var retrievedMonth = "";

                //Work out the order of day/month
                if (FormalDayFirstDate.IsMatch(Text))
                {
                    retrievedDay   = dateParts[0];
                    retrievedMonth = dateParts[1];
                }
                else
                {
                    retrievedDay   = dateParts[1];
                    retrievedMonth = dateParts[0];
                }

                var parsedDay = int.Parse(retrievedDay);

                //Check if the retrieved month can at least partial match a month
                var nameMatch = NameRetrieve.Match(retrievedMonth).Value;
                var month     = Months.Where(m => m.StartsWith(nameMatch)).FirstOrDefault();
                if (month == null)
                {
                    return(null);
                }
                var parsedMonth = GetMonthFromName(month);

                var parsedYear = baseDate.Year;
                if (dateParts.Length == 3)
                {
                    parsedYear = int.Parse(dateParts[2]);
                }

                //Handle that the parsed date is allowed for the given month
                var lastDayOfMonth = new Month(parsedYear, (YearMonth)parsedMonth).End;
                if (parsedDay > lastDayOfMonth.Day)
                {
                    return(null);
                }

                var pointInTime = new DateTime(parsedYear, parsedMonth, parsedDay);
                result = new TimeBlock(pointInTime, new Day(pointInTime).End);
            }
            else if (OnWeekdayDate.IsMatch(Text))
            {
                var retrievedWeekday = WeekdayNameRetrieve.Match(Text).Value;
                var weekDay          = Days.Where(d => d.StartsWith(retrievedWeekday)).FirstOrDefault();
                if (weekDay != null)
                {
                    //Note: This makes the assumption that the sentence infers a future date
                    var pointInTime = GetNextDateFromWeekDay(weekDay, baseDate);
                    result = new TimeBlock(pointInTime, new Day(pointInTime).End);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                //Must match one of the specific date formats
                return(null);
            }

            return(result);
        }
Exemplo n.º 22
0
 public void NonMomentTest() {
     var timeBlock = new TimeBlock(ClockProxy.Clock.Now, TimeSpec.MinPositiveDuration);
     timeBlock.IsMoment.Should().Be.False();
     timeBlock.Duration.Should().Be(TimeSpec.MinPositiveDuration);
 }
Exemplo n.º 23
0
        private static List <Renderable> ReadUsage(Dictionary <string, AnimationDef> animDefs, Dictionary <string, CharSet> charsets, Dictionary <string, TextDef> textDefs, Dictionary <string, UsageGroup> groupDefs, XmlNode time, TimeBlock parent)
        {
            List <Renderable> objects = new List <Renderable>();

            for (int i = 0; i < time.ChildNodes.Count; i++)
            {
                XmlNode use = time.ChildNodes[i];

                if (use.Name.ToLower() == "useanim")
                {
                    //AnimationDef aDef = (from ad in animDefs
                    //                     where ad.Name == use.Attributes["name"].Value
                    //                     select ad).ToList()[0];

                    Animation a = new Animation(parent, animDefs[use.Attributes["name"].Value])
                    {
                        X = int.Parse(use.Attributes["x"].Value),
                        Y = int.Parse(use.Attributes["y"].Value)
                    };
                    ReadRenderableParams(i, use, a);

                    // read animation attributes
                    a.Attributes = ReadUsageAttributes(use);

                    objects.Add(a);
                }
                else if (use.Name.ToLower() == "usetext")
                {
                    //TextDef tDef = (from t in textDefs
                    //                where t.Name == use.Attributes["name"].Value
                    //                select t).ToList()[0];

                    TextDef tdef;
                    if (use.Attributes["text"] != null && use.Attributes["charset"] != null)
                    {
                        tdef = new TextDef()
                        {
                            CharacterSet = charsets[use.Attributes["charset"].Value],
                            Value        = use.Attributes["text"].Value
                        };
                    }
                    else
                    {
                        tdef = textDefs[use.Attributes["name"].Value];
                    }

                    Text txt = new Text(parent, tdef)
                    {
                        X = int.Parse(use.Attributes["x"].Value),
                        Y = int.Parse(use.Attributes["y"].Value),
                    };
                    ReadRenderableParams(i, use, txt);

                    // read text attributes
                    txt.Attributes = ReadUsageAttributes(use);

                    objects.Add(txt);
                }
                else if (use.Name.ToLower() == "usegroup")
                {
                    UsageGroup g = groupDefs[use.Attributes["name"].Value];
                    foreach (Renderable o in g.Objects)
                    {
                        Renderable oClone = o.Clone();
                        oClone.ParentBlock = parent;
                        objects.Add(oClone);
                    }
                }
            }
            return(objects);
        }
Exemplo n.º 24
0
 public static double AverageShareOfBlockRewardPerSpanSafe(AverageShareOfBlockRewardDT data, TimeBlock timeSpan)
 {
     // ToDo: Add parameter checking
     return(AverageShareOfBlockRewardPerSpanFast(data, timeSpan));
 }
Exemplo n.º 25
0
        public static string GetDetail(DateTime now, DateTime timeToDescribe)
        {
            TimeBlock timeBlock = GetTimeBlock(now, timeToDescribe);

            return(GetDetail(timeBlock, timeToDescribe));
        }
Exemplo n.º 26
0
 public void EndTest() {
     var timeBlock = new TimeBlock(_duration, _end);
     Assert.AreEqual(timeBlock.End, _end);
     Assert.AreEqual(timeBlock.Duration, _duration);
     DateTime changedEnd = _end.AddHours(1);
     timeBlock.End = changedEnd;
     Assert.AreEqual(timeBlock.End, changedEnd);
     Assert.AreEqual(timeBlock.Duration, _duration);
 }
        public void StartReadOnlyTest()
        {
            TimeBlock timeBlock = new TimeBlock(ClockProxy.Clock.Now, ClockProxy.Clock.Now.AddHours(1), true);

            timeBlock.Start = timeBlock.Start.AddHours(-1);
        }         // StartReadOnlyTest
Exemplo n.º 28
0
 public void MaxDurationOutOfRangeTest() {
     TimeBlock timeBlock = new TimeBlock(_start, _duration);
     Assert.Throws<ArgumentOutOfRangeException>(() => timeBlock.Duration = TimeSpec.MaxPeriodDuration);
 }
        public void EndReadOnlyTest()
        {
            TimeBlock timeBlock = new TimeBlock(ClockProxy.Clock.Now.AddHours(-1), ClockProxy.Clock.Now, true);

            timeBlock.End = timeBlock.End.AddHours(1);
        }         // EndReadOnlyTest
Exemplo n.º 30
0
        public void DurationFromEndTest() {
            TimeBlock timeBlock = new TimeBlock(_start, _duration);
            Assert.AreEqual(timeBlock.Start, _start);
            Assert.AreEqual(timeBlock.End, _end);
            Assert.AreEqual(timeBlock.Duration, _duration);

            TimeSpan delta = TimeSpan.FromHours(1);
            TimeSpan newDuration = timeBlock.Duration + delta;
            timeBlock.DurationFromEnd(newDuration);
            Assert.AreEqual(timeBlock.Start, _start.Subtract(delta));
            Assert.AreEqual(timeBlock.End, _end);
            Assert.AreEqual(timeBlock.Duration, newDuration);

            timeBlock.DurationFromEnd(TimeSpec.MinPeriodDuration);
            Assert.AreEqual(timeBlock.Duration, TimeSpec.MinPeriodDuration);
        }
        public void MaxDurationOutOfRangeTest()
        {
            TimeBlock timeBlock = new TimeBlock(start, duration);

            timeBlock.Duration = TimeSpec.MaxPeriodDuration;
        }         // MaxDurationOutOfRangeTest
Exemplo n.º 32
0
        public void HasInsidePeriodTest() {
            TimeBlock timeBlock = new TimeBlock(_start, _duration);
            Assert.AreEqual(timeBlock.Duration, _duration);

            // before
            TimeBlock before1 = new TimeBlock(_start.AddHours(-2), _start.AddHours(-1));
            Assert.IsFalse(timeBlock.HasInside(before1));
            TimeBlock before2 = new TimeBlock(_start.AddMilliseconds(-1), _end);
            Assert.IsFalse(timeBlock.HasInside(before2));
            TimeBlock before3 = new TimeBlock(_start.AddMilliseconds(-1), _start);
            Assert.IsFalse(timeBlock.HasInside(before3));

            // after
            TimeBlock after1 = new TimeBlock(_end.AddHours(1), _end.AddHours(2));
            Assert.IsFalse(timeBlock.HasInside(after1));
            TimeBlock after2 = new TimeBlock(_start, _end.AddMilliseconds(1));
            Assert.IsFalse(timeBlock.HasInside(after2));
            TimeBlock after3 = new TimeBlock(_end, _end.AddMilliseconds(1));
            Assert.IsFalse(timeBlock.HasInside(after3));

            // inside
            Assert.IsTrue(timeBlock.HasInside(timeBlock));
            TimeBlock inside1 = new TimeBlock(_start.AddMilliseconds(1), _end);
            Assert.IsTrue(timeBlock.HasInside(inside1));
            TimeBlock inside2 = new TimeBlock(_start.AddMilliseconds(1), _end.AddMilliseconds(-1));
            Assert.IsTrue(timeBlock.HasInside(inside2));
            TimeBlock inside3 = new TimeBlock(_start, _end.AddMilliseconds(-1));
            Assert.IsTrue(timeBlock.HasInside(inside3));
        }
        public void DurationOutOfRangeTest()
        {
            TimeBlock timeBlock = new TimeBlock(start, duration);

            timeBlock.Duration = Duration.Millisecond.Negate();
        }         // DurationOutOfRangeTest
Exemplo n.º 34
0
        public void MoveTest() {
            TimeBlock timeBlockMoveZero = new TimeBlock(_start, _duration);
            timeBlockMoveZero.Move(TimeSpan.Zero);
            Assert.AreEqual(timeBlockMoveZero.Start, _start);
            Assert.AreEqual(timeBlockMoveZero.End, _end);
            Assert.AreEqual(timeBlockMoveZero.Duration, _duration);

            TimeBlock timeBlockMoveForward = new TimeBlock(_start, _duration);
            TimeSpan forwardOffset = new TimeSpan(2, 30, 15);
            timeBlockMoveForward.Move(forwardOffset);
            Assert.AreEqual(timeBlockMoveForward.Start, _start.Add(forwardOffset));
            Assert.AreEqual(timeBlockMoveForward.End, _end.Add(forwardOffset));

            TimeBlock timeBlockMoveBackward = new TimeBlock(_start, _duration);
            TimeSpan backwardOffset = new TimeSpan(-1, 10, 30);
            timeBlockMoveBackward.Move(backwardOffset);
            Assert.AreEqual(timeBlockMoveBackward.Start, _start.Add(backwardOffset));
            Assert.AreEqual(timeBlockMoveBackward.End, _end.Add(backwardOffset));
        }
Exemplo n.º 35
0
        /// <summary>
        /// Gets the Agents Calendar view.
        /// </summary>
        /// <param name="ssoToken">The sso access token used to make request against graph apis.</param>
        /// <param name="constraints">The time constraint for finding calendar view.</param>
        /// /// <param name="azureADSettings">Azure AD configuration settings.</param>
        /// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
        public static async Task<GraphResponse<IEnumerable<MeetingDetails>>> GetCalendarViewAsync(string ssoToken, TimeBlock constraints, AzureADSettings azureADSettings)
        {
            var authProvider = CreateOnBehalfOfProvider(azureADSettings, new[] { "Calendars.Read" });
            GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);

            var startDateTimeParam = Uri.EscapeDataString(constraints.StartDateTime.ToString("o"));
            var endDateTimeParam = Uri.EscapeDataString(constraints.EndDateTime.ToString("o"));
            var queryOptions = new List<QueryOption>()
                      {
                           new QueryOption("startdatetime", startDateTimeParam),
                           new QueryOption("enddatetime", endDateTimeParam),
                      };

            GraphResponse<IEnumerable<MeetingDetails>> response = new GraphResponse<IEnumerable<MeetingDetails>>();

            try
            {
                var page = await graphServiceClient.Me
                    .CalendarView.Request(queryOptions)
                    .WithUserAssertion(new UserAssertion(ssoToken))
                    .GetAsync();

                List<MeetingDetails> result = new List<MeetingDetails>();
                while (page != null)
                {
                    var meetingList = page.CurrentPage;
                    foreach (var meeting in meetingList)
                    {
                        result.Add(new MeetingDetails
                        {
                            Subject = meeting.Subject,
                            MeetingTime = new TimeBlock
                            {
                                StartDateTime = meeting.Start.ToDateTimeOffset().ToUniversalTime(),
                                EndDateTime = meeting.End.ToDateTimeOffset().ToUniversalTime(),
                            },
                        });
                    }

                    if (page.NextPageRequest == null)
                    {
                        break;
                    }

                    page = await page.NextPageRequest.GetAsync();
                }

                response.Result = result.ToImmutableList();
                return response;
            }
            catch (Exception e)
            {
                response.FailureReason = e.Message;
                response.Result = new List<MeetingDetails>();
            }

            return response;
        }
Exemplo n.º 36
0
        public void GetNextPeriodTest() {
            TimeBlock readOnlyTimeBlock = new TimeBlock(_start, _duration, true);
            Assert.IsTrue(readOnlyTimeBlock.GetNextBlock().IsReadOnly);

            TimeBlock timeBlock = new TimeBlock(_start, _duration);
            Assert.AreEqual(timeBlock.Start, _start);
            Assert.AreEqual(timeBlock.End, _end);
            Assert.AreEqual(timeBlock.Duration, _duration);

            ITimeBlock nextTimeBlock = timeBlock.GetNextBlock();
            Assert.AreEqual(nextTimeBlock.Start, _end);
            Assert.AreEqual(nextTimeBlock.End, _end.Add(_duration));
            Assert.AreEqual(nextTimeBlock.Duration, _duration);

            TimeSpan nextOffset = TimeSpan.FromHours(1);
            ITimeBlock nextOffsetTimeBlock = timeBlock.GetNextBlock(nextOffset);
            Assert.AreEqual(nextOffsetTimeBlock.Start, _end.Add(nextOffset));
            Assert.AreEqual(nextOffsetTimeBlock.End, _end.Add(_duration + nextOffset));
            Assert.AreEqual(nextOffsetTimeBlock.Duration, _duration);
        }
Exemplo n.º 37
0
        public void MomentByPeriodTest()
        {
            TimeBlock timeBlock = new TimeBlock(ClockProxy.Clock.Now, TimeSpan.Zero);

            Assert.True(timeBlock.IsMoment);
        }         // MomentByPeriodTest
Exemplo n.º 38
0
        public void IntersectsWithDurationTest() {
            TimeBlock timeBlock = new TimeBlock(_start, _duration);

            // before
            TimeBlock before1 = new TimeBlock(_start.AddHours(-2), _start.AddHours(-1));
            Assert.IsFalse(timeBlock.IntersectsWith(before1));
            TimeBlock before2 = new TimeBlock(_start.AddMilliseconds(-1), _start);
            Assert.IsTrue(timeBlock.IntersectsWith(before2));
            TimeBlock before3 = new TimeBlock(_start.AddMilliseconds(-1), _start.AddMilliseconds(1));
            Assert.IsTrue(timeBlock.IntersectsWith(before3));

            // after
            TimeBlock after1 = new TimeBlock(_end.AddHours(1), _end.AddHours(2));
            Assert.IsFalse(timeBlock.IntersectsWith(after1));
            TimeBlock after2 = new TimeBlock(_end, _end.AddMilliseconds(1));
            Assert.IsTrue(timeBlock.IntersectsWith(after2));
            TimeBlock after3 = new TimeBlock(_end.AddMilliseconds(-1), _end.AddMilliseconds(1));
            Assert.IsTrue(timeBlock.IntersectsWith(after3));

            // intersect
            Assert.IsTrue(timeBlock.IntersectsWith(timeBlock));
            TimeBlock itersect1 = new TimeBlock(_start.AddMilliseconds(-1), _end.AddMilliseconds(1));
            Assert.IsTrue(timeBlock.IntersectsWith(itersect1));
            TimeBlock itersect2 = new TimeBlock(_start.AddMilliseconds(-1), _start.AddMilliseconds(1));
            Assert.IsTrue(timeBlock.IntersectsWith(itersect2));
            TimeBlock itersect3 = new TimeBlock(_end.AddMilliseconds(-1), _end.AddMilliseconds(1));
            Assert.IsTrue(timeBlock.IntersectsWith(itersect3));
        }
Exemplo n.º 39
0
 // Start is called before the first frame update
 void Start()
 {
     CurrentTime = new TimeBlock();
 }
Exemplo n.º 40
0
        public void IsSamePeriodTest() {
            TimeBlock timeRange1 = new TimeBlock(_start, _duration);
            TimeBlock timeRange2 = new TimeBlock(_start, _duration);

            Assert.IsTrue(timeRange1.IsSamePeriod(timeRange1));
            Assert.IsTrue(timeRange2.IsSamePeriod(timeRange2));

            Assert.IsTrue(timeRange1.IsSamePeriod(timeRange2));
            Assert.IsTrue(timeRange2.IsSamePeriod(timeRange1));

            Assert.IsFalse(timeRange1.IsSamePeriod(TimeBlock.Anytime));
            Assert.IsFalse(timeRange2.IsSamePeriod(TimeBlock.Anytime));

            timeRange1.Move(new TimeSpan(1));
            Assert.IsFalse(timeRange1.IsSamePeriod(timeRange2));
            Assert.IsFalse(timeRange2.IsSamePeriod(timeRange1));

            timeRange1.Move(new TimeSpan(-1));
            Assert.IsTrue(timeRange1.IsSamePeriod(timeRange2));
            Assert.IsTrue(timeRange2.IsSamePeriod(timeRange1));
        }
Exemplo n.º 41
0
        private void DrawBackbuffer(int totalDuration)
        {
            int height = (ShowLegend ? Height - 20 : Height);

            using (Graphics g = Graphics.FromImage(backBuffer))

            {
                g.Clear(Color.White);

                for (int i = 0; i < Animation.Flow.TimeBlocks.Count; i++)
                {
                    TimeBlock tb    = Animation.Flow.TimeBlocks[i];
                    int       left  = (int)(((float)tb.From / (float)totalDuration) * Width);
                    int       right = (int)(((float)tb.To / (float)totalDuration) * Width);

                    Brush b = new SolidBrush(GetColorFrom(i));
                    g.FillRectangle(b, new Rectangle(left, 0, right - left + 1, height));
                }

                int blockHeight = (height / sortedRenderables.Count);
                for (int j = 0; j < sortedRenderables.Count; j++)
                {
                    foreach (Renderable r in sortedRenderables[j])
                    {
                        int currectRStartMs = r.ParentBlock.From + r.StartMs;
                        int currentREndMs   = r.ParentBlock.From + r.StartMs + r.TotalTime;

                        int leftRender  = (int)(((float)currectRStartMs / (float)totalDuration) * (Width - 1));
                        int rightRender = (int)(((float)currentREndMs / (float)totalDuration) * (Width - 1));

                        Brush fillColor = Brushes.Black;
                        if (r.Category == Color.Empty)
                        {
                            if (r is Animation)
                            {
                                fillColor = Brushes.Yellow;
                            }
                            else if (r is Text)
                            {
                                fillColor = Brushes.White;
                            }
                        }
                        else
                        {
                            fillColor = new SolidBrush(r.Category);
                        }

                        g.FillRectangle(fillColor, new Rectangle(leftRender, j * blockHeight, rightRender - leftRender, blockHeight));
                        g.DrawRectangle(Pens.Black, new Rectangle(leftRender, j * blockHeight, rightRender - leftRender, blockHeight));
                    }
                }

                if (ShowLegend)
                {
                    // draw legend
                    int curms = 0;
                    while (curms < totalDuration)
                    {
                        int offset = (int)(((float)curms / (float)totalDuration) * (Width - 1));
                        g.DrawLine(Pens.Black, new Point(offset, height), new Point(offset, height + 2));

                        SizeF strSize = g.MeasureString((curms / 1000).ToString(), Font);
                        g.DrawString((curms / 1000).ToString(), Font, Brushes.Black, new PointF(offset - strSize.Width / 2f, height + 3));
                        curms += 1000;
                    }
                }
            }
            updateBackbuffer = false;
        }
Exemplo n.º 42
0
        public void ResetTest() {
            TimeBlock timeBlock = new TimeBlock(_start, _duration);
            Assert.AreEqual(timeBlock.Start, _start);
            Assert.IsTrue(timeBlock.HasStart);
            Assert.AreEqual(timeBlock.End, _end);
            Assert.IsTrue(timeBlock.HasEnd);
            Assert.AreEqual(timeBlock.Duration, _duration);

            timeBlock.Reset();
            Assert.AreEqual(timeBlock.Start, TimeSpec.MinPeriodTime);
            Assert.IsFalse(timeBlock.HasStart);
            Assert.AreEqual(timeBlock.End, TimeSpec.MaxPeriodTime);
            Assert.IsFalse(timeBlock.HasEnd);
        }
 public ClaymoreMinerStatus(int iD, ClaymoreMinerStatusDetails minerStatusDetails, string statusQueryError, string version, TimeBlock moment) :
     base(iD, minerStatusDetails, statusQueryError, version, moment)
 {
 }
Exemplo n.º 44
0
 public void MomentByPeriodTest() {
     var timeBlock = new TimeBlock(ClockProxy.Clock.Now, TimeSpan.Zero);
     timeBlock.IsMoment.Should().Be.True();
 }
        public async Task <IActionResult> GetMeetingDetailsAsync([FromHeader] string authorization, [FromBody] TimeBlock constraints)
        {
            string ssoToken = authorization.Substring("Bearer".Length + 1);
            var    graphMeetingDetailsResponse = await GraphUtil.GetCalendarViewAsync(ssoToken, constraints, this.azureADOptions.Value);

            if (!graphMeetingDetailsResponse.FailureReason.Equals(string.Empty))
            {
                this.logger.LogError($"Failed to get meeting details for agent. The Graph call failed: {graphMeetingDetailsResponse.FailureReason}");
                return(this.StatusCode(400, new UnsuccessfulResponse {
                    Reason = graphMeetingDetailsResponse.FailureReason
                }));
            }

            // Graph /calendarView endpoint returns results that are inclusive of the given startDateTime
            // We filter out events that are adjacent to (but not inside of) the constraint
            var filteredResults = graphMeetingDetailsResponse.Result
                                  .Where(meeting => meeting.MeetingTime.StartDateTime <constraints.EndDateTime && meeting.MeetingTime.EndDateTime> constraints.StartDateTime);

            return(this.Ok(filteredResults));
        }
Exemplo n.º 46
0
        public void StartTimeSpanTest() {
            var timeBlock = new TimeBlock(_start, _duration);

            timeBlock.Start.Should().Be(_start);
            timeBlock.Duration.Should().Be(_duration);
            timeBlock.End.Should().Be(_end);

            timeBlock.HasPeriod.Should().Be.True();
            timeBlock.IsAnytime.Should().Be.False();
            timeBlock.IsMoment.Should().Be.False();
            timeBlock.IsReadOnly.Should().Be.False();
        }
Exemplo n.º 47
0
        public void CopyConstructorTest() {
            var source = new TimeBlock(_start, _start.AddHours(1), true);
            var copy = new TimeBlock(source);

            copy.Start.Should().Be(source.Start);
            copy.Duration.Should().Be(source.Duration);
            copy.End.Should().Be(source.End);

            copy.IsReadOnly.Should().Be.True();

            copy.HasPeriod.Should().Be.True();
            copy.IsAnytime.Should().Be.False();
            copy.IsMoment.Should().Be.False();
        }
Exemplo n.º 48
0
        public void EndReadOnlyTest()
        {
            var timeBlock = new TimeBlock(ClockProxy.Clock.Now.AddHours(-1), ClockProxy.Clock.Now, true);

            Assert.Throws <InvalidOperationException>(() => timeBlock.End = timeBlock.End.AddHours(1));
        }
Exemplo n.º 49
0
        public static double AverageShareOfBlockRewardPerSpanFast(AverageShareOfBlockRewardDT data, TimeBlock timeBlock)
        {
            // normalize into minerHashRateAsAPercentOfTotal the MinerHashRate / NetworkHashRate using the TimeBlock of the Miner
            HashRate minerHashRateAsAPercentOfTotal = default;// ToDo: Fix this calculation data.MinerHashRate / data.NetworkHashRate;
            // normalize the BlockRewardPerSpan to the same span the Miner HashRate span
            //ToDo Fix this calculation
            // normalize the BlockRewardPerSpan to the same span the network HashRate span
            double normalizedBlockCreationSpan = data.AverageBlockCreationSpan.Duration.Ticks /
                                                 data.NetworkHashRate.HashRateTimeSpan.Duration().Ticks;
            double normalizedBlockRewardPerSpan = data.BlockRewardPerBlock /
                                                  (data.AverageBlockCreationSpan.Duration.Ticks *
                                                   normalizedBlockCreationSpan);

            // The number of block rewards found, on average, within a given TimeBlock, is number of blocks in the span, times the fraction of the NetworkHashRate contributed by the miner
            return(normalizedBlockRewardPerSpan *
                   (minerHashRateAsAPercentOfTotal.HashRatePerTimeSpan /
                    data.NetworkHashRate.HashRatePerTimeSpan));
        }