Skip to content

Commit

Permalink
Merge pull request #5 from gaurangisaxena/gasaxena/powershell
Browse files Browse the repository at this point in the history
use resource strings
  • Loading branch information
mkadiri3 authored Jul 25, 2019
2 parents 8468bcd + c8ab647 commit a21f588
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 91 deletions.
7 changes: 2 additions & 5 deletions src/DataShare/DataShare/Account/GetAzDataShareAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Microsoft.Azure.Commands.DataShare.Account
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Extensions;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Properties;
using Microsoft.Rest.Azure;

/// <summary>
Expand Down Expand Up @@ -134,11 +135,7 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
string.Format(
"Account not found",
this.Name,
this.ResourceGroupName));
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.Name));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Microsoft.Azure.Commands.DataShare.ConsumerInvitation
using Microsoft.Azure.Management.DataShare.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Extensions;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Properties;
using Microsoft.Rest.Azure;

/// <summary>
Expand Down Expand Up @@ -70,8 +71,7 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"ConsumerInvitation {this.InvitationId} not found");
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.InvitationId));
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/DataShare/DataShare/DataSet/GetAzDataShareDataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Microsoft.Azure.Commands.DataShare.DataSet
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Extensions;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Properties;
using Microsoft.Rest.Azure;

/// <summary>
Expand Down Expand Up @@ -117,8 +118,7 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"DataSet {this.Name} not found");
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.Name));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Microsoft.Azure.Commands.DataShare.DataSetMapping
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Extensions;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Properties;
using Microsoft.Rest.Azure;

/// <summary>
Expand Down Expand Up @@ -118,8 +119,7 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"DataSetMapping {this.Name} not found");
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.Name));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Microsoft.Azure.Commands.DataShare.Invitation
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Extensions;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Properties;
using Microsoft.Rest.Azure;

/// <summary>
Expand Down Expand Up @@ -119,8 +120,7 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"Invitation {this.Name} not found");
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.Name));
}
}
else
Expand Down
18 changes: 18 additions & 0 deletions src/DataShare/DataShare/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/DataShare/DataShare/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,18 @@
<data name="ResourceCreateMessage" xml:space="preserve">
<value>Creating '{0}'</value>
</data>
<data name="ResourceNotFoundMessage" xml:space="preserve">
<value>Resource '{0}' does not exist</value>
</data>
<data name="ResourceRemovalConfirmation" xml:space="preserve">
<value>Are you sure you want to remove resource '{0}'? </value>
</data>
<data name="ResourceRemovedMessage" xml:space="preserve">
<value>Removing resource '{0}'</value>
</data>
<data name="ResourceUpdataConfirmation" xml:space="preserve">
<value>Are you sure you want to update this resource?</value>
</data>
<data name="RevokeShareSubscriptionAccess" xml:space="preserve">
<value>Revoking access of share subscription</value>
</data>
Expand Down
4 changes: 2 additions & 2 deletions src/DataShare/DataShare/Share/GetAzDataShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Microsoft.Azure.Commands.DataShare.Share
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Extensions;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Properties;
using Microsoft.Rest.Azure;

/// <summary>
Expand Down Expand Up @@ -106,8 +107,7 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"Share {this.Name} not found");
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.Name));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Microsoft.Azure.Commands.DataShare.Share
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Extensions;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Properties;
using Microsoft.Rest.Azure;

/// <summary>
Expand Down Expand Up @@ -122,8 +123,7 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"ProviderShareSubscription {this.ShareSubscriptionId} not found");
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.ShareSubscriptionId));
}
}
else
Expand Down
6 changes: 2 additions & 4 deletions src/DataShare/DataShare/Share/SetAzDataShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,13 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
string.Format(
$"Share {this.Name} not found"));
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.Name));
}

if (this.Description != null || this.TermsOfUse != null)
{
this.ConfirmAction(
"Update resource",
Resources.ResourceUpdataConfirmation,
this.Name,
() => this.UpdateShare(existingShare));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Microsoft.Azure.Commands.DataShare.ShareSubscription
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Extensions;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Properties;
using Microsoft.Rest.Azure;

/// <summary>
Expand Down Expand Up @@ -108,8 +109,7 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"ShareSubscription {this.Name} not found");
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.Name));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Microsoft.Azure.Commands.DataShare.Synchronization
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Extensions;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Properties;
using Microsoft.Rest.Azure;

/// <summary>
Expand Down Expand Up @@ -141,8 +142,7 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"ShareSynchronizationDetails {this.ShareName} not found");
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.ShareName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Microsoft.Azure.Commands.DataShare.SourceDataSet
using System.Linq;
using System.Net;
using System.Management.Automation;
using Hyak.Common.Properties;
using Microsoft.Azure.Commands.DataShare.Common;
using Microsoft.Azure.Commands.DataShare.Helpers;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
Expand Down Expand Up @@ -80,6 +81,7 @@ public class GetAzDataShareSourceDataSet : AzureDataShareCmdletBase
ValueFromPipelineByPropertyName = true,
HelpMessage = "Azure data share subscription resource id",
ParameterSetName = ParameterSetNames.ResourceIdParameterSet)]
[ResourceIdCompleter(ResourceTypes.ShareSubscription)]
[ValidateNotNullOrEmpty]
public string ShareSubscriptionResourceId { get; set; }

