public static void ResolveClientType(Workspace workspace, WebDataCtxWrapper ctx, Type resType) { if (workspace.Name == "Aruba") { switch (AstoriaTestProperties.DataLayerProviderKinds[0]) { case DataLayerProviderKind.Edm: ctx.ResolveType = delegate(string typeName) { return(resType.Assembly.GetType("ArubaClient." + typeName.Substring("Aruba.".Length), true, false)); }; ctx.ResolveName = delegate(Type type) { return("Aruba." + type.Name); }; break; case DataLayerProviderKind.LinqToSql: ctx.ResolveType = delegate(string typeName) { return(resType.Assembly.GetType("ArubaClientLTS." + typeName.Substring("Aruba.".Length), true, false)); }; ctx.ResolveName = delegate(Type type) { return("Aruba." + type.Name); }; break; } } }
public void VerifyClient(QueryModel qm) { WebDataCtxWrapper ctx = new WebDataCtxWrapper(new Uri(qm.Workspace.ServiceUri)); ctx.Credentials = CredentialCache.DefaultNetworkCredentials; try { UriQueryBuilder ub = new UriQueryBuilder(qm.Workspace, ""); string ruri = ub.Build(qm.QueryResult); string uriRel = ruri.Substring(ruri.LastIndexOf(".svc/") + 5); if ((ctx.BaseUri + "/" + uriRel).Length > 260) { return; } AstoriaTestLog.WriteLineIgnore(ctx.BaseUri + "/" + uriRel); ResolveClientType(qm.Workspace, ctx, qm.ResultType); object enumerable = ExecuteQuery(ctx, qm.ResultType, uriRel, "sync"); Verify(qm.Workspace, qm.QueryResult, (IEnumerable)enumerable, qm.ResType, null, qm.IsCount); } catch (Exception e) { AstoriaTestLog.FailAndContinue(e); } }
public static IEnumerable ExecuteQuery(WebDataCtxWrapper ctx, Type pType, string sUri, string execType) { MethodInfo mi = null; MethodInfo miConstructed = null; object enumerable = null; object[] args = { new Uri(sUri, UriKind.Relative) }; Type cType = typeof(WebDataCtxWrapper); switch (execType) { case "sync": mi = cType.GetMethod("Execute", new Type[] { typeof(System.Uri) }); miConstructed = mi.MakeGenericMethod(pType); enumerable = miConstructed.Invoke(ctx, args); break; case "async": mi = cType.GetMethod("BeginExecute", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(System.Uri), typeof(System.AsyncCallback), typeof(object) }, null); miConstructed = mi.MakeGenericMethod(pType); object asyncResult = miConstructed.Invoke(ctx, new object[] { new Uri(sUri, UriKind.Relative), null, null }); MethodInfo endexecute = cType.GetMethod("EndExecute", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(IAsyncResult) }, null); MethodInfo miConstructed2 = endexecute.MakeGenericMethod(pType); enumerable = miConstructed2.Invoke(ctx, new object[] { asyncResult }); break; } return((IEnumerable)enumerable); }
private void VerifyLoadProperty(object entity, string propertyName, WebDataCtxWrapper Context) { Uri entityUri = null; if (Context.TryGetUri(entity, out entityUri)) { Uri navigationPropertyURI = new Uri(String.Format("{0}/{1}", entityUri.OriginalString, propertyName));; Type navPropType = entity.GetType().GetProperty(propertyName).PropertyType; if (navPropType.IsGenericType) { navPropType = navPropType.GetGenericArguments()[0]; } WebDataCtxWrapper baselineCOntext = new WebDataCtxWrapper(Context.BaseUri); baselineCOntext.Credentials = CredentialCache.DefaultCredentials; QueryOperationResponse qoResponse = baselineCOntext.ExecuteOfT(navPropType, navigationPropertyURI) as QueryOperationResponse; IEnumerator enumerator = qoResponse.GetEnumerator(); while (enumerator.MoveNext()) { object baselineEntity = enumerator.Current; Uri navPropEntityURI = null; if (baselineCOntext.TryGetUri(baselineEntity, out navPropEntityURI)) { AstoriaTestLog.IsNotNull(Context.TryGetEntityOfT(navPropType, navPropEntityURI), "Could not find entity in Navigation property "); } } } }
private bool TryLoadProperty_Client(object entity, string propertyName, out object propertyValue) { propertyValue = null; Type type = entity.GetType(); if (!type.GetCustomAttributes(typeof(KeyAttribute), true).Any()) { return(false); } PropertyInfo property = type.GetProperty(propertyName); if (propertyName == null) { return(false); } WebDataCtxWrapper ctx = WebDataCtxWrapper.MostRecentContext; ctx.LoadProperty(entity, propertyName); propertyValue = property.GetValue(entity, null); return(true); }
protected WebDataCtxWrapper CreateContext(ResourceType resourceType, Workspace workspace) { CurrentContext = new WebDataCtxWrapper(new Uri(workspace.ServiceUri)); CurrentContext.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; CurrentContext.MergeOption = mergeOption; CurrentContext.IgnoreMissingProperties = true; CurrentContext.UnderlyingContext.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(CurrentContext_SendingRequest); return(CurrentContext); }
protected void QueryNavProperty(Func <IEdmEntityType, List <string> > getNavPropsLambda) { ForEachResourceType( (resourceType, resourceContainer, workspace) => { CreateContext(resourceType, workspace); AstoriaTestLog.WriteLine("Querying entityset {0}", resourceContainer.Name); IEdmEntityType entityType = DataServiceMetadata.EntityTypes.FirstOrDefault(eType => eType.Name == resourceType.Name); KeyExpression keyExp = workspace.GetRandomExistingKey(resourceContainer); if (keyExp != null && (!(resourceContainer is ServiceOperation))) { List <KVP> keyExpValues = WebDataCtxWrapper.ConvertKeyExpression(keyExp); foreach (string collNavProperty in getNavPropsLambda(entityType)) { AstoriaTestLog.WriteLine("Querying Properties {0}", collNavProperty); try { DataServiceQuery queryWithExpand = ((DataServiceQuery)CurrentContext.CreateQueryOfT(resourceContainer.Name, resourceType.ClientClrType)).Where(keyExpValues); //.SelectNavigationProperty(collNavProperty) as DataServiceQuery; IEnumerator enumerateQueryResults = ((IQueryable)queryWithExpand).GetEnumerator(); object entity = null; if (enumerateQueryResults.MoveNext()) { entity = enumerateQueryResults.Current; } while (enumerateQueryResults.MoveNext()) { ; } Uri entityUri = null; CurrentContext.UnderlyingContext.TryGetUri(entity, out entityUri); CurrentContext.Detach(entity); entityUri = new Uri(entityUri.OriginalString + "/" + collNavProperty); var qoREsponse = CurrentContext.ExecuteOfT(GetResourceType(collNavProperty, resourceType).ClientClrType, entityUri); IEnumerator enumerator = qoREsponse.GetEnumerator(); while (enumerator.MoveNext()) { ; } if (ChainedFunction != null) { ChainedFunction(); } } catch (System.Reflection.TargetInvocationException tiException) { if (!tiException.ToString().Contains("Sequence Contains")) { throw tiException; } } } } }, false); }
protected object ExecuteURI(ResourceType resourceType, string requestURI, WebDataCtxWrapper context) { IQueryable result = context.ExecuteOfT(resourceType.ClientClrType, new Uri(requestURI, UriKind.RelativeOrAbsolute)).AsQueryable(); object entity = null; IEnumerator requestEnumerator = result.GetEnumerator(); if (requestEnumerator.MoveNext()) { entity = requestEnumerator.Current; } return(entity); }
protected WebDataCtxWrapper CreateContext(Workspace workspace) { CurrentContext = new WebDataCtxWrapper(new Uri(workspace.ServiceUri)); CurrentContext.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; CurrentContext.ResolveName = (clrType) => { return(clrType.FullName.Replace("SDPV2", "").Replace("V2", "")); }; CurrentContext.MergeOption = mergeOption; CurrentContext.IgnoreMissingProperties = true; CurrentContext.UnderlyingContext.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(CurrentContext_SendingRequest); return(CurrentContext); }
public static object CreateDerivedDSC(Type enumerableType, WebDataCtxWrapper Context, string entitySetName, IEnumerable results, Func <EntityChangedParams, bool> entityChangedCallback, Func <EntityCollectionChangedParams, bool> collectionChangedCallback) { //DataServiceContext context, //string entitySetName, //IEnumerable<T> items, //Func<EntityChangedParams, bool> entityChangedCallback, //Func<EntityCollectionChangedParams, bool> collectionChangedCallback) ConstructorInfo pagedEnumerableConstruct = typeof(DerivedEnumerable <>).MakeGenericType(enumerableType) .GetConstructor(new Type[] { typeof(DataServiceContext), typeof(string), typeof(IEnumerable <>).MakeGenericType(enumerableType) , typeof(Func <EntityChangedParams, bool>) , typeof(Func <EntityCollectionChangedParams, bool>) }); object instance = pagedEnumerableConstruct.Invoke(new object[] { Context.UnderlyingContext, entitySetName, results, entityChangedCallback, collectionChangedCallback }); return(instance); }
protected void QueryExpandProperty(Func <IEdmEntityType, List <string> > getNavPropsLambda) { ForEachResourceType( (resourceType, resourceContainer, workspace) => { CreateContext(resourceType, workspace); AstoriaTestLog.WriteLine("Querying entityset {0}", resourceContainer.Name); IEdmEntityType entityType = DataServiceMetadata.EntityTypes.FirstOrDefault(eType => eType.Name == resourceType.Name); KeyExpression keyExp = workspace.GetRandomExistingKey(resourceContainer); if (keyExp != null) { List <KVP> keyExpValues = WebDataCtxWrapper.ConvertKeyExpression(keyExp); foreach (string collNavProperty in getNavPropsLambda(entityType)) { AstoriaTestLog.WriteLine("Expanding Properties {0}", collNavProperty); try { DataServiceQuery queryWithExpand = ((DataServiceQuery)CurrentContext.CreateQueryOfT(resourceContainer.Name, resourceType.ClientClrType)).Where(keyExpValues).Expand(collNavProperty); IEnumerator enumerateQueryResults = ((IQueryable)queryWithExpand).GetEnumerator(); try { while (enumerateQueryResults.MoveNext()) { ; } } catch (OptimisticConcurrencyException oException) { AstoriaTestLog.WriteLineIgnore("Failed as per Expand causes etags not to be included." + oException.Message); } if (ChainedFunction != null) { ChainedFunction(); } } catch (System.Reflection.TargetInvocationException tiException) { if (!tiException.ToString().Contains("Sequence Contains")) { throw tiException; } } } } }, false); }
public static void ExecuteLinq(Workspace workspace, ExpNode q, ResourceContainer container, bool bSingle, ExpNode altq) { System.Uri uri = new Uri(workspace.ServiceUri); WebDataCtxWrapper ctx = new WebDataCtxWrapper(uri); ctx.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; ctx.MergeOption = MergeOption.NoTracking; Type resType = container.BaseType.ClientClrType; ResolveClientType(workspace, ctx, resType); Type cType = typeof(WebDataCtxWrapper); MethodInfo mi = cType.GetMethod("CreateQuery", new Type[] { typeof(string) }); Type pType = container.BaseType.ClientClrType; MethodInfo miConstructed = mi.MakeGenericMethod(pType); string uri2 = container.Name; AstoriaTestLog.WriteLineIgnore(workspace.ServiceUri + "/" + uri2); object[] args = { uri2 }; object query = miConstructed.Invoke(ctx, args); LinqQueryBuilder lb = new LinqQueryBuilder(workspace, (IQueryable)query); string uri3 = lb.Build(q); AstoriaTestLog.WriteLineIgnore("Linq expression: " + lb.QueryExpression); //if (bSingle) //{ // var single = lb.QueryResultSingle; // VerifyLinqSingle(workspace, altq, single, container); //} //else //{ var queryable = lb.QueryResult; VerifyLinq(workspace, q, (IQueryable)queryable); //} }
public static ServerDrivenPagingClientWrapper Create(Type entityType, WebDataCtxWrapper context, bool trackChanges) { ConstructorInfo constructor = typeof(ServerDrivenPagingClientWrapper <>).MakeGenericType(entityType).GetConstructor(new Type[] { typeof(WebDataCtxWrapper), typeof(bool) }); return(constructor.Invoke(new object[] { context, trackChanges }) as ServerDrivenPagingClientWrapper); }
public static ServerDrivenPagingClientWrapper Create(Type entityType, object dsCollection, WebDataCtxWrapper context) { Type dsCollectionType = typeof(DataServiceCollection <>).MakeGenericType(entityType); ConstructorInfo constructor = typeof(ServerDrivenPagingClientWrapper <>).MakeGenericType(entityType).GetConstructor(new Type[] { dsCollectionType, typeof(WebDataCtxWrapper) }); return(constructor.Invoke(new object[] { dsCollection, context }) as ServerDrivenPagingClientWrapper); }
public static ServerDrivenPagingClientWrapper <T> CreateTracked <T>(IEnumerable <T> queryResults, WebDataCtxWrapper context) { return(new ServerDrivenPagingClientWrapper <T>(queryResults, context, true)); }