Пример #1
0
        public CompositeTypedEntity(TypedEntity entity)
        {
            Attributes.Clear();
            entity.Attributes.ForEach(x => Attributes.Add(x));

            RelationProxies.LazyLoadDelegate = entity.RelationProxies.LazyLoadDelegate;
        }
Пример #2
0
        public void GetIdPath_Returns_In_Correct_Order_For_Entities()
        {
            //mock hive
            IReadonlyEntityRepositoryGroup<IContentStore> readonlyEntitySession;
            IReadonlySchemaRepositoryGroup<IContentStore> readonlySchemaSession;
            IEntityRepositoryGroup<IContentStore> entityRepository;
            ISchemaRepositoryGroup<IContentStore> schemaSession;
            var hive = MockHiveManager.GetManager().MockContentStore(out readonlyEntitySession, out readonlySchemaSession, out entityRepository, out schemaSession);
            var entity = new TypedEntity {Id = new HiveId(100)};
            entityRepository.Get<TypedEntity>(Arg.Any<bool>(), Arg.Any<HiveId[]>()).Returns(new[] {entity});
            entityRepository.GetAncestorRelations(new HiveId(100), FixedRelationTypes.DefaultRelationType)
                .Returns(new[]
                    {
                        new Relation(FixedRelationTypes.DefaultRelationType, new TypedEntity{Id = new HiveId(99)}, entity),
                        new Relation(FixedRelationTypes.DefaultRelationType, new TypedEntity{Id = new HiveId(98)}, new TypedEntity{Id = new HiveId(99)}),
                        new Relation(FixedRelationTypes.DefaultRelationType, new TypedEntity{Id = new HiveId(97)}, new TypedEntity{Id = new HiveId(98)}),
                    });

            using (var uow = hive.OpenWriter<IContentStore>())
            {
                var path = uow.Repositories.GetEntityPath<TypedEntity>(new HiveId(100), FixedRelationTypes.DefaultRelationType);
                Assert.AreEqual(new HiveId(97), path.ElementAt(0));
                Assert.AreEqual(new HiveId(98), path.ElementAt(1));
                Assert.AreEqual(new HiveId(99), path.ElementAt(2));                
                Assert.AreEqual(new HiveId(100), path.ElementAt(3));
            }

        }
        /// <summary>
        /// Returns the TooltipContents after proxying through the task system to allow developers to modify the output
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="sender"></param>
        /// <param name="entity"> </param>
        /// <param name="htmlContent"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static TooltipContents CreateTooltipContentsViaTask(this INodeSelectorDataSource ds, 
                                                                   object sender, 
                                                                   TypedEntity entity,
                                                                   string htmlContent, 
                                                                   int width = -1, 
                                                                   int height = -1)
        {
            var args = new NodeSelectorTooltipEventArgs(entity, htmlContent)
                {
                    Height = height,
                    Width = width
                };

            //launch task to modify the contents
            ds.FrameworkContext.TaskManager
                .ExecuteInContext(
                    NodeSelectorTaskTriggers.GetTooltipContents,
                    sender,
                    new TaskEventArgs(ds.FrameworkContext, args));

            return new TooltipContents(args.HtmlContents)
                {
                    Height = args.Height,
                    Width = args.Width
                };
        }
Пример #4
0
        public static TypedEntity MapTypedEntity(XElement xElement)
        {
            Mandate.ParameterNotNull(xElement, "xElement");

            var attribs = new HashSet<TypedAttribute>();
            var ordinal = 0;
            foreach (var childElement in xElement.Elements().Where(x => !x.HasAttributes))
            {
                var typedAttribute = new TypedAttribute(new AttributeDefinition()
                                                            {
                                                                Alias = childElement.Name.LocalName,
                                                                Name = childElement.Name.LocalName,
                                                                Ordinal = ordinal,
                                                                Id = HiveId.Empty
                                                            }, childElement.Value)
                                         {
                                             Id = HiveId.Empty
                                         };
                attribs.Add(typedAttribute);
                ordinal++;
            }

            var nodeId = (int)xElement.Attribute("id");
            var returnValue = new TypedEntity
            {
                // TODO: Replace provider id with injected value inside UoWFactory
                Id = new HiveId("content", "r-xmlstore-01", new HiveIdValue(nodeId))
            };
            returnValue.Attributes.Reset(attribs);

            return returnValue;
        }
Пример #5
0
 public EntityPig(TypedEntity e)
     : base(e)
 {
     EntityPig e2 = e as EntityPig;
     if (e2 != null) {
         _saddle = e2._saddle;
     }
 }
Пример #6
0
 public EntityVillager(TypedEntity e)
     : base(e)
 {
     EntityVillager e2 = e as EntityVillager;
     if (e2 != null) {
         _profession = e2._profession;
     }
 }
Пример #7
0
 public EntityPrimedTnt(TypedEntity e)
     : base(e)
 {
     EntityPrimedTnt e2 = e as EntityPrimedTnt;
     if (e2 != null) {
         _fuse = e2._fuse;
     }
 }
 public EntityGuardian (TypedEntity e)
     : base(e)
 {
     EntityGuardian e2 = e as EntityGuardian;
     if (e2 != null) {
         _elder = e2._elder;
     }
 }
Пример #9
0
 public EntityPigZombie(TypedEntity e)
     : base(e)
 {
     EntityPigZombie e2 = e as EntityPigZombie;
     if (e2 != null) {
         _anger = e2._anger;
     }
 }
Пример #10
0
 public EntityCreeper(TypedEntity e)
     : base(e)
 {
     EntityCreeper e2 = e as EntityCreeper;
     if (e2 != null) {
         _powered = e2._powered;
     }
 }
