Skip to content

Commit

Permalink
Merge pull request #4 from gaurangisaxena/makadiri/object
Browse files Browse the repository at this point in the history
Makadiri/object
  • Loading branch information
gaurangisaxena authored Jul 24, 2019
2 parents 96c8367 + 6495f20 commit 8468bcd
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/DataShare/DataShare/DataSet/NewAzDataShareDataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ public override void ExecuteCmdlet()
StringComparison.OrdinalIgnoreCase))
{
storageAccountName = parsedStorageResourceId.GetAccountName();

if (this.ShouldProcess(this.Name, string.Format(Resources.ResourceCreateMessage, NewAzDataShareDataSet.ResourceType)))
{
if (this.FileName != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ public class StartAzDataShareSynchronization : AzureDataShareCmdletBase
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

/// <summary>
/// Data share subscription object
/// </summary>
[Parameter(
Mandatory = true,
ParameterSetName = ParameterSetNames.ObjectParameterSet,
ValueFromPipeline = true,
HelpMessage = "Azure data share subscription object")]
[ValidateNotNullOrEmpty]
public PSDataShareSubscription InputObject { get; set; }

[Parameter]
public SwitchParameter AsJob { get; set; }

Expand All @@ -123,21 +134,33 @@ private void StartSynchronization()
this.ShareSubscriptionName,
new Synchronize(this.SynchronizationMode));
this.WriteObject(synchronization.ToPsObject());
} catch (DataShareErrorException ex)
} catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.Conflict))
{
if (ex.Response.StatusCode.Equals(HttpStatusCode.Conflict)) {
throw new PSArgumentException($"Synchronization already in progress.");
}
throw new PSArgumentException($"Synchronization already in progress.");
}
}

private void SetParametersIfNeeded()
{
string resourceId = null;

if (this.ParameterSetName.Equals(
ParameterSetNames.ResourceIdParameterSet,
StringComparison.OrdinalIgnoreCase))
{
var parsedResourceId = new ResourceIdentifier(this.ResourceId);
resourceId = this.ResourceId;
}

if (this.ParameterSetName.Equals(
ParameterSetNames.ObjectParameterSet,
StringComparison.OrdinalIgnoreCase))
{
resourceId = this.InputObject.Id;
}

if (!string.IsNullOrEmpty(resourceId))
{
var parsedResourceId = new ResourceIdentifier(resourceId);
this.ResourceGroupName = parsedResourceId.ResourceGroupName;
this.AccountName = parsedResourceId.GetAccountName();
this.ShareSubscriptionName = parsedResourceId.GetShareSubscriptionName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ public class StopAzDataShareSubscriptionSynchronization : AzureDataShareCmdletBa
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

/// <summary>
/// Data share subscription object
/// </summary>
[Parameter(
Mandatory = true,
ParameterSetName = ParameterSetNames.ObjectParameterSet,
ValueFromPipeline = true,
HelpMessage = "Azure data share subscription object")]
[ValidateNotNullOrEmpty]
public PSDataShareSubscription InputObject { get; set; }

[Parameter]
public SwitchParameter AsJob { get; set; }

Expand Down Expand Up @@ -130,24 +141,33 @@ private void StopSynchronization()
shareSubscriptionSynchronization
);
this.WriteObject(synchronization.ToPsObject());
} catch (DataShareErrorException ex)
} catch (DataShareErrorException ex) when (ex.Response.StatusCode.Equals(HttpStatusCode.Conflict))
{
if (ex.Response.StatusCode.Equals(HttpStatusCode.Conflict)) {
throw new PSArgumentException($"Synchronization already in progress.");
} else
{
throw ex;
}
throw new PSArgumentException($"Synchronization already in progress.");
}
}

private void SetParametersIfNeeded()
{
string resourceId = null;

if (this.ParameterSetName.Equals(
ParameterSetNames.ResourceIdParameterSet,
StringComparison.OrdinalIgnoreCase))
{
var parsedResourceId = new ResourceIdentifier(this.ResourceId);
resourceId = this.ResourceId;
}

if (this.ParameterSetName.Equals(
ParameterSetNames.ObjectParameterSet,
StringComparison.OrdinalIgnoreCase))
{
resourceId = this.InputObject.Id;
}

if (!string.IsNullOrEmpty(resourceId))
{
var parsedResourceId = new ResourceIdentifier(resourceId);
this.ResourceGroupName = parsedResourceId.ResourceGroupName;
this.AccountName = parsedResourceId.GetAccountName();
this.ShareSubscriptionName = parsedResourceId.GetShareSubscriptionName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,10 @@ public override void ExecuteCmdlet()
shareName: this.ShareName,
synchronizationSettingName: this.Name) as ScheduledSynchronizationSetting;
this.WriteObject(setting.ToPsObject());
} catch (DataShareErrorException exception)
} catch (DataShareErrorException exception) when (exception.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
if (exception.Response.StatusCode.Equals(HttpStatusCode.NotFound))
{
throw new PSArgumentException(
$"Synchronization setting \"{this.Name}\" not found");
}
throw new PSArgumentException(
$"Synchronization setting \"{this.Name}\" not found");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ public class RemoveAzureDataShareSynchronizationSetting : AzureDataShareCmdletBa
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

/// <summary>
/// Share synchronization setting object.
/// </summary>
[Parameter(
Mandatory = true,
ParameterSetName = ParameterSetNames.ObjectParameterSet,
ValueFromPipeline = true,
HelpMessage = "The Azure Data Share Synchronization setting.")]
[ValidateNotNullOrEmpty]
public PSDataShareSynchronizationSetting InputObject { get; set; }

/// <summary>
/// Indicates whether you want to see deleted object or not
/// </summary>
Expand All @@ -106,14 +117,6 @@ public class RemoveAzureDataShareSynchronizationSetting : AzureDataShareCmdletBa
[Parameter]
public SwitchParameter AsJob { get; set; }

[Parameter(
Mandatory = true,
ParameterSetName = ParameterSetNames.ObjectParameterSet,
ValueFromPipeline = true,
HelpMessage = "The Azure Data Share Synchronization setting.")]
[ValidateNotNullOrEmpty]
public PSDataShareSynchronizationSetting InputObject { get; set; }

public override void ExecuteCmdlet()
{
string resourceId = null;
Expand Down

0 comments on commit 8468bcd

Please sign in to comment.