Ejemplo n.º 1
0
        public static Model FromDdf(string uriHost, string uriDbName, string uriUser = null, string uriPassword = null, bool?uriPrompt = null, string ownerName = null, string dllPath = null, IEnumerable <string> depedencyPaths = null, string nameSpace = null)
        {
            Model result = new Model();

            using (var client = new SchemaDbClient(dllPath))
                using (var fieldSchemaManager = client.FieldSchema(Path.Uri(uriHost, uriDbName, uriUser: uriUser, uriPassword: uriPassword, uriPrompt: uriPrompt), ownerName))
                    using (var fileSchemaManager = client.FileSchema(Path.Uri(uriHost, uriDbName, uriUser: uriUser, uriPassword: uriPassword, uriPrompt: uriPrompt), ownerName)) {
                        var fieldSchemas = fieldSchemaManager.Query().Where(s => s.DataType < 227).ToArray();;
                        var fileSchemas  = fileSchemaManager.Query().Where(s => !s.IsSchema).ToArray();
                        var records      = new List <Record>();
                        foreach (var fileSchema in fileSchemas)
                        {
                            var record    = Record.FromBtrieveFile(Path.Uri(uriHost, uriDbName, fileSchema.Name, uriUser: uriUser, uriPassword: uriPassword, uriPrompt: uriPrompt), dllPath, depedencyPaths, ownerName: ownerName);
                            var newFields = new List <Field>();
                            foreach (var fieldSchema in fieldSchemas.Where(s => s.FileId == fileSchema.Id))
                            {
                                var field = record.Fields
                                            .SingleOrDefault(f => f.Position == fieldSchema.Offset && f.Length == fieldSchema.Size && f.KeyType == fieldSchema.KeyType.Value);
                                if (field == null)
                                {
                                    field                   = new Field();
                                    field.Position          = fieldSchema.Offset;
                                    field.Length            = fieldSchema.Size;
                                    field.ConverterTypeName = Config.GetConverterTypeName(fieldSchema.KeyType.Value, fieldSchema.Size, fieldSchema.Dec);
                                    field.KeyType           = fieldSchema.KeyType.Value;
                                    field.Parameter         = Config.GetConverterParameter(fieldSchema.KeyType.Value, fieldSchema.Size, fieldSchema.Dec);
                                    newFields.Add(field);
                                }
                                field.NullType = fieldSchema.IsNullable ? NullType.Nullable : NullType.None;
                                field.Name     = fieldSchema.Name;

                                if (field.NullType == NullType.Nullable)
                                {
                                    field = record.Fields
                                            .SingleOrDefault(f => f.Position == fieldSchema.Offset - 1 && f.Length == 1 && f.KeyType == KeyType.LegacyString);
                                    if (field != null)
                                    {
                                        field.NullType      = NullType.NullFlag;
                                        field.ConverterType = typeof(Orm.Converters.NullFlagConverter);
                                        if (field.Name == null)
                                        {
                                            field.Name = "N_" + fieldSchema.Name;
                                        }
                                    }
                                    else
                                    {
                                        field = new Field()
                                        {
                                            Position      = (ushort)(fieldSchema.Offset - 1),
                                            Name          = "N_" + fieldSchema.Name,
                                            Length        = 1,
                                            ConverterType = typeof(Orm.Converters.NullFlagConverter),
                                            Parameter     = null,
                                            KeyType       = BtrieveWrapper.KeyType.LegacyString,
                                            NullType      = NullType.NullFlag,
                                        };
                                        newFields.Add(field);
                                    }
                                }
                            }
                            foreach (var field in newFields)
                            {
                                record.FieldCollection.Add(field);
                            }
                            record.Fields = record.Fields.OrderBy(f => f.Position).ToArray();
                            if (record.VariableOption != RecordVariableOption.NotVariable)
                            {
                                var capacity = record.Fields.Max(f => f.Position + f.Length);
                                if (capacity > record.FixedLength)
                                {
                                }
                                record.VariableFieldCapacity = (ushort)(capacity - record.FixedLength);
                            }
                            records.Add(record);
                        }
                        result.DllPath         = dllPath;
                        result.DependencyPaths = depedencyPaths.ToArray();
                        result.Name            = uriDbName;
                        result.PathType        = PathType.Uri;
                        result.UriHost         = uriHost;
                        result.UriDbName       = uriDbName;
                        result.UriUser         = uriUser;
                        result.UriPassword     = uriPassword;
                        result.UriPrompt       = uriPrompt.HasValue ? uriPrompt.Value ? "true" : "false" : null;
                        result.Namespace       = nameSpace ?? "BtrieveWrapper.Orm.Models.CustomModels";
                        result.Records         = records.ToArray();
                    }
            return(result);
        }