Пример #11
0
 public EntityMinecart (TypedEntity e)
     : base(e)
 {
     EntityMinecart e2 = e as EntityMinecart;
     if (e2 != null) {
         _type = e2._type;
     }
 }
Пример #12
0
 public EntityMinecartChest (TypedEntity e)
     : base(e)
 {
     EntityMinecartChest e2 = e as EntityMinecartChest;
     if (e2 != null) {
         _items = e2._items.Copy();
     }
 }
Пример #13
0
 public EntitySlime(TypedEntity e)
     : base(e)
 {
     EntitySlime e2 = e as EntitySlime;
     if (e2 != null) {
         _size = e2._size;
     }
 }
Пример #14
0
 public EntityFallingSand(TypedEntity e)
     : base(e)
 {
     EntityFallingSand e2 = e as EntityFallingSand;
     if (e2 != null) {
         _tile = e2._tile;
     }
 }
 public EntityEnderman (TypedEntity e)
     : base(e)
 {
     EntityEnderman e2 = e as EntityEnderman;
     if (e2 != null) {
         _carried = e2._carried;
         _carryingData = e2._carryingData;
     }
 }
 public EntityEndermite(TypedEntity e)
     : base(e)
 {
     EntityEndermite e2 = e as EntityEndermite;
     if (e2 != null) {
         _life = e2._life;
         _player = e2._player;
     }
 }
Пример #17
0
 public EntityAnimal(TypedEntity e)
     : base(e)
 {
     EntityAnimal e2 = e as EntityAnimal;
     if (e2 != null) {
         _age = e2._age;
         _inLove = e2._inLove;
     }
 }
Пример #18
0
 public EntityArrow(TypedEntity e)
     : base(e)
 {
     EntityArrow e2 = e as EntityArrow;
     if (e2 != null) {
         _inData = e2._inData;
         _player = e2._player;
     }
 }
Пример #19
0
 public EntityBat(TypedEntity e)
     : base(e)
 {
     EntityBat e2 = e as EntityBat;
     if (e2 != null)
     {
         _flag = e2._flag;
     }
 }
Пример #20
0
 public EntitySheep (TypedEntity e)
     : base(e)
 {
     EntitySheep e2 = e as EntitySheep;
     if (e2 != null) {
         _sheared = e2._sheared;
         _color = e2._color;
     }
 }
 public EntityChicken (TypedEntity e)
     : base(e)
 {
     EntityChicken e2 = e as EntityChicken;
     if (e2 != null)
     {
         _eggTime = e2._eggTime;
     }
 }
        public EntityRabbit(TypedEntity e)
            : base(e)
        {
            EntityRabbit e2 = e as EntityRabbit;
            if (e2 != null) {
                _type = e2._type;
                _carrots = e2._carrots;
        }
}
 public EntityXPOrb (TypedEntity e)
     : base(e)
 {
     EntityXPOrb e2 = e as EntityXPOrb;
     if (e2 != null) {
         _health = e2._health;
         _age = e2._age;
         _value = e2._value;
     }
 }
Пример #24
0
        public void RecycleCacheFor(TypedEntity entity)
        {
            string niceUrl = entity.NiceUrl();

            RemoveFromProvider(entity, frameworkContext.Caches.LimitedLifetime, niceUrl);
            RemoveFromProvider(entity, frameworkContext.Caches.ExtendedLifetime, niceUrl);
            RemoveFromProvider(frameworkContext.ApplicationCache, niceUrl);

            RegenerateCache(niceUrl);
        }
Пример #25
0
 public EntityItem(TypedEntity e)
     : base(e)
 {
     EntityItem e2 = e as EntityItem;
     if (e2 != null) {
         _health = e2._health;
         _age = e2._age;
         _item = e2._item.Copy();
     }
 }
 public EntityMinecartFurnace(TypedEntity e)
     : base(e)
 {
     EntityMinecartFurnace e2 = e as EntityMinecartFurnace;
     if (e2 != null) {
         _pushX = e2._pushX;
         _pushZ = e2._pushZ;
         _fuel = e2._fuel;
     }
 }
Пример #27
0
 public EntityWolf (TypedEntity e)
     : base(e)
 {
     EntityWolf e2 = e as EntityWolf;
     if (e2 != null) {
         _owner = e2._owner;
         _sitting = e2._sitting;
         _angry = e2._angry;
     }
 }
 public EntityPigZombie (TypedEntity e)
     : base(e)
 {
     EntityPigZombie e2 = e as EntityPigZombie;
     if (e2 != null) {
         _anger = e2._anger;
         _villager = e2._villager;
         _baby = e2._baby;
         _breakDoors = e2._breakDoors;
     }
 }
 protected TypedEntity AddChildNode(TypedEntity parent, TypedEntity child, int sortOrder = 0)
 {
     using (var uow = this.HiveManager.OpenWriter<IContentStore>())
     {
         parent.RelationProxies.EnlistChild(child, FixedRelationTypes.DefaultRelationType, sortOrder);
         uow.Repositories.AddOrUpdate(parent);
         uow.Repositories.AddOrUpdate(child);
         uow.Complete();
     }
     return child;
 }
        /// <summary>
        /// Creates a new instance of a nonspecific <see cref="TypedEntity"/> object by NBT node.
        /// </summary>
        /// <param name="tree">A <see cref="TagNodeCompound"/> representing a single Entity, containing an 'id' field.</param>
        /// <returns>A new instance of a <see cref="TypedEntity"/> object, or null if the entity is not typed.</returns>
        public static TypedEntity CreateGeneric (TagNodeCompound tree)
        {
            TagNode type;
            if (!tree.TryGetValue("id", out type)) {
                return null;
            }

            TypedEntity te = new TypedEntity(type.ToTagString().Data);

            return te.LoadTreeSafe(tree);
        }
