private bool UpdateLegacyPicker(string propertyValue, out string newPropertyValue)
        {
            newPropertyValue = null;

            //Get the INT ids stored for this property/drop down
            int[] ids = null;
            if (!propertyValue.IsNullOrWhiteSpace())
            {
                ids = ConvertStringValues(propertyValue);
            }

            if (ids == null || ids.Length <= 0)
            {
                return(false);
            }

            // map ids to values
            var values = new List <Udi>();

            foreach (var id in ids)
            {
                if (_nodeIdToKey.Value.TryGetValue(id, out var node))
                {
                    values.Add(Udi.Create(ObjectTypes.GetUdiType(node.NodeObjectType.Value), node.UniqueId));
                }
            }
            newPropertyValue = String.Join(",", values);

            return(true);
        }
Пример #2
0
 // Umbraco.Code.MapAll -Properties -Errors -Edited -Updater -Alias -IsContainer
 private void Map(IMedia source, MediaItemDisplay target, MapperContext context)
 {
     target.ContentApps      = _commonMapper.GetContentApps(source);
     target.ContentType      = _commonMapper.GetContentType(source, context);
     target.ContentTypeId    = source.ContentType.Id;
     target.ContentTypeAlias = source.ContentType.Alias;
     target.ContentTypeName  = source.ContentType.Name;
     target.CreateDate       = source.CreateDate;
     target.Icon             = source.ContentType.Icon;
     target.Id = source.Id;
     target.IsChildOfListView = DetermineIsChildOfListView(source);
     target.Key             = source.Key;
     target.MediaLink       = string.Join(",", source.GetUrls(Current.Configs.Settings().Content, _logger));
     target.Name            = source.Name;
     target.Owner           = _commonMapper.GetOwner(source, context);
     target.ParentId        = source.ParentId;
     target.Path            = source.Path;
     target.SortOrder       = source.SortOrder;
     target.State           = null;
     target.Tabs            = _tabsAndPropertiesMapper.Map(source, context);
     target.Trashed         = source.Trashed;
     target.TreeNodeUrl     = _commonMapper.GetTreeNodeUrl <MediaTreeController>(source);
     target.Udi             = Udi.Create(Constants.UdiEntityType.Media, source.Key);
     target.UpdateDate      = source.UpdateDate;
     target.VariesByCulture = source.ContentType.VariesByCulture();
 }
Пример #3
0
        // Umbraco.Code.MapAll -AllowPreview -Errors -PersistedContent
        private void Map(IContent source, ContentItemDisplay target, MapperContext context)
        {
            target.AllowedActions   = GetActions(source);
            target.AllowedTemplates = GetAllowedTemplates(source);
            target.ContentApps      = _commonMapper.GetContentApps(source);
            target.ContentTypeId    = source.ContentType.Id;
            target.ContentTypeKey   = source.ContentType.Key;
            target.ContentTypeAlias = source.ContentType.Alias;
            target.ContentTypeName  = _localizedTextService.UmbracoDictionaryTranslate(source.ContentType.Name);
            target.DocumentType     = _commonMapper.GetContentType(source, context);
            target.Icon             = source.ContentType.Icon;
            target.Id                = source.Id;
            target.IsBlueprint       = source.Blueprint;
            target.IsChildOfListView = DetermineIsChildOfListView(source, context);
            target.IsContainer       = source.ContentType.IsContainer;
            target.IsElement         = source.ContentType.IsElement;
            target.Key               = source.Key;
            target.Owner             = _commonMapper.GetOwner(source, context);
            target.ParentId          = source.ParentId;
            target.Path              = source.Path;
            target.SortOrder         = source.SortOrder;
            target.TemplateAlias     = GetDefaultTemplate(source);
            target.TemplateId        = source.TemplateId ?? default;
            target.Trashed           = source.Trashed;
            target.TreeNodeUrl       = _commonMapper.GetTreeNodeUrl <ContentTreeController>(source);
            target.Udi               = Udi.Create(source.Blueprint ? Constants.UdiEntityType.DocumentBlueprint : Constants.UdiEntityType.Document, source.Key);
            target.UpdateDate        = source.UpdateDate;
            target.Updater           = _commonMapper.GetCreator(source, context);
            target.Urls              = GetUrls(source);
            target.Variants          = _contentVariantMapper.Map(source, context);

            target.ContentDto            = new ContentPropertyCollectionDto();
            target.ContentDto.Properties = context.MapEnumerable <Property, ContentPropertyDto>(source.Properties);
        }
        private IEnumerable <UmbracoEntityReference> GetUmbracoEntityReferencesFromMacros(List <Tuple <string?, Dictionary <string, string> > > macros)
        {
            if (_macroService is not IMacroWithAliasService macroWithAliasService)
            {
                yield break;
            }

            var uniqueMacroAliases = macros.Select(f => f.Item1).Distinct();
            // TODO: Tracking Macro references
            // Here we are finding the used macros' Udis (there should be a Related Macro relation type - but Relations don't accept 'Macro' as an option)
            var foundMacroUmbracoEntityReferences = new List <UmbracoEntityReference>();
            // Get all the macro configs in one hit for these unique macro aliases - this is now cached with a custom cache policy
            var macroConfigs = macroWithAliasService.GetAll(uniqueMacroAliases.WhereNotNull().ToArray());

            foreach (var macro in macros)
            {
                var macroConfig = macroConfigs.FirstOrDefault(f => f.Alias == macro.Item1);
                if (macroConfig is null)
                {
                    continue;
                }
                foundMacroUmbracoEntityReferences.Add(new UmbracoEntityReference(Udi.Create(Constants.UdiEntityType.Macro, macroConfig.Key)));
                // Only do this if the macros actually have parameters
                if (macroConfig.Properties is not null && macroConfig.Properties.Keys.Any(f => f != "macroAlias"))
                {
                    foreach (var umbracoEntityReference in GetUmbracoEntityReferencesFromMacroParameters(macro.Item2, macroConfig, _parameterEditors))
                    {
                        yield return(umbracoEntityReference);
                    }
                }
            }
        }
