當前位置: 首頁>>代碼示例>>C#>>正文


C# TimeSpan.RoundUpToSeconds方法代碼示例

本文整理匯總了C#中System.TimeSpan.RoundUpToSeconds方法的典型用法代碼示例。如果您正苦於以下問題:C# TimeSpan.RoundUpToSeconds方法的具體用法?C# TimeSpan.RoundUpToSeconds怎麽用?C# TimeSpan.RoundUpToSeconds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.TimeSpan的用法示例。


在下文中一共展示了TimeSpan.RoundUpToSeconds方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetMessagesImpl

        /// <summary>
        /// Gets the messages impl.
        /// </summary>
        /// <param name="numberOfMessages">The number of messages.</param>
        /// <param name="visibilityTimeout">The visibility timeout.</param>
        /// <param name="setResult">The set result.</param>
        /// <returns>A <see cref="TaskSequence"/> that gets the message.</returns>
        private TaskSequence GetMessagesImpl(int? numberOfMessages, TimeSpan? visibilityTimeout, Action<IEnumerable<CloudQueueMessage>> setResult)
        {
            if (visibilityTimeout.HasValue)
            {
                CommonUtils.AssertInBounds("visibiliyTimeout", visibilityTimeout.Value, TimeSpan.Zero, TimeSpan.MaxValue);
            }

            if (numberOfMessages.HasValue)
            {
                CommonUtils.AssertInBounds("numberOfMessage", numberOfMessages.Value, 0, int.MaxValue);
            }

            int? visibilityTimeoutInSec = visibilityTimeout != null ? visibilityTimeout.RoundUpToSeconds() : (int?)null;

            var webRequest = QueueRequest.GetMessages(this.MessageRequestAddress, this.ServiceClient.Timeout.RoundUpToSeconds(), numberOfMessages, visibilityTimeoutInSec);
            CommonUtils.ApplyRequestOptimizations(webRequest, -1);
            this.ServiceClient.Credentials.SignRequest(webRequest);
            var task = webRequest.GetResponseAsyncWithTimeout(this.ServiceClient, this.ServiceClient.Timeout);
            yield return task;

            using (var webResponse = task.Result as HttpWebResponse)
            {
                var parsedResponse = QueueResponse.GetMessages(webResponse);
                setResult(MaterializeAndParseResponse(parsedResponse.Messages, this.SelectGetMessageResponse));
            }
        }
開發者ID:nickchal,項目名稱:pash,代碼行數:33,代碼來源:CloudQueue.cs

示例2: UpdateMessageImpl

        /// <summary>
        /// Implementation for the UpdateMessage method.
        /// </summary>
        /// <param name="message">A queue message.</param>
        /// <param name="visibilityTimeout">The visibility timeout for the message.</param>
        /// <param name="updateFlags">Indicates whether to update the visibility delay, message contents, or both.</param>
        /// <param name="options">An <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param>
        /// <returns>A <see cref="RESTCommand{T}"/> that sets the permissions.</returns>
        private RESTCommand<NullType> UpdateMessageImpl(CloudQueueMessage message, TimeSpan visibilityTimeout, MessageUpdateFields updateFlags, QueueRequestOptions options)
        {
            CommonUtils.AssertNotNull("message", message);
            CommonUtils.AssertNotNullOrEmpty("messageId", message.Id);
            CommonUtils.AssertNotNullOrEmpty("popReceipt", message.PopReceipt);
            CommonUtils.AssertInBounds<TimeSpan>("visibilityTimeout", visibilityTimeout, TimeSpan.Zero, CloudQueueMessage.MaxTimeToLive);

            if ((updateFlags & MessageUpdateFields.Visibility) == 0)
            {
                throw new ArgumentException("Calls to UpdateMessage must include the Visibility flag.", "updateFlags");
            }

            Uri messageUri = this.GetIndividualMessageAddress(message.Id);
            RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, messageUri);

            options.ApplyToStorageCommand(putCmd);
            putCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => QueueHttpWebRequestFactory.UpdateMessage(putCmd.Uri, serverTimeout, message.PopReceipt, visibilityTimeout.RoundUpToSeconds(), ctx);

            if ((updateFlags & MessageUpdateFields.Content) != 0)
            {
                MemoryStream memoryStream = new MemoryStream();
                QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage), memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);

                putCmd.SendStream = memoryStream;
                putCmd.RecoveryAction = RecoveryActions.RewindStream;
            }
            else
            {
                putCmd.SetHeaders = (r, ctx) =>
                {
                    r.ContentLength = 0;
                };
            }

            putCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest;
            putCmd.PreProcessResponse = (cmd, resp, ex, ctx) =>
            {
                HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex, ctx);
                GetPopReceiptAndNextVisibleTimeFromResponse(message, resp);
                return NullType.Value;
            };

            return putCmd;
        }
開發者ID:nberardi,項目名稱:azure-sdk-for-net,代碼行數:53,代碼來源:CloudQueue.cs


注:本文中的System.TimeSpan.RoundUpToSeconds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。