private Tuple <IMedia, IMedia, IMedia, IMedia, IMedia> CreateTrashedTestMedia()
        {
            // Create and Save folder-Media -> 1050
            IMediaType folderMediaType = MediaTypeService.Get(1031);
            Media      folder          = MediaBuilder.CreateMediaFolder(folderMediaType, -1);

            MediaService.Save(folder);

            // Create and Save folder-Media -> 1051
            Media folder2 = MediaBuilder.CreateMediaFolder(folderMediaType, -1);

            MediaService.Save(folder2);

            // Create and Save image-Media  -> 1052
            IMediaType imageMediaType = MediaTypeService.Get(1032);
            Media      image          = MediaBuilder.CreateMediaImage(imageMediaType, 1050);

            MediaService.Save(image);

            // Create and Save folder-Media that is trashed -> 1053
            Media folderTrashed = MediaBuilder.CreateMediaFolder(folderMediaType, -21);

            folderTrashed.Trashed = true;
            MediaService.Save(folderTrashed);

            // Create and Save image-Media child of folderTrashed -> 1054
            Media imageTrashed = MediaBuilder.CreateMediaImage(imageMediaType, folderTrashed.Id);

            imageTrashed.Trashed = true;
            MediaService.Save(imageTrashed);

            return(new Tuple <IMedia, IMedia, IMedia, IMedia, IMedia>(folder, folder2, image, folderTrashed, imageTrashed));
        }
Example #2
0
        public void SaveMediaMultiple()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository);

                IMediaType mediaType = mediaTypeRepository.Get(1032);
                Media      file      = MediaBuilder.CreateMediaFile(mediaType, -1);

                // Act
                repository.Save(file);

                Media image = MediaBuilder.CreateMediaImage(mediaType, -1);
                repository.Save(image);

                // Assert
                Assert.That(file.HasIdentity, Is.True);
                Assert.That(image.HasIdentity, Is.True);
                Assert.That(file.Name, Is.EqualTo("Test File"));
                Assert.That(image.Name, Is.EqualTo("Test Image"));
                Assert.That(file.ContentTypeId, Is.EqualTo(mediaType.Id));
                Assert.That(image.ContentTypeId, Is.EqualTo(mediaType.Id));
            }
        }
        public void Can_Copy_MediaType_By_Performing_Clone()
        {
            // Arrange
            var mediaType = MediaTypeBuilder.CreateImageMediaType("Image2") as IMediaType;

            MediaTypeService.Save(mediaType);

            // Act
            IMediaType sut = mediaType.DeepCloneWithResetIdentities("Image2_2");

            Assert.IsNotNull(sut);
            MediaTypeService.Save(sut);

            // Assert
            Assert.That(sut.HasIdentity, Is.True);
            Assert.AreEqual(mediaType.ParentId, sut.ParentId);
            Assert.AreEqual(mediaType.Level, sut.Level);
            Assert.AreEqual(mediaType.PropertyTypes.Count(), sut.PropertyTypes.Count());
            Assert.AreNotEqual(mediaType.Id, sut.Id);
            Assert.AreNotEqual(mediaType.Key, sut.Key);
            Assert.AreNotEqual(mediaType.Path, sut.Path);
            Assert.AreNotEqual(mediaType.SortOrder, sut.SortOrder);
            Assert.AreNotEqual(mediaType.PropertyTypes.First(x => x.Alias.Equals("umbracoFile")).Id, sut.PropertyTypes.First(x => x.Alias.Equals("umbracoFile")).Id);
            Assert.AreNotEqual(mediaType.PropertyGroups.First(x => x.Name.Equals("Media")).Id, sut.PropertyGroups.First(x => x.Name.Equals("Media")).Id);
        }
Example #4
0
    private IEnumerable <ContentNodeKit> CreateChildren(
        int startId,
        ContentNodeKit parent,
        IMediaType mediaType,
        int count)
    {
        for (var i = 0; i < count; i++)
        {
            var id = startId + i + 1;

            var item1Data = new ContentDataBuilder()
                            .WithName("Child " + id)
                            .WithProperties(new PropertyDataBuilder()
                                            .WithPropertyData("content", "<div>This is some content</div>")
                                            .Build())
                            .Build();

            var parentPath = parent.Node.Path;

            var item1 = ContentNodeKitBuilder.CreateWithContent(
                mediaType.Id,
                id,
                $"{parentPath},{id}",
                draftData: item1Data,
                publishedData: item1Data);

            yield return(item1);
        }
    }
