コード例 #1
0
ファイル: PackageInstaller.cs プロジェクト: jim116801/C1-CMS
        /// <exclude />
        public PackageInstaller(IPackageInstallerUninstallerFactory packageInstallerUninstallerFactory, string zipFilename, string packageInstallDirectory, string tempDirectory, PackageInformation packageInformation)
        {
            if (packageInstallerUninstallerFactory == null)
            {
                throw new ArgumentNullException("packageInstallerUninstallerFactory");
            }
            if (string.IsNullOrEmpty(zipFilename))
            {
                throw new ArgumentNullException("zipFilename");
            }
            if (string.IsNullOrEmpty(packageInstallDirectory))
            {
                throw new ArgumentNullException("packageInstallDirectory");
            }
            if (string.IsNullOrEmpty(tempDirectory))
            {
                throw new ArgumentNullException("tempDirectory");
            }
            if (packageInformation == null)
            {
                throw new ArgumentNullException("packageInformation");
            }

            this.PackageInstallerUninstallerFactory = packageInstallerUninstallerFactory;
            this.ZipFilename             = zipFilename;
            this.PackageInstallDirectory = packageInstallDirectory;
            this.TempDirectory           = tempDirectory;
            this.PackageInformation      = packageInformation;
        }
コード例 #2
0
        internal PackageUninstallerContext(IZipFileSystem zipFileSystem, string packageDirectory, PackageInformation packageInformation)
        {
            Verify.ArgumentNotNull(zipFileSystem, "zipFileSystem");

            this.ZipFileSystem = zipFileSystem;
            this.PackageDirectory = packageDirectory;
            this.PackageInformation = packageInformation;
        }
コード例 #3
0
        internal PackageInstallerContext(IZipFileSystem zipFileSystem, string packageDirectory, string tempDirectory, PackageInformation packageInformation)
        {
            Verify.ArgumentNotNull(zipFileSystem, "zipFileSystem");
            Verify.ArgumentNotNullOrEmpty(tempDirectory, "tempDirectory");
            Verify.ArgumentNotNull(packageInformation, "packageInformation");

            this.ZipFileSystem = zipFileSystem;
            this.PackageDirectory = packageDirectory;
            this.TempDirectory = tempDirectory;
            this.PackageInformation = packageInformation;
        }
コード例 #4
0
ファイル: PackageInstaller.cs プロジェクト: hitesh97/C1-CMS
        /// <exclude />
        public PackageInstaller(IPackageInstallerUninstallerFactory packageInstallerUninstallerFactory, string zipFilename, string packageInstallDirectory, string tempDirectory, PackageInformation packageInformation)
        {
            if (packageInstallerUninstallerFactory == null) throw new ArgumentNullException("packageInstallerUninstallerFactory");
            if (string.IsNullOrEmpty(zipFilename)) throw new ArgumentNullException("zipFilename");
            if (string.IsNullOrEmpty(packageInstallDirectory)) throw new ArgumentNullException("packageInstallDirectory");
            if (string.IsNullOrEmpty(tempDirectory)) throw new ArgumentNullException("tempDirectory");
            if (packageInformation == null) throw new ArgumentNullException("packageInformation");

            this.PackageInstallerUninstallerFactory = packageInstallerUninstallerFactory;
            this.ZipFilename = zipFilename;
            this.PackageInstallDirectory = packageInstallDirectory;
            this.TempDirectory = tempDirectory;
            this.PackageInformation = packageInformation;
        }
コード例 #5
0
        public PackageUninstaller(string zipFilename, string uninstallFilename, string packageInstallationDirectory, string tempDirectory, bool flushOnCompletion, bool reloadConsoleOnCompletion, bool useTransaction, PackageInformation packageInformation)
        {
            Verify.ArgumentNotNullOrEmpty(zipFilename, "zipFilename");
            Verify.ArgumentNotNullOrEmpty(uninstallFilename, "uninstallFilename");
            Verify.ArgumentNotNullOrEmpty(packageInstallationDirectory, "packageInstallationDirectory");
            Verify.ArgumentNotNullOrEmpty(tempDirectory, "tempDirectory");

            this.ZipFilename                  = zipFilename;
            this.UninstallFilename            = uninstallFilename;
            this.PackageInstallationDirectory = packageInstallationDirectory;
            this.TempDirectory                = tempDirectory;
            this.FlushOnCompletion            = flushOnCompletion;
            this.ReloadConsoleOnCompletion    = reloadConsoleOnCompletion;
            this.UseTransaction               = useTransaction;
            this.PackageInformation           = packageInformation;
        }
