/// <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
                };
        }
        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;
        }
Beispiel #3
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));
            }

        }
        public CompositeTypedEntity(TypedEntity entity)
        {
            Attributes.Clear();
            entity.Attributes.ForEach(x => Attributes.Add(x));

            RelationProxies.LazyLoadDelegate = entity.RelationProxies.LazyLoadDelegate;
        }
 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;
 }
 private TypedEntity CreateTypedEntity()
 {
     var entity = new TypedEntity
     {
         EntitySchema = new EntitySchema("schema", "Schema") { SchemaType = "Content", Id = new HiveId(Guid.NewGuid()) },
         Id = new HiveId(Guid.NewGuid()),
         UtcCreated = DateTimeOffset.UtcNow,
         UtcModified = DateTimeOffset.UtcNow,
         UtcStatusChanged = DateTimeOffset.UtcNow
     };
     SetupTypedEntity(entity);
     return entity;
 }
        private void SetupTypedEntity(TypedEntity entity)
        {

            entity.EntitySchema.AttributeGroups.Add(new AttributeGroup("tab1", "Tab 1", 0));
            entity.EntitySchema.AttributeGroups.Add(new AttributeGroup("tab2", "Tab 2", 1));
            entity.EntitySchema.AttributeGroups.Add(new AttributeGroup("tab3", "Tab 3", 2));
            entity.EntitySchema.AttributeDefinitions.Add(new AttributeDefinition("property1", "Property 1") { Description = "property1", AttributeGroup = entity.EntitySchema.AttributeGroups.ElementAt(0), AttributeType = _stringAttType });
            entity.EntitySchema.AttributeDefinitions.Add(new AttributeDefinition("property2", "Property 2") { Description = "property2", AttributeGroup = entity.EntitySchema.AttributeGroups.ElementAt(1), AttributeType = _stringAttType });
            entity.EntitySchema.AttributeDefinitions.Add(new AttributeDefinition("property3", "Property 3") { Description = "property3", AttributeGroup = entity.EntitySchema.AttributeGroups.ElementAt(2), AttributeType = _stringAttType });

            entity.Attributes.Add(new TypedAttribute(entity.EntitySchema.AttributeDefinitions.ElementAt(0), "Value 1"));
            entity.Attributes.Add(new TypedAttribute(entity.EntitySchema.AttributeDefinitions.ElementAt(1), "Value 2"));
            entity.Attributes.Add(new TypedAttribute(entity.EntitySchema.AttributeDefinitions.ElementAt(2), "Value 3"));

        }
Beispiel #8
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="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 string GetMediaUrl(TypedEntity entity, string propertyAlias, int size)
 {
     return _urlHelper.GetMediaUrl(entity, propertyAlias, size);
 }
Beispiel #9
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);
 }
