311 lines
9.5 KiB
Plaintext
311 lines
9.5 KiB
Plaintext
a) Read AppDomain
|
|
b) Read BindingPolicy
|
|
c) Change AppDomain prop
|
|
d) Add BindingPolicy
|
|
e) Change BindingPolicy
|
|
f) Remove BindingPolicy
|
|
g) Query for binding policy
|
|
|
|
//*******************************************************************************************
|
|
// I: ConfigCollection/Item
|
|
// a) Read AppDomain
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
AppDomainConfigItem appdomain = ConfigManager.GetItem("AppDomain", as);
|
|
Console.WriteLine(appdomain.ShadowCopy);
|
|
|
|
// b) Read BindingPolicy
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
|
|
// need to enable FOREACH!!!???
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
Console.WriteLine(binding.Name);
|
|
}
|
|
|
|
// c) Change appdomain property
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
ConfigManager.WriteProperty("AppDomain", as, "ShadowCopy", new Boolean(true));
|
|
|
|
// change more than one property at a time
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
ConfigManager.WriteProperty("AppDomain", as, "ShadowCopy", new Boolean(true));
|
|
ConfigManager.WriteProperty("AppDomain", as, "SharedPath", "c:\temp");
|
|
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
AppDomainConfigItem appdomain = ConfigManager.GetItem("AppDomain", as);
|
|
appdomain.ShadowCopy=False;
|
|
appdomain.SharedPath="c:\temp";
|
|
ConfigManager.WriteItem(as, appdomain);
|
|
|
|
// d) Add binding policy
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
|
|
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) ConfigManager.GetEmptyConfigItem("BindingPolicy");
|
|
|
|
bindings.Add(binding);
|
|
|
|
ConfigManager.Write(as, bindings);
|
|
|
|
// e) Change BindingPolicy
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
|
|
// need to enable FOREACH!!!???
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
binding.UseLatestBuildRevision=false;
|
|
}
|
|
|
|
ConfigManager.Write(as, bindings);
|
|
|
|
|
|
// f) Remove BindingPolicy
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
|
|
// need to enable FOREACH!!!???
|
|
String[] key = new String[3];
|
|
key[0]="g_SglAsm_SglMod1.dll";
|
|
key[1]="8e47bf1a5ed0ec84";
|
|
key[2]="*";
|
|
bindings.RemoveByKey(key);
|
|
ConfigManager.Write(as, bindings);
|
|
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
if (binding.Name=="g_SglAsm_SglMod1.dll") {
|
|
bindings.Remove(i);
|
|
break;
|
|
}
|
|
}
|
|
|
|
ConfigManager.Write(as, bindings);
|
|
|
|
// g) Query for binding policy
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
QuerySelector qs = new QuerySelector("Name=g_SglAsm_SglMod1.dll", as);
|
|
|
|
IConfigCollection bindings = ConfigManager.Get("BindingPolicy", qs);
|
|
// need to enable FOREACH!!!???
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
Console.WriteLine(binding.Name);
|
|
}
|
|
|
|
|
|
|
|
//*******************************************************************************************
|
|
// II: ConfigManager Add/Remove/Set
|
|
// a) Read AppDomain
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
AppDomainConfigItem appdomain = ConfigManager.GetItem("AppDomain", as);
|
|
Console.WriteLine(appdomain.ShadowCopy);
|
|
|
|
// b) Read BindingPolicy
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
|
|
// need to enable FOREACH!!!???
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
Console.WriteLine(binding.Name);
|
|
}
|
|
|
|
// c) Change appdomain property
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
ConfigManager.WriteProperty("AppDomain", as, "ShadowCopy", new Boolean(true));
|
|
|
|
// change more than one property at a time
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
ConfigManager.SetProperty("AppDomain", as, "ShadowCopy", new Boolean(true));
|
|
ConfigManager.SetProperty("AppDomain", as, "SharedPath", "c:\temp");
|
|
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
AppDomainConfigItem appdomain = ConfigManager.GetItem("AppDomain", as);
|
|
appdomain.ShadowCopy=False;
|
|
appdomain.SharedPath="c:\temp";
|
|
ConfigManager.SetItem(as, appdomain);
|
|
|
|
// d) Add binding policy
|
|
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) ConfigManager.GetEmptyConfigItem("BindingPolicy");
|
|
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
ConfigManger.AddItem(as, binding);
|
|
|
|
// e) Change BindingPolicy
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
|
|
// need to enable FOREACH!!!???
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
binding.UseLatestBuildRevision=false;
|
|
}
|
|
ConfigManager.Set(as, bindings);
|
|
|
|
// f) Remove BindingPolicy
|
|
String[] key = new String[3];
|
|
key[0]="g_SglAsm_SglMod1.dll";
|
|
key[1]="8e47bf1a5ed0ec84";
|
|
key[2]="*";
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
ConfigManager.RemoveByKey(as, key);
|
|
|
|
// alternate
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
IConfigCollection bindings = ConfigManager.Get("BindingPolicy", as);
|
|
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
if (binding.Name=="g_SglAsm_SglMod1.dll") {
|
|
ConfigManager.RemoveItem(as, binding);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// g) Query for binding policy
|
|
AppDomainSelector as = new AppDomainSelector();
|
|
QuerySelector qs = new QuerySelector("Name=g_SglAsm_SglMod1.dll", as);
|
|
|
|
IConfigCollection bindings = ConfigManager.Get("BindingPolicy", qs);
|
|
// need to enable FOREACH!!!???
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
Console.WriteLine(binding.Name);
|
|
}
|
|
|
|
|
|
//*******************************************************************************************
|
|
// III: ConfigStore Add/Remove/Set/Save
|
|
// a) Read AppDomain
|
|
AppDomainSettingsStore as = new AppDomainSettingsStore();
|
|
AppDomainConfigItem appdomain = as.GetItem("AppDomain");
|
|
Console.WriteLine(appdomain.ShadowCopy);
|
|
|
|
// b) Read BindingPolicy
|
|
AppDomainSettingsStore as = new AppDomainSettingsStore();
|
|
IConfigCollection bindings = as.Get("BindingPolicy");
|
|
// need to enable FOREACH!!!???
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
Console.WriteLine(binding.Name);
|
|
}
|
|
|
|
// c) Change appdomain property
|
|
AppDomainSettingsStore as = new AppDomainSettingsStore();
|
|
as.SetProperty("AppDomain", "ShadowCopy", new Boolean(true));
|
|
as.Save();
|
|
|
|
// change more than one property at a time
|
|
AppDomainSettingsStore as = new AppDomainSettingsStore();
|
|
as.SetProperty("AppDomain", "ShadowCopy", new Boolean(true));
|
|
as.SetProperty("AppDomain", "SharedPath", "c:\temp");
|
|
as.Save();
|
|
|
|
AppDomainSettingsStore as = new AppDomainSettingsStore();
|
|
AppDomainConfigItem appdomain = as.GetItem("AppDomain");
|
|
appdomain.ShadowCopy=False;
|
|
appdomain.SharedPath="c:\temp";
|
|
as.SetItem(appdomain);
|
|
as.Save();
|
|
|
|
// d) Add binding policy
|
|
AppDomainSettingsStore as = new AppDomainSettingsStore();
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) as.GetEmptyConfigItem("BindingPolicy");
|
|
|
|
// alternative:
|
|
BindingPolicyConfigItem binding = new BindingPolicyConfigItem();
|
|
IConfigItem item = new BaseConfigItem(String ConfigType);
|
|
|
|
as.AddItem(binding);
|
|
as.Save();
|
|
|
|
// e) Change BindingPolicy
|
|
AppDomainSettingsStore as = new AppDomainSettingsStore();
|
|
IConfigCollection bindings = as.Get("BindingPolicy");
|
|
// need to enable FOREACH!!!???
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
binding.UseLatestBuildRevision=false;
|
|
}
|
|
as.Set(bindings);
|
|
as.Save();
|
|
|
|
// f) Remove BindingPolicy
|
|
String[] key = new String[3];
|
|
key[0]="g_SglAsm_SglMod1.dll";
|
|
key[1]="8e47bf1a5ed0ec84";
|
|
key[2]="*";
|
|
AppDomainSettingsStore as = new AppDomainSettingsStore();
|
|
as.RemoveByKey(key);
|
|
as.Save();
|
|
|
|
// alternate
|
|
AppDomainSettingsStore as = new AppDomainSettingsStore();
|
|
IConfigCollection bindings = as.Get("BindingPolicy");
|
|
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
if (binding.Name=="g_SglAsm_SglMod1.dll") {
|
|
as.RemoveItem(binding);
|
|
break;
|
|
}
|
|
}
|
|
as.Save();
|
|
|
|
// g) Query for binding policy
|
|
AppDomainSettingsStore as = new AppDomainSettingsStore();
|
|
Query query = new Query("ConfigType=BindingPolicy AND Name=g_SglAsm_SglMod1.dll");
|
|
Query query = new Query("BindingPolicy", "Name=g_SglAsm_SglMod1.dll");
|
|
|
|
IConfigCollection bindings = as.Get(query);
|
|
// need to enable FOREACH!!!???
|
|
for (int i=0; i<bindings.Count; i++)
|
|
{
|
|
BindingPolicyConfigItem binding = (BindingPolicyConfigItem) bindings[i];
|
|
Console.WriteLine(binding.Name);
|
|
}
|
|
|
|
class Store {
|
|
IConfigCollection Get(String ConfigType);
|
|
IConfigCollection Get(Query query);
|
|
|
|
IConfigItem GetItem(String ConfigType);
|
|
IConfigItem GetItem(Query query);
|
|
|
|
Object GetProperty(String ConfigType, String PropertyName);
|
|
Object GetProperty(Query query, String PropertyName);
|
|
|
|
void Add(IConfigCollection coll);
|
|
void AddItem(IConfigItem item);
|
|
|
|
void Remove(IConfigCollection coll);
|
|
void RemoveItem(IConfigItem item);
|
|
void RemoveByKey(String ConfigType, String key);
|
|
void RemoveByKey(String ConfigType, Object[] key);
|
|
|
|
void Set(IConfigCollection coll);
|
|
void SetItem(IConfigItem item);
|
|
void SetProperty(String ConfigType, String PropertyName, Object Value);
|
|
void SetProperty(Query query, String PropertyName, Object Value);
|
|
|
|
void Save();
|
|
}
|
|
|
|
class AppDomainConfigItem {
|
|
AppDomainConfigItem();
|
|
}
|
|
|
|
class BaseConfigItem {
|
|
BaseConfigItem(String ConfigType);
|
|
}
|