Пример #31
0
 /// <summary>
 /// Gets the URL of the file in the first upload field found on the given TypedEntity
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns></returns>
 public string GetMediaUrl(TypedEntity entity)
 {
     return(_urlHelper.GetMediaUrl(entity));
 }
Пример #32
0
 /// <summary>
 /// Gets the URL for the given entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns></returns>
 public string GetUrl(TypedEntity entity)
 {
     return(_requestContext.RoutingEngine.GetUrl(entity.Id));
 }
Пример #33
0
 public EntityCow(TypedEntity e)
     : base(e)
 {
 }
        public MethodEntity Parse(TypedEntity typedEntity, String selector, IEnumerable <XElement> elements)
        {
            MethodEntity methodEntity = new MethodEntity();

            XElement declarationElement = (from el in elements
                                           where el.Name == "div" &&
                                           el.Attribute("class") != null &&
                                           el.Attribute("class").Value == "declaration_indent"
                                           select el).FirstOrDefault();

            XElement parameterElement = (from el in elements
                                         where el.Name == "div" &&
                                         el.Attribute("class") != null &&
                                         el.Attribute("class").Value == "param_indent"
                                         select el).FirstOrDefault();

            XElement returnValueElement = (from el in elements
                                           where el.Name == "h5" && el.Value.Trim() == "Return Value"
                                           select el).FirstOrDefault();

            //XElement discussionElement = (from el in elements
            //                              where el.Name == "h5" && el.Value.Trim() == "Discussion"
            //                              select el).FirstOrDefault();

            XElement availabilityElement = (from el in elements
                                            let term = el.Descendants("dt").FirstOrDefault()
                                                       let definition = el.Descendants("dd").FirstOrDefault()
                                                                        where el.Name == "dl" &&
                                                                        term != null &&
                                                                        term.Value.Trim() == "Availability"
                                                                        select definition).FirstOrDefault();

            methodEntity.Selector = selector;
            methodEntity.Name     = GetMethodName(methodEntity);

            methodEntity.Signature = declarationElement.TrimAll();
            methodEntity.Signature = methodEntity.Signature.TrimEnd(';');

            methodEntity.Static = methodEntity.Signature.StartsWith("+");

            // Extract abstract
            IEnumerable <XElement> abstractElements = elements.SkipWhile(el => el.Name != "p").TakeWhile(el => el.Name == "p");

            foreach (XElement element in abstractElements)
            {
                String line = element.TrimAll();
                if (!String.IsNullOrEmpty(line))
                {
                    methodEntity.Summary.Add(line);
                }
            }

            //// Extract discussion
            //if (discussionElement != null)
            //{
            //    IEnumerable<XElement> discussionElements = discussionElement.ElementsAfterSelf().TakeWhile(el => el.Name == "p");
            //    foreach (XElement element in discussionElements)
            //    {
            //        String line = element.TrimAll();
            //        if (!String.IsNullOrEmpty(line))
            //        {
            //            methodEntity.Summary.Add(line);
            //        }
            //    }
            //}

            // Extract return type
            MethodSignatureEnumerator signatureEnumerator = new MethodSignatureEnumerator(methodEntity.Signature);

            if (signatureEnumerator.MoveNext())
            {
                methodEntity.ReturnType = this.TypeManager.ConvertType(signatureEnumerator.Current.TrimAll(), this.Logger);
            }
            else
            {
                methodEntity.ReturnType = "Id";
            }

            // Extract parameter type and name
            MethodParametersEnumerator parameterTypesEnumerator = new MethodParametersEnumerator(methodEntity.Signature, false);
            MethodParametersEnumerator parameterNamesEnumerator = new MethodParametersEnumerator(methodEntity.Signature, true);

            while (parameterTypesEnumerator.MoveNext() && parameterNamesEnumerator.MoveNext())
            {
                MethodParameterEntity parameterEntity = new MethodParameterEntity();
                bool isOut, isByRef, isBlock;
                parameterEntity.Type    = this.TypeManager.ConvertType(parameterTypesEnumerator.Current, out isOut, out isByRef, out isBlock, this.Logger);
                parameterEntity.IsOut   = isOut;
                parameterEntity.IsByRef = isByRef;
                parameterEntity.IsBlock = isBlock;
                parameterEntity.Name    = parameterNamesEnumerator.Current.Trim();
                methodEntity.Parameters.Add(parameterEntity);
            }

            if (methodEntity.Parameters.Count > 0 && parameterElement != null)
            {
                XElement termList = parameterElement.Descendants("dl").FirstOrDefault();
                if (termList != null)
                {
                    IEnumerable <XElement> dtList = from el in termList.Elements("dt") select el;
                    IEnumerable <XElement> ddList = from el in termList.Elements("dd") select el;

                    if (dtList.Count() == ddList.Count())
                    {
                        // Iterate over definitions
                        for (int i = 0; i < dtList.Count(); i++)
                        {
                            String term = dtList.ElementAt(i).TrimAll();
                            //String summary = ddList.ElementAt(i).TrimAll();
                            IEnumerable <String> summaries = ddList.ElementAt(i).Elements("p").Select(p => p.Value.TrimAll());

                            // Find the parameter
                            MethodParameterEntity parameterEntity = methodEntity.Parameters.Find(p => String.Equals(p.Name, term));
                            if (parameterEntity != null)
                            {
                                //parameterEntity.Summary.Add(summary);
                                foreach (string sum in summaries)
                                {
                                    parameterEntity.Summary.Add(sum);
                                }
                            }
                        }
                    }
                }
            }

            // Fix the name only after looking for the documentation
            for (int i = 0; i < methodEntity.Parameters.Count; i++)
            {
                methodEntity.Parameters[i].Name = this.TypeManager.ConvertName(methodEntity.Parameters[i].Name);
            }

            // Get the summary for return type
            if (!String.Equals(methodEntity.ReturnType, "void", StringComparison.OrdinalIgnoreCase) && returnValueElement != null)
            {
                IEnumerable <XElement> returnTypeElements = returnValueElement.ElementsAfterSelf().TakeWhile(el => el.Name == "p");
                methodEntity.ReturnsDocumentation = String.Empty;
                foreach (XElement element in returnTypeElements)
                {
                    String line = element.TrimAll();
                    if (!String.IsNullOrEmpty(line))
                    {
                        methodEntity.ReturnsDocumentation += line;
                    }
                }
            }

            // Get the availability
            if (availabilityElement != null)
            {
                methodEntity.MinAvailability = CommentHelper.ExtractAvailability(availabilityElement.TrimAll());
            }

            return(methodEntity);
        }
        /// <summary>
        /// Determines whether the specified entity is content.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="uow"></param>
        /// <returns>
        ///   <c>true</c> if the specified entity is content; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsContent(this TypedEntity entity, IReadonlyGroupUnit <IContentStore> uow)
        {
            var ancestorRelations = uow.Repositories.GetAncestorRelations(entity.Id, FixedRelationTypes.DefaultRelationType).ToArray();

            return(ancestorRelations.Any(x => x.SourceId.Value == FixedHiveIds.ContentVirtualRoot.Value));
        }
        /// <summary>
        ///   Parses the specified property element.
        /// </summary>
        /// <param name = "propertyElement">The property element.</param>
        /// <returns></returns>
        public PropertyEntity Parse(TypedEntity typedEntity, XElement propertyElement)
        {
            XElement nameElement = propertyElement.Element("h3");
            String   name        = nameElement.TrimAll();

            this.Logger.WriteLine("  Property '" + name + "'");

            // Extract the declaration
            XElement signatureElement = (from el in propertyElement.Elements("div")
                                         where (String)el.Attribute("class") == "declaration"
                                         select el).FirstOrDefault();
            String signature = signatureElement.TrimAll();

            // Extract the abstract
            XElement abstractElement = (from el in propertyElement.Elements("p")
                                        where (String)el.Attribute("class") == "abstract"
                                        select el).FirstOrDefault();
            List <String> summary = new List <String>();

            summary.Add(abstractElement.TrimAll());

            //// Extract discussion
            //XElement discussionElement = (from el in propertyElement.Elements("div")
            //                              where (String) el.Attribute("class") == "api discussion"
            //                              select el).FirstOrDefault();
            //if (discussionElement != null)
            //{
            //    foreach (XElement paragraph in discussionElement.Elements("p"))
            //    {
            //        summary.Add(paragraph.TrimAll());
            //    }
            //}

            // Get the availability
            XElement availabilityElement = (from el in propertyElement.Elements("div")
                                            where (String)el.Attribute("class") == "api availability"
                                            select el).FirstOrDefault();
            String minAvailability = null;

            if (availabilityElement != null)
            {
                minAvailability = availabilityElement.Elements("ul").Elements("li").FirstOrDefault().TrimAll();
            }
            minAvailability = CommentHelper.ExtractAvailability(minAvailability);

            // Extract property's attribute
            List <String> attributes      = new List <String>();
            int           attributesStart = signature.IndexOf('(');
            int           attributesEnd   = signature.IndexOf(')');

            if (attributesStart > 0 && attributesEnd > attributesStart)
            {
                String attributesAll = signature.Substring(attributesStart + 1, attributesEnd - attributesStart - 1);
                attributes.AddRange(attributesAll.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(attr => attr.Trim()));
            }
            int    typeStart  = attributesEnd > 0 ? (attributesEnd + 1) : "@property".Length;
            int    typeEnd    = signature.LastIndexOf(name);
            string returnType = (typeStart > 0 && typeEnd > typeStart) ? signature.Substring(typeStart, typeEnd - typeStart).Trim() : "MISSING";

            // Is the property readonly ?
            bool readOnly = attributes.Contains("readonly");

            // Is there an explicit getter
            String getterSelector = attributes.Find(a => a.Contains("getter"));

            if (getterSelector != null)
            {
                getterSelector = getterSelector.Substring(getterSelector.IndexOf('=') + 1);
            }
            else
            {
                getterSelector = name;
            }

            // Alter the name
            name = name.UpperCaseFirstLetter();

            // Is there an explicit setter
            String setterSelector = attributes.Find(a => a.Contains("setter"));

            if (setterSelector != null)
            {
                setterSelector = setterSelector.Substring(setterSelector.IndexOf('=') + 1);
            }
            else
            {
                setterSelector = "set" + name + ":";
            }

            bool   isOut, isByRef, isBlock;
            String type = this.TypeManager.ConvertType(returnType, out isOut, out isByRef, out isBlock, this.Logger);

            PropertyEntity propertyEntity = new PropertyEntity();

            propertyEntity.MinAvailability = minAvailability;
            propertyEntity.Name            = getterSelector.UpperCaseFirstLetter();
            propertyEntity.Static          = false;
            propertyEntity.Summary         = summary;
            propertyEntity.Type            = type;

            propertyEntity.Getter           = new MethodEntity();
            propertyEntity.Getter.Signature = signature;
            propertyEntity.Getter.Selector  = getterSelector;

            if (readOnly)
            {
                propertyEntity.Setter = null;
            }
            else
            {
                propertyEntity.Setter           = new MethodEntity();
                propertyEntity.Setter.Signature = signature;
                propertyEntity.Setter.Selector  = setterSelector;
            }

            return(propertyEntity);
        }
