public Model() { #if DEBUG // This is some test data to assist in the UI Designer Expecting.Add(new PmsAppointment() { ArrivalTime = "10:35am", PatientName = "Postlethwaite, Brian", PatientMobilePhone = "0423857505", ArrivalStatus = "Pending", AppointmentStartTime = "9:45am", PractitionerName = "Dr Nathan Pinskier" }); Expecting.Add(new PmsAppointment() { ArrivalTime = "10:35am", PatientName = "Esler, Brett", PatientMobilePhone = "0423083847", ArrivalStatus = "Pending", AppointmentStartTime = "10:00am", PractitionerName = "Dr Nathan Pinskier" }); Waiting.Add(new PmsAppointment() { ArrivalTime = "10:35am", PatientName = "Grieve, Grahame", PatientMobilePhone = "0423083847", ArrivalStatus = "Arrived", AppointmentStartTime = "10:00am", PractitionerName = "Dr Nathan Pinskier" }); RoomMappings.Add(new DoctorRoomLabelMappings() { PractitionerFhirID = "1", PractitionerName = "Dr Nathan", LocationName = "Room 1", LocationDescription = "Proceed through the main lobby and its the 3rd door on the right" }); #endif }
private void NormalTurnCardSelected(Card card) { if (expecting == Expecting.Card) { card.Select(); selectedCard = card; if (!playedCard && doubleDiscard) { expecting = Expecting.CardSlot; } else if (!playedCard && !playerDiscard) { expecting = Expecting.CardSlotOrDiscardPile; } else if (playedCard && !playerDiscard) { expecting = Expecting.DiscardPile; } else if (!playedCard && playerDiscard) { expecting = Expecting.CardSlotOrDiscardPile; } } else { selectedCard.Deselect(); card.Select(); selectedCard = card; } }
private ISingleOperator <TCandidate> CreateOperator <TSpecification>(Expecting expecting) where TSpecification : ISpecification <TCandidate>, new() { var candidateOperator = new SingleOperator(_candidate); candidateOperator.AddToGroup <TSpecification>(expecting); return(candidateOperator); }
private void CreateTestDataForDebug() { #if DEBUG // This is some test data to assist in the UI Designer Expecting.Add(new PmsAppointment() { PatientName = "Postlethwaite, Brian", PatientMobilePhone = "0423857505", ArrivalStatus = Hl7.Fhir.Model.Appointment.AppointmentStatus.Pending, AppointmentStartTime = DateTime.Parse("9:45am"), PractitionerName = "Dr Nathan Pinskier" }); Expecting.Add(new PmsAppointment() { PatientName = "Esler, Brett", PatientMobilePhone = "0423083847", ArrivalStatus = Hl7.Fhir.Model.Appointment.AppointmentStatus.Pending, AppointmentStartTime = DateTime.Parse("10:00am"), PractitionerName = "Dr Nathan Pinskier" }); Waiting.Add(new PmsAppointment() { PatientName = "Grieve, Grahame", PatientMobilePhone = "0423083847", ArrivalStatus = Hl7.Fhir.Model.Appointment.AppointmentStatus.Arrived, AppointmentStartTime = DateTime.Parse("10:00am"), PractitionerName = "Dr Nathan Pinskier" }); RoomMappings.Add(new DoctorRoomLabelMapping() { PractitionerFhirID = "1", PractitionerName = "Dr Nathan", LocationName = "Room 1", LocationDescription = "Proceed through the main lobby and its the 3rd door on the right" }); RoomMappings.Add(new DoctorRoomLabelMapping() { PractitionerFhirID = "1", PractitionerName = "Dr Smith", LocationName = "Room 2", LocationDescription = "Proceed through the main lobby and its the 2nd door on the right" }); #endif }
public void NoneSelected() { if (phase == Phase.RatingsPlayer) { if (expecting == Expecting.RatingConfirmation && selectedCard != null) { DeFocusCard(selectedCard); } } else if (phase == Phase.NormalTurns) { if ((expecting == Expecting.CardSlot || expecting == Expecting.DiscardPile || expecting == Expecting.CardSlotOrDiscardPile) && selectedCard != null) { selectedCard.Deselect(); selectedCard = null; expecting = Expecting.Card; } } }
private void NextRatingTurn() { if (turnPhase == TurnPhase.Wait1) { turnPhase = TurnPhase.Player1; expecting = Expecting.Card; ratingToGive = 10; UI.Instance.ClearUI(); UI.Instance.UpdateHeader(turnPhase, "Player 1: Rate items"); UI.Instance.UpdateInstructions("Which of these bring you the most joy?" + System.Environment.NewLine + "Which card is worth " + ratingToGive + "?"); } else if (turnPhase == TurnPhase.Player1) { turnPhase = TurnPhase.Wait2; expecting = Expecting.Continue; UI.Instance.ClearUI(); UI.Instance.UpdateHeader(turnPhase, "Pass turn to player 2"); UI.Instance.UpdateInstructions("Pass turn to player 2.", "Continue"); } else if (turnPhase == TurnPhase.Wait2) { turnPhase = TurnPhase.Player2; expecting = Expecting.Card; ratingToGive = 10; UI.Instance.ClearUI(); UI.Instance.UpdateHeader(turnPhase, "Player 2: Rate items"); UI.Instance.UpdateInstructions("Which of these bring you the most joy?" + System.Environment.NewLine + "Which card is worth " + ratingToGive + "?"); deck.Shuffle(); deck.Organize(); } else if (turnPhase == TurnPhase.Player2) { discardPile.gameObject.SetActive(true); player1Room.gameObject.SetActive(true); player2Room.gameObject.SetActive(true); commonRoom.gameObject.SetActive(true); // Load instructions for Player 1 turn 1 phase = Phase.NormalTurns; turnPhase = TurnPhase.Wait1; expecting = Expecting.Continue; turnNumber = 1; UI.Instance.ClearUI(); UI.Instance.UpdateHeader(turnPhase, "Pass turn to player 1"); UI.Instance.UpdateInstructions("Hand the device to player 1.", "Continue"); } cameraTransitions.TransitionCamera(turnPhase); }
/// <summary> /// Convert escape sequences /// </summary> private string ConvertEscapeSequences(string s) { Expecting expecting = Expecting.ANY; int hexNum = 0; string outs = ""; foreach (char c in s) { switch (expecting) { case Expecting.ANY: if (c == '\\') { expecting = Expecting.ESCAPED_CHAR; } else { outs += c; } break; case Expecting.ESCAPED_CHAR: if (c == 'x') { expecting = Expecting.HEX_1ST_DIGIT; } else { char c2 = c; switch (c) { case 'n': c2 = '\n'; break; case 'r': c2 = '\r'; break; case 't': c2 = '\t'; break; } outs += c2; expecting = Expecting.ANY; } break; case Expecting.HEX_1ST_DIGIT: hexNum = GetHexDigit(c) * 16; expecting = Expecting.HEX_2ND_DIGIT; break; case Expecting.HEX_2ND_DIGIT: hexNum += GetHexDigit(c); outs += (char)hexNum; expecting = Expecting.ANY; break; } } return(outs); }
private void DeFocusCard(Card card) { card.Return(true); card.Deselect(); selectedCard = null; expecting = Expecting.Card; UI.Instance.UpdateInstructions("Rate the rest of the cards from most to least favorite." + System.Environment.NewLine + "Which card is worth " + ratingToGive + "?"); }
public void DiscardPileSelected(Discard discard) { bool turnOK = (turnPhase == TurnPhase.Player1 || turnPhase == TurnPhase.Player2); bool expectingOK = (expecting == Expecting.DiscardPile || expecting == Expecting.CardSlotOrDiscardPile); if (phase == Phase.NormalTurns && turnOK && expectingOK && selectedCard != null) { selectedCard.PutIn(discard); selectedCard.ShowAllRatings(turnPhase); selectedCard = null; if (!playedCard && !playerDiscard) { playerDiscard = true; expecting = Expecting.Card; UI.Instance.UpdateInstructions("Play 1 card OR discard another cards to play 1 from the discard pile."); } else if (playedCard && !playerDiscard) { playerDiscard = true; InitNextTurn(); } else if (!playedCard && playerDiscard) { if (turnPhase == TurnPhase.Player1) { player1Hand.NotYourTurn(); discardPile.DealCards(player1DiscardHand); UI.Instance.UpdateInstructions("Play one card from the discard pile."); } else if (turnPhase == TurnPhase.Player2) { player2Hand.NotYourTurn(); discardPile.DealCards(player2DiscardHand); UI.Instance.UpdateInstructions("Play one card from the discard pile."); } doubleDiscard = true; expecting = Expecting.Card; } } }
public void Start() { if (focalPoint == null) { focalPoint = transform.Find("Focal point").transform; } if (cameraTransitions == null) { cameraTransitions = GameObject.Find("Camera mount").GetComponent <CameraTransitions>(); } if (sceneCamera == null) { sceneCamera = GameObject.Find("Camera mount/Main Camera").GetComponent <Camera>(); if (sceneCamera == null) { sceneCamera = GameObject.Find("Main Camera").GetComponent <Camera>(); } } deck.Initialize(); deck.Shuffle(); deck.Organize(); cardArray = deck.GetWholeDeck(); if (quickStart) { phase = Phase.RatingsPlayer; turnPhase = TurnPhase.Player2; InitNextTurn(); } else { phase = Phase.RatingsPlayer; expecting = Expecting.Card; turnNumber = 0; UI.Instance.ClearUI(); UI.Instance.ShowTutorial(); discardPile.gameObject.SetActive(false); player1Room.gameObject.SetActive(false); player2Room.gameObject.SetActive(false); commonRoom.gameObject.SetActive(false); } }
private void FocusCard(Card card) { focalPoint.position = sceneCamera.transform.position + sceneCamera.transform.forward * 3f; if (turnPhase == TurnPhase.Player1) { focalPoint.rotation = Quaternion.LookRotation(sceneCamera.transform.position - focalPoint.position, Vector3.forward); } else if (turnPhase == TurnPhase.Player2) { focalPoint.rotation = Quaternion.LookRotation(sceneCamera.transform.position - focalPoint.position, Vector3.back); } card.InitMove(focalPoint.position, focalPoint.rotation, 0.4f); card.Select(); selectedCard = card; expecting = Expecting.RatingConfirmation; UI.Instance.UpdateInstructions("Is this card worth " + ratingToGive + "?" + System.Environment.NewLine + "Click again to confirm!"); }
IEnumerator NewGame() { UI.Instance.ClearUI(); player1commonRoomCards = 0; player2commonRoomCards = 0; foreach (Card card in cardArray) { card.Enable(); card.ClearRatings(); card.PutIn(deck, true); yield return(new WaitForSeconds(0.1f)); } yield return(new WaitForSeconds(0.2f)); deck.Shuffle(); deck.Organize(); yield return(new WaitForSeconds(0.2f)); phase = Phase.RatingsPlayer; turnPhase = TurnPhase.Wait1; expecting = Expecting.Continue; UI.Instance.ClearUI(); UI.Instance.ShowTutorial(); turnNumber = 0; cameraTransitions.TransitionCamera(turnPhase); yield return(new WaitForSeconds(0.2f)); discardPile.gameObject.SetActive(false); player1Room.gameObject.SetActive(false); player2Room.gameObject.SetActive(false); commonRoom.gameObject.SetActive(false); }
private void NextRating() { if (ratingToGive > 1) { ratingToGive--; expecting = Expecting.Card; UI.Instance.UpdateInstructions("Rate the rest of the cards from most to least favorite." + System.Environment.NewLine + "Which card is worth " + ratingToGive + "?"); } else if (ratingToGive == 1) { ratingToGive = -1; expecting = Expecting.Card; UI.Instance.UpdateInstructions("Rate the rest of the cards from most to least favorite." + System.Environment.NewLine + "Which card is worth " + ratingToGive + "?"); } else if (ratingToGive > -10) { ratingToGive--; expecting = Expecting.Card; UI.Instance.UpdateInstructions("Rate the rest of the cards from most to least favorite." + System.Environment.NewLine + "Which card is worth " + ratingToGive + "?"); } else if (ratingToGive == -10) { InitNextTurn(); } else { Debug.LogError("We shouldn't end up here!"); } }
public override string ToString() { int unexpectedType = UnexpectedType; string unexpected = (TokenNames != null && unexpectedType >= 0 && unexpectedType < TokenNames.Count) ? TokenNames[unexpectedType] : unexpectedType.ToString(); string expected = (TokenNames != null && Expecting >= 0 && Expecting < TokenNames.Count) ? TokenNames[Expecting] : Expecting.ToString(); return("MismatchedTokenException(" + unexpected + "!=" + expected + ")"); }
private SpecificationValidatorDecorator(ISpecification <TCandidate> specification, Expecting expecting) { _specification = specification; _expecting = expecting; FailureType = FailureType.Error; }
private void NextNormalTurn() { if (turnPhase == TurnPhase.Wait1) { turnPhase = TurnPhase.Player1; expecting = Expecting.Card; if (turnNumber == 1) { deck.Shuffle(); deck.DealCards(6, player1Hand, turnPhase); } else if (turnNumber >= 2 && turnNumber <= 5) { deck.DealCards(1, player1Hand, turnPhase); } playedCard = false; playerDiscard = false; doubleDiscard = false; player1Hand.YourTurn(); player2Hand.NotYourTurn(); UI.Instance.ClearUI(); UI.Instance.UpdateHeader(turnPhase, "Player 1: turn " + turnNumber); UI.Instance.UpdateInstructions("Play 1 card and discard 1 card OR discard 2 cards and play 1 from the discard pile."); player1Hand.UpdateHandCardRatings(TurnPhase.Player1); } else if (turnPhase == TurnPhase.Player1) { turnPhase = TurnPhase.Wait2; expecting = Expecting.Continue; player1Hand.NotYourTurn(); UI.Instance.ClearUI(); UI.Instance.UpdateHeader(turnPhase, "Pass turn to player 2"); UI.Instance.UpdateInstructions("Hand the device to player 2.", "Continue"); } else if (turnPhase == TurnPhase.Wait2) { turnPhase = TurnPhase.Player2; expecting = Expecting.Card; if (turnNumber == 1) { deck.DealCards(6, player2Hand, turnPhase); } else if (turnNumber >= 2 && turnNumber <= 5) { deck.DealCards(1, player2Hand, turnPhase); } playedCard = false; playerDiscard = false; doubleDiscard = false; player2Hand.YourTurn(); player1Hand.NotYourTurn(); UI.Instance.ClearUI(); UI.Instance.UpdateHeader(turnPhase, "Player 2: turn " + turnNumber); UI.Instance.UpdateInstructions("Play 1 card and discard 1 card OR discard 2 cards and play 1 from the discard pile."); player2Hand.UpdateHandCardRatings(TurnPhase.Player2); } else if (turnPhase == TurnPhase.Player2) { if (turnNumber == 5) { phase = Phase.EndScreen; CountScores(); return; } turnPhase = TurnPhase.Wait1; expecting = Expecting.Continue; player2Hand.NotYourTurn(); turnNumber++; UI.Instance.ClearUI(); UI.Instance.UpdateHeader(turnPhase, "Pass turn to player 1"); UI.Instance.UpdateInstructions("Hand the device to player 1.", "Continue"); player2Hand.UpdateHandCardRatings(TurnPhase.Player2); } player1Room.AlignAllCards(turnPhase); player2Room.AlignAllCards(turnPhase); commonRoom.AlignAllCards(turnPhase); if (turnPhase == TurnPhase.Player1 || turnPhase == TurnPhase.Player2) { player1Room.ShowAllCardRatings(turnPhase); player2Room.ShowAllCardRatings(turnPhase); commonRoom.ShowAllCardRatings(turnPhase); discardPile.UpdateAllRatings(turnPhase); } cameraTransitions.TransitionCamera(turnPhase); }
public static void AddToGroup <TSpecification, TCandidate>(this List <ValidationGroup <TCandidate> > source, Expecting expecting) where TSpecification : ISpecification <TCandidate>, new() => source.Last().AddToGroup <TSpecification>(expecting);
public void CardSlotSelected(CardSlot slot) { bool turnOK = (turnPhase == TurnPhase.Player1 || turnPhase == TurnPhase.Player2); bool expectingOK = (expecting == Expecting.CardSlot || expecting == Expecting.CardSlotOrDiscardPile); bool player1 = (turnPhase == TurnPhase.Player1); bool player2 = (turnPhase == TurnPhase.Player2); bool player1Room = (player1 && slot.ParentRoom.Type == Room.RoomType.Player1); bool player2Room = (player2 && slot.ParentRoom.Type == Room.RoomType.Player2); bool commonroom = (slot.ParentRoom.Type == Room.RoomType.CommonRoom) && ((player1 && player1commonRoomCards < 3) || (player2 && player2commonRoomCards < 3)); bool roomOK = player1Room || player2Room || commonroom; if (phase == Phase.NormalTurns && turnOK && expectingOK && roomOK && slot.Free && selectedCard != null && !playedCard) { selectedCard.PutIn(slot, turnPhase); selectedCard.ShowAllRatings(turnPhase); selectedCard = null; if (commonroom && player1) { player1commonRoomCards++; } else if (commonroom && player2) { player2commonRoomCards++; } if (!playedCard && !playerDiscard) { playedCard = true; expecting = Expecting.Card; UI.Instance.UpdateInstructions("Now discard 1 card."); } else if (!playedCard && playerDiscard) { playedCard = true; InitNextTurn(); } if (doubleDiscard && player1) { player1DiscardHand.DiscardWholeHand(discardPile); } else if (doubleDiscard && player2) { player2DiscardHand.DiscardWholeHand(discardPile); } } }
/// <summary> /// An asynchroneous method for a WebSocket request processing /// </summary> /// <param name="listenerContext">Listener context</param> private async void ProcessWebSocketRequestAsync(HttpListenerContext listenerContext) { // Accepting WebSocket connection from the context WebSocketContext webSocketContext; try { webSocketContext = await listenerContext.AcceptWebSocketAsync(subProtocol : null); } catch (Exception e) { // The upgrade process failed somehow. For simplicity lets assume it was a failure on the part of the server and indicate this using 500. listenerContext.Response.StatusCode = 500; listenerContext.Response.Close(); Logger.LogError(String.Format("Exception: {0}", e)); return; } // This is our new WebSocket object WebSocket webSocket = webSocketContext.WebSocket; lock (socketsAndMessagesLock) { // Adding the new client to the list connectedSockets.Add(webSocket); // Sending all the previous messages to the new client Logger.Log("Sending " + cabinetController.Cards.Count + " old cards to the new client"); foreach (var oldCard in cabinetController.Cards) { // Making an add_card command for the selected card var addCommand = new Model.Commands.UpdateCardCommand(oldCard.Key, oldCard.Value); var addCommandGram = new TextWebSockGram(serializer.SerializeCommand(addCommand)); // Sending the command to the new client addCommandGram.Send(webSocket).Wait(); } } // We are expecting a command to be sent from the client Expecting expecting = Expecting.Command; // Here the received command will be held if we will be waiting for an appended binary data Model.Commands.Command receivedCommand = null; // The received WebSocket message collector WebSockGram receivedGram = null; // Communicating try { byte[] receiveBuffer = new byte[16384]; // While the WebSocket connection remains open run a simple loop that receives data and sends it back. while (webSocket.State == WebSocketState.Open) { WebSocketReceiveResult receiveResult = await webSocket.ReceiveAsync(new ArraySegment <byte>(receiveBuffer), CancellationToken.None); if (receiveResult.MessageType == WebSocketMessageType.Close) { // We've got a Close request. Sending it back await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); } else { // We have received a message. Text or binary. We are going to collect it to the WebSockGram object if (receivedGram == null) { // Start building of a new message receivedGram = WebSockGram.StartReceivingFromReceiveResult(receiveBuffer, receiveResult); } else { // Continue building of the message receivedGram.AppendFromReceiveResult(receiveBuffer, receiveResult); } // If the message has just ended, let's interpret it if (receivedGram.Completed) { // Logging the message if (receivedGram is TextWebSockGram) { Logger.Log("Received text: \"" + receivedGram.ToString() + "\""); } else if (receivedGram is BinaryWebSockGram) { Logger.Log("Received binary: " + receivedGram.Length + " bytes"); } else { throw new Exception("Invalid case"); } // Checking what we have received (depending on what we have been expecting) if (expecting == Expecting.Command) { // We are expecting a command. So receivedGram has to be a text if (receivedGram is TextWebSockGram) { var command = serializer.DeserializeCommand(receivedGram.ToString()); // Executing the received command if (command is Model.Commands.UpdateCardCommand) { var updateCardCommand = command as Model.Commands.UpdateCardCommand; lock (socketsAndMessagesLock) { // Giving the received message to the controller cabinetController.UpdateCard(updateCardCommand.Id, updateCardCommand.Value); // Broadcasting the message Logger.Log("Broadcasting the new card " + updateCardCommand.Value + " to the " + connectedSockets.Count + " connected clients"); receivedGram.Broadcast(connectedSockets).Wait(); } } else if (command is Model.Commands.UploadImageCardCommand) { // After this command a binary should be appended (containing the image data). // So we are saving the command itself... receivedCommand = command; // ...and setting the state machine to expect binary appended to the command. expecting = Expecting.AppendedBinary; } else if (command is Model.Commands.ListCardIDsCommand) { // Sending all the cards ids IList <string> ids = cabinetController.ListCardIDs(); Model.Commands.ListCardIDsCommand response = new Model.Commands.ListCardIDsCommand(ids); var ser = serializer.SerializeCommand(response); WebSockGram listids = new TextWebSockGram(ser); await listids.Send(webSocket); } } else { throw new Exception("We are expecting a command, but the received WebSocket message isn't a text"); } } else if (expecting == Expecting.AppendedBinary) { // We are expecting an appended binary if (receivedGram is BinaryWebSockGram) { // We've got an appended binary if (receivedCommand is Model.Commands.UploadImageCardCommand) { // Our current command is upload_image_card var uploadImageMessageCommand = receivedCommand as Model.Commands.UploadImageCardCommand; // Saving the received image byte[] imageData = (receivedGram as BinaryWebSockGram).Data.ToArray(); var savedImageFileName = imagesController.Add(uploadImageMessageCommand.Value.Filename, new MemoryStream(imageData)); lock (socketsAndMessagesLock) { // Setting up the link to the saved file. Adding it to the received Card data var imageFileCard = uploadImageMessageCommand.Value; imageFileCard.Link = new Uri(listenerContext.Request.Url, "data/" + savedImageFileName); // Creating a new card in the controller, containing the received image cabinetController.UpdateCard(uploadImageMessageCommand.Id, imageFileCard); // Broadcasting the add_card command to all the connected clients Logger.Log("Broadcasting the new image card " + imageFileCard.Link + " to the " + connectedSockets.Count + " connected clients"); var addCommand = new Model.Commands.UpdateCardCommand(uploadImageMessageCommand.Id, imageFileCard); TextWebSockGram addCardGram = new TextWebSockGram(serializer.SerializeCommand(addCommand)); addCardGram.Broadcast(connectedSockets).Wait(); } } else { throw new Exception("Strange case"); } } else { // Resetting the received command (we have a client error here) throw new Exception("We are expecting a binary appended to a command, but the received WebSocket message isn't a binary"); } // After we received the appended binary, resetting the state machine to expect a command again expecting = Expecting.Command; receivedCommand = null; } receivedGram = null; } } } } catch (Exception e) { // Just log any exceptions to the console. // Pretty much any exception that occurs when calling `SendAsync`/`ReceiveAsync`/`CloseAsync` // is unrecoverable in that it will abort the connection and leave the `WebSocket` instance in an unusable state. Logger.Log(String.Format("Exception: {0}", e)); } finally { // Disposing the WebSocket and removing it from the list try { // Clean up by disposing the WebSocket once it is closed/aborted. if (webSocket != null) { lock (socketsAndMessagesLock) { connectedSockets.Remove(webSocket); } webSocket.Dispose(); } } catch (Exception e) { Logger.Log(String.Format("Exception during WebSocket disposure: {0}", e)); } } }
internal void AddToGroup <TSpecification>(Expecting expecting) where TSpecification : ISpecification <TCandidate>, new() => _validationGroups.AddToGroup <TSpecification, TCandidate>(expecting);
internal static EnumerableOperator Create <TSpecification>(IEnumerable <TCandidate> candidates, Expecting expecting) where TSpecification : ISpecification <TCandidate>, new() { var enumerableOperator = new EnumerableOperator(candidates); enumerableOperator.AddToGroup <TSpecification>(expecting); return(enumerableOperator); }
public override string ToString() { //int unexpectedType = getUnexpectedType(); //string unexpected = ( tokenNames != null && unexpectedType >= 0 && unexpectedType < tokenNames.Length ) ? tokenNames[unexpectedType] : unexpectedType.ToString(); string expected = (TokenNames != null && Expecting >= 0 && Expecting < TokenNames.Count) ? TokenNames[Expecting] : Expecting.ToString(); string exp = ", expected " + expected; if (Expecting == TokenTypes.Invalid) { exp = ""; } if (Token == null) { return("UnwantedTokenException(found=" + null + exp + ")"); } return("UnwantedTokenException(found=" + Token.Text + exp + ")"); }
public static SpecificationValidatorDecorator <TCandidate> CreateWithSpecification <TSpecification>(Expecting expecting) where TSpecification : ISpecification <TCandidate>, new() => new SpecificationValidatorDecorator <TCandidate>(new TSpecification(), expecting);
public ExpectingTypeError(SourceLocation location, Expecting expecting) : base(location) { _expecting = expecting; }
public async Task Initialize(Dispatcher dispatcher) { // read the settings from storage Settings.CopyFrom(await Storage.LoadSettings()); if (Settings.SystemIdentifier == Guid.Empty) { // this only occurs when the system hasn't had one allocated // so we can create a new one, then save the settings. // (this will force an empty setting file with the System Identifier if needed) Settings.AllocateNewSystemIdentifier(); await Storage.SaveSettings(Settings); } // read the room mappings from storage RoomMappings.Clear(); foreach (var map in await Storage.LoadRoomMappings()) { RoomMappings.Add(map); } Templates.Clear(); foreach (var template in await Storage.LoadTemplates()) { Templates.Add(template); } AddMissingTemplates(); // reload any unmatched messages var messages = await Storage.LoadUnprocessableMessages(DisplayingDate); foreach (var item in messages) { UnprocessableMessages.Add(item); } PmsSimulator.Initialize(Storage); if (!IsSimulation) { FhirApptReader = new FhirAppointmentReader(FhirAppointmentReader.GetServerConnection); SmsProcessor.Initialize(Settings); } logger.Log(1, "Start up"); if (!String.IsNullOrEmpty(Settings.AdministratorPhone)) { logger.Log(1, "Send SMS to " + Settings.AdministratorPhone); try { SmsProcessor.SendMessage(new SmsMessage(Settings.AdministratorPhone, "System is starting")); if (!IsSimulation) { App.AdministratorPhone = Settings.AdministratorPhone; App.SmsSender = SmsProcessor; } } catch (Exception ex) { System.Windows.MessageBox.Show("Error sending message: " + ex.Message); } } // setup the background worker routines ReadSmsMessage = new BackgroundProcess(Settings, serverStatuses.IncomingSmsReader, dispatcher, async() => { // Logic to run on this process // (called every settings.interval) StatusBarMessage = $"Last read SMS messages at {DateTime.Now.ToLongTimeString()}"; var engine = PrepareMessagingEngine(); List <PmsAppointment> appts = new List <PmsAppointment>(); appts.AddRange(Appointments); var messagesReceived = await engine.SmsSender.ReceiveMessages(); serverStatuses.IncomingSmsReader.Use(messagesReceived.Count()); engine.ProcessIncomingMessages(appts, messagesReceived); }); ScanAppointments = new BackgroundProcess(Settings, serverStatuses.AppointmentScanner, dispatcher, async() => { // Logic to run on this process // (called every settings.interval) var engine = PrepareMessagingEngine(); List <PmsAppointment> appts = await FhirApptReader.SearchAppointments(this.DisplayingDate, RoomMappings, Storage); serverStatuses.Oridashi.Use(1); serverStatuses.AppointmentScanner.Use(engine.ProcessTodaysAppointments(appts)); // Now update the UI once we've processed it all Expecting.Clear(); Waiting.Clear(); Appointments.Clear(); foreach (var appt in appts) { Appointments.Add(appt); if (appt.ArrivalStatus == Hl7.Fhir.Model.Appointment.AppointmentStatus.Booked) { Expecting.Add(appt); } else if (appt.ArrivalStatus == Hl7.Fhir.Model.Appointment.AppointmentStatus.Arrived) { Waiting.Add(appt); } } }); ProcessUpcomingAppointments = new BackgroundProcess(Settings, serverStatuses.UpcomingAppointmentProcessor, dispatcher, async() => { // Logic to run on this process // (called every settings.intervalUpcoming) var engine = PrepareMessagingEngine(); List <PmsAppointment> appts = new List <PmsAppointment>(); appts.AddRange(await FhirApptReader.SearchAppointments(this.DisplayingDate.AddDays(1), RoomMappings, Storage)); appts.AddRange(await FhirApptReader.SearchAppointments(this.DisplayingDate.AddDays(2), RoomMappings, Storage)); serverStatuses.Oridashi.Use(1); serverStatuses.UpcomingAppointmentProcessor.Use(engine.ProcessUpcomingAppointments(appts)); }, true); }