swithcboard <attribute name="value" type="string" />

This commit is contained in:
sergey 2013-06-03 16:06:00 +03:00
parent c0f13d3fd9
commit b62b699461

View file

@ -95,7 +95,9 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
{ {
if ((string)switchboardElement.GetAttributeValue("name") == "*") if ((string)switchboardElement.GetAttributeValue("name") == "*")
{ {
switchboardDisabledDefault = !(bool)switchboardElement.GetAttributeValue("enabled"); bool isEnabled = GetSwitchBoardValue(switchboardElement);
switchboardDisabledDefault = !isEnabled ;
break; break;
} }
} }
@ -149,7 +151,8 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
HeliconZooEngine item = Collection_GetHeliconZooEngineByName(result, (string)switchboardElement.GetAttributeValue("name")); HeliconZooEngine item = Collection_GetHeliconZooEngineByName(result, (string)switchboardElement.GetAttributeValue("name"));
if (item != null) if (item != null)
{ {
item.disabled = !(bool)switchboardElement.GetAttributeValue("enabled"); bool isEnabled = GetSwitchBoardValue(switchboardElement);
item.disabled = !isEnabled;
} }
else else
{ {
@ -165,6 +168,17 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
return result.ToArray(); return result.ToArray();
} }
private bool GetSwitchBoardValue(ConfigurationElement switchboardElement)
{
return (0 == String.Compare((string)switchboardElement.GetAttributeValue("value"),
"Enabled", StringComparison.OrdinalIgnoreCase));
}
private void SetSwitchBoardValue(ConfigurationElement switchboardElement, bool enabled)
{
switchboardElement.SetAttributeValue("value", enabled ? "Enabled" : "Disabled");
}
HeliconZooEngine Collection_GetHeliconZooEngineByName(List<HeliconZooEngine> collection, string name) HeliconZooEngine Collection_GetHeliconZooEngineByName(List<HeliconZooEngine> collection, string name)
{ {
foreach (HeliconZooEngine r in collection) foreach (HeliconZooEngine r in collection)
@ -200,14 +214,6 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
switchboardCollection.Clear(); switchboardCollection.Clear();
//Disable all engines, by default for WSP
/*
ConfigurationElement disableAll = switchboardCollection.CreateElement();
disableAll.SetAttributeValue("name", "*");
disableAll.SetAttributeValue("enabled", "false");
switchboardCollection.Add(disableAll);
*/
foreach(HeliconZooEngine item in userEngines) foreach(HeliconZooEngine item in userEngines)
{ {
@ -218,12 +224,7 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
enginesCollection.Add(engine); enginesCollection.Add(engine);
} }
/*
ConfigurationElement disable = switchboardCollection.CreateElement();
disable.SetAttributeValue("name", item.name );
disable.SetAttributeValue("enabled", item.disabled? "false": "true" );
switchboardCollection.Add(disable);
*/
} }
srvman.CommitChanges(); srvman.CommitChanges();
@ -249,7 +250,7 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
{ {
if ((string) switchboardElement.GetAttributeValue("name") == "*") if ((string) switchboardElement.GetAttributeValue("name") == "*")
{ {
isEnginesEnabled = (bool) switchboardElement.GetAttributeValue("enabled"); isEnginesEnabled = GetSwitchBoardValue(switchboardElement);
break; break;
} }
} }
@ -274,7 +275,7 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
{ {
if ((string)switchboardElement.GetAttributeValue("name") == "*") if ((string)switchboardElement.GetAttributeValue("name") == "*")
{ {
switchboardElement.SetAttributeValue("enabled", enabled ? "true" : "false"); switchboardElement.SetAttributeValue("value", enabled ? "Enabed" : "Disabled");
wildCardFound = true; wildCardFound = true;
break; break;
} }
@ -284,7 +285,7 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
{ {
ConfigurationElement element = switchboardCollection.CreateElement(); ConfigurationElement element = switchboardCollection.CreateElement();
element.SetAttributeValue("name", "*"); element.SetAttributeValue("name", "*");
element.SetAttributeValue("enabled", enabled ? "true" : "false"); SetSwitchBoardValue(element, enabled);
switchboardCollection.Add(element); switchboardCollection.Add(element);
} }
@ -321,8 +322,9 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
foreach (ConfigurationElement element in switchboardCollection) foreach (ConfigurationElement element in switchboardCollection)
{ {
string enabled = element.GetAttributeValue("enabled").ToString();
if (string.Equals(enabled, "true", StringComparison.OrdinalIgnoreCase)) bool isEnabled = GetSwitchBoardValue(element);
if (isEnabled)
{ {
engines.Add(element.GetAttributeValue("name").ToString()); engines.Add(element.GetAttributeValue("name").ToString());
} }
@ -350,14 +352,14 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
ConfigurationElement elementDisableAll = switchboardCollection.CreateElement(); ConfigurationElement elementDisableAll = switchboardCollection.CreateElement();
elementDisableAll.SetAttributeValue("name", "*"); elementDisableAll.SetAttributeValue("name", "*");
elementDisableAll.SetAttributeValue("enabled", "false"); SetSwitchBoardValue(elementDisableAll, false);
switchboardCollection.Add(elementDisableAll); switchboardCollection.Add(elementDisableAll);
foreach (string engineName in engineNames) foreach (string engineName in engineNames)
{ {
ConfigurationElement element = switchboardCollection.CreateElement(); ConfigurationElement element = switchboardCollection.CreateElement();
element.SetAttributeValue("name", engineName); element.SetAttributeValue("name", engineName);
element.SetAttributeValue("enabled", "true"); SetSwitchBoardValue(element, true);
switchboardCollection.Add(element); switchboardCollection.Add(element);
} }
@ -388,7 +390,7 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
{ {
if ((string)switchboardElement.GetAttributeValue("name") == "console") if ((string)switchboardElement.GetAttributeValue("name") == "console")
{ {
isEnginesEnabled = (bool)switchboardElement.GetAttributeValue("enabled"); isEnginesEnabled = GetSwitchBoardValue(switchboardElement);
break; break;
} }
} }
@ -413,7 +415,8 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
{ {
if ((string)switchboardElement.GetAttributeValue("name") == "console") if ((string)switchboardElement.GetAttributeValue("name") == "console")
{ {
switchboardElement.SetAttributeValue("enabled", enabled ? "true" : "false"); SetSwitchBoardValue(switchboardElement, enabled);
found = true; found = true;
break; break;
} }
@ -423,7 +426,7 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
{ {
ConfigurationElement element = switchboardCollection.CreateElement(); ConfigurationElement element = switchboardCollection.CreateElement();
element.SetAttributeValue("name", "console"); element.SetAttributeValue("name", "console");
element.SetAttributeValue("enabled", enabled ? "true" : "false"); SetSwitchBoardValue(element, enabled);
switchboardCollection.Add(element); switchboardCollection.Add(element);
} }
@ -431,6 +434,8 @@ namespace WebsitePanel.Providers.Web.HeliconZoo
} }
} }
#region private methods #region private methods
private void ConvertHeliconZooEngineToElement(HeliconZooEngine item, ConfigurationElement engine) private void ConvertHeliconZooEngineToElement(HeliconZooEngine item, ConfigurationElement engine)