Example #1
1
        /// <summary>
        /// Start the service with the given name and wait until the status of the service is running.
        /// If the service status is not running after the given timeout then the service is considered not started.
        /// You can call this method after stop or pause the service in order to re-start it.
        /// </summary>
        /// <param name="serviceName">The name of the service</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>True if the service has been started. Otherwise, false.</returns>
        public static bool StartService(string serviceName, TimeSpan timeout)
        {
            try
            {
                bool timeoutEnabled = (timeout.CompareTo(TimeSpan.Zero) > 0);
                using (ServiceController c = new ServiceController(serviceName))
                {
                    c.Refresh();
                    if (timeoutEnabled && c.Status == ServiceControllerStatus.Running)
                        return true;
                    if (!timeoutEnabled && (c.Status == ServiceControllerStatus.Running || c.Status == ServiceControllerStatus.StartPending || c.Status == ServiceControllerStatus.ContinuePending))
                        return true;

                    if (c.Status == ServiceControllerStatus.Paused || c.Status == ServiceControllerStatus.ContinuePending)
                        c.Continue();
                    else if (c.Status == ServiceControllerStatus.Stopped || c.Status == ServiceControllerStatus.StartPending)
                        c.Start();
                    if (timeoutEnabled)
                        c.WaitForStatus(ServiceControllerStatus.Running, timeout);
                    return true;
                }
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error starting service {0}.", serviceName);
                return false;
            }
        }
Example #2
0
        public static byte EvaluateExpirationParameters(DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            if(Web.Caching.Cache.NoAbsoluteExpiration.Equals(absoluteExpiration) &&
                Web.Caching.Cache.NoSlidingExpiration.Equals(slidingExpiration))
            {
                return 2;
            }

            if(Web.Caching.Cache.NoAbsoluteExpiration.Equals(absoluteExpiration))
            {
                if(slidingExpiration.CompareTo(TimeSpan.Zero) < 0)
                    throw new ArgumentOutOfRangeException("slidingExpiration");

                if(slidingExpiration.CompareTo(DateTime.Now.AddYears(1) - DateTime.Now) >= 0)
                    throw new ArgumentOutOfRangeException("slidingExpiration");

                return 0;
            }

            if(Web.Caching.Cache.NoSlidingExpiration.Equals(slidingExpiration))
            {
                return 1;
            }

            throw new ArgumentException("You cannot set both sliding and absolute expirations on the same cache item.");
        }
 public static IQueryable<BOLichBieuKhongDinhKy> GetAllVisualRun(KaraokeEntities kara,BAN ban)
 {
     int? khuID = ban == null ? null : ban.KhuID;
     DateTime dtNow = DateTime.Now;
     DateTime dt = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day);
     TimeSpan ts = new TimeSpan(dt.Hour, dt.Minute, dt.Second);
     var querya = BOMenuLoaiGia.GetAllVisual(kara);
     var queryb = from b in GetAllVisual(kara)
                  where
                      ts.CompareTo(b.GioBatDau.Value) >= 0 && ts.CompareTo(b.GioKetThuc.Value) <= 0 &&
                      dt.CompareTo(b.NgayBatDau.Value) >= 0 && dt.CompareTo(b.NgayKetThuc.Value) <= 0 &&
                      (
                         b.KhuID == null ||
                         b.KhuID == khuID
                      )
                  select b;
     var query = from a in querya
                 join b in queryb on a.LoaiGiaID equals b.LoaiGiaID
                 select new BOLichBieuKhongDinhKy
                 {
                     MenuLoaiGia = a,
                     LichBieuKhongDinhKy = b
                 };
     return query.Distinct();
 }
		public void CompareToWorks() {
			var time1 = new TimeSpan(15, 10, 20, 5, 14);
			var time2 = new TimeSpan(14, 10, 20, 5, 14);
			var time3 = new TimeSpan(15, 11, 20, 5, 14);
			Assert.AreEqual(0, time1.CompareTo(time1));
			Assert.AreEqual(1, time1.CompareTo(time2));
			Assert.AreEqual(-1, time1.CompareTo(time3));
		}
 private static string GetVacationName(DateTime h)
 {
     TimeSpan t = new TimeSpan(h.Hour, h.Minute, h.Second);
     if (t.CompareTo(new TimeSpan(7, 30, 00)) >= 0 && t.CompareTo(new TimeSpan(19, 30, 00)) < 0) //t plus grand que 7h30  et t plus petit que 19h30 alors vac jour
     {
         return "Jour";
     }
     else
     {
         return "Nuit";
     }
 }
