public void Undo()
        {
            var videoMediaType = _contentTypeService.GetMediaType(AddVideoMediaTypeStepConstants.DocumentTypeAliases.Video);

            if (videoMediaType != null)
            {
                _contentTypeService.Delete(videoMediaType);
            }
        }
Exemple #2
0
        public IEnumerable <Media> GetAll()
        {
            var mediaList  = new List <Media>();
            var mediaItems = _mediaService.GetMediaOfMediaType(_contentTypeService.GetMediaType("image").Id);

            foreach (var item in mediaItems)
            {
                mediaList.Add(item as Media);
            }

            return(mediaList);
        }
Exemple #3
0
        /// <summary>
        ///  these shoud be doable with the entity service, but for now, we
        ///  are grouping these making it eaiser should we add another
        /// contentTypeBased type to it.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private IContentTypeBase LookupByKey(Guid key)
        {
            IContentTypeBase item = default(IContentTypeBase);

            switch (_itemType)
            {
            case Constants.Packaging.DocumentTypeNodeName:
                item = _contentTypeService.GetContentType(key);
                break;

            case "MediaType":
                item = _contentTypeService.GetMediaType(key);
                break;

            case "MemberType":
                item = _memberTypeService.Get(key);
                break;
            }

            return(item);
        }
Exemple #4
0
        private void CreateMediaUseInSearch()
        {
            var searchMediaCompositionType = _contentTypeService.GetMediaType(MediaAliases.SearchMediaCompositionAlias) ?? CreateSearchMediaComposition();
            var searchableMediaTypes       = GetSearchableMediaTypes();

            foreach (var type in searchableMediaTypes)
            {
                type.AddContentType(searchMediaCompositionType);
                _contentTypeService.Save(type);
                MakeMediaSearchable(_mediaService.GetMediaOfMediaType(type.Id));
            }
        }
Exemple #5
0
        public void ProcessMediaSaved(IMediaService sender, SaveEventArgs <IMedia> args)
        {
            var newMedia = args
                           .SavedEntities
                           .Where(m => m.IsNewEntity()).ToList();

            foreach (var media in newMedia)
            {
                var convertInProgress = _videoConverter.IsConverting(media);
                if (convertInProgress || media.ContentType.Alias == UmbracoAliases.Media.ImageTypeAlias)
                {
                    continue;
                }

                var umbracoFile = media.GetValue <string>(UmbracoAliases.Media.UmbracoFilePropertyAlias);

                if (_videoConverter.IsVideo(umbracoFile))
                {
                    var videoContentType = _contentTypeService.GetMediaType(UmbracoAliases.Media.VideoTypeAlias);
                    media.ChangeContentType(videoContentType, false);
                    _mediaService.Save(media);

                    var video = _mediaService.GetById(media.Id);

                    if (_videoConverter.IsMp4(umbracoFile))
                    {
                        var thumbnailUrl = _videoHelper.CreateThumbnail(video);
                        video.SetValue(UmbracoAliases.Video.ThumbnailUrlPropertyAlias, thumbnailUrl);
                        _mediaService.Save(video);

                        continue;
                    }

                    video.SetValue(UmbracoAliases.Video.ThumbnailUrlPropertyAlias, _videoHelper.CreateConvertingThumbnail());
                    _mediaService.Save(video);

                    var fileBytes = System.IO.File.ReadAllBytes(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + umbracoFile));

                    System.Threading.Tasks.Task.Run(() =>
                    {
                        _videoConverter.Convert(new MediaConvertModel()
                        {
                            File = new TempFile {
                                FileName = umbracoFile, FileBytes = fileBytes
                            },
                            MediaId = media.Id
                        });
                    });
                }
            }
        }
Exemple #6
0
        public override uSyncAction DeleteItem(Guid key, string keyString)
        {
            IMediaType item = null;

            if (key != Guid.Empty)
            {
                item = _contentTypeService.GetMediaType(key);
            }

            if (item == null || !string.IsNullOrEmpty(keyString))
            {
                item = _contentTypeService.GetMediaType(keyString);
            }

            if (item != null)
            {
                LogHelper.Info <ContentTypeHandler>("Deleting Content Type: {0}", () => item.Name);
                _contentTypeService.Delete(item);
                return(uSyncAction.SetAction(true, keyString, typeof(IMediaType), ChangeType.Delete, "Not found"));
            }

            return(uSyncAction.Fail(keyString, typeof(IMediaType), ChangeType.Delete, "Not found"));
        }
