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


C# Cmdlet.WriteProgress方法代码示例

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


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

示例1: Handle

 /// <summary>
 /// Output a message in the appropriate way in a powershell command
 /// </summary>
 /// <param name="caller">the Cmdlet object running</param>
 /// <param name="e">the event containing the message</param>
 public static void Handle(Cmdlet caller, MessageEventArgs e)
 {
     switch (e.MessageType)
     {
         case MessageType.Verbose:
             caller.WriteVerbose(e.Message);
             break;
         case MessageType.Progress:
             caller.WriteProgress(new ProgressRecord(0, e.Activity, e.Message));
             break;
         case MessageType.Error:
             ToolsHelper.WriteException(caller, e.Exception);
             caller.ThrowTerminatingError(new ErrorRecord(e.Exception, "0", ErrorCategory.InvalidOperation, caller));
             break;
         case MessageType.Output:
             caller.WriteObject(e.Message);
             break;
     }
 }
开发者ID:jamesej,项目名称:lynicon,代码行数:24,代码来源:MessageHandler.cs

示例2: UpdateProgress

 /// <summary>
 /// Updates the progress in a friendly way in the event that we are not running in PowerShell
 /// </summary>
 /// <param name="progress">The progress record to use when sending out the update.</param>
 /// <param name="cmdletRunningRequest">The command running the request, if any</param>
 private void UpdateProgress(ProgressRecord progress, Cmdlet cmdletRunningRequest = null)
 {
     if (cmdletRunningRequest != null)
     {
         cmdletRunningRequest.WriteProgress(progress);
     }
     else
     {
         Console.WriteLine(
             @"Performing action: {0}. Details: {1}. Percent Complete: {2}%",
             progress.Activity,
             progress.StatusDescription,
             progress.PercentComplete);
     }
 }
开发者ID:singhkays,项目名称:azure-powershell,代码行数:20,代码来源:DataLakeStoreFileSystemClient.cs

示例3: TrackUploadProgress

        /// <summary>
        /// Tracks the upload progress in the PowerShell console.
        /// </summary>
        /// <param name="uploadTask">The task that tracks the upload.</param>
        /// <param name="uploadProgress">The upload progress that will be displayed in the console.</param>
        private void TrackUploadProgress(Task uploadTask, ProgressRecord uploadProgress,
            Cmdlet commandToUpdateProgressFor, CancellationToken token)
        {
            // Update the UI with the progress.
            var lastUpdate = DateTime.Now.Subtract(TimeSpan.FromSeconds(2));
            while (!uploadTask.IsCompleted && !uploadTask.IsCanceled)
            {
                if (token.IsCancellationRequested)
                {
                    // we are done tracking progress and will just break and let the task clean itself up.
                    try
                    {
                        uploadTask.Wait();
                    }
                    catch (OperationCanceledException)
                    {
                        if (uploadTask.IsCanceled)
                        {
                            uploadTask.Dispose();
                        }
                    }
                    catch (AggregateException ex)
                    {
                        if (ex.InnerExceptions.OfType<OperationCanceledException>().Any())
                        {
                            if (uploadTask.IsCanceled)
                            {
                                uploadTask.Dispose();
                            }
                        }
                        else
                        {
                            throw;
                        }
                    }
                    break;
                }

                if (DateTime.Now - lastUpdate > TimeSpan.FromSeconds(1))
                {
                    lock (ConsoleOutputLock)
                    {
                        if (commandToUpdateProgressFor != null && !token.IsCancellationRequested &&
                            !commandToUpdateProgressFor.Stopping)
                        {
                            commandToUpdateProgressFor.WriteProgress(uploadProgress);
                        }
                    }
                }

                TestMockSupport.Delay(250);
            }

            if (uploadTask.IsCanceled || token.IsCancellationRequested)
            {
                uploadProgress.RecordType = ProgressRecordType.Completed;
            }
            else if (uploadTask.IsFaulted && uploadTask.Exception != null)
            {
                // If there are errors, raise them to the user.
                if (uploadTask.Exception.InnerException != null)
                {
                    // we only go three levels deep. This is the Inception rule.
                    if (uploadTask.Exception.InnerException.InnerException != null)
                    {
                        throw uploadTask.Exception.InnerException.InnerException;
                    }

                    throw uploadTask.Exception.InnerException;
                }

                throw uploadTask.Exception;
            }
            else
            {
                // finally execution is finished, set progress state to completed.
                uploadProgress.PercentComplete = 100;
                uploadProgress.RecordType = ProgressRecordType.Completed;

                if (commandToUpdateProgressFor != null)
                {
                    commandToUpdateProgressFor.WriteProgress(uploadProgress);
                }
            }
        }
