Пример #1
0
        private XmlElementEx GetConnectionStringsElement()
        {
            XmlDocumentEx webConfig = Instance.GetWebConfig();

            Assert.IsNotNull(webConfig, nameof(webConfig));

            return(GetConnectionStringsElement(webConfig));
        }
        private static void ProcessActions(Instance instance, SqlConnectionStringBuilder connectionString, 
      IPipelineController controller, Product module, Dictionary<string, string> variables, 
      XmlElement actionsElement)
        {
            // made replacement
              actionsElement.InnerXml = variables.Aggregate(actionsElement.InnerXml,
            (result, variable) => result.Replace(variable.Key, variable.Value)).Replace("{InstanceName}", instance.Name);

              var actions = actionsElement.ChildNodes.OfType<XmlElement>();
              var webRootPath = instance.WebRootPath;
              List<string> ignoreCommands = new List<string>();
              foreach (XmlElement action in actions.Where(a => a.Name.EqualsIgnoreCase("patch")))
              {
            var commandText = action.GetAttribute("command").EmptyToNull().IsNotNull("The command attribute of <patch /> element must exist and must not be empty");
            var actionText = action.GetAttribute("action");
            if (actionText == "delete")
            {
              ignoreCommands.Add(commandText);
            }
              }

              // give extract more priority
              if (actions.Any(xml => xml.Name.EqualsIgnoreCase("extract")) && !ignoreCommands.Contains("extract"))
              {
            FileSystem.FileSystem.Local.Zip.UnpackZip(module.PackagePath, instance.WebRootPath);
              }

              foreach (XmlElement action in actions)
              {
            var children = action.ChildNodes.OfType<XmlElement>();
            string actionName = action.Name;
            if (ignoreCommands.Contains(actionName))
            {
              continue;
            }

            switch (actionName)
            {
              case "extract":
              {
            // give extract more priority
            // FileSystem.Instance.UnpackZip(module.PackagePath, instance.GetRootPath(webRootPath));
            break;
              }

              case "config":
              {
            string configPath = action.GetAttribute("path");
            try
            {
              XmlDocumentEx config = !string.IsNullOrEmpty(configPath)
                ? XmlDocumentEx.LoadFile(Path.Combine(webRootPath, configPath))
                : instance.GetWebConfig(webRootPath);
              PerformConfigChanges(instance, children, module, config, variables);
            }
            catch (XmlDocumentEx.FileIsMissingException ex)
            {
              Log.Warn(
                "The path attribute is specified (path: {0}) but the file doesn't exist".FormatWith(configPath),
                typeof(ConfigurationActions), ex);
            }

            break;
              }

              case "databases":
              {
            AddDatabase(instance, children, module, connectionString, controller);
            break;
              }

              case "editfile":
              {
            EditFile(action.GetAttribute("path"), children, instance, variables);
            break;
              }

              case "setRestrictingPlaceholders":
              {
            InstanceHelper.StartInstance(instance);
            SetRestrictingPlaceholders(action.GetAttribute("names"), GetWebServiceUrl(instance));
            break;
              }

              case "custom":
              {
            var typeName = action.GetAttribute("type").EmptyToNull().IsNotNull("The type attribute is missing in the <custom> install action");
            var obj = (IPackageInstallActions)ReflectionUtil.CreateObject(typeName);
            obj.Execute(instance, module);
            break;
              }

              case "sql":
              {
            var db = action.GetAttribute("database");
            var file = action.GetAttribute("file").Replace("$(data)", instance.DataFolderPath).Replace("$(website)", instance.WebRootPath);
            if (!string.IsNullOrEmpty(file))
            {
              Assert.IsTrue(File.Exists(file), string.Format("The {0} file does not exist", file));
            }

            var sql = string.IsNullOrEmpty(file) ? action.InnerText : FileSystem.FileSystem.Local.File.ReadAllText(file);
            Assert.IsNotNullOrEmpty(sql.Trim(), "The SQL command is empty");

            var cstr = instance.Configuration.ConnectionStrings.FirstOrDefault(x => x.Name == db);
            Assert.IsNotNull(cstr, "The {0} connection string is not found".FormatWith(db));
            using (var conn = SqlServerManager.Instance.OpenConnection(new SqlConnectionStringBuilder(cstr.Value), false))
            {
              foreach (var command in sql.Split("GO"))
              {
                SqlServerManager.Instance.Execute(conn, command);
              }
            }

            break;
              }
            }
              }
        }
        public void OnClick(Window mainWindow, Instance instance)
        {
            if (!this.Showconfig && !this.WebConfigResult)
              {
            RunConfigApp("Sitecore.ConfigBuilder.Tool.exe", mainWindow, instance != null ? Path.Combine(instance.WebRootPath, "web.config") : null);
            return;
              }

              var path = instance.GetWebConfig().FilePath;

              if (this.Showconfig)
              {
            path = Path.Combine(Path.GetDirectoryName(path), "showconfig.xml");
              }
              else if (this.WebConfigResult)
              {
            path += ".result.xml";
              }
              else
              {
            Assert.IsTrue(false, "Impossible");
              }

              if (this.Normalize)
              {
            path += ".normalized.xml";
              }

              if (this.Showconfig)
              {
            instance.GetShowconfig(this.Normalize).Save(path);
              }
              else if (this.WebConfigResult)
              {
            instance.GetWebResultConfig(this.Normalize).Save(path);
              }
              else
              {
            Assert.IsTrue(false, "Impossible");
              }

              WindowHelper.OpenFile(path);
        }