Example #5
0
        /// <summary>
        /// Exports an <see cref="IMediaType"/> to xml as an <see cref="XElement"/>
        /// </summary>
        /// <param name="mediaType">MediaType to export</param>
        /// <returns><see cref="XElement"/> containing the xml representation of the MediaType item.</returns>
        internal XElement Export(IMediaType mediaType)
        {
            var info = new XElement("Info",
                                    new XElement("Name", mediaType.Name),
                                    new XElement("Alias", mediaType.Alias),
                                    new XElement("Icon", mediaType.Icon),
                                    new XElement("Thumbnail", mediaType.Thumbnail),
                                    new XElement("Description", mediaType.Description),
                                    new XElement("AllowAtRoot", mediaType.AllowedAsRoot.ToString()));

            var masterContentType = mediaType.CompositionAliases().FirstOrDefault();

            if (masterContentType != null)
            {
                info.Add(new XElement("Master", masterContentType));
            }

            var structure = new XElement("Structure");

            foreach (var allowedType in mediaType.AllowedContentTypes)
            {
                structure.Add(new XElement("MediaType", allowedType.Alias));
            }

            var genericProperties = new XElement("GenericProperties");

            foreach (var propertyType in mediaType.PropertyTypes)
            {
                var definition      = _dataTypeService.GetDataTypeDefinitionById(propertyType.DataTypeDefinitionId);
                var propertyGroup   = mediaType.PropertyGroups.FirstOrDefault(x => x.Id == propertyType.PropertyGroupId.Value);
                var genericProperty = new XElement("GenericProperty",
                                                   new XElement("Name", propertyType.Name),
                                                   new XElement("Alias", propertyType.Alias),
                                                   new XElement("Type", propertyType.DataTypeId.ToString()),
                                                   new XElement("Definition", definition.Key),
                                                   new XElement("Tab", propertyGroup == null ? "" : propertyGroup.Name),
                                                   new XElement("Mandatory", propertyType.Mandatory.ToString()),
                                                   new XElement("Validation", propertyType.ValidationRegExp),
                                                   new XElement("Description", new XCData(propertyType.Description)));
                genericProperties.Add(genericProperty);
            }

            var tabs = new XElement("Tabs");

            foreach (var propertyGroup in mediaType.PropertyGroups)
            {
                var tab = new XElement("Tab",
                                       new XElement("Id", propertyGroup.Id.ToString(CultureInfo.InvariantCulture)),
                                       new XElement("Caption", propertyGroup.Name));
                tabs.Add(tab);
            }

            var xml = new XElement("MediaType",
                                   info,
                                   structure,
                                   genericProperties,
                                   tabs);

            return(xml);
        }
        public void Can_Delete_Container_Containing_Media_Types()
        {
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var containerRepository = CreateContainerRepository((IScopeAccessor)provider, Constants.ObjectTypes.MediaTypeContainer);
                var repository          = CreateMediaTypeRepository((IScopeAccessor)provider);
                var container           = new EntityContainer(Constants.ObjectTypes.MediaType)
                {
                    Name = "blah"
                };
                containerRepository.Save(container);


                IMediaType contentType = MockedContentTypes.CreateSimpleMediaType("test", "Test", propertyGroupName: "testGroup");
                contentType.ParentId = container.Id;
                repository.Save(contentType);


                // Act
                containerRepository.Delete(container);


                var found = containerRepository.Get(container.Id);
                Assert.IsNull(found);

                contentType = repository.Get(contentType.Id);
                Assert.IsNotNull(contentType);
                Assert.AreEqual(-1, contentType.ParentId);
            }
        }
Example #7
0
        public static IMedia BuildEntity(ContentVersionDto dto, IMediaType contentType)
        {
            var media = new Models.Media(dto.ContentDto.NodeDto.Text, dto.ContentDto.NodeDto.ParentId, contentType);

            try
            {
                media.DisableChangeTracking();

                media.Id         = dto.NodeId;
                media.Key        = dto.ContentDto.NodeDto.UniqueId;
                media.Path       = dto.ContentDto.NodeDto.Path;
                media.CreatorId  = dto.ContentDto.NodeDto.UserId.Value;
                media.Level      = dto.ContentDto.NodeDto.Level;
                media.ParentId   = dto.ContentDto.NodeDto.ParentId;
                media.SortOrder  = dto.ContentDto.NodeDto.SortOrder;
                media.Trashed    = dto.ContentDto.NodeDto.Trashed;
                media.CreateDate = dto.ContentDto.NodeDto.CreateDate;
                media.UpdateDate = dto.VersionDate;
                media.Version    = dto.VersionId;
                //on initial construction we don't want to have dirty properties tracked
                // http://issues.umbraco.org/issue/U4-1946
                media.ResetDirtyProperties(false);
                return(media);
            }
            finally
            {
                media.EnableChangeTracking();
            }
        }
