Exemple #1
0
        /// <summary>
        /// Parses a XML node that contains information about a web node.
        /// </summary>
        /// <param name="node">A XML node containing the data to parse.</param>
        /// <param name="nodes">A <see cref="DictionaryValue"/> containing the collection of
        /// configuration nodes.</param>
        /// <remarks>
        /// The <paramref name="nodes"/> is used to store the nodes that is parsed by this class.
        /// </remarks>
        public void Parse(XmlNode node, DictionaryValue nodes) {
            XmlNode xml_web_node;
            DictionaryValue<ContentGroupNode> content_groups;

            if (GetNode<ContentGroupNode>(NohrosConfiguration.kContentGroupsNodeName
                    ,NohrosConfiguration.kContentGroupNodeTree
                    ,nodes
                    ,node
                    ,out xml_web_node
                    ,out content_groups)) {

                DictionaryValue<RepositoryNode> repositories =
                    (DictionaryValue <RepositoryNode>)nodes[NohrosConfiguration.kRepositoryNodeTree];

                foreach (XmlNode n in xml_web_node.ChildNodes) {
                    if (string.Compare(n.Name, "group", StringComparison.OrdinalIgnoreCase) == 0) {
                        string name;
                        if (!GetAttributeValue(n, "name", out name))
                            Thrower.ThrowConfigurationException("[Parse   Nohros.Configuration.WebNode]",
                                string.Format(StringResources.Config_MissingAt, "name",
                                NohrosConfiguration.kContentGroupNodeTree));

                        ContentGroupNode content_group = new ContentGroupNode(name);
                        content_group.Parse(n, repositories);
                        content_groups[ContentGroupKey(content_group.Name,
                            (content_group.BuildType == BuildType.Release) ?
                                "release" : "build", content_group.MimeType)] = content_group;
                    }
                }
            }
        }
        private FileCacheItem UpdateFileCache(ContentGroupNode content_group, string cache_key)
        {
            CacheDependency cd;
            StringBuilder merged = new StringBuilder();
            List<string> merged_files = new List<string>(content_group.Files.Count);

			// the embedded resource must be readed from the resource assembly.
			Assembly assembly = Assembly.GetExecutingAssembly();

            foreach (string file_name in content_group.Files) {
                string file_path = Path.Combine(content_group.BasePath, file_name);

                // sanity check file existence
                if (File.Exists(file_path)) {
                    using (StreamReader stream = new StreamReader(file_path)) {
                        string content = stream.ReadToEnd().Trim();
                        if (content.Length > 0) {
                            merged.Append(content).Append("\r\n");
                            merged_files.Add(file_path);
                        }
                        stream.Close();
                    }
                }
            }

            if (merged.Length > 0) {
                FileCacheItem ci = new FileCacheItem(merged.ToString());

                // add the the application configuration file to the CacheDependency
                merged_files.Add(Utility.BaseDirectory + "web.config");
                cd = new CacheDependency(merged_files.ToArray());

                // Store the FileCacheItem in cache w/ a dependency on the merged files changing
                context_.Cache.Insert(cache_key, ci, cd);

                return ci;
            }

            return null;
        }
Exemple #3
0
        /// <summary>
        /// Parses a XML node that contains information about a web node.
        /// </summary>
        /// <param name="node">A XML node containing the data to parse.</param>
        /// <param name="nodes">A <see cref="DictionaryValue"/> containing the collection of
        /// configuration nodes.</param>
        /// <remarks>
        /// The <paramref name="nodes"/> is used to store the nodes that is parsed by this class.
        /// </remarks>
        public void Parse(XmlNode node, DictionaryValue nodes)
        {
            XmlNode xml_web_node;
            DictionaryValue <ContentGroupNode> content_groups;

            if (GetNode <ContentGroupNode>(NohrosConfiguration.kContentGroupsNodeName
                                           , NohrosConfiguration.kContentGroupNodeTree
                                           , nodes
                                           , node
                                           , out xml_web_node
                                           , out content_groups))
            {
                DictionaryValue <RepositoryNode> repositories =
                    (DictionaryValue <RepositoryNode>)nodes[NohrosConfiguration.kRepositoryNodeTree];

                foreach (XmlNode n in xml_web_node.ChildNodes)
                {
                    if (string.Compare(n.Name, "group", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        string name;
                        if (!GetAttributeValue(n, "name", out name))
                        {
                            Thrower.ThrowConfigurationException("[Parse   Nohros.Configuration.WebNode]",
                                                                string.Format(StringResources.Config_MissingAt, "name",
                                                                              NohrosConfiguration.kContentGroupNodeTree));
                        }

                        ContentGroupNode content_group = new ContentGroupNode(name);
                        content_group.Parse(n, repositories);
                        content_groups[ContentGroupKey(content_group.Name,
                                                       (content_group.BuildType == BuildType.Release) ?
                                                       "release" : "build", content_group.MimeType)] = content_group;
                    }
                }
            }
        }