Пример #5
0
        public static Content CreateAllTypesContent(IContentType contentType, string name, int parentId)
        {
            Content content = new ContentBuilder()
                              .WithName(name)
                              .WithParentId(parentId)
                              .WithContentType(contentType)
                              .Build();

            content.SetValue("isTrue", true);
            content.SetValue("number", 42);
            content.SetValue("bodyText", "Lorem Ipsum Body Text Test");
            content.SetValue("singleLineText", "Single Line Text Test");
            content.SetValue("multilineText", "Multiple lines \n in one box");
            content.SetValue("upload", "/media/1234/koala.jpg");
            content.SetValue("label", "Non-editable label");
            content.SetValue("dateTime", DateTime.Now.AddDays(-20));
            content.SetValue("colorPicker", "black");
            content.SetValue("ddlMultiple", "1234,1235");
            content.SetValue("rbList", "random");
            content.SetValue("date", DateTime.Now.AddDays(-10));
            content.SetValue("ddl", "1234");
            content.SetValue("chklist", "randomc");
            content.SetValue("contentPicker", Udi.Create(Constants.UdiEntityType.Document, new Guid("74ECA1D4-934E-436A-A7C7-36CC16D4095C")).ToString());
            content.SetValue("mediaPicker", Udi.Create(Constants.UdiEntityType.Media, new Guid("44CB39C8-01E5-45EB-9CF8-E70AAF2D1691")).ToString());
            content.SetValue("memberPicker", Udi.Create(Constants.UdiEntityType.Member, new Guid("9A50A448-59C0-4D42-8F93-4F1D55B0F47D")).ToString());
            content.SetValue("multiUrlPicker", "[{\"name\":\"https://test.com\",\"url\":\"https://test.com\"}]");
            content.SetValue("tags", "this,is,tags");

            return(content);
        }
Пример #6
0
        // Umbraco.Code.MapAll -Alias
        private static void Map(IEntitySlim source, EntityBasic target, MapperContext context)
        {
            target.Icon     = MapContentTypeIcon(source);
            target.Id       = source.Id;
            target.Key      = source.Key;
            target.Name     = MapName(source, context);
            target.ParentId = source.ParentId;
            target.Path     = source.Path;
            target.Trashed  = source.Trashed;
            target.Udi      = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key);

            if (source.NodeObjectType == Constants.ObjectTypes.Member && target.Icon.IsNullOrWhiteSpace())
            {
                target.Icon = "icon-user";
            }

            // NOTE: we're mapping the objects in AdditionalData by object reference here.
            // it works fine for now, but it's something to keep in mind in the future
            foreach (var kvp in source.AdditionalData)
            {
                target.AdditionalData[kvp.Key] = kvp.Value;
            }

            target.AdditionalData.Add("IsContainer", source.IsContainer);
        }
