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


C# PSCmdlet.WriteProgress方法代码示例

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


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

示例1: WaitForDatabaseOperation

        /// <summary>
        /// Queries the server until the database assignment succeeds or there is an error.
        /// </summary>
        /// <param name="context">The context upon which to perform the action</param>
        /// <param name="response">The database object.</param>
        /// <returns>Returns the response from the server</returns>
        internal static Database WaitForDatabaseOperation(PSCmdlet cmdlet, IServerDataServiceContext context, Database response, string databaseName, bool isCreate)
        {
            // Duration to sleep: 2 second
            TimeSpan sleepDuration = TimeSpan.FromSeconds(2.0);

            // Poll for a maximum of 10 minutes;
            TimeSpan maximumPollDuration = TimeSpan.FromMinutes(10.0);

            // Text to display to the user while they wait.
            string pendingText = "Pending";
            string textToDisplay = "";

            // Start the timer
            Stopwatch watch = Stopwatch.StartNew();

            while (watch.Elapsed < maximumPollDuration)
            {
                if (response == null)
                {
                    throw new Exception("An unexpected error occured. The response from the server was invalid, please try your request again.");
                }

                // Check to see if the database is ready for use.
                if ((isCreate && (response.Status != (int)DatabaseStatus.Creating)) || // The database is done being created
                    (!isCreate && (response.ServiceObjectiveAssignmentState != 0)))     // The database is done with SLO upgrade
                {
                    break;
                }

                // Wait before next poll.
                Thread.Sleep(sleepDuration);

                // Display that the status is pending and how long the operation has been waiting
                textToDisplay = string.Format("{0}: {1}", pendingText, watch.Elapsed.ToString("%s' sec.'"));
                cmdlet.WriteProgress(new ProgressRecord(0, "Waiting for database creation completion.", textToDisplay));

                // Poll the server for the database status.
                response = context.GetDatabase(databaseName);
            }

            return response;
        }
开发者ID:kangyangthu,项目名称:azure-sdk-tools,代码行数:48,代码来源:CmdletCommon.cs

示例2: ReadStream

 internal static MemoryStream ReadStream(Stream stream, long contentLength, PSCmdlet cmdlet)
 {
     MemoryStream stream3;
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (!stream.CanRead)
     {
         throw new ArgumentOutOfRangeException("stream");
     }
     if (0L >= contentLength)
     {
         contentLength = 0x186a0L;
     }
     int capacity = (int) Math.Min(contentLength, 0x7fffffffL);
     MemoryStream stream2 = new MemoryStream(capacity);
     try
     {
         long o = 0L;
         byte[] buffer = new byte[0x2710];
         int count = 1;
         while (0 < count)
         {
             if (cmdlet != null)
             {
                 ProgressRecord progressRecord = new ProgressRecord(0xa681412, WebCmdletStrings.ReadResponseProgressActivity, StringUtil.Format(WebCmdletStrings.ReadResponseProgressStatus, o));
                 cmdlet.WriteProgress(progressRecord);
             }
             count = stream.Read(buffer, 0, buffer.Length);
             if (0 < count)
             {
                 stream2.Write(buffer, 0, count);
             }
             o += count;
         }
         if (cmdlet != null)
         {
             ProgressRecord record2 = new ProgressRecord(0xa681412, WebCmdletStrings.ReadResponseProgressActivity, StringUtil.Format(WebCmdletStrings.ReadResponseComplete, o)) {
                 RecordType = ProgressRecordType.Completed
             };
             cmdlet.WriteProgress(record2);
         }
         stream2.SetLength(o);
         stream3 = stream2;
     }
     catch (Exception)
     {
         stream2.Close();
         throw;
     }
     return stream3;
 }
开发者ID:nickchal,项目名称:pash,代码行数:53,代码来源:StreamHelper.cs

示例3: WriteToStream

 internal static void WriteToStream(Stream input, Stream output, PSCmdlet cmdlet)
 {
     byte[] buffer = new byte[0x2710];
     long length = input.Length;
     int count = 1;
     while (0 < count)
     {
         if (cmdlet != null)
         {
             ProgressRecord progressRecord = new ProgressRecord(0xa681412, WebCmdletStrings.WriteRequestProgressActivity, StringUtil.Format(WebCmdletStrings.WriteRequestProgressStatus, length));
             cmdlet.WriteProgress(progressRecord);
         }
         int num3 = (int) Math.Min(length, 0x2710L);
         count = input.Read(buffer, 0, num3);
         if (0 < count)
         {
             output.Write(buffer, 0, count);
         }
         length -= count;
     }
     if (cmdlet != null)
     {
         ProgressRecord record2 = new ProgressRecord(0xa681412, WebCmdletStrings.WriteRequestProgressActivity, StringUtil.Format(WebCmdletStrings.WriteRequestComplete, length)) {
             RecordType = ProgressRecordType.Completed
         };
         cmdlet.WriteProgress(record2);
     }
     output.Flush();
 }
开发者ID:nickchal,项目名称:pash,代码行数:29,代码来源:StreamHelper.cs

示例4: WriteToStream

 internal static void WriteToStream(Stream input, Stream output, PSCmdlet cmdlet)
 {
     byte[] buffer = new byte[0x2710];
     long length = input.Length;
     int count = 1;
     while (0 < count)
     {
         if (cmdlet != null)
         {
             ProgressRecord progressRecord = new ProgressRecord(0xa681412, "Writing web request.", string.Format("Writing request stream... (Number of bytes remaining: {0})", length));
             cmdlet.WriteProgress(progressRecord);
         }
         int num3 = (int) Math.Min(length, 0x2710L);
         count = input.Read(buffer, 0, num3);
         if (0 < count)
         {
             output.Write(buffer, 0, count);
         }
         length -= count;
     }
     if (cmdlet != null)
     {
         ProgressRecord record2 = new ProgressRecord(0xa681412, "Writing web request.", string.Format("Writing web request completed. (Number of bytes remaining: {0})", length))
         {
             RecordType = ProgressRecordType.Completed
         };
         cmdlet.WriteProgress(record2);
     }
     output.Flush();
 }
开发者ID:ejaya2,项目名称:PowerShell-SPOCmdlets,代码行数:30,代码来源:StreamHelper.cs

示例5: WriteToStream

        internal static void WriteToStream(Stream input, Stream output, PSCmdlet cmdlet)
        {
            byte[] data = new byte[ChunkSize];

            int read = 0;
            long totalWritten = 0;
            do
            {
                if (cmdlet != null)
                {
                    ProgressRecord record = new ProgressRecord(ActivityId,
                        WebCmdletStrings.WriteRequestProgressActivity,
                        StringUtil.Format(WebCmdletStrings.WriteRequestProgressStatus, totalWritten));
                    cmdlet.WriteProgress(record);
                }

                read = input.Read(data, 0, ChunkSize);

                if (0 < read)
                {
                    output.Write(data, 0, read);
                    totalWritten += read;
                }
            } while (read != 0);


            if (cmdlet != null)
            {
                ProgressRecord record = new ProgressRecord(ActivityId,
                    WebCmdletStrings.WriteRequestProgressActivity,
                    StringUtil.Format(WebCmdletStrings.WriteRequestComplete, totalWritten));
                record.RecordType = ProgressRecordType.Completed;
                cmdlet.WriteProgress(record);
            }

            output.Flush();
        }
开发者ID:40a,项目名称:PowerShell,代码行数:37,代码来源:StreamHelper.cs


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