Beispiel #10
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);
 }
 public NodeSelectorTooltipEventArgs(TypedEntity entity, string htmlContents)
 {
     Entity = entity;
     HtmlContents = htmlContents;
 }
        private static void ChangeValue(TypedAttribute nodeNameAttr, IQueryable<TypedEntity> parentQuery, TypedEntity item, string potentialValue, string valueKey, string existsSuffixCheck, string defaultSuffix, string dupeFormat)
        {
            var iterationCount = 0;
            var itExists = false;
            var originalValue = potentialValue;
            var valueCheck = potentialValue;
            do
            {
                iterationCount++;
                itExists = parentQuery.Any(x => x.InnerAttribute<string>(NodeNameAttributeDefinition.AliasValue, valueKey) == valueCheck && x.Id != item.Id);
                if (itExists)
                {
                    // Don't concatenate (1) (2) etc. just use the original value plus a count
                    valueCheck = originalValue + string.Format(dupeFormat, iterationCount);
                }
            } while (itExists);

            if (iterationCount > 1)
            {
                nodeNameAttr.Values[valueKey] = valueCheck;
            }

            //var exists = parentQuery
            //    .Any(x => x.InnerAttribute<string>(NodeNameAttributeDefinition.AliasValue, valueKey) == potentialValue && x.Id != item.Id);

            //if (exists)
            //{
            //    // Get the count of items matching potentialValue + "("
            //    var dupeName = potentialValue + existsSuffixCheck;
            //    var items = parentQuery
            //        .Where(
            //            x =>
            //            x.InnerAttribute<string>(NodeNameAttributeDefinition.AliasValue, valueKey).StartsWith(dupeName) &&
            //            x.Id != item.Id)
            //        .ToList();

            //    var itemsDebug = items.Select(x => new
            //        {
            //            x.Id,
            //            x.Attributes,
            //            ValueKey = x.InnerAttribute<string>(NodeNameAttributeDefinition.AliasValue, valueKey)
            //        }).ToArray();

            //    var count = items.Count;

            //    if (count == 0)
            //    {
            //        potentialValue = potentialValue + defaultSuffix;
            //    }
            //    else
            //    {
            //        var newCount = (count + 1);
            //        var format = string.Format(dupeFormat, newCount);
            //        potentialValue = potentialValue + format;
            //    }
            //}

            //nodeNameAttr.Values[valueKey] = potentialValue;
        }
 /// <summary>
 /// Creates a new RedirectToUmbracoResult
 /// </summary>
 /// <param name="pageEntity"></param>
 public RedirectToUmbracoPageResult(TypedEntity pageEntity)
     : this(pageEntity, DependencyResolver.Current.GetService<IRoutableRequestContext>())
 {
 }
 /// <summary>
 /// Redirects to the Umbraco page with the given id
 /// </summary>
 /// <param name="pageEntity"></param>
 /// <returns></returns>
 protected RedirectToUmbracoPageResult RedirectToUmbracoPage(TypedEntity pageEntity)
 {
     return new RedirectToUmbracoPageResult(pageEntity, RoutableRequestContext);
 }
 public EntityRouteResult(TypedEntity entity, EntityRouteStatus status)
 {
     Status = status;
     RoutableEntity = entity;
 }
 protected virtual string GetTreeNodeAlias(TypedEntity x)
 {
     var toReturn = string.Empty;
     var nodeName = x.Attributes.FirstOrDefault(y => y.AttributeDefinition.Alias == NodeNameAttributeDefinition.AliasValue);
     if (nodeName != null) toReturn = nodeName.GetValueAsString("Name");
     if (string.IsNullOrEmpty(toReturn))
     {
         if (x.EntitySchema != null)
         {
             toReturn = "[Unnamed {0}]".InvariantFormat(string.IsNullOrEmpty(x.EntitySchema.Name)
                                                            ? x.EntitySchema.Alias
                                                            : (string)x.EntitySchema.Name);
         }
         else
         {
             toReturn = "[Unnamed, untyped]";
         }
     }
     return toReturn;
 }
        protected virtual TreeNode ConvertEntityToTreeNode(TypedEntity entity, HiveId parentId, FormCollection queryStrings, IReadonlyGroupUnit<IContentStore> uow)
        {
            var treeNode = CreateTreeNode(entity.Id,
                queryStrings,
                GetTreeNodeAlias(entity),
                GetEditorUrl(entity.Id, queryStrings),
                uow.Repositories.GetChildRelations(entity.Id, FixedRelationTypes.DefaultRelationType).Any());

            var icon = entity.EntitySchema.GetXmlConfigProperty("icon");
            if (!string.IsNullOrEmpty(icon))
            {
                if (icon.Contains("."))
                {
                    //need to get the path
                    //TODO: Load this in from the right hive provider --Aaron
                    treeNode.Icon =
                        Url.Content(
                            BackOfficeRequestContext.Application.Settings.UmbracoFolders.
                                DocTypeIconFolder + "/" + icon);
                }
                else
                {
                    treeNode.Icon = icon;
                }
            }

            //TODO: This is going to make a few calls to the db for each node, is there a better way?
            var snapshot = uow.Repositories.Revisions.GetLatestSnapshot<TypedEntity>(entity.Id);
            if (!snapshot.IsPublished())
                treeNode.Style.DimNode();
            else if (snapshot.IsPublishPending())
                treeNode.Style.HighlightNode();
            else
            {
                if (BackOfficeRequestContext.Application.Security.PublicAccess.IsProtected(entity.Id))
                {
                    treeNode.Style.SecureNode();
                }
            }

            //now, check if we're in the recycle bin, if so we need to filter the nodes based on the user's start node
            //and where the nodes originated from.
            if (parentId == RecycleBinId)
            {
                //TODO: Hopefully there's a better way of looking all this up as this will make quite a few queries as well...

                var recycledRelation = uow.Repositories.GetParentRelations(entity, FixedRelationTypes.RecycledRelationType);
                var allowed = true;
                foreach (var r in recycledRelation)
                {
                    //get the path of the original parent
                    var path = uow.Repositories.GetEntityPath(r.SourceId, FixedRelationTypes.DefaultRelationType).ToList();
                    //append the current node to the path to create the full original path
                    path.Add(r.DestinationId);

                    //BUG: This currently will always be false because NH is not returning the correct Ids for 'system' ids.
                    // so we've commented out the return null below until fixed

                    //now we can determine if this node can be viewed
                    if (!path.Contains(RootNodeId, new HiveIdComparer(true)))
                    {
                        allowed = false;
                    }
                }
                //if (!allowed)
                //    return null;
            }

            //TODO: Check if node has been secured

            AddQueryStringsToAdditionalData(treeNode, queryStrings);

            return treeNode;
        }
 public abstract HiveId StartNodeId(IBackOfficeRequestContext requestContext, TypedEntity currentNode, TypedEntity rootNode);