Пример #7
0
        // Umbraco.Code.MapAll -Blueprints
        private void Map(IContentTypeBase source, ContentTypeBasic target, string entityType)
        {
            target.Udi          = Udi.Create(entityType, source.Key);
            target.Alias        = source.Alias;
            target.CreateDate   = source.CreateDate;
            target.Description  = source.Description;
            target.Icon         = source.Icon;
            target.IconFilePath = target.IconIsClass
                ? string.Empty
                : $"{_globalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith("/")}images/umbraco/{source.Icon}";

            target.Trashed           = source.Trashed;
            target.Id                = source.Id;
            target.IsContainer       = source.IsContainer;
            target.IsElement         = source.IsElement;
            target.Key               = source.Key;
            target.Name              = source.Name;
            target.ParentId          = source.ParentId;
            target.Path              = source.Path;
            target.Thumbnail         = source.Thumbnail;
            target.ThumbnailFilePath = target.ThumbnailIsClass
                ? string.Empty
                : _hostingEnvironment.ToAbsolute("~/umbraco/images/thumbnails/" + source.Thumbnail);
            target.UpdateDate = source.UpdateDate;
        }
Пример #8
0
        internal static Udi MapContentTypeUdi(IContentTypeComposition source)
        {
            if (source == null)
            {
                return(null);
            }

            string udiType;

            switch (source)
            {
            case IMemberType _:
                udiType = Constants.UdiEntityType.MemberType;
                break;

            case IMediaType _:
                udiType = Constants.UdiEntityType.MediaType;
                break;

            case IContentType _:
                udiType = Constants.UdiEntityType.DocumentType;
                break;

            default:
                throw new Exception("panic");
            }

            return(Udi.Create(udiType, source.Key));
        }
        public static Content CreateAllTypesContent(IContentType contentType, string name, int parentId)
        {
            var content = new Content("Random Content Name", parentId, contentType)
            {
                Level = 1, SortOrder = 1, CreatorId = 0, WriterId = 0
            };

            content.SetValue("isTrue", true);
            content.SetValue("number", 42);
            content.SetValue("bodyText", "Lorem Ipsum Body Text Test");
            content.SetValue("singleLineText", "Single Line Text Test");
            content.SetValue("multilineText", "Multiple lines \n in one box");
            content.SetValue("upload", "/media/1234/koala.jpg");
            content.SetValue("label", "Non-editable label");
            content.SetValue("dateTime", DateTime.Now.AddDays(-20));
            content.SetValue("colorPicker", "black");
            //that one is gone in 7.4
            //content.SetValue("folderBrowser", "");
            content.SetValue("ddlMultiple", "1234,1235");
            content.SetValue("rbList", "random");
            content.SetValue("date", DateTime.Now.AddDays(-10));
            content.SetValue("ddl", "1234");
            content.SetValue("chklist", "randomc");
            content.SetValue("contentPicker", Udi.Create(Constants.UdiEntityType.Document, new Guid("74ECA1D4-934E-436A-A7C7-36CC16D4095C")).ToString());
            content.SetValue("mediaPicker", Udi.Create(Constants.UdiEntityType.Media, new Guid("44CB39C8-01E5-45EB-9CF8-E70AAF2D1691")).ToString());
            content.SetValue("memberPicker", Udi.Create(Constants.UdiEntityType.Member, new Guid("9A50A448-59C0-4D42-8F93-4F1D55B0F47D")).ToString());
            content.SetValue("relatedLinks", "<links><link title=\"google\" link=\"http://google.com\" type=\"external\" newwindow=\"0\" /></links>");
            content.SetValue("tags", "this,is,tags");

            return(content);
        }
Пример #10
0
        protected uSyncDependency CalcDocTypeDependency(IContentBase item, DependencyFlags flags)
        {
            if (item.ContentType == null)
            {
                return(null);
            }


            var entity = entityService.GetKey(item.ContentTypeId, contentTypeObjectType);

            if (entity.Success)
            {
                var udi = Udi.Create(contentTypeObjectType.GetUdiType(), entity.Result);

                return(new uSyncDependency()
                {
                    Name = item.Name,
                    Udi = udi,
                    Order = DependencyOrders.ContentTypes,
                    Flags = flags & ~DependencyFlags.IncludeAncestors,
                    Level = item.Level
                });
            }

            return(null);
        }
