private void dontUse_Click(object sender, EventArgs e)
        {
            UriOperationParameter param1 = new UriOperationParameter("state", false);

            context.Execute(new Uri("SetCategoriesFiltering", UriKind.Relative), "GET", param1);
            entityToShow_SelectedIndexChanged(null, null);
        }
Exemplo n.º 2
0
        public string GenerateQueryUri <T>(string entitySet, IDictionary <string, object> entityParams, IDictionary <string, object> filters) where T : class
        {
            UriOperationParameter[] myParams = null;

            DataServiceQuery <T> query = null;

            if (!this.isConnected)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(entitySet))
            {
                return(null);
            }

            if (entityParams == null)
            {
                query = this.container.CreateQuery <T>(entitySet);
            }
            else
            {
                int count = entityParams.Count;
                if (count > 0)
                {
                    myParams = new UriOperationParameter[count];

                    int i = 0;
                    foreach (string paramKey in entityParams.Keys)
                    {
                        // check for null value here
                        myParams[i++] = new UriOperationParameter(paramKey, entityParams[paramKey]);
                    }

                    query = this.container.CreateFunctionQuery <T>("", entitySet, false, myParams);
                }
            }
            if (query == null)
            {
                return(null);
            }
            if (filters != null)
            {
                foreach (string filter in filters.Keys)
                {
                    object filterValue = filters[filter];
                    if (filterValue != null)
                    {
                        // Immutability here ?
                        query = query.AddQueryOption(filter, filterValue);
                    }
                }
            }

            return(query.ToString());
        }
 private void Authorize(object sender, EventArgs e)
 {
     try {
         UriOperationParameter param1 = new UriOperationParameter("name", "Davolio");
         UriOperationParameter param2 = new UriOperationParameter("password", "abracadabra");
         string res = context.Execute <string>(new Uri("GetAuthorizationCookie", UriKind.Relative), "GET", true, param1, param2).Single();
         authCookie           = res;
         entityToShow.Enabled = true;
         entityToShow_SelectedIndexChanged(null, null);
         AuthorizeButton.Enabled = false;
     } catch (Exception ex) {
         MessageBox.Show(ex.Message.ToString());
     }
 }
        // permite realizar queries a cualquier entidad, con cualquier no de params (e.g. id=23) y filtros (e.g. $expand)
        public ObservableCollection <object> LoadAllEntities <T>(string entitySetName, IDictionary <string, object> entityParams, IDictionary <string, object> filters) where T : class
        // public IList<object> LoadAllEntities<T>(string entitySetName, IDictionary<string, object> entityParams, IDictionary<string, object> filters) where T : class
        {
            UriOperationParameter[] myParams = null;

            IEnumerable <object> result = null;

            DataServiceQuery <T> query = null;

            if (this.container == null)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(entitySetName))
            {
                return(null);
            }
            if (entityParams == null)
            {
                query = this.container.CreateQuery <T>(entitySetName);
            }
            else
            {
                int count = entityParams.Count;
                if (count > 0)
                {
                    myParams = new UriOperationParameter[count];

                    int i = 0;
                    foreach (string paramKey in entityParams.Keys)
                    {
                        // check for null value here
                        myParams[i++] = new UriOperationParameter(paramKey, entityParams[paramKey]);
                    }

                    query = this.container.CreateFunctionQuery <T>("", entitySetName, false, myParams);
                }
            }
            if (query == null)
            {
                return(null);
            }
            if (filters != null)
            {
                foreach (string filter in filters.Keys)
                {
                    object filterValue = filters[filter];
                    if (filterValue != null)
                    {
                        // Immutability here ?
                        query = query.AddQueryOption(filter, filterValue);
                    }
                }
            }

            try
            {
                // 1.- Query
                // The service is down or any other network related issue(s)
                result = query.Execute();

                // Synchronous operation ???
                var list = result.ToList();

                // return list;
                return(new ObservableCollection <object>(list));
            }
            catch (Exception ex)
            {
                //this.statusInfo.Text = ex.Message;
                // this.errorMessage = ex.Message;
            }

            return(null);
        }
Exemplo n.º 5
0
        public string GenerateFunctionQueryUri <T>(string entitySet, string functionName, IDictionary <string, object> functionParams) where T : class
        {
            UriOperationParameter[] myParams = null;

            DataServiceQuery <T> query = null;

            if (!this.isConnected)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(functionName))
            {
                return(null);
            }
            // Are they manadatory?

            /*if (functionParams == null)
             * {
             *  return null;
             * }*/

            if (functionParams != null)
            {
                int count = functionParams.Count;
                if (count > 0)
                {
                    myParams = new UriOperationParameter[count];

                    int i = 0;
                    foreach (string paramKey in functionParams.Keys)
                    {
                        myParams[i++] = new UriOperationParameter(paramKey, functionParams[paramKey]);
                    }
                }
            }
            //query = this.container.CreateFunctionQuery<T>(entitySet, "EIV.Demo.WebService.PaisAction", false, myParams);
            // First param cannot be null, but empty
            // Last param cannot be null
            // Java service (OLingo) requires '()' at the end of the function name
            if (myParams == null)
            {
                query = this.container.CreateFunctionQuery <T>(entitySet, functionName, false);
            }
            else
            {
                // I guess I need a two-step process
                //query = this.container.CreateFunctionQuery<T>(entitySet, functionName, false, myParams);
                query = this.container.CreateFunctionQuery <T>("", entitySet, false, myParams);
            }
            if (query == null)
            {
                return(null);
            }

            // Awful hack!
            string rstQuery = string.Empty;
            string preQuery = query.ToString();

            if (myParams == null)
            {
                rstQuery = preQuery;
            }
            else
            {
                rstQuery = string.Format("{0}/{1}", preQuery, functionName);
            }

            return(rstQuery);
        }