public static string GetHint(StateEnum state, int additional = 0) { if (hint[state.ToString()].ContainsKey(additional.ToString())) { return(hint[state.ToString()][additional.ToString()]); } else { return(hint[state.ToString()]["0"]); } }
static async void SendTruckTelemetryAsync(Random rand, CancellationToken token) { while (true) { UpdateTruck(); // Create the telemetry JSON message. var telemetryDataPoint = new { ContentsTemperature = Math.Round(tempContents, 2), TruckState = state.ToString(), CoolingSystemState = fan.ToString(), ContentsState = contents.ToString(), Location = new { lon = currentLon, lat = currentLat }, Event = eventText, }; var telemetryMessageString = JsonSerializer.Serialize(telemetryDataPoint); var telemetryMessage = new Message(Encoding.ASCII.GetBytes(telemetryMessageString)); // Clear the events, as the message has been sent. eventText = noEvent; Console.WriteLine($"\nTelemetry data: {telemetryMessageString}"); // Bail if requested. token.ThrowIfCancellationRequested(); // Send the telemetry message. await s_deviceClient.SendEventAsync(telemetryMessage); greenMessage($"Telemetry sent {DateTime.Now.ToShortTimeString()}"); await Task.Delay(intervalInMilliseconds); } }
/// <summary> /// All contents here are for debugging. /// </summary> void OnGUI() { GUI.color = Color.red; GUI.Label(new Rect(0, 0, 100, 50), state.ToString()); GUI.Label( new Rect(0, 50, 200, 50), string.Format("HP: {0}\nProgress: {1}\nJump CD: {2}, Fire CD: {3}", playerController.hp, progressToRecord, playerController.jumpCooldown, playerController.fireCooldown)); }
public InputForma(PropertyInterface myInterface, StateEnum state, string email, string ID) { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; userEmail = email; Id = ID; Text = myInterface.ToString().Remove(0, 36) + " " + state.ToString(); this.myInterface = myInterface; this.state = state; PopulateControls(); }
public void AddOrUpdateState(StateEnum state) { lock (_states) { var key = state.ToString(); if (!_states.ContainsKey(key)) { _states.Add(key, state); } else { _states[key] = state; } _parent?.AddOrUpdateState(state); } }
public void RemoveState(StateEnum stateName) { if (stateName == StateEnum.Null) { Debug.LogError("FSM ERROR: NullStateID is not allowed for a real state"); return; } if (!stateDic.ContainsKey(stateName)) { Debug.LogError("FSM ERROR: Impossible to delete state " + stateName.ToString() + ". It was not on the list of states"); } stateDic.Remove(stateName); }
public ProductStock ChangeStateProductStock(ProductStock productStock, int amount, StateEnum nextState) { if (amount > productStock.Amount) { var message = string.Format("value {0} exceds amount in stock", amount); throw new Exception(message); } if (nextState == productStock.State) { var message = string.Format("product has {0} state", nextState.ToString()); throw new Exception(message); } var nextProductStock = new ProductStock() { ProductId = productStock.ProductId, ProviderId = productStock.ProviderId, Amount = amount, State = nextState, Product = productStock.Product, Provider = productStock.Provider, }; var productStockBefore = ProductStockList.Where(p => p.ProductId == productStock.ProductStockId) .FirstOrDefault(); productStockBefore.Amount -= amount; Update(productStockBefore); ChangeState changeState = new ChangeState() { ProductStockId = productStock.ProductStockId, BeforeState = productStock.State, NextState = nextState, Amount = amount, }; _dataService.Insert <ChangeState>(changeState); nextProductStock.Code = GenerateCode(nextProductStock); return(Add(nextProductStock)); }
public void AddState(StateEnum stateName, FSMState state) { if (state == null) { Debug.LogError("FSM ERROR: Null reference is not allowed"); } if (stateDic.ContainsKey(stateName)) { Debug.LogError("FSM ERROR: Impossible to add state " + stateName.ToString() + " because state has already been added"); return; } if (stateDic.Count == 0) { currentState = state; currentStateEnum = stateName; currentState.OnEnterState(); } stateDic.Add(stateName, state); }
public void SetState(StateEnum state) { switch (state) { case StateEnum.SoldOut: StateController = SoldOutState; break; case StateEnum.NoQuarter: StateController = NoQuarterState; break; case StateEnum.HasQuarter: StateController = HasQuarterState; break; case StateEnum.Sold: StateController = SoldState; break; default: throw new InvalidStateException(state.ToString()); } }
public void ChangeState(TransitionEnum trans) { if (trans == TransitionEnum.Null) { Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition"); return; } StateEnum nextState = currentState.GetOutputState(trans); if (nextState == StateEnum.Null) { Debug.LogError("FSM ERROR: State " + currentStateEnum.ToString() + " does not have a target state " + " for transition " + trans.ToString()); return; } currentStateEnum = nextState; if (!stateDic.ContainsKey(nextState)) { Debug.LogError("FSM ERROR: State " + currentStateEnum.ToString() + " does not have a target state " + " for transition " + trans.ToString()); return; } currentState.OnLeaveState(); //Debug.LogError("上一个状态已经离开 " + currentState.StateName.ToString()); currentState = stateDic[nextState]; //Debug.LogError("下一个状态即将进入 " + currentState.StateName.ToString()); currentState.OnEnterState(); }
public ResponseJson(StateEnum State, string Message, object Data) { this.State = State.ToString(); this.Message = Message; this.Data = Data; }
public static string ToTitle(this StateEnum value) { var title = value.GetType().GetMember(value.ToString()).First().GetCustomAttribute<DisplayAttribute>().Name; return title; }
/// <summary> /// Changes the state of the Client State Machine. /// Intended to be PROTECTED - only the Client States should be able to call this from their encapsulated transition methods. /// Changes the internal state of the Client State Machine based on the given state type Enum. /// </summary> /// <param name="stateType">The new state type to be changed to.</param> /// <param name="optionalData">Optional data to be passed to the transitioning state.</param> public void ChangeState(StateEnum stateType, object optionalData = null) { if (currentState != null) { // Only time when the current state will be null is when the client starts. currentState.Exit(); currentState.enabled = false; } try { switch (stateType) { case StateEnum.Intermission: currentState = GetComponent <ClientIntermissionState>(); break; case StateEnum.Race: currentState = GetComponent <ClientRaceState>(); break; case StateEnum.ClientSpectate: currentState = GetComponent <ClientSpectateState>(); break; case StateEnum.ClientStartMenu: currentState = GetComponent <ClientStartMenuState>(); break; case StateEnum.ClientDeath: currentState = GetComponent <ClientDeathState>(); break; default: throw new InvalidOperationException("Invalid Client ChangeState attempt: " + stateType.ToString()); } SentrySdk.AddBreadcrumb($"Client State Machine for { LocalPlayer?.PlayerName } changed state from { StateType } to { stateType }."); StateType = stateType; } catch (InvalidOperationException e) { Debug.LogError(e); } currentState.enabled = true; currentState.Enter(optionalData); }
public string toString() { return(state.ToString()); }
public ResponseJson(StateEnum State, string Message) { this.State = State.ToString(); this.Message = Message; this.Data = "[]"; }
private static MovieData Parse(IHtmlDocument doc) { MovieData movie = new MovieData(); StateEnum state = StateEnum.ID; try { IElement element = doc.QuerySelector("head > meta[property=og\\3A url]"); movie.ID = int.Parse(new DirectoryInfo(element .GetAttribute("content")).Name); state = StateEnum.Poster; movie.PosterLink = doc.QuerySelector("head > link[rel=image_src]") .GetAttribute("href"); state = StateEnum.Localized; element = doc.QuerySelector("div#viewFilmInfoWrapper"); movie.LocalizedTitle = WebUtility.HtmlDecode( element.QuerySelector("h1.moviename-big > span").InnerHtml); state = StateEnum.Original; movie.OriginalTitle = Regex.Replace (WebUtility.HtmlDecode(element.QuerySelector("span.alternativeHeadline").InnerHtml), "\\([Вв]идео\\)|\\(ТВ\\)|в\\s3D", ""); state = StateEnum.Year; element = element.QuerySelector("table.info"); var elements = element .QuerySelectorAll("tr"); movie.Year = short.Parse(elements[0] .QuerySelector("a") .InnerHtml); state = StateEnum.Country; movie.Countries = elements[1] .QuerySelectorAll("a") ?.Select(a => new CountryData(WebUtility.HtmlDecode(a.InnerHtml))) .ToList() ?? new List <CountryData>(); state = StateEnum.TagLine; movie.TagLine = WebUtility.HtmlDecode(elements[2] .Children[1] .InnerHtml); state = StateEnum.Director; movie.Directors = elements[3] .QuerySelectorAll("a") ?.Where(a => !a.InnerHtml.Equals("...")) .Select(a => new PersonData(ConvertToPair(a))) .ToList() ?? new List <PersonData>(); state = StateEnum.Screenwriter; movie.Screenwriters = elements[4] .QuerySelectorAll("a") ?.Where(a => !a.InnerHtml.Equals("...")) .Select(a => new PersonData(ConvertToPair(a))) .ToList() ?? new List <PersonData>(); state = StateEnum.Genre; movie.Genres = element .QuerySelectorAll("span[itemprop=genre] > a") ?.Select(a => new GenreData(WebUtility.HtmlDecode(a.InnerHtml))) .ToList() ?? new List <GenreData>(); state = StateEnum.Runtime; if (!short.TryParse(element .QuerySelector("tr td.time") .InnerHtml .Split(' ')[0], out short runtime)) { runtime = 0; } movie.Runtime = runtime; state = StateEnum.Actor; movie.Actors = doc.QuerySelector("div#actorList > ul") .Children ?.Select(li => li.FirstElementChild) .Where(li => !li.InnerHtml.Equals("...")) .Select(li => new PersonData(ConvertToPair(li))) .ToList() ?? new List <PersonData>(); state = StateEnum.Storyline; movie.Storyline = WebUtility.HtmlDecode(doc.QuerySelector("div.film-synopsys") ?.InnerHtml ?? "-"); state = StateEnum.RatingKP; elements = doc.QuerySelectorAll("div.block_2 > div"); if (!float.TryParse(elements[0] .QuerySelector("span.rating_ball") ?.InnerHtml ?? "0", NumberStyles.Any, CultureInfo.InvariantCulture, out float rate)) { rate = 0; } movie.RatingKP = rate; state = StateEnum.RatingIMDB; if (!float.TryParse(elements[1] .InnerHtml .Split(' ')[1], NumberStyles.Any, CultureInfo.InvariantCulture, out rate)) { rate = 0; } movie.RatingIMDB = rate; return(movie); } catch (Exception) { throw new FormatException("Error occurred when parsing " + state.ToString()); } }
public void RemoveTransition(TransitionEnum trans) { if (trans == TransitionEnum.Null) { Debug.LogError("FSMState ERROR: NullTransition is not allowed"); return; } if (stateDic.ContainsKey(trans)) { stateDic.Remove(trans); } else { Debug.LogError("FSMState ERROR: Transition " + trans.ToString() + " passed to " + stateName.ToString() + " was not on the state's transition list"); } }
/** * \brief Stringify the enum * \return String that has the name of the enum */ public string ToString() { return(state_.ToString()); }