Example #8
0
        public void SaveMedia()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository);

                IMediaType mediaType = mediaTypeRepository.Get(1032);
                Media      image     = MediaBuilder.CreateMediaImage(mediaType, -1);

                // Act
                mediaTypeRepository.Save(mediaType);
                repository.Save(image);

                IMedia fetched = repository.Get(image.Id);

                // Assert
                Assert.That(mediaType.HasIdentity, Is.True);
                Assert.That(image.HasIdentity, Is.True);

                TestHelper.AssertPropertyValuesAreEqual(image, fetched);
            }
        }
Example #9
0
        public void QueryMedia_ContentTypeAliasFilter()
        {
            // we could support this, but it would require an extra join on the query,
            // and we don't absolutely need it now, so leaving it out for now

            // Arrange
            IMediaType     folderMediaType = MediaTypeService.Get(1031);
            IScopeProvider provider        = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository);

                // Act
                for (int i = 0; i < 10; i++)
                {
                    Media folder = MediaBuilder.CreateMediaFolder(folderMediaType, -1);
                    repository.Save(folder);
                }

                string[]             types  = new[] { "Folder" };
                IQuery <IMedia>      query  = provider.CreateQuery <IMedia>().Where(x => types.Contains(x.ContentType.Alias));
                IEnumerable <IMedia> result = repository.Get(query);

                // Assert
                Assert.That(result.Count(), Is.GreaterThanOrEqualTo(11));
            }
        }
Example #10
0
        public void QueryMedia_ContentTypeIdFilter()
        {
            // Arrange
            IMediaType     folderMediaType = MediaTypeService.Get(1031);
            IScopeProvider provider        = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository);

                // Act
                for (int i = 0; i < 10; i++)
                {
                    Media folder = MediaBuilder.CreateMediaFolder(folderMediaType, -1);
                    repository.Save(folder);
                }

                int[]                types  = new[] { 1031 };
                IQuery <IMedia>      query  = provider.CreateQuery <IMedia>().Where(x => types.Contains(x.ContentTypeId));
                IEnumerable <IMedia> result = repository.Get(query);

                // Assert
                Assert.That(result.Count(), Is.GreaterThanOrEqualTo(11));
            }
        }
        public void Can_Delete_Container_Containing_Media_Types()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                EntityContainerRepository containerRepository = CreateContainerRepository(provider);
                MediaTypeRepository       repository          = CreateRepository(provider);

                var container = new EntityContainer(Constants.ObjectTypes.MediaType)
                {
                    Name = "blah"
                };
                containerRepository.Save(container);

                IMediaType contentType =
                    MediaTypeBuilder.CreateSimpleMediaType("test", "Test", propertyGroupAlias: "testGroup", propertyGroupName: "testGroup");
                contentType.ParentId = container.Id;
                repository.Save(contentType);

                // Act
                containerRepository.Delete(container);

                EntityContainer found = containerRepository.Get(container.Id);
                Assert.IsNull(found);

                contentType = repository.Get(contentType.Id);
                Assert.IsNotNull(contentType);
                Assert.AreEqual(-1, contentType.ParentId);
            }
        }
Example #12
0
        private void SetupNode(IMediaType mediaType)
        {
            _mediaType = mediaType;

            base.PopulateContentTypeFromContentTypeBase(_mediaType);
            base.PopulateCMSNodeFromContentTypeBase(_mediaType, _objectType);
        }
Example #13
0
        public IdentityInfo(Uri location, IMediaType type, string name, string summary, DateTime fromDate, DateTime toDate, uint number)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (summary == null)
            {
                throw new ArgumentNullException("summary");
            }

            this.location = location;
            this.type     = type;
            this.name     = name;
            this.summary  = summary;
            this.fromDate = fromDate;
            this.toDate   = toDate;
            this.number   = number;
        }
