Esempio n. 1
0
        static int Main(string[] args)
        {
            var parameters = string.Join("; ", args);
            string from = null;
            string to = null;
            try
            {
                var builder = new DbConnectionStringBuilder() { ConnectionString = parameters };
                foreach (DictionaryEntry it in (IDictionary)builder)
                {
                    switch (it.Key.ToString())
                    {
                        case "from": from = it.Value.ToString(); break;
                        case "to": to = it.Value.ToString(); break;
                        default: throw new ArgumentException("Unknown key: " + it.Key);
                    }
                }

                if (from == null) throw new ArgumentException("Missing key 'From'.");
                if (to == null) throw new ArgumentException("Missing key 'To'.");
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(string.Format(null, Usage, e.Message, parameters));
                return 1;
            }

            try
            {
                var converter = new Converter();
                using (var reader = new XmlTextReader(from))
                {
                    using (var writer = new StreamWriter(to, false, Encoding.UTF8))
                    {
                        converter.Reader = reader;
                        converter.Writer = writer;
                        converter.Run();
                    }
                }

                return 0;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                return 1;
            }
        }