开发者ID:singhkays,项目名称:azure-powershell,代码行数:90,代码来源:DataLakeStoreFileSystemClient.cs

示例4: PreviewFile

        public Stream PreviewFile(string filePath, string accountName, long bytesToPreview,
            CancellationToken cmdletCancellationToken, Cmdlet cmdletRunningRequest = null)
        {
            var lengthToUse = GetFileStatus(filePath, accountName).Length.Value;
            if (bytesToPreview <= lengthToUse && bytesToPreview > 0)
            {
                lengthToUse = bytesToPreview;
            }

            var numRequests = Math.Ceiling(lengthToUse/MaximumBytesPerDownloadRequest);

            var byteStream = new MemoryStream();
            var progress = new ProgressRecord(
                0,
                "Previewing a file from DataLakeStore Store",
                string.Format("Previewing file in DataLakeStore Store Location: {0}. Bytes to preview: {1}", filePath,
                    bytesToPreview));
            long currentOffset = 0;
            var bytesToRequest = (long) MaximumBytesPerDownloadRequest;

            //TODO: defect: 4259238 (located here: http://vstfrd:8080/Azure/RD/_workitems/edit/4259238) needs to be resolved or the tracingadapter work around needs to be put back in
            for (long i = 0; i < numRequests; i++)
            {
                cmdletCancellationToken.ThrowIfCancellationRequested();
                progress.PercentComplete = (int) Math.Ceiling((i/numRequests)*100);
                UpdateProgress(progress, cmdletRunningRequest);

                if (lengthToUse < bytesToRequest)
                {
                    bytesToRequest = lengthToUse;
                }
                else
                {
                    lengthToUse -= bytesToRequest;
                }

                var responseStream =
                    ReadFromFile(
                        filePath,
                        accountName,
                        currentOffset,
                        bytesToRequest);

                responseStream.CopyTo(byteStream);
                currentOffset += bytesToRequest;
            }

            // final update to 100% completion
            if (cmdletRunningRequest != null && !cmdletCancellationToken.IsCancellationRequested)
            {
                progress.PercentComplete = 100;
                progress.RecordType = ProgressRecordType.Completed;
                cmdletRunningRequest.WriteProgress(progress);
            }

            return byteStream;
        }
开发者ID:singhkays,项目名称:azure-powershell,代码行数:57,代码来源:DataLakeStoreFileSystemClient.cs

示例5: DownloadFile

        public void DownloadFile(string filePath, string accountName, string destinationFilePath,
            CancellationToken cmdletCancellationToken, bool overwrite = false, Cmdlet cmdletRunningRequest = null)
        {
            if (File.Exists(destinationFilePath) && overwrite)
            {
                File.Delete(destinationFilePath);
            }

            if (File.Exists(destinationFilePath) && !overwrite)
            {
                throw new IOException(string.Format(Properties.Resources.LocalFileAlreadyExists, destinationFilePath));
            }
            // create all of the directories along the way.
            if (!Directory.Exists(Path.GetDirectoryName(destinationFilePath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));
            }

            var lengthToUse = GetFileStatus(filePath, accountName).Length.Value;
            var numRequests = Math.Ceiling(lengthToUse/MaximumBytesPerDownloadRequest);

            using (var fileStream = new FileStream(destinationFilePath, FileMode.CreateNew))
            {
                var progress = new ProgressRecord(
                    0,
                    "Download from DataLakeStore Store",
                    string.Format("Downloading File in DataLakeStore Store Location: {0} to destination path: {1}",
                        filePath, destinationFilePath));
                long currentOffset = 0;
                var bytesToRequest = (long) MaximumBytesPerDownloadRequest;
                
                //TODO: defect: 4259238 (located here: http://vstfrd:8080/Azure/RD/_workitems/edit/4259238) needs to be resolved or the tracingadapter work around needs to be put back in
                for (long i = 0; i < numRequests; i++)
                {
                    cmdletCancellationToken.ThrowIfCancellationRequested();
                    progress.PercentComplete = (int) Math.Ceiling((i/numRequests)*100);
                    UpdateProgress(progress, cmdletRunningRequest);
                    var responseStream =
                        ReadFromFile(
                            filePath,
                            accountName,
                            currentOffset,
                            bytesToRequest);
                        
                    responseStream.CopyTo(fileStream);
                    currentOffset += bytesToRequest;
                }

                // final update to 100% completion
                if (cmdletRunningRequest != null && !cmdletCancellationToken.IsCancellationRequested)
                {
                    progress.PercentComplete = 100;
                    progress.RecordType = ProgressRecordType.Completed;
                    cmdletRunningRequest.WriteProgress(progress);
                }
            }
        }
开发者ID:singhkays,项目名称:azure-powershell,代码行数:57,代码来源:DataLakeStoreFileSystemClient.cs


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