示例#1
0
        public override void ExecuteCmdlet()
        {
            PSMongoIndex pSMongoIndex = new PSMongoIndex();

            if (Key != null && Key.Length > 0)
            {
                pSMongoIndex.Key = new PSMongoIndexKeys
                {
                    Keys = new List <string>()
                };

                foreach (string key in Key)
                {
                    pSMongoIndex.Key.Keys.Add(key);
                }
            }

            if (TtlInSeconds != null || Unique != null)
            {
                pSMongoIndex.Options = new PSMongoIndexOptions
                {
                    ExpireAfterSeconds = TtlInSeconds,
                    Unique             = Unique
                };
            }

            WriteObject(pSMongoIndex);
            return;
        }
示例#2
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                DatabaseName      = resourceIdentifier.ResourceName;
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
            }

            MongoDBCollectionResource mongoDBCollectionResource = new MongoDBCollectionResource
            {
                Id = Name
            };

            if (Shard != null)
            {
                mongoDBCollectionResource.ShardKey = new Dictionary <string, string> {
                    { Shard, "Hash" }
                };
            }

            if (Index != null)
            {
                List <MongoIndex> Indexes = new List <MongoIndex>();
                foreach (PSMongoIndex psMongoIndex in Index)
                {
                    Indexes.Add(PSMongoIndex.ConvertPSMongoIndexToMongoIndex(psMongoIndex));
                }

                mongoDBCollectionResource.Indexes = Indexes;
            }

            CreateUpdateOptions options = new CreateUpdateOptions();

            if (Throughput != null)
            {
                options.Throughput = Throughput.ToString();
            }

            MongoDBCollectionCreateUpdateParameters mongoDBCollectionCreateUpdateParameters = new MongoDBCollectionCreateUpdateParameters
            {
                Resource = mongoDBCollectionResource,
                Options  = options
            };

            if (ShouldProcess(Name, "Setting CosmosDB MongoDB Collection"))
            {
                MongoDBCollectionGetResults mongoDBCollectionGetResults = CosmosDBManagementClient.MongoDBResources.CreateUpdateMongoDBCollectionWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, mongoDBCollectionCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSMongoDBCollectionGetResults(mongoDBCollectionGetResults));
            }

            return;
        }
示例#3
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                DatabaseName      = resourceIdentifier.ResourceName;
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
            }
            else if (ParameterSetName.Equals(ObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                Name         = resourceIdentifier.ResourceName;
                DatabaseName = ResourceIdentifierExtensions.GetMongoDBDatabaseName(resourceIdentifier);
                AccountName  = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
            }

            MongoDBCollectionGetResults readMongoDBCollectionGetResults = null;

            try
            {
                readMongoDBCollectionGetResults = CosmosDBManagementClient.MongoDBResources.GetMongoDBCollection(ResourceGroupName, AccountName, DatabaseName, Name);
            }
            catch (CloudException e)
            {
                if (e.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new ResourceNotFoundException(message: string.Format(ExceptionMessage.NotFound, Name), innerException: e);
                }
            }

            MongoDBCollectionResource mongoDBCollectionResource = PopulateMongoDBResource(readMongoDBCollectionGetResults.Resource);

            if (Shard != null)
            {
                mongoDBCollectionResource.ShardKey = new Dictionary <string, string> {
                    { Shard, "Hash" }
                };
            }

            if (Index != null)
            {
                List <MongoIndex> Indexes = new List <MongoIndex>();
                foreach (PSMongoIndex psMongoIndex in Index)
                {
                    Indexes.Add(PSMongoIndex.ToSDKModel(psMongoIndex));
                }

                mongoDBCollectionResource.Indexes = Indexes;
            }

            if (AnalyticalStorageTtl != null)
            {
                mongoDBCollectionResource.AnalyticalStorageTtl = AnalyticalStorageTtl;
            }

            CreateUpdateOptions options = ThroughputHelper.PopulateCreateUpdateOptions(Throughput, AutoscaleMaxThroughput);

            MongoDBCollectionCreateUpdateParameters mongoDBCollectionCreateUpdateParameters = new MongoDBCollectionCreateUpdateParameters
            {
                Resource = mongoDBCollectionResource,
                Options  = options
            };

            if (ShouldProcess(Name, "Updating an existing CosmosDB MongoDB Collection"))
            {
                MongoDBCollectionGetResults mongoDBCollectionGetResults = CosmosDBManagementClient.MongoDBResources.CreateUpdateMongoDBCollectionWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, mongoDBCollectionCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSMongoDBCollectionGetResults(mongoDBCollectionGetResults));
            }

            return;
        }