Example #1
0
        public void ExportConfigurationClass()
        {
            var dt = LastOrCurrentTable();

            //not .cfg file
            if (cmd.InputPath() == null)
            {
                if (dt == null)
                {
                    return;
                }
            }

            var builder = new ConfClassBuilder(cmd, dt);

            builder.ExportCSharpData();
        }
Example #2
0
        private void ImportResourceData()
        {
            string         file_name              = cmd.InputPath();
            ResourceFormat format                 = cmd.GetEnum("format", ResourceFormat.resx);
            string         schema_name            = cmd.GetValue("schema-name") ?? SchemaName.dbo;
            string         table_name             = cmd.GetValue("table-name");
            string         name_column            = cmd.GetValue("name-column") ?? "name";
            string         value_column           = cmd.GetValue("value-column") ?? name_column;
            string         order_column           = cmd.GetValue("order-column");
            bool           trim_name              = cmd.Has("trim-name");
            bool           trim_value             = cmd.Has("trim-value");
            bool           deleteRowNotInResource = cmd.Has("delete-rows-not-in-resource-file");

            if (file_name == null)
            {
                cerr.WriteLine($"file name is not defined, use option /in:file_name");
                return;
            }

            if (!File.Exists(file_name))
            {
                cerr.WriteLine($"file doesn't exist: \"{file_name}\"");
                return;
            }

            if (tname == null)
            {
                if (table_name == null)
                {
                    cerr.WriteLine($"/table-name is not defined");
                    return;
                }

                if (dname == null)
                {
                    cerr.WriteLine($"required to select a database");
                    return;
                }

                tname = new TableName(dname, schema_name, table_name);
                if (!tname.Exists())
                {
                    cerr.WriteLine($"table-name doesn't exist: {tname}");
                    return;
                }
            }

            DataTable dt = new TableReader(tname)
            {
                CaseSensitive = true,
            }.Table;

            if (!ValidateColumn <string>(dt, name_column, "name-column", required: true))
            {
                return;
            }
            if (!ValidateColumn <string>(dt, value_column, "value-column", required: true))
            {
                return;
            }
            if (!ValidateColumn <int>(dt, order_column, "order-column", required: false))
            {
                return;
            }

            cout.WriteLine($"{dt.Rows.Count} of entries on \"{file_name}\"");

            ResourceTableWriter  writer  = new ResourceTableWriter(file_name, tname, name_column, value_column, order_column);
            List <ResourceEntry> entries = writer.Differ(format, dt, trim_name, trim_value);

            foreach (var entry in entries)
            {
                switch (entry.Action)
                {
                case DataRowAction.Add:
                    cout.WriteLine($"new entry: \"{entry.Name}\", \"{entry.NewValue}\"");
                    break;

                case DataRowAction.Change:
                    cout.WriteLine($"update entry: \"{entry.Name}\", \"{entry.OldValue}\" -> \"{entry.NewValue}\"");
                    break;

                case DataRowAction.Delete:
                    cout.WriteLine($"delete entry: \"{entry.Name}\"");
                    break;
                }
            }

            if (entries.Count > 0)
            {
                cout.WriteLine($"{entries.Count} of entries were changed");
            }
            else
            {
                cout.WriteLine($"no entry is changed");
            }

            if (entries.Count == 0)
            {
                return;
            }

            bool commit = cmd.Has("submit-changes");

            if (!commit)
            {
                return;
            }

            cout.WriteLine($"starting to save changes into table \"{tname}\"");
            try
            {
                writer.SubmitChanges(entries, deleteRowNotInResource);
                cout.WriteLine($"completed to save on table \"{tname}\" from \"{file_name}\"");
            }
            catch (Exception ex)
            {
                cerr.WriteLine($"failed to save in \"{tname}\" , {ex.AllMessages()}");
            }
        }