foreach (GridViewRow giConfig in grdConfig.Rows)
{
XElement XConfigElement = new XElement("Configuration");
string configName = ((TextBox) giConfig.Cells[0].FindControl("txtConfigName")).Text;
XConfigElement.Add(new XAttribute("Name", configName));
string configValue = ((TextBox)giConfig.Cells[1].FindControl("txtConfigValue")).Text;
if(configName.ToLower().Equals("password"))
{
if (ViewState["password"] != null && !string.IsNullOrEmpty(ViewState["password"].ToString()))
{
string[] psdArray = ViewState["password"].ToString().Split('#');
configValue = psdArray[1];
XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
}else
XConfigElement.Add(new XAttribute("Encrypted", "false"));
}
if (configName.ToLower().Equals("servicesurl"))
{
if (ViewState["servicesUrl"] != null && !string.IsNullOrEmpty(ViewState["servicesUrl"].ToString()))
{
string[] psdArray = ViewState["servicesUrl"].ToString().Split('#');
configValue = psdArray[1];
XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
}
else
XConfigElement.Add(new XAttribute("Encrypted", "false"));
}
if (configName.ToLower().Equals("pollingobject"))
{
if (ViewState["PollingObject"] != null && !string.IsNullOrEmpty(ViewState["PollingObject"].ToString()))
{
string[] psdArray = ViewState["PollingObject"].ToString().Split('#');
configValue = psdArray[1];
XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
}
else
XConfigElement.Add(new XAttribute("Encrypted", "false"));
}
if (configName.ToLower().Equals("debug"))
{
if (ViewState["debug"] != null && !string.IsNullOrEmpty(ViewState["debug"].ToString()))
{
string[] psdArray = ViewState["debug"].ToString().Split('#');
configValue = psdArray[1];
XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
}
else
XConfigElement.Add(new XAttribute("Encrypted", "false"));
}
if (configName.ToLower().Equals("version"))
{
if (ViewState["version"] != null && !string.IsNullOrEmpty(ViewState["version"].ToString()))
{
string[] psdArray = ViewState["version"].ToString().Split('#');
configValue = psdArray[1];
XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
}
else
XConfigElement.Add(new XAttribute("Encrypted", "false"));
}
if (configName.ToLower().Equals("username"))
{
if (ViewState["username"] != null && !string.IsNullOrEmpty(ViewState["username"].ToString()))
{
string[] psdArray = ViewState["username"].ToString().Split('#');
configValue = psdArray[1];
XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
}
else
XConfigElement.Add(new XAttribute("Encrypted", "false"));
}
if (configName.ToLower().Equals("host"))
{
if (ViewState["host"] != null && !string.IsNullOrEmpty(ViewState["host"].ToString()))
{
string[] psdArray = ViewState["host"].ToString().Split('#');
configValue = psdArray[1];
XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
}
else
XConfigElement.Add(new XAttribute("Encrypted", "false"));
}
XConfigElement.Value = configValue;
XConfig.Add(XConfigElement);
}