/// <summary>General factory entrance method which will return a TypedList EntityFields object with the format generated by the factory specified</summary>
 /// <param name="relatedTypedListType">The type of typed list the fields are for</param>
 /// <returns>The IEntityFields2 instance requested</returns>
 public static IEntityFields2 CreateTypedListEntityFieldsObject(TypedListType relatedTypedListType)
 {
     IEntityFields2 fieldsToReturn=null;
     switch(relatedTypedListType)
     {
         case TypedListType.EmployeesByRegionAndTerritoryTypedList:
             fieldsToReturn = (new TypedListClasses.EmployeesByRegionAndTerritoryTypedList()).GetFieldsInfo();
             break;
     }
     return fieldsToReturn;
 }
        /// <summary>General factory entrance method which will return a TypedList EntityFields object with the format generated by the factory specified</summary>
        /// <param name="relatedTypedListType">The type of typed list the fields are for</param>
        /// <returns>The IEntityFields2 instance requested</returns>
        public static IEntityFields2 CreateTypedListEntityFieldsObject(TypedListType relatedTypedListType)
        {
            IEntityFields2 fieldsToReturn = null;

            switch (relatedTypedListType)
            {
            case TypedListType.EmployeesByRegionAndTerritoryTypedList:
                fieldsToReturn = (new TypedListClasses.EmployeesByRegionAndTerritoryTypedList()).GetFieldsInfo();
                break;
            }
            return(fieldsToReturn);
        }
