コード例 #1
0
        public IDynaField[] Action(string cmd)
        {
            var out_fields = Query.Action(FieldDict.Values, cmd);

            Result = Query.Result;
            //fields with returned values
            return(out_fields);
        }
コード例 #2
0
        protected override void ProcessRecord()
        {
            if (Id != null && Uri != null)
            {
                throw new Exception("Set only Id or Uri");
            }
            if (Action == null && Cast != null)
            {
                Action = Cast;
            }
            if (Action == null && Navigation != null)
            {
                Action = Navigation;
            }
            if (Method == null)
            {
                Method = "GET";
            }
            Method = Method.ToUpper();

            Query <ODataObject> query = new Query <ODataObject>(Client.Client);

            query.HttpMethod = Method;

            if (Entity != null)
            {
                query = query.From(Entity);
            }
            if (Action != null)
            {
                query = query.Action(Action);
            }
            if (Id != null)
            {
                query = query.Id(Id);
            }
            else if (Uri != null)
            {
                query = query.Id(Uri.ToString());
            }

            if (Parameters != null)
            {
                foreach (var key in Parameters.Keys)
                {
                    if (!(key is string))
                    {
                        throw new Exception("Use strings for parameter keys");
                    }
                    query = query.QueryString((string)key, Parameters[key].ToString());
                }
            }
            if (Expand != null)
            {
                query = query.Expand(Expand);
            }
            if (Select != null)
            {
                query = query.Select(Select);
            }
            if (Body != null)
            {
                query.Body = Body;
            }
            else if (BodyText != null)
            {
                query.Body = BodyText;
            }
            try
            {
                var response = query.Execute();
                if (response != null)
                {
                    Type t = response.GetType();
                    if (t.IsGenericType)
                    {
                        if (t.GetGenericTypeDefinition() == typeof(ODataFeed <>))
                        {
                            var feed = t.GetProperty("Feed").GetValue(response, null) as IEnumerable <ODataObject>;
                            foreach (var o in feed)
                            {
                                WriteObject(o);
                            }
                        }
                    }
                    else
                    {
                        WriteObject(response);
                    }
                }
            }
            catch (ODataException e)
            {
                WriteError(new ErrorRecord(new Exception(e.Code.ToString() + ": " + e.ODataExceptionMessage.Message), e.Code.ToString(), ErrorCategory.NotSpecified, query.GetEntity()));
            }
        }