コード例 #1
0
 public static void ProcessQuery(DataViewModelBase sender, DataServiceQuery query, AsyncCallback callback)
 {
     if (!objectRepository.Value.Keys.Contains(query.ToString()))
     {
         query.BeginExecute(callback, null);
     }
     else
     {
         sender.OnCompleteSource(objectRepository.Value[query.ToString()]);
     }
 }
コード例 #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());
        }
コード例 #3
0
        /// <summary>
        /// Verify the passed query tree.
        /// </summary>
        /// <param name="expression">The query tree which will be verified</param>
        public virtual void Verify(QueryExpression expression)
        {
            ExceptionUtilities.CheckAllRequiredDependencies(this);
            ExceptionUtilities.Assert(this.IsAsync, "this verifier can only run async");

            this.ThrowSkippedExceptionIfQueryExpressionNotSupported(expression);

            var resolvedQuery      = this.LinqQueryResolver.Resolve(expression);
            var dataServiceContext = this.DataServiceContextCreator.CreateContext(this.DataServiceContextScope, this.workspace.ContextType, this.workspace.ServiceUri);

            if (this.IsExecuteURI)
            {
                // TODO: update this verifier to call ExecuteUriAndCompare if ExecuteURI test parameter is set to true
            }
            else
            {
                ClientQueryGenerator queryGenerator      = new ClientQueryGenerator(new CSharpGenericTypeBuilder());
                DataServiceContext   clientContext       = dataServiceContext.Product as DataServiceContext;
                CoreLinq.Expression  queryLinqExpression = queryGenerator.Generate(resolvedQuery, clientContext);
                IQueryProvider       queryProvider       = clientContext.CreateQuery <int>("Set").Provider as IQueryProvider;
                DataServiceQuery     dataServiceQuery    = queryProvider.CreateQuery(queryLinqExpression) as DataServiceQuery;

                this.ResultComparer.EnqueueNextQuery(resolvedQuery);
                AsyncExecutionContext.EnqueueAsynchronousAction((queryContinuation) =>
                {
                    this.Log.WriteLine(LogLevel.Info, dataServiceQuery.ToString());
                    QueryValue baselineValue = this.GetBaselineValue(resolvedQuery);
                    DataServiceProtocolVersion maxProtocolVersion = this.workspace.ConceptualModel.GetMaxProtocolVersion();
#if  WINDOWS_PHONE
                    DataServiceProtocolVersion maxClientProtocolVersion = DataServiceProtocolVersion.V4;
#else
                    DataServiceProtocolVersion maxClientProtocolVersion = ((DSC.DataServiceProtocolVersion)dataServiceContext.MaxProtocolVersion.Product).ToTestEnum();
#endif
                    // Calculate version errors
                    ExpectedClientErrorBaseline clientError = this.LinqToAstoriaErrorCalculator.CalculateExpectedClientVersionError(resolvedQuery, true, maxClientProtocolVersion, maxProtocolVersion);
                    if (clientError != null)
                    {
                        this.Log.WriteLine(LogLevel.Info, "Expected client exception: " + clientError.ExpectedExceptionType.ToString());
                    }

                    Type queryType = dataServiceQuery.ElementType;
                    MethodInfo genericExecuteMethod = this.ResultComparer.GetType().GetMethod("ExecuteAndCompare").MakeGenericMethod(queryType);
                    genericExecuteMethod.Invoke(this.ResultComparer, new object[] { queryContinuation, this.IsAsync, dataServiceQuery, baselineValue, clientContext, clientError });
                });
            }
        }
コード例 #4
0
 public override string ToString()
 {
     return(_query.ToString());
 }
