コード例 #1
0
ファイル: Model.cs プロジェクト: jishida/BtrieveWrapper
        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;
        }
コード例 #2
0
ファイル: Model.cs プロジェクト: jishida/BtrieveWrapper
 public static bool ToXml(Model model, string path) {
     try {
         using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)) {
             var serializer = new XmlSerializer(typeof(Model));
             serializer.Serialize(stream, model);
         }
     } catch {
         return false;
     }
     return true;
 }
コード例 #3
0
ファイル: Model.cs プロジェクト: jishida/BtrieveWrapper
 public static bool ToXml(Model model, Stream stream) {
     var serializer = new XmlSerializer(typeof(Model));
     try {
         serializer.Serialize(stream, model);
     } catch {
         return false;
     }
     return true;
 }
コード例 #4
0
ファイル: Model.cs プロジェクト: jishida/BtrieveWrapper
 public static string ToXml(Model model) {
     using (var stream = new MemoryStream()) {
         Model.ToXml(model, stream);
         var buffer = new byte[stream.Length];
         stream.Read(buffer, 0, (int)stream.Length);
         return Encoding.UTF8.GetString(buffer);
     }
 }
コード例 #5
0
ファイル: Model.cs プロジェクト: jishida/BtrieveWrapper
        public static Model FromDirectory(string name, string directory, string searchPattern = null, SearchOption searchOption = SearchOption.AllDirectories, string ownerName = null, string dllPath = null, IEnumerable<string> dependencyPaths = null, string nameSpace = null) {
            if (searchPattern == null) {
                searchPattern = "*";
            }
            var directoryInfo = new DirectoryInfo(directory);

            var records = new List<Record>();
            foreach (var file in directoryInfo.GetFiles(searchPattern, searchOption)) {
                var filePath = file.FullName.Substring(directoryInfo.FullName.Length).TrimStart('\\');
                try {
                    var record = Record.FromBtrieveFile(Path.Relative(filePath, directoryInfo.FullName), dllPath, dependencyPaths, ownerName: ownerName);
                    record.RelativePath = filePath;
                    records.Add(record);
                } catch (OperationException e) {
                    if (e.StatusCode != 12 && e.StatusCode != 30) {
                        throw;
                    }
                }
            }
            var result = new Model();
            result.Name = name;
            result.PathType = PathType.Relative;
            result.RelativeDirectory = directoryInfo.FullName;
            result.DllPath = dllPath;
            result.DependencyPaths = dependencyPaths == null ? null : dependencyPaths.ToArray();
            result.Records = records.ToArray();
            result.Namespace = nameSpace ?? "BtrieveWrapper.Orm.Models.CustomModels";
            var i = 0;
            foreach (var record in result.Records) {
                Record.Initialize(record);
                record.Number = i++;
            }
            return result;
        }