Beispiel #19
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);
 }
 private void AssertFoundEntityByUrl(TypedEntity domainRoot, Uri fullUrlIncludingDomain)
 {
     var entityByUrl = GetEngine(new Uri("http://hello.com")).FindEntityByUrl(fullUrlIncludingDomain, null);
     Assert.NotNull(entityByUrl);
     Assert.That(entityByUrl.Status, Is.EqualTo(EntityRouteStatus.SuccessWithoutHostname));
     Assert.NotNull(entityByUrl.RoutableEntity);
     Assert.AreEqual(domainRoot.Id, entityByUrl.RoutableEntity.Id);
 }
 public static TypedEntity CreateTypedEntity(EntitySchema schema, TypedAttribute[] attribs, bool assignId = false)
 {
     var entity = new TypedEntity
         {
             EntitySchema = schema
         };
     entity.Attributes.Reset(attribs);
     if (assignId)
         entity.Id = new HiveId(Guid.NewGuid());
     return entity;
 }
        public void Initialize()
        {
            //Seup permissions
            _permissions = new Permission[] { new SavePermission(), new PublishPermission(), new HostnamesPermission(), 
                new CopyPermission(), new MovePermission(), new BackOfficeAccessPermission() }
                .Select(x => new Lazy<Permission, PermissionMetadata>(() => x, new PermissionMetadata(new Dictionary<string, object>
                    {
                        {"Id", x.Id},
                        {"Name", x.Name},
                        {"Type", x.Type}
                    })));

            //Setup user groups
            _userGroups = new List<UserGroup>
            {
                new UserGroup
                {
                    Id = new HiveId("9DB63B97-4C8F-489C-98C7-017DC6AD869A"),
                    Name = "Administrator"
                },
                new UserGroup
                {
                    Id = new HiveId("F61E4B62-513B-4858-91BF-D873401AD3CA"),
                    Name = "Editor"
                },
                new UserGroup
                {
                    Id = new HiveId("8B65EF91-D49B-43A3-AFD9-6A47D5341B7D"),
                    Name = "Writter"
                }
            };

            // Setup user id
            _userId = new HiveId("857BD0F6-49DC-4378-84C1-6CD8AE14301D");

            //Setup content nodes
            _systemRootNode = new TypedEntity { Id = FixedHiveIds.SystemRoot };
            _childContentNode = new TypedEntity { Id = new HiveId("00E55027-402F-41CF-9052-B8D8F3DBCD76") };

            //Setup relations
            var systemRootPermissionRelations = new List<RelationById>
                {
                    new RelationById(
                        _userGroups.First().Id,
                        _systemRootNode.Id,
                        FixedRelationTypes.PermissionRelationType,
                        0,
                        new RelationMetaDatum(FixedPermissionIds.BackOfficeAccess, PermissionStatus.Allow.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Copy, PermissionStatus.Allow.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Save, PermissionStatus.Allow.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Publish, PermissionStatus.Deny.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Hostnames, PermissionStatus.Inherit.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Move, PermissionStatus.Inherit.ToString())
                        ),
                    new RelationById(
                        _userGroups.Last().Id,
                        _systemRootNode.Id,
                        FixedRelationTypes.PermissionRelationType,
                        0,
                        new RelationMetaDatum(FixedPermissionIds.Copy, PermissionStatus.Allow.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Save, PermissionStatus.Deny.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Publish, PermissionStatus.Allow.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Hostnames, PermissionStatus.Allow.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Move, PermissionStatus.Inherit.ToString())
                        )
                };

            var childContentNodePermissionRelations = new List<RelationById>
                {
                    new RelationById(
                        _userGroups.Skip(1).First().Id,
                        _childContentNode.Id,
                        FixedRelationTypes.PermissionRelationType,
                        0,
                        new RelationMetaDatum(FixedPermissionIds.BackOfficeAccess, PermissionStatus.Deny.ToString()), // Back office access is not an entity action so this should get ignored
                        new RelationMetaDatum(FixedPermissionIds.Copy, PermissionStatus.Allow.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Save, PermissionStatus.Deny.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Publish, PermissionStatus.Allow.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Hostnames, PermissionStatus.Allow.ToString()),
                        new RelationMetaDatum(FixedPermissionIds.Move, PermissionStatus.Inherit.ToString())
                        )
                };

            var childContentNodeAncestorRelations = new List<RelationById>
            {
                new RelationById( 
                    _systemRootNode.Id,
                    _childContentNode.Id,
                    FixedRelationTypes.DefaultRelationType,
                    0)
            };

            var userGroupRelations = new List<RelationById>
            {
                new RelationById( 
                    _userGroups.First().Id,
                    _userId,
                    FixedRelationTypes.UserGroupRelationType,
                    0),
                new RelationById( 
                    _userGroups.Skip(1).First().Id,
                    _userId,
                    FixedRelationTypes.UserGroupRelationType,
                    0),
                new RelationById( 
                    _userGroups.Last().Id,
                    _userId,
                    FixedRelationTypes.UserGroupRelationType,
                    0)
            };

            _membershipService = Substitute.For<IMembershipService<User>>();
            _membershipService.GetById(_userId, true).Returns(new User
            {
                Id = _userId,
                Username = "******",
                Groups = _userGroups.Select(x => x.Id).ToArray()
            });


            //Setup hive
            _hive = MockHiveManager.GetManager()
                .MockContentStore(out _readonlyContentStoreSession, out _readonlyContentStoreSchemaSession, out _contentStoreRepository, out _contentStoreSchemaRepository)
                .MockSecurityStore(out _readonlySecurityStoreSession, out _readonlySecurityStoreSchemaSession, out _securityStoreRepository, out _securityStoreSchemaRepository);

            //Setup content store
            _readonlyContentStoreSession.Exists<TypedEntity>(HiveId.Empty).ReturnsForAnyArgs(true);

            _readonlySecurityStoreSession
                .Get<UserGroup>(true, Arg.Any<HiveId[]>())
                .Returns(MockHiveManager.MockReturnForGet<UserGroup>());

            _readonlyContentStoreSession
                .Get<UserGroup>(true, Arg.Any<HiveId[]>())
                .Returns(MockHiveManager.MockReturnForGet<UserGroup>());

            _securityStoreRepository
                .Get<UserGroup>(true, Arg.Any<HiveId[]>())
                .Returns(MockHiveManager.MockReturnForGet<UserGroup>());

            _contentStoreRepository
                .Get<UserGroup>(true, Arg.Any<HiveId[]>())
                .Returns(MockHiveManager.MockReturnForGet<UserGroup>());

            //Setup security store
            _readonlySecurityStoreSession.GetParentRelations(_systemRootNode.Id, FixedRelationTypes.PermissionRelationType).Returns(systemRootPermissionRelations);
            _readonlySecurityStoreSession.GetParentRelations(_childContentNode.Id, FixedRelationTypes.PermissionRelationType).Returns(childContentNodePermissionRelations);
            _readonlySecurityStoreSession.GetAncestorRelations(_childContentNode.Id, FixedRelationTypes.DefaultRelationType).Returns(childContentNodeAncestorRelations);
            _readonlySecurityStoreSession.GetParentRelations(_userId, FixedRelationTypes.UserGroupRelationType).Returns(userGroupRelations);

            _readonlySecurityStoreSession.Query<UserGroup>().Returns(x => Enumerable.Repeat(new UserGroup() { Name = "Administrator" }, 1).AsQueryable());
        }
 public abstract bool IsMatch(IBackOfficeRequestContext requestContext, TypedEntity entity);
        /// <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>())
            {
                // Check to see if anonymous view is allowed
                var anonymousViewAllowed = !appContext.Security.PublicAccess.IsProtected(entity.Id);

                // 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

                        var member = appContext.Security.Members.GetCurrent();
                        if (member == null || !appContext.Security.PublicAccess.GetPublicAccessStatus(member.Id, entity.Id).CanAccess)
                        {
                            // Member can't access,  but check to see if logged in identiy is a User, if so, just allow access
                            var wrapper = new HttpContextWrapper(HttpContext.Current);
                            var ticket = wrapper.GetUmbracoAuthTicket();
                            if (ticket == null || ticket.Expired)
                            {
                                return null;
                            }
                        }

                        return url.Action("Proxy", "MediaProxy", new { area = "", propertyAlias = prop.AttributeDefinition.Alias, mediaId, size, fileName = file.Name });
                    }
                }
            }
            
        }
 /// <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;
 }
 public UrlResolutionResult[] GetAllUrlsForEntity(TypedEntity entity)
 {
     return new UrlResolutionResult[0];
 }
        private TypedEntity SetupTestStructure(
            out TypedEntity multiGrandChild,
            out TypedEntity firstChild,
            out TypedEntity firstGrandChild,
            out TypedEntity secondChild)
        {
            var domainRoot = CreateNewEntity();
            firstChild = CreateNewEntity();
            secondChild = CreateNewEntity();
            firstGrandChild = CreateNewEntity();
            multiGrandChild = CreateNewEntity();
            using (var writer = GetHive().Create<IContentStore>())
            {
                domainRoot.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "homepage";
                firstChild.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "first-child";
                firstGrandChild.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "first-grandchild";
                multiGrandChild.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "multi-grandchild";
                secondChild.Attributes[NodeNameAttributeDefinition.AliasValue].Values["UrlName"] = "second-child";
                writer.Repositories.AddOrUpdate(domainRoot);
                writer.Repositories.AddOrUpdate(firstChild);
                writer.Repositories.AddOrUpdate(firstGrandChild);
                writer.Repositories.AddOrUpdate(multiGrandChild);
                writer.Repositories.AddOrUpdate(secondChild);
                writer.Repositories.AddRelation(
                    FixedHiveIds.ContentVirtualRoot, domainRoot.Id, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(domainRoot, firstChild, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(firstChild, firstGrandChild, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(firstChild, multiGrandChild, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(secondChild, multiGrandChild, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(domainRoot, secondChild, FixedRelationTypes.DefaultRelationType, 0);

                var hostname = new Hostname { Name = "hello.com" };
                writer.Repositories.AddOrUpdate(hostname);
                writer.Repositories.AddRelation(domainRoot.Id, hostname.Id, FixedRelationTypes.HostnameRelationType, 0);

                writer.Complete();
            }
            return domainRoot;
        }
        private void AddDuplicateEntityTestData(TypedEntity existingEntity)
        {
            using (var uow = this.Setup.ProviderSetup.UnitFactory.Create())
            {
                // Save another item so that we should have two matching for the same attribute value
                existingEntity.Id = HiveId.Empty;
                // Add another attribute to this "clone" that should correctly then match a Single query for testing
                var existingDef = existingEntity.EntitySchema.AttributeDefinitions[0];
                var newDef = HiveModelCreationHelper.CreateAttributeDefinition(
                    "uniqueAliasForQuerying", "", "", existingDef.AttributeType, existingDef.AttributeGroup, true);
                existingEntity.EntitySchema.AttributeDefinitions.Add(newDef);
                existingEntity.Attributes.Add(new TypedAttribute(newDef, "my-new-value"));

                uow.EntityRepository.AddOrUpdate(existingEntity);
                uow.Complete();
            }
        }
 private void AddRevision(TypedEntity entity, RevisionStatusType revisionStatusType)
 {
     using (var uow = GroupUnitFactory.Create())
     {
         // Make a new revision that is published
         var revision = new Revision<TypedEntity>(entity);
         revision.MetaData.StatusType = revisionStatusType;
         uow.Repositories.Revisions.AddOrUpdate(revision);
         uow.Complete();
     }
 }
 public UrlResolutionResult GetUrlForEntity(TypedEntity entity)
 {
     return new UrlResolutionResult("/this-is-a-test", UrlResolutionStatus.SuccessWithoutHostname);
 }