Example #6
0
        public static string PrettyDeltaTime(TimeSpan span, string rough = "")
        {
            int day = Convert.ToInt32(span.ToString("%d"));
              int hour = Convert.ToInt32(span.ToString("%h"));
              int minute = Convert.ToInt32(span.ToString("%m"));

              if (span.CompareTo(TimeSpan.Zero) == -1) {
            Log($"Time to sync the clock?{span}", ConsoleColor.Red);
            return "a few seconds";
              }

              if (day > 1) {
            if (hour == 0) return $"{day} days";
            return $"{day} days {hour}h";
              }

              if (day == 1) {
            if (hour == 0) return "1 day";
            return $"1 day {hour}h";
              }

              if (hour == 0) return $"{rough}{minute}m";
              if (minute == 0) return $"{rough}{hour}h";

              return $"{rough}{hour}h {minute}m";
        }
Example #7
0
 public static string OffsetToString(TimeSpan aTimeSpan)
 {
     string sign = aTimeSpan.CompareTo(TimeSpan.Zero) >= 0 ? "+" : "-";
     string hours = Math.Abs(aTimeSpan.Hours).ToString();
     string minutes = Math.Abs(aTimeSpan.Minutes).ToString("00");
     return sign + hours + ":" + minutes;
 }
Example #8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ticks"></param>
        /// <param name="isSliding"></param>
        /// <returns></returns>
        public static ExpirationHint MakeExpirationHint(long ticks, bool isAbsolute)
        {
            if (ticks == 0) return null;

            if (!isAbsolute)
            {
                TimeSpan slidingExpiration = new TimeSpan(ticks);
                if (slidingExpiration.CompareTo(TimeSpan.Zero) < 0)
                    throw new ArgumentOutOfRangeException("slidingExpiration");
                if (slidingExpiration.CompareTo(DateTime.Now.AddYears(1) - DateTime.Now) >= 0)
                    throw new ArgumentOutOfRangeException("slidingExpiration");
                return new IdleExpiration(slidingExpiration);
            }
            else
            {
                DateTime absoluteExpiration = new DateTime(ticks, DateTimeKind.Utc);
                return new FixedExpiration(absoluteExpiration);
            }
        }
        public static DateTime GetHeureLimiteVacation(string borne)
        {
            TimeSpan t = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            if (t.CompareTo(new TimeSpan(7, 30, 00)) >= 0 && t.CompareTo(new TimeSpan(19, 30, 00)) < 0) //Vac jour?
            {
                if (borne == "début")
                {
                    return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 30, 00);
                }
                else
                {
                    return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 19, 30, 00);
                }
            }
            else
            {

                if (t.CompareTo(new TimeSpan(23, 59, 59)) <= 0 && t.CompareTo(new TimeSpan(19, 30, 00)) >= 0) //S'il est avant ou égale à 23h59:59 --> alors on est le soir
                {
                    if (borne == "début")
                    {
                        return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 19, 30, 00);
                    }
                    else
                    {
                        return new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day, 7, 30, 00);
                    }
                }
                else
                {
                    if (borne == "début")
                    {
                        return new DateTime(DateTime.Now.AddDays(-1).Year, DateTime.Now.AddDays(-1).Month, DateTime.Now.AddDays(-1).Day, 19, 30, 00);
                    }
                    else
                    {
                        return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 30, 00);
                    }
                }

            }
        }
