当前位置: 首页>>代码示例>>C#>>正文


C# MultipartFormDataContent.AddIf方法代码示例

本文整理汇总了C#中System.Net.Http.MultipartFormDataContent.AddIf方法的典型用法代码示例。如果您正苦于以下问题:C# MultipartFormDataContent.AddIf方法的具体用法?C# MultipartFormDataContent.AddIf怎么用?C# MultipartFormDataContent.AddIf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.MultipartFormDataContent的用法示例。


在下文中一共展示了MultipartFormDataContent.AddIf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AnswerInlineQueryAsync

        /// <summary>Sends answers to an inline query.</summary>
        /// <param name="inlineQueryId">Unique identifier for answered query.</param>
        /// <param name="results">Results of the inline query.</param>
        /// <param name="cacheTime">
        /// The maximum amount of time in seconds the result of the inline query may be cached on the Telegram
        /// server. Default is 300.
        /// </param>
        /// <param name="isPersonal">
        /// <c>true</c>, to cache the results on the Telegram server only for the user that sent the query. By
        /// default, results may be returned to any user who sends the same query.
        /// </param>
        /// <param name="nextOffset">
        /// The offset that a client should send in the next query with the same text to receive more results.
        /// <c>null</c> or <see cref="string.Empty" /> if there are no more results or if you don't support
        /// pagination. Offset length can't exceed 64 bytes.
        /// </param>
        /// <param name="switchPrivateMessageText">
        /// If passed, clients will display a button with specified text that switches the user to a private
        /// chat with the bot and sends the bot a start message with the parameter
        /// <paramref name="switchPrivateMessageParameter" />.
        /// </param>
        /// <param name="switchPrivateMessageParameter">
        /// Parameter for the start message sent to the bot when user presses the switch button.
        /// <para>
        /// Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their
        /// YouTube account to adapt search results accordingly. To do this, it displays a ‘Connect your
        /// YouTube account’ button above the results, or even before showing any. The user presses the button,
        /// switches to a private chat with the bot and, in doing so, passes a start parameter that instructs
        /// the bot to return an oauth link. Once done, the bot can offer a switch_inline button so that the
        /// user can easily return to the chat where they wanted to use the bot's inline capabilities.
        /// </para>
        /// </param>
        /// <param name="cancellationToken">
        /// A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to
        /// complete.
        /// </param>
        /// <returns>
        /// A task that represents the asynchronous operation. The task results contains <c>true</c> if the
        /// answer successfully sent; otherwise <c>false</c>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="inlineQueryId" /> is null -or- <paramref name="results" /> is null.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// The nextOffset argument must be less than 64 bytes.
        /// </exception>
        /// <exception cref="ArgumentException">No more than 50 results per query are allowed.</exception>
        public Task<bool> AnswerInlineQueryAsync([NotNull] string inlineQueryId, [NotNull] IEnumerable<InlineQueryResult> results, int cacheTime = 300, bool isPersonal = false, string nextOffset = null, string switchPrivateMessageText = null, string switchPrivateMessageParameter = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(inlineQueryId, nameof(inlineQueryId));
            Contracts.EnsureNotNull(results, nameof(results));

            var inlineQueryResults = results as IList<InlineQueryResult> ?? results.ToList();
            if( inlineQueryResults.Count > 50 )
                throw new ArgumentException("No more than 50 results per query are allowed.", nameof(results));

            var parameters = new MultipartFormDataContent();

            if( !string.IsNullOrWhiteSpace(nextOffset) )
            {
                Contracts.EnsureByteCount(nextOffset, nameof(nextOffset));
                parameters.Add("next_offset", nextOffset);
            }

            parameters.Add("inline_query_id", inlineQueryId);
            parameters.Add("results", inlineQueryResults);
            parameters.AddIf(cacheTime != 300, "cache_time", cacheTime);
            parameters.AddIf(isPersonal, "is_peronal", isPersonal);
            parameters.AddIf(!string.IsNullOrWhiteSpace(switchPrivateMessageText), "switch_pm_text", switchPrivateMessageText);
            parameters.AddIf(!string.IsNullOrWhiteSpace(switchPrivateMessageParameter), "switch_pm_parameter", switchPrivateMessageParameter);

            return this.CallTelegramMethodAsync<bool>(cancellationToken, "answerInlineQuery", parameters);
        }