Example #14
0
        private PropertyCollection GetPropertyCollection(int id, Guid versionId, IMediaType contentType, DateTime createDate, DateTime updateDate)
        {
            var sql = new Sql();

            sql.Select("*")
            .From <PropertyDataDto>()
            .InnerJoin <PropertyTypeDto>()
            .On <PropertyDataDto, PropertyTypeDto>(left => left.PropertyTypeId, right => right.Id)
            .Where <PropertyDataDto>(x => x.NodeId == id)
            .Where <PropertyDataDto>(x => x.VersionId == versionId);

            var propertyDataDtos = Database.Fetch <PropertyDataDto, PropertyTypeDto>(sql);
            var propertyFactory  = new PropertyFactory(contentType, versionId, id, createDate, updateDate);
            var properties       = propertyFactory.BuildEntity(propertyDataDtos);

            var newProperties = properties.Where(x => x.HasIdentity == false);

            foreach (var property in newProperties)
            {
                var propertyDataDto = new PropertyDataDto {
                    NodeId = id, PropertyTypeId = property.PropertyTypeId, VersionId = versionId
                };
                int primaryKey = Convert.ToInt32(Database.Insert(propertyDataDto));

                property.Version = versionId;
                property.Id      = primaryKey;
            }

            return(new PropertyCollection(properties));
        }
        public void Can_Update_MediaType_With_PropertyType_Removed()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MediaTypeRepository repository = CreateRepository(provider);

                MediaType mediaType = MediaTypeBuilder.CreateNewMediaType();
                repository.Save(mediaType);

                // Act
                IMediaType mediaTypeV2 = repository.Get(mediaType.Id);
                mediaTypeV2.PropertyGroups["media"].PropertyTypes.Remove("title");
                repository.Save(mediaTypeV2);

                IMediaType mediaTypeV3 = repository.Get(mediaType.Id);

                // Assert
                Assert.That(mediaTypeV3.PropertyTypes.Any(x => x.Alias == "title"), Is.False);
                Assert.That(mediaTypeV2.PropertyGroups.Count, Is.EqualTo(mediaTypeV3.PropertyGroups.Count));
                Assert.That(mediaTypeV2.PropertyTypes.Count(), Is.EqualTo(mediaTypeV3.PropertyTypes.Count()));
            }
        }
Example #16
0
        public static void AddIsDeletedProperty(IMediaType mediaType)
        {
            var dataTypeService    = ApplicationContext.Current.Services.DataTypeService;
            var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;

            var dataType = dataTypeService.GetDataTypeDefinitionByName(UmbracoAliases.Media.IsDeletedDataTypeDefinitionName);

            if (dataType == null)
            {
                dataType = new DataTypeDefinition("Umbraco.TrueFalse")
                {
                    Name = UmbracoAliases.Media.IsDeletedDataTypeDefinitionName
                };

                dataTypeService.Save(dataType);
            }

            var imageIsDeletedPropertyType = GetIsDeletedPropertyType(dataType);

            if (!mediaType.PropertyTypeExists(imageIsDeletedPropertyType.Alias))
            {
                mediaType.AddPropertyType(imageIsDeletedPropertyType);
                contentTypeService.Save(mediaType);
            }
        }
        private void SetupNode(IMediaType mediaType)
        {
            MediaTypeItem = mediaType;

            base.PopulateContentTypeFromContentTypeBase(MediaTypeItem);
            base.PopulateCMSNodeFromUmbracoEntity(MediaTypeItem, _objectType);
        }
Example #18
0
        public MediaBuilder WithMediaType(IMediaType mediaType)
        {
            _mediaTypeBuilder = null;
            _mediaType        = mediaType;

            return(this);
        }
        public void Can_Perform_Update_On_MediaTypeRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                MediaTypeRepository repository = CreateRepository(provider);

                MediaType videoMediaType = MediaTypeBuilder.CreateNewMediaType();
                repository.Save(videoMediaType);

                // Act
                IMediaType mediaType = repository.Get(videoMediaType.Id);

                mediaType.Thumbnail = "Doc2.png";
                mediaType.PropertyGroups["media"].PropertyTypes.Add(new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "subtitle")
                {
                    Name        = "Subtitle",
                    Description = "Optional Subtitle",
                    Mandatory   = false,
                    SortOrder   = 1,
                    DataTypeId  = -88
                });
                repository.Save(mediaType);

                bool dirty = ((MediaType)mediaType).IsDirty();

                // Assert
                Assert.That(mediaType.HasIdentity, Is.True);
                Assert.That(dirty, Is.False);
                Assert.That(mediaType.Thumbnail, Is.EqualTo("Doc2.png"));
                Assert.That(mediaType.PropertyTypes.Any(x => x.Alias == "subtitle"), Is.True);
            }
        }
Example #20
0
        public MediaTypeBuilder AddMediaType()
        {
            _mediaType = null;
            var builder = new MediaTypeBuilder(this);

            _mediaTypeBuilder = builder;
            return(builder);
        }
 public static void RemoveMediaTypeCache(this DistributedCache dc, IMediaType mediaType)
 {
     if (mediaType == null)
     {
         return;
     }
     dc.RefreshByJson(DistributedCache.ContentTypeCacheRefresherGuid, ContentTypeCacheRefresher.SerializeToJsonPayload(true, mediaType));
 }