コード例 #6
0
        public PackageUninstaller(string zipFilename, string uninstallFilename, string packageInstallationDirectory, string tempDirectory, bool flushOnCompletion, bool reloadConsoleOnCompletion, bool useTransaction, PackageInformation packageInformation)
        {
            Verify.ArgumentNotNullOrEmpty(zipFilename, "zipFilename");
            Verify.ArgumentNotNullOrEmpty(uninstallFilename, "uninstallFilename");
            Verify.ArgumentNotNullOrEmpty(packageInstallationDirectory, "packageInstallationDirectory");
            Verify.ArgumentNotNullOrEmpty(tempDirectory, "tempDirectory");

            this.ZipFilename = zipFilename;
            this.UninstallFilename = uninstallFilename;
            this.PackageInstallationDirectory = packageInstallationDirectory;
            this.TempDirectory = tempDirectory;
            this.FlushOnCompletion = flushOnCompletion;
            this.ReloadConsoleOnCompletion = reloadConsoleOnCompletion;
            this.UseTransaction = useTransaction;
            this.PackageInformation = packageInformation;
        }
 public IPackageUninstaller CreateUninstaller(string zipFilename, string uninstallFilename, string packageInstallationDirectory, string tempDirectory, bool flushOnCompletion, bool reloadConsoleOnCompletion, bool useTransaction, PackageInformation packageInformation)
 {
     return(new PackageUninstaller(zipFilename, uninstallFilename, packageInstallationDirectory, tempDirectory, flushOnCompletion, reloadConsoleOnCompletion, useTransaction, packageInformation));
 }
コード例 #8
0
        internal PackageInstallerContext(IZipFileSystem zipFileSystem, string packageDirectory, string tempDirectory, PackageInformation packageInformation)
        {
            Verify.ArgumentNotNull(zipFileSystem, "zipFileSystem");
            Verify.ArgumentNotNullOrEmpty(tempDirectory, "tempDirectory");
            Verify.ArgumentNotNull(packageInformation, "packageInformation");

            this.ZipFileSystem      = zipFileSystem;
            this.PackageDirectory   = packageDirectory;
            this.TempDirectory      = tempDirectory;
            this.PackageInformation = packageInformation;
        }
コード例 #9
0
        internal PackageUninstallerContext(IZipFileSystem zipFileSystem, string packageDirectory, PackageInformation packageInformation)
        {
            Verify.ArgumentNotNull(zipFileSystem, "zipFileSystem");

            this.ZipFileSystem      = zipFileSystem;
            this.PackageDirectory   = packageDirectory;
            this.PackageInformation = packageInformation;
        }
コード例 #10
0
        private static string CreatePackageDirectoryName(PackageInformation packageInformation)
        {
            string directoryName = $"{packageInformation.Id}";

            return(Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.PackageDirectory), directoryName));
        }
