示例#1
0
        /// <summary>
        ///     Make transformation of file <see cref="SourceFilePath" /> with transform file <see cref="TransformFile" /> to <paramref
        ///      name="destinationFilePath" />.
        /// </summary>
        /// <param name="destinationFilePath"> File path of destination transformation. </param>
        /// <param name="forceParametersTask"> Invoke parameters task even if the parameters are not set with <see
        ///      cref="SetParameters" /> . </param>
        /// <returns> Return true if transformation finish successfully, otherwise false. </returns>
        public bool Execute(string destinationFilePath, bool forceParametersTask = false)
        {
            if (string.IsNullOrWhiteSpace(destinationFilePath))
            {
                throw new ArgumentException("Destination file can't be empty.", "destinationFilePath");
            }

            Trace.TraceInformation("Start tranformation to '{0}'.", destinationFilePath);

            if (string.IsNullOrWhiteSpace(SourceFilePath) || !File.Exists(SourceFilePath))
            {
                throw new FileNotFoundException("Can't find source file.", SourceFilePath);
            }

            if (string.IsNullOrWhiteSpace(TransformFile) || !File.Exists(TransformFile))
            {
                throw new FileNotFoundException("Can't find transform  file.", TransformFile);
            }

            Trace.TraceInformation("Source file: '{0}'.", SourceFilePath);
            Trace.TraceInformation("Transform  file: '{0}'.", TransformFile);

            try
            {
                var transformFile = ReadContent(TransformFile);

                if ((_parameters != null && _parameters.Count > 0) || forceParametersTask)
                {
                    ParametersTask parametersTask = new ParametersTask();
                    if (_parameters != null)
                    {
                        parametersTask.AddParameters(_parameters);
                    }
                    transformFile = parametersTask.ApplyParameters(transformFile);
                }

                XmlDocument document = new XmlDocument();
                document.Load(SourceFilePath);

                XmlTransformation transformation = new XmlTransformation(transformFile, false, _transfomrationLogger);

                bool result = transformation.Apply(document);

                document.Save(destinationFilePath);

                return(result);
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// 	Make transformation of file <see cref="SourceFilePath" /> with transform file <see cref="TransformFile" /> to <paramref
        /// 	 name="destinationFilePath" />.
        /// </summary>
        /// <param name="destinationFilePath"> File path of destination transformation. </param>
        /// <param name="forceParametersTask"> Invoke parameters task even if the parameters are not set with <see
        /// 	 cref="SetParameters" /> . </param>
        /// <returns> Return true if transformation finish successfully, otherwise false. </returns>
        public bool Execute(string destinationFilePath, bool forceParametersTask = false)
        {
            if (string.IsNullOrWhiteSpace(destinationFilePath))
                throw new ArgumentException("Destination file can't be empty.", "destinationFilePath");

            Trace.TraceInformation("Start tranformation to '{0}'.", destinationFilePath);

            if (string.IsNullOrWhiteSpace(SourceFilePath) || !File.Exists(SourceFilePath))
                throw new FileNotFoundException("Can't find source file.", SourceFilePath);

            if (string.IsNullOrWhiteSpace(TransformFile) || !File.Exists(TransformFile))
                throw new FileNotFoundException("Can't find transform  file.", TransformFile);

            Trace.TraceInformation("Source file: '{0}'.", SourceFilePath);
            Trace.TraceInformation("Transform  file: '{0}'.", TransformFile);

            try
            {
                var transformFile = ReadContent(TransformFile);

                if ((_parameters != null && _parameters.Count > 0) || forceParametersTask)
                {
                    ParametersTask parametersTask = new ParametersTask();
                    if (_parameters != null)
                        parametersTask.AddParameters(_parameters);
                    transformFile = parametersTask.ApplyParameters(transformFile);
                }

                XmlDocument document = new XmlDocument();
                document.Load(SourceFilePath);

                XmlTransformation transformation = new XmlTransformation(transformFile, false, _transfomrationLogger);

                bool result = transformation.Apply(document);

                document.Save(destinationFilePath);

                return result;
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                return false;
            }
        }