Example #22
0
        public static Media CreateAngryKittenMedia(IMediaType mediaType)
        {
            var media = CreateImageMedia(mediaType, "Angry kitten", -1, "/media/1002/angry-little-kitten-1024-768.jpg");

            media.Id  = 1062;
            media.Key = Guid.Parse("51e50c3a1a494507b4364068c4b429cd");
            return(media);
        }
Example #23
0
 /// <summary>
 /// Changes the <see cref="IMediaType"/> for the current Media object
 /// </summary>
 /// <param name="contentType">New MediaType for this Media</param>
 /// <remarks>Leaves PropertyTypes intact after change</remarks>
 public void ChangeContentType(IMediaType contentType)
 {
     ContentTypeId   = contentType.Id;
     _contentType    = contentType;
     ContentTypeBase = contentType;
     Properties.EnsurePropertyTypes(PropertyTypes);
     Properties.CollectionChanged += PropertiesChanged;
 }
 public static void SaveToDisk(IMediaType item)
 {
     if (item != null)
     {
         XElement node = _engine.MediaType.Export(item);
         uSyncIO.SaveXmlToDisk(node, GetMediaPath(item), item.Alias, "MediaType");
     }
 }
Example #25
0
        public static Media CreateCuteKittenMedia(IMediaType mediaType)
        {
            var media = CreateImageMedia(mediaType, "Cute kitten", -1, "/media/1001/cute-little-kitten-cute-kittens-16288222-1024-768.jpg");

            media.Id  = 1061;
            media.Key = Guid.Parse("eb0ad3395cad417a90051bd871eccc9c");
            return(media);
        }
Example #26
0
 /// <summary>
 /// Changes the <see cref="IMediaType"/> for the current Media object
 /// </summary>
 /// <param name="contentType">New MediaType for this Media</param>
 /// <remarks>Leaves PropertyTypes intact after change</remarks>
 public void ChangeContentType(IMediaType contentType)
 {
     ContentTypeId = contentType.Id;
     _contentType = contentType;
     ContentTypeBase = contentType;
     Properties.EnsurePropertyTypes(PropertyTypes);
     Properties.CollectionChanged += PropertiesChanged;
 }
 /// <summary>
 /// Gets the entity identifier of the entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns>The entity identifier of the entity.</returns>
 public static GuidUdi GetUdi(this IMediaType entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     return(new GuidUdi(Constants.UdiEntityType.MediaType, entity.Key).EnsureClosed());
 }
Example #28
0
 public void SetDefault(IMediaType defaultMediaType)
 {
     if (!IsRegistered(defaultMediaType))
     {
         throw new RestfulieConfigurationException(string.Format("Can't set type as default. {0} is not a registered media type.", defaultMediaType));
     }
     Default = defaultMediaType;
 }
Example #29
0
        private ActionResult RestfulieResult(ActionExecutedContext context, IMediaType type, IRequestInfoFinder requestInfoFinder)
        {
            var result = (RestfulieResult) context.Result;
            result.MediaType = type;
            result.RequestInfo = requestInfoFinder;

            return result;
        }
Example #30
0
        public override Media Build()
        {
            var      id                    = _id ?? 0;
            Guid     key                   = _key ?? Guid.NewGuid();
            var      parentId              = _parentId ?? -1;
            DateTime createDate            = _createDate ?? DateTime.Now;
            DateTime updateDate            = _updateDate ?? DateTime.Now;
            var      name                  = _name ?? Guid.NewGuid().ToString();
            var      creatorId             = _creatorId ?? 0;
            var      level                 = _level ?? 1;
            var      path                  = _path ?? $"-1,{id}";
            var      sortOrder             = _sortOrder ?? 0;
            var      trashed               = _trashed ?? false;
            var      propertyValues        = _propertyValues ?? null;
            var      propertyValuesCulture = _propertyValuesCulture ?? null;
            var      propertyValuesSegment = _propertyValuesSegment ?? null;

            if (_mediaTypeBuilder is null && _mediaType is null)
            {
                throw new InvalidOperationException("A media item cannot be constructed without providing a media type. Use AddMediaType() or WithMediaType().");
            }

            IMediaType mediaType = _mediaType ?? _mediaTypeBuilder.Build();

            var media = new Media(name, parentId, mediaType)
            {
                Id         = id,
                Key        = key,
                CreateDate = createDate,
                UpdateDate = updateDate,
                CreatorId  = creatorId,
                Level      = level,
                Path       = path,
                SortOrder  = sortOrder,
                Trashed    = trashed,
            };

            if (_propertyDataBuilder != null || propertyValues != null)
            {
                if (_propertyDataBuilder != null)
                {
                    IDictionary <string, object> propertyData = _propertyDataBuilder.Build();
                    foreach (KeyValuePair <string, object> keyValuePair in propertyData)
                    {
                        media.SetValue(keyValuePair.Key, keyValuePair.Value);
                    }
                }
                else
                {
                    media.PropertyValues(propertyValues, propertyValuesCulture, propertyValuesSegment);
                }

                media.ResetDirtyProperties(false);
            }

            return(media);
        }
