Exemple #1
0
        public static ImagemapMessage ToImagemapMessage(this IImagemapMessage self)
        {
            if (self.BaseUrl == null)
                throw new InvalidOperationException("The base url cannot be null.");

            if (self.AlternativeText == null)
                throw new InvalidOperationException("The alternative text cannot be null.");

            if (self.BaseSize == null)
                throw new InvalidOperationException("The base size cannot be null.");

            if (self.Actions == null)
                throw new InvalidOperationException("The actions cannot be null.");

            ImagemapMessage imagemapMessage = self as ImagemapMessage;
            if (imagemapMessage == null)
            {
                imagemapMessage = new ImagemapMessage()
                {
                    BaseUrl = self.BaseUrl,
                    AlternativeText = self.AlternativeText,
                };
            }

            imagemapMessage.BaseSize = self.BaseSize.ToImagemapSize();
            imagemapMessage.Actions = self.Actions.ToImagemapActions().ToArray();

            return imagemapMessage;
        }
Exemple #2
0
        public static ISendMessage[] Convert(ISendMessage[] messages)
        {
            if (messages.Length > 5)
            {
                throw new InvalidOperationException("The maximum number of messages is 5.");
            }

            ISendMessage[] result = new ISendMessage[messages.Length];

            for (int i = 0; i < messages.Length; i++)
            {
                if (messages[i] == null)
                {
                    throw new InvalidOperationException("The message should not be null.");
                }

                switch (messages[i])
                {
                case ITextMessage textMessage:
                    result[i] = TextMessage.Convert(textMessage);
                    break;

                case IImageMessage imageMessage:
                    result[i] = ImageMessage.Convert(imageMessage);
                    break;

                case IVideoMessage videoMessage:
                    result[i] = VideoMessage.Convert(videoMessage);
                    break;

                case IAudioMessage audioMessage:
                    result[i] = AudioMessage.Convert(audioMessage);
                    break;

                case ILocationMessage locationMessage:
                    result[i] = LocationMessage.Convert(locationMessage);
                    break;

                case IStickerMessage stickerMessage:
                    result[i] = StickerMessage.Convert(stickerMessage);
                    break;

                case IImagemapMessage imagemapMessage:
                    result[i] = ImagemapMessage.Convert(imagemapMessage);
                    break;

                case ITemplateMessage templateMessage:
                    result[i] = TemplateMessage.Convert(templateMessage);
                    break;

                default:
                    throw new NotSupportedException("Invalid message type.");
                }
            }

            return(result);
        }
        internal static ImagemapMessage Convert(IImagemapMessage message)
        {
            if (message.BaseUrl == null)
            {
                throw new InvalidOperationException("The base url cannot be null.");
            }

            if (message.AlternativeText == null)
            {
                throw new InvalidOperationException("The alternative text cannot be null.");
            }

            if (message.BaseSize == null)
            {
                throw new InvalidOperationException("The base size cannot be null.");
            }

            if (message.Actions == null)
            {
                throw new InvalidOperationException("The actions cannot be null.");
            }

            if (!(message is ImagemapMessage imagemapMessage))
            {
                imagemapMessage = new ImagemapMessage()
                {
                    BaseUrl         = message.BaseUrl,
                    AlternativeText = message.AlternativeText,
                };
            }

            imagemapMessage.BaseSize = ImagemapSize.Convert(message.BaseSize);
            imagemapMessage.Actions  = ConvertActions(message.Actions);

            return(imagemapMessage);
        }