Beispiel #1
0
        /// <summary>
        /// This is implementation for Get cmdlet: all instances, single instance, Get on associations
        /// </summary>
        /// <param name="query"></param>
        public override void ProcessRecord(QueryBuilder query)
        {
            ODataQueryBuilder odataQuery = query as ODataQueryBuilder;

            if (!this.PassInnerException.IsPresent)
            {
                string passInnerExceptionKey = "PassInnerException";
                if (PrivateData.ContainsKey(passInnerExceptionKey))
                {
                    string PassInnerExceptionValue = PrivateData[passInnerExceptionKey];
                    this.PassInnerException = PassInnerExceptionValue.Equals("True", StringComparison.OrdinalIgnoreCase);
                }
            }

            string parentTypeName       = this.Cmdlet.ParameterSetName;
            string privateDataEntryName = "NavigationLink" + parentTypeName;

            if (PrivateData.ContainsKey(privateDataEntryName))
            {
                string parent = PrivateData[privateDataEntryName];

                string[] parentParts        = parent.Split('|');
                string   parentPropertyName = parentParts[2];

                System.Management.Automation.PSObject[] argumentObjects = (System.Management.Automation.PSObject[]) this.Cmdlet.MyInvocation.BoundParameters[parentTypeName];

                foreach (System.Management.Automation.PSObject parentObject in argumentObjects)
                {
                    bool isCollection = parentParts[parentParts.Length - 1].Equals("Collection", StringComparison.OrdinalIgnoreCase);

                    if (isCollection)
                    {
                        object[] parentPropertyObjectArray = (object[])parentObject.Properties[parentPropertyName].Value;
                        foreach (System.Management.Automation.PSObject parentPropertyObject in parentPropertyObjectArray)
                        {
                            string     odataId    = (string)parentPropertyObject.Properties["@odata.id"].Value;
                            string     hostUri    = GetCustomUriHelper(this.ClassName, this.ConnectionUri, odataQuery.Keys);
                            UriBuilder uriBuilder = new UriBuilder(hostUri);
                            uriBuilder.Path = odataId;
                            GetCmdlet(this.Cmdlet, uriBuilder.Uri, true, odataQuery);
                        }
                    }
                    else
                    {
                        System.Management.Automation.PSObject parentPropertyObject = (System.Management.Automation.PSObject)parentObject.Properties[parentPropertyName].Value;
                        string     odataId    = (string)parentPropertyObject.Properties["@odata.id"].Value;
                        string     hostUri    = GetCustomUriHelper(this.ClassName, this.ConnectionUri, odataQuery.Keys);
                        UriBuilder uriBuilder = new UriBuilder(hostUri);
                        uriBuilder.Path = odataId;
                        GetCmdlet(this.Cmdlet, uriBuilder.Uri, true, odataQuery);
                    }
                }
            }
            else
            {
                base.ProcessRecord(query);
            }
        }
Beispiel #2
0
        /// <summary>
        /// TryUpdateQueryOptions is a helper function used to update the query options (i.e., Filters, Top, Skip, OrderBy) to the base Uri.
        /// </summary>
        /// <param name="uri">Base Uri.</param>
        /// <param name="adapterQueryBuilder">Adapter specific Query Builder</param>
        /// <returns>If Query options is specified, Base Uri would be appended with the Query options or else the Base Uri would be returned.</returns>
        protected override Uri TryUpdateQueryOptions(Uri uri, ODataQueryBuilder adapterQueryBuilder)
        {
            Debug.Assert(((uri != null) && (uri.AbsoluteUri != null)), "Uri is pointing to NULL in ODataCmdletAdapter.TryUpdateQueryOptions");

            StringBuilder queryOperation = new StringBuilder();
            List <string> queryOptions   = new List <string>();

            if (adapterQueryBuilder != null)
            {
                if (!string.IsNullOrEmpty(adapterQueryBuilder.FilterQuery))
                {
                    queryOptions.Add(adapterQueryBuilder.FilterQuery);
                }

                if (!string.IsNullOrEmpty(adapterQueryBuilder.OrderByQuery))
                {
                    queryOptions.Add(adapterQueryBuilder.OrderByQuery);
                }

                if (!string.IsNullOrEmpty(adapterQueryBuilder.SelectQuery))
                {
                    queryOptions.Add(adapterQueryBuilder.SelectQuery);
                }

                if (!string.IsNullOrEmpty(adapterQueryBuilder.IncludeTotalResponseCountQuery))
                {
                    queryOptions.Add(adapterQueryBuilder.IncludeTotalResponseCountQuery);
                }

                if (!string.IsNullOrEmpty(adapterQueryBuilder.SkipQuery))
                {
                    queryOptions.Add(adapterQueryBuilder.SkipQuery);
                }

                if (!string.IsNullOrEmpty(adapterQueryBuilder.TopQuery))
                {
                    queryOptions.Add(adapterQueryBuilder.TopQuery);
                }

                if (queryOptions.Count > 0)
                {
                    queryOperation.Append(queryOptions[0]);
                    for (int index = 1; index < queryOptions.Count; index++)
                    {
                        queryOperation.Append(adapterQueryBuilder.ConcatinationOperator);
                        queryOperation.Append(queryOptions[index]);
                    }

                    return(new Uri(uri.AbsoluteUri + "?" + queryOperation.ToString()));
                }
            }

            return(uri);
        }