Esempio n. 1
0
        public void WixMD5WithFile()
        {
            using (ShimsContext.Create())
              {
            // Компонент создает Guid сам, вмешаемся.
            System.Fakes.ShimGuid.NewGuid = () => { return Guid.Parse("53773F52-67A0-475E-8622-A2C57E7E6B7B"); };

            // Создадим директорию не привязанную к исполняющей программе.
            string dir = "TestDirectory";
            Directory.CreateDirectory(dir);

            // Создадим файлы имитирующие файлы базы данных.
            string mdfFile = dir + "\\" + "File.mdf";
            string ldfFile = dir + "\\" + "File.ldf";
            File.WriteAllText(mdfFile, "Data");
            File.WriteAllText(ldfFile, "Log");

            WixDbComponentElement component = new WixDbComponentElement();
            component.MdfFile = mdfFile;
            component.LdfFile = ldfFile;

            WixMD5ElementHash hash = component.GetMD5(dir);

            Directory.Delete(dir, true);

            // Хеши для файлов:
            // ce0be71e33226e4c1db2bcea5959f16b - File.ldf
            // f6068daa29dbb05a7ead1e3b5a48bbee - File.mdf
            Assert.IsNotNull(hash.Files);
            Assert.AreEqual(2, hash.Files.Count);
            Assert.AreEqual("ce0be71e33226e4c1db2bcea5959f16b", hash.Files["File.ldf"]);
            Assert.AreEqual("f6068daa29dbb05a7ead1e3b5a48bbee", hash.Files["File.mdf"]);
              }
        }
Esempio n. 2
0
        private void ProcessingTemplateDbComponent(IBuildContext context, CancellationTokenSource cts, XElement xmlWix, WixDbComponentElement component)
        {
            Dictionary<string, string> binaries = new Dictionary<string, string>();

              string formatedMdfFile = component.MdfFile.ReplaceNotLetterAndNotDigitWithASCIICode();
              string formatedLdfFile = component.LdfFile.ReplaceNotLetterAndNotDigitWithASCIICode();

              XElement xmlComponent;
              // Компонент базы данных должен быть один во всем пакете.
              // Устанавливаем его по умолчанию в директорию продукта ProductFolder/DBINSTALLLOCATION.
              // В дальнейшем пользователь сможет сменить директорию.
              XElement xmlDirectory = new XElement(XmlNameSpaceWIX + "DirectoryRef",
            new XAttribute("Id", "ProductFolder"),
            new XElement(XmlNameSpaceWIX + "Directory",
              new XAttribute("Id", "DBINSTALLLOCATION"),
              new XAttribute("Name", "DataBases"),
              xmlComponent = new XElement(XmlNameSpaceWIX + "Component",
            new XAttribute("Id", component.Id),
            new XAttribute("Guid", component.Guid),
            new XComment("Принудительно создаем каталог."),
            new XElement(XmlNameSpaceWIX + "CreateFolder"),
            new XComment("Ключевой компонент."),
            new XElement(XmlNameSpaceWIX + "RegistryValue",
              new XAttribute("Root", "HKLM"),
              new XAttribute("Key", "$(var.MainRegistryPath)"),
              new XAttribute("Name", component.Id),
              new XAttribute("Type", "integer"),
              new XAttribute("Value", "1"),
              new XAttribute("KeyPath", "yes")),
            new XElement(XmlNameSpaceST + "SqlTemplateFiles",
              new XAttribute("Id", "Template" + component.Id),
              new XAttribute("MdfFileBinaryKey", formatedMdfFile),
              new XAttribute("LdfFileBinaryKey", formatedLdfFile)))));

              binaries[formatedMdfFile] = Path.Combine(context.SourceStoreDirectory, component.MdfFile);
              binaries[formatedLdfFile] = Path.Combine(context.SourceStoreDirectory, component.LdfFile);

              XElement xmlFragment = new XElement(XmlNameSpaceWIX + "Fragment");
              xmlWix.Add(xmlFragment);
              xmlFragment.Add(xmlDirectory);

              // Если есть скрипты, добавляем.
              foreach (WixSqlScriptElement script in component.Items.OfType<WixSqlScriptElement>())
              {
            string formatedFile = script.Script.ReplaceNotLetterAndNotDigitWithASCIICode();
            xmlComponent.Add(new XElement(XmlNameSpaceST + "SqlScriptFile",
              new XAttribute("Id", script.Id),
              new XAttribute("BinaryKey", formatedFile),
              new XAttribute("ExecuteOnInstall", script.ExecuteOnInstall ? "yes" : "no"),
              new XAttribute("ExecuteOnReinstall", script.ExecuteOnReinstall ? "yes" : "no"),
              new XAttribute("ExecuteOnUninstall", script.ExecuteOnUninstall ? "yes" : "no"),
              new XAttribute("Sequence", script.Sequence)));
            binaries[formatedFile] = Path.Combine(context.SourceStoreDirectory, script.Script);
              }

              // Если есть хранимые процедуры, добавляем.
              foreach (WixSqlExtentedProceduresElement procedure in component.Items.OfType<WixSqlExtentedProceduresElement>())
              {
            string formatedFile = procedure.FileName.ReplaceNotLetterAndNotDigitWithASCIICode();
            xmlComponent.Add(new XElement(XmlNameSpaceST + "SqlExtendedProcedures",
              new XAttribute("Id", procedure.Id),
              new XAttribute("Name", procedure.FileName),
              new XAttribute("BinaryKey", formatedFile)));
            binaries[formatedFile] = Path.Combine(context.SourceStoreDirectory, procedure.FileName);
              }

              // Добавляем бинарные файлы.
              foreach (var binary in binaries)
              {
            xmlFragment.Add(new XElement(XmlNameSpaceWIX + "Binary",
              new XAttribute("Id", binary.Key),
              new XAttribute("SourceFile", binary.Value)));
              }
        }