Пример #11
0
        protected IEnumerable <uSyncDependency> CalcChildren(int itemId, DependencyFlags flags)
        {
            var childItems = new List <uSyncDependency>();

            if (flags.HasFlag(DependencyFlags.IncludeChildren))
            {
                var children = entityService.GetDescendants(itemId, this.ObjectType);

                if (children != null && children.Any())
                {
                    foreach (var child in children.OrderBy(x => x.Level))
                    {
                        if (child != null)
                        {
                            childItems.Add(new uSyncDependency()
                            {
                                Name  = child.Name,
                                Udi   = Udi.Create(UdiEntityType.FromUmbracoObjectType(this.ObjectType), child.Key),
                                Flags = flags & ~DependencyFlags.IncludeAncestors,
                                Level = child.Level,
                                Order = DependencyOrders.ContentTypes + child.Level
                            });
                        }
                    }
                }
            }

            return(childItems);
        }
Пример #12
0
        public MacroMapperProfile()
        {
            //FROM IMacro TO EntityBasic
            CreateMap <IMacro, EntityBasic>()
            .ForMember(x => x.Udi, expression => expression.MapFrom(content => Udi.Create(Constants.UdiEntityType.Macro, content.Key)))
            .ForMember(entityBasic => entityBasic.Icon, expression => expression.UseValue("icon-settings-alt"))
            .ForMember(dto => dto.ParentId, expression => expression.UseValue(-1))
            .ForMember(dto => dto.Path, expression => expression.ResolveUsing(macro => "-1," + macro.Id))
            .ForMember(dto => dto.Trashed, expression => expression.Ignore())
            .ForMember(dto => dto.AdditionalData, expression => expression.Ignore());

            CreateMap <IMacro, IEnumerable <MacroParameter> >()
            .ConvertUsing(macro => macro.Properties.Values.Select(Mapper.Map <MacroParameter>).ToList());

            CreateMap <IMacroProperty, MacroParameter>()
            .ForMember(x => x.View, expression => expression.Ignore())
            .ForMember(x => x.Configuration, expression => expression.Ignore())
            .ForMember(x => x.Value, expression => expression.Ignore())
            .AfterMap((property, parameter) =>
            {
                //map the view and the config
                // we need to show the depracated ones for backwards compatibility
                var paramEditor = Current.ParameterEditors[property.EditorAlias];     // fixme - include/filter deprecated?!
                if (paramEditor == null)
                {
                    //we'll just map this to a text box
                    paramEditor = Current.ParameterEditors[Constants.PropertyEditors.Aliases.TextBox];
                    Current.Logger.Warn <MacroMapperProfile>("Could not resolve a parameter editor with alias {PropertyEditorAlias}, a textbox will be rendered in it's place", property.EditorAlias);
                }

                parameter.View = paramEditor.GetValueEditor().View;
                //set the config
                parameter.Configuration = paramEditor.DefaultConfiguration;
            });
        }
Пример #13
0
 /// <summary>
 ///  Get the Root item for the tree (default implimentation uses first entity type)
 /// </summary>
 /// <param name="treeItem"></param>
 /// <returns></returns>
 protected virtual SyncLocalItem GetRootItem(SyncTreeItem treeItem)
 => new SyncLocalItem(Constants.System.RootString)
 {
     EntityType = EntityType,
     Name       = EntityType,
     Udi        = Udi.Create(EntityType)
 };
Пример #14
0
        /// <summary>
        /// The method called to render the contents of the tree structure
        /// </summary>
        /// <param name="id"></param>
        /// <param name="queryStrings">
        /// All of the query string parameters passed from jsTree
        /// </param>
        /// <remarks>
        /// We are allowing an arbitrary number of query strings to be pased in so that developers are able to persist custom data from the front-end
        /// to the back end to be used in the query for model data.
        /// </remarks>
        protected override ActionResult <TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
        {
            var nodes = new TreeNodeCollection();

            var found = id == Constants.System.RootString
                ? _fileService.GetTemplates(-1)
                : _fileService.GetTemplates(int.Parse(id, CultureInfo.InvariantCulture));

            if (found is not null)
            {
                nodes.AddRange(found.Select(template => CreateTreeNode(
                                                template.Id.ToString(CultureInfo.InvariantCulture),
                                                // TODO: Fix parent ID stuff for templates
                                                "-1",
                                                queryStrings,
                                                template.Name,
                                                template.IsMasterTemplate ? "icon-newspaper" : "icon-newspaper-alt",
                                                template.IsMasterTemplate,
                                                null,
                                                Udi.Create(ObjectTypes.GetUdiType(Constants.ObjectTypes.TemplateType), template.Key)
                                                )));
            }

            return(nodes);
        }
