Пример #1
0
        static void Main(string[] args)
        {
            var getopt = new Getopt(Assembly.GetExecutingAssembly().GetName().Name, args, "s:i:c:nadp")
            {
                Opterr = false
            };

            string input   = null;
            string culture = null;

            bool dontDeleteSet  = false;
            bool insertAll      = false;
            bool skipValidation = false;
            bool onlyPrepare    = false;

            string connString   = ConfigurationManager.ConnectionStrings["Gettext"].ConnectionString;
            string insertSP     = ConfigurationManager.AppSettings["SP.Insert"];
            string deleteSP     = ConfigurationManager.AppSettings["SP.Delete"];
            string getSP        = ConfigurationManager.AppSettings["SP.Get"];
            string tableName    = ConfigurationManager.AppSettings["Table.Name"];
            string tableCulture = ConfigurationManager.AppSettings["Table.Fields.Culture"];
            string tableKey     = ConfigurationManager.AppSettings["Table.Fields.Key"];
            string tableValue   = ConfigurationManager.AppSettings["Table.Fields.Value"];

            int option;

            while (-1 != (option = getopt.getopt()))
            {
                switch (option)
                {
                case 'i': input = getopt.Optarg; break;

                case 'c': culture = getopt.Optarg; break;

                case 'n': dontDeleteSet = true; break;

                case 's': connString = getopt.Optarg; break;

                case 'a': insertAll = true; break;

                case 'd': skipValidation = true; break;

                case 'p': onlyPrepare = true; break;

                default: PrintUsage(); return;
                }
            }

            if (input == null && !onlyPrepare)
            {
                PrintUsage();
                return;
            }

            if (connString == null || getSP == null || insertSP == null || deleteSP == null || tableName == null || tableKey == null || tableCulture == null || tableValue == null)
            {
                Console.Out.WriteLine("Ensure that connection string, table name, table fields, insert and delete stored procedures are set in app config.");
                Console.Out.WriteLine();
                Console.Out.WriteLine("Expected connection strings are:");
                Console.Out.WriteLine(" Gettext");
                Console.Out.WriteLine();
                Console.Out.WriteLine("Expected app settings are:");
                Console.Out.WriteLine(" SP.Get");
                Console.Out.WriteLine(" SP.Insert");
                Console.Out.WriteLine(" SP.Delete");
                Console.Out.WriteLine(" Table.Name");
                Console.Out.WriteLine(" Table.Fields.Key");
                Console.Out.WriteLine(" Table.Fields.Value");
                Console.Out.WriteLine(" Table.Fields.Culture");
                return;
            }

            try
            {
                using (var db = new DatabaseInterface(connString)
                {
                    GetSP = getSP,
                    DeleteSP = deleteSP,
                    InsertSP = insertSP,
                    CultureField = tableCulture,
                    KeyField = tableKey,
                    ValueField = tableValue,
                    TableName = tableName
                })
                {
                    db.Init();

                    // Check if table and sps exist
                    if (!skipValidation || onlyPrepare)
                    {
                        db.Prepare();
                    }

                    // If only prepare is set, do not use po file, just make sure everything is ready to use it later
                    if (onlyPrepare)
                    {
                        Console.Out.WriteLine("Table and stored procedures ready.");
                        db.Commit();
                        return;
                    }

                    // Delete previous resource set for the specified culture
                    if (!dontDeleteSet)
                    {
                        db.DeleteResourceSet(culture);
                    }

                    // Dump the file into the database
                    var requestor = new DatabaseParserRequestor(culture, db, insertAll);
                    new PoParser().Parse(new StreamReader(input), requestor);

                    db.Commit();
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Exception in program: {0}\n{1}", ex.Message, ex.StackTrace);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var getopt = new Getopt(Assembly.GetExecutingAssembly().GetName().Name, args, "s:i:c:nadp") { Opterr = false };

            string input = null;
            string culture = null;

            bool dontDeleteSet = false;
            bool insertAll = false;
            bool skipValidation = false;
            bool onlyPrepare = false;

            string connString = ConfigurationManager.ConnectionStrings["Gettext"].ConnectionString;
            string insertSP = ConfigurationManager.AppSettings["SP.Insert"];
            string deleteSP = ConfigurationManager.AppSettings["SP.Delete"];
            string getSP = ConfigurationManager.AppSettings["SP.Get"];
            string tableName = ConfigurationManager.AppSettings["Table.Name"];
            string tableCulture = ConfigurationManager.AppSettings["Table.Fields.Culture"];
            string tableKey = ConfigurationManager.AppSettings["Table.Fields.Key"];
            string tableValue = ConfigurationManager.AppSettings["Table.Fields.Value"];

            int option;
            while (-1 != (option = getopt.getopt()))
            {
                switch (option)
                {
                    case 'i': input = getopt.Optarg; break;
                    case 'c': culture = getopt.Optarg; break;
                    case 'n': dontDeleteSet = true; break;
                    case 's': connString = getopt.Optarg; break;
                    case 'a': insertAll = true; break;
                    case 'd': skipValidation = true; break;
                    case 'p': onlyPrepare = true; break;
                    default: PrintUsage(); return;
                }
            }

            if (input == null && !onlyPrepare)
            {
                PrintUsage();
                return;
            }

            if (connString == null || getSP == null || insertSP == null || deleteSP == null || tableName == null || tableKey == null || tableCulture == null || tableValue == null)
            {
                Console.Out.WriteLine("Ensure that connection string, table name, table fields, insert and delete stored procedures are set in app config.");
                Console.Out.WriteLine();
                Console.Out.WriteLine("Expected connection strings are:");
                Console.Out.WriteLine(" Gettext");
                Console.Out.WriteLine();
                Console.Out.WriteLine("Expected app settings are:");
                Console.Out.WriteLine(" SP.Get");
                Console.Out.WriteLine(" SP.Insert");
                Console.Out.WriteLine(" SP.Delete");
                Console.Out.WriteLine(" Table.Name");
                Console.Out.WriteLine(" Table.Fields.Key");
                Console.Out.WriteLine(" Table.Fields.Value");
                Console.Out.WriteLine(" Table.Fields.Culture");
                return;
            }

            try
            {
                using (var db = new DatabaseInterface(connString)
                    {
                        GetSP = getSP,
                        DeleteSP = deleteSP,
                        InsertSP = insertSP,
                        CultureField = tableCulture,
                        KeyField = tableKey,
                        ValueField = tableValue,
                        TableName = tableName
                    })
                {
                    db.Init();

                    // Check if table and sps exist
                    if (!skipValidation || onlyPrepare)
                    {
                        db.Prepare();
                    }

                    // If only prepare is set, do not use po file, just make sure everything is ready to use it later
                    if (onlyPrepare)
                    {
                        Console.Out.WriteLine("Table and stored procedures ready.");
                        db.Commit();
                        return;
                    }

                    // Delete previous resource set for the specified culture
                    if (!dontDeleteSet)
                    {
                        db.DeleteResourceSet(culture);
                    }

                    // Dump the file into the database
                    var requestor = new DatabaseParserRequestor(culture, db, insertAll);
                    new PoParser().Parse(new StreamReader(input), requestor);

                    db.Commit();
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Exception in program: {0}\n{1}", ex.Message, ex.StackTrace);
            }

        }