private void successPersisted(string supplmentmessage, ServiceUsers updateUser)
        {
            if (supplmentmessage == null)
                supplmentmessage = "<span style=\"color:PaleGreen \">The user was sucessfully " + actiontext + ".</span>";
            else
                supplmentmessage = "<span style=\"color:Maroon\">" + supplmentmessage + ".</span>";
            SessionInfo info = new SessionInfo();
            string hostnameSession = null;
            string confignameSession = null;
            info.getHostNameConfigName(out hostnameSession, out confignameSession);
            if (oldUser != null && oldUser.UserKey == user.UserKey && (hostnameSession.Equals(hostNameIdentifier) && confignameSession.Equals(configName)))
            {
                string addressSes = null;
                string IDSes = null;
                ServiceUsers csUserSes = null;
                string confignameSes = null;
                string hosterSes = null;
                string versionSes = null;
                string platformSes = null;
                string clientSession = null;
                string nameSes = null;
                info.getSessionData(false, out addressSes, out csUserSes, out clientSession, out nameSes, out confignameSes, out hosterSes, out versionSes, out platformSes, out IDSes);
                HttpCookie cookie = info.setSessionData(addressSes, updateUser, clientSession, nameSes, confignameSes, hosterSes, versionSes, platformSes,IDSes);
                Response.Cookies.Remove(cookie.Name);
                Response.Cookies.Add(cookie);
                user = updateUser;
            }
            userList = configProxy.getServiceUsers(hostNameIdentifier, configName, traversePath, user);
            if (userList == null)
                Response.Redirect(ConfigSettings.PAGE_NODES, true);
            if (action.Equals(ConfigUtility.ADD_USER))
                thisUser = userList.Find(delegate(ServiceUsers userExist) { return userExist.UserId.ToLower().Equals(updateUser.UserId.ToLower()) && userExist.LocalUser == updateUser.LocalUser && userExist.Password.Equals(updateUser.Password); });
            else
                if (action.Equals(ConfigUtility.UPDATE_USER))
                    thisUser = userList.Find(delegate(ServiceUsers userExist) { return userExist.UserKey == thisUser.UserKey; });
            UpdateMessage.Text = supplmentmessage;
            if (action == ConfigUtility.REMOVE_USER && !oldUser.LocalUser)
                UpdateMessage.Text = UpdateMessage.Text + "<br>Note that all Connected Service Definitions and corresponding active Connection Point instances associated with the Connected Service user have also been removed from the configuration database.";
            ViewState["thisUser"] = thisUser;
            ViewState["oldUser"] = thisUser;
            ViewState["identify"] = thisUser.UserKey.ToString();
            if (action.Equals(ConfigUtility.ADD_USER))
            {
                Add.Enabled = false;
                Update.Enabled = true;
                Delete.Enabled = true;
            }
            if (action.Equals(ConfigUtility.REMOVE_USER))
            {
                Add.Enabled = false;
                Update.Enabled = false;
                Delete.Enabled = false;
            }
            ViewState["userList"] = userList;
            action = ConfigUtility.UPDATE_USER;
            ViewState["action"] = action;
            ViewState["CompositeServiceData"] = null;

        }
        private void processUpdate()
        {
            if (!checkPorts())
            {
                UpdateMessage.Text = UpdateMessage.Text + "<br/><span style=\"color:Yellow \">You are already using the same port for another endpoint with a different" +
                " network scheme (protocol) within this service host. You must choose a different port.</span>";
                return;
            }
            int success = ConfigUtility.CLUSTER_UPDATE_FULL_SUCCESS;
            UpdateMessage.Text = "";
            LabelBaseAddressWarning.Text = "";
            List<HostedServices> thisServiceHostServices = compositeServiceData[0].HostedServices.FindAll(delegate(HostedServices hsExist) { return hsExist.ServiceHostID == SHID; });
            if (!validateBaseAddresses(thisServiceHostServices, action))
                return;
            Page.Validate();
            if (!Page.IsValid)
                return;
            if (DropDownListBindingConfig.Items.Count == 0 || DropDownListInternalClient.Items.Count == 0)
            {
                UpdateMessage.Text = "You must ensure this host has valid Binding Configurations for both the host binding and the internal client binding defined in it's config file.  Currently, for the selected binding type, this is not the case. Please see tutorial: Binding Configurations names must be prefaced with 'Host_' and 'Client_' to appear properly in this page.";
                UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                return;
            }
            HostedServices updateHostedService = new HostedServices();
            if (TextBoxOnlineMethod.Text.Trim() == null || TextBoxOnlineMethod.Text.Trim() == "")
                updateHostedService.OnlineMethod = ConfigUtility.NO_ONLINE_METHOD;
            else
                updateHostedService.OnlineMethod = TextBoxOnlineMethod.Text;
            if (CheckBoxOnlineParms.Checked)
                updateHostedService.OnlineParms = TextBoxOnlineParms.Text;
            else
                updateHostedService.OnlineParms = ConfigUtility.NO_ONLINE_PARMS;
            switch (thisServiceHost.ServiceType)
            {
                case ConfigUtility.HOST_TYPE_CONFIG:
                    {
                        if (action == ConfigUtility.REMOVE_HOSTED_SERVICE || action == ConfigUtility.UPDATE_HOSTED_SERVICE)
                        {
                            List<HostedServices> configList = compositeServiceData[0].HostedServices.FindAll(delegate(HostedServices hsExist) { return hsExist.ServiceType == ConfigUtility.HOST_TYPE_CONFIG; });
                            if (configList.Count < 2 && action == ConfigUtility.REMOVE_HOSTED_SERVICE)
                            {
                                if (action == ConfigUtility.REMOVE_HOSTED_SERVICE || !CheckBoxActivate.Checked)
                                    UpdateMessage.Text = "You must have at least one active Configuration Service Endpoint!";
                                UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                                CheckBoxActivate.Checked = true;
                                return;
                            }
                        }
                        break;
                    }
                case ConfigUtility.HOST_TYPE_NODE:
                    {
                        ConfigurationKeyValues activeNodeID = compositeServiceData[0].ConfigurationData.Find(delegate(ConfigurationKeyValues keyExist) { return keyExist.ConfigurationKeyFieldName == "NODE_ACTIVE_SERVICE_ID"; });
                        if (activeNodeID.ConfigurationKeyValue.Equals(thisService.HostedServiceID.ToString()))
                        {
                            if (!CheckBoxActivate.Checked)
                            {
                                UpdateMessage.Text = "You cannot deactivate the configured Active Node Endpoint!";
                                UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                                CheckBoxActivate.Checked = true;
                                return;
                            }
                            if (action == ConfigUtility.REMOVE_HOSTED_SERVICE)
                            {
                                UpdateMessage.Text = "You cannot delete the configured Active Node Endpoint!";
                                UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                                return;
                            }
                            if (DropDownListInternalClient.SelectedValue.Equals(ConfigUtility.NO_CLIENT_CONFIGURATION))
                            {

                                UpdateMessage.Text = "You cannot define an Active Node Service Endpoint without selecting a valid Internal Client Configuration from your existing definitions in the applications 'client' section of config.  Please either select an existing client configuration above, or add a new client definition to your configuration if needed.";
                                UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                                return;
                            }
                        }
                        break;
                    }

                case ConfigUtility.HOST_TYPE_NODE_DC:
                    {
                        ConfigurationKeyValues activeNodeDCID = compositeServiceData[0].ConfigurationData.Find(delegate(ConfigurationKeyValues keyExist) { return keyExist.ConfigurationKeyFieldName == "NODE_ACTIVE_DC_SERVICE_ID"; });
                        if (activeNodeDCID.ConfigurationKeyValue.Equals(thisService.HostedServiceID.ToString()))
                        {
                            if (!CheckBoxActivate.Checked)
                            {
                                UpdateMessage.Text = "You cannot deactivate the configured Active Node Distributed Cache Endpoint!";
                                UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                                CheckBoxActivate.Checked = true;
                                return;
                            }
                            if (action == ConfigUtility.REMOVE_HOSTED_SERVICE)
                            {
                                UpdateMessage.Text = "You cannot delete the configured Active Node Distributed Cache Endpoint!";
                                UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                                return;
                            }
                            if (DropDownListInternalClient.SelectedValue.Equals(ConfigUtility.NO_CLIENT_CONFIGURATION))
                            {

                                UpdateMessage.Text = "You cannot define an Active Node DC Service Endpoint without selecting a valid Internal Client Configuration from your existing definitions in the applications 'client' section of config.  Please either select an existing client configuration above, or add a new client definition to your configuration if needed.";
                                UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                                return;
                            }
                        }
                        break;
                    }
            }
            if (CheckBoxActivate.Checked)
                updateHostedService.Activated = true;
            else
                updateHostedService.Activated = false;
            updateHostedService.BindingType = RadioButtonListBindingType.SelectedValue;
            updateHostedService.UseHttps = CheckBoxHttps.Checked;
            updateHostedService.VirtualPath = TextBoxVirtualPath.Text.ToLower().Trim().Trim(new char[] { '/' });
            TextBoxVirtualPath.Text = updateHostedService.VirtualPath;
            int port = -1;
            try
            {
                port = Convert.ToInt32(TextBoxPort.Text.Trim().Trim(new char[] { ':' }));
            }
            catch
            {
                UpdateMessage.Text = "You must specify a port in the form of an integer!";
                UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                return;
            }
            if (updateHostedService.BindingType != ConfigUtility.NET_MSMQ_BINDING && updateHostedService.BindingType != ConfigUtility.CUSTOM_BINDING_NET_MSMQ)
            {
                if (port < 80 || port > 65534)
                {
                    UpdateMessage.Text = "You must specify a port between 80 and 65534!";
                    UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                    return;
                }
            }
            if (!CheckBoxIdentity.Checked)
                updateHostedService.IdentityConfigName = ConfigUtility.NO_ENDPOINT_IDENTITY;
            else
                updateHostedService.IdentityConfigName = DropDownListIdentity.SelectedValue;
            updateHostedService.Port = TextBoxPort.Text.Trim().Trim(new char[] { ':' });
            TextBoxPort.Text = updateHostedService.Port;
            if (thisServiceHost.ServiceType == ConfigUtility.HOST_TYPE_PRIMARY || thisServiceHost.ServiceType == ConfigUtility.HOST_TYPE_CONFIG)
            {
                int userKey = -1;
                if (DropDownListCsUser.Items.Count > 0)
                    userKey = Convert.ToInt32(DropDownListCsUser.SelectedValue);
                updateHostedService.csUserKey = userKey;
            }
            else
                updateHostedService.csUserKey = -1;
            string scheme = ConfigUtility.getBindingScheme(updateHostedService.BindingType, updateHostedService.UseHttps);
            string defaultAddress = null;
            if (DropDownListEPB.Items.Count == 0 || !CheckBoxEPB.Checked)
                updateHostedService.EndPointBehavior = ConfigUtility.NO_ENDPOINT_BEHAVIOR;
            else
                if (DropDownListEPB.Items.Count == 0)
                    updateHostedService.EndPointBehavior = ConfigUtility.NO_ENDPOINT_BEHAVIOR;
                else
                    updateHostedService.EndPointBehavior = DropDownListEPB.SelectedValue;
            updateHostedService.FriendlyName = TextBoxHostedServiceName.Text.Trim();
            if (action != ConfigUtility.ADD_HOSTED_SERVICE)
                updateHostedService.HostedServiceID = thisService.HostedServiceID;
            else
                updateHostedService.HostedServiceID = -1;
            updateHostedService.HostName = LabelVHostName.Text;
            updateHostedService.InternalClientConfiguration = DropDownListInternalClient.SelectedValue;
            updateHostedService.IsBaseAddress = CheckBoxBaseAddress.Checked;
            if (thisServiceHost.ServiceType != ConfigUtility.HOST_TYPE_NODE && thisServiceHost.ServiceType != ConfigUtility.HOST_TYPE_NODE_DC)
                updateHostedService.LoadBalanceType = Convert.ToInt32(RadioButtonListLoadBalanceType.SelectedValue);
            else
                updateHostedService.LoadBalanceType = ConfigUtility.LOAD_BALANCE_TYPE_HOST_ADDRESS;
            if (updateHostedService.LoadBalanceType == ConfigUtility.LOAD_BALANCE_TYPE_VIRTUAL_ADDRESS)
            {
                string lba = TextBoxLoadBalanceAddress.Text.ToLower().Trim().Trim(new char[] { '/' });
                if (lba == null || lba.Length < 1)
                {
                    UpdateMessage.Text = "If using external load balancing, you must supply the load balanced address!";
                    UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                    return;
                }
                updateHostedService.LoadBalanceAddress = lba;
            }
            else
                updateHostedService.LoadBalanceAddress = "Not Implemented";
            if (thisServiceHost.ServiceType == ConfigUtility.HOST_TYPE_PRIMARY)
                if (updateHostedService.LoadBalanceType.Equals(ConfigUtility.LOAD_BALANCE_TYPE_HOST_ADDRESS))
                    defaultAddress = updateHostedService.LoadBalanceAddress;
                else
                    defaultAddress = "[enter servername here]";
            else
                defaultAddress = "none";
            updateHostedService.DefaultAddress = defaultAddress;
            updateHostedService.MarkedForFailover = CheckBoxFailover.Checked;
            updateHostedService.mex = CheckBoxMex.Checked;
            updateHostedService.OnlineMethod = TextBoxOnlineMethod.Text.Trim();
            if (updateHostedService.OnlineMethod == null || updateHostedService.OnlineMethod == "")
                updateHostedService.OnlineMethod = ConfigUtility.NO_ONLINE_METHOD;
            if (CheckBoxOnlineParms.Checked)
            {
                string parms = TextBoxOnlineParms.Text.Trim();
                if (parms == null || parms.Length < 1)
                {
                    UpdateMessage.Text = "If your online method expects parameters as you indicate, you must supply here in form of delimited list like 'string=strvalue;int=6;bool=true' or combination thereof.";
                    UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                    return;
                }
                updateHostedService.OnlineParms = parms;
            }
            else
                updateHostedService.OnlineParms = ConfigUtility.NO_ONLINE_PARMS;
            updateHostedService.ServiceBinding = DropDownListBindingConfig.SelectedValue;
            updateHostedService.ServiceHostID = SHID;
            updateHostedService.ServiceImplementationClassName = thisServiceHost.ServiceImplementationClass;
            updateHostedService.ServiceType = thisServiceHost.ServiceType;
            updateHostedService.ServiceContract = DropDownListContracts.SelectedValue;
            traversePath = DynamicTraversePath.getTraversePath(hostNameIdentifier, configName, ref configProxy,  address, binding, user);

            //OK, enough checking for valid settings---lets do it! Make the call to update or add or delete this endpoint!!
            success = configProxy.receiveService(hostNameIdentifier, configName, thisOldService, updateHostedService, null, null, null, null, null, true, action, traversePath, user);
            if (success == ConfigUtility.CLUSTER_UPDATE_FULL_SUCCESS)
            {
                Thread.Sleep(5000);
                if (compositeServiceData[0].RunTimePlatform.ToLower().Contains("azure"))
                {
                    if (!updateHostedService.LoadBalanceType.Equals(ConfigUtility.LOAD_BALANCE_TYPE_VIRTUAL_ADDRESS) && updateHostedService.ServiceType != ConfigUtility.HOST_TYPE_NODE)
                    {
                        UpdateMessageAzureLB.Text = "<br/><span style=\"color:#FFFF99;\">WARNING: You are hosting on Windows Azure so typically, you should mark your Configuration Service and Primary endpoints as externally load balanced on this page; and supply " +
                            "the Azure hosted service DNS base address + port for this endpoint.  Windows Azure will <strong>always</strong> externally load balance input endpoints.  By not specifiying the external load balance address and port" +
                            " (for example azurestocktraderbsl.cloudapp.net:443) on this page, Configuration Service may not work properly. It is very important to get the address and port exactly right.  The update has gone through, " +
                            "but after considering this message, you can make any adjustments and update the endpoint again with the correct Azure public-facing address + port.  If this is an internal endpoint, you can ignore this message.</span>";
                    }
                }
                try
                {
                    configProxy.Channel = null;
                    traversePath = DynamicTraversePath.getTraversePath(hostNameIdentifier, configName, ref configProxy, address, binding, user);
                    compositeServiceData = configProxy.getServiceConfiguration(hostNameIdentifier, configName, ConfigUtility.CONFIG_LEVEL_BASIC, false, traversePath, user);
                }
                catch (Exception)
                {
                    //Try again for good measure.
                    Thread.Sleep(3000);
                    try
                    {
                        traversePath = DynamicTraversePath.getTraversePath(hostNameIdentifier, configName, ref configProxy, address, binding, user);
                        compositeServiceData = null;
                        compositeServiceData = configProxy.getServiceConfiguration(hostNameIdentifier, configName, ConfigUtility.CONFIG_LEVEL_BASIC, false, traversePath, user);
                        if (compositeServiceData == null || compositeServiceData[0] == null)
                        {
                            UpdateMessage.Text = "<br/><span style=\"color:Maroon\">Error! The Configuration Service was not able to restart with your new definition.  Please check the event log.  You will" +
                                "not be able to continue until this is fixed, since ConfigWeb has no way to establish a connection to the Configuration Service, since it is no longer running at the remote host(s).</span>";
                            return;
                        }
                    }
                    catch (Exception)
                    {
                        UpdateMessage.Text = "<br/><span style=\"color:Maroon\">Error! The Configuration Service was not able to restart with your new definition.  Please check the event log.  You will" +
                               "not be able to continue until you login in again.  If there is an errror starting the Configuration Service Host, you will not be able to login until this issue is fixed.</span>";
                        SessionInfo info = new SessionInfo();
                        info.setSessionData(null, null, null, null, null, null, null, null, null);
                        return;
                    }
                }
                switch (action)
                {
                    case ConfigUtility.ADD_HOSTED_SERVICE:
                        {
                            if (compositeServiceData != null)
                            {
                                thisService = compositeServiceData[0].HostedServices.Find(delegate(HostedServices hsExist) { return hsExist.FriendlyName == updateHostedService.FriendlyName && hsExist.ServiceHostID == SHID; });
                                //thisService = updateHostedService;
                                if (thisService != null)
                                {
                                    thisOldService = thisService;
                                    SHID = thisService.ServiceHostID;
                                    ViewState["SHID"] = SHID;
                                    HSID = thisService.HostedServiceID;
                                    ViewState["HSID"] = HSID;
                                    ViewState["CompositeServiceData"] = compositeServiceData;
                                    ViewState["thisOldService"] = thisService;
                                    ViewState["thisService"] = thisService;
                                    action = ConfigUtility.UPDATE_HOSTED_SERVICE;
                                    ViewState["action"] = action;
                                    Add.Enabled = false;
                                    Update.Enabled = true;
                                    Delete.Enabled = true;
                                }
                            }
                            break;
                        }
                    case ConfigUtility.REMOVE_HOSTED_SERVICE:
                        {
                            Add.Enabled = false;
                            Update.Enabled = false;
                            Delete.Enabled = false;
                            break;
                        }
                }
                if (compositeServiceData!=null)
                    UpdateMessage.Text = "<br/><span style=\"color:PaleGreen \">The Hosted Service definition was sucessfully " + actiontext + ".</span>";
                else
                    UpdateMessage.Text = "<br/><span style=\"color:Maroon \">The Hosted Service definition was sucessfully sent.  However, there was an error retrieving updated results.</span>";
            }
            else
            {
                string message = null;
                switch (success)
                {
                    case ConfigUtility.CLUSTER_UPDATE_FAIL_PERSISTED:
                        {
                            message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_PERSISTED;
                            break;
                        }

                    case ConfigUtility.CLUSTER_UPDATE_FAIL_VALIDATION:
                        {
                            message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_VALIDATION;
                            break;
                        }

                    case ConfigUtility.CLUSTER_UPDATE_FAIL_AUTHENTICATION:
                        {
                            message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_AUTHORIZATION;
                            break;
                        }
                    case ConfigUtility.CLUSTER_UPDATE_FAIL_REMOTE:
                        {
                            message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_REMOTE_UPDATE;
                            break;
                        }
                    default:
                        {
                            message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_REMOTE_PEER + success.ToString();
                            break;
                        }
                }
                UpdateMessage.Text = "<br/><span style=\"color:Maroon\">" + message + "</span>";
                thisOldService = (HostedServices)ViewState["thisOldService"];
                thisService = thisOldService;
                ViewState["thisService"] = thisService;
            }
        }