public static void WriteExceptionalLog(Exception exceptionalSunny) { LogName logName = new LogName(ProjectId, LogId); var jsonPayload = CreateJsonPayload(); var value = new ProtoWellKnownTypes.Value() { StringValue = exceptionalSunny.ToString() }; jsonPayload.Fields[MessageFieldName] = value; LogEntry logEntry = new LogEntry { LogName = logName.ToString(), Severity = LogSeverity.Error, JsonPayload = jsonPayload }; MonitoredResource resource = new MonitoredResource { Type = "global" }; // global does not use label. // resource.Labels["name"] = "This_is_another_name"; IDictionary <string, string> entryLabels = new Dictionary <string, string> { { "size", "large" }, { "color", "red" } }; _client.Value.WriteLogEntries(LogNameOneof.From(logName), resource, entryLabels, new[] { logEntry }, null); //TestTrace($"Written entry {logEntry.ToString()}"); }
/// <summary> /// Converts a <see cref="Value"/> value, which must represent a Struct, /// to the specified message type. /// </summary> /// <typeparam name="T">The message type to convert the struct to.</typeparam> /// <param name="structValue">The Struct to convert. Must not be null.</param> /// <returns>The message representation of the Struct.</returns> public static T ToMessage <T>(WktValue structValue) where T : IMessage, new() { GaxPreconditions.CheckNotNull(structValue, nameof(structValue)); GaxPreconditions.CheckArgument(structValue.KindCase == WktValue.KindOneofCase.StructValue, nameof(structValue), "The value being converted must represent a Struct"); return(ToMessage <T>(structValue.StructValue)); }
/// <summary> /// Converts a protobuf message to a <see cref="Value"/>. /// </summary> /// <param name="message">The message to convert. Must not be null.</param> /// <returns>The Struct representation of the message.</returns> public static WktValue ToValue(IMessage message) => WktValue.ForStruct(ToStruct(message));
public async Task <ActionResult> HandleRequest([FromBody] dynamic request) { // Read the request JSON asynchronously, as the Google.Protobuf library // doesn't (yet) support asynchronous parsing. //string requestJson; //using (TextReader reader = new StreamReader(Request.Body)) //{ // requestJson = await reader.ReadToEndAsync(); //} //// Parse the body of the request using the Protobuf JSON parser, //// *not* Json.NET. //var request = jsonParser.Parse<WebhookRequest>(requestJson); // Note: you should authenticate the request here. var message = new Message { Text = new Text { Text_ = { "Hello world" } } }; var payload = new MapField <string, Value>(); var responseText = "Hello word"; var textToSpeech = new Value { StringValue = responseText }; var simpleResponse = new Struct { }; simpleResponse.Fields.Add("textToSpeech", textToSpeech); var googlePayload = new Google.Protobuf.WellKnownTypes.Value { StructValue = new Google.Protobuf.WellKnownTypes.Struct { } }; payload.Add("google", googlePayload); // Populate the response var response = new WebhookResponse() { FulfillmentMessages = { message }, Payload = new Google.Protobuf.WellKnownTypes.Struct { Fields = { payload } } }; // Ask Protobuf to format the JSON to return. // Again, we don't want to use Json.NET - it doesn't know how to handle Struct // values etc. string responseJson = response.ToString(); return(Content(responseJson, "application/json")); }