开发者ID:mrtaikandi,项目名称:Telebot,代码行数:73,代码来源:Telebot.cs

示例2: SendDocumentAsync

        /// <summary>
        /// Sends a general file.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient or username of the target channel (in the format
        /// @channelusername).</param>
        /// <param name="documentStream">A <see cref="Stream" /> to the document file to send.</param>
        /// <param name="fileName">A name for the file to be sent using <paramref name="documentStream" />.</param>
        /// <param name="caption">Document caption, 0-200 characters.</param>
        /// <param name="disableNotification">If set to <c>true</c> sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message.</param>
        /// <param name="replyMarkup">Additional interface options. An <see cref="IReply" /> object for a custom reply keyboard,
        /// instructions to hide keyboard or to force a reply from the user.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of
        /// cancellation.</param>
        /// <returns>
        /// On success, returns the sent <see cref="Message" />.
        /// </returns>
        /// <remarks>
        /// Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the
        /// future.
        /// </remarks>
        public Task<Message> SendDocumentAsync([NotNull] string chatId, [NotNull] Stream documentStream, string fileName, string caption = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(chatId, nameof(chatId));
            Contracts.EnsureNotNull(documentStream, nameof(documentStream));

            // ReSharper disable once UseObjectOrCollectionInitializer
            var content = new MultipartFormDataContent();
            content.Add("document", documentStream, fileName);
            content.AddIf(!string.IsNullOrWhiteSpace(caption), "caption", caption);

            return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendDocument", content, chatId, replyToMessageId, replyMarkup, disableNotification);
        }
开发者ID:mrtaikandi,项目名称:Telebot,代码行数:33,代码来源:Telebot.document.cs

示例3: SendAudioAsync

        /// <summary>
        /// Sends an audio file. If you want Telegram clients to display them in the music player. Your audio must be in the .mp3 format.
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient or username of the target channel (in the format
        /// @channelusername).</param>
        /// <param name="audioStream">A <see cref="Stream" /> to the audio file to send.</param>
        /// <param name="fileName">A name for the file to be sent using <paramref name="audioStream" />.</param>
        /// <param name="duration">Duration of the audio in seconds.</param>
        /// <param name="performer">The performer of the audio.</param>
        /// <param name="title">The track name.</param>
        /// <param name="disableNotification">If set to <c>true</c> sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.</param>
        /// <param name="replyToMessageId">If the message is a reply, ID of the original message.</param>
        /// <param name="replyMarkup">Additional interface options. An <see cref="IReply" /> object for a custom reply keyboard,
        /// instructions to hide keyboard or to force a reply from the user.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of
        /// cancellation.</param>
        /// <returns>
        /// On success, returns the sent <see cref="Message" />.
        /// </returns>
        public Task<Message> SendAudioAsync([NotNull] string chatId, [NotNull] Stream audioStream, string fileName, int duration, string performer = null, string title = null, bool disableNotification = false, long replyToMessageId = 0, IReply replyMarkup = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(chatId, nameof(chatId));
            Contracts.EnsureNotNull(audioStream, nameof(audioStream));

            // ReSharper disable once UseObjectOrCollectionInitializer
            var content = new MultipartFormDataContent();
            content.Add("audio", audioStream, fileName);
            content.AddIf(duration > 0, "duration", duration);
            content.AddIf(!string.IsNullOrWhiteSpace(performer), "performer", performer);
            content.AddIf(!string.IsNullOrWhiteSpace(title), "title", title);

            return this.CallTelegramMethodAsync<Message>(cancellationToken, "sendAudio", content, chatId, replyToMessageId, replyMarkup, disableNotification);
        }
开发者ID:mrtaikandi,项目名称:Telebot,代码行数:33,代码来源:Telebot.audio.cs


注:本文中的System.Net.Http.MultipartFormDataContent.AddIf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。