Пример #37
0
        public MethodEntity Parse(TypedEntity typedEntity, XElement methodElement)
        {
            MethodEntity methodEntity = new MethodEntity();

            bool   isStatic   = (methodElement.Attribute("static").Value == "yes");
            String selector   = methodElement.Element("name").TrimAll();
            String returnType = methodElement.Element("type").TrimAll();

            // Elements for brief description
            IEnumerable <XElement> abstractElements = methodElement.Element("briefdescription").Elements("para");

            // Extract for detailed description
            IEnumerable <XElement> detailsElements = (from el in methodElement.Element("detaileddescription").Elements("para")
                                                      where !el.Elements("simplesect").Any() &&
                                                      el.Elements("parameterlist").Any() &&
                                                      el.Elements("xrefsect").Any()
                                                      select el);

            // Element for parameters
            IEnumerable <XElement> parameterElements = methodElement.Elements("param");

            // Element for detailed description
            XElement detailedDescriptionElement = methodElement.Element("detaileddescription");

            // Sets some data
            methodEntity.Selector = selector;
            methodEntity.Name     = GetMethodName(methodEntity);
            methodEntity.Static   = isStatic;

            // Add brief description
            foreach (XElement paragraph in abstractElements)
            {
                methodEntity.Summary.Add(paragraph.TrimAll());
            }
            foreach (XElement paragraph in detailsElements)
            {
                methodEntity.Summary.Add(paragraph.TrimAll());
            }

            // Recreate the signature
            StringBuilder signature = new StringBuilder();

            signature.Append(isStatic ? "+ " : "- ");
            signature.AppendFormat("({0})", returnType);
            if (selector.IndexOf(":") != -1)
            {
                String[] parts = selector.Split(':');
                for (int i = 0; i < parameterElements.Count(); i++)
                {
                    XElement parameterElement = parameterElements.ElementAt(i);
                    String   parameterType    = parameterElement.Element("type").TrimAll();

                    String parameterName;
                    if (parameterType.Equals("..."))
                    {
                        parameterName = String.Empty;
                    }
                    else
                    {
                        parameterName = parameterElement.Element("declname").TrimAll();
                        if (parameterElement.Element("defname") != null)
                        {
                            parameterName = parameterElement.Element("defname").TrimAll();
                        }
                    }

                    signature.Append(parts [i]);
                    signature.AppendFormat(":({0}){1} ", parameterType, parameterName);
                }
            }
            else
            {
                signature.Append(selector);
            }
            methodEntity.Signature = signature.ToString().Trim() + ";";

            // Set the return type
            methodEntity.ReturnType = this.TypeManager.ConvertType(returnType, this.Logger);

            // Extract documentation for return type
            if (!String.Equals(returnType, "void", StringComparison.OrdinalIgnoreCase))
            {
                XElement returnTypeSectionElement = (from el in detailedDescriptionElement.Descendants("simplesect")
                                                     where el.Attribute("kind") != null &&
                                                     el.Attribute("kind").Value == "return"
                                                     select el).FirstOrDefault();
                if (returnTypeSectionElement != null)
                {
                    IEnumerable <String> documentations = (from el in returnTypeSectionElement.Elements("para")
                                                           select el.TrimAll());
                    methodEntity.ReturnsDocumentation = String.Join(" ", documentations.ToArray());
                }
            }

            // Create the parameters
            for (int i = 0; i < parameterElements.Count(); i++)
            {
                XElement parameterElement = parameterElements.ElementAt(i);
                String   parameterType    = parameterElement.Element("type").TrimAll();

                String parameterName;
                if (parameterType.Equals("..."))
                {
                    parameterType = "params Object[]";
                    parameterName = "values";
                }
                else
                {
                    parameterName = parameterElement.Element("declname").TrimAll();
                    if (parameterElement.Element("defname") != null)
                    {
                        parameterName = parameterElement.Element("defname").TrimAll();
                    }
                }

                MethodParameterEntity parameterEntity = new MethodParameterEntity();
                bool isOut, isByRef, isBlock;
                parameterEntity.Type    = this.TypeManager.ConvertType(parameterType, out isOut, out isByRef, out isBlock, this.Logger);
                parameterEntity.IsOut   = isOut;
                parameterEntity.IsByRef = isByRef;
                parameterEntity.IsBlock = isBlock;
                parameterEntity.Name    = parameterName;
                methodEntity.Parameters.Add(parameterEntity);
            }

            // Extract documentation for parameters
            XElement parameterSectionElement = (from el in detailedDescriptionElement.Descendants("parameterlist")
                                                where el.Attribute("kind") != null &&
                                                el.Attribute("kind").Value == "param"
                                                select el).FirstOrDefault();

            if (parameterSectionElement != null)
            {
                IEnumerable <XElement> parameterItemElements = parameterSectionElement.Elements("parameteritem");
                for (int i = 0; i < parameterElements.Count(); i++)
                {
                    XElement parameterElement = parameterElements.ElementAt(i);
                    String   parameterType    = parameterElement.Element("type").TrimAll();
                    String   parameterName;
                    if (parameterType.Equals("..."))
                    {
                        continue;
                    }
                    else
                    {
                        parameterName = parameterElement.Element("declname").TrimAll();
                        if (parameterElement.Element("defname") != null)
                        {
                            parameterName = parameterElement.Element("defname").TrimAll();
                        }
                    }

                    MethodParameterEntity parameterEntity = methodEntity.Parameters.Find(p => String.Equals(p.Name, parameterName));

                    IEnumerable <XElement> documentations = (from el in parameterItemElements
                                                             let filter = el.Element("parameternamelist").Value.TrimAll()
                                                                          where String.Equals(filter, parameterName)
                                                                          select el);
                    if (documentations.Count() > 0)
                    {
                        XElement documentation = documentations.Elements("parameterdescription").First();
                        foreach (XElement element in documentation.Elements("para"))
                        {
                            parameterEntity.Summary.Add(element.TrimAll());
                        }
                    }
                }
            }

            // Fix the name only after looking for the documentation
            for (int i = 0; i < methodEntity.Parameters.Count; i++)
            {
                methodEntity.Parameters [i].Name = this.TypeManager.ConvertName(methodEntity.Parameters [i].Name);
            }

            /*
             *
             * // Get the availability
             * if (availabilityElement != null)
             * {
             * methodEntity.MinAvailability = CommentHelper.ExtractAvailability(availabilityElement.TrimAll());
             * }
             */

            return(methodEntity);
        }