Пример #15
0
        protected virtual Udi PathToUdi(string entityPath)
        {
            if (entityPath.IndexOf(':') == -1)
            {
                return(null);
            }

            var entityType = entityPath.Substring(0, entityPath.IndexOf(':'));
            var objectType = UdiEntityTypeHelper.ToUmbracoObjectType(entityType);

            var names = entityPath.Substring(entityPath.IndexOf(':') + 1).ToDelimitedList("/");

            int parentId = -1;

            IEntitySlim next = null;

            foreach (var name in names)
            {
                next = FindItem(parentId, name, objectType);
                if (next == null)
                {
                    return(null);
                }

                parentId = next.Id;
            }

            if (next != null)
            {
                return(Udi.Create(entityType, next.Key));
            }


            return(null);
        }
 /// <remarks>
 ///     Note: no FromEditor() and ToEditor() methods
 ///     We do not want to transform the way the data is stored in the DB and would like to keep a raw JSON string
 /// </remarks>
 public IEnumerable <UmbracoEntityReference> GetReferences(object?value)
 {
     foreach (MediaWithCropsDto dto in Deserialize(_jsonSerializer, value))
     {
         yield return(new UmbracoEntityReference(Udi.Create(Constants.UdiEntityType.Media, dto.MediaKey)));
     }
 }
Пример #17
0
        // Umbraco.Code.MapAll -Trashed -Alias -Score
        private static void Map(EntitySlim source, SearchResultEntity target, MapperContext context)
        {
            target.Icon     = MapContentTypeIcon(source);
            target.Id       = source.Id;
            target.Key      = source.Key;
            target.Name     = source.Name;
            target.ParentId = source.ParentId;
            target.Path     = source.Path;
            target.Udi      = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key);

            if (target.Icon.IsNullOrWhiteSpace())
            {
                if (source.NodeObjectType == Constants.ObjectTypes.Member)
                {
                    target.Icon = "icon-user";
                }
                else if (source.NodeObjectType == Constants.ObjectTypes.DataType)
                {
                    target.Icon = "icon-autofill";
                }
                else if (source.NodeObjectType == Constants.ObjectTypes.DocumentType)
                {
                    target.Icon = "icon-item-arrangement";
                }
                else if (source.NodeObjectType == Constants.ObjectTypes.MediaType)
                {
                    target.Icon = "icon-thumbnails";
                }
                else if (source.NodeObjectType == Constants.ObjectTypes.TemplateType)
                {
                    target.Icon = "icon-newspaper-alt";
                }
            }
        }
        public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
        {
            //FROM IMacro TO EntityBasic
            config.CreateMap <IMacro, EntityBasic>()
            .ForMember(x => x.Udi, expression => expression.MapFrom(content => Udi.Create(Constants.UdiEntityType.Macro, content.Key)))
            .ForMember(entityBasic => entityBasic.Icon, expression => expression.UseValue("icon-settings-alt"))
            .ForMember(dto => dto.ParentId, expression => expression.UseValue(-1))
            .ForMember(dto => dto.Path, expression => expression.ResolveUsing(macro => "-1," + macro.Id))
            .ForMember(dto => dto.Trashed, expression => expression.Ignore())
            .ForMember(dto => dto.AdditionalData, expression => expression.Ignore());

            config.CreateMap <IMacro, IEnumerable <MacroParameter> >()
            .ConvertUsing(macro => macro.Properties.Select(Mapper.Map <MacroParameter>).ToList());

            config.CreateMap <IMacroProperty, MacroParameter>()
            .ForMember(x => x.View, expression => expression.Ignore())
            .ForMember(x => x.Configuration, expression => expression.Ignore())
            .ForMember(x => x.Value, expression => expression.Ignore())
            .AfterMap((property, parameter) =>
            {
                //map the view and the config
                // we need to show the depracated ones for backwards compatibility
                var paramEditor = ParameterEditorResolver.Current.GetByAlias(property.EditorAlias, true);
                if (paramEditor == null)
                {
                    //we'll just map this to a text box
                    paramEditor = ParameterEditorResolver.Current.GetByAlias(Constants.PropertyEditors.TextboxAlias);
                    LogHelper.Warn <MacroModelMapper>("Could not resolve a parameter editor with alias " + property.EditorAlias + ", a textbox will be rendered in it's place");
                }

                parameter.View = paramEditor.ValueEditor.View;
                //set the config
                parameter.Configuration = paramEditor.Configuration;
            });
        }
 public IEnumerable <UmbracoEntityReference> GetReferences(object value)
 {
     foreach (var dto in Deserialize(value))
     {
         yield return(new UmbracoEntityReference(Udi.Create(Constants.UdiEntityType.Media, dto.MediaKey)));
     }
 }