Пример #3
0
        internal static IEntityField2 GetField(TypedListType typedListType, string fieldName)
        {
            var fields = EntityFieldsFactory.CreateTypedListEntityFieldsObject(typedListType);

            return
                ((IEntityField2)fields.FirstOrDefault(
                     f => f.Alias.Equals(fieldName, StringComparison.OrdinalIgnoreCase)));

            /*
             * return
             *  (IEntityField2)fields.FirstOrDefault(
             *      f =>
             *      !string.IsNullOrEmpty(f.Alias)
             *          ? f.Alias.Equals(fieldName, StringComparison.OrdinalIgnoreCase)
             *          : f.Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase));
             */
        }
        public TypedListMetaDetailsResponse GetTypedListMetaDetails(ServiceStack.ServiceInterface.Service service)
        {
            // The entity meta details don't change per type, so cache these for performance
            var cacheKey    = string.Format("{0}-typedlist-meta-details", TypedListType.ToString().ToLower());
            var metaDetails = CacheClient.Get <TypedListMetaDetailsResponse>(cacheKey);

            if (metaDetails != null)
            {
                return(metaDetails);
            }

            var request        = service.RequestContext.Get <IHttpRequest>();
            var appUri         = request.GetApplicationUrl().TrimEnd('/');
            var baseServiceUri = appUri + request.PathInfo.Replace("/meta", "");
            var queryString    = request.QueryString["format"] != null ? "&format=" + request.QueryString["format"] : "";
            var pkCount        = FieldMap.Count(pk => pk.Value.IsPrimaryKey);
            var fields         = new List <Link>();
            var fieldIndex     = -1;

            foreach (var f in FieldMap)
            {
                fieldIndex++;
                var isUnique = false;
                var link     = Link.Create(
                    f.Key.ToCamelCase(), f.Value.DataType.Name, "field",
                    string.Format("{0}?select={1}{2}", baseServiceUri, f.Key.ToLowerInvariant(), queryString),
                    string.Format("The {0} field for the {1} resource.", f.Value.Name, typeof(TDto).Name),
                    new Dictionary <string, string>()
                    );
                var props = new SortedDictionary <string, string>();
                props.Add("index", fieldIndex.ToString() /*WRONG: f.Value.FieldIndex.ToString(CultureInfo.InvariantCulture)*/);
                if (f.Value.IsPrimaryKey)
                {
                    props.Add("isPrimaryKey", f.Value.IsPrimaryKey.ToString().ToLower());
                    if (pkCount == 1)
                    {
                        isUnique = true;
                    }
                }
                if (f.Value.IsForeignKey)
                {
                    props.Add("isForeignKey", "true");
                }

                if (isUnique)
                {
                    props.Add("isUnique", "true");
                }
                if (f.Value.IsOfEnumDataType)
                {
                    props.Add("isOfEnumDataType", "true");
                }
                if (f.Value.IsReadOnly)
                {
                    props.Add("isReadOnly", "true");
                }
                if (f.Value.IsNullable)
                {
                    props.Add("isNullable", "true");
                }
                if (f.Value.IsOfEnumDataType)
                {
                    props.Add("isEnumType", "true");
                }
                if (f.Value.MaxLength > 0)
                {
                    props.Add("maxLength", f.Value.MaxLength.ToString(CultureInfo.InvariantCulture));
                }
                if (f.Value.Precision > 0)
                {
                    props.Add("precision", f.Value.Precision.ToString(CultureInfo.InvariantCulture));
                }
                if (f.Value.Scale > 0)
                {
                    props.Add("scale", f.Value.Scale.ToString(CultureInfo.InvariantCulture));
                }
                link.Properties = new Dictionary <string, string>(props);
                fields.Add(link);
            }

            metaDetails = new TypedListMetaDetailsResponse()
            {
                Fields = fields.ToArray(),
            };
            CacheClient.Set(cacheKey, metaDetails);
            return(metaDetails);
        }
 private static IDictionary <string, IEntityField2> GetFieldMap(TypedListType typedListType)
 {
     return(EntityFieldsFactory.CreateTypedListEntityFieldsObject(typedListType)
            .ToDictionary(k => k.Alias, v => (IEntityField2)v));
 }
        internal static IRelationPredicateBucket ConvertStringToRelationPredicateBucket(TypedListType typedListType, IRelationPredicateBucket predicateBucket, string filterStr)
        {
            if (string.IsNullOrEmpty(filterStr))
                return predicateBucket;

            var inferredRelationsList = new List<IEntityRelation>();
            var predicate = ConvertStringToPredicate(s => GetField(typedListType, s), null, filterStr, inferredRelationsList);
            if (inferredRelationsList.Count > 0)
                predicateBucket.Relations.AddRange(inferredRelationsList);
            if (predicate != null)
                predicateBucket.PredicateExpression.Add(predicate);
            return predicateBucket;
        }
 internal static IEntityField2 GetField(TypedListType typedListType, string fieldName)
 {
     var fields = EntityFieldsFactory.CreateTypedListEntityFieldsObject(typedListType);
     return
         (IEntityField2)fields.FirstOrDefault(
             f => f.Alias.Equals(fieldName, StringComparison.OrdinalIgnoreCase));
     /*
     return
         (IEntityField2)fields.FirstOrDefault(
             f =>
             !string.IsNullOrEmpty(f.Alias)
                 ? f.Alias.Equals(fieldName, StringComparison.OrdinalIgnoreCase)
                 : f.Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase));
     */
 }
 internal static SortExpression ConvertStringToSortExpression(TypedListType typedListType, string sortStr)
 {
     return ConvertStringToSortExpression(sortStr, s => GetField(typedListType, s));
 }
Пример #9
0
 internal static SortExpression ConvertStringToSortExpression(TypedListType typedListType, string sortStr)
 {
     return(ConvertStringToSortExpression(sortStr, s => GetField(typedListType, s)));
 }
Пример #10
0
        internal static IRelationPredicateBucket ConvertStringToRelationPredicateBucket(TypedListType typedListType, IRelationPredicateBucket predicateBucket, string filterStr)
        {
            if (string.IsNullOrEmpty(filterStr))
            {
                return(predicateBucket);
            }

            var inferredRelationsList = new List <IEntityRelation>();
            var predicate             = ConvertStringToPredicate(s => GetField(typedListType, s), null, filterStr, inferredRelationsList);

            if (inferredRelationsList.Count > 0)
            {
                predicateBucket.Relations.AddRange(inferredRelationsList);
            }
            if (predicate != null)
            {
                predicateBucket.PredicateExpression.Add(predicate);
            }
            return(predicateBucket);
        }