Пример #38
0
 /// <summary>
 /// Gets the URL of the file in the upload field with the given property alias on the given TypedEntity
 /// </summary>
 /// <param name="url">The URL.</param>
 /// <param name="entity">The entity.</param>
 /// <param name="propertyAlias">The property alias.</param>
 /// <returns></returns>
 public static string GetMediaUrl(this UrlHelper url, TypedEntity entity, string propertyAlias)
 {
     return(url.GetMediaUrl(entity, propertyAlias, 0));
 }
        protected TypedEntity AddChildNodeWithId(TypedEntity parent, HiveId childGuid, int sortOrder = 0)
        {
            var child = HiveModelCreationHelper.MockTypedEntity(childGuid);

            return(AddChildNode(parent, child, sortOrder));
        }
Пример #40
0
 public EntityEnderEye(TypedEntity e)
     : base(e)
 {
 }
Пример #41
0
 public EntitySilverfish(TypedEntity e)
     : base(e)
 {
 }
Пример #42
0
 public EntityCaveSpider(TypedEntity e)
     : base(e)
 {
 }
Пример #43
0
 /// <summary>
 /// Gets the URL of the file in the first upload field found on the given TypedEntity at the specific size
 /// </summary>
 /// <param name="url">The URL.</param>
 /// <param name="entity">The entity.</param>
 /// <param name="size">The size (must be a prevalue on the upload property editor).</param>
 /// <returns></returns>
 public static string GetMediaUrl(this UrlHelper url, TypedEntity entity, int size)
 {
     return(url.GetMediaUrl(entity, null, size));
 }
