Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Common/AzurePSCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable
IAzureEventListener _azureEventListener;
protected static ConcurrentQueue<string> InitializationWarnings { get; set; } = new ConcurrentQueue<string>();

protected static ConcurrentQueue<string> PromptedPreviewMessageCmdlets { get; set; } = new ConcurrentQueue<string>();

private RecordingTracingInterceptor _httpTracingInterceptor;
private object lockObject = new object();
private AzurePSDataCollectionProfile _cachedProfile = null;
Expand Down Expand Up @@ -378,7 +380,17 @@ private void WriteBreakingChangeOrPreviewMessage()
&& configManager.GetConfigValue<bool>(ConfigKeysForCommon.DisplayBreakingChangeWarning))
{
BreakingChangeAttributeHelper.ProcessCustomAttributesAtRuntime(this.GetType(), this.MyInvocation, WriteWarning);
PreviewAttributeHelper.ProcessCustomAttributesAtRuntime(this.GetType(), this.MyInvocation, WriteDebug);

// Write preview message once for each cmdlet in one session
// Preview message may be outputed more than once if a cmdlet is concurrently called
// Considering lock affects performance but warning message is no harm
if (this.MyInvocation?.MyCommand != null
&& !PromptedPreviewMessageCmdlets.Contains(this.MyInvocation?.MyCommand?.Name)
&& PreviewAttributeHelper.ContainsPreviewAttribute(this.GetType(), this.MyInvocation))
{
PreviewAttributeHelper.ProcessCustomAttributesAtRuntime(this.GetType(), this.MyInvocation, WriteWarning);
PromptedPreviewMessageCmdlets.Enqueue(this.MyInvocation.MyCommand.Name);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>true</DesignTime>
<DesignTime>True</DesignTime>
<AutoGen>true</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
Expand Down
30 changes: 29 additions & 1 deletion src/Common/CustomAttributes/CmdletPreviewAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using Microsoft.WindowsAzure.Commands.Common.Properties;
using System;
using System.Globalization;
using System.Management.Automation;

namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
Expand All @@ -25,19 +26,46 @@ public class CmdletPreviewAttribute : System.Attribute
{
public string _message;

/// <summary>
/// EstimatedGaDate assumes value follows "en-US" culture,
/// which means dates are written in the month–day–year order like
/// July 19, 2023, 19 July 2023, 07/19/2023 or 2023-07-19
/// </summary>
public DateTime EstimatedGaDate { get; }

public bool IsEstimatedGaDateSet { get; } = false;

public CmdletPreviewAttribute()
{
this._message = Resources.PreviewCmdletMessage;
}

public CmdletPreviewAttribute(string message)
{
this._message = message;
this._message = string.IsNullOrEmpty(message) ? Resources.PreviewCmdletMessage : message;
}

/// <summary>
/// Constructor with message and estimated GA date
/// </summary>
/// <param name="message">Customized preview message</param>
/// <param name="estimatedGaDate">EstimatedGaDate assumes value follows "en-US" culture, which means dates are written in the month–day–year order</param>
public CmdletPreviewAttribute(string message, string estimatedGaDate) : this(message)
{
if (DateTime.TryParse(estimatedGaDate, new CultureInfo("en-US"), DateTimeStyles.None, out DateTime result))
{
this.EstimatedGaDate = result;
this.IsEstimatedGaDateSet = true;
}
}

public void PrintCustomAttributeInfo(Action<string> writeOutput)
{
writeOutput(this._message);
if (IsEstimatedGaDateSet)
{
writeOutput(string.Format(Resources.PreviewCmdletETAMessage, this.EstimatedGaDate.ToShortDateString()));
}
}

public virtual bool IsApplicableToInvocation(InvocationInfo invocation)
Expand Down
4 changes: 2 additions & 2 deletions src/Common/CustomAttributes/GenericBreakingChangeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public string GetBreakingChangeTextFromAttribute(Type type, bool withCmdletName)

if (ChangeInEfectByDateSet)
{
breakingChangeMessage.Append(string.Format(Resources.BreakingChangesAttributesInEffectByDateMessage, this.ChangeInEfectByDate));
breakingChangeMessage.Append(string.Format(Resources.BreakingChangesAttributesInEffectByDateMessage, this.ChangeInEfectByDate.ToShortDateString()));
}

if (DeprecateByVersionSet)
Expand Down Expand Up @@ -147,7 +147,7 @@ public void PrintCustomAttributeInfo(Type type, bool withCmdletName, Action<stri

if (ChangeInEfectByDateSet)
{
writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByDateMessage, this.ChangeInEfectByDate));
writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByDateMessage, this.ChangeInEfectByDate.ToShortDateString()));
}

if (DeprecateByVersionSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public string GetBreakingChangeTextFromAttribute(Type type, bool withCmdletName)

if (ChangeInEffectByDateSet)
{
breakingChangeMessage.Append(string.Format(Resources.BreakingChangesAttributesInEffectByDateMessage, this.ChangeInEffectByDate));
breakingChangeMessage.Append(string.Format(Resources.BreakingChangesAttributesInEffectByDateMessage, this.ChangeInEffectByDate.ToShortDateString()));
}

if (!string.IsNullOrWhiteSpace(DeprecateByVersion))
Expand Down Expand Up @@ -144,7 +144,7 @@ public void PrintCustomAttributeInfo(Type type, bool withCmdletName, Action<stri

if (ChangeInEffectByDateSet)
{
writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByDateMessage, this.ChangeInEffectByDate));
writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByDateMessage, this.ChangeInEffectByDate.ToShortDateString()));
}

writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByAzVersion, this.DeprecateByAzVersion));
Expand Down
18 changes: 17 additions & 1 deletion src/Common/CustomAttributes/PreviewAttributeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Linq;
using System.Management.Automation;
using System.Reflection;
using System.Text;

namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
{
Expand All @@ -33,16 +34,31 @@ internal class PreviewAttributeHelper
public static void ProcessCustomAttributesAtRuntime(Type type, InvocationInfo invocationInfo, Action<string> writeOutput)
{
List<CmdletPreviewAttribute> attributes = new List<CmdletPreviewAttribute>(GetAllAttributesInType(type, invocationInfo));
StringBuilder sb = new StringBuilder().Clear();
Action<string> appendPreviewMessage = (string s) => sb.Append(s);

if (attributes != null && attributes.Count > 0)
{
foreach (CmdletPreviewAttribute attribute in attributes)
{
attribute.PrintCustomAttributeInfo(writeOutput);
attribute.PrintCustomAttributeInfo(appendPreviewMessage);
}
writeOutput(sb.ToString());

}
}

/// <summary>
/// Process CmdletExperimentation attribute in runtime
/// </summary>
/// <param name="type"></param>
/// <param name="invocationInfo"></param>
/// <param name="writeOutput"></param>
public static bool ContainsPreviewAttribute(Type type, InvocationInfo invocationInfo)
{
return GetAllAttributesInType(type, invocationInfo).Count() > 0;
}

private static IEnumerable<CmdletPreviewAttribute> GetAllAttributesInType(Type type, InvocationInfo invocationInfo)
{
List<CmdletPreviewAttribute> attributeList = new List<CmdletPreviewAttribute>();
Expand Down
Loading