Example #31
0
        public static Media CreateMediaFolder(IMediaType mediaType, int parentId)
        {
            var media = new Media("Test Folder", parentId, mediaType)
            {
                CreatorId = 0
            };

            return(media);
        }
Example #32
0
         public static IMedia CreateMediaFolder(IMediaType mediaType, int parentId)
         {
             var media = new Media("Test Folder", parentId, mediaType)
                             {
                                 CreatorId = 0
                             };

             return media;
         }
        public NodeEditorData Save(IMediaType mediaType)
        {
            var nodeData = _content.Save();

            nodeData.Id = ID;
            return(new NodeEditorData {
                X = _rect.x, Y = _rect.y, NodeData = nodeData
            });
        }
Example #34
0
        protected ImageBase(Uri location, IMediaType type)
        {
            if (location == null)
                throw new ArgumentNullException("location");
            if (type == null)
                throw new ArgumentNullException("type");

            this.location = location;
            this.type = type;
        }
        public MicrosoftShortcut(Uri location, IMediaType type)
        {
            if (location == null)
                throw new ArgumentNullException("location");
            if (type == null)
                throw new ArgumentNullException("type");

            this.location = location;
            this.type = type;
        }
        public GnosisFilesystemDirectory(Uri location, IMediaType type)
        {
            if (location == null)
                throw new ArgumentNullException("location");
            if (type == null)
                throw new ArgumentNullException("type");

            this.location = location;
            this.type = type;
        }
Example #37
0
        public ActionResult BasedOnMediaType(ActionExecutedContext context, IMediaType type, IRequestInfoFinder requestInfoFinder)
        {
            if (!context.Result.IsRestfulieResult())
                return context.Result;

            if (type is HTML && (context.Result is OK || context.Result is Created))
                return AspNetResult(context);

            return RestfulieResult(context, type, requestInfoFinder);
        }
Example #38
0
        public Media(string path, IMediaType type)
        {
            if (path == null)
                throw new ArgumentNullException("path");
            if (type == null)
                throw new ArgumentNullException("type");

            this.path = path;
            this.type = type;
        }
Example #39
0
        public PlainText(Uri location, IMediaType type)
        {
            if (location == null)
                throw new ArgumentNullException("location");
            if (type == null)
                throw new ArgumentNullException("type");

            this.location = location;
            this.type = type;
        }
        public void SetUp()
        {
            anyList = new List<IMediaType>
                          {
                              new HTML(),
                              new AtomPlusXml(),
                              new XmlAndHypermedia(),
                              new JsonAndHypermedia()
                          };

            anyMediaType = new Mock<IMediaType>().Object;
        }
Example #41
0
         public static IMedia CreateMediaFile(IMediaType mediaType, int parentId)
         {
             var media = new Media("Test File", parentId, mediaType)
                             {
                                 CreatorId = 0
                             };

             media.SetValue("umbracoFile", "/media/test-file.txt");
             media.SetValue("umbracoBytes", "4");
             media.SetValue("umbracoExtension", "txt");

             return media;
         }
Example #42
0
         public static IMedia CreateMediaFile(IMediaType mediaType, int parentId)
         {
             var media = new Media("Test File", parentId, mediaType)
                             {
                                 CreatorId = 0
                             };

             media.SetValue(Constants.Conventions.Media.File, "/media/test-file.txt");
             media.SetValue(Constants.Conventions.Media.Bytes, "4");
             media.SetValue(Constants.Conventions.Media.Extension, "txt");

             return media;
         }
        public void SetUp()
        {
            anyList = new List<IMediaType>
                          {
                              new HTML(),
                              new AtomPlusXml(),
                              new XmlAndHypermedia(),
                              new JsonAndHypermedia()
                          };

            anyMediaType = new HTML();

        	_list = new DefaultMediaTypeList(anyList, anyMediaType);
        }