Пример #44
0
 /// <summary>
 /// Gets the URL of the file in the first upload field found on the given TypedEntity at the specific size
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <param name="size">The size (must be a prevalue on the upload property editor).</param>
 /// <returns></returns>
 public string GetMediaUrl(TypedEntity entity, int size)
 {
     return(_urlHelper.GetMediaUrl(entity, size));
 }
Пример #45
0
 public EntitySkeleton(TypedEntity e)
     : base(e)
 {
 }
Пример #46
0
 public EntityEgg(TypedEntity e)
     : base(e)
 {
 }
Пример #47
0
 public UrlResolutionResult GetUrlForEntity(TypedEntity entity)
 {
     return(new UrlResolutionResult("/this-is-a-test", UrlResolutionStatus.SuccessWithoutHostname));
 }
Пример #48
0
 /// <summary>
 /// Creates a new RedirectToUmbracoResult
 /// </summary>
 /// <param name="pageEntity"></param>
 public RedirectToUmbracoPageResult(TypedEntity pageEntity)
     : this(pageEntity, DependencyResolver.Current.GetService <IRoutableRequestContext>())
 {
 }
Пример #49
0
 /// <summary>
 /// Redirects to the Rebel page with the given id
 /// </summary>
 /// <param name="pageEntity"></param>
 /// <returns></returns>
 protected RedirectToRebelPageResult RedirectToRebelPage(TypedEntity pageEntity)
 {
     return(new RedirectToRebelPageResult(pageEntity, RoutableRequestContext));
 }
 /// <summary>
 /// Determines whether the specified entity is media.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <param name="uow"></param>
 /// <returns>
 ///   <c>true</c> if the specified entity is media; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsMedia(this TypedEntity entity, IReadonlyGroupUnit <IContentStore> uow)
 {
     return(uow.Repositories.GetAncestorRelations(entity.Id, FixedRelationTypes.DefaultRelationType).Any(x => x.SourceId.Value == FixedHiveIds.MediaVirtualRoot.Value));
 }
        /// <summary>
        /// Executes the task.
        /// </summary>
        protected override void ExecuteTask()
        {
            String baseFolder = this.CreateBaseDir();
            DocSet docSet     = this.CreateDocSet();
            IEnumerable <Framework> frameworks = this.CreateFrameworks(docSet);
            IList <FrameworkEntity> entities   = frameworks.SelectMany(f => f.GetEntities()).ToList();

            String mixedTypesFile = this.MixedTypesFile.ToString();
            Dictionary <String, String> mixedTypesTable = new Dictionary <String, String> ();

            this.LoadMixedTypes(mixedTypesFile, mixedTypesTable);

            foreach (var e in entities)
            {
                String sourcePath = e.GetPath(baseFolder, DocumentType.Model);
                if (sourcePath == null || !File.Exists(sourcePath))
                {
                    continue;
                }

                if (sourcePath.IsOlderThan(mixedTypesFile))
                {
                    continue;
                }

                this.Log(Level.Verbose, String.Format("Scanning '{0}' for mixed types...", e.name));

                switch (e.type)
                {
                case FrameworkEntityType.T:
                {
                    TypedEntity entity = BaseEntity.LoadFrom <TypedEntity> (sourcePath);
                    if (entity.Generate)
                    {
                        foreach (EnumerationEntity enumerationEntity in entity.Enumerations)
                        {
                            if (!enumerationEntity.Generate)
                            {
                                continue;
                            }
                            this.AddMixedType(mixedTypesTable, enumerationEntity);
                        }
                    }
                }
                break;

                case FrameworkEntityType.C:
                {
                    ClassEntity entity = BaseEntity.LoadFrom <ClassEntity> (sourcePath);
                    if (entity.Generate)
                    {
                        foreach (EnumerationEntity enumerationEntity in entity.Enumerations)
                        {
                            if (!enumerationEntity.Generate)
                            {
                                continue;
                            }
                            this.AddMixedType(mixedTypesTable, enumerationEntity);
                        }
                    }
                }
                break;

                case FrameworkEntityType.P:
                {
                    ProtocolEntity entity = BaseEntity.LoadFrom <ProtocolEntity> (sourcePath);
                    if (entity.Generate)
                    {
                        foreach (EnumerationEntity enumerationEntity in entity.Enumerations)
                        {
                            if (!enumerationEntity.Generate)
                            {
                                continue;
                            }
                            this.AddMixedType(mixedTypesTable, enumerationEntity);
                        }
                    }
                }
                break;

                case FrameworkEntityType.S:
                {
                    StructureEntity entity = BaseEntity.LoadFrom <StructureEntity> (sourcePath);
                    if (entity.Generate)
                    {
                        this.AddMixedType(mixedTypesTable, entity);
                    }
                }
                break;

                case FrameworkEntityType.E:
                {
                    EnumerationEntity entity = BaseEntity.LoadFrom <EnumerationEntity> (sourcePath);
                    if (entity.Generate)
                    {
                        this.AddMixedType(mixedTypesTable, entity);
                    }
                }
                break;

                default:
                    throw new NotSupportedException("Entity type not support: " + e.type);
                }
            }

            this.SaveMixedTypes(mixedTypesFile, mixedTypesTable);
        }
