コード例 #1
0
        private void SendCustomNotification(CustomMessageType messageType, string objectId, string eventId,
                                            params string[] data)
        {
            using (Trace.Main.scope())
            {
                try
                {
                    Trace.Main.note("SendCustomNotification request\nCustomMessageType: {}\nOID: {}\nEID: {}\nData:\n{}", messageType, objectId, eventId,
                                    data == null ? "*NO DATA*" : data.Aggregate((a, b) => a + "\n" + b));

                    switch (messageType)
                    {
                    case CustomMessageType.ServerNotification:
                    {
                        var requestServerNotification =
                            new CustomRequest(new CustomMessageHeader(messageType, objectId, eventId));
                        if (data != null && data.Length > 0)
                        {
                            requestServerNotification.Write(data);
                        }
                        _customNotification.SendServerRequestNoResponse(requestServerNotification);
                        break;
                    }

                    case CustomMessageType.ApplicationRequest:
                    {
                        var requestApplicationRequest =
                            new CustomRequest(new CustomMessageHeader(messageType, objectId, eventId));
                        if (data != null && data.Length > 0)
                        {
                            requestApplicationRequest.Write(data);
                        }
                        _customNotification.SendApplicationRequest(requestApplicationRequest);
                        break;
                    }

                    case CustomMessageType.ApplicationResponse:
                    {
                        var responseApplicationResponse =
                            new CustomResponse(
                                new CustomMessage(new CustomMessageHeader(messageType, objectId, eventId)));
                        if (data != null && data.Length > 0)
                        {
                            responseApplicationResponse.Write(data);
                        }
                        _customNotification.SendApplicationResponse(responseApplicationResponse);
                        break;
                    }

                    default:
                        throw new Exception("Unsupported message type: " + messageType);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Trace.Main.exception(ex);
                }
            }
        }