Esempio n. 1
0
        public static void Main(string[] args)
        {
            int    exitCode = 0;
            XTArgs xtargs   = new XTArgs(args);

            try {
                if (string.IsNullOrEmpty(xtargs.inputFile))
                {
                    Console.Error.WriteLine("missing input-file");
                    showUsage(1);
                    //throw new ApplicationException("input-file is empty!");
                }
                if (string.IsNullOrEmpty(xtargs.transformFile))
                {
                    Console.Error.WriteLine("missing transformation-file");
                    showUsage(1);
                    //throw new ApplicationException("transformationb-file is empty!");
                }
                exitCode = processArgs(xtargs);
            } catch (ApplicationException ae) {
                MiniLogger.log(MethodBase.GetCurrentMethod(), ae);
            } catch (Exception ex) {
                MiniLogger.log(MethodBase.GetCurrentMethod(), ex);
            }
            Environment.Exit(exitCode);
        }
Esempio n. 2
0
        static int processArgs(XTArgs args)
        {
            int ret = 0;
            XslCompiledTransform t;
            XsltArgumentList     argsList;

            try {
                t = new XslCompiledTransform(true);

                argsList = new XsltArgumentList();
                foreach (string akey in args.arguments.Keys)
                {
                    argsList.AddParam(akey, string.Empty, args.arguments[akey]);
                }

                if (args.verbose)
                {
                    MiniLogger.log("[VERBOSE] " + "using transform: " + args.transformFile);
                }
                t.Load(args.transformFile);

                if (args.verbose)
                {
                    MiniLogger.log("[VERBOSE] " + "transforming " + args.inputFile);
                }

                XmlWriter xw = null;

                if (string.IsNullOrEmpty(args.outputFile))
                {
                    settings.CloseOutput      = false;
                    settings.ConformanceLevel = ConformanceLevel.Auto;
                    xw = XmlWriter.Create(Console.Out, settings);
                }
                else
                {
                    xw = XmlWriter.Create(args.outputFile, settings);
                }
                if (xw != null)
                {
                    t.Transform(args.inputFile, argsList, xw);
                    xw.Close();
                    xw.Dispose();
                    xw = null;
                }
                if (args.verbose)
                {
                    if (string.IsNullOrEmpty(args.outputFile))
                    {
                        Console.Out.WriteLine();
                    }
                    MiniLogger.log("[VERBOSE] " + "transformed into :" +
                                   (string.IsNullOrEmpty(args.outputFile) ? "<stdout>" : args.outputFile));
                }
            } catch (XmlException xe) {
                ret = 1;
                throw new ApplicationException("XML Exception ", xe);
            } catch (DirectoryNotFoundException dnfe) {
                ret = 1;
                throw new ApplicationException("Directory not found", dnfe);
            } catch (Exception ex) {
                MiniLogger.log(MethodBase.GetCurrentMethod(), ex);
                ret = 1;
            }
            return(ret);
        }