コード例 #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                if (!hasVideo || pbcVideo.Position >= MaximumProgess)
                {
                    pbcVideo.Position = 0;
                    pbcVideo.Position = 0;
                    StartTime         = TransBegin;
                    pePlay.Image      = new Bitmap(Properties.Resources.media_playback_start);
                    timer1.Stop();
                }
                else
                {
                    if (pbcVideo.Position > MaximumProgess)
                    {
                        pbcVideo.Position = MaximumProgess;
                    }
                    pbcVideo.PerformStep();
                    StartTime = StartTime.AddMilliseconds(pbcVideo.Position);
                }

                var dFrom = TimeSpan.FromSeconds(pbcVideo.Position / 1000);
                var dTo   = TimeSpan.FromSeconds(totalTime - pbcVideo.Position / 1000);
                label1.Text = string.Format("{0:D2}:{1:D2}", dFrom.Minutes, dFrom.Seconds);
                label2.Text = string.Format("{0:D2}:{1:D2}", dTo.Minutes, dTo.Seconds);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
コード例 #2
0
        public void UpdateEffect()
        {
            Template.Start(Caster, Owner, this);
            if (Duration == 0)
            {
                Duration = Template.GetDuration();
            }
            if (StartTime == DateTime.MinValue)
            {
                StartTime = DateTime.Now;
                EndTime   = StartTime.AddMilliseconds(Duration);
            }

            Tick = Template.GetTick();

            if (Tick > 0)
            {
                var time = GetTimeLeft();
                if (time > 0)
                {
                    _count = (int)(time / Tick + 0.5f + 1);
                }
                else
                {
                    _count = -1;
                }
                EffectTaskManager.Instance.AddDispelTask(this, Tick);
            }
            else
            {
                EffectTaskManager.Instance.AddDispelTask(this, GetTimeLeft());
            }
        }
コード例 #3
0
        /// <summary>
        /// The StartTime property should be set before calling Run() (unless IgnoreTimer is set to true).
        /// The CurrentGameState must also be set.
        /// </summary>
        public void Run()
        {
            if (IgnoreTimer)
            {
                /* Run solver in the same thread: */
                if (Solver != null)
                {
                    Solver.Solve();
                }
            }
            else
            {
                /* Create an event which can be triggered to signal that a move has been chosen by the solver: */
                if (OutputTriggeringEvent == null)
                {
                    OutputTriggeringEvent = new ManualResetEvent(false /* Not signalled yet*/);
                }
                else
                {
                    OutputTriggeringEvent.Reset();
                }

                /* Run solver in a separate thread: */
                SolverThread = new Thread(RunTheSolver);
                SolverThread.Start();
                try
                {
                    /* Wait for solver to finish running, or for a timeout to occur: */
                    DateTime timeAtWhichToStopSolver = StartTime.AddMilliseconds(TIME_TO_WAIT_UNTIL_STOPPING_SOLVER_IN_MILLISECONDS);
                    TimeSpan remainingTime           = timeAtWhichToStopSolver - DateTime.Now;
                    TimeSpan minimumTimeToProvide    = TimeSpan.FromMilliseconds(100); // TODO: remove hard-coding of 0.1 seconds to make a move
                    if (remainingTime <= minimumTimeToProvide)
                    {
                        remainingTime = minimumTimeToProvide;
                    }

                    /* Wait for the solver to finish running: */
                    OutputTriggeringEvent.WaitOne(remainingTime);

                    /* Stop the solver algorithm: */
                    Solver.Stop();

                    /* Wait for solver to stop: */
                    int milliSecondsUntilSolverStopped = 0;
                    while ((Solver.SolverState != SolverState.NotRunning) && (milliSecondsUntilSolverStopped <= MAX_GRACE_PERIOD_TO_STOP_IN))
                    {
                        Thread.Sleep(10);
                        milliSecondsUntilSolverStopped += 10;
                    }
                    System.Diagnostics.Debug.WriteLine("Time for solver to stop: {0}", TimeSpan.FromMilliseconds(milliSecondsUntilSolverStopped));
                }
                finally
                {
                    SolverThread = null;
                }
            }
        }
コード例 #4
0
        public double GetTimeLeft()
        {
            if (Duration == 0)
            {
                return(-1);
            }
            var time = (long)(StartTime.AddMilliseconds(Duration) - DateTime.Now).TotalMilliseconds;

            return(time > 0 ? time : 0);
        }