コード例 #11
0
        internal static PackageFragmentValidationResult ValidatePackageInformation(XElement installContent, out PackageInformation packageInformation)
        {
            packageInformation = null;

            XElement packageInformationElement = installContent.Element(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageInformationElementName));

            if (packageInformationElement == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingElement"), PackageSystemSettings.PackageInformationElementName), installContent));
            }

            XAttribute idAttribute                        = packageInformationElement.Attribute(PackageSystemSettings.IdAttributeName);
            XAttribute nameAttribute                      = packageInformationElement.Attribute(PackageSystemSettings.NameAttributeName);
            XAttribute groupNameAttribute                 = packageInformationElement.Attribute(PackageSystemSettings.GroupNameAttributeName);
            XAttribute authorAttribute                    = packageInformationElement.Attribute(PackageSystemSettings.AuthorAttributeName);
            XAttribute websiteAttribute                   = packageInformationElement.Attribute(PackageSystemSettings.WebsiteAttributeName);
            XAttribute versionAttribute                   = packageInformationElement.Attribute(PackageSystemSettings.VersionAttributeName);
            XAttribute canBeUninstalledAttribute          = packageInformationElement.Attribute(PackageSystemSettings.CanBeUninstalledAttributeName);
            XAttribute systemLockingAttribute             = packageInformationElement.Attribute(PackageSystemSettings.SystemLockingAttributeName);
            XAttribute flushOnCompletionAttribute         = packageInformationElement.Attribute(PackageSystemSettings.FlushOnCompletionAttributeName);
            XAttribute reloadConsoleOnCompletionAttribute = packageInformationElement.Attribute(PackageSystemSettings.ReloadConsoleOnCompletionAttributeName);

            if (idAttribute == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.IdAttributeName), packageInformationElement));
            }
            if (nameAttribute == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.NameAttributeName), packageInformationElement));
            }
            if (groupNameAttribute == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.GroupNameAttributeName), packageInformationElement));
            }
            if (authorAttribute == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.AuthorAttributeName), packageInformationElement));
            }
            if (websiteAttribute == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.WebsiteAttributeName), packageInformationElement));
            }
            if (versionAttribute == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.VersionAttributeName), packageInformationElement));
            }
            if (canBeUninstalledAttribute == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.CanBeUninstalledAttributeName), packageInformationElement));
            }
            if (systemLockingAttribute == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.SystemLockingAttributeName), packageInformationElement));
            }

            if (string.IsNullOrEmpty(nameAttribute.Value))
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.NameAttributeName), nameAttribute));
            }
            if (string.IsNullOrEmpty(groupNameAttribute.Value))
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.GroupNameAttributeName), groupNameAttribute));
            }
            if (string.IsNullOrEmpty(authorAttribute.Value))
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.AuthorAttributeName), authorAttribute));
            }
            if (string.IsNullOrEmpty(websiteAttribute.Value))
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.WebsiteAttributeName), websiteAttribute));
            }
            if (string.IsNullOrEmpty(versionAttribute.Value))
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.VersionAttributeName), versionAttribute));
            }
            if (string.IsNullOrEmpty(packageInformationElement.Value))
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidElementValue"), PackageSystemSettings.PackageInformationElementName), packageInformationElement));
            }

            Guid id;

            if (idAttribute.TryGetGuidValue(out id) == false)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.IdAttributeName), idAttribute));
            }


            string newVersion;

            if (VersionStringHelper.ValidateVersion(versionAttribute.Value, out newVersion))
            {
                versionAttribute.Value = newVersion;
            }
            else
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.VersionAttributeName), versionAttribute));
            }

            bool canBeUninstalled;

            if (canBeUninstalledAttribute.TryGetBoolValue(out canBeUninstalled) == false)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.CanBeUninstalledAttributeName), canBeUninstalledAttribute));
            }

            SystemLockingType systemLockingType;

            if (systemLockingAttribute.TryDeserialize(out systemLockingType) == false)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.SystemLockingAttributeName), systemLockingAttribute));
            }

            bool flushOnCompletion = false;

            if ((flushOnCompletionAttribute != null) && (flushOnCompletionAttribute.TryGetBoolValue(out flushOnCompletion) == false))
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.FlushOnCompletionAttributeName), flushOnCompletionAttribute));
            }

            bool reloadConsoleOnCompletion = false;

            if ((reloadConsoleOnCompletionAttribute != null) && (reloadConsoleOnCompletionAttribute.TryGetBoolValue(out reloadConsoleOnCompletion) == false))
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.ReloadConsoleOnCompletionAttributeName), reloadConsoleOnCompletionAttribute));
            }


            XElement packageRequirementsElement = installContent.Element(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageRequirementsElementName));

            if (packageRequirementsElement == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingElement"), PackageSystemSettings.PackageRequirementsElementName), installContent));
            }

            XAttribute minimumCompositeVersionAttribute = packageRequirementsElement.Attribute(PackageSystemSettings.MinimumCompositeVersionAttributeName);
            XAttribute maximumCompositeVersionAttribute = packageRequirementsElement.Attribute(PackageSystemSettings.MaximumCompositeVersionAttributeName);

            if (minimumCompositeVersionAttribute == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.MinimumCompositeVersionAttributeName), packageRequirementsElement));
            }
            if (maximumCompositeVersionAttribute == null)
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.MaximumCompositeVersionAttributeName), packageRequirementsElement));
            }

            if (string.IsNullOrEmpty(minimumCompositeVersionAttribute.Value))
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.MinimumCompositeVersionAttributeName), minimumCompositeVersionAttribute));
            }
            if (string.IsNullOrEmpty(maximumCompositeVersionAttribute.Value))
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.MaximumCompositeVersionAttributeName), maximumCompositeVersionAttribute));
            }

            if (VersionStringHelper.ValidateVersion(minimumCompositeVersionAttribute.Value, out newVersion))
            {
                minimumCompositeVersionAttribute.Value = newVersion;
            }
            else
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.VersionAttributeName), minimumCompositeVersionAttribute));
            }

            if (VersionStringHelper.ValidateVersion(maximumCompositeVersionAttribute.Value, out newVersion))
            {
                maximumCompositeVersionAttribute.Value = newVersion;
            }
            else
            {
                return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.VersionAttributeName), maximumCompositeVersionAttribute));
            }


            packageInformation = new PackageInformation
            {
                Id                           = id,
                Name                         = nameAttribute.Value,
                GroupName                    = groupNameAttribute.Value,
                Author                       = authorAttribute.Value,
                Website                      = websiteAttribute.Value,
                Version                      = versionAttribute.Value,
                CanBeUninstalled             = canBeUninstalled,
                SystemLockingType            = systemLockingType,
                Description                  = packageInformationElement.Value,
                FlushOnCompletion            = flushOnCompletion,
                ReloadConsoleOnCompletion    = reloadConsoleOnCompletion,
                MinCompositeVersionSupported = new Version(minimumCompositeVersionAttribute.Value),
                MaxCompositeVersionSupported = new Version(maximumCompositeVersionAttribute.Value)
            };

            return(null);
        }