Ejemplo n.º 2
0
        public static Model FromDdf(string uriHost, string uriDbName, string uriUser = null, string uriPassword = null, bool? uriPrompt = null, string ownerName = null, string dllPath = null, IEnumerable<string> depedencyPaths = null, string nameSpace = null) {
            Model result = new Model();
            using (var client = new SchemaDbClient(dllPath))
            using (var fieldSchemaManager = client.FieldSchema(Path.Uri(uriHost, uriDbName, uriUser: uriUser, uriPassword: uriPassword, uriPrompt: uriPrompt), ownerName))
            using (var fileSchemaManager = client.FileSchema(Path.Uri(uriHost, uriDbName, uriUser: uriUser, uriPassword: uriPassword, uriPrompt: uriPrompt), ownerName)) {
                var fieldSchemas = fieldSchemaManager.Query().Where(s => s.DataType < 227).ToArray(); ;
                var fileSchemas = fileSchemaManager.Query().Where(s => !s.IsSchema).ToArray();
                var records = new List<Record>();
                foreach (var fileSchema in fileSchemas) {
                    var record = Record.FromBtrieveFile(Path.Uri(uriHost, uriDbName, fileSchema.Name, uriUser: uriUser, uriPassword: uriPassword, uriPrompt: uriPrompt), dllPath, depedencyPaths, ownerName: ownerName);
                    var newFields = new List<Field>();
                    foreach (var fieldSchema in fieldSchemas.Where(s => s.FileId == fileSchema.Id)) {
                        var field = record.Fields
                            .SingleOrDefault(f => f.Position == fieldSchema.Offset && f.Length == fieldSchema.Size && f.KeyType == fieldSchema.KeyType.Value);
                        if (field == null) {
                            field = new Field();
                            field.Position = fieldSchema.Offset;
                            field.Length = fieldSchema.Size;
                            field.ConverterTypeName = Config.GetConverterTypeName(fieldSchema.KeyType.Value, fieldSchema.Size, fieldSchema.Dec);
                            field.KeyType = fieldSchema.KeyType.Value;
                            field.Parameter = Config.GetConverterParameter(fieldSchema.KeyType.Value, fieldSchema.Size, fieldSchema.Dec);
                            newFields.Add(field);
                        }
                        field.NullType = fieldSchema.IsNullable ? NullType.Nullable : NullType.None;
                        field.Name = fieldSchema.Name;

                        if (field.NullType == NullType.Nullable) {
                            field = record.Fields
                                .SingleOrDefault(f => f.Position == fieldSchema.Offset - 1 && f.Length == 1 && f.KeyType == KeyType.LegacyString);
                            if (field != null) {
                                field.NullType = NullType.NullFlag;
                                field.ConverterType = typeof(Orm.Converters.NullFlagConverter);
                                if (field.Name == null) {
                                    field.Name = "N_" + fieldSchema.Name;
                                }
                            } else {
                                field = new Field() {
                                    Position = (ushort)(fieldSchema.Offset - 1),
                                    Name = "N_" + fieldSchema.Name,
                                    Length = 1,
                                    ConverterType = typeof(Orm.Converters.NullFlagConverter),
                                    Parameter = null,
                                    KeyType = BtrieveWrapper.KeyType.LegacyString,
                                    NullType = NullType.NullFlag,
                                };
                                newFields.Add(field);
                            }
                        }
                    }
                    foreach (var field in newFields) {
                        record.FieldCollection.Add(field);
                    }
                    record.Fields = record.Fields.OrderBy(f => f.Position).ToArray();
                    if (record.VariableOption != RecordVariableOption.NotVariable) {
                        var capacity = record.Fields.Max(f => f.Position + f.Length);
                        if (capacity > record.FixedLength) {

                        }
                        record.VariableFieldCapacity = (ushort)(capacity - record.FixedLength);
                    }
                    records.Add(record);
                }
                result.DllPath = dllPath;
                result.DependencyPaths = depedencyPaths.ToArray();
                result.Name = uriDbName;
                result.PathType = PathType.Uri;
                result.UriHost = uriHost;
                result.UriDbName = uriDbName;
                result.UriUser = uriUser;
                result.UriPassword = uriPassword;
                result.UriPrompt = uriPrompt.HasValue ? uriPrompt.Value ? "true" : "false" : null;
                result.Namespace = nameSpace ?? "BtrieveWrapper.Orm.Models.CustomModels";
                result.Records = records.ToArray();
            }
            return result;
        }