|
18 | 18 | using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
|
19 | 19 | using Microsoft.Azure.ServiceManagemenet.Common.Models;
|
20 | 20 | using Microsoft.WindowsAzure.Commands.Common;
|
| 21 | +using Microsoft.WindowsAzure.Commands.Utilities.Common; |
21 | 22 | using System;
|
22 | 23 | using System.Collections.Concurrent;
|
23 | 24 | using System.Diagnostics;
|
@@ -688,22 +689,78 @@ protected override void ProcessRecord()
|
688 | 689 | }
|
689 | 690 | }
|
690 | 691 |
|
| 692 | + private string _implementationBackgroundJobDescription; |
| 693 | + |
691 | 694 | /// <summary>
|
692 | 695 | /// Job Name paroperty iof this cmdlet is run as a job
|
693 | 696 | /// </summary>
|
694 | 697 | public virtual string ImplementationBackgroundJobDescription
|
695 | 698 | {
|
696 | 699 | get
|
697 | 700 | {
|
698 |
| - string name = "Long Running Azure Operation"; |
699 |
| - string commandName = MyInvocation?.MyCommand?.Name; |
700 |
| - if (!string.IsNullOrWhiteSpace(commandName)) |
| 701 | + if (_implementationBackgroundJobDescription != null) |
701 | 702 | {
|
702 |
| - name = string.Format("Long Running Operation for '{0}'", commandName); |
| 703 | + return _implementationBackgroundJobDescription; |
703 | 704 | }
|
| 705 | + else |
| 706 | + { |
| 707 | + string name = "Long Running Azure Operation"; |
| 708 | + string commandName = MyInvocation?.MyCommand?.Name; |
| 709 | + string objectName = null; |
| 710 | + if (this.IsBound("Name")) |
| 711 | + { |
| 712 | + objectName = MyInvocation.BoundParameters["Name"].ToString(); |
| 713 | + } |
| 714 | + else if (this.IsBound("InputObject") == true) |
| 715 | + { |
| 716 | + var type = MyInvocation.BoundParameters["InputObject"].GetType(); |
| 717 | + var inputObject = Convert.ChangeType(MyInvocation.BoundParameters["InputObject"], type); |
| 718 | + if (type.GetProperty("Name") != null) |
| 719 | + { |
| 720 | + objectName = inputObject.GetType().GetProperty("Name").GetValue(inputObject).ToString(); |
| 721 | + } |
| 722 | + else if (type.GetProperty("ResourceId") != null) |
| 723 | + { |
| 724 | + string[] tokens = inputObject.GetType().GetProperty("ResourceId").GetValue(inputObject).ToString().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); |
| 725 | + if (tokens.Length >= 8) |
| 726 | + { |
| 727 | + objectName = tokens[tokens.Length - 1]; |
| 728 | + } |
| 729 | + } |
| 730 | + } |
| 731 | + else if (this.IsBound("ResourceId") == true) |
| 732 | + { |
| 733 | + string[] tokens = MyInvocation.BoundParameters["ResourceId"].ToString().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); |
| 734 | + if (tokens.Length >= 8) |
| 735 | + { |
| 736 | + objectName = tokens[tokens.Length - 1]; |
| 737 | + } |
| 738 | + } |
| 739 | + |
| 740 | + if (!string.IsNullOrWhiteSpace(commandName)) |
| 741 | + { |
| 742 | + if (!string.IsNullOrWhiteSpace(objectName)) |
| 743 | + { |
| 744 | + name = string.Format("Long Running Operation for '{0}' on resource '{1}'", commandName, objectName); |
| 745 | + } |
| 746 | + else |
| 747 | + { |
| 748 | + name = string.Format("Long Running Operation for '{0}'", commandName); |
| 749 | + } |
| 750 | + } |
704 | 751 |
|
705 |
| - return name; |
| 752 | + return name; |
| 753 | + } |
706 | 754 | }
|
| 755 | + set |
| 756 | + { |
| 757 | + _implementationBackgroundJobDescription = value; |
| 758 | + } |
| 759 | + } |
| 760 | + |
| 761 | + public void SetBackgroundJobDescription(string jobName) |
| 762 | + { |
| 763 | + ImplementationBackgroundJobDescription = jobName; |
707 | 764 | }
|
708 | 765 |
|
709 | 766 | protected virtual void Dispose(bool disposing)
|
|
0 commit comments