// This method is called to execute the multicate delegate // object. public static void ExecuteDelegate(Greeting greetings) { if (null != greetings) { foreach (Greeting g in greetings.GetInvocationList()) { int result = g(); Console.WriteLine("\t Result = {0}.\n", result); } } }
protected void ButtonCreateGreeting_Click(object sender, EventArgs e) { string username = TextBoxName.Text; Greeting greeting = new Greeting { ArgUserName = username }; IDictionary<string, object> results = WorkflowInvoker.Invoke(greeting); LabelGreeting.Text = results["Result"].ToString(); }
// Entry point. public static void Main() { // Create a delegate object of type Greeting and have it // encapsulate a single method - Salutation1(). Greeting myGreeting = new Greeting(Salutation1); Console.WriteLine ("My single greeting: "); myGreeting(); // Create another delegate object of type Greeting and have // it encapsulate a single method - Salutation2(). Greeting yourGreeting = new Greeting(Salutation2); Console.WriteLine ("\nYour single greeting: "); yourGreeting(); // Create a multicast delegate of type Greeting and have // it encapsulate two methods. These methods are represented // by delegate objects already. Notice the use of the '+' // operator to create a multicast delegate. Greeting ourGreeting = myGreeting + yourGreeting; Console.WriteLine ("\nOur multicast greeting: "); ourGreeting(); // Continue to use the multicast delegate and add another // encapsulated method to it - Salutation3. Now the // multicast delegate encapsulates 3 methods. Notice the // use of the '+=' operator. If we would have used just // the '=' operator, the already referenced methods in the // multicast delegate would be unreferenced and replaced by // the new method we're assigning here. ourGreeting += new Greeting(Salutation3); Console.WriteLine ("\nMulticast greeting with all salutations: "); ourGreeting(); // Remove one of the encapsulated methods from the multicast // delegate - the one represented by the yourGreeting delegate // object. Notice the use of the '-' operator. ourGreeting = ourGreeting - yourGreeting; Console.WriteLine ("\nMulticast greeting without your greeting: "); ourGreeting(); // Remove another encapsulated method from the multicast // delegate - the one represented by the myGreeting delegate // object. Notice the use of the '-=' operator. ourGreeting -= myGreeting; Console.WriteLine ("\nGreeting without your greeting and my greeting: "); ourGreeting(); // Now create a multicast delegate to show that it will // call each method in the order it was encapsulated by the // delegate object. Greeting newGreeting = new Greeting(Salutation2); newGreeting += new Greeting(Salutation1); newGreeting += new Greeting(Salutation3); Console.WriteLine ("\nNew multicast delegate with different order of methods:"); newGreeting(); Console.Write ("\n\nPress <ENTER> to end: "); Console.Read(); }
public void GetGreeting_AfterNoon_ReturnsCorrectValue() { ITimeSupplier timeSupplier = new TimeSupplierStub(new DateTime(2014, 5, 22, 14, 0, 0)); Greeting greetingSut = new Greeting(timeSupplier); greetingSut.GetGreeting().Should().Be("Good Afternoon"); }
public void GetGreeting_Morning_ReturnsCorrectValue() { ITimeSupplier timeSupplier = new TimeSupplierStub(new DateTime(2014, 5, 22, 6, 0, 0)); Greeting greetingSut = new Greeting(timeSupplier); greetingSut.GetGreeting().Should().Be("Good Morning"); }
// Entry point. public static void Main() { //// Notice in each block of code that instead of calling the delegate //// directly, it's passed to ExecuteDelegate. //Greeting myGreeting = new Greeting(Salutation1); //Console.WriteLine ("My single greeting:\n"); //ExecuteDelegate (myGreeting); //Greeting yourGreeting = new Greeting(Salutation2); //Console.WriteLine("\nYour single greeting:\n"); //ExecuteDelegate (yourGreeting); //Greeting ourGreeting = myGreeting + yourGreeting; //Console.WriteLine("\nOur multicast greeting:\n"); //ExecuteDelegate (ourGreeting); //ourGreeting += new Greeting(Salutation3); //Console.WriteLine("\nMulticast greeting including all salutations:\n"); //ExecuteDelegate (ourGreeting); //ourGreeting = ourGreeting - yourGreeting; //Console.WriteLine("\nMulticast greeting without your greeting:\n"); //ExecuteDelegate (ourGreeting); //ourGreeting -= myGreeting; //Console.WriteLine("\nGreeting without your greeting and my greeting:\n"); //ExecuteDelegate (ourGreeting); Greeting newGreeting = new Greeting(Salutation2); newGreeting += new Greeting(Salutation1); newGreeting += new Greeting(Salutation3); Console.WriteLine("\nNew multicast delegate with different order of methods:\n"); ExecuteDelegate (newGreeting); Console.Write ("\nPress <ENTER> to end: "); Console.Read(); }
public static string ToOutput(RawMessage message, Company company, Guest guest) { if (message.text.Contains("{timeGreeting}")) { var currentTime = new DateTime(); currentTime = DateTime.Now; var greeting = new Greeting(); if (currentTime.Hour >= 6 && currentTime.Hour < 11) { greeting.Salutation = "GOOD DAY TO YOU, PARTNER"; } else if (currentTime.Hour >= 11 && currentTime.Hour < 17) { greeting.Salutation = "GOOD DAY TO YOU, PARTNER"; } else if (currentTime.Hour >= 17 && currentTime.Hour < 11) { greeting.Salutation = "GOOD EVENING, COMRADE"; } else { greeting.Salutation = "YOU SHOULD BE SLEEPING"; } message.text = message.text.Replace("{timeGreeting}", greeting.Salutation); } if (message.text.Contains("{guestName}")) { message.text = message.text.Replace("{guestName}", ($"{guest.firstName} {guest.lastName}")); } if (message.text.Contains("{company}")) { message.text = message.text.Replace("{company}", company.company); } if (message.text.Contains("{roomNumber}")) { message.text = message.text.Replace("{roomNumber}", guest.reservation.roomNumber.ToString()); } if (message.text.Contains("{startTimeStamp}")) { message.text = message.text.Replace("{startTimeStamp}", DateConverter.ToDateTime(guest.reservation.startTimeStamp).ToString()); } if (message.text.Contains("{endTimeStamp}")) { message.text = message.text.Replace("{endTimeStamp}", DateConverter.ToDateTime(guest.reservation.endTimeStamp).ToString()); } if (message.text.Contains("{city}")) { message.text = message.text.Replace("{city}", company.city); } if (message.text.Contains("{timezone}")) { message.text = message.text.Replace("{timezone}", company.timezone); } return(message.text); }
public IActionResult Greets(Greeting greet) { return(RedirectToAction("Greet", greet)); }
public async Task <Greeting> Update([FromBody] Greeting greeting) { return(await _greetingService.Update(greeting)); }
static async Task Main(string[] args) { Channel channel = new Channel(target, ChannelCredentials.Insecure); await channel.ConnectAsync().ContinueWith((task) => { if (task.Status == TaskStatus.RanToCompletion) { Console.WriteLine("The client connected successfully"); } }); //var client = new DummyService.DummyServiceClient(channel); var client = new GreetingService.GreetingServiceClient(channel); //var client = new SqrtService.SqrtServiceClient(channel); var greeting = new Greeting() { FirstName = "Lada", LastName = "Hruska" }; //var request = new GreetingRequest() { Greeting = greeting }; //var response = client.Greet(request); //var request = new GreetManyTimesRequest() { Greeting = greeting }; //var response = client.GreetManyTimes(request); //Console.WriteLine(response.Result); //while(await response.ResponseStream.MoveNext()) //{ // Console.WriteLine(response.ResponseStream.Current.Result); // await Task.Delay(200); //} //var request = new LongGreetRequest() { Greeting = greeting }; //var stream = client.LongGreet(); //foreach(int i in Enumerable.Range(1,10)) //{ // await stream.RequestStream.WriteAsync(request); //} //await stream.RequestStream.CompleteAsync(); //var response = await stream.ResponseAsync; //Console.WriteLine(response.Result); //var stream = client.GreetEveryone(); //var responseReaderTask = Task.Run(async () => { // while(await stream.ResponseStream.MoveNext()) // { // Console.WriteLine("Received: " + stream.ResponseStream.Current.Result); // } //}); //Greeting[] greetings = //{ // new Greeting() { FirstName = "John", LastName = "Doh"}, // new Greeting() { FirstName = "Hikaru" , LastName = "Kenta"}, // new Greeting() { FirstName = "Sayaka", LastName = "Mori"} //}; //foreach(var oneGreeting in greetings) //{ // Console.WriteLine("Sending : " + oneGreeting.ToString()); // await stream.RequestStream.WriteAsync(new GreetEveryoneRequest() { Greeting = oneGreeting }); // await Task.Delay(2000); //} //await stream.RequestStream.CompleteAsync(); //await responseReaderTask; //int number = 16; //int number = -1; //try //{ // var response = client.sqrt(new SqrtRequest() { Number = number }); // Console.WriteLine(response.SquareRoot); //} //catch (RpcException ex) //{ // Console.WriteLine("Error : " + ex.Status.Detail); //} try { //var request = new GreetingRequest() { Greeting = greeting }; //var response = client.Greet(request); var response = client.GreetWithDeadline(new GreetingRequest() { Greeting = greeting }, deadline: DateTime.UtcNow.AddMilliseconds(100)); Console.WriteLine(response.Result); } catch (RpcException ex) when(ex.StatusCode == StatusCode.DeadlineExceeded) { Console.WriteLine("Error: " + ex.Status.Detail); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } //var client = new CalcService.CalcServiceClient(channel); //var request = new CalcRequest() { A = 10, B = 3 }; //var response = client.Calculate(request); //Console.WriteLine(response.Sum); channel.ShutdownAsync().Wait(); Console.ReadKey(); }
//const string target = "127.0.0.1:50051"; static async Task Main(string[] args) { var clientCert = File.ReadAllText("ssl/client.crt"); var clientKey = File.ReadAllText("ssl/client.key"); var caCrt = File.ReadAllText("ssl/ca.crt"); var channelCredentials = new SslCredentials(caCrt, new KeyCertificatePair(clientCert, clientKey)); Channel channel = new Channel("localhost", 50051, channelCredentials); await channel.ConnectAsync().ContinueWith((task) => { if (task.Status == TaskStatus.RanToCompletion) { Console.WriteLine("The client connected successfuly"); } }); // Greeting var client = new GreetingService.GreetingServiceClient(channel); var calcClient = new CalculatorService.CalculatorServiceClient(channel); var greeting = new Greeting() { FirstName = "Johan", LastName = "Clementes" }; #region "Unary" DoSimpleGreet(client, new GreetingRequest() { Greeting = greeting }); #endregion #region "Server streaming" //DoManyGreetings(client, greeting); #endregion #region "Calculator" //Calc(calcClient); #endregion #region "Number to Prime Numbers" //await GetPrimeNumbers(calcClient); #endregion #region "Client streaming" //await DoLongGreet(client, greeting); #endregion #region "Client streaming Avg" //await GetAvg(calcClient); #endregion #region "Bi-Di streaming" //await DoGreetEveryone(client); #endregion #region "Find Max Number" //await FindMaxNumber(calcClient); #endregion #region "Errors in gRPC" //CalcSqrt(new SqrtService.SqrtServiceClient(channel)); #endregion #region "Deadlines in gRPC" //GreetClientDeadlines(new GreetDeadlinesService.GreetDeadlinesServiceClient(channel)); #endregion channel.ShutdownAsync().Wait(); Console.ReadKey(); }
public void SetUp() { greeting = new Greeting(); }
public IActionResult Greeting() { var hello = new Greeting(); return(new JsonResult(hello)); }
internal static GreetingResponse MapFrom(Greeting source) => new GreetingResponse() { Message = source.Content };
public IActionResult Greeting(string name) { Greeting greet = new Greeting(name); return(new JsonResult(greet)); }
/// <param name='cancellationToken'> /// Cancellation token. /// </param> public async Task <HttpOperationResponse <Greeting> > GetGreetingAsync(CancellationToken cancellationToken) { // Tracing bool shouldTrace = ServiceClientTracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); ServiceClientTracing.Enter(invocationId, this, "GetGreetingAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/greetings"; string baseUrl = this.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Send Request if (shouldTrace) { ServiceClientTracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { ServiceClientTracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); if (statusCode != HttpStatusCode.OK) { HttpOperationException <object> ex = new HttpOperationException <object>(); ex.Request = httpRequest; ex.Response = httpResponse; ex.Body = null; if (shouldTrace) { ServiceClientTracing.Error(invocationId, ex); } throw ex; } // Create Result HttpOperationResponse <Greeting> result = new HttpOperationResponse <Greeting>(); result.Request = httpRequest; result.Response = httpResponse; // Deserialize Response if (statusCode == HttpStatusCode.OK) { Greeting resultModel = new Greeting(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null) { resultModel.DeserializeJson(responseDoc); } result.Body = resultModel; } if (shouldTrace) { ServiceClientTracing.Exit(invocationId, result); } return(result); }
public IActionResult Greeting(string name) { var greeting = new Greeting(name); return(new JsonResult(greeting)); }
public PrintGreetingAtObjectAdapter(string name) { this.Greeting = new Greeting(name); }
static void Main() { Greeting greeting = new Greeting(); greeting.greet(); greeting.bye(); }
public Greeting UpdateGreetingAsync(Greeting greeting) { throw new NotImplementedException(); }
public IActionResult Greeting(string yourName = "Anonimous") { Greeting greeting = new Greeting(yourName); return(new JsonResult(greeting)); }
public Greeting Greeting(string name) { Greeting greet = new Greeting(counter++, $"Hello, {name}!"); return(greet); }
public void AddEditDeleteCallHandler_GreetingOptionTests() { Greeting oGreeting; GreetingStreamFile oStream; WebCallResult res = _tempHandler.GetGreeting(GreetingTypes.Alternate, out oGreeting); Assert.IsTrue(res.Success, "Failed to get alternate greeting" + res); //update the greeting propert and upload a wav file to it oGreeting.PlayWhat = PlayWhatTypes.RecordedGreeting; oGreeting.TimeExpiresSetNull(); res = oGreeting.Update(); Assert.IsTrue(res.Success, "Failed updating 'playWhat' for alternate greeting rule:" + res.ToString()); res = oGreeting.SetGreetingWavFile(1033, "wavcopy.exe", true); Assert.IsFalse(res.Success, "Uploading invalid WAV file should fail"); res = oGreeting.SetGreetingWavFile(1033, "Dummy.wav", true); Assert.IsTrue(res.Success, "Failed updating the greeting wav file for the alternate greeting:" + res); //use static greeting stream to set wav file instead res = GreetingStreamFile.SetGreetingWavFile(_connectionServer, _tempHandler.ObjectId, GreetingTypes.Alternate, 1033, "Dummy.wav", true); Assert.IsTrue(res.Success, "Updating voice name on new call handler failed: " + res); //upload the wav file again, this time using an instance of the GreetingStreamFile object res = GreetingStreamFile.GetGreetingStreamFile(_connectionServer, _tempHandler.ObjectId, GreetingTypes.Alternate, 1033, out oStream); Assert.IsTrue(res.Success, "Failed to create GreetingStreamFile object" + res); res = oStream.SetGreetingWavFile("Dummy.wav", true); Assert.IsTrue(res.Success, "Failed to upload WAV file via GreetingStreamFile instance" + res); //check some failure resuls for GreetingStreamFile static calls while we're here since we know this greeting exists. res = GreetingStreamFile.GetGreetingWavFile(null, "temp.wav", _tempHandler.ObjectId, GreetingTypes.Alternate, 1033); Assert.IsFalse(res.Success, "Null connection server param should fail" + res); res = GreetingStreamFile.GetGreetingWavFile(_connectionServer, "temp.wav", "", GreetingTypes.Alternate, 1033); Assert.IsFalse(res.Success, "Empty call handler object ID param should fail" + res); res = GreetingStreamFile.GetGreetingWavFile(_connectionServer, "temp.wav", _tempHandler.ObjectId, GreetingTypes.Invalid, 1033); Assert.IsFalse(res.Success, "Invalid greeting type name should fail" + res); res = GreetingStreamFile.GetGreetingWavFile(_connectionServer, "temp.wav", _tempHandler.ObjectId, GreetingTypes.Alternate, 10); Assert.IsFalse(res.Success, "Invalid language code should fail" + res); res = GreetingStreamFile.GetGreetingWavFile(_connectionServer, "temp.wav", _tempHandler.ObjectId, GreetingTypes.Alternate, 1033); Assert.IsTrue(res.Success, "Uploading WAV file to greeting via static GreetingStreamFile call failed:" + res); //get list of all greeting stream files List <GreetingStreamFile> oStreams = oGreeting.GetGreetingStreamFiles(true); Assert.IsNotNull(oStreams, "Null list of greeting streams returned from greeting streams fetch"); Assert.IsTrue(oStreams.Count > 0, "Empty list of greeting streams returned"); //create a new greeting and fetch the stream files we just uploaded for it oGreeting = new Greeting(_connectionServer, _tempHandler.ObjectId, GreetingTypes.Alternate); Assert.IsNotNull(oGreeting, "Failed to create new greeting object"); //fetch the stream back out res = oGreeting.GetGreetingStreamFile(1033, out oStream); Assert.IsTrue(res.Success, "Failed to fetch greeting stream file:" + res); res = oGreeting.UpdateGreetingEnabledStatus(true, DateTime.Now.AddDays(1)); Assert.IsTrue(res.Success, "Failed updating greeting eneabled status for one day:" + res); //exercise the "auto fill" greeting, menu entry and transfer option interfaces List <Greeting> oGreetings = _tempHandler.GetGreetings(); Assert.IsTrue(oGreetings.Count > 5, "Greetings collection not returned from call handler properly."); }
public static async Task DoLongGreet(GreetingService.GreetingServiceClient client, Greeting greeting) { var request = new LongGreetingRequest() { Greeting = greeting }; var stream = client.LongGreet(); foreach (int i in Enumerable.Range(1, 10)) { await stream.RequestStream.WriteAsync(request); } await stream.RequestStream.CompleteAsync(); var response = await stream.ResponseAsync; Console.WriteLine(response.Result); }
public async Task <ActionResult <Greeting> > Get() { Greeting result = await GreetingService.GetGreetingAsync(); return(result); }
public static async Task DoManyGreetings(GreetingService.GreetingServiceClient client, Greeting greeting) { var request = new GreetingManyTimesRequest { Greeting = greeting }; var response = client.GreetManyTimes(request); while (await response.ResponseStream.MoveNext()) { Console.WriteLine(response.ResponseStream.Current.Result); await Task.Delay(200); } }
public IActionResult Greeting(string name = "Lúzer") { var greeting = new Greeting(name); return(View(greeting)); }
public async Task <Greeting> Add([FromBody] Greeting greeting) { return(await _greetingService.Add(greeting)); }
public TestGreetingMiddleware(OwinMiddleware next, Greeting greeting) : base(next) { Greeting = greeting; }
public HomeController(Greeting greet) { this.greet = greet; }
public GreetingsByIdResult(Greeting greeting) { Id = greeting.Id; Message = greeting.Message; }
public IActionResult Greet(Greeting greet) { return(View(greet)); }
private void Button_Click(object sender, RoutedEventArgs e) { var greeting = new Greeting(); MessageBox.Show(greeting.SayHello()); }
public Task SayHelloToServer(Greeting greeting) => ExecuteOnServer("SayHelloToServer", greeting);
public SpeakService(IOptions <Greeting> hello, IOptions <SpeakEnvironment> speakEnvironment) { _greeting = hello.Value; _speakEnvironment = speakEnvironment.Value; }
public void SayHello_HelloConcatWithNull_Throw_ArgumentNullException() { string userName = null; Greeting.SayHello(userName); }
public Greeting AddGreetingAsync(Greeting greeting, int projectId) { throw new NotImplementedException(); }