예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <summary>
        /// Gets the group ressources.
        /// </summary>
        /// <typeparam name="TRessource">
        /// The type of the ressource.
        /// </typeparam>
        /// <param name="groupNamespaceRessource">
        /// The group namespace ressource.
        /// </param>
        /// <param name="getChildNamespace">
        /// get child namespace
        /// </param>
        /// <returns>
        /// </returns>
        public override IRessourceGroup <TRessource> GetGroupRessources <TRessource>(Namespace groupNamespaceRessource, bool getChildNamespace)
        {
            if (groupNamespaceRessource == null)
            {
                throw new ArgumentNullException(nameof(groupNamespaceRessource));
            }

            this._CheckInit();
            var ressources = new IdentifiableList <TRessource>();

            using (var reader = XmlReader.Create(this._streamSource.GetStream(), this._getReadingPermformenceSettings()))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        if (reader.LocalName == XD.ELEMENT_RESSOURCE)
                        {
                            var idattr = new Identity(reader.GetAttribute(XD.ATTRIBUTE_ID));
                            var test   = getChildNamespace ?
                                         groupNamespaceRessource.InNamespace(idattr.Namespace) : idattr.Namespace == groupNamespaceRessource;
                            if (test)
                            {
                                var typeattr = reader.GetAttribute(XD.ATTRIBUTE_TYPE);
                                if (typeattr == typeof(TRessource).FullName)
                                {
                                    var subreader = reader.ReadSubtree();
                                    while (subreader.ReadToFollowing(XD.ELEMENT_VALUE, XD.NAMESPACE))
                                    {
                                        var lang = subreader.GetAttribute(XD.ATTRIBUTE_LANG);
                                        if (lang == this.Culture.TwoLetterISOLanguageName)
                                        {
                                            var ressource = new TRessource();
                                            ressource.SetId(idattr);
                                            ressource.UnSerialize(subreader, new XmlContext(XD.NAMESPACE, XD.PREFIX));
                                            ressources.Add(ressource);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == XD.ELEMENT_RESSOURCES)
                    {
                        break;
                    }
                }
            }
            if (ressources.Count > 0)
            {
                return(new RessourceGroup <TRessource>(groupNamespaceRessource.ToString(), this.Culture, ressources));
            }
            else
            {
                return(default);
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RessourceGroup{TRessource}" /> class.
 /// </summary>
 /// <param name="id">
 /// The identifier.
 /// </param>
 /// <param name="culture">
 /// The culture.
 /// </param>
 /// <param name="ressources">
 /// The ressources.
 /// </param>
 public RessourceGroup(Identity id, CultureInfo culture, IdentifiableList <TRessource> ressources)
 {
     this._id         = id ?? throw new ArgumentNullException(nameof(id));
     this._culture    = culture ?? throw new ArgumentNullException(nameof(culture));
     this._ressources = ressources ?? throw new ArgumentNullException(nameof(ressources));
 }