Example #10
0
 //TODO: Recurring
 public void CreateAlarm(string ID, DateTime dt, TimeSpan recurring)
 {
     Form1.updateLog("Creating timer for: " + dt.ToShortTimeString(), ELogLevel.Info,
         ELogType.AlarmClock);
     TimeSpan ts = dt - DateTime.Now;
     bool isRecurring = (recurring!=null && recurring.CompareTo(zero)!=0);
     Timer t = new Timer(new TimerCallback(Tick), ID, ts, recurring);
     lock(timers){
         timers.Add(ID, new Tuple<Timer, bool>(t, isRecurring));
     }
 }
Example #11
0
 public void update(GameTime time)
 {
     if (!stopped)
     {
         elapsed += time.ElapsedGameTime;
         if (elapsed.CompareTo(interval) >= 0)
         {
             fire();
             elapsed = new TimeSpan();
         }
     }
 }
 protected override void Update(GameTime gameTime)
 {
     frame += gameTime.ElapsedGameTime;
     if (frame.CompareTo(new  TimeSpan(0, 0, 0,0 ,30)) == 1)
     {
         Debug.Print(frame.TotalMilliseconds + "");
         frame = new TimeSpan();
         printFrame = true;
         StateManager.CurrentState.Update();
         base.Update(gameTime);
     }
 }
Example #13
0
        public void UpdateSprite(GameTime gameTime, GraphicsDeviceManager graphics)
        {
            if (!alive) return;
            // Move the sprite by speed, scaled by elapsed time.
            DateTime a = DateTime.Now;

            timeToLive=timeToLive.Subtract(gameTime.ElapsedGameTime);
            if (timeToLive.CompareTo(TimeSpan.Zero) < 0)
            {
                alive = false;
            }

            blend = (float)timeToLive.TotalMilliseconds / 500;
            scale = (1000-(float)timeToLive.TotalMilliseconds)/1000;
        }
