コード例 #1
0
        private static void ProcessShxFiles(string path)
        {
            var files = Directory.GetFiles(path, "*.shx", SearchOption.TopDirectoryOnly);

            if (files.Length > 0)
            {
                using (var ctx = new FontsDbContext(Properties.Settings.Default.ShxConnStrings)) {
                    ctx.Configuration.AutoDetectChangesEnabled = true;
                    var machineName = Environment.MachineName;
                    var lds         = ctx.LoadDirectories.Where(d => d.FullPath.Equals(path, StringComparison.InvariantCultureIgnoreCase) &&
                                                                d.ComputerName.Equals(machineName, StringComparison.CurrentCultureIgnoreCase)).ToList();
                    LoadDirectory loadDir;
                    if (lds.Count == 0)
                    {
                        loadDir = new LoadDirectory {
                            FullPath = path, ComputerName = machineName
                        };
                        ctx.LoadDirectories.Add(loadDir);
                        ctx.SaveChanges();
                    }
                    else
                    {
                        loadDir = lds[0];
                    }
                    var tmpDir = CreateUniqueTempDirectory();
                    foreach (var file in files)
                    {
                        var fi      = new FileInfo(file);
                        var shpFile = Path.ChangeExtension(Path.Combine(tmpDir, fi.Name), ".SHP");
                        try {
                            if (File.Exists(shpFile))
                            {
                                File.Delete(shpFile);
                            }
                            var shxFile = new ShxFontFile {
                                ShxFileName = fi.Name,
                                ShxFileSize = (int)fi.Length,
                                ShxFileDate = fi.CreationTime,
                                Crc32       = Crc32OfFile(file),
                                Remarks     = "Before Read"
                            };
                            loadDir.ShxFontFiles.Add(shxFile);
                            ctx.SaveChanges();
                            var exitCode = -1;
                            using (var proc = new Process()) {
                                proc.StartInfo.FileName        = Properties.Settings.Default.DumpShxProgram;
                                proc.StartInfo.Arguments       = "-o \"" + shpFile + "\" \"" + fi + "\"";
                                proc.StartInfo.UseShellExecute = false;
                                proc.StartInfo.CreateNoWindow  = true;
                                proc.Start();
                                proc.WaitForExit(1000);
                                exitCode = proc.ExitCode;
                            }
                            if (exitCode == 0 && File.Exists(shpFile))
                            {
                                Console.WriteLine($"\t{shpFile}");
                                var shpFontFile = new ShpFontFile(ctx, shxFile);
                                shpFontFile.Parse(shpFile);
                            }
                        } catch (Exception ex) {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            }
        }
コード例 #2
0
 public ShpFontFile(FontsDbContext ctx, ShxFontFile shxFile)
 {
     this._ctx     = ctx;
     this._shxFile = shxFile;
 }