Exemple #7
0
        private IUmbracoEntity GetEntity(Guid childObjectType, int childId)
        {
            switch (UmbracoObjectTypesExtensions.GetUmbracoObjectType(childObjectType))
            {
            case UmbracoObjectTypes.Document:
                return(contentService.GetById(childId));

            case UmbracoObjectTypes.Media:
                return(mediaService.GetById(childId));

            case UmbracoObjectTypes.DocumentType:
                return(contentTypeService.GetContentType(childId));

            case UmbracoObjectTypes.MediaType:
                return(contentTypeService.GetMediaType(childId));
            }
            throw new Exception("Unknown child type");
        }
        private IContentTypeBase GetParentType(IContentTypeBase type)
        {
            if (type.ParentId <= 0)
            {
                return(null);
            }

            if (type is IContentType)
            {
                return(ContentTypeService.GetContentType(type.ParentId));
            }
            else if (type is IMediaType)
            {
                return(ContentTypeService.GetMediaType(type.ParentId));
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Exemple #9
0
        internal void ExportToFile(string absoluteFilePath, string nodeType, int id)
        {
            XElement xml = null;

            if (nodeType.Equals("content", StringComparison.InvariantCultureIgnoreCase))
            {
                var content = _contentService.GetById(id);
                xml = Export(content);
            }

            if (nodeType.Equals("media", StringComparison.InvariantCultureIgnoreCase))
            {
                var media = _mediaService.GetById(id);
                xml = Export(media);
            }

            if (nodeType.Equals("contenttype", StringComparison.InvariantCultureIgnoreCase))
            {
                var contentType = _contentTypeService.GetContentType(id);
                xml = Export(contentType);
            }

            if (nodeType.Equals("mediatype", StringComparison.InvariantCultureIgnoreCase))
            {
                var mediaType = _contentTypeService.GetMediaType(id);
                xml = Export(mediaType);
            }

            if (nodeType.Equals("datatype", StringComparison.InvariantCultureIgnoreCase))
            {
                var dataType = _dataTypeService.GetDataTypeDefinitionById(id);
                xml = Export(dataType);
            }

            if (xml != null)
            {
                xml.Save(absoluteFilePath);
            }
        }
Exemple #10
0
        /// <summary>
        /// Get all media
        /// </summary>
        /// <returns>IEnumerable of Media</returns>
        public IEnumerable <Media> GetAll()
        {
            var mediaItems = _mediaService.GetMediaOfMediaType(_contentTypeService.GetMediaType(PackageConstants.ImageAlias).Id);

            return(mediaItems.Select(item => item as Media).ToList());
        }
Exemple #11
0
            public override object ConvertDbToEditor(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
            {
                string value = property.Value?.ToString();

                if (string.IsNullOrEmpty(value))
                {
                    return(Enumerable.Empty <object>());
                }

                try
                {
                    ServiceContext      services           = ApplicationContext.Current.Services;
                    IEntityService      entityService      = services.EntityService;
                    IContentTypeService contentTypeService = services.ContentTypeService;

                    var links = JsonConvert.DeserializeObject <List <LinkDto> >(value);

                    var documentLinks = links.FindAll(link =>
                                                      link.Id.HasValue && false == link.IsMedia.GetValueOrDefault() ||
                                                      link.Udi != null && link.Udi.EntityType == Constants.UdiEntityType.Document
                                                      );

                    var mediaLinks = links.FindAll(link =>
                                                   link.Id.HasValue && true == link.IsMedia.GetValueOrDefault() ||
                                                   link.Udi != null && link.Udi.EntityType == Constants.UdiEntityType.Media
                                                   );

                    List <IUmbracoEntity> entities = new List <IUmbracoEntity>();
                    if (documentLinks.Count > 0)
                    {
                        if (documentLinks[0].Id.HasValue)
                        {
                            entities.AddRange(
                                entityService.GetAll(UmbracoObjectTypes.Document, documentLinks.Select(link => link.Id.Value).ToArray())
                                );
                        }
                        else
                        {
                            entities.AddRange(
                                entityService.GetAll(UmbracoObjectTypes.Document, documentLinks.Select(link => link.Udi.Guid).ToArray())
                                );
                        }
                    }

                    if (mediaLinks.Count > 0)
                    {
                        if (mediaLinks[0].Id.HasValue)
                        {
                            entities.AddRange(
                                entityService.GetAll(UmbracoObjectTypes.Media, mediaLinks.Select(link => link.Id.Value).ToArray())
                                );
                        }
                        else
                        {
                            entities.AddRange(
                                entityService.GetAll(UmbracoObjectTypes.Media, mediaLinks.Select(link => link.Udi.Guid).ToArray())
                                );
                        }
                    }

                    var result = new List <LinkDisplay>();
                    foreach (LinkDto dto in links)
                    {
                        if (dto.Id.HasValue || dto.Udi != null)
                        {
                            IUmbracoEntity entity = entities.Find(e => e.Key == dto.Udi?.Guid || e.Id == dto.Id);
                            if (entity == null)
                            {
                                continue;
                            }

                            string entityType = Equals(entity.AdditionalData["NodeObjectTypeId"], Constants.ObjectTypes.MediaGuid) ?
                                                Constants.UdiEntityType.Media :
                                                Constants.UdiEntityType.Document;

                            var udi = new GuidUdi(entityType, entity.Key);

                            string contentTypeAlias = entity.AdditionalData["ContentTypeAlias"] as string;
                            string icon;
                            bool   isMedia   = false;
                            bool   published = Equals(entity.AdditionalData["IsPublished"], true);
                            string url       = dto.Url;

                            if (string.IsNullOrEmpty(contentTypeAlias))
                            {
                                continue;
                            }

                            if (udi.EntityType == Constants.UdiEntityType.Document)
                            {
                                IContentType contentType = contentTypeService.GetContentType(contentTypeAlias);

                                if (contentType == null)
                                {
                                    continue;
                                }

                                icon = contentType.Icon;

                                if (UmbracoContext.Current != null)
                                {
                                    url = UmbracoContext.Current.UrlProvider.GetUrl(entity.Id);
                                }
                            }
                            else
                            {
                                IMediaType mediaType = contentTypeService.GetMediaType(contentTypeAlias);

                                if (mediaType == null)
                                {
                                    continue;
                                }

                                icon      = mediaType.Icon;
                                isMedia   = true;
                                published = true;

                                if (UmbracoContext.Current != null)
                                {
                                    url = UmbracoContext.Current.MediaCache.GetById(entity.Id)?.Url;
                                }
                            }

                            result.Add(new LinkDisplay
                            {
                                Icon        = icon,
                                Id          = entity.Id,
                                IsMedia     = isMedia,
                                Name        = dto.Name,
                                Target      = dto.Target,
                                Published   = published,
                                Udi         = udi,
                                Url         = url,
                                Querystring = dto.Querystring
                            });
                        }
                        else
                        {
                            result.Add(new LinkDisplay
                            {
                                Icon        = "icon-link",
                                Name        = dto.Name,
                                Published   = true,
                                Target      = dto.Target,
                                Url         = dto.Url,
                                Querystring = dto.Querystring
                            });
                        }
                    }
                    return(result);
                }
                catch (Exception ex)
                {
                    ApplicationContext.Current.ProfilingLogger.Logger.Error <MultiUrlPickerPropertyValueEditor>("Error getting links", ex);
                }

                return(base.ConvertDbToEditor(property, propertyType, dataTypeService));
            }
Exemple #12
0
 protected override IContentTypeComposition GetContentTypeByAlias(string alias)
 {
     return(_service.GetMediaType(alias));
 }
Exemple #13
0
        private int CreateMediaItem(IMediaService service, IContentTypeService contentTypeService,
                                    int parentFolderId, string nodeTypeAlias, Guid key, string nodeName, string mediaPath, bool checkForDuplicateName = false)
        {
            //if the item with the exact id exists we cannot install it (the package was probably already installed)
            if (service.GetById(key) != null)
            {
                return(-1);
            }

            //cannot continue if the media type doesn't exist
            var mediaType = contentTypeService.GetMediaType(nodeTypeAlias);

            if (mediaType == null)
            {
                LogHelper.Warn <InstallPackageAction>(
                    $"Could not create media, the '{nodeTypeAlias}' media type is missing, the Starter Kit package will not function correctly");
                return(-1);
            }

            var isDuplicate = false;

            if (checkForDuplicateName)
            {
                IEnumerable <IMedia> children;
                if (parentFolderId == -1)
                {
                    children = service.GetRootMedia();
                }
                else
                {
                    var parentFolder = service.GetById(parentFolderId);
                    if (parentFolder == null)
                    {
                        LogHelper.Warn <InstallPackageAction>("No media parent found by Id " + parentFolderId + " the media item " + nodeName + " cannot be installed");
                        return(-1);
                    }
                    children = service.GetChildren(parentFolderId);
                }
                foreach (var m in children)
                {
                    if (m.Name == nodeName)
                    {
                        isDuplicate = true;
                        break;
                    }
                }
            }

            if (isDuplicate)
            {
                return(-1);
            }

            if (parentFolderId != -1)
            {
                var parentFolder = service.GetById(parentFolderId);
                if (parentFolder == null)
                {
                    LogHelper.Warn <InstallPackageAction>("No media parent found by Id " + parentFolderId + " the media item " + nodeName + " cannot be installed");
                    return(-1);
                }
            }

            var media = service.CreateMedia(nodeName, parentFolderId, nodeTypeAlias);

            if (nodeTypeAlias != "folder")
            {
                media.SetValue("umbracoFile", mediaPath);
            }
            if (key != Guid.Empty)
            {
                media.Key = key;
            }
            service.Save(media);
            return(media.Id);
        }
        /// <summary>
        /// Update the existing content Type based on the data in the attributes
        /// </summary>
        /// <param name="contentTypeService"></param>
        /// <param name="fileService"></param>
        /// <param name="attribute"></param>
        /// <param name="mediaType"></param>
        /// <param name="type"></param>
        /// <param name="dataTypeService"></param>
        private static void UpdateMediaType(IContentTypeService contentTypeService, IFileService fileService, UmbracoMediaTypeAttribute attribute, IMediaType mediaType, Type type, IDataTypeService dataTypeService)
        {
            mediaType.Name = attribute.MediaTypeName;
            mediaType.Alias = attribute.MediaTypeAlias;
            mediaType.Icon = attribute.Icon;
            mediaType.Description = attribute.Description;
            mediaType.IsContainer = attribute.EnableListView;
            mediaType.AllowedContentTypes = FetchAllowedContentTypes(attribute.AllowedChildren, contentTypeService);
            mediaType.AllowedAsRoot = attribute.AllowedAtRoot;

            Type parentType = type.BaseType;
            if (parentType != null && parentType != typeof(UmbracoGeneratedBase) && parentType.GetBaseTypes(false).Any(x => x == typeof(UmbracoGeneratedBase)))
            {
                UmbracoMediaTypeAttribute parentAttribute = parentType.GetCustomAttribute<UmbracoMediaTypeAttribute>();
                if (parentAttribute != null)
                {
                    string parentAlias = parentAttribute.MediaTypeAlias;
                    IMediaType parentContentType = contentTypeService.GetMediaType(parentAlias);
                    mediaType.ParentId = parentContentType.Id;
                }
                else
                {
                    throw new Exception("The given base class has no UmbracoMediaTypeAttribute");
                }
            }

            VerifyProperties(mediaType, type, dataTypeService);

            //verify if a tab has no properties, if so remove
            var propertyGroups = mediaType.PropertyGroups.ToArray();
            int length = propertyGroups.Length;
            for (int i = 0; i < length; i++)
            {
                if (propertyGroups[i].PropertyTypes.Count == 0)
                {
                    //remove
                    mediaType.RemovePropertyGroup(propertyGroups[i].Name);
                }
            }

            //persist
            contentTypeService.Save(mediaType, 0);
        }
        /// <summary>
        /// This method is called when the Media Type declared in the attribute hasn't been found in Umbraco
        /// </summary>
        /// <param name="contentTypeService"></param>
        /// <param name="fileService"></param>
        /// <param name="attribute"></param>
        /// <param name="type"></param>
        /// <param name="dataTypeService"></param>
        private static void CreateMediaType(IContentTypeService contentTypeService, IFileService fileService,
            UmbracoMediaTypeAttribute attribute, Type type, IDataTypeService dataTypeService)
        {
            IMediaType newMediaType;
            Type parentType = type.BaseType;
            if (parentType != null && parentType != typeof(UmbracoGeneratedBase) && parentType.GetBaseTypes(false).Any(x => x == typeof(UmbracoGeneratedBase)))
            {
                UmbracoMediaTypeAttribute parentAttribute = parentType.GetCustomAttribute<UmbracoMediaTypeAttribute>();
                if (parentAttribute != null)
                {
                    string parentAlias = parentAttribute.MediaTypeAlias;
                    IMediaType parentContentType = contentTypeService.GetMediaType(parentAlias);
                    newMediaType = new MediaType(parentContentType);
                }
                else
                {
                    throw new Exception("The given base class has no UmbracoMediaTypeAttribute");
                }
            }
            else
            {
                newMediaType = new MediaType(-1);
            }

            newMediaType.Name = attribute.MediaTypeName;
            newMediaType.Alias = attribute.MediaTypeAlias;
            newMediaType.Icon = attribute.Icon;
            newMediaType.Description = attribute.Description;
            newMediaType.AllowedAsRoot = attribute.AllowedAtRoot;
            newMediaType.IsContainer = attribute.EnableListView;
            newMediaType.AllowedContentTypes = FetchAllowedContentTypes(attribute.AllowedChildren, contentTypeService);

            //create tabs
            CreateTabs(newMediaType, type, dataTypeService);
            
            //create properties on the generic tab
            var propertiesOfRoot = type.GetProperties().Where(x => x.GetCustomAttribute<UmbracoPropertyAttribute>() != null);
            foreach (var item in propertiesOfRoot)
            {
                CreateProperty(newMediaType, null, dataTypeService, true, item);
            }

            //Save and persist the media Type
            contentTypeService.Save(newMediaType, 0);
        }