Example #14
0
 public float 取平均值(float d, int t)
 {
     span = System.DateTime.Now - 基点时间;
     int 比较值 = span.CompareTo(比较时间戳);
     if (比较值 > 0)
     {
         基点时间 = System.DateTime.Now;
         平均值 = (d + 平均值) / 2;
         return 平均值;
     }
     else
     {
         平均值 = (d + 平均值) / 2;
         return -1;
     }
 }
        public void horarioComercial()
        {
            TimeSpan inicio = new TimeSpan(07, 50, 0);
            TimeSpan final = new TimeSpan(17, 10, 0);
            TimeSpan puts = DateTime.Now - DateTime.Now.Date;
            TimeSpan agora = new TimeSpan(puts.Hours, puts.Minutes, puts.Seconds);

            if (inicio.CompareTo(agora) == 1)
            {
                MessageBox.Show("O sistema funciona somente em horário comercial: 08:00h às 17:00h !", "Fora do horário comercial", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
            }
            if (final.CompareTo(agora) == -1)
            {
                MessageBox.Show("O sistema funciona somente em horário comercial: 08:00h às 17:00h !", "Fora do horário comercial", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
            }
        }
        /// <summary>
        /// Converts a TimeSpan into a SCORM 2004 Timespan string. 
        /// *** WARNING: This method exists in the SLS unit tests!! If you change this you must also change the 
        /// real code!!!*************
        /// </summary>
        /// <remarks>
        /// Returns a length of time in hours, minutes and seconds shown in the following 
        /// format: P[yY][mM][dD][T[hH][mM][s[.s]S]] with a precision of 0.01 seconds.
        /// 
        /// <para>
        /// XmlConvert.ToTimeSpan() will not work for converting SCORM 2004 values (which are also ISO 
        /// 8601 values) since XmlConvert uses an incorrect value for days per year and days per month.
        /// XmlConvert.ToString(TimeSpan) will produce a correct equivalent, however.</para>
        /// <para>
        /// 1 year ~ (365*4+1)/4*60*60*24*100 = 3155760000 centiseconds
        /// 1 month ~ (365*4+1)/48*60*60*24*100 = 262980000 centiseconds
        /// 1 day = 8640000 centiseconds
        /// 1 hour = 360000 centiseconds
        /// 1 minute = 6000 centiseconds
        /// </para>
        /// </remarks>
        private static string TimeSpanToStringScormV1p3(TimeSpan value)
        {
            bool hasTime = false;
            double num;
            double remainingCentiseconds = 0;

            // Oddly valid
            if (value.CompareTo(TimeSpan.Zero) == 0)
            {
                return "PT0H0M0S";
            }

            StringBuilder retTimeSpan = new StringBuilder(50);
            retTimeSpan.Append("P");

            remainingCentiseconds = value.Ticks / 100000;

            // If there is at least enough time for 1 year...
            if (remainingCentiseconds >= 3155760000)
            {
                num = (int)(remainingCentiseconds / 3155760000);
                retTimeSpan.AppendFormat("{0}Y", num.ToString(NumberFormatInfo.InvariantInfo));
                remainingCentiseconds -= (num * 3155760000);
            }

            // If there is at least enough time for 1 month...
            if (remainingCentiseconds >= 262980000)
            {
                num = (int)(remainingCentiseconds / 262980000);
                retTimeSpan.AppendFormat("{0}M", num.ToString(NumberFormatInfo.InvariantInfo));
                remainingCentiseconds = remainingCentiseconds - (num * 262980000);
            }

            // If there is at least enough time for 1 day...
            if (remainingCentiseconds >= 8640000)
            {
                num = (int)(remainingCentiseconds / 8640000);
                retTimeSpan.AppendFormat("{0}D", num.ToString(NumberFormatInfo.InvariantInfo));
                remainingCentiseconds -= num * 8640000;
            }

            // If there is at least enough time for 1 hour...
            if (remainingCentiseconds >= 360000)
            {
                hasTime = true;
                num = (int)(remainingCentiseconds / 360000);
                retTimeSpan.AppendFormat("T{0}H", num.ToString(NumberFormatInfo.InvariantInfo));
                remainingCentiseconds -= num * 360000;
            }

            // If there is at least enough time for 1 minute
            if (remainingCentiseconds >= 6000)
            {
                if (!hasTime)
                {
                    retTimeSpan.Append("T");
                    hasTime = true;
                }
                num = (int)(remainingCentiseconds / 6000);
                retTimeSpan.AppendFormat("{0}M", num.ToString(NumberFormatInfo.InvariantInfo));
                remainingCentiseconds -= num * 6000;
            }

            // If there is at least enough time for .01 second
            if (remainingCentiseconds > 0)
            {
                if (!hasTime)
                {
                    retTimeSpan.Append("T");
                    hasTime = true;
                }
                num = remainingCentiseconds / 100;
                retTimeSpan.AppendFormat("{0}S", num.ToString("#.##", NumberFormatInfo.InvariantInfo));
            }

            return retTimeSpan.ToString();
        }
Example #17
0
 /// <summary>Makes the iteration timespan from a string.
 /// </summary>
 /// <param name="iterationLength">dd.hhmmss</param>
 /// <returns></returns>
 internal static TimeSpan IterationTimeSpanFromString(string iterationLength)
 {
     int days = IterationDays(iterationLength);
     int hours = IterationHours(iterationLength);
     int minutes = IterationMinutes(iterationLength);
     int seconds = IterationSeconds(iterationLength);
     TimeSpan retVal = new TimeSpan(days, hours, minutes, seconds);
     // less than one second will default to one day
     if (retVal.CompareTo(new TimeSpan(0, 0, 1)) < 0)
     {
         return new TimeSpan(1, 0, 0, 0);
     }
     return retVal;
 }
Example #18
0
 public static void TestCompareTo_Invalid()
 {
     IComparable comparable = new TimeSpan(10000);
     Assert.Throws<ArgumentException>(null, () => comparable.CompareTo("10000")); // Obj is not a time span
 }
Example #19
0
    public static void TestCompareTo(TimeSpan timeSpan1, object obj, int expected)
    {
        if (obj is TimeSpan)
        {
            TimeSpan timeSpan2 = (TimeSpan)obj;
            Assert.Equal(expected, Math.Sign(timeSpan1.CompareTo(timeSpan2)));
            Assert.Equal(expected, Math.Sign(TimeSpan.Compare(timeSpan1, timeSpan2)));

            if (expected >= 0)
            {
                Assert.True(timeSpan1 >= timeSpan2);
                Assert.False(timeSpan1 < timeSpan2);
            }
            if (expected > 0)
            {
                Assert.True(timeSpan1 > timeSpan2);
                Assert.False(timeSpan1 <= timeSpan2);
            }
            if (expected <= 0)
            {
                Assert.True(timeSpan1 <= timeSpan2);
                Assert.False(timeSpan1 > timeSpan2);
            }
            if (expected < 0)
            {
                Assert.True(timeSpan1 < timeSpan2);
                Assert.False(timeSpan1 >= timeSpan2);
            }
        }
        IComparable comparable = timeSpan1;
        Assert.Equal(expected, Math.Sign(comparable.CompareTo(obj)));
    }
Example #20
0
        private void Popup()
        {
            try
            {
                if (InvokeRequired)
                {
                    BeginInvoke(new MethodInvoker(Popup));
                }
                else
                {
                    if (Context.User != null && Context.User.HasPopups)
                    {
                        DL.Internal.Popup.PopupObjectCollection popups = new BL.Internal.Popup().GetallActivePopupsByUser(Context.User);
                        TimeSpan time;
                        foreach (DL.Internal.Popup.PopupObject popup in popups)
                        {
                            //Show popup directly?
                            if (popup.ShowDirect == true)
                            {
                                Alert(popup);
                                popup.ShowDirect = false;
                                new BL.Internal.Popup().Save(popup);
                            }

                            time = new TimeSpan(int.Parse(popup.Time.Substring(0, 2)), int.Parse(popup.Time.Substring(2, 2)), int.Parse(popup.Time.Substring(4, 2)));
                            switch (popup.Repeation)
                            {
                                case Enumeration.Frequency.TimeFrequency.Daily:
                                    DateTime compTime = DateTime.Now;
                                    if (time.CompareTo(DateTime.Now.TimeOfDay.Add(new TimeSpan(0, 0, 15))) != time.CompareTo(DateTime.Now.TimeOfDay.Add(new TimeSpan(0, 0, -15))))
                                        Alert(popup);
                                    break;
                                case Enumeration.Frequency.TimeFrequency.Monthly:
                                    if (PROF_IT.Common.Convert.DateFunctions.DBDateToDate(popup.CreationDate, false).Day == DateTime.Now.Day
                                        && time.CompareTo(DateTime.Now.TimeOfDay.Add(new TimeSpan(0, 0, 15))) != time.CompareTo(DateTime.Now.TimeOfDay.Add(new TimeSpan(0, 0, -15))))
                                        Alert(popup);
                                    break;
                                case Enumeration.Frequency.TimeFrequency.Weekly:
                                    if (PROF_IT.Common.Convert.DateFunctions.DBDateToDate(popup.CreationDate, false).DayOfWeek == DateTime.Now.DayOfWeek
                                        && time.CompareTo(DateTime.Now.TimeOfDay.Add(new TimeSpan(0, 0, 15))) != time.CompareTo(DateTime.Now.TimeOfDay.Add(new TimeSpan(0, 0, -15))))
                                        Alert(popup);
                                    break;

                            }

                        }
                    }
                }
            }
            catch (System.Exception exception1)
            {
                //System.Exception innerException = exception1;
                //throw new System.Exception(MethodBase.GetCurrentMethod().Name, innerException);
            }
        }
        public override void Update(GameTime gameTime, Pantheon gameReference)
        {
            base.Update(gameTime, gameReference);

            if (!isRoaming)
            {
                switch (facing)
                {
                    case Direction.forward:
                        sprite.changeState(currentState + " Forward");
                        break;
                    case Direction.forwardLeft:
                        sprite.changeState(currentState + " Forward Left");
                        break;
                    case Direction.Left:
                        sprite.changeState(currentState + " Left");
                        break;
                    case Direction.backLeft:
                        sprite.changeState(currentState + " Back Left");
                        break;
                    case Direction.back:
                        sprite.changeState(currentState + " Back");
                        break;
                    case Direction.backRight:
                        sprite.changeState(currentState + " Back Right");
                        break;
                    case Direction.Right:
                        sprite.changeState(currentState + " Right");
                        break;
                    case Direction.forwardRight:
                        sprite.changeState(currentState + " Forward Right");
                        break;
                    default:
                        sprite.changeState(currentState + " Forward");
                        break;
                }
            }

            changeDirection = changeDirection.Subtract(gameTime.ElapsedGameTime);
            if (changeDirection.CompareTo(TimeSpan.Zero) <= 0)
            {
                if (isRoaming)
                {
                    switchDirection(gameReference);
                }
                changeDirection = TimeSpan.FromSeconds(gameReference.rand.Next(3) + 1);
            }

            ComfortZone = new Rectangle(BoundingBox.X - ComfortZone.Width / 2, BoundingBox.Y - ComfortZone.Height / 2,
                ComfortZone.Width, ComfortZone.Height);
        }
Example #22
0
 public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
 {
     currentSlideRuntime = currentSlideRuntime.Add(gameTime.ElapsedGameTime);
     if (currentSlideRuntime.CompareTo(SLIDE_LENGTH) > 0) nextSlide(true);
     currentTrans = currentTrans.Add(gameTime.ElapsedGameTime);
 }
 /// <summary>
 /// Check that the request's expire time is valid.
 /// Reject negative expiration times, except for the Infinite TimeSpan
 /// </summary>
 /// <param name="expire" />
 /// <returns>True if the expire time is valid</returns>
 public static bool IsValid(TimeSpan expire)
 {
     return (expire.Ticks >= 0) || (expire.CompareTo(Infinite) == 0);
 }
Example #24
0
 private bool IsNegative(TimeSpan timeSpan)
 {
     return timeSpan.CompareTo(TimeSpan.Zero) < 0;
 }
Example #25
0
 /// <summary>
 /// Updates the timer. If time has run out, exectue the delegate.
 /// If it's a periodic timer, reset for the next iteration.
 /// </summary>
 /// <param name="time">The GameTime object.</param>
 public virtual void update(GameTime time)
 {
     if (!stopped)
     {
         elapsed += time.ElapsedGameTime;
         if (elapsed.CompareTo(interval) >= 0)
         {
             execute();
             if (!periodic) stopped = true;
             elapsed = new TimeSpan();
         }
     }
 }
Example #26
0
        /// <summary>
        /// Méthode appelé par le système de jeu en boucle
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(GameTime gameTime)
        {
            keyboardInput.Update();

            if (keyboardInput.Exit)
            {
                this.Exit();
            }

            if (keyboardInput.ChangeColors())
            {
                ColorManager.ChangeColors();
            }

            // Si le joueur demande de l'aide
            bool AskHelping = IsKinectMode ? keyboardInput.Help() || kinectInput.Help() : keyboardInput.Help();

            #region Playing
            if (gamestate == GameStates.Running)
            {
                jeu.Help = AskHelping;
                jeu.Update();

                if (jeu.IsFinish)
                {
                    EndMenu.Description = jeu.getMessage();
                    EndMenu.StartDescription();
                    keyboardInput.IsHoldable = false;
                    gamestate = GameStates.EndMenu;
                }
                if (!IsKinectMode ? keyboardInput.Break() : kinectInput.Break())
                {
                    keyboardInput.IsHoldable = false;
                    gamestate = GameStates.PauseMenu;
                    PauseMenu.StartDescription();
                }
            }
            #endregion Playing
            #region ModeMenu
            else if (gamestate == GameStates.ModeMenu)
            {
                ModeMenu.Help = AskHelping;
                ModeMenu.Update();

                // Lors de la selection
                if (ModeMenu.Valid)
                {
                    gamestate = GameStates.PlayingMenu;
                    if (ModeMenu.Iterator == 0)
                    {
                        IsKinectMode = false;
                    }
                    else if (ModeMenu.Iterator == 1)
                    {
                        IsKinectMode = true;
                        kinectInput = new KinectInput(this);
                    }
                    else if (ModeMenu.Iterator == 2)
                    {
                        this.Exit();
                    }
                    SetMenus();
                    PlayingMenu.StartDescription();
                }
            }
            #endregion ModeMenu
            #region Menu Jouer
            else if (gamestate == GameStates.PlayingMenu)
            {
                PlayingMenu.Help = AskHelping;
                PlayingMenu.Update();
                // Lors de la selection
                if (PlayingMenu.Valid)
                {
                    gamestate = GameStates.DifficultyMenu;
                    DifficultyMenu.StartDescription();
                    if (PlayingMenu.Iterator == 0)
                    {
                        IsOnePlayer = true;
                    }
                    else if (PlayingMenu.Iterator == 1)
                    {
                        IsOnePlayer = false;
                    }
                }
                if (PlayingMenu.Back)
                {
                    gamestate = GameStates.ModeMenu;
                    ModeMenu.StartDescription();
                    IsKinectMode = false;
                }
            }
            #endregion Menu Jouer
            #region DifficultyMenu
            else if (gamestate == GameStates.DifficultyMenu)
            {
                DifficultyMenu.Help = AskHelping;
                DifficultyMenu.Update();

                // Lors de la selection
                if (DifficultyMenu.Valid)
                {
                    gamestate = GameStates.Running;
                    keyboardInput.IsHoldable = true;
                    if (DifficultyMenu.Iterator == 0)
                    {
                        Jouer(Difficulty.EASY);
                    }
                    else if (DifficultyMenu.Iterator == 1)
                    {
                        Jouer(Difficulty.MEDIUM);
                    }
                    else if (DifficultyMenu.Iterator == 2)
                    {
                        Jouer(Difficulty.HARD);
                    }
                }
                if (DifficultyMenu.Back)
                {
                    gamestate = GameStates.PlayingMenu;
                    PlayingMenu.StartDescription();
                }
            }
            #endregion DifficultyMenu
            #region PauseMenu
            else if (gamestate == GameStates.PauseMenu)
            {
                PauseMenu.Help = AskHelping;
                PauseMenu.Update();

                // Lors de la selection
                if (PauseMenu.Valid)
                {
                    if (PauseMenu.Iterator == 0)
                    {
                        keyboardInput.IsHoldable = true;
                        jeu.SetAfterBreak();
                        gamestate = GameStates.Running;
                    }
                    else if (PauseMenu.Iterator == 1)
                    {
                        gamestate = GameStates.PlayingMenu;
                        PlayingMenu.StartDescription();
                    }
                    else if (PauseMenu.Iterator == 2)
                    {
                        this.Exit();
                    }
                }
                if (PauseMenu.Back)
                {
                    keyboardInput.IsHoldable = true;
                    jeu.SetAfterBreak();
                    gamestate = GameStates.Running;
                }
            }
            #endregion PauseMenu
            #region EndMenu
            else if (gamestate == GameStates.EndMenu)
            {
                EndMenu.Help = AskHelping;
                EndMenu.Update();

                // Lors de la selection
                if (EndMenu.Valid)
                {
                    if (EndMenu.Iterator == 0)
                    {
                        gamestate = GameStates.PlayingMenu;
                        PlayingMenu.StartDescription();
                    }
                    else if (EndMenu.Iterator == 1)
                    {
                        this.Exit();
                    }
                }
            }
            #endregion EndMenu
            #region SplashCreen
            else if (gamestate == GameStates.SplashScreen)
            {
                splashScreenTimer -= gameTime.ElapsedGameTime;
                if (splashScreenTimer.CompareTo(new TimeSpan(0)) <= 0)
                {
                    gamestate = GameStates.ModeMenu;
                    ModeMenu.StartDescription();
                }
            }
            #endregion SplashCreen

            base.Update(gameTime);
        }
Example #27
0
      public static WaitReturn WaitForComplete(double mill, WaitHandle completeHandle, WaitHandle resetTimeoutHandle)
      {
         TimeSpan goal = new TimeSpan(DateTime.Now.AddMilliseconds(mill).Ticks);
         MSG msg = new MSG();
         HandleRef h = new HandleRef(null, IntPtr.Zero);
         
         WaitHandle []waitHandles = new WaitHandle[2]{resetTimeoutHandle, completeHandle};

         do
         {
            if(PeekMessage(out msg, h, 0, 0, PM_REMOVE))
            {
                  TranslateMessage(ref msg);
                  DispatchMessage(ref msg);
            }
            
            int index = WaitHandle.WaitAny(waitHandles, new TimeSpan(1), false);
            
            if (index == WaitHandle.WaitTimeout)
            {
               if (goal.CompareTo(new TimeSpan(DateTime.Now.Ticks)) < 0)
               {
                  return WaitReturn.Timeout;
               }
            }
            
            else
            {
               Debug.Assert(index == 0 || index == 1);
               AutoResetEvent autoEvent = waitHandles[index] as AutoResetEvent;
               if (autoEvent == completeHandle)
               {
                  return WaitReturn.Complete;
               }
               else if (autoEvent == resetTimeoutHandle)
               {
                  Console.WriteLine("Reset Timer");
                  goal = new TimeSpan(DateTime.Now.AddMilliseconds(mill).Ticks);
               }
            }



         } while(true);
      }
 public bool CheckIntervalPreceedings()
 {
     switch (drpPeriod.SelectedIndex)
     {
         case 0: // Minute
         case 1: // Hour
             TimeSpan start = new TimeSpan(Convert.ToInt32(txtFromHours.Text), Convert.ToInt32(txtFromMinutes.Text), 0);
             TimeSpan end = new TimeSpan(Convert.ToInt32(txtToHours.Text), Convert.ToInt32(txtToMinutes.Text), 0); ;
             return (start.CompareTo(end) < 0);
         default: return true;
     }
 }
Example #29
0
      public static WaitReturn WaitForComplete(double mill, WaitHandle wh)
      {
         TimeSpan goal = new TimeSpan(DateTime.Now.AddMilliseconds(mill).Ticks);
         MSG msg = new MSG();
         HandleRef h = new HandleRef(null, IntPtr.Zero);

         do
         {
            if(PeekMessage(out msg, h, 0, 0, PM_REMOVE))
            {
                  TranslateMessage(ref msg);
                  DispatchMessage(ref msg);
               }

            if(wh.WaitOne(new TimeSpan(1), false))
            {
               return WaitReturn.Complete;
            }

            if(goal.CompareTo(new TimeSpan(DateTime.Now.Ticks)) < 0)
            {
               return WaitReturn.Timeout;
            }

         } while(true);
      }
 static TimeSpan GetDueTime(TimeSpan timeSpan)
 {
     return timeSpan.CompareTo(TimeSpan.Zero) <= 0 ? timeSpan.Negate() : timeSpan;
 }