コード例 #12
0
        /// <exclude />
        public static PackageManagerUninstallProcess Uninstall(Guid id)
        {
            try
            {
                string absolutePath = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.PackageDirectory), id.ToString());

                InstalledPackageInformation installedPackageInformation =
                    (from package in GetInstalledPackages()
                     where package.Id == id
                     select package).SingleOrDefault();

                if (installedPackageInformation == null)
                {
                    return(new PackageManagerUninstallProcess(new List <PackageFragmentValidationResult> {
                        new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingPackageDirectory"), absolutePath))
                    }));
                }

                Log.LogVerbose("PackageManager", "Uninstalling package: {0}, Id = {1}", installedPackageInformation.Name, installedPackageInformation.Id);

                if (installedPackageInformation.CanBeUninstalled == false)
                {
                    return(new PackageManagerUninstallProcess(new List <PackageFragmentValidationResult> {
                        new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, GetText("PackageManager.Uninstallable"))
                    }));
                }

                string zipFilePath = Path.Combine(absolutePath, PackageSystemSettings.ZipFilename);
                if (C1File.Exists(zipFilePath) == false)
                {
                    return(new PackageManagerUninstallProcess(new List <PackageFragmentValidationResult> {
                        new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingZipFile"), zipFilePath))
                    }));
                }

                string uninstallFilePath = Path.Combine(absolutePath, PackageSystemSettings.UninstallFilename);
                if (C1File.Exists(uninstallFilePath) == false)
                {
                    return(new PackageManagerUninstallProcess(new List <PackageFragmentValidationResult> {
                        new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingUninstallFile"), uninstallFilePath))
                    }));
                }

                PackageInformation packageInformation = new PackageInformation
                {
                    Id                        = installedPackageInformation.Id,
                    Name                      = installedPackageInformation.Name,
                    GroupName                 = installedPackageInformation.GroupName,
                    Author                    = installedPackageInformation.Author,
                    Website                   = installedPackageInformation.Website,
                    Description               = installedPackageInformation.Description,
                    Version                   = installedPackageInformation.Version,
                    CanBeUninstalled          = installedPackageInformation.CanBeUninstalled,
                    SystemLockingType         = installedPackageInformation.SystemLockingType,
                    FlushOnCompletion         = installedPackageInformation.FlushOnCompletion,
                    ReloadConsoleOnCompletion = installedPackageInformation.ReloadConsoleOnCompletion,
                };


                PackageUninstaller packageUninstaller = new PackageUninstaller(zipFilePath, uninstallFilePath, absolutePath, TempDirectoryFacade.CreateTempDirectory(), installedPackageInformation.FlushOnCompletion, installedPackageInformation.ReloadConsoleOnCompletion, true, packageInformation);

                PackageManagerUninstallProcess packageManagerUninstallProcess = new PackageManagerUninstallProcess(packageUninstaller, absolutePath, installedPackageInformation.SystemLockingType);
                return(packageManagerUninstallProcess);
            }
            catch (Exception ex)
            {
                return(new PackageManagerUninstallProcess(new List <PackageFragmentValidationResult> {
                    new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex)
                }));
            }
        }
