コード例 #1
0
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            XPathExpression artIdExpression   = XPathExpression.Compile("string(@id)"),
                            artFileExpression = XPathExpression.Compile("string(image/@file)"),
                            artTextExpression = XPathExpression.Compile("string(image/altText)");

            XPathNodeIterator targetsNodes = configuration.Select("targets");

            foreach (XPathNavigator targetsNode in targetsNodes)
            {
                // Get the configuration values for this target
                string inputPath = targetsNode.GetAttribute("input", String.Empty);

                if (String.IsNullOrEmpty(inputPath))
                {
                    this.WriteMessage(MessageLevel.Error, "Each targets element must have an input attribute " +
                                      "specifying a directory containing art files.");
                }

                inputPath = Environment.ExpandEnvironmentVariables(inputPath);

                if (!Directory.Exists(inputPath))
                {
                    this.WriteMessage(MessageLevel.Error, "The art input directory '{0}' does not exist.",
                                      inputPath);
                }

                string baseOutputPath = targetsNode.GetAttribute("baseOutput", String.Empty);

                if (!String.IsNullOrEmpty(baseOutputPath))
                {
                    baseOutputPath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(baseOutputPath));
                }

                string outputPathValue = targetsNode.GetAttribute("outputPath", String.Empty);

                if (String.IsNullOrEmpty(outputPathValue))
                {
                    this.WriteMessage(MessageLevel.Error, "Each targets element must have an output attribute " +
                                      "specifying a directory in which to place referenced art files.");
                }

                XPathExpression outputXPath = XPathExpression.Compile(outputPathValue);

                string linkPath = targetsNode.GetAttribute("link", String.Empty);

                if (String.IsNullOrEmpty(linkPath))
                {
                    linkPath = "../art";
                }

                string map = targetsNode.GetAttribute("map", String.Empty);

                if (String.IsNullOrEmpty(map))
                {
                    this.WriteMessage(MessageLevel.Error, "Each targets element must have a map attribute " +
                                      "specifying a file that maps art IDs to files in the input directory.");
                }

                map = Environment.ExpandEnvironmentVariables(map);

                if (!File.Exists(map))
                {
                    this.WriteMessage(MessageLevel.Error, "The art map file '{0}' does not exist.", map);
                }

                string format = targetsNode.GetAttribute("format", String.Empty);

                XPathExpression formatXPath = String.IsNullOrEmpty(format) ? null :
                                              XPathExpression.Compile(format);

                string relativeTo = targetsNode.GetAttribute("relative-to", String.Empty);

                XPathExpression relativeToXPath = String.IsNullOrEmpty(relativeTo) ? null :
                                                  XPathExpression.Compile(relativeTo);

                // Load the content of the media map file
                using (var reader = XmlReader.Create(map, new XmlReaderSettings {
                    CloseInput = true
                }))
                {
                    XPathDocument     mediaMap = new XPathDocument(reader);
                    XPathNodeIterator items    = mediaMap.CreateNavigator().Select("/*/item");

                    foreach (XPathNavigator item in items)
                    {
                        string id   = (string)item.Evaluate(artIdExpression);
                        string file = (string)item.Evaluate(artFileExpression);
                        string text = (string)item.Evaluate(artTextExpression);
                        string name = Path.GetFileName(file);

                        targets[id] = new ArtTarget
                        {
                            Id              = id,
                            InputPath       = Path.Combine(inputPath, file),
                            BaseOutputPath  = baseOutputPath,
                            OutputXPath     = outputXPath,
                            LinkPath        = String.IsNullOrEmpty(name) ? linkPath : String.Concat(linkPath, "/", name),
                            Text            = text,
                            Name            = name,
                            FormatXPath     = formatXPath,
                            RelativeToXPath = relativeToXPath
                        };
                    }
                }
            }

            this.WriteMessage(MessageLevel.Info, "Indexed {0} art targets.", targets.Count);
        }
コード例 #2
0
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            XPathExpression artIdExpression = XPathExpression.Compile("string(@id)"),
                artFileExpression = XPathExpression.Compile("string(image/@file)"),
                artTextExpression = XPathExpression.Compile("string(image/altText)");

            XPathNodeIterator targetsNodes = configuration.Select("targets");

            foreach(XPathNavigator targetsNode in targetsNodes)
            {
                // Get the configuration values for this target
                string inputPath = targetsNode.GetAttribute("input", String.Empty);

                if(String.IsNullOrEmpty(inputPath))
                    base.WriteMessage(MessageLevel.Error, "Each targets element must have an input attribute " +
                        "specifying a directory containing art files.");

                inputPath = Environment.ExpandEnvironmentVariables(inputPath);

                if(!Directory.Exists(inputPath))
                    base.WriteMessage(MessageLevel.Error, "The art input directory '{0}' does not exist.",
                        inputPath);

                string baseOutputPath = targetsNode.GetAttribute("baseOutput", String.Empty);

                if(!String.IsNullOrEmpty(baseOutputPath))
                    baseOutputPath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(baseOutputPath));

                string outputPathValue = targetsNode.GetAttribute("outputPath", string.Empty);

                if(string.IsNullOrEmpty(outputPathValue))
                    base.WriteMessage(MessageLevel.Error, "Each targets element must have an output attribute " +
                        "specifying a directory in which to place referenced art files.");

                XPathExpression outputXPath = XPathExpression.Compile(outputPathValue);

                string linkPath = targetsNode.GetAttribute("link", String.Empty);

                if(String.IsNullOrEmpty(linkPath))
                    linkPath = "../art";

                string map = targetsNode.GetAttribute("map", String.Empty);

                if(String.IsNullOrEmpty(map))
                    base.WriteMessage(MessageLevel.Error, "Each targets element must have a map attribute " +
                        "specifying a file that maps art IDs to files in the input directory.");

                map = Environment.ExpandEnvironmentVariables(map);

                if(!File.Exists(map))
                    base.WriteMessage(MessageLevel.Error, "The art map file '{0}' does not exist.", map);

                string format = targetsNode.GetAttribute("format", String.Empty);

                XPathExpression formatXPath = String.IsNullOrEmpty(format) ? null :
                    XPathExpression.Compile(format);

                string relativeTo = targetsNode.GetAttribute("relative-to", String.Empty);

                XPathExpression relativeToXPath = String.IsNullOrEmpty(relativeTo) ? null :
                    XPathExpression.Compile(relativeTo);

                // Load the content of the media map file
                XPathDocument mediaMap = new XPathDocument(map);
                XPathNodeIterator items = mediaMap.CreateNavigator().Select("/*/item");

                foreach(XPathNavigator item in items)
                {
                    string id = (string)item.Evaluate(artIdExpression);
                    string file = (string)item.Evaluate(artFileExpression);
                    string text = (string)item.Evaluate(artTextExpression);
                    string name = Path.GetFileName(file);

                    targets[id] = new ArtTarget
                    {
                        InputPath = Path.Combine(inputPath, file),
                        BaseOutputPath = baseOutputPath,
                        OutputXPath = outputXPath,
                        LinkPath = String.IsNullOrEmpty(name) ? linkPath : String.Concat(linkPath, "/", name),
                        Text = text,
                        Name = name,
                        FormatXPath = formatXPath,
                        RelativeToXPath = relativeToXPath
                    };
                }
            }

            base.WriteMessage(MessageLevel.Info, "Indexed {0} art targets.", targets.Count);
        }