Exemplo n.º 1
0
        public void Linq_Bug_StackOverflow()
        {
            // There was a bug in a customer code that caused StackOverflowException but in Sense/Net this case has never been reproduced.

            var aspectName = "Aspect_Linq_Bug_StackOverflow";
            var aspect     = Aspect.LoadAspectByName(aspectName);

            if (aspect == null)
            {
                aspect = new Aspect(Repository.AspectsFolder)
                {
                    Name = aspectName
                };
                aspect.Save();
            }


            aspect = Content.All.DisableAutofilters().OfType <Aspect>().Where(x => x.Name == aspectName).FirstOrDefault();
            Assert.IsNotNull(aspect);

            aspect.ForceDelete();

            aspect = Content.All.DisableAutofilters().OfType <Aspect>().Where(x => x.Name == aspectName).FirstOrDefault();
            Assert.IsNull(aspect);
        }
Exemplo n.º 2
0
        public void Indexing_LongText_CaseInsensitive()
        {
            var contentName = Guid.NewGuid().ToString();
            var content     = Content.CreateNew("Car", TestRoot, contentName);

            content.AddAspects(Aspect.LoadAspectByName("Summarizable"));
            content["Summarizable.Summary"] = "Indexing_LongText_CaseInsensitive Hello Word";
            content.Save();

            var result = ContentQuery.Query("Indexing_LongText_CaseInsensitive Hello W* .AUTOFILTERS:OFF");

            Assert.IsTrue(result.Identifiers.Contains(content.Id));
        }
Exemplo n.º 3
0
        private Aspect EnsureAspect(string name)
        {
            var existing = Aspect.LoadAspectByName(name);

            if (existing != null)
            {
                return(existing);
            }
            var aspectContent = Content.CreateNew("Aspect", Repository.AspectsFolder, name);

            aspectContent.Save();
            return((Aspect)aspectContent.ContentHandler);
        }
Exemplo n.º 4
0
        private Aspect EnsureAspect(string name)
        {
            var aspect = Aspect.LoadAspectByName(name);

            if (aspect == null)
            {
                aspect = new Aspect(Repository.AspectsFolder)
                {
                    Name = name
                };
                aspect.Save();
            }
            return(aspect);
        }
        private Expression GetDynamicMember(Type type, string fieldName)
        {
            var fieldType = GetGenericParamType(fieldName);

            if (fieldType == null)
            {
                if (type == typeof(Content))
                {
                    // maybe an aspect
                    var aspect = Aspect.LoadAspectByName(fieldName);
                    if (aspect == null)
                    {
                        throw new InvalidOperationException("Field not found: " + fieldName);
                    }
                    return(null); // means: aspectName
                }
                throw new InvalidOperationException("Field not found: " + fieldName);
            }
            return(CreateFieldOfContentAccessExpression(this.x, fieldName, fieldType));
        }
Exemplo n.º 6
0
        private Aspect CreateDI9Aspect(string name, IDictionary <string, string> fields)
        {
            var aspect = Aspect.LoadAspectByName(name);

            if (aspect == null)
            {
                aspect = new Aspect(Repository.AspectsFolder)
                {
                    Name = name
                }
            }
            ;

            aspect.AspectDefinition = String.Format(@"<AspectDefinition " +
                                                    "xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/AspectDefinition'>" +
                                                    "<Fields>{0}</Fields></AspectDefinition>",
                                                    "\r\n  " + String.Join("\r\n  ", fields.Select(i => String.Format("<AspectField name='{0}' type='{1}' />",
                                                                                                                      i.Key, i.Value))));
            aspect.Save();

            return(aspect);
        }
Exemplo n.º 7
0
        public void Aspect_UniqueName_02()
        {
            var aspectName = Guid.NewGuid().ToString();
            var aspect1    = new Aspect(Repository.AspectsFolder)
            {
                Name = aspectName
            };

            aspect1.Save();

            Assert.AreEqual(aspect1.Id, Aspect.LoadAspectByName(aspectName).Id, "#1 load newly created aspect by name failed: a different aspect was loaded.");

            //delete aspect to make its name available
            aspect1.ForceDelete();

            //create aspect with the same name
            var aspect2 = new Aspect(Repository.AspectsFolder)
            {
                Name = aspectName
            };

            aspect2.Save();
        }
        internal Expression BuildMemberPath(List <string> steps)
        {
            Type type;
            int  k;

            if (steps[0].Contains('.'))
            {
                type = TypeResolver.GetType(steps[0], false);
                if (type == null)
                {
                    throw ODataParser.SyntaxError(this.Parser.Lexer, "Unknown type: " + steps[0]);
                }
                k = 1;
            }
            else
            {
                if (steps.Count == 1 && steps[0] == "ContentType")
                {
                    steps.Add("Name");
                }
                type = typeof(SenseNet.ContentRepository.Content);
                k    = 0;
            }

            Expression expression     = this.x; // Expression.Parameter(type, "x");
            Expression lastExpr       = null;
            Expression lastLastExpr   = null;
            string     lastAspectName = null;

            for (var i = k; i < steps.Count; i++)
            {
                lastLastExpr = lastExpr;
                lastExpr     = expression;

                if (lastAspectName == null)
                {
                    var member = type.GetProperty(steps[i]);
                    expression = member == null?GetDynamicMember(type, steps[i]) : Expression.MakeMemberAccess(member.GetGetMethod().IsStatic ? null : expression, member);

                    if (expression == null)
                    {
                        lastAspectName = steps[i];
                    }
                }
                else
                {
                    var aspect       = Aspect.LoadAspectByName(lastAspectName);
                    var fieldSetting = aspect.FieldSettings.Where(f => f.Name == steps[i]).FirstOrDefault();
                    if (fieldSetting == null)
                    {
                        throw new InvalidOperationException("Field not found: " + lastAspectName + "." + steps[i]);
                    }

                    var fieldName = lastAspectName + "." + steps[i];
                    var fieldType = fieldSetting.FieldDataType;

                    expression     = CreateFieldOfContentAccessExpression(lastLastExpr, fieldName, fieldType);
                    lastAspectName = null;
                }
                type = expression == null ? null : expression.Type;
            }

            if (expression == null)
            {
                throw new InvalidOperationException("Field not found: " + lastAspectName);
            }

            return(expression);
        }