Beispiel #1
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (ShouldProcess(this.StorageAccountName, "Set Storage Account Object Replication Policy"))
            {
                ObjectReplicationPolicy policyToSet = null;
                switch (ParameterSetName)
                {
                case AccountObjectParameterSet:
                    this.ResourceGroupName  = StorageAccount.ResourceGroupName;
                    this.StorageAccountName = StorageAccount.StorageAccountName;
                    break;

                case PolicyObjectParameterSet:
                    this.PolicyId = InputObject.PolicyId;
                    policyToSet   = InputObject.ParseObjectReplicationPolicy();
                    break;

                default:
                    // For AccountNameParameterSet, the ResourceGroupName and StorageAccountName can get from input directly
                    break;
                }

                // Build the policy object to set from the input policy properties
                if (ParameterSetName != PolicyObjectParameterSet)
                {
                    // If not specify the destination account, will set destination account to the account which the policy will be set to
                    if (string.IsNullOrWhiteSpace(this.DestinationAccount))
                    {
                        // If source account is resource ID, destonation account also need be resource ID
                        if (this.SourceAccount.Contains("/"))
                        {
                            var account = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.StorageAccountName);
                            this.DestinationAccount = account.Id;
                        }
                        else // if source account is account name, destination account should also be account name
                        {
                            this.DestinationAccount = this.StorageAccountName;
                        }
                    }

                    policyToSet = new ObjectReplicationPolicy()
                    {
                        SourceAccount      = this.SourceAccount,
                        DestinationAccount = this.DestinationAccount,
                        Rules = PSObjectReplicationPolicyRule.ParseObjectReplicationPolicyRules(this.Rule)
                    };
                }

                ObjectReplicationPolicy policy = this.StorageClient.ObjectReplicationPolicies.CreateOrUpdate(
                    this.ResourceGroupName,
                    this.StorageAccountName,
                    PolicyId,
                    policyToSet);

                WriteObject(new PSObjectReplicationPolicy(policy, this.ResourceGroupName, this.StorageAccountName));
            }
        }
Beispiel #2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            string[] blobType = new string[] { AzureBlobType.BlockBlob };
            PSObjectReplicationPolicyRule rule = new PSObjectReplicationPolicyRule()
            {
                RuleId               = this.RuleId,
                SourceContainer      = this.SourceContainer,
                DestinationContainer = this.DestinationContainer
            };

            if (this.PrefixMatch != null || minCreationTime != null)
            {
                rule.Filters = new PSObjectReplicationPolicyFilter()
                {
                    PrefixMatch     = this.PrefixMatch,
                    MinCreationTime = this.minCreationTime,
                };
            }

            WriteObject(rule);
        }