private void buildIndexTables(IEnumerable<ITag> originalRootTags, TagUserAuthorizations auths) { //Search for visible tags and authorized photos Dictionary<string, IPhoto> authorizedPhotos = new Dictionary<string, IPhoto>(); List<ITag> authorizedTags = getAuthorizedTags(originalRootTags, auths).ToList(); HashSet<ITag> visibleTags = new HashSet<ITag>(); foreach (var tag in authorizedTags) { foreach (var photo in tag.Photos) { //even not directly authorized tags can be traversed or can reference authorized photo. //We register them, but not theirs photos. photo.Tags .ForEach(t => getTagsHierarchy(t) .ForEach(t2 => visibleTags.Add(t2))); //Register photos from a directly authorized tag. authorizedPhotos[photo.Id] = photo; } } //root tags this.rootTags = (from rootTag in originalRootTags.Intersect(visibleTags) select new InternalTag(rootTag, authorizedTags, visibleTags, null)).ToList(); //tag index tags = new Dictionary<string, InternalTag>(); foreach (var rootTag in rootTags) { tags[rootTag.Id] = rootTag; foreach(var subTag in rootTag.AllTags) tags[subTag.Id] = subTag; } //Order photo in a timeline list. var tempTimeline = new List<IPhoto>(authorizedPhotos.Values); tempTimeline.Sort((p1, p2) => p2.Date.CompareTo(p1.Date)); timelinePhotos = new LinkedList<IPhoto>(tempTimeline); //day index for timeline. photosByDays = new Dictionary<DateTime, LinkedListNode<IPhoto>>(); for (var item = timelinePhotos.First; item != null; item = item.Next) if (item == timelinePhotos.First || item.Previous.Value.Date.Date != item.Value.Date.Date) photosByDays[item.Value.Date.Date] = item; //photo ids index for timeline. photosByIds = new Dictionary<string, LinkedListNode<IPhoto>>(); for (var item = timelinePhotos.First; item != null; item = item.Next) photosByIds[item.Value.Id] = item; }
private IEnumerable<ITag> getAuthorizedTags(IEnumerable<ITag> originalRootTags, TagUserAuthorizations auths) { return from tagId in auths.GetTags(user) select getTagById(originalRootTags, tagId); }
public UserPhotoLibrary(string user, IEnumerable<ITag> originalRootTags, TagUserAuthorizations auths) { this.user = user; buildIndexTables(originalRootTags, auths); }
private void initAuthorizations() { var allTags = getAllTags(rootTags).ToList(); Func<string, bool> tagExists = (id) => allTags.Any(t => t.Id == id); var oldData = ConfigurationClient.Get<TagUserAuthorizations>( confNamespace, confTagUserAuthorizationsKey, null); tagUserAuthorizations = new TagUserAuthorizations(oldData, tagExists); //save it again : can be updated regarding current provider and available tags. saveAuthorizations(); }