コード例 #5
0
        public void NamedStreams_NestedQuery_2()
        {
            // projecting out collection of collection properties - both narrow type and anonymous type
            {
                // Querying url of the nested type - doing this makes the entity non-tracking, but populated the link property
                DataServiceContext context = new DataServiceContext(request.ServiceRoot, ODataProtocolVersion.V4);
                context.EnableAtom = true;
                context.Format.UseAtom();
                DataServiceQuery <EntityWithNamedStreams1> q = (DataServiceQuery <EntityWithNamedStreams1>) from s in context.CreateQuery <EntityWithNamedStreams1>("MySet1")
                                                               select new EntityWithNamedStreams1
                {
                    ID         = s.ID,
                    Stream1    = s.Stream1,
                    Collection = (from c in s.Collection
                                  select new EntityWithNamedStreams2()
                    {
                        ID = c.ID,
                        ColStream = c.ColStream,
                        Collection1 = (from c1 in c.Collection1
                                       select new EntityWithNamedStreams1()
                        {
                            ID = c1.ID,
                            RefStream1 = c1.RefStream1
                        }).ToList()
                    }).ToList()
                };

                Assert.AreEqual(request.ServiceRoot.AbsoluteUri + "/MySet1?$expand=Collection($select=ID),Collection($select=ColStream),Collection($expand=Collection1($select=ID)),Collection($expand=Collection1($select=RefStream1))&$select=ID,Stream1", q.ToString(), "make sure the right uri is produced by the linq translator");

                var response = (QueryOperationResponse <EntityWithNamedStreams1>)q.Execute();
                DataServiceQueryContinuation <EntityWithNamedStreams2> continuation = null;
                foreach (var o in response)
                {
                    Assert.IsNotNull(o.Stream1.EditLink, "Stream1 should not be null");
                    Assert.AreEqual(o.Stream1.EditLink, context.GetReadStreamUri(o, "Stream1"), "the stream url for Stream1 must be populated correctly");
                    foreach (var c in o.Collection)
                    {
                        Assert.IsNotNull(c.ColStream.EditLink, "ColStream should not be null");
                        Assert.AreEqual(c.ColStream.EditLink, context.GetReadStreamUri(c, "ColStream"), "the url for the nested collection entity should match - Level 0");
                        foreach (var c1 in c.Collection1)
                        {
                            Assert.IsNotNull(c1.RefStream1.EditLink, "RefStream1 should not be null");
                            Assert.AreEqual(c1.RefStream1.EditLink, context.GetReadStreamUri(c1, "RefStream1"), "the url for the nested collection entity should match - Level 1");
                        }
                    }

                    // Make sure you get the continuation token for the collection and try and get the next page
                    continuation = response.GetContinuation(o.Collection);
                }

                Assert.AreEqual(context.Entities.Count, 3, "there should be 3 entities tracked by the context");
                Assert.AreEqual(context.Entities[0].EditLink.AbsoluteUri, request.ServiceRoot.AbsoluteUri + "/MySet1(1)", "top level entity must be tracked");
                Assert.AreEqual(context.Entities[1].EditLink.AbsoluteUri, request.ServiceRoot.AbsoluteUri + "/MySet3('ABCDE')", "top level entity must be tracked");
                Assert.AreEqual(context.Entities[2].EditLink.AbsoluteUri, request.ServiceRoot.AbsoluteUri + "/MySet2(3)", "the nested entity must be tracked");
                Assert.IsNotNull(continuation, "since SDP is turned on, we should get the continuation token");

                // Get the next page and make sure we get the right entity and the link is populated.
                foreach (var entity in context.Execute(continuation))
                {
                    Assert.IsNotNull(entity.ColStream.EditLink, "ColStream should not be null");
                    Assert.AreEqual(entity.ColStream.EditLink, context.GetReadStreamUri(entity, "ColStream"), "the url for the nested collection entity should match - Level 1");
                    foreach (var c1 in entity.Collection1)
                    {
                        Assert.IsNotNull(c1.RefStream1.EditLink, "RefStream1 should not be null");
                        Assert.AreEqual(c1.RefStream1.EditLink, context.GetReadStreamUri(c1, "RefStream1"), "the url for the nested collection entity should match - Level 1");
                    }
                }

                Assert.AreEqual(context.Entities.Count, 4, "there should be 4 entities tracked by the context");
            }

            {
                // Querying url of the nested type - doing this makes the entity non-tracking, but populated the link property
                DataServiceContext context = new DataServiceContext(request.ServiceRoot, ODataProtocolVersion.V4);
                context.EnableAtom = true;
                context.Format.UseAtom();
                var q = from s in context.CreateQuery <EntityWithNamedStreams1>("MySet1")
                        select new
                {
                    ID         = s.ID,
                    Stream1Url = s.Stream1,
                    Collection = (from c in s.Collection
                                  select new
                    {
                        Name = c.Name,
                        Stream1Url = c.ColStream,
                        Collection1 = (from c1 in c.Collection1
                                       select new
                        {
                            ID = c1.ID,
                            Stream1Url = c1.RefStream1
                        })
                    })
                };

                Assert.AreEqual(request.ServiceRoot.AbsoluteUri + "/MySet1?$expand=Collection($select=Name),Collection($select=ColStream),Collection($expand=Collection1($select=ID)),Collection($expand=Collection1($select=RefStream1))&$select=ID,Stream1", q.ToString(), "make sure the right uri is produced by the linq translator");

                foreach (var o in q)
                {
                    Assert.AreEqual(o.Stream1Url.EditLink, request.ServiceRoot.AbsoluteUri + "/MySet1(1)/Stream1", "the stream url for Stream1 must be populated correctly");
                    Assert.AreEqual(o.Collection.First().Stream1Url.EditLink, request.ServiceRoot.AbsoluteUri + "/MySet3('ABCDE')/ColStream", "the stream url of the collection stream must be populated correctly - index 0");
                    Assert.AreEqual(o.Collection.First().Collection1.Single().Stream1Url.EditLink, request.ServiceRoot.AbsoluteUri + "/MySet2(3)/RefStream1", "the stream url of the collection stream must be populated correctly - index 0 - index 0");
                }

                Assert.AreEqual(context.Entities.Count, 0, "there should be no entities tracked by the context");
            }
        }
コード例 #6
0
 public void RefreshData()
 {
     ProxyServiceQuery.ClearData(_query.ToString());
     GetData();
 }
コード例 #7
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);
        }