コード例 #13
0
ファイル: PackageManager.cs プロジェクト: DBailey635/C1-CMS
        private static string CreatePackageDirectoryName(PackageInformation packageInformation)
        {
            string directoryName = $"{packageInformation.Id}";

            return Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.PackageDirectory), directoryName);
        }
コード例 #14
0
ファイル: PackageManager.cs プロジェクト: DBailey635/C1-CMS
        internal static PackageFragmentValidationResult ValidatePackageInformation(XElement installContent, out PackageInformation packageInformation)
        {
            packageInformation = null;

            XElement packageInformationElement = installContent.Element(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageInformationElementName));
            if (packageInformationElement == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingElement"), PackageSystemSettings.PackageInformationElementName), installContent);

            XAttribute idAttribute = packageInformationElement.Attribute(PackageSystemSettings.IdAttributeName);
            XAttribute nameAttribute = packageInformationElement.Attribute(PackageSystemSettings.NameAttributeName);
            XAttribute groupNameAttribute = packageInformationElement.Attribute(PackageSystemSettings.GroupNameAttributeName);
            XAttribute authorAttribute = packageInformationElement.Attribute(PackageSystemSettings.AuthorAttributeName);
            XAttribute websiteAttribute = packageInformationElement.Attribute(PackageSystemSettings.WebsiteAttributeName);
            XAttribute versionAttribute = packageInformationElement.Attribute(PackageSystemSettings.VersionAttributeName);
            XAttribute canBeUninstalledAttribute = packageInformationElement.Attribute(PackageSystemSettings.CanBeUninstalledAttributeName);
            XAttribute systemLockingAttribute = packageInformationElement.Attribute(PackageSystemSettings.SystemLockingAttributeName);
            XAttribute flushOnCompletionAttribute = packageInformationElement.Attribute(PackageSystemSettings.FlushOnCompletionAttributeName);
            XAttribute reloadConsoleOnCompletionAttribute = packageInformationElement.Attribute(PackageSystemSettings.ReloadConsoleOnCompletionAttributeName);

            if (idAttribute == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.IdAttributeName), packageInformationElement);
            if (nameAttribute == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.NameAttributeName), packageInformationElement);
            if (groupNameAttribute == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.GroupNameAttributeName), packageInformationElement);
            if (authorAttribute == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.AuthorAttributeName), packageInformationElement);
            if (websiteAttribute == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.WebsiteAttributeName), packageInformationElement);
            if (versionAttribute == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.VersionAttributeName), packageInformationElement);
            if (canBeUninstalledAttribute == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.CanBeUninstalledAttributeName), packageInformationElement);
            if (systemLockingAttribute == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.SystemLockingAttributeName), packageInformationElement);

            if (string.IsNullOrEmpty(nameAttribute.Value)) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.NameAttributeName), nameAttribute);
            if (string.IsNullOrEmpty(groupNameAttribute.Value)) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.GroupNameAttributeName), groupNameAttribute);
            if (string.IsNullOrEmpty(authorAttribute.Value)) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.AuthorAttributeName), authorAttribute);
            if (string.IsNullOrEmpty(websiteAttribute.Value)) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.WebsiteAttributeName), websiteAttribute);
            if (string.IsNullOrEmpty(versionAttribute.Value)) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.VersionAttributeName), versionAttribute);
            if (string.IsNullOrEmpty(packageInformationElement.Value)) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidElementValue"), PackageSystemSettings.PackageInformationElementName), packageInformationElement);

            Guid id;
            if (idAttribute.TryGetGuidValue(out id) == false) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.IdAttributeName), idAttribute);


            string newVersion;

            if (VersionStringHelper.ValidateVersion(versionAttribute.Value, out newVersion)) versionAttribute.Value = newVersion;
            else return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.VersionAttributeName), versionAttribute);

            bool canBeUninstalled;
            if (canBeUninstalledAttribute.TryGetBoolValue(out canBeUninstalled) == false) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.CanBeUninstalledAttributeName), canBeUninstalledAttribute);

            SystemLockingType systemLockingType;
            if (systemLockingAttribute.TryDeserialize(out systemLockingType) == false) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.SystemLockingAttributeName), systemLockingAttribute);

            bool flushOnCompletion = false;
            if ((flushOnCompletionAttribute != null) && (flushOnCompletionAttribute.TryGetBoolValue(out flushOnCompletion) == false)) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.FlushOnCompletionAttributeName), flushOnCompletionAttribute);

            bool reloadConsoleOnCompletion = false;
            if ((reloadConsoleOnCompletionAttribute != null) && (reloadConsoleOnCompletionAttribute.TryGetBoolValue(out reloadConsoleOnCompletion) == false)) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.ReloadConsoleOnCompletionAttributeName), reloadConsoleOnCompletionAttribute);


            XElement packageRequirementsElement = installContent.Element(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageRequirementsElementName));
            if (packageRequirementsElement == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingElement"), PackageSystemSettings.PackageRequirementsElementName), installContent);

            XAttribute minimumCompositeVersionAttribute = packageRequirementsElement.Attribute(PackageSystemSettings.MinimumCompositeVersionAttributeName);
            XAttribute maximumCompositeVersionAttribute = packageRequirementsElement.Attribute(PackageSystemSettings.MaximumCompositeVersionAttributeName);

            if (minimumCompositeVersionAttribute == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.MinimumCompositeVersionAttributeName), packageRequirementsElement);
            if (maximumCompositeVersionAttribute == null) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingAttribute"), PackageSystemSettings.MaximumCompositeVersionAttributeName), packageRequirementsElement);

            if (string.IsNullOrEmpty(minimumCompositeVersionAttribute.Value)) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.MinimumCompositeVersionAttributeName), minimumCompositeVersionAttribute);
            if (string.IsNullOrEmpty(maximumCompositeVersionAttribute.Value)) return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.MaximumCompositeVersionAttributeName), maximumCompositeVersionAttribute);

            if (VersionStringHelper.ValidateVersion(minimumCompositeVersionAttribute.Value, out newVersion)) minimumCompositeVersionAttribute.Value = newVersion;
            else return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.VersionAttributeName), minimumCompositeVersionAttribute);

            if (VersionStringHelper.ValidateVersion(maximumCompositeVersionAttribute.Value, out newVersion)) maximumCompositeVersionAttribute.Value = newVersion;
            else return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.InvalidAttributeValue"), PackageSystemSettings.VersionAttributeName), maximumCompositeVersionAttribute);


            packageInformation = new PackageInformation
            {
                Id = id,
                Name = nameAttribute.Value,
                GroupName = groupNameAttribute.Value,
                Author = authorAttribute.Value,
                Website = websiteAttribute.Value,
                Version = versionAttribute.Value,
                CanBeUninstalled = canBeUninstalled,
                SystemLockingType = systemLockingType,
                Description = packageInformationElement.Value,
                FlushOnCompletion = flushOnCompletion,
                ReloadConsoleOnCompletion = reloadConsoleOnCompletion,
                MinCompositeVersionSupported = new Version(minimumCompositeVersionAttribute.Value),
                MaxCompositeVersionSupported = new Version(maximumCompositeVersionAttribute.Value)
            };

            return null;
        }
