Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
9.5 KiB

  1. a) Read AppDomain
  2. b) Read BindingPolicy
  3. c) Change AppDomain prop
  4. d) Add BindingPolicy
  5. e) Change BindingPolicy
  6. f) Remove BindingPolicy
  7. g) Query for binding policy
  8. //*******************************************************************************************
  9. // I: ConfigCollection/Item
  10. // a) Read AppDomain
  11. AppDomainSelector as = new AppDomainSelector();
  12. AppDomainConfigItem appdomain = ConfigManager.GetItem("AppDomain", as);
  13. Console.WriteLine(appdomain.ShadowCopy);
  14. // b) Read BindingPolicy
  15. AppDomainSelector as = new AppDomainSelector();
  16. IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
  17. // need to enable FOREACH!!!???
  18. for (int i=0; i<bindings.Count; i++)
  19. {
  20. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  21. Console.WriteLine(binding.Name);
  22. }
  23. // c) Change appdomain property
  24. AppDomainSelector as = new AppDomainSelector();
  25. ConfigManager.WriteProperty("AppDomain", as, "ShadowCopy", new Boolean(true));
  26. // change more than one property at a time
  27. AppDomainSelector as = new AppDomainSelector();
  28. ConfigManager.WriteProperty("AppDomain", as, "ShadowCopy", new Boolean(true));
  29. ConfigManager.WriteProperty("AppDomain", as, "SharedPath", "c:\temp");
  30. AppDomainSelector as = new AppDomainSelector();
  31. AppDomainConfigItem appdomain = ConfigManager.GetItem("AppDomain", as);
  32. appdomain.ShadowCopy=False;
  33. appdomain.SharedPath="c:\temp";
  34. ConfigManager.WriteItem(as, appdomain);
  35. // d) Add binding policy
  36. AppDomainSelector as = new AppDomainSelector();
  37. IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
  38. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) ConfigManager.GetEmptyConfigItem("BindingPolicy");
  39. bindings.Add(binding);
  40. ConfigManager.Write(as, bindings);
  41. // e) Change BindingPolicy
  42. AppDomainSelector as = new AppDomainSelector();
  43. IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
  44. // need to enable FOREACH!!!???
  45. for (int i=0; i<bindings.Count; i++)
  46. {
  47. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  48. binding.UseLatestBuildRevision=false;
  49. }
  50. ConfigManager.Write(as, bindings);
  51. // f) Remove BindingPolicy
  52. AppDomainSelector as = new AppDomainSelector();
  53. IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
  54. // need to enable FOREACH!!!???
  55. String[] key = new String[3];
  56. key[0]="g_SglAsm_SglMod1.dll";
  57. key[1]="8e47bf1a5ed0ec84";
  58. key[2]="*";
  59. bindings.RemoveByKey(key);
  60. ConfigManager.Write(as, bindings);
  61. for (int i=0; i<bindings.Count; i++)
  62. {
  63. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  64. if (binding.Name=="g_SglAsm_SglMod1.dll") {
  65. bindings.Remove(i);
  66. break;
  67. }
  68. }
  69. ConfigManager.Write(as, bindings);
  70. // g) Query for binding policy
  71. AppDomainSelector as = new AppDomainSelector();
  72. QuerySelector qs = new QuerySelector("Name=g_SglAsm_SglMod1.dll", as);
  73. IConfigCollection bindings = ConfigManager.Get("BindingPolicy", qs);
  74. // need to enable FOREACH!!!???
  75. for (int i=0; i<bindings.Count; i++)
  76. {
  77. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  78. Console.WriteLine(binding.Name);
  79. }
  80. //*******************************************************************************************
  81. // II: ConfigManager Add/Remove/Set
  82. // a) Read AppDomain
  83. AppDomainSelector as = new AppDomainSelector();
  84. AppDomainConfigItem appdomain = ConfigManager.GetItem("AppDomain", as);
  85. Console.WriteLine(appdomain.ShadowCopy);
  86. // b) Read BindingPolicy
  87. AppDomainSelector as = new AppDomainSelector();
  88. IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
  89. // need to enable FOREACH!!!???
  90. for (int i=0; i<bindings.Count; i++)
  91. {
  92. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  93. Console.WriteLine(binding.Name);
  94. }
  95. // c) Change appdomain property
  96. AppDomainSelector as = new AppDomainSelector();
  97. ConfigManager.WriteProperty("AppDomain", as, "ShadowCopy", new Boolean(true));
  98. // change more than one property at a time
  99. AppDomainSelector as = new AppDomainSelector();
  100. ConfigManager.SetProperty("AppDomain", as, "ShadowCopy", new Boolean(true));
  101. ConfigManager.SetProperty("AppDomain", as, "SharedPath", "c:\temp");
  102. AppDomainSelector as = new AppDomainSelector();
  103. AppDomainConfigItem appdomain = ConfigManager.GetItem("AppDomain", as);
  104. appdomain.ShadowCopy=False;
  105. appdomain.SharedPath="c:\temp";
  106. ConfigManager.SetItem(as, appdomain);
  107. // d) Add binding policy
  108. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) ConfigManager.GetEmptyConfigItem("BindingPolicy");
  109. AppDomainSelector as = new AppDomainSelector();
  110. ConfigManger.AddItem(as, binding);
  111. // e) Change BindingPolicy
  112. AppDomainSelector as = new AppDomainSelector();
  113. IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
  114. // need to enable FOREACH!!!???
  115. for (int i=0; i<bindings.Count; i++)
  116. {
  117. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  118. binding.UseLatestBuildRevision=false;
  119. }
  120. ConfigManager.Set(as, bindings);
  121. // f) Remove BindingPolicy
  122. String[] key = new String[3];
  123. key[0]="g_SglAsm_SglMod1.dll";
  124. key[1]="8e47bf1a5ed0ec84";
  125. key[2]="*";
  126. AppDomainSelector as = new AppDomainSelector();
  127. ConfigManager.RemoveByKey(as, key);
  128. // alternate
  129. AppDomainSelector as = new AppDomainSelector();
  130. IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
  131. for (int i=0; i<bindings.Count; i++)
  132. {
  133. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  134. if (binding.Name=="g_SglAsm_SglMod1.dll") {
  135. ConfigManager.RemoveItem(as, binding);
  136. break;
  137. }
  138. }
  139. // g) Query for binding policy
  140. AppDomainSelector as = new AppDomainSelector();
  141. QuerySelector qs = new QuerySelector("Name=g_SglAsm_SglMod1.dll", as);
  142. IConfigCollection bindings = ConfigManager.Get("BindingPolicy", qs);
  143. // need to enable FOREACH!!!???
  144. for (int i=0; i<bindings.Count; i++)
  145. {
  146. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  147. Console.WriteLine(binding.Name);
  148. }
  149. //*******************************************************************************************
  150. // III: ConfigStore Add/Remove/Set/Save
  151. // a) Read AppDomain
  152. AppDomainSettingsStore as = new AppDomainSettingsStore();
  153. AppDomainConfigItem appdomain = as.GetItem("AppDomain");
  154. Console.WriteLine(appdomain.ShadowCopy);
  155. // b) Read BindingPolicy
  156. AppDomainSettingsStore as = new AppDomainSettingsStore();
  157. IConfigCollection bindings = as.Get("BindingPolicy");
  158. // need to enable FOREACH!!!???
  159. for (int i=0; i<bindings.Count; i++)
  160. {
  161. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  162. Console.WriteLine(binding.Name);
  163. }
  164. // c) Change appdomain property
  165. AppDomainSettingsStore as = new AppDomainSettingsStore();
  166. as.SetProperty("AppDomain", "ShadowCopy", new Boolean(true));
  167. as.Save();
  168. // change more than one property at a time
  169. AppDomainSettingsStore as = new AppDomainSettingsStore();
  170. as.SetProperty("AppDomain", "ShadowCopy", new Boolean(true));
  171. as.SetProperty("AppDomain", "SharedPath", "c:\temp");
  172. as.Save();
  173. AppDomainSettingsStore as = new AppDomainSettingsStore();
  174. AppDomainConfigItem appdomain = as.GetItem("AppDomain");
  175. appdomain.ShadowCopy=False;
  176. appdomain.SharedPath="c:\temp";
  177. as.SetItem(appdomain);
  178. as.Save();
  179. // d) Add binding policy
  180. AppDomainSettingsStore as = new AppDomainSettingsStore();
  181. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) as.GetEmptyConfigItem("BindingPolicy");
  182. // alternative:
  183. BindingPolicyConfigItem binding = new BindingPolicyConfigItem();
  184. IConfigItem item = new BaseConfigItem(String ConfigType);
  185. as.AddItem(binding);
  186. as.Save();
  187. // e) Change BindingPolicy
  188. AppDomainSettingsStore as = new AppDomainSettingsStore();
  189. IConfigCollection bindings = as.Get("BindingPolicy");
  190. // need to enable FOREACH!!!???
  191. for (int i=0; i<bindings.Count; i++)
  192. {
  193. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  194. binding.UseLatestBuildRevision=false;
  195. }
  196. as.Set(bindings);
  197. as.Save();
  198. // f) Remove BindingPolicy
  199. String[] key = new String[3];
  200. key[0]="g_SglAsm_SglMod1.dll";
  201. key[1]="8e47bf1a5ed0ec84";
  202. key[2]="*";
  203. AppDomainSettingsStore as = new AppDomainSettingsStore();
  204. as.RemoveByKey(key);
  205. as.Save();
  206. // alternate
  207. AppDomainSettingsStore as = new AppDomainSettingsStore();
  208. IConfigCollection bindings = as.Get("BindingPolicy");
  209. for (int i=0; i<bindings.Count; i++)
  210. {
  211. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  212. if (binding.Name=="g_SglAsm_SglMod1.dll") {
  213. as.RemoveItem(binding);
  214. break;
  215. }
  216. }
  217. as.Save();
  218. // g) Query for binding policy
  219. AppDomainSettingsStore as = new AppDomainSettingsStore();
  220. Query query = new Query("ConfigType=BindingPolicy AND Name=g_SglAsm_SglMod1.dll");
  221. Query query = new Query("BindingPolicy", "Name=g_SglAsm_SglMod1.dll");
  222. IConfigCollection bindings = as.Get(query);
  223. // need to enable FOREACH!!!???
  224. for (int i=0; i<bindings.Count; i++)
  225. {
  226. BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
  227. Console.WriteLine(binding.Name);
  228. }
  229. class Store {
  230. IConfigCollection Get(String ConfigType);
  231. IConfigCollection Get(Query query);
  232. IConfigItem GetItem(String ConfigType);
  233. IConfigItem GetItem(Query query);
  234. Object GetProperty(String ConfigType, String PropertyName);
  235. Object GetProperty(Query query, String PropertyName);
  236. void Add(IConfigCollection coll);
  237. void AddItem(IConfigItem item);
  238. void Remove(IConfigCollection coll);
  239. void RemoveItem(IConfigItem item);
  240. void RemoveByKey(String ConfigType, String key);
  241. void RemoveByKey(String ConfigType, Object[] key);
  242. void Set(IConfigCollection coll);
  243. void SetItem(IConfigItem item);
  244. void SetProperty(String ConfigType, String PropertyName, Object Value);
  245. void SetProperty(Query query, String PropertyName, Object Value);
  246. void Save();
  247. }
  248. class AppDomainConfigItem {
  249. AppDomainConfigItem();
  250. }
  251. class BaseConfigItem {
  252. BaseConfigItem(String ConfigType);
  253. }