public override void OnActionExecuting(HttpActionContext actionContext) { var key = string.Concat(Name, "-", c.HttpContext.Request.UserHostAddress); var allowExecute = false; if (HttpRuntime.Cache[key] == null) { HttpRuntime.Cache.Add(key, true, // is this the smallest data we can have? null, // no dependencies DateTime.Now.AddSeconds(Seconds), // absolute expiration Cache.NoSlidingExpiration, CacheItemPriority.Low, null); // no callback allowExecute = true; } if (!allowExecute) { if (string.IsNullOrEmpty(Message)) { Message = "You may only perform this action every {n} seconds."; } actionContext.Response = actionContext.Request.CreateResponse( HttpStatusCode.Conflict, Message.Replace("{n}", Seconds.ToString()) ); } }
public string ToString(string format, IFormatProvider formatProvider) { //Lyyymmssdddd int indexOfL = format.IndexOf("L", 0, format.Length); string yToReplace = GetStringToReplace(format, "d"); string mToReplace = GetStringToReplace(format, "m"); string sToReplace = GetStringToReplace(format, "s"); string output = format.Replace("L", Str); if (yToReplace != string.Empty) { output = output.Replace(yToReplace, Degrees.ToString()); } if (mToReplace != string.Empty) { output = output.Replace(mToReplace, Minutes.ToString()); } if (sToReplace != string.Empty) { output = output.Replace(sToReplace, Seconds.ToString()); } return(output); //throw new NotImplementedException(); }
public override void OnActionExecuting(ActionExecutingContext c) { var key = VaryByIp ? string.Concat(Name, "-", c.HttpContext.Request.HttpContext.Connection.RemoteIpAddress) : Name; if (!Cache.TryGetValue(key, out bool entry)) { var cacheEntryOptions = new MemoryCacheEntryOptions() .SetAbsoluteExpiration(TimeSpan.FromSeconds(Seconds)); Cache.Set(key, true, cacheEntryOptions); } else { if (string.IsNullOrEmpty(Message)) { Message = "You may only perform this action every {n} seconds."; } c.Result = new ContentResult { Content = Message.Replace("{n}", Seconds.ToString()) }; c.HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict; } }
public IEnumerator ClocksTicking() { do { timeElapsed += Time.deltaTime; TimePassed = Mathf.Clamp01((totalTime - timeElapsed) / totalTime); Timer.fillAmount = TimePassed; Minutes = Mathf.Clamp(Mathf.FloorToInt((totalTime - timeElapsed) / 60f), 0, Mathf.Infinity); Seconds = Mathf.Clamp(Mathf.FloorToInt((totalTime - timeElapsed) % 60f), 0, Mathf.Infinity); MinutesText.text = Minutes.ToString(); SecondsText.text = Seconds.ToString(); if (Minutes < 10) { MinutesText.text = "0" + Minutes.ToString(); } if (Seconds < 10) { SecondsText.text = "0" + Seconds.ToString(); } yield return(null); }while (Timer.fillAmount > 0); if (Faild != null) { Faild(); } }
public override void OnActionExecuting(ActionExecutingContext actionContext) { var key = string.Concat(Name, "-", actionContext.HttpContext.Request.GetIp()); var allowExecute = false; if (ContextBase.CacheRead(key) == null) { ContextBase.CacheInsertWithSeconds(key, true, Seconds); allowExecute = true; } if (allowExecute) { return; } if (!Message.HasValue()) { Message = "You may only perform this action every {n} seconds."; } actionContext.Result = new ContentResult { Content = Message.Replace("{n}", Seconds.ToString(CultureInfo.InvariantCulture)) }; // see 429 - Rate Limit Exceeded HTTP error actionContext.HttpContext.Response.StatusCode = 429; }
public override void OnActionExecuting(ActionExecutingContext c) { //TODO: some one can abuse this by blocking access to some one else by changing RemoteIpAddress header frequently // TODO: change on doing work first principle, before asking for some action client first need to encrypt some random phrase or get token for action var key = string.Concat(Name, "-", c.HttpContext.Request.HttpContext.Connection.RemoteIpAddress); if (!Cache.TryGetValue(key, out bool entry)) { var cacheEntryOptions = new MemoryCacheEntryOptions() .SetAbsoluteExpiration(TimeSpan.FromSeconds(Seconds)); Cache.Set(key, true, cacheEntryOptions); } else { if (string.IsNullOrEmpty(Message)) { Message = "You may only perform this action every {n} seconds."; } c.Result = new ContentResult { Content = Message.Replace("{n}", Seconds.ToString()) }; c.HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict; } }
private string GetShortString() { StringBuilder sb = new StringBuilder(); if (Hours > 0) { sb.Append(Hours.ToString() + ":"); } if (Minutes > 0) { if (sb.Length == 0) { sb.Append(Minutes.ToString() + ":"); } else { sb.Append(Minutes.ToString("00") + ":"); } } if (sb.Length == 0) { sb.Append(Seconds.ToString() + ","); } else { sb.Append(Seconds.ToString("00") + ","); } sb.Append(Miliseconds.ToString("000")); return(sb.ToString()); }
public override void OnLoad() { CanSave = true; MessageBox.Text = Message; //the minimum time span must be 1 if (Seconds == 0) { Seconds = 1; } SecondsBox.Text = Seconds.ToString(CultureInfo.InvariantCulture); //we need to check if the message and the number of seconds are setted correctly string errorString = CheckValidityMessage(); if (!errorString.Equals(string.Empty)) { textInvalid.Text = errorString; textInvalid.Visibility = Visibility.Visible; return; } errorString = CheckValiditySeconds(); if (!errorString.Equals(string.Empty)) { textInvalid.Text = errorString; } textInvalid.Visibility = CanSave ? Visibility.Collapsed : Visibility.Visible; }
public override void OnActionExecuting(ActionExecutingContext c) { var key = string.Concat(Name, "-", c.HttpContext.Request.UserHostAddress); var allowExecute = false; // var cache = HttpRuntime.Cache; var cache = c.HttpContext.Cache; if (cache[key] == null) { cache.Add(key, true, // is this the smallest data we can have? null, // no dependencies DateTime.Now.AddSeconds(Seconds), // absolute expiration Cache.NoSlidingExpiration, CacheItemPriority.Low, null); // no callback allowExecute = true; } if (!allowExecute) { if (String.IsNullOrEmpty(Message)) { Message = "You may only perform this action every {n} seconds."; } c.Result = new ContentResult { Content = Message.Replace("{n}", Seconds.ToString()) }; // see 409 - http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html c.HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict; } }
public void ShowTimer() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(Minutes.ToString()); if (Seconds >= 10) { stringBuilder.Append(":"); stringBuilder.Append(Seconds.ToString()); } else { stringBuilder.Append(":0"); stringBuilder.Append(Seconds.ToString()); } if (Milliseconds >= 100) { stringBuilder.Append(":"); stringBuilder.Append(Milliseconds.ToString()); } else if (Milliseconds >= 10) { stringBuilder.Append(":0"); stringBuilder.Append(Milliseconds.ToString()); } else { stringBuilder.Append(":00"); stringBuilder.Append(Milliseconds.ToString()); } Console.WriteLine(stringBuilder.ToString()); }
// Update is called once per frame void Update() { //SPAWN SpawnTime -= 1 + Time.deltaTime; if (SpawnTime <= 0) { for (int i = 0; i < Ghoslys.Length; i++) { Descarte = Random.Range(0, Ghoslys.Length); if (Ghoslys[Descarte] != null) { Ghoslys [Descarte].gameObject.SetActive(true); break; } } SpawnTime = Random.Range(DelayFrom, DelayTo); } //SCOREBAR ScoreBar.value = Score / MaxScore; //ComboBar ComboTime -= 1 * Time.deltaTime; if (ComboTime <= 0) { ComboTime = 0; } if (ComboTime >= 15) { ComboTime = 15; } ComboBar.value = ComboTime / ComboTimeEnd; //TIEMPO Seconds -= 1 * Time.deltaTime; if (Seconds < 0) { Minutes -= 1; Seconds = 59; } if (Minutes == 0 && Seconds == 0) { Debug.Log("Se acabo el tiempo!!"); } TimeText.text = Minutes.ToString("00") + ":" + Seconds.ToString("00"); //Creatures Counter CountCreatures.text = Creatures.ToString("D"); }
protected override void DrawSelf(SpriteBatch spriteBatch) { base.DrawSelf(spriteBatch); if (Ability != null) { CalculatedStyle dims = base.GetDimensions(); Effect effect = DoTariaMod.Instance.GetEffect("Effects/ProgressBar"); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, effect, Main.UIScaleMatrix); effect.Parameters["uSourceRect"].SetValue(new Vector4(0, 0, 34, 34)); effect.Parameters["uImageSize0"].SetValue(new Vector2(34, 34)); effect.Parameters["uRotation"].SetValue(3f); effect.Parameters["uDirection"].SetValue(-1f); effect.Parameters["uSaturation"].SetValue(Percent); effect.CurrentTechnique.Passes[0].Apply(); spriteBatch.Draw(_cooldownTexture, dims.Position(), new Rectangle(0, 0, 32, 32), Color.White * 0.85f, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Main.UIScaleMatrix); if (Seconds > 0.0f) { Utils.DrawBorderString(spriteBatch, Seconds.ToString(), dims.Position() + new Vector2(12, 7) - new Vector2(2 * (Seconds.ToString().Length - 1), 0), Color.White, 1); } Texture2D unleveled = DoTariaMod.Instance.GetTexture("UserInterfaces/Abilities/AbilityUnlevel"), leveled = DoTariaMod.Instance.GetTexture("UserInterfaces/Abilities/AbilityLevel"); float spacing = 0; if (Ability.MaxLevel != 0) { spacing = 32 / Ability.MaxLevel; } if (Ability.MaxLevel > 0) { for (int i = 0; i < Ability.MaxLevel; i++) { spriteBatch.Draw(unleveled, dims.Position() + new Vector2(spacing * 0.5f + spacing * i, 34 + 4), null, Color.White, 0f, Vector2.Zero, 1.5f, SpriteEffects.None, 1f); } for (int i = 0; i < CurrentLevel; i++) { spriteBatch.Draw(leveled, dims.Position() + new Vector2(spacing * 0.5f + spacing * i, 34 + 4), null, Color.White, 0f, Vector2.Zero, 1.5f, SpriteEffects.None, 1f); } } if (IsMouseHovering) { DrawDescription(spriteBatch, Ability); } } }
public override void OnLoad() { HoursBox.Text = Hours.ToString(CultureInfo.InvariantCulture); MinutesBox.Text = Minutes.ToString(CultureInfo.InvariantCulture); SecondsBox.Text = Seconds.ToString(CultureInfo.InvariantCulture); shouldCheckValidity = true; }
protected void Timer1_Tick(object sender, EventArgs e) { if (Started) { Seconds++; time.Text = Seconds.ToString(); } }
/// <summary>Returns the string representation of the value of this instance.</summary> /// <param name="format">Format string using the usual characters to interpret custom datetime - as per standard Timespan custom formats</param> /// <returns>A string that represents the value of this instance.</returns> public String ToString(String format, IFormatProvider provider) { //parse and replace the format stuff MatchCollection matches = Regex.Matches(format, "([a-zA-z])\\1{0,}"); for (int i = matches.Count - 1; i >= 0; i--) { Match m = matches[i]; Int32 mIndex = m.Index, mLength = m.Length; if (mIndex > 0 && format[m.Index - 1] == '\\') { if (m.Length == 1) { continue; } else { mIndex++; mLength--; } } switch (m.Value[0]) { case 'y': format = format.Substring(0, mIndex) + Years.ToString("D" + mLength) + format.Substring(mIndex + mLength); break; case 'd': format = format.Substring(0, mIndex) + Days.ToString("D" + mLength) + format.Substring(mIndex + mLength); break; case 'h': format = format.Substring(0, mIndex) + Hours.ToString("D" + mLength.Clamp(1, KSPDateStructure.HoursPerDay.ToString().Length)) + format.Substring(mIndex + mLength); break; case 'm': format = format.Substring(0, mIndex) + Minutes.ToString("D" + mLength.Clamp(1, KSPDateStructure.MinutesPerHour.ToString().Length)) + format.Substring(mIndex + mLength); break; case 's': format = format.Substring(0, mIndex) + Seconds.ToString("D" + mLength.Clamp(1, KSPDateStructure.SecondsPerMinute.ToString().Length)) + format.Substring(mIndex + mLength); break; default: break; } } //Now strip out the \ , but not multiple \\ format = Regex.Replace(format, "\\\\(?=[a-z])", ""); return(format); //if (KSPDateStructure.CalendarType == CalendarTypeEnum.Earth) // return String.Format(format, _EarthDateTime); //else // return String.Format(format, this); //"TEST"; }
public string CombineTime() { var alertTime = new StringBuilder(); alertTime.Append(Hours.ToString().PadLeft(2, '0') + ":"); alertTime.Append(Minutes.ToString().PadLeft(2, '0') + ":"); alertTime.Append(Seconds.ToString().PadLeft(2, '0')); return(alertTime.ToString()); }
void start_Tick(object sender, EventArgs e) { if ((player1.win == VSmaxwins || player2.win == VSmaxwins) && VSmaxwins != 0) { Seconds = -2; if (player1.win == VSmaxwins) { countdownText.Text = "Red won\nthe game!"; } else { countdownText.Text = "Blue won\nthe game!"; } //player2.win = player1.win = 0; //return; } if (Seconds > 0) { countdownText.Text = "" + Seconds.ToString(); } switch (Seconds) { case 0: { countdownText.Text = "Start!"; leftScore.Text = rightScore.Text = "0"; leftScore.Visibility = rightScore.Visibility = Visibility.Visible; break; } case -1: { //centerborder.Visibility = Visibility.Visible; countdownText.Text = ""; //countdownText.Visibility = Visibility.Hidden;//.Text = ""; leftborder.Visibility = rightborder.Visibility = Visibility.Visible; var timer = (DispatcherTimer)sender; timer.Stop(); VStimer.Start(); ball.setpos(0, 0); ballvelocity = randomvelocity(_const.minvelocity, _const.maxvelocity); break; } case -4: { Menu menu = new Menu(); menu.VSmaxscore.Text = VSmaxscore.ToString(); menu.VSmaxwin.Text = VSmaxwins.ToString(); menu.Show(); Close(); break; } } Seconds--; }
public void Seconds_Arithmetic_zbrajanje_ReturnsTrue() { Seconds a = new Seconds(2.1); Seconds b = new Seconds(1.1); Seconds rjesenje = new Seconds(3.2); Seconds razlikaZbrajanja = a + b - rjesenje; Assert.IsTrue(razlikaZbrajanja.Angle < tolerance, razlikaZbrajanja.ToString()); }
/// <summary> /// String representation in seconds /// </summary> /// <returns> /// A <see cref="System.String"/> /// </returns> public string ToSecondsString(bool includeHour = false) { if (Hours > 0 || includeHour) { return(String.Format("{0}:{1}:{2}", Hours, Minutes.ToString("d2"), Seconds.ToString("d2"))); } return(String.Format("{0}:{1}", Minutes, Seconds.ToString("d2"))); }
public void Seconds_Arithmetic_oduzimanje2_ReturnsTrue() { Seconds a = new Seconds(1.3); Seconds b = new Seconds(2.1); Seconds rjesenje = new Seconds(-0.8); Seconds razlikaOduzimanja = a - b - rjesenje; Assert.IsTrue(razlikaOduzimanja.Angle < tolerance, razlikaOduzimanja.ToString()); }
public override string ToString() { StringBuilder builder = new StringBuilder(); if (Signum == -1) { builder.Append("-"); } builder.Append("P"); if (Years != 0) { builder.Append(Years.ToString()); builder.Append("Y"); } if (Months != 0) { builder.Append(Months.ToString()); builder.Append("M"); } if (Weeks != 0) { builder.Append(Weeks.ToString()); builder.Append("W"); } if (Days != 0 || (Years == 0 && Months == 0 && Weeks == 0 && Hours == 0 && Minutes == 0 && Seconds == 0 && FractionOfSecond == 0)) { builder.Append(Days.ToString()); builder.Append("D"); } if (!(Hours == 0 && Minutes == 0 && Seconds == 0 && FractionOfSecond == 0)) { builder.Append("T"); if (Hours != 0) { builder.Append(Hours.ToString()); builder.Append("H"); } if (Minutes != 0) { builder.Append(Minutes.ToString()); builder.Append("M"); } if (Seconds != 0 || FractionOfSecond != 0M) { builder.Append(Seconds.ToString()); if (FractionOfSecond != 0) { builder.Append(FractionOfSecond.ToString().Substring(1)); } builder.Append("S"); } } return(builder.ToString()); }
public override void OnActionExecuting(ActionExecutingContext c) { var key = string.Concat(Name, "-", c.HttpContext.Request.UserHostAddress); var allowExecute = false; var isInRole = false; //Checking whether the user is in one of the allowed roles if (c.HttpContext.User.Identity.IsAuthenticated) { if (ExceptForRoles != null) { foreach (var role in ExceptForRoles.Split(',')) { if (c.HttpContext.User.IsInRole(role)) { isInRole = true; break; } } } if (isInRole) { allowExecute = true; } } if (HttpRuntime.Cache[key] == null) { HttpRuntime.Cache.Add(key, true, // is this the smallest data we can have? null, // no dependencies DateTime.Now.AddSeconds(Seconds), // absolute expiration Cache.NoSlidingExpiration, CacheItemPriority.Low, null); // no callback allowExecute = true; } if (!allowExecute) { if (String.IsNullOrEmpty(Message)) { Message = "You may only perform this action every {n} seconds."; } // see 409 - http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html //c.HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict; // TODO: why is this not working? c.Result = new ContentResult { Content = Message.Replace("{n}", Seconds.ToString()) }; } }
public string ToString(string format) { format = format.Replace("YYYY", Years.ToString()); format = format.Replace("MM", Months.ToString()); format = format.Replace("DD", Days.ToString()); format = format.Replace("hh", Hours.ToString()); format = format.Replace("mm", Minutes.ToString()); format = format.Replace("ss", Seconds.ToString()); format = format.Replace("ms", Milliseconds.ToString()); return format; }
public void SaveGame() { if (Directory.Exists("C:\\NCCPlayers\\") == false) { try { Directory.CreateDirectory("C:\\NCCPlayers\\"); } catch (Exception) { MessageBox.Show("Couldn't create the required directory C:\\NCCPlayer\\. Games wont be saved!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } XmlDocument newDoc = new XmlDocument(); XmlElement newRoot = newDoc.CreateElement("Game"); XmlNode xmlE = newDoc.AppendChild(newRoot); XmlElement XPlayerName = newDoc.CreateElement("PlayerName"); XPlayerName.InnerText = PlayerName; xmlE.AppendChild(XPlayerName); XmlElement XEMail = newDoc.CreateElement("PlayerEMail"); XEMail.InnerText = PlayerEMail; xmlE.AppendChild(XEMail); XmlElement XLevel = newDoc.CreateElement("Level"); XLevel.InnerText = Level.ToString(); xmlE.AppendChild(XLevel); XmlElement XSeconds = newDoc.CreateElement("Seconds"); XSeconds.InnerText = Seconds.ToString(); xmlE.AppendChild(XSeconds); XmlElement X5050 = newDoc.CreateElement("FiftyFifty"); X5050.InnerText = FiftyFifty.ToString(); xmlE.AppendChild(X5050); XmlElement XBackdoor = newDoc.CreateElement("Backdoor"); XBackdoor.InnerText = FoneAFriend.ToString(); xmlE.AppendChild(XBackdoor); XmlElement XMoreTime = newDoc.CreateElement("MoreTime"); XMoreTime.InnerText = XMoreTime.ToString(); xmlE.AppendChild(XMoreTime); string strFile = "C:\\NCCPlayers\\" + GetTimestamp(DateTime.Now) + ".xml"; newDoc.Save(@strFile); }
private void GameTimer() { if (!(Minutes >= MaxMinutes)) { Minutes = (int)(Time.time / 60); Seconds = (int)(Time.time % 60); TextTimer.text = Minutes.ToString("00") + ":" + Seconds.ToString("00"); if (Minutes >= MaxMinutes) { Time.timeScale = 0f; } } }
public override string ToString() { var sb = new StringBuilder(); sb.Append(Hours.ToString("D2")); sb.Append(Minutes.ToString("D2")); sb.Append(Seconds.ToString("D2")); if (Utc) { sb.Append('Z'); } return(sb.ToString()); }
public override String ToString() { StringBuilder sb = new StringBuilder("P"); if (Years != 0) { sb.Append(Years.ToString()); sb.Append("Y"); } if (Months != 0) { sb.Append(Months.ToString()); sb.Append("M"); } if (Weeks != 0) { sb.Append(Weeks.ToString()); sb.Append("W"); } if (Days != 0) { sb.Append(Days.ToString()); sb.Append("D"); } if (Hours != 0 || Minutes != 0 || Seconds != 0 || Millis != 0) { sb.Append("T"); } if (Hours != 0) { sb.Append(Hours.ToString()); sb.Append("H"); } if (Minutes != 0) { sb.Append(Minutes.ToString()); sb.Append("M"); } if (Seconds != 0 || Millis != 0) { sb.Append(Seconds.ToString()); if (Millis != 0) { sb.Append("."); sb.Append(Millis.ToString("000")); } sb.Append("S"); } return(sb.ToString()); }
public override void OnLoad() { DeviceBox.Text = DeviceName; // The minimum timespan must be 5. if (Seconds < 5) { Seconds = 5; } SecondsBox.Text = Seconds.ToString(CultureInfo.InvariantCulture); CheckValidity(); }
public string ToString(string format, IFormatProvider formatProvider) { if (format == null) { return(ToString()); } if (char.IsNumber(format, format.Length - 1)) { string lastChar = format.Substring(format.Length - 1, 1); switch (format.Substring(0, format.Length - 1)) { case "D": return(String.Format(formatProvider, "{0}{1}°", (IsPositive ? '+' : '-'), AbsDegrees.ToString("F" + lastChar, formatProvider))); case "DM": return(String.Format(formatProvider, "{0}{1}°{2}\'", (IsPositive ? '+' : '-'), (int)AbsDegrees, DecimalMinutes.ToString("F" + lastChar, formatProvider))); case "DMS": return(String.Format(formatProvider, "{0}{1}°{2}\'{3}\"", (IsPositive ? '+' : '-'), (int)AbsDegrees, Minute, Seconds.ToString("F" + lastChar, formatProvider))); case "M": return(String.Format(formatProvider, "{0}\'", DecimalMinutes.ToString("F" + lastChar, formatProvider))); case "MS": return(String.Format(formatProvider, "{0}\'{1}\"", Minute, Seconds.ToString("F" + lastChar, formatProvider))); case "S": return(String.Format(formatProvider, "{0}\"", Seconds.ToString("F" + lastChar, formatProvider))); default: throw new FormatException("Format Exception of Angle.ToString(): " + format); } } else { if (format == "DMs") { return(String.Format(formatProvider, "{0}{1:D2}°{2:D2}\'{3,2:F0}\"", IsPositive ? '+' : '-', Hour, Minute, Seconds)); } else { return(ToString(format + "2", formatProvider)); } } }
/// <summary> /// Return string of format "mm:ss" /// </summary> /// <returns>new string</returns> public override string ToString() { if (DNF) { return(dnfDescription); } else if (Unknown) { return(unknownDescription); } else { return(Minutes.ToString() + separator + Seconds.ToString("00")); } }