WIL説明書(.NET)  3.1.0
DisplayConverter の作成要領

1. コンソールアプリケーションの作成
Visual Studio のプロジェクトの新規作成でコンソールアプリケーションを作成します。

imageview_form_error-4-1.png

下記3箇所の編集を行います。
(2) 参照設定の追加
(3) アプリケーション構成ファイルの設定
(4) ソースコード

imageview_form_error-4-1map.png

2. 参照設定の追加
WIL 3.1 のアセンブリを参照設定に追加します。

imageview_form_error-4-2.png

3. アプリケーション構成ファイルの設定
WIL 3.0 のインスタンスを WIL 3.1 の型へキャストする際に例外を発生させないためにバージョンリダイレクトの設定を行います。

▽ app.config:

1 <?xml version="1.0" encoding="utf-8" ?>
2 <configuration>
3  <startup>
4  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5  </startup>
6  <runtime>
7  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8  <dependentAssembly>
9  <assemblyIdentity name="fvalgcli" publicKeyToken="20bef69103785603" culture="neutral" />
10  <bindingRedirect oldVersion="3.0.0.0" newVersion="3.1.0.0"/>
11  </dependentAssembly>
12  <dependentAssembly>
13  <assemblyIdentity name="FVILbasic" publicKeyToken="6b92ad76edadb73c" culture="neutral" />
14  <bindingRedirect oldVersion="3.0.0.0" newVersion="3.1.0.0"/>
15  </dependentAssembly>
16  <dependentAssembly>
17  <assemblyIdentity name="FVILdevice" publicKeyToken="46550952301e8a49" culture="neutral" />
18  <bindingRedirect oldVersion="3.0.0.0" newVersion="3.1.0.0"/>
19  </dependentAssembly>
20  <dependentAssembly>
21  <assemblyIdentity name="FVILforms" publicKeyToken="2b3e48e63fd7f1a8" culture="neutral" />
22  <bindingRedirect oldVersion="3.0.0.0" newVersion="3.1.0.0"/>
23  </dependentAssembly>
24  </assemblyBinding>
25  </runtime>
26 </configuration>

4. ソースコード
カレントディレクトリまたは引数に指定されたディレクトリの配下の XML リソースファイル (.resx 拡張子) を探索して、 各リソースファイル内の FVIL.GDI.CFviDisplay のインスタンスを一旦デコードして再度エンコードし直す処理です。

▽ Program.cs:

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6 using System.Reflection;
7 
8 namespace DisplayConverter
9 {
10  public class Program
11  {
12  [STAThread]
13  static void Main(string[] args)
14  {
15  FVIL._SetUp.InitVisionLibrary();
16 
17  string dir = "";
18  if (args.Length < 1)
19  {
20  dir = System.IO.Directory.GetCurrentDirectory();
21  }
22  else
23  {
24  dir = args[0];
25  }
26 
27  var paths = new List<string>();
28  Find(dir, paths);
29 
30  if (paths.Count == 0)
31  {
32  Console.WriteLine("The corresponding file was not found.");
33  }
34  else
35  {
36  ulong file_counter = 0;
37  foreach (var item in paths)
38  {
39  Console.WriteLine("{0}", item);
40  if (Convert(item))
41  file_counter++;
42  }
43  switch (file_counter)
44  {
45  case 0: Console.WriteLine("File conversion was not done."); break;
46  case 1: Console.WriteLine("One file was converted."); break;
47  default: Console.WriteLine("{0} files were converted.", file_counter); break;
48  }
49  }
50 
51  FVIL._SetUp.ExitVisionLibrary();
52  }
53 
54  static void Find(string dir, List<string> paths)
55  {
56  if (string.IsNullOrWhiteSpace(dir)) return;
57  if (System.IO.Directory.Exists(dir) == false)
58  {
59  Console.WriteLine("error: The specified directory is not exist.");
60  return;
61  }
62 
63  var files = System.IO.Directory.GetFiles(dir, "*.resx");
64  paths.AddRange(files);
65 
66  var dirs = System.IO.Directory.GetDirectories(dir);
67  foreach (var item in dirs)
68  {
69  Find(item, paths);
70  }
71  }
72 
73  static bool Convert(string filename)
74  {
75  var found = false;
76  var tempfile = filename + ".converted";
77 
78  using (var src_resx = new System.Resources.ResXResourceSet(filename))
79  using (var dst_resx = new System.Resources.ResXResourceWriter(tempfile))
80  {
81  foreach (System.Collections.DictionaryEntry entry in src_resx)
82  {
83  if (entry.Value.GetType().FullName == "FVIL.GDI.CFviDisplay")
84  found = true;
85  dst_resx.AddResource((string)entry.Key, entry.Value);
86  }
87  }
88 
89  if (found)
90  {
91  System.IO.File.Move(filename, filename + ".old");
92  System.IO.File.Move(tempfile, filename);
93  }
94  else
95  {
96  System.IO.File.Delete(tempfile);
97  }
98 
99  return found;
100  }
101  }
102 }

Documentation copyright © 2008 FAST Corporation. [B-001864]
Generated on 2024年10月10日(木) 10時07分52秒 for WIL説明書(.NET) by doxygen 1.8.11