protected override void OnLoad(EventArgs e) { base.OnLoad(e); //create workflow runtime and manager _workflowManager = new WorkflowRuntimeManager( new WorkflowRuntime()); //add the external data exchange service to the runtime ExternalDataExchangeService exchangeService = new ExternalDataExchangeService(); _workflowManager.WorkflowRuntime.AddService(exchangeService); //add our local service _gameService = new GuessingGameService(); exchangeService.AddService(_gameService); //subscribe to the service event that sends us messages _gameService.MessageReceived += new EventHandler <MessageReceivedEventArgs>( gameService_MessageReceived); //handle the terminated event _workflowManager.WorkflowRuntime.WorkflowTerminated += new EventHandler <WorkflowTerminatedEventArgs>( WorkflowRuntime_WorkflowTerminated); }
static void Main(string[] args) { System.ServiceModel.Activities.WorkflowServiceHost host = null; try { waitEvent = new AutoResetEvent(false); string baseAddr = "net.pipe://localhost/GuessingGame"; host = new System.ServiceModel.Activities.WorkflowServiceHost( new GuessingGame35Interop(), new Uri(baseAddr)); System.Workflow.Activities.ExternalDataExchangeService des = new System.Workflow.Activities.ExternalDataExchangeService(); ggService = new GuessingGameService(); ggService.MessageReceived += new EventHandler <MessageReceivedEventArgs>( Service_MessageReceived); des.AddService(ggService); WorkflowRuntimeEndpoint endpoint = new WorkflowRuntimeEndpoint(); endpoint.AddService(des); host.AddServiceEndpoint(endpoint); host.AddDefaultEndpoints(); ////configure persistence //string connectionString = ConfigurationManager.ConnectionStrings // ["InstanceStore"].ConnectionString; //SqlWorkflowInstanceStoreBehavior storeBehavior = // new SqlWorkflowInstanceStoreBehavior(connectionString); //host.Description.Behaviors.Add(storeBehavior); //WorkflowIdleBehavior idleBehavior = new WorkflowIdleBehavior(); //idleBehavior.TimeToUnload = TimeSpan.FromSeconds(0); //host.Description.Behaviors.Add(idleBehavior); host.Open(); IServiceStarter client = ChannelFactory <IServiceStarter> .CreateChannel( new NetNamedPipeBinding(), new EndpointAddress(baseAddr)); client.Start(); waitEvent.WaitOne(TimeSpan.FromMinutes(2)); Console.WriteLine("Program exiting..."); } catch (Exception exception) { Console.WriteLine("Unhandled exception: {0}", exception.Message); } finally { if (host != null) { host.Close(); } } }
public IActionResult GuessingGame() { if (HttpContext.Session.GetString("NumberToGuess") == null) { int numberToGuess = GuessingGameService.CreateRandomNumber(); HttpContext.Session.SetInt32("NumberToGuess", numberToGuess); } return(View()); }
internal void Start() { Trait livesInWater = new Trait("lives in water"); Node root = new Node(livesInWater, new Animal("monkey")); Node firstChildNode = new Node(null, new Animal("shark")); livesInWater.NodeForSpecializatedTrait = firstChildNode; IGuessingGameMessages questionMessageBox = new GuessingGameMessagesDialog(); GuessingGameService guessingGameService = new GuessingGameService(questionMessageBox); while (guessingGameService.startGame()) { guessingGameService.doQuestion(root); } }
public void WhenRegisterAnimal_NewNodeWithNewAnimalMustBeCreatedUnderFirstTrait() { Trait livesInWater = new Trait("lives in water"); Node root = new Node(livesInWater, new Animal("monkey")); Node firstChildNode = new Node(null, new Animal("shark")); livesInWater.NodeForSpecializatedTrait = firstChildNode; IGuessingGameMessages questionMessageBox = new GuessingGameMessagesFish(); GuessingGameService guessingGameService = new GuessingGameService(questionMessageBox); guessingGameService.doQuestion(root); Trait livesInAguaDoce = livesInWater.NodeForSpecializatedTrait.Traits[0]; Assert.AreEqual("fish", livesInAguaDoce.NodeForSpecializatedTrait.AnimalSuperiorTrait); }
public IActionResult GuessingGame(int guess) { int numberToGuess = Convert.ToInt32(HttpContext.Session.GetInt32("NumberToGuess")); if (numberToGuess == 0) { return(RedirectToAction(nameof(GuessingGame))); //Gen a new no } String result = GuessingGameService.CheckGuess(guess, numberToGuess); ViewBag.Result = result; ViewBag.Guess = guess; ViewBag.NumberToGuess = numberToGuess; return(View()); }