Example #44
0
        public User(IMediaType type, string name, Uri thumbnail, Uri location)
        {
            if (type == null)
                throw new ArgumentNullException("type");
            if (name == null)
                throw new ArgumentNullException("name");
            if (location == null)
                throw new ArgumentNullException("location");

            this.type = type;
            this.name = name;
            this.thumbnail = thumbnail;
            this.location = location;
        }
Example #45
0
         public static IMedia CreateMediaImage(IMediaType mediaType, int parentId)
         {
             var media = new Media("Test Image", parentId, mediaType)
                             {
                                 CreatorId = 0
                             };

             media.SetValue(Constants.Conventions.Media.File, "/media/test-image.png");
             media.SetValue(Constants.Conventions.Media.Width, "200");
             media.SetValue(Constants.Conventions.Media.Height, "200");
             media.SetValue(Constants.Conventions.Media.Bytes, "100");
             media.SetValue(Constants.Conventions.Media.Extension, "png");

             return media;
         }
Example #46
0
         public static IMedia CreateMediaImage(IMediaType mediaType, int parentId)
         {
             var media = new Media("Test Image", parentId, mediaType)
                             {
                                 CreatorId = 0
                             };

             media.SetValue("umbracoFile", "/media/test-image.png");
             media.SetValue("umbracoWidth", "200");
             media.SetValue("umbracoHeight", "200");
             media.SetValue("umbracoBytes", "100");
             media.SetValue("umbracoExtension", "png");

             return media;
         }
Example #47
0
        public IdentityInfo(Uri location, IMediaType type, string name, string summary, DateTime fromDate, DateTime toDate, uint number)
        {
            if (location == null)
                throw new ArgumentNullException("location");
            if (type == null)
                throw new ArgumentNullException("type");
            if (name == null)
                throw new ArgumentNullException("name");
            if (summary == null)
                throw new ArgumentNullException("summary");

            this.location = location;
            this.type = type;
            this.name = name;
            this.summary = summary;
            this.fromDate = fromDate;
            this.toDate = toDate;
            this.number = number;
        }
Example #48
0
 public static IdentityInfo GetNew(IMediaType type)
 {
     return new IdentityInfo(Guid.NewGuid().ToUrn(), type, "Unknown", string.Empty, DateTime.MinValue, DateTime.MaxValue, 0);
 }
        /// <summary>
        /// Saves a single <see cref="IMediaType"/> object
        /// </summary>
        /// <param name="mediaType"><see cref="IMediaType"/> to save</param>
        /// <param name="userId">Optional Id of the user saving the MediaType</param>
        public void Save(IMediaType mediaType, int userId = 0)
        {
	        if (SavingMediaType.IsRaisedEventCancelled(new SaveEventArgs<IMediaType>(mediaType), this)) 
				return;

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateMediaTypeRepository(uow))
                {
                    mediaType.CreatorId = userId;
                    repository.AddOrUpdate(mediaType);
                    uow.Commit();
                    
                }

                UpdateContentXmlStructure(mediaType);
            }

            SavedMediaType.RaiseEvent(new SaveEventArgs<IMediaType>(mediaType, false), this);
	        Audit.Add(AuditTypes.Save, string.Format("Save MediaType performed by user"), userId, mediaType.Id);
        }
Example #50
0
 protected VideoBase(Uri location, IMediaType type)
 {
     this.location = location;
     this.type = type;
 }
Example #51
0
 public ActionResult BasedOnMediaType(ActionExecutedContext context, IMediaType type, IRequestInfoFinder requestInfoFinder)
 {
     if (!context.Result.IsRestfulieResult()) return context.Result;
     return (type is HTML) ? AspNetResult(context) : RestfulieResult(context, type, requestInfoFinder);
 }
Example #52
0
 internal MediaType(IMediaType mediaType)
     : base(mediaType)
 {
     SetupNode(mediaType);
 }
Example #53
0
        private void SetupNode(IMediaType mediaType)
        {
            _mediaType = mediaType;

            base.PopulateContentTypeFromContentTypeBase(_mediaType);
            base.PopulateCMSNodeFromContentTypeBase(_mediaType, _objectType);
        }
 /// <summary>
 /// Remove all cache for a given media type
 /// </summary>
 /// <param name="dc"></param>
 /// <param name="mediaType"></param>
 public static void RemoveMediaTypeCache(this DistributedCache dc, IMediaType mediaType)
 {
     if (mediaType != null)
     {
         //dc.Remove(new Guid(DistributedCache.ContentTypeCacheRefresherId), x => x.Id, mediaType);
         dc.RefreshByJson(new Guid(DistributedCache.ContentTypeCacheRefresherId),
             ContentTypeCacheRefresher.SerializeToJsonPayload(true, mediaType));
     }
 } 