コード例 #5
0
        public void Run()
        {
            var stopwatch = new Stopwatch();

            StartTime = DateTime.Now;

            stopwatch.Start();

            TestTask = Task.Run(() => _action(StartTimerAndGetCancellationToken()), _token);

            Task.WaitAny(TestTask);

            stopwatch.Stop();

            RunTime = stopwatch.ElapsedMilliseconds;

            EndTime = StartTime.AddMilliseconds(RunTime);
        }
コード例 #6
0
        // So rev code is 0, 0, 33, 1 (last might be id?)
        // CTRE is 0, 0, 25, 0  (last might be id?)
        // Rev uses 30 bytes for pdp + only has temp (not volt or restist)
        // CTRE uses 21 + voltage + resist + temp
        protected DSLOGEntry ReadEntryV4()
        {
            var tripTime   = TripTimeToDouble(reader.ReadByte());
            var packetLoss = PacketLossToDouble(reader.ReadSByte());
            var voltage    = VoltageToDouble(reader.ReadUInt16());
            var rio        = RoboRioCPUToDouble(reader.ReadByte());
            var status     = StatusFlagsToBooleanArray(reader.ReadByte());
            var can        = CANUtilToDouble(reader.ReadByte());
            var wifi       = WifidBToDouble(reader.ReadByte());
            var bandwidth  = BandwidthToDouble(reader.ReadUInt16());
            var pdpId      = reader.ReadByte();
            var pdpData    = ReadPdpData();

            if (!pdpData.HasValue)
            {
                return(null);
            }
            var time = StartTime.AddMilliseconds(EntryDistanceMs * EntryNum++);

            return(new DSLOGEntry(tripTime, packetLoss, voltage, rio, status, can, wifi, bandwidth, pdpId, pdpData.Value.data, pdpData.Value.res, pdpData.Value.volt, pdpData.Value.temp, time));
        }
コード例 #7
0
        //public IList<ActivityEntity> ActivityEntities { get; set; }

        public async Task <IActionResult> OnGetAsync()
        {
            PopulateTimeFrameDropDownList(_context, "");
            StartTime = DateTimeOffset.UtcNow.ToLocalTime();

            //remove hours, minutes, seconds, milliseconds
            StartTime = StartTime.AddMilliseconds(-StartTime.Millisecond).AddSeconds(-StartTime.Second).AddMinutes(-StartTime.Minute).AddHours(-StartTime.Hour);

            //get current day of week
            var dayOfWeek = StartTime.DayOfWeek;

            //if Sunday subtract 6 to get the previous Monday, otherwise subtract the day of week index plus one
            var daysToSubtract = (dayOfWeek) == DayOfWeek.Sunday ? -6 : -(int)dayOfWeek + 1;

            StartTime = StartTime.AddDays(daysToSubtract);
            EndTime   = StartTime.AddDays(6).AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(999);

            Rate = 37.5M;

            var p = new object[]
            {
                new SqlParameter("@p0", SqlDbType.DateTimeOffset, 7)
                {
                    Value = StartTime
                },
                new SqlParameter("@p1", SqlDbType.DateTimeOffset, 7)
                {
                    Value = EndTime
                },
                new SqlParameter("@p2", SqlDbType.Money, 4)
                {
                    Value = Rate
                },
                new SqlParameter("@p3", SqlDbType.Bit, 1)
                {
                    Value = true
                }
            };

            Clients = await _context.Clients.ToListAsync();

            Projects = await _context.Projects.ToListAsync();

            ActivityTypes = await _context.ActivityTypes.ToListAsync();

            Report = await _context
                     .Report
                     .FromSqlRaw("EXEC sp_Report @p0, @p1, @p2, @p3", p)
                     .TagWith("my statement")
                     .ToListAsync();

            ReportDetails = await _context.ReportDetails
                            .FromSqlRaw("EXEC sp_ReportDetails @p0, @p1, @p2, @p3", p)
                            .TagWith("my second statement")
                            .ToListAsync();

            ReportDetailsByDay = await _context.ReportDetailsByDay
                                 .FromSqlRaw("EXEC sp_ReportDetailsByDay @p0, @p1, @p2, @p3", p)
                                 .TagWith("my third statement")
                                 .ToListAsync();

            //ActivityEntities = await PopulateActivityEntities(StartTime, EndTime);
            return(Page());
        }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance with the specified parameters.
 /// </summary>
 /// <param name="start">The date and time that the GraphQL document began execution. If not UTC, this value will be converted to UTC.</param>
 /// <param name="durationMs">The number of milliseconds that it took to execute the GraphQL document.</param>
 public ApolloTrace(DateTime start, double durationMs)
 {
     StartTime = start.ToUniversalTime();
     EndTime   = StartTime.AddMilliseconds(durationMs);
     Duration  = ConvertTime(durationMs);
 }
