예제 #1
0
        private void AddAddmlFieldDefinitions(AddmlFlatFileDefinition addmlFlatFileDefinition,
                                              flatFileDefinition flatFileDefinition)
        {
            List <recordDefinition> recordDefinitions = GetRecordDefinitions(flatFileDefinition);

            foreach (recordDefinition recordDefinition in recordDefinitions)
            {
                string        recordDefinitionName       = recordDefinition.name;
                int?          recordLength               = GetRecordLength(recordDefinition);
                string        recordDefinitionFieldValue = recordDefinition.recordDefinitionFieldValue;
                List <string> recordProcesses            = GetRecordProcessNames(addmlFlatFileDefinition.Name, recordDefinition.name);

                List <AddmlForeignKey> foreignKeys = GetForeignKeysForRecord(flatFileDefinition, recordDefinition);

                AddmlRecordDefinition addmlRecordDefinition =
                    addmlFlatFileDefinition.AddAddmlRecordDefinition(recordDefinitionName, recordLength, recordDefinitionFieldValue, foreignKeys, recordProcesses);

                List <fieldDefinition> fieldDefinitions = GetFieldDefinitions(recordDefinition);
                foreach (fieldDefinition fieldDefinition in fieldDefinitions)
                {
                    string        name               = fieldDefinition.name;
                    int?          startPosition      = GetStartPosition(fieldDefinition);
                    int?          endPosition        = GetEndPosition(fieldDefinition); // Henter slutt-posisjon med ny funksjon
                    DataType      dataType           = GetFieldType(fieldDefinition.typeReference);
                    bool          isPartOfPrimaryKey = IsPartOfPrimaryKey(recordDefinition, fieldDefinition);
                    bool          isUnique           = IsUnique(fieldDefinition);
                    bool          isNullable         = IsNullable(fieldDefinition);
                    int?          minLength          = GetMinLength(fieldDefinition);
                    int?          maxLength          = GetMaxLength(fieldDefinition);
                    int?          fixedLength        = GetFixedLength(fieldDefinition) ?? endPosition - startPosition + 1;
                    List <string> processes          = GetFieldProcessNames(flatFileDefinition.name, recordDefinition.name,
                                                                            fieldDefinition.name);
                    List <AddmlCode> addmlCodes = GetCodes(fieldDefinition);

                    AddmlFieldDefinition addAddmlFieldDefinition = addmlRecordDefinition.AddAddmlFieldDefinition(
                        name, startPosition, fixedLength, dataType, isUnique, isNullable, minLength,
                        maxLength, processes, addmlCodes, isPartOfPrimaryKey);

                    FieldIndex fieldIndex = new FieldIndex(flatFileDefinition, recordDefinition, fieldDefinition);
                    if (_allFieldDefinitions.ContainsKey(fieldIndex))
                    {
                        throw new AddmlDefinitionParseException("ADDML file already contains a field definition with same index: " + fieldIndex);
                    }
                    _allFieldDefinitions.Add(fieldIndex, addAddmlFieldDefinition);
                }
            }
        }
예제 #2
0
        public AddmlFieldDefinition AddAddmlFieldDefinition(string name,
                                                            int?startPosition,
                                                            int?fixedLength,
                                                            DataType dataType,
                                                            bool isUnique,
                                                            bool isNullable,
                                                            int?minLength,
                                                            int?maxLength,
                                                            List <string> processes,
                                                            List <AddmlCode> codes,
                                                            bool isPartOfPrimaryKey)
        {
            AddmlFieldDefinition addmlFieldDefinition = new AddmlFieldDefinition(
                name,
                startPosition,
                fixedLength,
                dataType,
                isUnique,
                isNullable,
                minLength,
                maxLength,
                this,
                processes,
                codes);

            if (isPartOfPrimaryKey)
            {
                if (PrimaryKey == null)
                {
                    PrimaryKey = new List <AddmlFieldDefinition>();
                }
                PrimaryKey.Add(addmlFieldDefinition);
            }



            AddmlFieldDefinitions.Add(addmlFieldDefinition);

            return(addmlFieldDefinition);
        }