Пример #20
0
        // Umbraco.Code.MapAll -Trashed -Alias -Score
        private static void Map(EntitySlim source, SearchResultEntity target, MapperContext context)
        {
            target.Icon     = MapContentTypeIcon(source);
            target.Id       = source.Id;
            target.Key      = source.Key;
            target.Name     = source.Name;
            target.ParentId = source.ParentId;
            target.Path     = source.Path;
            target.Udi      = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key);

            if (target.Icon.IsNullOrWhiteSpace())
            {
                if (source.NodeObjectType == Constants.ObjectTypes.Member)
                {
                    target.Icon = Constants.Icons.Member;
                }
                else if (source.NodeObjectType == Constants.ObjectTypes.DataType)
                {
                    target.Icon = Constants.Icons.DataType;
                }
                else if (source.NodeObjectType == Constants.ObjectTypes.DocumentType)
                {
                    target.Icon = Constants.Icons.ContentType;
                }
                else if (source.NodeObjectType == Constants.ObjectTypes.MediaType)
                {
                    target.Icon = Constants.Icons.MediaType;
                }
                else if (source.NodeObjectType == Constants.ObjectTypes.TemplateType)
                {
                    target.Icon = Constants.Icons.Template;
                }
            }
        }
Пример #21
0
        public static Udi MapContentTypeUdi(IContentTypeComposition source)
        {
            if (source == null)
            {
                return(null);
            }

            string udiType;

            switch (source)
            {
            case IMemberType _:
                udiType = Constants.UdiEntityType.MemberType;
                break;

            case IMediaType _:
                udiType = Constants.UdiEntityType.MediaType;
                break;

            case IContentType _:
                udiType = Constants.UdiEntityType.DocumentType;
                break;

            default:
                throw new PanicException($"Source is of type {source.GetType()} which isn't supported here");
            }

            return(Udi.Create(udiType, source.Key));
        }
Пример #22
0
        // Umbraco.Code.MapAll -Alias
        private static void Map(IEntitySlim source, EntityBasic target, MapperContext context)
        {
            target.Icon     = MapContentTypeIcon(source);
            target.Id       = source.Id;
            target.Key      = source.Key;
            target.Name     = MapName(source, context);
            target.ParentId = source.ParentId;
            target.Path     = source.Path;
            target.Trashed  = source.Trashed;
            target.Udi      = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key);

            if (source is IContentEntitySlim contentSlim)
            {
                source.AdditionalData["ContentTypeAlias"] = contentSlim.ContentTypeAlias;
            }

            if (source is IDocumentEntitySlim documentSlim)
            {
                source.AdditionalData["IsPublished"] = documentSlim.Published;
            }

            if (source is IMediaEntitySlim mediaSlim)
            {
                source.AdditionalData["MediaPath"] = mediaSlim.MediaPath;
            }

            // NOTE: we're mapping the objects in AdditionalData by object reference here.
            // it works fine for now, but it's something to keep in mind in the future
            foreach (var kvp in source.AdditionalData)
            {
                target.AdditionalData[kvp.Key] = kvp.Value;
            }

            target.AdditionalData.Add("IsContainer", source.IsContainer);
        }
Пример #23
0
    // Umbraco.Code.MapAll -Icon -Trashed -AdditionalData
    // Umbraco.Code.MapAll -ParentId -Notifications
    private void Map(IRelationType source, RelationTypeDisplay target, MapperContext context)
    {
        target.ChildObjectType = source.ChildObjectType;
        target.Id = source.Id;
        target.IsBidirectional = source.IsBidirectional;

        if (source is IRelationTypeWithIsDependency sourceWithIsDependency)
        {
            target.IsDependency = sourceWithIsDependency.IsDependency;
        }

        target.Key              = source.Key;
        target.Name             = source.Name;
        target.Alias            = source.Alias;
        target.ParentObjectType = source.ParentObjectType;
        target.Udi              = Udi.Create(Constants.UdiEntityType.RelationType, source.Key);
        target.Path             = "-1," + source.Id;

        target.IsSystemRelationType = source.IsSystemRelationType();

        // Set the "friendly" and entity names for the parent and child object types
        if (source.ParentObjectType.HasValue)
        {
            UmbracoObjectTypes objType = ObjectTypes.GetUmbracoObjectType(source.ParentObjectType.Value);
            target.ParentObjectTypeName = objType.GetFriendlyName();
        }

        if (source.ChildObjectType.HasValue)
        {
            UmbracoObjectTypes objType = ObjectTypes.GetUmbracoObjectType(source.ChildObjectType.Value);
            target.ChildObjectTypeName = objType.GetFriendlyName();
        }
    }
