/// <summary> /// Gets the group ressource. /// </summary> /// <typeparam name="TRessource"> /// The type of the ressource. /// </typeparam> /// <param name="groupRessourceId"> /// The group ressource identifier. /// </param> /// <returns> /// </returns> public IRessourceGroup <TRessource> GetGroupRessources <TRessource>(Identity groupRessourceId) where TRessource : class, IRessource, new() { var grpInfo = new RessourceGroupInformation(groupRessourceId, typeof(TRessource)); var lst = new IdentifiableList <TRessource>(); lst.AddRange(this.GetRessourceFromGroupInternal <TRessource>(groupRessourceId)); if (this._groupesRessources.ContainsKey(grpInfo)) { if (this._ressources.ContainsKey(typeof(TRessource))) { foreach (var item in this._groupesRessources[grpInfo]) { if (this._ressources[typeof(TRessource)].Contains(item.Id)) { lst.Add((TRessource)this._ressources[typeof(TRessource)][item.Id]); } } } foreach (var id in this._groupesRessources[grpInfo].RemovedElement) { lst.Remove(id); } } if (lst.Count > 0) { return(new RessourceGroup <TRessource>(groupRessourceId, this.Culture, lst)); } return(null); }
/// <summary> /// Detaches the ressource to group. /// </summary> ///<param name="ressource">ressource</param> /// <param name="groupRessourceId">The group ressource identifier.</param> public void DetachRessourceToGroup <TRessource>(TRessource ressource, Identity groupRessourceId) where TRessource : class, IRessource { if (ressource == null) { throw new ArgumentNullException(nameof(ressource)); } if (ressource.IsEmptyRessource) { throw new InvalidOperationException("You not be use a empty Ressource"); } var grp = new RessourceGroupInformation(groupRessourceId, typeof(TRessource)); if (!this._groupesRessources.ContainsKey(grp)) { this._groupesRessources.Add(grp, new IdentifiableList <IdentityContainer>()); } this._groupesRessources[grp].Remove(ressource.Id); }
/// <summary> /// Attaches the ressource to group. /// </summary> /// <typeparam name="TRessource"> /// The type of the ressource. /// </typeparam> /// <param name="ressource"> /// The ressource. /// </param> /// <param name="groupRessourceId"> /// The group ressource identifier. /// </param> /// <exception cref="ArgumentNullException"> /// ressourceId or groupRessourceId /// </exception> public void AttachRessourceToGroup <TRessource>(TRessource ressource, Identity groupRessourceId) where TRessource : class, IRessource { if (ressource == null) { throw new ArgumentNullException(nameof(ressource)); } if (groupRessourceId == null) { throw new ArgumentNullException(nameof(groupRessourceId)); } if (ressource.IsEmptyRessource) { throw new InvalidOperationException("You not be use a empty Ressource"); } if (this.Logger.InfoIsEnabled) { this.Logger.Info($"Attach Ressource {ressource.Id} to group {groupRessourceId} in culture {this.Culture}"); } var grpInfo = new RessourceGroupInformation(groupRessourceId, typeof(TRessource)); if (this.ContainsRessource <TRessource>(ressource.Id)) { if (!this._groupesRessources.ContainsKey(grpInfo)) { this._groupesRessources.Add(grpInfo, new IdentifiableList <IdentityContainer>()); } this._groupesRessources[grpInfo].Add(new IdentityContainer(ressource.Id)); } else { throw new InvalidOperationException($"The Ressource {ressource} is not valid for this RessourceManager."); } }