Пример #52
0
 public EntitySnowman(TypedEntity e)
     : base(e)
 {
 }
        public void Initialize()
        {
            #region Vars

            IReadonlyEntityRepositoryGroup <IContentStore> readonlyContentStoreRepository;
            IReadonlySchemaRepositoryGroup <IContentStore> readonlyContentStoreSchemaRepository;
            IEntityRepositoryGroup <IContentStore>         contentStoreRepository;
            ISchemaRepositoryGroup <IContentStore>         contentStoreSchemaRepository;

            IReadonlyEntityRepositoryGroup <IFileStore> readonlyFileStoreRepository;
            IReadonlySchemaRepositoryGroup <IFileStore> readonlyFileStoreSchemaRepository;
            IEntityRepositoryGroup <IFileStore>         fileStoreRepository;
            ISchemaRepositoryGroup <IFileStore>         fileStoreSchemaRepository;

            #endregion

            var hive = MockHiveManager.GetManager()
                       .MockContentStore(out readonlyContentStoreRepository, out readonlyContentStoreSchemaRepository, out contentStoreRepository, out contentStoreSchemaRepository)
                       .MockFileStore(out readonlyFileStoreRepository, out readonlyFileStoreSchemaRepository, out fileStoreRepository, out fileStoreSchemaRepository);

            //Setup file store
            var fileId = new HiveId("storage", "file-uploader", new HiveIdValue("test.jpg"));
            var file   = new File
            {
                Id           = fileId,
                Name         = "test.jpg",
                ContentBytes = Encoding.UTF8.GetBytes("test")
            };

            readonlyFileStoreRepository
            .Get <File>(true, Arg.Any <HiveId[]>())
            .Returns(new[] { file });

            var thumbnailId = new HiveId("storage", "file-uploader", new HiveIdValue("test_100.jpg"));
            var thumbnail   = new File
            {
                Id           = thumbnailId,
                Name         = "test_100.jpg",
                ContentBytes = Encoding.UTF8.GetBytes("test_100")
            };

            var relation = Substitute.For <IReadonlyRelation <IRelatableEntity, IRelatableEntity> >();
            relation.MetaData.Returns(new RelationMetaDataCollection(new[] { new RelationMetaDatum("size", "100") }));
            relation.Source.Returns(file);
            relation.SourceId.Returns(fileId);
            relation.Destination.Returns(thumbnail);
            relation.DestinationId.Returns(thumbnailId);

            readonlyFileStoreRepository.GetLazyChildRelations(fileId, FixedRelationTypes.ThumbnailRelationType)
            .Returns(new[] { relation });

            //Setup media store
            var mediaPickerAttributeDefType = new AttributeType {
                RenderTypeProvider = CorePluginConstants.FileUploadPropertyEditorId
            };
            var mediaPickerAttributeDef = new AttributeDefinition("umbracoFile", "")
            {
                Id = FixedHiveIds.FileUploadAttributeType, AttributeType = mediaPickerAttributeDefType
            };
            var mediaPickerProperty = new TypedAttribute(mediaPickerAttributeDef, fileId.ToString());

            var mediaId     = new HiveId("0A647849-BF5C-413B-9420-7AB4C9521505");
            var mediaEntity = new TypedEntity {
                Id = mediaId
            };
            mediaEntity.Attributes.Add(mediaPickerProperty);

            //readonlyContentStoreRepository
            //    .Get<TypedEntity>(true, Arg.Any<HiveId[]>())
            //    .Returns(new[] { mediaEntity });

            //readonlyContentStoreRepository
            //    .SingleOrDefault<TypedEntity>(Arg.Any<Expression<Func<TypedEntity, bool>>>())
            //    .Returns(mediaEntity);

            var mediaEntityList = new List <TypedEntity> {
                mediaEntity
            };
            readonlyContentStoreRepository
            .Provider
            .Returns(mediaEntityList.AsQueryable().Provider);

            // Setup application
            var appContext = Substitute.For <IUmbracoApplicationContext>();
            appContext.Hive.Returns(hive);

            // Setup back office request
            _backOfficeRequestContext = Substitute.For <IBackOfficeRequestContext>();
            _backOfficeRequestContext.Application.Returns(appContext);
        }
