Exemplo n.º 1
0
        internal void Validate(OutputItem item)
        {
            if (this.encoding != null && !object.Equals(item.Encoding, this.Encoding))
            {
                throw this.PropertyDiscrepancyException("Encoding", item.Encoding.EncodingName, this.Encoding.EncodingName);
            }

            if (this.itemType != null && !string.Equals(item.ItemType, this.ItemType, StringComparison.OrdinalIgnoreCase))
            {
                throw this.PropertyDiscrepancyException("ItemType", item.ItemType, this.ItemType);
            }

            foreach (KeyValuePair <string, string> metadata in item.Metadata)
            {
                string previousValue;
                bool   metadataExists = this.Metadata.TryGetValue(metadata.Key, out previousValue);
                if (metadataExists && metadata.Value != previousValue)
                {
                    throw this.PropertyDiscrepancyException(
                              string.Format(CultureInfo.InvariantCulture, "Metadata '{0}'", metadata.Key),
                              metadata.Value,
                              previousValue);
                }
            }

            if (item.PreserveExistingFile != this.PreserveExistingFile)
            {
                throw this.PropertyDiscrepancyException("PreserveExistingFile", item.PreserveExistingFile.ToString(), this.PreserveExistingFile.ToString());
            }
        }
Exemplo n.º 2
0
        internal void CopyPropertiesFrom(OutputItem item)
        {
            this.File                 = item.File;
            this.Directory            = item.Directory;
            this.Project              = item.Project;
            this.Encoding             = item.Encoding;
            this.ItemType             = item.ItemType;
            this.PreserveExistingFile = item.PreserveExistingFile;

            foreach (string reference in item.References)
            {
                if (!this.References.Contains(reference))
                {
                    this.References.Add(reference);
                }
            }

            foreach (KeyValuePair <string, string> metadata in item.Metadata)
            {
                if (!this.Metadata.ContainsKey(metadata.Key))
                {
                    this.Metadata.Add(metadata.Key, metadata.Value);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes text to the output of this transformation.
        /// </summary>
        /// <param name="output">An <see cref="OutputItem"/> object that specifies how the text must be saved.</param>
        /// <param name="text">A <see cref="String"/> that contains generated content.</param>
        public void Write(OutputItem output, string text)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            output.Validate();

            OutputFile outputFile = this.outputFiles.FirstOrDefault(o => string.Equals(o.Path, output.Path, StringComparison.OrdinalIgnoreCase));

            // If content was previously generated for this file
            if (outputFile != null)
            {
                // Validate new output attributes for consistency
                outputFile.Validate(output);
            }
            else
            {
                // create a new output file
                outputFile = new OutputFile();
                this.outputFiles.Add(outputFile);
            }

            outputFile.CopyPropertiesFrom(output);

            if (string.IsNullOrEmpty(output.File))
            {
                // Append text to transformation output
                this.WriteToTransformation(text);
            }
            else
            {
                // Append text to the output file
                outputFile.Content.Append(text);
            }
        }
Exemplo n.º 4
0
        internal void Validate(OutputItem item)
        {
            if (this.encoding != null && !object.Equals(item.Encoding, this.Encoding))
            {
                throw this.PropertyDiscrepancyException("Encoding", item.Encoding.EncodingName, this.Encoding.EncodingName);
            }

            if (this.itemType != null && !string.Equals(item.ItemType, this.ItemType, StringComparison.OrdinalIgnoreCase))
            {
                throw this.PropertyDiscrepancyException("ItemType", item.ItemType, this.ItemType); 
            }

            foreach (KeyValuePair<string, string> metadata in item.Metadata)
            {
                string previousValue;
                bool metadataExists = this.Metadata.TryGetValue(metadata.Key, out previousValue);
                if (metadataExists && metadata.Value != previousValue)
                {
                    throw this.PropertyDiscrepancyException(
                        string.Format(CultureInfo.InvariantCulture, "Metadata '{0}'", metadata.Key),
                        metadata.Value, 
                        previousValue);
                }
            }

            if (item.PreserveExistingFile != this.PreserveExistingFile)
            {
                throw this.PropertyDiscrepancyException("PreserveExistingFile", item.PreserveExistingFile.ToString(), this.PreserveExistingFile.ToString()); 
            }
        }
Exemplo n.º 5
0
        internal void CopyPropertiesFrom(OutputItem item)
        {
            this.File = item.File;
            this.Directory = item.Directory;
            this.Project = item.Project;
            this.Encoding = item.Encoding;
            this.ItemType = item.ItemType;
            this.PreserveExistingFile = item.PreserveExistingFile;

            foreach (string reference in item.References)
            {
                if (!this.References.Contains(reference))
                {
                    this.References.Add(reference);
                }
            }

            foreach (KeyValuePair<string, string> metadata in item.Metadata)
            {
                if (!this.Metadata.ContainsKey(metadata.Key))
                {
                    this.Metadata.Add(metadata.Key, metadata.Value);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Writes text to the output of this transformation.
        /// </summary>
        /// <param name="output">An <see cref="OutputItem"/> object that specifies how the text must be saved.</param>
        /// <param name="text">A <see cref="String"/> that contains generated content.</param>
        public void Write(OutputItem output, string text)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            output.Validate();

            OutputFile outputFile = this.outputFiles.FirstOrDefault(o => string.Equals(o.Path, output.Path, StringComparison.OrdinalIgnoreCase));

            // If content was previously generated for this file
            if (outputFile != null)
            {
                // Validate new output attributes for consistency
                outputFile.Validate(output);
            }
            else
            {
                // create a new output file
                outputFile = new OutputFile();
                this.outputFiles.Add(outputFile);
            }

            outputFile.CopyPropertiesFrom(output); 
            
            if (string.IsNullOrEmpty(output.File))
            {
                // Append text to transformation output
                this.WriteToTransformation(text);
            }
            else
            {
                // Append text to the output file
                outputFile.Content.Append(text);                
            }
        }