Example #1
0
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(Constants.configPath);
                XmlNode node = xmldoc.DocumentElement;

                string EndpointURL = Context.Parameters["DEFAULTENDPOINT"];
                string UserName    = Context.Parameters["ADMINUSERNAME"];
                string Password    = Context.Parameters["ADMINPASSWORD"];

                // Need to trim trailing slashes as the wsdlPath starts with one
                string URL        = EndpointURL.Trim().TrimEnd(new char[] { '\\', '/' });
                string bindingURL = modelWsdlPath;
                string fullURL    = bindingURL + wsdlQuery;

                foreach (XmlNode rootNode in node.ChildNodes)
                {
                    foreach (XmlNode childNode in rootNode.ChildNodes)
                    {
                        if (rootNode.Name == "appSettings" && childNode.Name == "add")
                        {
                            switch (childNode.Attributes.GetNamedItem("key").Value)
                            {
                            case "DefaultEndpoint":
                                childNode.Attributes.GetNamedItem("value").Value = string.IsNullOrEmpty(URL) ? "" : URL;
                                break;

                            case "AdminUserName":
                                childNode.Attributes.GetNamedItem("value").Value = string.IsNullOrEmpty(UserName.Trim()) ? "null" : Encryptor.Encrypt(UserName);
                                break;

                            case "AdminPassword":
                                childNode.Attributes.GetNamedItem("value").Value = string.IsNullOrEmpty(Password.Trim()) ? "null" : Encryptor.Encrypt(Password);
                                break;

                            default:
                                break;
                            }
                        }

                        if (rootNode.Name == "system.serviceModel" && childNode.Name == "client")
                        {
                            foreach (XmlNode grandChildNode in childNode.ChildNodes)
                            {
                                if (grandChildNode.Name == "endpoint" && !string.IsNullOrEmpty(bindingURL))
                                {
                                    grandChildNode.Attributes.GetNamedItem("address").Value = modelWsdlPath;
                                }
                            }
                        }
                    }
                }

                xmldoc.Save(Constants.configPath);


                try
                {
                    // Add the password filter dll to registry
                    RegistryEditor.SetRegistryKey();

                    try
                    {
                        // Create scheduled task for processor
                        ScheduledTask.CreateScheduledTask();
                    }
                    catch (Exception ex)
                    {
                        throw new InstallException("Unable to create scheduled task: '" + ex.Message + "'");
                    }
                }
                catch (Exception ex)
                {
                    throw new InstallException("Unable to modify registry: '" + ex.Message + "'");
                }
            }
            catch (Exception ex)
            {
                throw new InstallException("Unable to modify configuration file: '" + ex.Message + "'");
            }
        }