예제 #1
0
        protected override void ProcessRecord()
        {
            //Check the objectType in MoBaseMo.ObjectTypeEnum if it belongs to that enum
            //fetch the display name.
            //this is done to work with specific Get cmdlets.
            // Get-IntersightNtpPoicy -Name xxxx | Remove-IntersightManagedObject
            var result = PSUtils.GetObjectTypeDisplayName(ObjectType);

            if (!string.IsNullOrEmpty(result))
            {
                ObjectType = result;
            }

            var psClient = new PSHttpClient(CmdletBase.Config);
            PSRequestOptions psRequestOption = new PSRequestOptions
            {
                BasePath = CmdletBase.Config.BasePath,
                Path     = string.Format("/api/v1/{0}/{{Moid}}", PSUtils.GetPath(ObjectType)),
                Method   = "Delete",
            };

            psRequestOption.PathParameters.Add(PSUtils.Moid, Moid);
            var response = psClient.Execute(psRequestOption);

            WriteObject(response);
        }
        protected override void ProcessRecord()
        {
            //Check the objectType in MoBaseMo.ObjectTypeEnum if it belongs to that enum
            //fetch the display name.
            //this is done to work with specific Get cmdlets.
            // Get-IntersightNtpPoicy -Name xxxx | Set-IntersightManagedObject
            var result = PSUtils.GetObjectTypeDisplayName(ObjectType);

            if (!string.IsNullOrEmpty(result))
            {
                ObjectType = result;
            }

            var psClient = new PSHttpClient(CmdletBase.Config);
            PSRequestOptions psRequestOption = new PSRequestOptions
            {
                BasePath = CmdletBase.Config.BasePath,
                Method   = "POST",
            };

            if (ParameterSetName == PSUtils.CmdletParam)
            {
                psRequestOption.RequestData = JsonConvert.SerializeObject(AdditionalProperties, Formatting.Indented);
            }
            else
            {
                var tempHashTable = JsonConvert.DeserializeObject <Hashtable>(JsonRequestBody);
                if (tempHashTable.ContainsKey(PSUtils.ObjectType))
                {
                    ObjectType = tempHashTable[PSUtils.ObjectType].ToString();
                }
                else
                {
                    throw new Exception(string.Format("Property {0} is missing in JsonRequestBody", PSUtils.ObjectType));
                }

                if (tempHashTable.ContainsKey(PSUtils.Moid))
                {
                    Moid = tempHashTable[PSUtils.Moid].ToString();
                }
                else
                {
                    throw new Exception(string.Format("Property {0} is missing in JsonRequestBody", PSUtils.Moid));
                }

                psRequestOption.RequestData = JsonRequestBody;
            }

            psRequestOption.PathParameters.Add(PSUtils.Moid, Moid);
            psRequestOption.Path = string.Format("/api/v1/{0}/{{Moid}}", PSUtils.GetPath(ObjectType));
            var response = psClient.Execute(psRequestOption);

            WriteObject(response);
        }
        protected override void ProcessRecord()
        {
            //Check the objectType in MoBaseMo.ObjectTypeEnum if it belongs to that enum
            //fetch the display name.
            //this is done to work with specific Get cmdlets.
            // Get-IntersightNtpPoicy -Name xxxx | Set-IntersightManagedObject
            var result = PSUtils.GetObjectTypeDisplayName(ObjectType);

            if (!string.IsNullOrEmpty(result))
            {
                ObjectType = result;
            }

            var psClient = new PSHttpClient(CmdletBase.Config);
            PSRequestOptions psRequestOption = new PSRequestOptions
            {
                BasePath    = CmdletBase.Config.BasePath,
                Method      = "PATCH",
                ContentType = "application/json-patch+json"
            };

            if (ParameterSetName == PSUtils.CmdletParam)
            {
                psRequestOption.RequestData = JsonConvert.SerializeObject(PatchDocument, Formatting.Indented);
            }
            else
            {
                var tempHashTable = JsonConvert.DeserializeObject <List <PatchDocument> >(JsonPatchDocument);
                psRequestOption.RequestData = JsonPatchDocument;
            }

            psRequestOption.PathParameters.Add(PSUtils.Moid, Moid);
            psRequestOption.Path = string.Format("/api/v1/{0}/{{Moid}}", PSUtils.GetPath(ObjectType));
            var response = psClient.Execute(psRequestOption);

            WriteObject(response);
        }
        protected override void ProcessRecord()
        {
            // ExecuteRequestAsync(string.Format("/api/v1/{0}",ObjectType));

            //Check the objectType in MoBaseMo.ObjectTypeEnum if it belongs to that enum
            //fetch the display name.
            //this is done to work with specific Get cmdlets.
            // Get-IntersightNtpPoicy -Name xxxx | Get-IntersightManagedObject
            var result = PSUtils.GetObjectTypeDisplayName(ObjectType);

            if (!string.IsNullOrEmpty(result))
            {
                ObjectType = result;
            }

            var psClient = new PSHttpClient(CmdletBase.Config);
            PSRequestOptions psRequestOption = new PSRequestOptions
            {
                BasePath = CmdletBase.Config.BasePath,
                Path     = string.Format("/api/v1/{0}", PSUtils.GetPath(ObjectType)),
                Method   = "Get",
            };

            if (ParameterSetName == "CmdletParam")
            {
                string queryStr = string.Empty;
                var    index    = 0;
                foreach (var item in this.MyInvocation.BoundParameters)
                {
                    if (item.Key == "ObjectType")
                    {
                        continue;
                    }
                    if (index != 0)
                    {
                        queryStr += " and ";
                    }
                    queryStr += string.Format("{0} eq \'{1}\'", item.Key, item.Value);
                    index++;
                }

                if (!string.IsNullOrEmpty(queryStr))
                {
                    psRequestOption.QueryParameters.Add("$filter", queryStr);
                }
            }
            else if (ParameterSetName == "QueryParam")
            {
                foreach (var item in this.MyInvocation.BoundParameters)
                {
                    if (item.Key == "ObjectType")
                    {
                        continue;
                    }

                    psRequestOption.QueryParameters.Add(string.Concat("$", item.Key.ToLower()), item.Value.ToString());
                }
            }

            var response = psClient.Execute(psRequestOption);

            if (!string.IsNullOrEmpty(response))
            {
                Dictionary <string, object> responseData = JsonConvert.DeserializeObject <Dictionary <string, object> >(response);
                if (ParameterSetName == "CmdletParam" && responseData.ContainsKey("Results"))
                {
                    var moList = JsonConvert.SerializeObject(responseData["Results"], Formatting.Indented);
                    WriteObject(moList);
                }
                else
                {
                    WriteObject(response);
                }
            }
        }