Beispiel #1
0
        private string HandleIncludesAndFields <TAttr>(
            Expression relationshipSelector,
            Expression fieldSelector = null)
        {
            if (!(relationshipSelector is LambdaExpression lambda))
            {
                throw new ArgumentException(nameof(relationshipSelector));
            }

            if (!(lambda.Body is MemberExpression body))
            {
                throw new ArgumentException(nameof(relationshipSelector));
            }

            var attribute = (JsonPropertyNameAttribute)body.Member.GetCustomAttribute(typeof(JsonPropertyNameAttribute));

            if (Includes.Contains(attribute.Name))
            {
                return(attribute.Name);
            }

            Includes.Add(attribute.Name);
            Fields.Add(fieldSelector == null ? Field.All <TAttr>() : Field.Create <TAttr>(fieldSelector));

            return(attribute.Name);
        }
Beispiel #2
0
        /// <summary>
        /// Include referenced properties
        /// </summary>
        /// <param name="propertyPaths">Comma-separated list of property paths</param>
        /// <returns>Current instance</returns>
        public IEntityFrameworkRepository <TEntity> Include(string propertyPaths)
        {
            if (!string.IsNullOrWhiteSpace(propertyPaths))
            {
                var propertyPathList = propertyPaths
                                       .Split(',')
                                       .Select(r => r.Trim())
                                       .Where(s => !string.IsNullOrWhiteSpace(s));
                foreach (var propertyPath in propertyPathList)
                {
                    var validatedPropertyPath = propertyPath;
                    if (!TryCheckPropertyPath(propertyPath, out validatedPropertyPath))
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      "'{0}' is not a valid property path of '{1}'.",
                                      propertyPath,
                                      EntityTypeName));
                    }

                    if (!Includes.Contains(validatedPropertyPath))
                    {
                        Includes.Add(validatedPropertyPath);
                    }
                }
            }

            return(this);
        }
Beispiel #3
0
 public static bool SetInclude(string include)
 {
     if (string.IsNullOrWhiteSpace(include))
     {
         return(false);
     }
     if (Includes.Contains(include))
     {
         return(false);
     }
     Includes.Add(include);
     return(true);
 }
Beispiel #4
0
        private void ParseIncludes(XElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            var includes = from el in element.Descendants("Include") select el;

            foreach (var include in includes)
            {
                var source = (string)include.Attribute("source");

                if (source.IsNullOrWhiteSpace())
                {
                    continue;
                }

                var pointer  = (string)include.Attribute("pointer") ?? DefaultPointer;
                var required = (bool?)include.Attribute("required") ?? false;

                var sourcePath = Path.Combine(SourceDirectory, source);
                sourcePath = Path.GetFullPath(sourcePath);

                if (required && !File.Exists(sourcePath))
                {
                    // Break due to error
                }

                if (!Includes.Contains(sourcePath))
                {
                    Includes.Add(sourcePath);
                }
            }

            foreach (var include in Includes)
            {
                var asset = Load(include);

                if (asset == null)
                {
                    continue;
                }

                Combine(asset);
            }
        }
Beispiel #5
0
        /// <summary>添加包含目录</summary>
        /// <param name="path"></param>
        /// <param name="sub"></param>
        /// <param name="allSub"></param>
        public void AddIncludes(String path, Boolean sub = false, Boolean allSub = false)
        {
            path = path.GetFullPath();
            if (!Directory.Exists(path))
            {
                return;
            }

            // 有头文件才要,没有头文件不要
            //var fs = path.AsDirectory().GetAllFiles("*.h;*.hpp");
            //if (!fs.Any()) return;

            if (!Includes.Contains(path) && HasHeaderFile(path))
            {
                WriteLog("引用目录:{0}".F(path));
                Includes.Add(path);
            }

            if (sub)
            {
                var opt = allSub ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
                foreach (var item in path.AsDirectory().GetDirectories("*", opt))
                {
                    if (item.FullName.Contains(".svn"))
                    {
                        continue;
                    }
                    if (item.Name.EqualIgnoreCase("List", "Obj", "ObjD", "Log"))
                    {
                        continue;
                    }

                    if (!Includes.Contains(item.FullName) && HasHeaderFile(item.FullName))
                    {
                        WriteLog("引用目录:{0}".F(item.FullName));
                        Includes.Add(item.FullName);
                    }
                }
            }
        }
Beispiel #6
0
        public virtual IQuery Include(string propertyName)
        {
            //TODO: recursive include.
            propertyName.NotNullOrEmpty(nameof(propertyName));

            var propertyDefinition = EntityDefinition.Properties.SafeGet(propertyName);

            if (propertyDefinition == null)
            {
                throw new QueryException(this, $"Unable to include property {propertyName} because it is not a valid property of {EntityDefinition}.");
            }

            if (propertyDefinition.PropertyType.DataTypeType != DataTypeType.Relation)
            {
                throw new QueryException(this, $"Unable to include property {propertyName} because it is not a relation property of {EntityDefinition}.");
            }

            if (!Includes.Contains(propertyDefinition))
            {
                Includes.Add(propertyDefinition);
            }

            return(this);
        }
Beispiel #7
0
 public void AddNode(IncludeGraphNode node, IncludeGraphNode parentNode)
 {
     if (Includes.Contains(parentNode))
     {
     }
 }
Beispiel #8
0
 public bool IsIncluded(string name)
 {
     return(Includes.Contains(name));
 }