예제 #1
0
        static void Main(string[] args)
        {
            var opts = new Options();
            CommandLine.Parser.Default.ParseArguments(args, opts);

            string tFileName = null;
            Action<string> writeLineHandler = null;

            switch (opts.Transform.ToLower())
            {
                case "mirtarbase":
                    tFileName = "mirtarbase.xslt";
                    writeLineHandler = Program.MirtarbaseWriteLineHandler;
                    break;

                default:
                    throw new NotSupportedException(string.Format(
                        "Unknown XSLT transform '{0}'.",
                        opts.Transform
                    ));
            }

            #if DEBUG
            var t = new XslCompiledTransform(true);
            #else
            var t = new XslCompiledTransform(false);
            #endif
            using (var tStream = ResourceHelper.GetAssemblyManifestResourceStream(
                typeof(Program),
                string.Format("XSLT.{0}", tFileName)))
            using (var tXr = XmlReader.Create(tStream))
            {
                t.Load(tXr);
            }

            using (var srcStream = new FileStream(opts.Input, FileMode.Open, FileAccess.Read, FileShare.Read))
            using (var srcXr = XmlReader.Create(srcStream))
            {
                t.Transform(
                    srcXr,
                    new XsltArgumentList(),
                    new MyTextWriter(
                        delegate(string line)
                        {
                            if (!line.StartsWith("#"))
                            {
                                writeLineHandler(line);
                            }
                        }));
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            // Application.EnableVisualStyles();
            // Application.SetCompatibleTextRenderingDefault(false);
            // Application.Run(new Form1());

            // Find out current working directory
            // var dir = Directory.GetCurrentDirectory();
            // Console.WriteLine(dir);

            var opts = new Options();
            CommandLine.Parser.Default.ParseArguments(args, opts);

            var connStrBldr = new SQLiteConnectionStringBuilder();
            connStrBldr.DataSource = opts.Database;
            connStrBldr.Version = 3;

            using (var srcStream = new FileStream(opts.Input, FileMode.Open, FileAccess.Read, FileShare.Read))
            using (var src = new StreamReader(srcStream))
            using (var conn = new SQLiteConnection(connStrBldr.ConnectionString))
            {
                conn.Open();

                using (var tran = conn.BeginTransaction())
                {
                    try
                    {
                        var engine = new GtfUploader(src, tran);
                        engine.Run();

                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();

                        Console.WriteLine(ex.ToString());
                    }
                }
            }

            #if DEBUG
            Console.WriteLine("Press any key ...");
            Console.ReadKey();
            #endif
        }