Пример #24
0
        // Umbraco.Code.MapAll -Properties -Errors -Edited -Updater -Alias -IsChildOfListView
        // Umbraco.Code.MapAll -Trashed -IsContainer -VariesByCulture
        private void Map(IMember source, MemberDisplay target, MapperContext context)
        {
            target.ContentApps      = _commonMapper.GetContentAppsForEntity(source);
            target.ContentType      = _commonMapper.GetContentType(source, context);
            target.ContentTypeId    = source.ContentType.Id;
            target.ContentTypeAlias = source.ContentType.Alias;
            target.ContentTypeName  = source.ContentType.Name;
            target.CreateDate       = source.CreateDate;
            target.Icon             = source.ContentType.Icon;
            target.Id          = source.Id;
            target.Key         = source.Key;
            target.Name        = source.Name;
            target.Owner       = _commonMapper.GetOwner(source, context);
            target.ParentId    = source.ParentId;
            target.Path        = source.Path;
            target.SortOrder   = source.SortOrder;
            target.State       = null;
            target.Tabs        = _tabsAndPropertiesMapper.Map(source, context);
            target.TreeNodeUrl = _commonTreeNodeMapper.GetTreeNodeUrl <MemberTreeController>(source);
            target.Udi         = Udi.Create(Constants.UdiEntityType.Member, source.Key);
            target.UpdateDate  = source.UpdateDate;

            //Membership
            target.Username             = source.Username;
            target.Email                = source.Email;
            target.IsLockedOut          = source.IsLockedOut;
            target.IsApproved           = source.IsApproved;
            target.MembershipProperties = _tabsAndPropertiesMapper.MapMembershipProperties(source, context);
        }
Пример #25
0
        /// <summary>
        ///  Get the actual media file as a dependency.
        /// </summary>
        public override IEnumerable <uSyncDependency> GetDependencies(object value, string editorAlias, DependencyFlags flags)
        {
            var stringValue = value?.ToString();

            if (string.IsNullOrWhiteSpace(stringValue))
            {
                return(Enumerable.Empty <uSyncDependency>());
            }

            var stringPath = GetImagePath(stringValue).TrimStart('/').ToLower();

            if (!string.IsNullOrWhiteSpace(stringPath))
            {
                return(new uSyncDependency()
                {
                    Name = $"File: {Path.GetFileName(stringPath)}",
                    Udi = Udi.Create(Constants.UdiEntityType.MediaFile, stringPath),
                    Flags = flags,
                    Order = DependencyOrders.OrderFromEntityType(Constants.UdiEntityType.MediaFile),
                    Level = 0
                }.AsEnumerableOfOne());
            }

            return(Enumerable.Empty <uSyncDependency>());
        }
        protected ActionResult<TreeNode> GetSingleTreeNode(string id, FormCollection queryStrings)
        {
            Guid asGuid;
            if (Guid.TryParse(id, out asGuid) == false)
            {
                return NotFound();
            }

            var member = _memberService.GetByKey(asGuid);
            if (member == null)
            {
                return NotFound();
            }

            var node = CreateTreeNode(
                member.Key.ToString("N"),
                "-1",
                queryStrings,
                member.Name,
                Constants.Icons.Member,
                false,
                "",
                Udi.Create(ObjectTypes.GetUdiType(Constants.ObjectTypes.Member), member.Key));

            node.AdditionalData.Add("contentType", member.ContentTypeAlias);
            node.AdditionalData.Add("isContainer", true);

            return node;
        }
Пример #27
0
 // Umbraco.Code.MapAll -Properties -Errors -Edited -Updater -Alias -IsChildOfListView
 // Umbraco.Code.MapAll -Trashed -IsContainer -VariesByCulture
 private void Map(IMember source, MemberDisplay target, MapperContext context)
 {
     target.ContentApps = _commonMapper.GetContentApps(source);
     target.ContentType = _commonMapper.GetContentType(source, context);
     target.ContentTypeId = source.ContentType.Id;
     target.ContentTypeAlias = source.ContentType.Alias;
     target.ContentTypeName = source.ContentType.Name;
     target.CreateDate = source.CreateDate;
     target.Email = source.Email;
     target.Icon = source.ContentType.Icon;
     target.Id = source.Id;
     target.Key = source.Key;
     target.MemberProviderFieldMapping = GetMemberProviderFieldMapping();
     target.MembershipScenario = GetMembershipScenario();
     target.Name = source.Name;
     target.Owner = _commonMapper.GetOwner(source, context);
     target.ParentId = source.ParentId;
     target.Path = source.Path;
     target.SortOrder = source.SortOrder;
     target.State = null;
     target.Tabs = _tabsAndPropertiesMapper.Map(source, context);
     target.TreeNodeUrl = _commonMapper.GetMemberTreeNodeUrl(source);
     target.Udi = Udi.Create(Constants.UdiEntityType.Member, source.Key);
     target.UpdateDate = source.UpdateDate;
     target.Username = source.Username;
 }
