Ejemplo n.º 1
0
        public void ProcessCreateNewDataType()
        {
            var databaseID = new ProjectTreeHelper().GetFirstAncestorID <DatabaseDTO>();

            if (databaseID == Guid.Empty)
            {
                throw new InvalidOperationException("No database selected.");
            }
            var newDataType = new DataTypeDTO()
            {
                TypeName = "<Enter name>", DatabaseID = databaseID
            };

            var view = new DataTypeDetailsView();

            view.Object = newDataType;

            var popup = new PopupWindow();

            popup.Title    = "New Data Type";
            popup.Validate = () => { return(new Validator().Validate(newDataType)); };
            popup.ViewPanel.Children.Add(view);

            if (popup.ShowDialog() == true)
            {
                new ObjectDataSource().SaveObject(newDataType);
                ServiceLocator serviceLocator = ServiceLocator.GetActive();
                serviceLocator.BasicController.ProcessProjectTreeRefresh();
            }
        }
Ejemplo n.º 2
0
        internal List <EntityDTO> LoadEntities(DatabaseDTO database, ref int lastTable)
        {
            const int ExpectedColumnsTotal = 9;
            const int TablesPerCall        = 4;

            // TODO: merge entities, attributes, not only data types

            var dataTypes = new Dictionary <string, DataTypeDTO>();
            var entities  = new List <EntityDTO>();

            foreach (var dataType in database.DataTypes)
            {
                dataTypes.Add(dataType.TypeName, dataType);
            }

            var commandText = SqlQueries.GetColumnsQuery;

            using (var connection = new SqlConnection(database.ConnectionString))
            {
                var command = connection.CreateCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = commandText;

                var param1 = new SqlParameter();
                param1.ParameterName = "@TABLE_NUMBER";
                param1.SqlDbType     = SqlDbType.Int;
                param1.Direction     = ParameterDirection.Input;
                param1.Value         = lastTable;
                command.Parameters.Add(param1);

                var param2 = new SqlParameter();
                param2.ParameterName = "@TABLES_IN_ONE_CALL";
                param2.SqlDbType     = SqlDbType.Int;
                param2.Direction     = ParameterDirection.Input;
                param2.Value         = TablesPerCall;
                command.Parameters.Add(param2);

                connection.Open();
                var reader = command.ExecuteReader();
                {
                    if (reader.HasRows)
                    {
                        if (reader.FieldCount != ExpectedColumnsTotal)
                        {
                            throw new InvalidOperationException(String.Format("Query returned less or more than {0} columns ({1})", ExpectedColumnsTotal, commandText));
                        }

                        string    lastTableSchema = string.Empty;
                        string    lastTableName   = string.Empty;
                        EntityDTO entity          = null;

                        int tablesProcessed = 0;
                        while (reader.Read())
                        {
                            lastTable = Convert.ToInt32(reader["TABLE_NUMBER"]);

                            string tableSchema = reader["SchemaName"].ToString();
                            string tableName   = reader["TableName"].ToString();

                            // New table
                            if (!tableSchema.Equals(lastTableSchema, StringComparison.InvariantCultureIgnoreCase) ||
                                !tableName.Equals(lastTableName, StringComparison.InvariantCultureIgnoreCase))
                            {
                                entity = new EntityDTO()
                                {
                                    DatabaseID = database.ID,
                                    SchemaName = tableSchema,
                                    EntityName = tableName
                                };
                                entities.Add(entity);
                                tablesProcessed++;
                            }

                            var attribute = new AttributeDTO()
                            {
                                EntityID      = entity.ID,
                                AttributeName = reader["ColumnName"].ToString(),
                                IsRequired    = Convert.ToInt32(reader["IsNullable"]) == 0 ? true : false,
                                IsPrimaryKey  = Convert.ToInt32(reader["IsPrimaryKey"]) == 0 ? false : true,
                            };

                            var attributeTypeName = reader["DataType"].ToString();
                            if (!dataTypes.ContainsKey(attributeTypeName))
                            {
                                var dataType = new DataTypeDTO()
                                {
                                    DatabaseID = database.ID,
                                    TypeName   = attributeTypeName
                                };
                                dataTypes.Add(attributeTypeName, dataType);
                                database.DataTypes.Add(dataType);
                            }
                            var attributeType = dataTypes[attributeTypeName];
                            attribute.DataTypeID = attributeType.ID;

                            entity.Attributes.Add(attribute);

                            lastTableSchema = tableSchema;
                            lastTableName   = tableName;
                        }
                    }
                }
                reader.Close();
            }

            return(entities);
        }
    public void Read(TProtocol iprot)
    {
        iprot.IncrementRecursionDepth();
        try
        {
            TField field;
            iprot.ReadStructBegin();
            while (true)
            {
                field = iprot.ReadFieldBegin();
                if (field.Type == TType.Stop)
                {
                    break;
                }
                switch (field.ID)
                {
                case 1:
                    if (field.Type == TType.String)
                    {
                        Id = iprot.ReadString();
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 2:
                    if (field.Type == TType.String)
                    {
                        Name = iprot.ReadString();
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 3:
                    if (field.Type == TType.String)
                    {
                        Description = iprot.ReadString();
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 4:
                    if (field.Type == TType.Struct)
                    {
                        DataType = new DataTypeDTO();
                        DataType.Read(iprot);
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                default:
                    TProtocolUtil.Skip(iprot, field.Type);
                    break;
                }
                iprot.ReadFieldEnd();
            }
            iprot.ReadStructEnd();
        }
        finally
        {
            iprot.DecrementRecursionDepth();
        }
    }