protected void ResolveManager() { SPModelDescriptor.RegisterReferencedAssemblies(this.Web.Read().Site); this.Descriptor = SPModelDescriptor.Resolve(this.TypeName); this.Manager = this.Descriptor.CreateManager(this.Web.Read()); OnManagerResolved(); }
protected override Expression VisitTypeIs(TypeBinaryExpression expression) { SPModelQueryExpressionScope currentScope = stack.Peek(); try { SPModelDescriptor descriptor = SPModelDescriptor.Resolve(expression.TypeOperand); currentScope.Expression = descriptor.GetContentTypeExpression(manager.Descriptor); } catch (ArgumentException) { currentScope.Expression = Caml.False; } return(expression); }
protected override Expression VisitTypeIs(TypeBinaryExpression expression) { if (invariantExpression || builder.SelectExpression != null) { return(base.VisitTypeIs(expression)); } try { SPModelDescriptor descriptor = SPModelDescriptor.Resolve(expression.TypeOperand); currentScope.Expression = descriptor.GetContentTypeExpression(manager.Descriptor); } catch (ArgumentException) { currentScope.Expression = Caml.False; } return(expression); }
private SPModelManager <SiteConfigEntry> CreateManager(SPSite site) { SPListAttribute listAttribute = new SPListAttribute(); listAttribute.Url = "Lists/SiteConfig"; listAttribute.Title = "Site Config"; listAttribute.EnableVersioning = SPOption.True; listAttribute.OnQuickLaunch = true; listAttribute.DefaultViewQuery = "<OrderBy><FieldRef Name=\"SiteConfigCategory\" Ascending=\"TRUE\"/><FieldRef Name=\"Title\" Ascending=\"TRUE\"/></OrderBy>"; listAttribute = InitializeListSettings(listAttribute); SPModelDescriptor descriptor = SPModelDescriptor.Resolve(typeof(SiteConfigEntry)); descriptor.Provision(site.RootWeb, SPModelProvisionOptions.Asynchronous, new SPModelListProvisionOptions(listAttribute)).GetListCollection(); return(new SPModelManager <SiteConfigEntry>(site.RootWeb)); }
object IDynamicParameters.GetDynamicParameters() { ResolveManager(); SPModelDescriptor descriptor = SPModelDescriptor.Resolve(this.TypeName); RuntimeDefinedParameterDictionary parameters = new RuntimeDefinedParameterDictionary(); foreach (PropertyInfo property in descriptor.ModelType.GetProperties()) { if (property.CanWrite || property.PropertyType.IsOf(typeof(IList <>))) { ParameterAttribute attribute = new ParameterAttribute(); attribute.ParameterSetName = "__AllParameterSets"; parameters.Add(property.Name, new RuntimeDefinedParameter(property.Name, property.PropertyType, new Collection <Attribute> { attribute })); } } modelParameters = parameters; return(parameters); }
private SPModelParameterizedQuery(ParameterizedExpression expression, ISPModelManagerInternal manager) { SPModelQueryBuilder builder = SPModelQueryExpressionVisitor.Translate(expression, manager); this.Descriptor = builder.ModelType != null?SPModelDescriptor.Resolve(builder.ModelType) : manager.Descriptor; this.Expression = builder.Expression; this.TaxonomyFields = new ReadOnlyCollection <string>(builder.TaxonomyFields.ToArray()); this.expression = expression; this.executeMode = builder.ExecuteMode; this.emptyArray = Array.CreateInstance(this.Descriptor.ModelType, 0); if (builder.SelectExpression != null) { this.projector = ((Expression <ResultEvaluator>)builder.SelectExpression).Compile(); } else { this.projector = (ResultEvaluator)Delegate.CreateDelegate(typeof(ResultEvaluator), mOfType.MakeGenericMethod(this.Descriptor.ModelType)); } this.evaluators = new ReadOnlyDictionary <string, ParameterEvaluator>(builder.ParameterEvaluators); for (int i = 0; i < PIndexMax; i++) { parameterNames[i] = (string)builder.Parameters[i]; } if (builder.ModelType != null) { this.ContentTypeFilterExpression = builder.ContentTypeIds.Aggregate(Caml.False, (v, a) => v | Caml.OfContentType(a)); } if (!builder.SelectAllProperties) { List <string> properties = new List <string>(builder.SelectProperties); if (!properties.Contains(SPBuiltInFieldName.ContentTypeId)) { properties.Add(SPBuiltInFieldName.ContentTypeId); } this.SelectProperties = new ReadOnlyCollection <string>(properties); } }
private CamlExpression GetExpressionFromQueryableMethod(MethodCallExpression expression) { int argCount = expression.Arguments.Count; if (argCount > 1) { LambdaExpression lamdba = StripQuotes(expression.Arguments[1]) as LambdaExpression; if (lamdba != null) { lambdaParam = lamdba.Parameters[0]; } } switch (expression.Method.Name) { case "Count": case "Any": case "FirstOrDefault": case "First": case "SingleOrDefault": case "Single": if (argCount == 2) { Visit(expression.Arguments[1]); } builder.ExecuteMode = Enum <SPModelQueryExecuteMode> .Parse(expression.Method.Name); AppendSelectExpression(expression, builder.ExecuteMode.ToString(), true); return(currentScope.Expression); case "All": Visit(expression.Arguments[1]); builder.ExecuteMode = SPModelQueryExecuteMode.Any; AppendSelectExpression(expression, builder.ExecuteMode.ToString(), true); return(~currentScope.Expression); case "ElementAtOrDefault": case "ElementAt": Visit(expression.Arguments[1]); builder.Parameters[SPModelParameterizedQuery.PIndexOffset] = currentScope.ParameterName; builder.ExecuteMode = expression.Method.Name == "ElementAt" ? SPModelQueryExecuteMode.First : SPModelQueryExecuteMode.FirstOrDefault; AppendSelectExpression(expression, builder.ExecuteMode.ToString(), true, Expression.Constant(0)); return(Caml.Empty); case "Aggregate": case "Average": case "Max": case "Min": case "Sum": case "Select": case "SelectMany": AppendSelectExpression(expression); return(Caml.Empty); case "Take": Visit(expression.Arguments[1]); builder.Parameters[SPModelParameterizedQuery.PIndexLimit] = currentScope.ParameterName; return(Caml.Empty); case "Skip": Visit(expression.Arguments[1]); builder.Parameters[SPModelParameterizedQuery.PIndexOffset] = currentScope.ParameterName; return(Caml.Empty); case "OrderBy": case "ThenBy": case "OrderByDescending": case "ThenByDescending": CamlOrder dir = expression.Method.Name.Contains("Descending") ? CamlOrder.Descending : CamlOrder.Ascending; Visit(expression.Arguments[1]); return(this.currentScope.GetExpression(s => Caml.OrderBy(s.FieldRef, dir), true)); case "Where": Visit(expression.Arguments[1]); return(currentScope.Expression); case "OfType": if (builder.SelectExpression != null) { AppendSelectExpression(expression); } else { if (builder.ModelType == null) { builder.ContentTypeIds.AddRange(manager.Descriptor.ContentTypeIds); } builder.ModelType = expression.Method.GetGenericArguments()[0]; SPModelDescriptor descriptor; try { descriptor = SPModelDescriptor.Resolve(builder.ModelType); } catch (ArgumentException) { throw new NotSupportedException("'OfType' constraint must be used with valid model type or interface type"); } SPContentTypeId[] result = SPModelDescriptor.IntersectContentTypeIds(builder.ContentTypeIds, descriptor.ContentTypeIds.ToArray()); builder.ContentTypeIds.Clear(); builder.ContentTypeIds.AddRange(result); } return(Caml.Empty); } throw ThrowMethodNotSupported(expression.Method); }