Beispiel #1
0
        private void _HandleNextPageCommand()
        {
            if (CandidateTables != null && CandidateTables.Any(item => item.IsSelected))
            {
                var selectedTables = CandidateTables.Where(item => item.IsSelected).ToArray();
                var payload        = new SelectedTablesPayload
                {
                    SelectedTables = selectedTables.Select(item => item.Description).ToArray(),
                    Server         = Server,
                    Database       = Database,
                    Username       = Username,
                    Password       = Password,
                    FilePath       = FilePath
                };

                Properties.Settings.Default.LastSelectedTables = string.Join("@", selectedTables.Select(item => item.Description).ToArray());

                Properties.Settings.Default.LastDatabase    = Database;
                Properties.Settings.Default.DefaultServer   = Server;
                Properties.Settings.Default.DefaultUsername = Username;
                Properties.Settings.Default.DefaultPassword = Password;

                Properties.Settings.Default.Save();

                EntityEntryView view = new EntityEntryView(payload);

                EntityGeneratorViewModel.NavigateTo(view);
            }
            else
            {
                MessageBox.Show("Please connect and select one or more tables to generate entities for.");
            }
        }
        public EntityEntryViewModel(SelectedTablesPayload payload)
        {
            mPayload = payload;

            CandidateDefinitions = payload.SelectedTables.Select(table => new EntityDefinition()
            {
                TableName  = table,
                EntityName = table + "Entity"
            }).ToArray();

            if (payload.FilePath != null)
            {
                OutputPath = payload.FilePath;
            }

            else if (!string.IsNullOrEmpty(Properties.Settings.Default.LastOutputPath))
            {
                OutputPath = Properties.Settings.Default.LastOutputPath;
            }
            else
            {
                var currentDirectory = Directory.GetCurrentDirectory();
                if (currentDirectory.EndsWith(@"XXX\Tools\CodeGenerators\EntityGenerator\EntityGenerator\bin\Debug"))
                {
                    OutputPath = currentDirectory.Replace(@"XXX\Tools\CodeGenerators\EntityGenerator\EntityGenerator\bin\Debug", @"XXX\Server");
                }
                else
                {
                    OutputPath = currentDirectory;
                }
            }

            if (payload.FilePath == null)
            {
                if (!string.IsNullOrEmpty(Properties.Settings.Default.LastNamespace))
                {
                    Namespace = Properties.Settings.Default.LastNamespace;
                }
                else
                {
                    Namespace = "XXX";
                }
            }

            if (!string.IsNullOrEmpty(Properties.Settings.Default.LastEntityNames))
            {
                var oldPairs = Properties.Settings.Default.LastEntityNames.Split('@');
                foreach (var oldPair in oldPairs)
                {
                    var tablePairs = oldPair.Split('#');
                    var newDef     = CandidateDefinitions.SingleOrDefault(def => def.TableName == tablePairs[0]);
                    if (newDef != null)
                    {
                        newDef.EntityName = tablePairs[1];
                    }
                }
            }
        }
 public EntityEntryView(SelectedTablesPayload payload)
 {
     InitializeComponent();
     DataContext = new EntityEntryViewModel(payload);
 }