private async void _HandleGenerateCodeCommandExecuted()
        {
            if (!CandidateDefinitions.Any(def => string.IsNullOrEmpty(def.TableName)))
            {
                EntityGeneratorViewModel.ShowBusy("Generating entities...");

                var request = new EntityGenerationRequest
                {
                    OutputPath        = OutputPath,
                    Server            = mPayload.Server,
                    Database          = mPayload.Database,
                    Username          = mPayload.Username,
                    Password          = mPayload.Password,
                    EntityDefinitions = CandidateDefinitions.ToArray(),
                    Namespace         = Namespace,
                };

                await EntityGenerationManager.GenerateEntities(request);

                Properties.Settings.Default.LastEntityNames = string.Join("@", request.EntityDefinitions.Select(entity => string.Format("{0}#{1}", entity.TableName, entity.EntityName)));
                Properties.Settings.Default.LastNamespace   = Namespace;
                Properties.Settings.Default.LastOutputPath  = OutputPath;
                Properties.Settings.Default.Save();

                EntityGeneratorViewModel.HideBusy();

                MessageBox.Show(
                    @"Generation complete! ", "Entity Generation Complete", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                MessageBox.Show("An entity name is required for all tables. Please define an entity name for the following tables: " +
                                string.Join(",", CandidateDefinitions.Where(def => string.IsNullOrEmpty(def.EntityName)).Select(def => def.TableName)));
            }
        }
Exemplo n.º 2
0
        private async void _HandleConnectToDatabaseCommand()
        {
            if (!string.IsNullOrWhiteSpace(Server) &&
                !string.IsNullOrEmpty(Database) &&
                !string.IsNullOrWhiteSpace(Username) &&
                !string.IsNullOrWhiteSpace(Password))
            {
                EntityGeneratorViewModel.ShowBusy("Connecting...");

                var results = await SchemaManager.RetrieveDatabaseTables(Server, Database, Username, Password);

                CandidateTables = results.Select(table => new SelectableItem
                {
                    Description = table
                }).ToArray();

                var lastSelected = Properties.Settings.Default.LastSelectedTables;
                if (!string.IsNullOrEmpty(lastSelected))
                {
                    var tables = lastSelected.Split('@');
                    foreach (var table in tables)
                    {
                        var selectableTableItem = CandidateTables.SingleOrDefault(item => item.Description == table);
                        if (selectableTableItem != null)
                        {
                            selectableTableItem.IsSelected = true;
                        }
                    }
                }

                CandidateTablesViewSource = new CollectionViewSource()
                {
                    Source = CandidateTables
                };
                CandidateTablesViewSource.Filter += _HandleCandidateTablesFilter;

                EntityGeneratorViewModel.HideBusy();
            }
            else
            {
                MessageBox.Show("Please enter a connection string.");
            }
        }