Пример #54
0
 public EntityGhast(TypedEntity e)
     : base(e)
 {
 }
Пример #55
0
 /// <summary>
 /// Gets the URL of the file in the upload field with the given property alias on the given TypedEntity
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <param name="propertyAlias">The property alias.</param>
 /// <returns></returns>
 public string GetMediaUrl(TypedEntity entity, string propertyAlias)
 {
     return(_urlHelper.GetMediaUrl(entity, propertyAlias));
 }
Пример #56
0
 /// <summary>
 /// Creates a new RedirectToUmbracoResult
 /// </summary>
 /// <param name="pageEntity"></param>
 /// <param name="routableRequestContext"></param>
 public RedirectToUmbracoPageResult(TypedEntity pageEntity, IRoutableRequestContext routableRequestContext)
 {
     _pageEntity             = pageEntity;
     _pageId                 = pageEntity.Id;
     _routableRequestContext = routableRequestContext;
 }
Пример #57
0
        /// <summary>
        /// Gets the URL of the file in the upload field with the given property alias on the given TypedEntity at the specific size
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="propertyAlias">The property alias.</param>
        /// <param name="size">The size (must be a prevalue on the upload property editor).</param>
        /// <returns></returns>
        public static string GetMediaUrl(this UrlHelper url, TypedEntity entity, string propertyAlias, int size)
        {
            //TODO: There is a lot of duplication between this and the MediaProxyController (with slight differences). Need to find a way to reuse code.

            var appContext = DependencyResolver.Current.GetService <IUmbracoApplicationContext>();

            using (var securityUow = appContext.Hive.OpenReader <ISecurityStore>())
            {
                // Get anonymous role
                var resultIds = entity.Id.AsEnumerableOfOne().ToArray();

                using (var contentUow = appContext.Hive.OpenReader <IContentStore>())
                    resultIds = resultIds.FilterAnonymousWithPermissions(appContext.Security, contentUow, securityUow, new Guid(FixedPermissionIds.View)).ToArray();

                // Check to see if anonymous view is allowed
                var anonymousViewAllowed = resultIds.Length != 0;

                // Get upload property
                var prop = propertyAlias.IsNullOrWhiteSpace()
                    ? entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.AttributeType.RenderTypeProvider.InvariantEquals(CorePluginConstants.FileUploadPropertyEditorId))
                    : entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.Alias == propertyAlias);

                if (prop == null || !prop.Values.ContainsKey("MediaId"))
                {
                    return(null); // Couldn't find property so return null
                }
                var mediaId = prop.Values["MediaId"].ToString();
                var fileId  = new HiveId(prop.Values["Value"].ToString());

                // Get the file
                using (var fileUow = appContext.Hive.OpenReader <IFileStore>(fileId.ToUri()))
                {
                    var file = fileUow.Repositories.Get <File>(fileId);

                    if (file == null)
                    {
                        return(null); // Couldn't find file so return null
                    }
                    // Fetch the thumbnail
                    if (size > 0)
                    {
                        var relation = fileUow.Repositories.GetLazyChildRelations(fileId, FixedRelationTypes.ThumbnailRelationType)
                                       .SingleOrDefault(x => x.MetaData.Single(y => y.Key == "size").Value == size.ToString());

                        file = (relation != null && relation.Destination != null)
                            ? (File)relation.Destination
                            : null;
                    }

                    if (file == null)
                    {
                        return(null);                                                      // Couldn't find file so return null
                    }
                    if (anonymousViewAllowed && !file.PublicUrl.StartsWith("~/App_Data/")) // Don't proxy
                    {
                        return(url.Content(file.PublicUrl));
                    }
                    else // Proxy
                    {
                        //NOTE: THIS IS TEMPORARY CODE UNTIL MEMBER PERMISSIONS IS DONE
                        if (anonymousViewAllowed)
                        {
                            // If they are anonymous, but media happens to be in app_data folder proxy
                            return(url.Action("Proxy", "MediaProxy", new { area = "", propertyAlias = prop.AttributeDefinition.Alias, mediaId, size, fileName = file.Name }));
                        }

                        return(null);

                        // Check permissions
                        //var authAttr = new UmbracoAuthorizeAttribute {AllowAnonymous = true, Permissions = new [] { FixedPermissionIds.View }};
                        //var authorized = authAttr.IsAuthorized(url.RequestContext.HttpContext, entity.Id);
                        //if (!authorized)
                        //    return null; // Not authorized so return null

                        //return url.Action("Proxy", "MediaProxy", new { area = "", propertyAlias = prop.AttributeDefinition.Alias, mediaId, size, fileName = file.Name });
                    }
                }
            }
        }
Пример #58
0
 public EntityEnderPearl(TypedEntity e)
     : base(e)
 {
 }
Пример #59
0
 public EntityMonster(TypedEntity e)
     : base(e)
 {
 }