private void CheckForPotentialBrokenReferences(IData data, List <PackageFragmentValidationResult> validationResult, Type type, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale, DataKeyPropertyCollection dataKeyPropertyCollection) { var pagesReferencingPageTypes = new HashSet <string>(); var dataReferencingDataToBeUninstalled = new HashSet <string>(); List <IData> referees = data.GetReferees(); bool addToDelete = true; foreach (IData referee in referees) { if (this.UninstallerContext.IsPendingForDeletionData(referee)) { continue; } addToDelete = false; if (referee is IPage && data is IPageType) { string pathToPage; using (new DataScope(referee.DataSourceId.PublicationScope, referee.DataSourceId.LocaleScope)) { pathToPage = GetPathToPage(referee as IPage); } if (!pagesReferencingPageTypes.Contains(pathToPage)) { validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_PageTypeIsReferenced( data.GetLabel(), pathToPage)); pagesReferencingPageTypes.Add(pathToPage); } } else { var refereeType = referee.DataSourceId.InterfaceType; string label = referee.GetLabel(); string key = label + refereeType.FullName; if (!dataReferencingDataToBeUninstalled.Contains(key)) { validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_DataIsReferenced( data.GetLabel(), type.FullName, label, refereeType.FullName)); dataReferencingDataToBeUninstalled.Add(key); } } } if (addToDelete) { AddDataToDelete(type, dataScopeIdentifier, locale, dataKeyPropertyCollection); } }
/// <summary> /// Gets a single configuration element. Elements other than the specified one will cause validation errors. /// </summary> internal static XElement GetSingleConfigurationElement(this XElement configurationElement, string elementName, IList <PackageFragmentValidationResult> validationResult, bool required) { XElement result = null; foreach (var element in configurationElement.Elements()) { if (element.Name.LocalName != elementName) { validationResult.AddFatal(Texts.PackageFragmentInstaller_IncorrectElement(element.Name.LocalName, elementName), element); continue; } if (result != null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_OnlyOneElementAllowed(elementName)); return(null); } result = element; } if (required && result == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingElement(elementName)); } return(result); }
private void CheckForBrokenReference(DataType refereeType, Type type, string propertyName, object propertyValue) { Type referredType; string keyPropertyName; object referenceKey; MapReference(type, propertyName, propertyValue, out referredType, out keyPropertyName, out referenceKey); // Checking key in the keys to be installed var keyValuePair = new KeyValuePair <string, object>(keyPropertyName, referenceKey); if (_missingDataReferences.ContainsKey(referredType) && _missingDataReferences[referredType].Contains(keyValuePair)) { return; } if (_dataKeysToBeInstalled.ContainsKey(referredType) && _dataKeysToBeInstalled[referredType].KeyRegistered(refereeType, keyValuePair)) { return; } using (GetDataScopeFromDataTypeElement(refereeType)) { if (DataFacade.TryGetDataByUniqueKey(type, propertyValue) == null) { _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_ReferencedDataMissing( type.FullName, propertyName, propertyValue)); var missingReferences = _missingDataReferences.GetOrAdd(referredType, () => new HashSet <KeyValuePair <string, object> >()); missingReferences.Add(keyValuePair); } } }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { _xsls = new List <XslTransformation>(); var validationResult = new List <PackageFragmentValidationResult>(); var filesElement = this.ConfigurationParent.GetSingleConfigurationElement("XslFiles", validationResult, false); if (filesElement == null) { return(validationResult); } foreach (XElement fileElement in filesElement.Elements("XslFile")) { XAttribute pathXMLAttribute = fileElement.Attribute(Installer.TargetXmlAttributeName); XAttribute pathXSLAttribute = fileElement.Attribute(Installer.UninstallXslAttributeName); if (pathXMLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute(Installer.TargetXmlAttributeName), fileElement); continue; } if (pathXSLAttribute == null) { //if there isn no uninstall xsl continue; } string inputPathXMLAttributeValue = PathUtil.Resolve(pathXMLAttribute.Value); string inpuPathXSLAttributeValue = pathXSLAttribute.Value; _xsls.Add(new XslTransformation { pathXml = inputPathXMLAttributeValue, pathXsl = inpuPathXSLAttributeValue }); } if (validationResult.Count > 0) { _xsls = null; } return(validationResult); }
/// <summary> /// Gets a child configuration elements. Elements with names other than the specified one will cause validation errors. /// </summary> internal static IEnumerable <XElement> GetConfigurationElements(this XElement configurationElement, string elementName, IList <PackageFragmentValidationResult> validationResult) { var result = new List <XElement>(); foreach (var element in configurationElement.Elements()) { if (element.Name.LocalName != elementName) { validationResult.AddFatal(Texts.PackageFragmentInstaller_IncorrectElement(element.Name.LocalName, elementName), element); continue; } result.Add(element); } return(result); }
private bool ValidateTargetLocaleInfo(DataType dataType, bool dataTypeLocalized) { bool localeInfoSpecified = dataType.Locale != null || dataType.AddToAllLocales || dataType.AddToCurrentLocale; if (dataTypeLocalized && !localeInfoSpecified) { _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_TypeLocalizedWithoutLocale(dataType.InterfaceType)); return(false); } if (!dataTypeLocalized && localeInfoSpecified) { _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_TypeNonLocalizedWithLocale(dataType.InterfaceType)); return(false); } return(true); }
private void ValidateDynamicAddedType(DataType dataType) { DataTypeDescriptor dataTypeDescriptor = this.InstallerContext.GetPendingDataTypeDescriptor(dataType.InterfaceTypeName); if (dataTypeDescriptor == null) { _validationResult.AddFatal(GetText("DataPackageFragmentInstaller.MissingTypeDescriptor").FormatWith(dataType.InterfaceTypeName)); return; } bool dataTypeLocalized = dataTypeDescriptor.SuperInterfaces.Contains(typeof(ILocalizedControlled)); if (!ValidateTargetLocaleInfo(dataType, dataTypeLocalized)) { return; } foreach (XElement addElement in dataType.Dataset) { var dataKeyPropertyCollection = new DataKeyPropertyCollection(); bool propertyValidationPassed = true; var fieldValues = new Dictionary <string, object>(); foreach (XAttribute attribute in addElement.Attributes()) { string fieldName = attribute.Name.LocalName; // A compatibility fix if (IsObsoleteField(dataTypeDescriptor, fieldName)) { continue; } DataFieldDescriptor dataFieldDescriptor = dataTypeDescriptor.Fields[fieldName]; if (dataFieldDescriptor == null) { _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_MissingProperty(dataTypeDescriptor, fieldName)); propertyValidationPassed = false; continue; } object fieldValue; try { fieldValue = ValueTypeConverter.Convert(attribute.Value, dataFieldDescriptor.InstanceType); } catch (Exception) { _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_ConversionFailed(attribute.Value, dataFieldDescriptor.InstanceType)); propertyValidationPassed = false; continue; } if (dataTypeDescriptor.KeyPropertyNames.Contains(fieldName)) { dataKeyPropertyCollection.AddKeyProperty(fieldName, fieldValue); } fieldValues.Add(fieldName, fieldValue); } if (!propertyValidationPassed) { continue; } if (!dataType.AllowOverwrite && !dataType.OnlyUpdate) { // TODO: implement check if the same key has already been added } // TODO: to be implemented for dynamic types // RegisterKeyToBeAdded(dataType, dataKeyPropertyCollection); // Checking foreign key references foreach (var referenceField in dataTypeDescriptor.Fields.Where(f => f.ForeignKeyReferenceTypeName != null)) { object propertyValue; if (!fieldValues.TryGetValue(referenceField.Name, out propertyValue) || propertyValue == null || (propertyValue is Guid && (Guid)propertyValue == Guid.Empty) || propertyValue is string && (string)propertyValue == "") { continue; } string referredTypeName = referenceField.ForeignKeyReferenceTypeName; var referredType = TypeManager.TryGetType(referredTypeName); if (referredType == null) { // TODO: implement reference check for dynamic types as well continue; } string targetKeyPropertyName = referredType.GetKeyPropertyNames().SingleOrDefault(); CheckForBrokenReference(dataType, referredType, targetKeyPropertyName, propertyValue); } } }
private void ValidateAndLoadConfiguration() { XElement typesElement = this.Configuration.SingleOrDefault(f => f.Name == "Types"); if (typesElement == null) { _validationResult.AddFatal(GetText("DataPackageFragmentInstaller.MissingElement")); } if (typesElement == null) { return; } foreach (XElement typeElement in typesElement.Elements("Type")) { var typeAttribute = typeElement.Attribute("type"); if (typeAttribute == null) { _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_MissingAttribute("type"), typeElement); continue; } XAttribute allowOverwriteAttribute = typeElement.Attribute("allowOverwrite"); XAttribute onlyUpdateAttribute = typeElement.Attribute("onlyUpdate"); bool allowOverwrite = allowOverwriteAttribute != null && (bool)allowOverwriteAttribute; bool onlyUpdate = onlyUpdateAttribute != null && (bool)onlyUpdateAttribute; string interfaceTypeName = typeAttribute.Value; interfaceTypeName = TypeManager.FixLegasyTypeName(interfaceTypeName); foreach (XElement dataElement in typeElement.Elements("Data")) { XAttribute dataScopeIdentifierAttribute = dataElement.Attribute("dataScopeIdentifier"); if (dataScopeIdentifierAttribute == null) { _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_MissingAttribute("dataScopeIdentifier"), typeElement); continue; } DataScopeIdentifier dataScopeIdentifier; try { dataScopeIdentifier = DataScopeIdentifier.Deserialize(dataScopeIdentifierAttribute.Value); } catch (Exception) { _validationResult.AddFatal(GetText("DataPackageFragmentInstaller.WrongDataScopeIdentifier").FormatWith(dataScopeIdentifierAttribute.Value), dataScopeIdentifierAttribute); continue; } CultureInfo locale = null; // null => do not use localization bool allLocales = false; bool currentLocale = false; XAttribute localeAttribute = dataElement.Attribute("locale"); if (localeAttribute != null) { if (localeAttribute.Value == "*") { allLocales = true; } else if (localeAttribute.Value == "?") { currentLocale = true; } else { try { locale = CultureInfo.CreateSpecificCulture(localeAttribute.Value); } catch (Exception) { _validationResult.AddFatal(GetText("DataPackageFragmentInstaller.WrongLocale").FormatWith(localeAttribute.Value), localeAttribute); continue; } } } XAttribute dataFilenameAttribute = dataElement.Attribute("dataFilename"); if (dataFilenameAttribute == null) { _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_MissingAttribute("dataFilename"), typeElement); continue; } if (!this.InstallerContext.ZipFileSystem.ContainsFile(dataFilenameAttribute.Value)) { _validationResult.AddFatal(GetText("DataPackageFragmentInstaller.MissingFile").FormatWith(dataFilenameAttribute.Value), dataFilenameAttribute); continue; } XDocument doc; try { using (var stream = this.InstallerContext.ZipFileSystem.GetFileStream(dataFilenameAttribute.Value)) using (var reader = new C1StreamReader(stream)) { doc = XDocument.Load(reader); } } catch (Exception ex) { _validationResult.Add(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex)); continue; } XAttribute isDynamicAddedAttribute = typeElement.Attribute("isDynamicAdded"); bool isDynamicAdded = isDynamicAddedAttribute != null && (bool)isDynamicAddedAttribute; var dataType = new DataType { InterfaceTypeName = interfaceTypeName, DataScopeIdentifier = dataScopeIdentifier, Locale = locale, AddToAllLocales = allLocales, AddToCurrentLocale = currentLocale, IsDynamicAdded = isDynamicAdded, AllowOverwrite = allowOverwrite, OnlyUpdate = onlyUpdate, Dataset = doc.Root.Elements("Add") }; _dataTypes.Add(dataType); } } }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); var foreignKeyReferences = new List <string>(); if (this.Configuration.Count(f => f.Name == "Types") > 1) { validationResult.AddFatal(Texts.DynamicDataTypePackageFragmentInstaller_OnlyOneElement); return(validationResult); } XElement typesElement = this.Configuration.SingleOrDefault(f => f.Name == "Types"); if (typesElement == null) { validationResult.AddFatal(Texts.DynamicDataTypePackageFragmentInstaller_MissingElement); return(validationResult); } _dataTypeDescriptors = new List <DataTypeDescriptor>(); foreach (XElement typeElement in typesElement.Elements("Type")) { XElement serializedDataTypeDescriptor; XAttribute fileAttribute = typeElement.Attribute("dataTypeDescriptorFile"); if (fileAttribute != null) { string relativeFilePath = (string)fileAttribute; string markup; using (var stream = this.InstallerContext.ZipFileSystem.GetFileStream(relativeFilePath)) using (var reader = new StreamReader(stream)) { markup = reader.ReadToEnd(); } serializedDataTypeDescriptor = XElement.Parse(markup); } else { var dataTypeDescriptorAttribute = typeElement.Attribute("dataTypeDescriptor"); if (dataTypeDescriptorAttribute == null) { validationResult.AddFatal(Texts.DataTypePackageFragmentInstaller_MissingAttribute("dataTypeDescriptor"), typeElement); continue; } try { serializedDataTypeDescriptor = XElement.Parse(dataTypeDescriptorAttribute.Value); } catch (Exception) { validationResult.AddFatal(Texts.DynamicDataTypePackageFragmentInstaller_DataTypeDescriptorParseError, dataTypeDescriptorAttribute); continue; } } DataTypeDescriptor dataTypeDescriptor; try { bool inheritedFieldsIncluded = serializedDataTypeDescriptor.Descendants().Any(e => e.Attributes("inherited").Any(a => (string)a == "true")); dataTypeDescriptor = DataTypeDescriptor.FromXml(serializedDataTypeDescriptor, inheritedFieldsIncluded); } catch (Exception e) { validationResult.AddFatal(Texts.DynamicDataTypePackageFragmentInstaller_DataTypeDescriptorDeserializeError(e.Message)); continue; } Type type = TypeManager.TryGetType(dataTypeDescriptor.TypeManagerTypeName); if (type != null && DataFacade.GetAllKnownInterfaces().Contains(type)) { validationResult.AddFatal(Texts.DynamicDataTypePackageFragmentInstaller_TypeExists(type)); } if (dataTypeDescriptor.SuperInterfaces.Any(f => f.Name == nameof(IVersioned))) { if (dataTypeDescriptor.Fields.All(f => f.Name != nameof(IVersioned.VersionId))) { dataTypeDescriptor.Fields.Add(new DataFieldDescriptor(Guid.NewGuid(), nameof(IVersioned.VersionId), StoreFieldType.Guid, typeof(Guid), true)); } } foreach (var field in dataTypeDescriptor.Fields) { if (!field.ForeignKeyReferenceTypeName.IsNullOrEmpty()) { foreignKeyReferences.Add(field.ForeignKeyReferenceTypeName); } } _dataTypeDescriptors.Add(dataTypeDescriptor); this.InstallerContext.AddPendingDataTypeDescritpor(dataTypeDescriptor.TypeManagerTypeName, dataTypeDescriptor); } foreach (string foreignKeyTypeName in foreignKeyReferences) { if (!TypeManager.HasTypeWithName(foreignKeyTypeName) && !_dataTypeDescriptors.Any(descriptor => descriptor.TypeManagerTypeName == foreignKeyTypeName)) { validationResult.AddFatal(Texts.DynamicDataTypePackageFragmentInstaller_MissingReferencedType(foreignKeyTypeName)); } } if (validationResult.Count > 0) { _dataTypeDescriptors = null; } return(validationResult); }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); if (this.Configuration.Count(f => f.Name == "PackageVersions") > 1) { validationResult.AddFatal(Texts.PackageVersionBumperFragmentUninstaller_OnlyOneElement, this.ConfigurationParent); return(validationResult); } XElement packageVersionsElement = this.Configuration.SingleOrDefault(f => f.Name == "PackageVersions"); _packagesToBumb = new Dictionary <Guid, string>(); if (packageVersionsElement != null) { foreach (XElement packageVersionElement in packageVersionsElement.Elements("PackageVersion")) { XAttribute packageIdAttribute = packageVersionElement.Attribute("packageId"); XAttribute newVersionAttribute = packageVersionElement.Attribute("newVersion"); if (packageIdAttribute == null) { validationResult.AddFatal(Texts.PackageVersionBumperFragmentUninstaller_MissingAttribute("packageId"), packageVersionElement); continue; } if (newVersionAttribute == null) { validationResult.AddFatal(Texts.PackageVersionBumperFragmentUninstaller_MissingAttribute("newVersion"), packageVersionElement); continue; } Guid packageId; if (!packageIdAttribute.TryGetGuidValue(out packageId)) { validationResult.AddFatal(Texts.PackageVersionBumperFragmentUninstaller_WrongAttributeGuidFormat, packageIdAttribute); continue; } if (_packagesToBumb.ContainsKey(packageId)) { validationResult.AddFatal(Texts.PackageVersionBumperFragmentUninstaller_PackageIdDuplicate(packageId), packageIdAttribute); continue; } Version version; try { version = new Version(newVersionAttribute.Value); } catch { validationResult.AddFatal(Texts.PackageVersionBumperFragmentUninstaller_WrongAttributeVersionFormat, newVersionAttribute); continue; } _packagesToBumb.Add(packageId, version.ToString()); } } if (validationResult.Count > 0) { _packagesToBumb = null; } return(validationResult); }
/// <exclude /> public static PackageManagerInstallProcess Install(Stream zipFileStream, bool isLocalInstall, string packageServerAddress) { if (!isLocalInstall && string.IsNullOrEmpty(packageServerAddress)) { throw new ArgumentException("Non local install needs a packageServerAddress"); } string zipFilename = null; try { PackageFragmentValidationResult packageFragmentValidationResult = SaveZipFile(zipFileStream, out zipFilename); if (packageFragmentValidationResult != null) { return(new PackageManagerInstallProcess(new List <PackageFragmentValidationResult> { packageFragmentValidationResult }, null)); } XElement installContent; packageFragmentValidationResult = XmlHelper.LoadInstallXml(zipFilename, out installContent); if (packageFragmentValidationResult != null) { return(new PackageManagerInstallProcess(new List <PackageFragmentValidationResult> { packageFragmentValidationResult }, zipFilename)); } PackageInformation packageInformation; packageFragmentValidationResult = ValidatePackageInformation(installContent, out packageInformation); if (packageFragmentValidationResult != null) { return(new PackageManagerInstallProcess(new List <PackageFragmentValidationResult> { packageFragmentValidationResult }, zipFilename)); } if (RuntimeInformation.ProductVersion < packageInformation.MinCompositeVersionSupported || RuntimeInformation.ProductVersion > packageInformation.MaxCompositeVersionSupported) { return(new PackageManagerInstallProcess(new List <PackageFragmentValidationResult> { new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, Texts.PackageManager_CompositeVersionMisMatch( RuntimeInformation.ProductVersion, packageInformation.MinCompositeVersionSupported, packageInformation.MaxCompositeVersionSupported)) }, zipFilename)); } bool updatingInstalledPackage = false; if (IsInstalled(packageInformation.Id)) { string currentVersionString = GetCurrentVersion(packageInformation.Id); Version currentVersion = new Version(currentVersionString); Version newVersion = new Version(packageInformation.Version); if (newVersion <= currentVersion) { string validationError = newVersion == currentVersion ? Texts.PackageManager_PackageAlreadyInstalled : Texts.PackageManager_NewerVersionInstalled; return(new PackageManagerInstallProcess( new List <PackageFragmentValidationResult> { new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, validationError) }, zipFilename)); } updatingInstalledPackage = true; } string originalInstallDirectory = null; string packageInstallDirectory = CreatePackageDirectoryName(packageInformation); if (updatingInstalledPackage) { originalInstallDirectory = packageInstallDirectory; packageInstallDirectory += "-" + packageInformation.Version; } C1Directory.CreateDirectory(packageInstallDirectory); string packageZipFilename = Path.Combine(packageInstallDirectory, Path.GetFileName(zipFilename)); C1File.Copy(zipFilename, packageZipFilename, true); string username = "******"; if (UserValidationFacade.IsLoggedIn()) { username = UserValidationFacade.GetUsername(); } var doc = new XDocument(); XElement packageInfoElement = new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageInfoElementName)); doc.Add(packageInfoElement); packageInfoElement.Add( new XAttribute(PackageSystemSettings.PackageInfo_NameAttributeName, packageInformation.Name), new XAttribute(PackageSystemSettings.PackageInfo_GroupNameAttributeName, packageInformation.GroupName), new XAttribute(PackageSystemSettings.PackageInfo_VersionAttributeName, packageInformation.Version), new XAttribute(PackageSystemSettings.PackageInfo_AuthorAttributeName, packageInformation.Author), new XAttribute(PackageSystemSettings.PackageInfo_WebsiteAttributeName, packageInformation.Website), new XAttribute(PackageSystemSettings.PackageInfo_DescriptionAttributeName, packageInformation.Description), new XAttribute(PackageSystemSettings.PackageInfo_InstallDateAttributeName, DateTime.Now), new XAttribute(PackageSystemSettings.PackageInfo_InstalledByAttributeName, username), new XAttribute(PackageSystemSettings.PackageInfo_IsLocalInstalledAttributeName, isLocalInstall), new XAttribute(PackageSystemSettings.PackageInfo_CanBeUninstalledAttributeName, packageInformation.CanBeUninstalled), new XAttribute(PackageSystemSettings.PackageInfo_FlushOnCompletionAttributeName, packageInformation.FlushOnCompletion), new XAttribute(PackageSystemSettings.PackageInfo_ReloadConsoleOnCompletionAttributeName, packageInformation.ReloadConsoleOnCompletion), new XAttribute(PackageSystemSettings.PackageInfo_SystemLockingAttributeName, packageInformation.SystemLockingType.Serialize())); if (!string.IsNullOrEmpty(packageServerAddress)) { packageInfoElement.Add(new XAttribute(PackageSystemSettings.PackageInfo_PackageServerAddressAttributeName, packageServerAddress)); } string infoFilename = Path.Combine(packageInstallDirectory, PackageSystemSettings.PackageInformationFilename); doc.SaveToFile(infoFilename); var packageInstaller = new PackageInstaller(new PackageInstallerUninstallerFactory(), packageZipFilename, packageInstallDirectory, TempDirectoryFacade.CreateTempDirectory(), packageInformation); return(new PackageManagerInstallProcess( packageInstaller, packageInformation.SystemLockingType, zipFilename, packageInstallDirectory, packageInformation.Name, packageInformation.Version, packageInformation.Id, originalInstallDirectory)); } catch (Exception ex) { return(new PackageManagerInstallProcess(new List <PackageFragmentValidationResult> { new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex) }, zipFilename)); } }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { _xslTransformations = new List <XslTransformation>(); var validationResult = new List <PackageFragmentValidationResult>(); var filesElement = this.ConfigurationParent.GetSingleConfigurationElement("XslFiles", validationResult, false); if (filesElement == null) { return(validationResult); } foreach (XElement fileElement in filesElement.GetConfigurationElements("XslFile", validationResult)) { XAttribute pathXMLAttribute = fileElement.Attribute(TargetXmlAttributeName); XAttribute inputXMLAttribute = fileElement.Attribute(InputXmlAttributeName); XAttribute outputXMLAttribute = fileElement.Attribute(OutputXmlAttributeName); XAttribute pathXSLAttribute = fileElement.Attribute(TargetXslAttributeName); XAttribute installXSLAttribute = fileElement.Attribute(InstallXslAttributeName); XAttribute uninstallXSLAttribute = fileElement.Attribute(UninstallXslAttributeName); XAttribute overrideReadOnlyAttribute = fileElement.Attribute(OverrideReadOnlyAttributeName); XAttribute skipIfNotExistAttribute = fileElement.Attribute(SkipIfNotExistAttributeName); bool skipIfNotExist = skipIfNotExistAttribute != null && skipIfNotExistAttribute.Value.ToLower() == "true"; if (pathXSLAttribute == null && installXSLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute(TargetXmlAttributeName), fileElement); continue; } if (outputXMLAttribute != null && uninstallXSLAttribute != null) { validationResult.AddFatal("Xsl installer does not suppurt simultaneous usage of attributes '{0}' and '{1}'" .FormatWith(OutputXmlAttributeName, UninstallXslAttributeName), fileElement); continue; } string xslFilePath = (pathXSLAttribute ?? installXSLAttribute).Value; XslTransformation xslFile; if (inputXMLAttribute != null) { if (outputXMLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("outputFilename"), fileElement); continue; } xslFile = new XslTransformation { XslPath = xslFilePath, InputXmlPath = inputXMLAttribute.Value, OutputXmlPath = outputXMLAttribute.Value }; } else { if (pathXMLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute(TargetXmlAttributeName), fileElement); continue; } string pathToXmlFile = pathXMLAttribute.Value; xslFile = new XslTransformation { XslPath = xslFilePath, // UninstallXslPath = uninstallXSLAttribute != null ? uninstallXSLAttribute.Value : null, InputXmlPath = pathToXmlFile, OutputXmlPath = pathToXmlFile }; } if (!C1File.Exists(PathUtil.Resolve(xslFile.InputXmlPath))) { if (skipIfNotExist) { continue; } validationResult.AddFatal(Texts.FileXslTransformationPackageFragmentInstaller_FileNotFound(xslFile.InputXmlPath), fileElement); continue; } string outputXmlFullPath = PathUtil.Resolve(xslFile.OutputXmlPath); if (C1File.Exists(outputXmlFullPath) && (C1File.GetAttributes(outputXmlFullPath) & FileAttributes.ReadOnly) > 0) { if (overrideReadOnlyAttribute == null || overrideReadOnlyAttribute.Value != "true") { validationResult.AddFatal(Texts.FileXslTransformationPackageFragmentInstaller_FileReadOnly(xslFile.OutputXmlPath), fileElement); continue; } FileUtils.RemoveReadOnly(outputXmlFullPath); Log.LogWarning(LogTitle, Texts.FileXslTransformationPackageFragmentInstaller_FileReadOnlyOverride(xslFile.OutputXmlPath)); } if (!PathUtil.WritePermissionGranted(outputXmlFullPath)) { validationResult.AddFatal(Texts.NotEnoughNtfsPermissions(xslFile.OutputXmlPath), fileElement); continue; } _xslTransformations.Add(xslFile); } if (validationResult.Count > 0) { _xslTransformations = null; } return(validationResult); }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); if (this.Configuration.Count(f => f.Name == "Locales") > 1) { validationResult.AddFatal(Texts.PackageFragmentInstaller_OnlyOneElementAllowed("Locales")); return(validationResult); } XElement areasElement = this.Configuration.SingleOrDefault(f => f.Name == "Locales"); _localesToInstall = new List <Tuple <CultureInfo, string, bool> >(); if (areasElement != null) { foreach (XElement localeElement in areasElement.Elements("Locale")) { XAttribute nameAttribute = localeElement.Attribute("name"); XAttribute urlMappingNameAttribute = localeElement.Attribute("urlMappingName"); XAttribute defaultAttribute = localeElement.Attribute("default"); if (nameAttribute == null) { // Missing attribute validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("name"), localeElement); continue; } CultureInfo cultureInfo; try { cultureInfo = CultureInfo.CreateSpecificCulture(nameAttribute.Value); } catch { // Name error validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("name"), nameAttribute); continue; } if (LocalizationFacade.IsLocaleInstalled(cultureInfo)) { continue; // Skip it, it is installed } if (_localesToInstall.Any(f => f.Item1.Equals(cultureInfo))) { // Already installed or going to be installed validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("name"), nameAttribute); continue; } string urlMappingName = cultureInfo.Name; if (urlMappingNameAttribute != null) { urlMappingName = urlMappingNameAttribute.Value; } if (LocalizationFacade.IsUrlMappingNameInUse(urlMappingName) || _localesToInstall.Any(f => f.Item2 == urlMappingName)) { // Url mapping name already used or going to be used validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("urlMappingName"), urlMappingNameAttribute); continue; } bool isDefault = false; if (defaultAttribute != null) { if (!defaultAttribute.TryGetBoolValue(out isDefault)) { // Wrong attribute value validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("default"), defaultAttribute); continue; } } if (isDefault && _localesToInstall.Any(f => f.Item3)) { // More than one is specified as default validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("default"), defaultAttribute); continue; } _localesToInstall.Add(new Tuple <CultureInfo, string, bool>(cultureInfo, urlMappingName, isDefault)); this.InstallerContext.AddPendingLocale(cultureInfo); } } if (validationResult.Count > 0) { _localesToInstall = null; } return(validationResult); }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); if (this.Configuration.Count(f => f.Name == "Files") > 1) { validationResult.AddFatal(Texts.FilePackageFragmentUninstaller_OnlyOneFilesElement, ConfigurationParent); return(validationResult); } XElement filesElement = this.Configuration.SingleOrDefault(f => f.Name == "Files"); _filesToDelete = new List <string>(); _filesToCopy = new List <Tuple <string, string> >(); // NOTE: Packages, that were installed on version earlier than C1 1.2 SP3 have absolute file path references, f.e.: // <File filename="C:\inetpub\docs\Frontend\Composite\Forms\Renderer\CaptchaImageCreator.ashx" /> // <File filename="C:\inetpub\docs\Frontend\Composite\Forms\Renderer\Controls/FormsRender.ascx" /> // <File filename="C:\inetpub\docs\Frontend\Composite\Forms\Renderer\Controls/FormsRender.ascx.cs" /> List <string> absoluteReferences = new List <string>(); if (filesElement != null) { foreach (XElement fileElement in filesElement.Elements("File").Reverse()) { XAttribute filenameAttribute = fileElement.Attribute("filename"); if (filenameAttribute == null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingAttribute("filename"), fileElement); continue; } string filePath = filenameAttribute.Value; if (filePath.Contains(":\\")) { absoluteReferences.Add(filePath); continue; } filePath = PathUtil.Resolve(filePath); string backupFile = (string)fileElement.Attribute("backupFile"); if (backupFile != null) { var backupFilePath = Path.Combine(UninstallerContext.PackageDirectory, "FileBackup", backupFile); if (!C1File.Exists(backupFilePath)) { validationResult.AddFatal("Missing backup file '{0}'".FormatWith(backupFilePath), fileElement); continue; } _filesToCopy.Add(new Tuple <string, string>(backupFilePath, filePath)); } else { _filesToDelete.Add(filePath); } } } if (absoluteReferences.Count > 0) { // Trying to resolve what was the old absolute path. // To do that the longest common beginning is calculated string longestCommonBegining; string firstPath = absoluteReferences[0]; if (absoluteReferences.Count == 1) { longestCommonBegining = firstPath; } else { int shortestPathLength = absoluteReferences.Min(path => path.Length); int commonStartLength = 0; for (; commonStartLength < shortestPathLength; commonStartLength++) { bool match = true; char symbol = firstPath[commonStartLength]; for (int i = 1; i < absoluteReferences.Count; i++) { if (absoluteReferences[i][commonStartLength] != symbol) { match = false; break; } } if (!match) { break; } } longestCommonBegining = firstPath.Substring(0, commonStartLength); } longestCommonBegining = longestCommonBegining.Replace('/', '\\'); if (!longestCommonBegining.EndsWith("\\")) { longestCommonBegining = longestCommonBegining.Substring(0, longestCommonBegining.LastIndexOf("\\", StringComparison.Ordinal) + 1); } string newRoot = PathUtil.BaseDirectory; if (!newRoot.EndsWith("\\")) { newRoot += "\\"; } // If the site hasn't been moved to another folder, just using the pathes if (longestCommonBegining.StartsWith(newRoot, StringComparison.OrdinalIgnoreCase)) { _filesToDelete.AddRange(absoluteReferences); } else { // If the longest common path looks like C:\inetpub\docs\Frontend\Composite\ // than we will the following pathes as site roots: // // C:\inetpub\docs\Frontend\Composite\ // C:\inetpub\docs\Frontend\ // C:\inetpub\docs\ // C:\inetpub\ // C:\ string oldRoot = longestCommonBegining; bool fileExists = false; while (!string.IsNullOrEmpty(oldRoot)) { for (int i = 0; i < absoluteReferences.Count; i++) { if (C1File.Exists(ReplaceFolder(absoluteReferences[0], oldRoot, newRoot))) { fileExists = true; break; } } if (fileExists) { break; } oldRoot = ReducePath(oldRoot); } if (!fileExists) { // Showing a message if we don't have a match validationResult.AddFatal(Texts.FilePackageFragmentInstaller_WrongBasePath); } else { _filesToDelete.AddRange(absoluteReferences.Select(path => ReplaceFolder(path, oldRoot, newRoot))); } } } if (validationResult.Count > 0) { _filesToDelete = null; _filesToCopy = null; } return(validationResult); }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); if (this.Configuration.Count(f => f.Name == "Files") > 1) { validationResult.AddFatal(Texts.FilePackageFragmentUninstaller_OnlyOneFilesElement, ConfigurationParent); return(validationResult); } XElement filesElement = this.Configuration.SingleOrDefault(f => f.Name == "Files"); _filesToDelete = new List <string>(); _filesToCopy = new List <FileToCopy>(); if (filesElement != null) { foreach (XElement fileElement in filesElement.Elements("File").Reverse()) { XAttribute filenameAttribute = fileElement.Attribute("filename"); if (filenameAttribute == null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingAttribute("filename"), fileElement); continue; } string relativeFilePath = filenameAttribute.Value; string filePath = PathUtil.Resolve(relativeFilePath); string backupFile = (string)fileElement.Attribute("backupFile"); if (backupFile != null) { var backupFilePath = Path.Combine(UninstallerContext.PackageDirectory, "FileBackup", backupFile); if (!C1File.Exists(backupFilePath)) { validationResult.AddFatal("Missing backup file '{0}'".FormatWith(backupFilePath), fileElement); continue; } _filesToCopy.Add(new FileToCopy { BackupFilePath = backupFilePath, FilePath = filePath, RelativeFilePath = relativeFilePath }); } else { _filesToDelete.Add(filePath); } } } if (validationResult.Count > 0) { _filesToDelete = null; _filesToCopy = null; } return(validationResult); }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); if (this.Configuration.Count(f => f.Name == "Files") > 1) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyOneFilesElement, this.ConfigurationParent); return(validationResult); } if (this.Configuration.Count(f => f.Name == "Directories") > 1) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyOneDirectoriesElement, this.ConfigurationParent); return(validationResult); } XElement filesElement = this.Configuration.SingleOrDefault(f => f.Name == "Files"); XElement directoriesElement = this.Configuration.SingleOrDefault(f => f.Name == "Directories"); _filesToCopy = new List <FileToCopy>(); _directoriesToDelete = new List <string>(); if (filesElement != null) { foreach (XElement fileElement in filesElement.Elements("File")) { XAttribute sourceFilenameAttribute = fileElement.Attribute("sourceFilename"); XAttribute targetFilenameAttribute = fileElement.Attribute("targetFilename"); if (sourceFilenameAttribute == null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingAttribute("sourceFilename"), fileElement); continue; } if (targetFilenameAttribute == null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingAttribute("targetFilename"), fileElement); continue; } XAttribute allowOverwriteAttribute = fileElement.Attribute("allowOverwrite"); XAttribute assemblyLoadAttribute = fileElement.Attribute("assemblyLoad"); XAttribute deleteTargetDirectoryAttribute = fileElement.Attribute("deleteTargetDirectory"); XAttribute onlyUpdateAttribute = fileElement.Attribute("onlyUpdate"); XAttribute onlyAddAttribute = fileElement.Attribute("onlyAdd"); if (deleteTargetDirectoryAttribute != null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_DeleteTargetDirectoryNotAllowed, fileElement); continue; } bool allowOverwrite = false; if (!ParseBoolAttribute(allowOverwriteAttribute, validationResult, ref allowOverwrite)) { continue; } bool loadAssembly = false; if (!ParseBoolAttribute(assemblyLoadAttribute, validationResult, ref loadAssembly)) { continue; } bool onlyUpdate = false; if (!ParseBoolAttribute(onlyUpdateAttribute, validationResult, ref onlyUpdate)) { continue; } bool onlyAdd = false; if (!ParseBoolAttribute(onlyAddAttribute, validationResult, ref onlyAdd)) { continue; } string sourceFilename = sourceFilenameAttribute.Value; if (!this.InstallerContext.ZipFileSystem.ContainsFile(sourceFilename)) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingFile(sourceFilename), sourceFilenameAttribute); continue; } if (loadAssembly && onlyUpdate) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyUpdateNotAllowedWithLoadAssemlby, onlyUpdateAttribute); continue; } if (onlyAdd && onlyUpdate) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyUpdateAndOnlyAddNotAllowed, onlyUpdateAttribute); continue; } if (onlyAdd && allowOverwrite) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyAddAndAllowOverwriteNotAllowed, onlyAddAttribute); continue; } string targetFilename = PathUtil.Resolve(targetFilenameAttribute.Value); if (C1File.Exists(targetFilename)) { if (onlyAdd) { Log.LogVerbose(LogTitle, "Skipping adding of the file '{0}' because it already exist and is marked 'onlyAdd'", targetFilename); continue; // Target file does not, so skip this } if (!allowOverwrite && !onlyUpdate) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_FileExists(targetFilename), targetFilenameAttribute); continue; } if (((C1File.GetAttributes(targetFilename) & FileAttributes.ReadOnly) > 0) && !allowOverwrite) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_FileReadOnly(targetFilename), targetFilenameAttribute); continue; } } else if (onlyUpdate) { Log.LogVerbose(LogTitle, "Skipping updating of the file '{0}' because it does not exist", targetFilename); continue; // Target file does not, so skip this } var fileToCopy = new FileToCopy { SourceFilename = sourceFilename, TargetRelativeFilePath = targetFilenameAttribute.Value, TargetFilePath = targetFilename, Overwrite = allowOverwrite || onlyUpdate }; _filesToCopy.Add(fileToCopy); if (loadAssembly) { string tempFilename = Path.Combine(this.InstallerContext.TempDirectory, Path.GetFileName(targetFilename)); this.InstallerContext.ZipFileSystem.WriteFileToDisk(sourceFilename, tempFilename); PackageAssemblyHandler.AddAssembly(tempFilename); } } } if (directoriesElement != null) { foreach (XElement directoryElement in directoriesElement.Elements("Directory")) { XAttribute sourceDirectoryAttribute = directoryElement.Attribute("sourceDirectory"); XAttribute targetDirectoryAttribute = directoryElement.Attribute("targetDirectory"); if (sourceDirectoryAttribute == null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingAttribute("sourceDirectory"), directoryElement); continue; } if (targetDirectoryAttribute == null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingAttribute("targetDirectory"), directoryElement); continue; } XAttribute allowOverwriteAttribute = directoryElement.Attribute("allowOverwrite"); XAttribute assemblyLoadAttribute = directoryElement.Attribute("assemblyLoad"); XAttribute deleteTargetDirectoryAttribute = directoryElement.Attribute("deleteTargetDirectory"); XAttribute onlyUpdateAttribute = directoryElement.Attribute("onlyUpdate"); if (assemblyLoadAttribute != null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_AssemblyLoadNotAllowed, directoryElement); continue; } if (onlyUpdateAttribute != null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyUpdateNotAllowed, directoryElement); continue; } bool allowOverwrite = false; if (!ParseBoolAttribute(allowOverwriteAttribute, validationResult, ref allowOverwrite)) { continue; } bool deleteTargetDirectory = false; if (!ParseBoolAttribute(deleteTargetDirectoryAttribute, validationResult, ref deleteTargetDirectory)) { continue; } string sourceDirectory = sourceDirectoryAttribute.Value; if (!this.InstallerContext.ZipFileSystem.ContainsDirectory(sourceDirectory)) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingDirectory(sourceDirectory), sourceDirectoryAttribute); continue; } string targetDirectory = PathUtil.Resolve(targetDirectoryAttribute.Value); if (deleteTargetDirectory) { if (C1Directory.Exists(targetDirectory)) { _directoriesToDelete.Add(targetDirectory); } } foreach (string sourceFilename in this.InstallerContext.ZipFileSystem.GetFilenames(sourceDirectory)) { string resolvedSourceFilename = sourceFilename.Remove(0, sourceDirectory.Length); if (resolvedSourceFilename.StartsWith("/")) { resolvedSourceFilename = resolvedSourceFilename.Remove(0, 1); } string targetFilename = Path.Combine(targetDirectory, resolvedSourceFilename); if (C1File.Exists(targetFilename) && !deleteTargetDirectory && !allowOverwrite) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_FileExists(targetFilename), targetDirectoryAttribute); continue; } var fileToCopy = new FileToCopy { SourceFilename = sourceFilename, TargetRelativeFilePath = Path.Combine(targetDirectoryAttribute.Value, resolvedSourceFilename), TargetFilePath = targetFilename, Overwrite = allowOverwrite }; _filesToCopy.Add(fileToCopy); } } } if (validationResult.Count > 0) { _filesToCopy = null; _directoriesToDelete = null; } return(validationResult); }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); if (this.Configuration.Count(f => f.Name == "Types") > 1) { validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_OnlyOneElement); return(validationResult); } _dataToDelete = new List <DataType>(); XElement typesElement = this.Configuration.SingleOrDefault(f => f.Name == "Types"); if (typesElement == null) { return(validationResult); } foreach (XElement typeElement in typesElement.Elements("Type").Reverse()) { XAttribute typeAttribute = typeElement.Attribute("type"); XAttribute dataScopeIdentifierAttribute = typeElement.Attribute("dataScopeIdentifier"); if (typeAttribute == null) { validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_MissingAttribute("type"), typeElement); continue; } if (dataScopeIdentifierAttribute == null) { validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_MissingAttribute("dataScopeIdentifier"), typeElement); continue; } Type type = TypeManager.TryGetType(typeAttribute.Value); if (type == null) { continue; } if (!DataFacade.GetAllInterfaces().Contains(type)) { continue; } DataScopeIdentifier dataScopeIdentifier; try { dataScopeIdentifier = DataScopeIdentifier.Deserialize(dataScopeIdentifierAttribute.Value); } catch (Exception) { validationResult.AddFatal("Wrong DataScopeIdentifier ({0}) name in the configuration".FormatWith(dataScopeIdentifierAttribute.Value), dataScopeIdentifierAttribute); continue; } foreach (XElement datasElement in typeElement.Elements("Datas").Reverse()) { CultureInfo locale = null; XAttribute localeAttribute = datasElement.Attribute("locale"); if (localeAttribute != null) { locale = CultureInfo.CreateSpecificCulture(localeAttribute.Value); } foreach (XElement keysElement in datasElement.Elements("Keys").Reverse()) { bool allKeyPropertiesValidated = true; var dataKeyPropertyCollection = new DataKeyPropertyCollection(); foreach (XElement keyElement in keysElement.Elements("Key")) { XAttribute keyNameAttribute = keyElement.Attribute("name"); XAttribute keyValueAttribute = keyElement.Attribute("value"); if (keyNameAttribute == null || keyValueAttribute == null) { if (keyNameAttribute == null) { validationResult.AddFatal(GetText("DataPackageFragmentUninstaller.MissingAttribute").FormatWith("name"), keyElement); } if (keyValueAttribute == null) { validationResult.AddFatal(GetText("DataPackageFragmentUninstaller.MissingAttribute").FormatWith("value"), keyElement); } allKeyPropertiesValidated = false; continue; } string keyName = keyNameAttribute.Value; PropertyInfo keyPropertyInfo = type.GetPropertiesRecursively().SingleOrDefault(f => f.Name == keyName); if (keyPropertyInfo == null) { validationResult.AddFatal(GetText("DataPackageFragmentUninstaller.MissingKeyProperty").FormatWith(type, keyName)); allKeyPropertiesValidated = false; } else { try { object keyValue = ValueTypeConverter.Convert(keyValueAttribute.Value, keyPropertyInfo.PropertyType); dataKeyPropertyCollection.AddKeyProperty(keyName, keyValue); } catch (Exception) { allKeyPropertiesValidated = false; validationResult.AddFatal(GetText("DataPackageFragmentUninstaller.DataPackageFragmentUninstaller").FormatWith(keyValueAttribute.Value, keyPropertyInfo.PropertyType)); } } } if (allKeyPropertiesValidated) { IData data; using (new DataScope(dataScopeIdentifier, locale)) { data = DataFacade.TryGetDataByUniqueKey(type, dataKeyPropertyCollection); } if (data != null) { CheckForPotentialBrokenReferences(data, validationResult, type, dataScopeIdentifier, locale, dataKeyPropertyCollection); } } } } } if (validationResult.Count > 0) { _dataToDelete = null; } return(validationResult); }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); if (this.Configuration.Count(f => f.Name == "Files") > 1) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyOneFilesElement, this.ConfigurationParent); return(validationResult); } XElement filesElement = this.Configuration.SingleOrDefault(f => f.Name == "Files"); _filesToCopy = new List <FileToCopy>(); if (filesElement != null) { foreach (XElement fileElement in filesElement.Elements("File")) { XAttribute sourceFilenameAttribute = fileElement.Attribute("sourceFilename"); XAttribute targetFilenameAttribute = fileElement.Attribute("targetFilename"); if (sourceFilenameAttribute == null) { validationResult.AddFatal( Texts.FilePackageFragmentInstaller_MissingAttribute("sourceFilename"), fileElement); continue; } if (targetFilenameAttribute == null) { validationResult.AddFatal( Texts.FilePackageFragmentInstaller_MissingAttribute("targetFilename"), fileElement); continue; } XAttribute allowOverwriteAttribute = fileElement.Attribute("allowOverwrite"); XAttribute assemblyLoadAttribute = fileElement.Attribute("assemblyLoad"); XAttribute onlyUpdateAttribute = fileElement.Attribute("onlyUpdate"); XAttribute addAssemblyBindingAttribute = fileElement.Attribute("addAssemblyBinding"); bool allowOverwrite = false; if (!ParseBoolAttribute(allowOverwriteAttribute, validationResult, ref allowOverwrite)) { continue; } bool loadAssembly = false; if (!ParseBoolAttribute(assemblyLoadAttribute, validationResult, ref loadAssembly)) { continue; } bool onlyUpdate = false; if (!ParseBoolAttribute(onlyUpdateAttribute, validationResult, ref onlyUpdate)) { continue; } bool addAssemblyBinding = false; if (!ParseBoolAttribute(addAssemblyBindingAttribute, validationResult, ref addAssemblyBinding)) { continue; } string sourceFilename = sourceFilenameAttribute.Value; if (!this.InstallerContext.ZipFileSystem.ContainsFile(sourceFilename)) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingFile(sourceFilename), sourceFilenameAttribute); continue; } if (loadAssembly && onlyUpdate) { validationResult.AddFatal( Texts.FilePackageFragmentInstaller_OnlyUpdateNotAllowedWithLoadAssemlby, onlyUpdateAttribute); continue; } string targetFilename = PathUtil.Resolve(targetFilenameAttribute.Value); if (C1File.Exists(targetFilename)) { if (!allowOverwrite && !onlyUpdate) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_FileExists(targetFilename), targetFilenameAttribute); continue; } if (((C1File.GetAttributes(targetFilename) & FileAttributes.ReadOnly) > 0) && !allowOverwrite) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_FileReadOnly(targetFilename), targetFilenameAttribute); continue; } } else if (onlyUpdate) { Log.LogVerbose(LogTitle, "Skipping updating of the file '{0}' because it does not exist", targetFilename); continue; // Target file does not, so skip this } var fileToCopy = new FileToCopy { SourceFilename = sourceFilename, TargetRelativeFilePath = targetFilenameAttribute.Value, TargetFilePath = targetFilename, Overwrite = allowOverwrite || onlyUpdate, AddAssemblyBinding = addAssemblyBinding }; _filesToCopy.Add(fileToCopy); if (loadAssembly) { string tempFilename = Path.Combine(this.InstallerContext.TempDirectory, Path.GetFileName(targetFilename)); this.InstallerContext.ZipFileSystem.WriteFileToDisk(sourceFilename, tempFilename); PackageAssemblyHandler.AddAssembly(tempFilename); } } } if (validationResult.Count > 0) { _filesToCopy = null; } return(validationResult); }
/// <exclude/> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); _contentToAdd = new List <ContentToAdd>(); foreach (var element in this.Configuration) { if (element.Name != AppendText_ElementName) { validationResult.AddFatal(Texts.PackageFragmentInstaller_IncorrectElement(element.Name.LocalName, AppendText_ElementName), element); continue; } var pathAttr = element.Attribute(TargetXml_AttributeName); if (pathAttr == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute(TargetXml_AttributeName), element); continue; } string path = (string)pathAttr; var actionOnMissingFile = ActionOnMissingFile.Fail; var whenNotExistsAttr = element.Attribute(WhenNotExist_AttributeName); if (whenNotExistsAttr != null) { actionOnMissingFile = (ActionOnMissingFile)Enum.Parse(typeof(ActionOnMissingFile), whenNotExistsAttr.Value, true); } string filePath = PathUtil.Resolve(path); if (!C1File.Exists(filePath)) { if (actionOnMissingFile == ActionOnMissingFile.Fail) { validationResult.AddFatal(Texts.FileModifyPackageFragmentInstaller_FileDoesNotExist(filePath), pathAttr); continue; } if (actionOnMissingFile == ActionOnMissingFile.Ignore) { continue; } } _contentToAdd.Add(new ContentToAdd { Path = filePath, Content = element.Value }); } if (validationResult.Any()) { _contentToAdd = null; } return(validationResult); }