Пример #1
0
        public static HealthCheckResponse CreateHealthCheckResponse(IConnectorClient connector)
        {
            // A derived class may override this, however, the default is that the bot is healthy given we have got to here.
            var healthResults = new HealthResults {
                Success = true
            };

            if (connector != null)
            {
                try
                {
                    // This is a mock secure SendToConversation to grab the exact HTTP headers.
                    // If you have no appId and no secret this code will run but not produce an Authorization header.
                    using (var captureHandler = new CaptureRequestHandler())
                    {
                        using (var client = new ConnectorClient(connector.BaseUri, connector.Credentials, captureHandler))
                        {
                            var activity = new Activity
                            {
                                Type         = ActivityTypes.Message,
                                Conversation = new ConversationAccount {
                                    Id = "capture"
                                }
                            };
                            client.Conversations.SendToConversation(activity);
                            var headers = captureHandler.Request.Headers;
                            healthResults.Authorization = headers.Authorization?.ToString();
                            healthResults.UserAgent     = headers.UserAgent?.ToString();
                        }
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types (ignoring, see comment in catch block)
                catch (Exception)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    // This exception happens when you have a valid appId but invalid or blank secret.
                    // No callbacks will be possible, although the bot maybe healthy in other respects.
                }
            }

            var successMessage = "Health check succeeded.";
            healthResults.Messages = healthResults.Authorization != null
                ? new[] { successMessage }
                : new[]
            {
                successMessage,
                "Callbacks are not authorized."
            };

            return(new HealthCheckResponse {
                HealthResults = healthResults
            });
        }
Пример #2
0
        static void Main(string[] args)
        {
            Logger logger = new Logger();

            if (args.Length == 0)
            {
                Console.WriteLine("Please specify running mode. Must be \"publisher\" or \"listener\" (without quote).");
                Environment.Exit(-1);
            }

            if ("publisher".Equals(args[0]))
            {
                Client client = new DefaultClient("Camera-Request", "Camera-Response");
                while (true)
                {
                    Console.WriteLine("Type \"send\" to send a camera capture request: (type \"exit\" to exit)");
                    String text = Console.ReadLine();
                    if (text.Equals("send"))
                    {
                        CameraCaptureRequest request = new CameraCaptureRequest();
                        Message message = client.SendAndWait(request);
                        if (message != null)
                        {
                            logger.Log("Got response with id " + message.GetId());
                        }
                    }
                    else if (text.Equals("exit"))
                    {
                        Environment.Exit(0);
                    }
                }
            }
            else if ("listener".Equals(args[0]))
            {
                CaptureRequestHandler handler = new CaptureRequestHandler();
                Client client = new DefaultClient("Camera-Response", "Camera-Request");
                Console.WriteLine("Listener will never exit. Please kill the process if you want to quit.");
                client.WaitAndResponse(handler);
            }
            else
            {
                Console.WriteLine("Please specify running mode as parameter. Must be \"publisher\" or \"listener\" (without quote).");
                Environment.Exit(-2);
            }
        }