Example #1
0
        /// <exclude />
        public static string GetEulaText(PackageDescription packageDescription)
        {
            string packageSource = PackageSystemServices.GetPackageSourceNameByPackageId(packageDescription.Id, InstallationInformationFacade.InstallationId, UserSettings.CultureInfo);

            string text = PackageServerFacade.GetEulaText(packageSource, packageDescription.EulaId, UserSettings.CultureInfo);

            return(text);
        }
        /// <exclude />
        public static string GetEulaText(PackageDescription packageDescription)
        {
            string packageSource = PackageSystemServices.GetPackageSourceNameByPackageId(packageDescription.Id, InstallationInformationFacade.InstallationId, UserSettings.CultureInfo);

            string text = PackageServerFacade.GetEulaText(packageSource, packageDescription.EulaId, UserSettings.CultureInfo);

            return text;
        }
Example #3
0
        /// <exclude />
        public static string GetPackageSourceNameByPackageId(Guid id, Guid installationId, CultureInfo userCulture)
        {
            List <IPackageServerSource> packageServerSources = DataFacade.GetData <IPackageServerSource>().ToList();

            foreach (IPackageServerSource packageServerSource in packageServerSources)
            {
                PackageDescription foundPackageDescription =
                    (from package in PackageServerFacade.GetPackageDescriptions(packageServerSource.Url, installationId, userCulture)
                     where package.Id == id
                     select package).FirstOrDefault();

                if (foundPackageDescription != null)
                {
                    return(packageServerSource.Url);
                }
            }

            throw new InvalidOperationException("Source not found");
        }
        public Stream GetInstallFileStream(string packageFileDownloadUrl)
        {
            Initialize();

            PackageDescription packageDescription = null;
            ExtraInfo          extraInfo          = null;

            foreach (List <KeyValuePair <PackageDescription, ExtraInfo> > packageDescriptions in _packageDescriptions.Values)
            {
                KeyValuePair <PackageDescription, ExtraInfo>?q =
                    (from desc in packageDescriptions
                     where desc.Key.PackageFileDownloadUrl == packageFileDownloadUrl
                     select desc).FirstOrDefault();

                if (q != null)
                {
                    packageDescription = q.Value.Key;
                    extraInfo          = q.Value.Value;
                    break;
                }
            }

            XElement rootElement =
                new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageInstallerElementName),
                             new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageRequirementsElementName),
                                          new XAttribute(PackageSystemSettings.MinimumCompositeVersionAttributeName, packageDescription.MinCompositeVersionSupported),
                                          new XAttribute(PackageSystemSettings.MaximumCompositeVersionAttributeName, packageDescription.MaxCompositeVersionSupported)
                                          ),
                             new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageInformationElementName),
                                          new XAttribute(PackageSystemSettings.IdAttributeName, packageDescription.Id),
                                          new XAttribute(PackageSystemSettings.NameAttributeName, packageDescription.Name),
                                          new XAttribute(PackageSystemSettings.GroupNameAttributeName, packageDescription.GroupName),
                                          new XAttribute(PackageSystemSettings.AuthorAttributeName, packageDescription.Vendor),
                                          new XAttribute(PackageSystemSettings.WebsiteAttributeName, packageDescription.ReadMoreUrl),
                                          new XAttribute(PackageSystemSettings.VersionAttributeName, packageDescription.PackageVersion),
                                          new XAttribute(PackageSystemSettings.CanBeUninstalledAttributeName, extraInfo.CanBeUninstalled),
                                          new XAttribute(PackageSystemSettings.SystemLockingAttributeName, extraInfo.SystemLockingType.Serialize()),
                                          new XAttribute(PackageSystemSettings.FlushOnCompletionAttributeName, extraInfo.FlushOnCompletion),
                                          new XAttribute(PackageSystemSettings.ReloadConsoleOnCompletionAttributeName, extraInfo.ReloadConsoleOnCompletion),
                                          packageDescription.Description
                                          ),
                             new XElement(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageFragmentInstallersElementName))
                             );

            XDocument doc     = new XDocument(rootElement);
            string    content = doc.GetDocumentAsString();

            UTF8Encoding encoding = new UTF8Encoding();

            byte[] buffer = encoding.GetBytes(content);

            var outputStream = new MemoryStream();

            var zipArchive = new ZipArchive(outputStream);

            var zipEntry = zipArchive.CreateEntry("install.xml");

            using (var stream = zipEntry.Open())
            {
                stream.Write(buffer, 0, buffer.Length);
            }

            zipEntry.LastWriteTime = DateTimeOffset.Now;

            outputStream.Seek(0, SeekOrigin.Begin);

            return(outputStream);
        }
        private void LoadXml()
        {
            _packageDescriptions = new Dictionary <string, List <KeyValuePair <PackageDescription, ExtraInfo> > >();
            _eulaTexts           = new Dictionary <string, Dictionary <Guid, string> >();

            XDocument doc = XDocumentUtils.Load(_configFilePath);

            foreach (XElement element in doc.Root.Elements("Source"))
            {
                XAttribute urlAttribute = element.Attribute("url");

                List <KeyValuePair <PackageDescription, ExtraInfo> > packageDescriptions = new List <KeyValuePair <PackageDescription, ExtraInfo> >();
                foreach (XElement packageElement in element.Elements("PackageDescription"))
                {
                    PackageDescription packageDescription = new PackageDescription();

                    packageDescription.PackageVersion         = packageElement.Attribute("packageVersion").Value;
                    packageDescription.PackageFileDownloadUrl = packageElement.Attribute("packageFileDownloadUrl").Value;
                    packageDescription.Description            = packageElement.Attribute("description").Value;
                    packageDescription.EulaId    = (Guid)packageElement.Attribute("eulaId");
                    packageDescription.GroupName = packageElement.Attribute("groupName").Value;
                    packageDescription.Id        = (Guid)packageElement.Attribute("id");
                    packageDescription.InstallationRequireLicenseFileUpdate = (bool)packageElement.Attribute("installationRequireLicenseFileUpdate");
                    packageDescription.IsFree        = (bool)packageElement.Attribute("isFree");
                    packageDescription.IsTrial       = (bool)packageElement.Attribute("isTrial");
                    packageDescription.LicenseRuleId = (Guid)packageElement.Attribute("licenseRuleId");
                    packageDescription.MaxCompositeVersionSupported = packageElement.Attribute("maxCompositeVersionSupported").Value;
                    packageDescription.MinCompositeVersionSupported = packageElement.Attribute("minCompositeVersionSupported").Value;
                    packageDescription.Name                      = packageElement.Attribute("name").Value;
                    packageDescription.PriceAmmount              = (decimal)packageElement.Attribute("priceAmmount");
                    packageDescription.PriceCurrency             = packageElement.Attribute("priceCurrency").Value;
                    packageDescription.ReadMoreUrl               = packageElement.Attribute("readMoreUrl").Value;
                    packageDescription.TechicalDetails           = packageElement.Attribute("techicalDetails").Value;
                    packageDescription.TrialPeriodDays           = (int)packageElement.Attribute("trialPeriodDays");
                    packageDescription.UpgradeAgreementMandatory = (bool)packageElement.Attribute("upgradeAgreementMandatory");
                    packageDescription.Vendor                    = packageElement.Attribute("vendor").Value;
                    ExtraInfo extraInfo = new ExtraInfo();

                    if (packageElement.Attribute("canBeUninstalled") != null)
                    {
                        extraInfo.CanBeUninstalled = (bool)packageElement.Attribute("canBeUninstalled");
                    }
                    if (packageElement.Attribute("flushOnCompletion") != null)
                    {
                        extraInfo.FlushOnCompletion = (bool)packageElement.Attribute("flushOnCompletion");
                    }
                    if (packageElement.Attribute("reloadConsoleOnCompletion") != null)
                    {
                        extraInfo.ReloadConsoleOnCompletion = (bool)packageElement.Attribute("reloadConsoleOnCompletion");
                    }

                    if (packageElement.Attribute("systemLocking") != null)
                    {
                        SystemLockingType systemLockingType;
                        packageElement.Attribute("systemLocking").TryDeserialize(out systemLockingType);
                        extraInfo.SystemLockingType = systemLockingType;
                    }

                    packageDescriptions.Add(new KeyValuePair <PackageDescription, ExtraInfo>(packageDescription, extraInfo));
                }

                _packageDescriptions.Add(element.Attribute("url").Value.ToLowerInvariant(), packageDescriptions);


                Dictionary <Guid, string> eulaTexts = new Dictionary <Guid, string>();
                foreach (XElement eulaTextElement in element.Elements("EulaText"))
                {
                    eulaTexts.Add(
                        (Guid)eulaTextElement.Attribute("id"),
                        eulaTextElement.Value
                        );
                }
                _eulaTexts.Add(element.Attribute("url").Value.ToLowerInvariant(), eulaTexts);
            }
        }
        private void LoadXml()
        {
            _packageDescriptions = new Dictionary<string, List<KeyValuePair<PackageDescription, ExtraInfo>>>();
            _eulaTexts = new Dictionary<string, Dictionary<Guid, string>>();

            XDocument doc = XDocumentUtils.Load(_configFilePath);

            foreach (XElement element in doc.Root.Elements("Source"))
            {
                XAttribute urlAttribute = element.Attribute("url");

                List<KeyValuePair<PackageDescription, ExtraInfo>> packageDescriptions = new List<KeyValuePair<PackageDescription, ExtraInfo>>();
                foreach (XElement packageElement in element.Elements("PackageDescription"))
                {
                    PackageDescription packageDescription = new PackageDescription();

                    packageDescription.PackageVersion = packageElement.Attribute("packageVersion").Value;
                    packageDescription.PackageFileDownloadUrl = packageElement.Attribute("packageFileDownloadUrl").Value;
                    packageDescription.Description = packageElement.Attribute("description").Value;
                    packageDescription.EulaId = (Guid)packageElement.Attribute("eulaId");
                    packageDescription.GroupName = packageElement.Attribute("groupName").Value;
                    packageDescription.Id = (Guid)packageElement.Attribute("id");
                    packageDescription.InstallationRequireLicenseFileUpdate = (bool)packageElement.Attribute("installationRequireLicenseFileUpdate");
                    packageDescription.IsFree = (bool)packageElement.Attribute("isFree");
                    packageDescription.IsTrial = (bool)packageElement.Attribute("isTrial");
                    packageDescription.LicenseRuleId = (Guid)packageElement.Attribute("licenseRuleId");
                    packageDescription.MaxCompositeVersionSupported = packageElement.Attribute("maxCompositeVersionSupported").Value;
                    packageDescription.MinCompositeVersionSupported = packageElement.Attribute("minCompositeVersionSupported").Value;
                    packageDescription.Name = packageElement.Attribute("name").Value;
                    packageDescription.PriceAmmount = (decimal)packageElement.Attribute("priceAmmount");
                    packageDescription.PriceCurrency = packageElement.Attribute("priceCurrency").Value;
                    packageDescription.ReadMoreUrl = packageElement.Attribute("readMoreUrl").Value;
                    packageDescription.TechicalDetails = packageElement.Attribute("techicalDetails").Value;
                    packageDescription.TrialPeriodDays = (int)packageElement.Attribute("trialPeriodDays");
                    packageDescription.UpgradeAgreementMandatory = (bool)packageElement.Attribute("upgradeAgreementMandatory");
                    packageDescription.Vendor = packageElement.Attribute("vendor").Value;
                    ExtraInfo extraInfo = new ExtraInfo();

                    if (packageElement.Attribute("canBeUninstalled") != null) extraInfo.CanBeUninstalled = (bool)packageElement.Attribute("canBeUninstalled");
                    if (packageElement.Attribute("flushOnCompletion") != null) extraInfo.FlushOnCompletion = (bool)packageElement.Attribute("flushOnCompletion");
                    if (packageElement.Attribute("reloadConsoleOnCompletion") != null) extraInfo.ReloadConsoleOnCompletion = (bool)packageElement.Attribute("reloadConsoleOnCompletion");

                    if (packageElement.Attribute("systemLocking") != null)
                    {
                        SystemLockingType systemLockingType;
                        packageElement.Attribute("systemLocking").TryDeserialize(out systemLockingType);
                        extraInfo.SystemLockingType = systemLockingType;
                    }

                    packageDescriptions.Add(new KeyValuePair<PackageDescription, ExtraInfo>(packageDescription, extraInfo));
                }

                _packageDescriptions.Add(element.Attribute("url").Value.ToLowerInvariant(), packageDescriptions);

                Dictionary<Guid, string> eulaTexts = new Dictionary<Guid, string>();
                foreach (XElement eulaTextElement in element.Elements("EulaText"))
                {
                    eulaTexts.Add(
                        (Guid)eulaTextElement.Attribute("id"),
                        eulaTextElement.Value
                        );
                }
                _eulaTexts.Add(element.Attribute("url").Value.ToLowerInvariant(), eulaTexts);
            }
        }
        private string GetDocumentTitle(PackageDescription packageDescription)
        {
            // Valid package names:
            //  "Composite.Community.Versioning"
            //  "Orckestra CMS 3.0"
            string name = packageDescription.Name.Trim();

            string documentTitle = name;

            if (name.Contains(".") && !name.EndsWith("."))
            {
                string packageName = name.Substring(name.LastIndexOf('.') + 1);
                string packageNamespace = name.Substring(0, name.LastIndexOf('.'));

                int temp;
                if (!int.TryParse(packageName, out temp))
                {
                    documentTitle = $"{packageName} ({packageNamespace})";
                }
            }

            return documentTitle;
        }
        private LicenseInformation[] GetRelatedLicenses(Guid packageId, PackageDescription packageDescription)
        {
            var result = new List<LicenseInformation>();

            var licenseInfo = PackageLicenseHelper.GetLicenseDefinition(packageId);
            if (licenseInfo != null)
            {
                result.Add(new LicenseInformation
                {
                    Name = licenseInfo.ProductName,
                    IsSubscription = false,
                    ExpirationDate = licenseInfo.Expires,
                    HasExpired = !licenseInfo.Permanent && licenseInfo.Expires < DateTime.Now,
                    IsTrial = !licenseInfo.Permanent,
                    PurchaseUrl = licenseInfo.PurchaseUrl
                });
            }

            if (packageDescription != null)
            {
                foreach (var subscription in packageDescription.AvailableInSubscriptions)
                {
                    var subscriptionLicense = PackageLicenseHelper.GetLicenseDefinition(subscription.Id);
                    if (subscriptionLicense == null) continue;
                    
                    result.Add(new LicenseInformation
                    {
                        Name = subscription.Name,
                        IsSubscription = true,
                        ExpirationDate = subscriptionLicense.Expires,
                        HasExpired = !subscriptionLicense.Permanent && subscriptionLicense.Expires < DateTime.Now,
                        IsTrial = false,
                        PurchaseUrl = subscription.DetailsUrl,
                    });
                }
            }

            return result.ToArray();
        }