public string ComputeReplacement(Match matchResult) { var uri = matchResult.Value; var item = _context.Content.GetById(Udi.Parse(uri)); return(item.Url().Trim("/") + ".json"); }
private string GetCategoryUdis(IEnumerable <string> categoryInput) { categoryInput = categoryInput.Select(i => i.ToUpper()); return(string.Join(",", Home.Descendants <CategoryPage>() .Where(c => categoryInput.Contains(c.Name.ToUpper())) .Select(c => Udi.Create(Constants.UdiEntityType.Document, c.Key).ToString()))); }
public IPublishedContent Content(Udi id) { if (!(id is GuidUdi udi)) { return(null); } return(ItemById(udi.Guid, _publishedSnapshot.Content)); }
public IPublishedContent Content(Udi id) { if (!(id is GuidUdi udi)) { return(null); } return(ItemById(udi.Guid, _contentCache)); }
// Umbraco.Code.MapAll -Icon -Trashed -ParentId -Alias private void Map(IMemberGroup source, MemberGroupDisplay target, MapperContext context) { target.Id = source.Id; target.Key = source.Key; target.Name = source.Name; target.Path = "-1" + source.Id; target.Udi = Udi.Create(Constants.UdiEntityType.MemberGroup, source.Key); }
protected ArtifactBase(TUdi udi, IEnumerable <ArtifactDependency> dependencies = null) { Udi = udi ?? throw new ArgumentNullException("udi"); Name = Udi.ToString(); Dependencies = dependencies ?? Enumerable.Empty <ArtifactDependency>(); _checksum = new Lazy <string>(GetChecksum); }
public ElementsImage(IPublishedContent media, int width, int height) { Id = media.Id; Key = media.Key; Udi = Udi.Create("media", media.Key); Name = media.Name; Thumbnail = media.GetCropUrl(width, height, preferFocalPoint: true); }
/// <summary> /// Helper method to create tree nodes and automatically generate the json url + UDI /// </summary> /// <param name="entity"></param> /// <param name="entityObjectType"></param> /// <param name="parentId"></param> /// <param name="queryStrings"></param> /// <param name="hasChildren"></param> /// <returns></returns> public TreeNode CreateTreeNode(UmbracoEntity entity, Guid entityObjectType, string parentId, FormDataCollection queryStrings, bool hasChildren) { var treeNode = CreateTreeNode(entity.Id.ToInvariantString(), parentId, queryStrings, entity.Name, entity.ContentTypeIcon); treeNode.Udi = Udi.Create(UmbracoObjectTypesExtensions.GetUdiType(entityObjectType), entity.Key); treeNode.HasChildren = hasChildren; return(treeNode); }
public void GetAllReferences_Invariant_With_IDataValueReference_Editor() { var collection = new DataValueReferenceFactoryCollection(Enumerable.Empty <IDataValueReferenceFactory>()); // mediaPicker does implement IDataValueReference var mediaPicker = new MediaPickerPropertyEditor(Mock.Of <ILogger>()); var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(mediaPicker.Yield())); var trackedUdi1 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi2 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi3 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi4 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var property = new Property(new PropertyType(new DataType(mediaPicker)) { Variations = ContentVariation.Nothing | ContentVariation.Segment }) { Values = new List <PropertyValue> { new PropertyValue { EditedValue = trackedUdi1 }, // Ignored (has culture) new PropertyValue { Culture = "en-US", EditedValue = trackedUdi2 }, // Ignored (has culture) new PropertyValue { Culture = "en-US", Segment = "A", EditedValue = trackedUdi3 }, new PropertyValue { Segment = "A", EditedValue = trackedUdi4 }, // duplicate new PropertyValue { Segment = "B", EditedValue = trackedUdi4 } } }; var properties = new PropertyCollection { property }; var result = collection.GetAllReferences(properties, propertyEditors); Assert.AreEqual(2, result.Count()); Assert.AreEqual(trackedUdi1, result.ElementAt(0).Udi.ToString()); Assert.AreEqual(trackedUdi4, result.ElementAt(1).Udi.ToString()); }
/// <summary> /// Helper method to create tree nodes and automatically generate the json URL + UDI /// </summary> /// <param name="entity"></param> /// <param name="entityObjectType"></param> /// <param name="parentId"></param> /// <param name="queryStrings"></param> /// <param name="icon"></param> /// <param name="hasChildren"></param> /// <returns></returns> public TreeNode CreateTreeNode(IUmbracoEntity entity, Guid entityObjectType, string parentId, FormCollection queryStrings, string icon, bool hasChildren) { TreeNode treeNode = CreateTreeNode(entity.Id.ToInvariantString(), parentId, queryStrings, entity.Name, icon); treeNode.Udi = Udi.Create(ObjectTypes.GetUdiType(entityObjectType), entity.Key); treeNode.Path = entity.Path; treeNode.HasChildren = hasChildren; return(treeNode); }
protected TreeNode GetSingleTreeNode(string id, FormDataCollection queryStrings) { if (_isUmbracoProvider) { Guid asGuid; if (Guid.TryParse(id, out asGuid) == false) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } var member = Services.MemberService.GetByKey(asGuid); if (member == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } var node = CreateTreeNode( member.Key.ToString("N"), "-1", queryStrings, member.Name, "icon-user", false, "", Udi.Create(ObjectTypes.GetUdiType(Constants.ObjectTypes.Member), member.Key)); node.AdditionalData.Add("contentType", member.ContentTypeAlias); node.AdditionalData.Add("isContainer", true); return(node); } else { object providerId = id; Guid asGuid; if (Guid.TryParse(id, out asGuid)) { providerId = asGuid; } var member = _provider.GetUser(providerId, false); if (member == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } var node = CreateTreeNode( member.ProviderUserKey.TryConvertTo <Guid>().Result.ToString("N"), "-1", queryStrings, member.UserName, "icon-user", false); return(node); } }
private void AppendPath(StringBuilder sb, UmbracoObjectTypes objectType, int[] startNodeIds, string searchFrom, bool ignoreUserStartNodes, IEntityService entityService) { if (sb == null) { throw new ArgumentNullException("sb"); } if (entityService == null) { throw new ArgumentNullException("entityService"); } Udi udi; Udi.TryParse(searchFrom, true, out udi); searchFrom = udi == null ? searchFrom : entityService.GetIdForUdi(udi).Result.ToString(); int searchFromId; var entityPath = int.TryParse(searchFrom, out searchFromId) && searchFromId > 0 ? entityService.GetAllPaths(objectType, searchFromId).FirstOrDefault() : null; if (entityPath != null) { // find... only what's underneath sb.Append("+__Path:"); AppendPath(sb, entityPath.Path, false); sb.Append(" "); } else if (startNodeIds.Length == 0) { // make sure we don't find anything sb.Append("+__Path:none "); } else if (startNodeIds.Contains(-1) == false && ignoreUserStartNodes == false) // -1 = no restriction { var entityPaths = entityService.GetAllPaths(objectType, startNodeIds); // for each start node, find the start node, and what's underneath // +__Path:(-1*,1234 -1*,1234,* -1*,5678 -1*,5678,* ...) sb.Append("+__Path:("); var first = true; foreach (var ep in entityPaths) { if (first) { first = false; } else { sb.Append(" "); } AppendPath(sb, ep.Path, true); } sb.Append(") "); } }
public PagedResult <ContentItemBasic <ContentPropertyBasic> > GetChildren(Udi id, int pageNumber = 0, int pageSize = 0, string orderBy = "SortOrder", Direction orderDirection = Direction.Ascending, bool orderBySystemField = true, string filter = "") { return(GetChildren(id, ignoreUserStartNodes: false, pageNumber, pageSize, orderBy, orderDirection, orderBySystemField, filter)); }
protected override void AddSingleValue(Document doc, object value) { if (value is string valueString) { if (Udi.TryParse(valueString, out Udi udi) == true) { doc.Add(new Field(FieldName, udi.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); } } }
public MediaItemDisplay GetById(Udi id) { var guidUdi = id as GuidUdi; if (guidUdi != null) { return(GetById(guidUdi.Guid)); } throw new HttpResponseException(HttpStatusCode.NotFound); }
/// <summary> /// Gets an entity by it's UDI /// </summary> /// <param name="id"></param> /// <param name="type"></param> /// <returns></returns> public EntityBasic GetById(Udi id, UmbracoEntityTypes type) { var guidUdi = id as GuidUdi; if (guidUdi != null) { return(GetResultForKey(guidUdi.Guid, type)); } throw new HttpResponseException(HttpStatusCode.NotFound); }
/// <summary> /// Helper method to create tree nodes and automatically generate the json url + UDI /// </summary> /// <param name="entity"></param> /// <param name="entityObjectType"></param> /// <param name="parentId"></param> /// <param name="queryStrings"></param> /// <param name="hasChildren"></param> /// <returns></returns> public TreeNode CreateTreeNode(IEntitySlim entity, Guid entityObjectType, string parentId, FormDataCollection queryStrings, bool hasChildren) { var contentTypeIcon = entity is IContentEntitySlim contentEntity ? contentEntity.ContentTypeIcon : null; var treeNode = CreateTreeNode(entity.Id.ToInvariantString(), parentId, queryStrings, entity.Name, contentTypeIcon); treeNode.Path = entity.Path; treeNode.Udi = Udi.Create(ObjectTypes.GetUdiType(entityObjectType), entity.Key); treeNode.HasChildren = hasChildren; return(treeNode); }
/// <summary> /// Gets the Url for a given node ID /// </summary> /// <param name="id"></param> /// <returns></returns> public HttpResponseMessage GetNiceUrl(Udi id) { var guidUdi = id as GuidUdi; if (guidUdi != null) { return(GetNiceUrl(guidUdi.Guid)); } throw new HttpResponseException(HttpStatusCode.NotFound); }
/// <summary> /// Gets the path for a given node ID /// </summary> /// <param name="id"></param> /// <param name="type"></param> /// <returns></returns> public IEnumerable <int> GetPath(Udi id, UmbracoEntityTypes type) { var guidUdi = id as GuidUdi; if (guidUdi != null) { return(GetPath(guidUdi.Guid, type)); } throw new HttpResponseException(HttpStatusCode.NotFound); }
// TODO: Replace mediaCache with media url provider internal static string ParseInternalLinks(string text, UrlProvider urlProvider, IPublishedMediaCache mediaCache) { if (urlProvider == null) { throw new ArgumentNullException(nameof(urlProvider)); } if (mediaCache == null) { throw new ArgumentNullException(nameof(mediaCache)); } // Parse internal links var tags = LocalLinkPattern.Matches(text); foreach (Match tag in tags) { if (tag.Groups.Count > 0) { var id = tag.Groups[1].Value; //.Remove(tag.Groups[1].Value.Length - 1, 1); //The id could be an int or a UDI if (Udi.TryParse(id, out var udi)) { var guidUdi = udi as GuidUdi; if (guidUdi != null) { var newLink = "#"; if (guidUdi.EntityType == Constants.UdiEntityType.Document) { newLink = urlProvider.GetUrl(guidUdi.Guid); } else if (guidUdi.EntityType == Constants.UdiEntityType.Media) { newLink = mediaCache.GetById(guidUdi.Guid)?.Url; } if (newLink == null) { newLink = "#"; } text = text.Replace(tag.Value, "href=\"" + newLink); } } if (int.TryParse(id, out var intId)) { var newLink = urlProvider.GetUrl(intId); text = text.Replace(tag.Value, "href=\"" + newLink); } } } return(text); }
public string GenerateItemHtml(Udi udi) { var id = GetItemId(udi); if (id > 0) { return(GenerateItemHtml(id)); } return("Item not found"); }
public ActionResult <MediaItemDisplay> GetById(Udi id) { var guidUdi = id as GuidUdi; if (guidUdi != null) { return(GetById(guidUdi.Guid)); } return(NotFound()); }
// Umbraco.Code.MapAll -Trashed -AdditionalData private static void Map(IMacro source, EntityBasic target, MapperContext context) { target.Alias = source.Alias; target.Icon = Constants.Icons.Macro; target.Id = source.Id; target.Key = source.Key; target.Name = source.Name; target.ParentId = -1; target.Path = "-1," + source.Id; target.Udi = Udi.Create(Constants.UdiEntityType.Macro, source.Key); }
// Umbraco.Code.MapAll -Trashed private static void Map(ITemplate source, EntityBasic target, MapperContext context) { target.Alias = source.Alias; target.Icon = "icon-layout"; target.Id = source.Id; target.Key = source.Key; target.Name = source.Name; target.ParentId = -1; target.Path = source.Path; target.Udi = Udi.Create(Constants.UdiEntityType.Template, source.Key); }
public void CreateTest() { var guid = Guid.NewGuid(); var udi = Udi.Create(Constants.UdiEntityType.AnyGuid, guid); Assert.AreEqual(Constants.UdiEntityType.AnyGuid, udi.EntityType); Assert.AreEqual(guid, ((GuidUdi)udi).Guid); // *not* testing whether Udi.Create(type, invalidValue) throws // because we don't throw anymore - see U4-10409 }
/// <summary> /// UDIs are required for setting picker content values, etc. in ContentService, and /// many other places, since numeric content Ids are being phased out. This method gets the /// UDI for a single IPublishedContent object. /// </summary> /// <param name="content">The current IPublishedContent content object</param> /// <returns>UDI (e.g. "umb://document/28b551d1e9e74c758686604c9168b910")</returns> public static string GetUdi(this IPublishedContent content) { if (content != null) { return(Udi.Create(UdiEntityType.Document, content.GetKey()).ToString()); } else { return(""); } }
public void StringEntityParseTest() { var udi = Udi.Parse("umb://" + Constants.UdiEntityType.AnyString + "/test-id"); Assert.AreEqual(Constants.UdiEntityType.AnyString, udi.EntityType); Assert.IsInstanceOf <StringUdi>(udi); var stringEntityId = udi as StringUdi; Assert.IsNotNull(stringEntityId); Assert.AreEqual("test-id", stringEntityId.Id); Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/test-id", udi.ToString()); }
public dynamic GetAddressByUdi(string udi) { var umbracoHelper = new UmbracoHelper(UmbracoContext); string venueStringUdi = HttpUtility.UrlDecode(udi); Udi venueUdi = Udi.Parse(venueStringUdi); IPublishedContent venueNode = umbracoHelper.TypedContent(venueUdi); string venueAddress = venueNode.GetPropertyValue <string>("address"); return(new { value = venueAddress }); }
public void SetUp() { // fixme - bad in a unit test - but Udi has a static ctor that wants it?! var container = new Mock <IFactory>(); var globalSettings = SettingsForTests.GenerateMockGlobalSettings(); container.Setup(x => x.GetInstance(typeof(TypeLoader))).Returns( new TypeLoader(NullCacheProvider.Instance, LocalTempStorage.Default, new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()))); Current.Factory = container.Object; Udi.ResetUdiTypes(); }
public static IMedia CreateMedia(this IMediaService mediaService, string name, Udi parentId, string mediaTypeAlias, int userId = 0) { if (parentId is not GuidUdi guidUdi) { throw new InvalidOperationException("The UDI provided isn't of type " + typeof(GuidUdi) + " which is required by media"); } IMedia?parent = mediaService.GetById(guidUdi.Guid); return(mediaService.CreateMedia(name, parent, mediaTypeAlias, userId)); }