Expand All @@ -98,32 +100,23 @@ public override void ExecuteCmdlet()
string nextPageLink = null;
var consumerSourceDataSetList = new List<ConsumerSourceDataSet>();

try
do
{
do
{
IPage<ConsumerSourceDataSet> sourceDataSets = string.IsNullOrEmpty(nextPageLink)
? this.DataShareManagementClient.ConsumerSourceDataSets.ListByShareSubscription(
this.ResourceGroupName,
this.AccountName,
this.ShareSubscriptionName)
: this.DataShareManagementClient.ConsumerSourceDataSets.ListByShareSubscriptionNext(
nextPageLink);
IPage<ConsumerSourceDataSet> sourceDataSets = string.IsNullOrEmpty(nextPageLink)
? this.DataShareManagementClient.ConsumerSourceDataSets.ListByShareSubscription(
this.ResourceGroupName,
this.AccountName,
this.ShareSubscriptionName)
: this.DataShareManagementClient.ConsumerSourceDataSets.ListByShareSubscriptionNext(
nextPageLink);

consumerSourceDataSetList.AddRange(sourceDataSets.AsEnumerable());
nextPageLink = sourceDataSets.NextPageLink;
} while (nextPageLink != null);
consumerSourceDataSetList.AddRange(sourceDataSets.AsEnumerable());
nextPageLink = sourceDataSets.NextPageLink;
} while (nextPageLink != null);

IEnumerable<PSDataShareSourceDataSet> dataSetsInShareSubscription =
consumerSourceDataSetList.Select(dataSet => dataSet.ToPsObject());
this.WriteObject(dataSetsInShareSubscription, true);

}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"Source DataSets not found for {this.ShareSubscriptionName}");
}
IEnumerable<PSDataShareSourceDataSet> dataSetsInShareSubscription =
consumerSourceDataSetList.Select(dataSet => dataSet.ToPsObject());
this.WriteObject(dataSetsInShareSubscription, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Microsoft.Azure.Commands.DataShare.Synchronization
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Extensions;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Models;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Properties;
using Microsoft.Rest.Azure;

/// <summary>
Expand Down Expand Up @@ -123,8 +124,7 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"Synchronization not found for {this.ShareSubscriptionName}");
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.ShareSubscriptionName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Microsoft.Azure.Commands.DataShare.Synchronization
using System.Linq;
using System.Management.Automation;
using System.Net;
using Hyak.Common.Properties;
using Microsoft.Azure.Commands.DataShare.Common;
using Microsoft.Azure.Commands.DataShare.Helpers;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
Expand All @@ -28,6 +29,7 @@ namespace Microsoft.Azure.Commands.DataShare.Synchronization
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Extensions;
using Microsoft.Azure.PowerShell.Cmdlets.DataShare.Models;
using Microsoft.Rest.Azure;
using Resources = Microsoft.Azure.PowerShell.Cmdlets.DataShare.Properties.Resources;

/// <summary>
/// Defines Get-AzDataShareSubscriptionSynchronizationDetail cmdlet.
Expand Down Expand Up @@ -143,8 +145,7 @@ public override void ExecuteCmdlet()
}
catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"ShareSubscriptionSynchronizationDetails {this.ShareSubscriptionName} not found");
throw new PSArgumentException(string.Format(Resources.ResourceNotFoundMessage, this.ShareSubscriptionName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,16 @@ public override void ExecuteCmdlet()

private void StartSynchronization()
{
var startFunc = (Func<string, string, string, Synchronize, ShareSubscriptionSynchronization>)this.DataShareManagementClient
.ShareSubscriptions.SynchronizeMethod;
try
{
var synchronization = startFunc(
this.ResourceGroupName,
this.AccountName,
this.ShareSubscriptionName,
new Synchronize(this.SynchronizationMode));
this.WriteObject(synchronization.ToPsObject());
} catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.Conflict))
{
throw new PSArgumentException($"Synchronization already in progress.");
}
var startFunc = (Func<string, string, string, Synchronize, ShareSubscriptionSynchronization>)this
.DataShareManagementClient
.ShareSubscriptions.SynchronizeMethod;

var synchronization = startFunc(
this.ResourceGroupName,
this.AccountName,
this.ShareSubscriptionName,
new Synchronize(this.SynchronizationMode));
this.WriteObject(synchronization.ToPsObject());
}

private void SetParametersIfNeeded()
Expand Down
Loading

0 comments on commit a21f588

Please sign in to comment.