コード例 #9
0
        public void ScheduleEffect()
        {
            switch (State)
            {
            case EffectState.Created:
            {
                State = EffectState.Acting;

                Template.Start(Caster, Owner, this);

                if (Duration == 0)
                {
                    Duration = Template.GetDuration();
                }
                if (StartTime == DateTime.MinValue)
                {
                    StartTime = DateTime.Now;
                    EndTime   = StartTime.AddMilliseconds(Duration);
                }

                Tick = Template.GetTick();

                if (Tick > 0)
                {
                    var time = GetTimeLeft();
                    if (time > 0)
                    {
                        _count = (int)(time / Tick + 0.5f + 1);
                    }
                    else
                    {
                        _count = -1;
                    }
                    EffectTaskManager.Instance.AddDispelTask(this, Tick);
                }
                else
                {
                    EffectTaskManager.Instance.AddDispelTask(this, GetTimeLeft());
                }

                return;
            }

            case EffectState.Acting:
            {
                if (_count == -1)
                {
                    if (Template.OnActionTime)
                    {
                        Template.TimeToTimeApply(Caster, Owner, this);
                        return;
                    }
                }
                else if (_count > 0)
                {
                    _count--;
                    if (Template.OnActionTime && _count > 0)
                    {
                        Template.TimeToTimeApply(Caster, Owner, this);
                        return;
                    }
                }

                State = EffectState.Finishing;
                break;
            }
            }

            if (State == EffectState.Finishing)
            {
                State = EffectState.Finished;
                InUse = false;
                StopEffectTask();
            }
        }
コード例 #10
0
 private void stream()
 {
     while (!done)
     {
         if (reader.BaseStream.Length - reader.BaseStream.Position >= 35)
         {
             while (reader.BaseStream.Position != reader.BaseStream.Length)
             {
                 Queue.Add(new Entry(TripTimeToDouble(reader.ReadByte()), PacketLossToDouble(reader.ReadSByte()), VoltageToDouble(reader.ReadUInt16()), RoboRioCPUToDouble(reader.ReadByte()), StatusFlagsToBooleanArray(reader.ReadByte()), CANUtilToDouble(reader.ReadByte()), WifidBToDouble(reader.ReadByte()), BandwidthToDouble(reader.ReadUInt16()), reader.ReadByte(), PDPValuesToArrayList(reader.ReadBytes(21)), reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), StartTime.AddMilliseconds(20 * i++)));
             }
         }
         Thread.Sleep(50);
     }
 }
コード例 #11
0
        protected override void readFile(string path)
        {
            if (File.Exists(path))
            {
                reader = new BinaryReader2(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));

                Version = reader.ReadInt32();
                if (Version == 3)
                {
                    StartTime = FromLVTime(reader.ReadInt64(), reader.ReadUInt64());
                    // int i = 0;
                    while (reader.BaseStream.Position != reader.BaseStream.Length)
                    {
                        Entries.Add(new Entry(TripTimeToDouble(reader.ReadByte()), PacketLossToDouble(reader.ReadSByte()), VoltageToDouble(reader.ReadUInt16()), RoboRioCPUToDouble(reader.ReadByte()), StatusFlagsToBooleanArray(reader.ReadByte()), CANUtilToDouble(reader.ReadByte()), WifidBToDouble(reader.ReadByte()), BandwidthToDouble(reader.ReadUInt16()), reader.ReadByte(), PDPValuesToArrayList(reader.ReadBytes(21)), reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), StartTime.AddMilliseconds(20 * i++)));
                    }
                    Thread t = new Thread(stream);
                    t.Start();
                }
            }
            else
            {
            }
        }