コード例 #15
0
ファイル: PackageManager.cs プロジェクト: DBailey635/C1-CMS
        /// <exclude />
        public static PackageManagerUninstallProcess Uninstall(Guid id)
        {
            try
            {
                string absolutePath = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.PackageDirectory), id.ToString());

                InstalledPackageInformation installedPackageInformation =
                    (from package in GetInstalledPackages()
                     where package.Id == id
                     select package).SingleOrDefault();

                if (installedPackageInformation == null) return new PackageManagerUninstallProcess(new List<PackageFragmentValidationResult> { new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingPackageDirectory"), absolutePath)) });

                Log.LogVerbose("PackageManager", "Uninstalling package: {0}, Id = {1}", installedPackageInformation.Name, installedPackageInformation.Id);

                if (installedPackageInformation.CanBeUninstalled == false) return new PackageManagerUninstallProcess(new List<PackageFragmentValidationResult> { new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, GetText("PackageManager.Uninstallable")) });

                string zipFilePath = Path.Combine(absolutePath, PackageSystemSettings.ZipFilename);
                if (C1File.Exists(zipFilePath) == false) return new PackageManagerUninstallProcess(new List<PackageFragmentValidationResult> { new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingZipFile"), zipFilePath)) });

                string uninstallFilePath = Path.Combine(absolutePath, PackageSystemSettings.UninstallFilename);
                if (C1File.Exists(uninstallFilePath) == false) return new PackageManagerUninstallProcess(new List<PackageFragmentValidationResult> { new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format(GetText("PackageManager.MissingUninstallFile"), uninstallFilePath)) });

                PackageInformation packageInformation = new PackageInformation
                {
                    Id = installedPackageInformation.Id,
                    Name = installedPackageInformation.Name,
                    GroupName = installedPackageInformation.GroupName,
                    Author = installedPackageInformation.Author,
                    Website = installedPackageInformation.Website,
                    Description = installedPackageInformation.Description,
                    Version = installedPackageInformation.Version,
                    CanBeUninstalled = installedPackageInformation.CanBeUninstalled,
                    SystemLockingType = installedPackageInformation.SystemLockingType,
                    FlushOnCompletion = installedPackageInformation.FlushOnCompletion,
                    ReloadConsoleOnCompletion = installedPackageInformation.ReloadConsoleOnCompletion,
                };


                PackageUninstaller packageUninstaller = new PackageUninstaller(zipFilePath, uninstallFilePath, absolutePath, TempDirectoryFacade.CreateTempDirectory(), installedPackageInformation.FlushOnCompletion, installedPackageInformation.ReloadConsoleOnCompletion, true, packageInformation);

                PackageManagerUninstallProcess packageManagerUninstallProcess = new PackageManagerUninstallProcess(packageUninstaller, absolutePath, installedPackageInformation.SystemLockingType);
                return packageManagerUninstallProcess;
            }
            catch (Exception ex)
            {
                return new PackageManagerUninstallProcess(new List<PackageFragmentValidationResult> { new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex) });
            }
        }
コード例 #16
0
 public IPackageUninstaller CreateUninstaller(string zipFilename, string uninstallFilename, string packageInstallationDirectory, string tempDirectory, bool flushOnCompletion, bool reloadConsoleOnCompletion, bool useTransaction, PackageInformation packageInformation)
 {
     return new PackageUninstaller(zipFilename, uninstallFilename, packageInstallationDirectory, tempDirectory, flushOnCompletion, reloadConsoleOnCompletion, useTransaction, packageInformation);
 }