Пример #28
0
        public static Content CreateAllTypesContent(IContentType contentType, string name, int parentId)
        {
            var content = new Content("Random Content Name", parentId, contentType)
            {
                Level = 1, SortOrder = 1, CreatorId = 0, WriterId = 0
            };

            content.SetValue("isTrue", true);
            content.SetValue("number", 42);
            content.SetValue("bodyText", "Lorem Ipsum Body Text Test");
            content.SetValue("singleLineText", "Single Line Text Test");
            content.SetValue("multilineText", "Multiple lines \n in one box");
            content.SetValue("upload", "/media/1234/koala.jpg");
            content.SetValue("label", "Non-editable label");
            content.SetValue("dateTime", DateTime.Now.AddDays(-20));
            content.SetValue("colorPicker", "black");
            //that one is gone in 7.4
            //content.SetValue("folderBrowser", "");
            content.SetValue("ddlMultiple", "1234,1235");
            content.SetValue("rbList", "random");
            content.SetValue("date", DateTime.Now.AddDays(-10));
            content.SetValue("ddl", "1234");
            content.SetValue("chklist", "randomc");
            content.SetValue("contentPicker", Udi.Create(Constants.UdiEntityType.Document, new Guid("74ECA1D4-934E-436A-A7C7-36CC16D4095C")).ToString());
            content.SetValue("mediaPicker3", "[{\"key\": \"8f78ce9e-8fe0-4500-a52d-4c4f35566ba9\",\"mediaKey\": \"44CB39C8-01E5-45EB-9CF8-E70AAF2D1691\",\"crops\": [],\"focalPoint\": {\"left\": 0.5,\"top\": 0.5}}]");
            content.SetValue("memberPicker", Udi.Create(Constants.UdiEntityType.Member, new Guid("9A50A448-59C0-4D42-8F93-4F1D55B0F47D")).ToString());
            content.SetValue("multiUrlPicker", "[{\"name\":\"https://test.com\",\"url\":\"https://test.com\"}]");
            content.SetValue("tags", "this,is,tags");

            return(content);
        }
        public PagedResult <EntityBasic> GetPagedReferences(int id, string entityType, int pageNumber = 1, int pageSize = 100)
        {
            if (pageNumber <= 0 || pageSize <= 0)
            {
                throw new NotSupportedException("Both pageNumber and pageSize must be greater than zero");
            }

            var objectType = ObjectTypes.GetUmbracoObjectType(entityType);
            var udiType    = ObjectTypes.GetUdiType(objectType);

            var relations = _relationService.GetPagedParentEntitiesByChildId(id, pageNumber - 1, pageSize, out var totalRecords, objectType);

            return(new PagedResult <EntityBasic>(totalRecords, pageNumber, pageSize)
            {
                Items = relations.Cast <ContentEntitySlim>().Select(rel => new EntityBasic
                {
                    Id = rel.Id,
                    Key = rel.Key,
                    Udi = Udi.Create(udiType, rel.Key),
                    Icon = rel.ContentTypeIcon,
                    Name = rel.Name,
                    Alias = rel.ContentTypeAlias
                })
            });
        }
Пример #30
0
        public IEnumerable <DataListItem> GetItems(Dictionary <string, object> config)
        {
            DataListItem mapMember(IMember member)
            {
                var guidUdi = Udi.Create(UmbConstants.UdiEntityType.Member, member.Key).ToString();

                return(new DataListItem
                {
                    Name = member.Name,
                    Value = guidUdi,
                    Icon = member.ContentType.Icon ?? UmbConstants.Icons.Member,
                    Description = guidUdi,
                });
            };

            if (config.TryGetValueAs("memberType", out JArray array) == true &&
                array.Count > 0 &&
                array[0].Value <string>() is string str &&
                string.IsNullOrWhiteSpace(str) == false &&
                GuidUdi.TryParse(str, out var udi) == true)
            {
                var memberType = _memberTypeService.Get(udi.Guid);
                if (memberType != null)
                {
                    return(_memberService.GetMembersByMemberType(memberType.Id).Select(mapMember));
                }
            }