Example #55
0
		public MediaType(IMediaType parent) : base(parent)
		{
		}
Example #56
0
 public BitmapImage(Uri location, IMediaType mediaType)
     : base(location, mediaType)
 {
 }
        /// <summary>
        /// Exports an <see cref="IMediaType"/> to xml as an <see cref="XElement"/>
        /// </summary>
        /// <param name="mediaType">MediaType to export</param>
        /// <returns><see cref="XElement"/> containing the xml representation of the MediaType item.</returns>
        internal XElement Export(IMediaType mediaType)
        {
            var info = new XElement("Info",
                                    new XElement("Name", mediaType.Name),
                                    new XElement("Alias", mediaType.Alias),
                                    new XElement("Icon", mediaType.Icon),
                                    new XElement("Thumbnail", mediaType.Thumbnail),
                                    new XElement("Description", mediaType.Description),
                                    new XElement("AllowAtRoot", mediaType.AllowedAsRoot.ToString()));

            var masterContentType = mediaType.CompositionAliases().FirstOrDefault();
            if (masterContentType != null)
                info.Add(new XElement("Master", masterContentType));

            var structure = new XElement("Structure");
            foreach (var allowedType in mediaType.AllowedContentTypes)
            {
                structure.Add(new XElement("MediaType", allowedType.Alias));
            }

            var genericProperties = new XElement("GenericProperties");
            foreach (var propertyType in mediaType.PropertyTypes)
            {
                var definition = _dataTypeService.GetDataTypeDefinitionById(propertyType.DataTypeDefinitionId);
                var propertyGroup = mediaType.PropertyGroups.FirstOrDefault(x => x.Id == propertyType.PropertyGroupId.Value);
                var genericProperty = new XElement("GenericProperty",
                                                   new XElement("Name", propertyType.Name),
                                                   new XElement("Alias", propertyType.Alias),
                                                   new XElement("Type", propertyType.DataTypeId.ToString()),
                                                   new XElement("Definition", definition.Key),
                                                   new XElement("Tab", propertyGroup == null ? "" : propertyGroup.Name),
                                                   new XElement("Mandatory", propertyType.Mandatory.ToString()),
                                                   new XElement("Validation", propertyType.ValidationRegExp),
                                                   new XElement("Description", new XCData(propertyType.Description)));
                genericProperties.Add(genericProperty);
            }

            var tabs = new XElement("Tabs");
            foreach (var propertyGroup in mediaType.PropertyGroups)
            {
                var tab = new XElement("Tab",
                                       new XElement("Id", propertyGroup.Id.ToString(CultureInfo.InvariantCulture)),
                                       new XElement("Caption", propertyGroup.Name));
                tabs.Add(tab);
            }

            var xml = new XElement("MediaType",
                                   info,
                                   structure,
                                   genericProperties,
                                   tabs);
            return xml;
        }
Example #58
0
 public PngImage(Uri location, IMediaType mediaType)
     : base(location, mediaType)
 {
 }
 public QualifiedMediaType(IMediaType mediaType, double qualifier)
 {
     MediaType = mediaType;
     Qualifier = qualifier;
 }
        /// <summary>
        /// Deletes a single <see cref="IMediaType"/> object
        /// </summary>
        /// <param name="mediaType"><see cref="IMediaType"/> to delete</param>
        /// <param name="userId">Optional Id of the user deleting the MediaType</param>
        /// <remarks>Deleting a <see cref="IMediaType"/> will delete all the <see cref="IMedia"/> objects based on this <see cref="IMediaType"/></remarks>
        public void Delete(IMediaType mediaType, int userId = 0)
        {
	        if (DeletingMediaType.IsRaisedEventCancelled(new DeleteEventArgs<IMediaType>(mediaType), this)) 
				return;
            using (new WriteLock(Locker))
            {
                _mediaService.DeleteMediaOfType(mediaType.Id, userId);

                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateMediaTypeRepository(uow))
                {

                    repository.Delete(mediaType);
                    uow.Commit();

                    DeletedMediaType.RaiseEvent(new DeleteEventArgs<IMediaType>(mediaType, false), this);
                }

                Audit.Add(AuditTypes.Delete, string.Format("Delete MediaType performed by user"), userId, mediaType.Id);
            }
        }