private ResourceHandle GetIconForPackageItem(Guid packageId)
        {
            ResourceHandle           icon       = InstalledPackageItemIcon;
            PackageLicenseDefinition licenseDef = PackageLicenseHelper.GetLicenseDefinition(packageId);

            if (licenseDef != null && !licenseDef.Permanent)
            {
                icon = InstalledCommercialPackageItemIcon;
            }
            return(icon);
        }
 private SubscriptionLicense[] GetSubscriptionLicenses(IEnumerable <Subscription> availableInSubscriptions)
 {
     return((from subscription in availableInSubscriptions
             let license = PackageLicenseHelper.GetLicenseDefinition(subscription.Id)
                           where license != null
                           select new SubscriptionLicense
     {
         Name = subscription.Name,
         ExpirationDate = license.Expires,
         Expired = !license.Permanent && license.Expires < DateTime.Now
     }).ToArray());
 }
        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());
        }
        private void viewStateCodeActivity_Initialize_ExecuteCode(object sender, EventArgs e)
        {
            var castedToken = (PackageElementProviderInstalledPackageItemEntityToken)this.EntityToken;

            if (!this.BindingExist("InstalledPackageInformation"))
            {
                InstalledPackageInformation installedAddOnInformation =
                    (from info in PackageManager.GetInstalledPackages()
                     where info.Id == castedToken.PackageId
                     select info).Single();

                string name          = installedAddOnInformation.Name;
                string documentTitle = (name.Contains('.') && !name.EndsWith(".") ?
                                        string.Format("{0} ({1})", name.Substring(name.LastIndexOf('.') + 1), name.Substring(0, name.LastIndexOf('.'))) :
                                        name);

                this.Bindings.Add("DocumentTitle", documentTitle);
                this.Bindings.Add("InstalledPackageInformation", installedAddOnInformation);
                this.Bindings.Add("InstallDate", installedAddOnInformation.InstallDate.ToLocalTime().ToString());

                PackageLicenseDefinition licenseInfo = PackageLicenseHelper.GetLicenseDefinition(installedAddOnInformation.Id);
                bool isTrial = (licenseInfo != null && !licenseInfo.Permanent);
                this.Bindings.Add("IsTrial", isTrial);

                this.Bindings.Add("ShowPurchaseThisButton", isTrial && !string.IsNullOrWhiteSpace(licenseInfo.PurchaseUrl));

                PackageDescription packageDescription = null;
                try
                {
                    Guid packageId = new Guid(castedToken.Id);

                    var allPackages = PackageServerFacade.GetAllPackageDescriptions(InstallationInformationFacade.InstallationId,
                                                                                    UserSettings.CultureInfo);

                    packageDescription = allPackages.FirstOrDefault(p => p.Id == packageId);
                }
                catch
                {
                }

                if (packageDescription != null && !string.IsNullOrEmpty(packageDescription.ReadMoreUrl))
                {
                    this.Bindings.Add("ReadMoreUrl", packageDescription.ReadMoreUrl);
                }

                if (isTrial)
                {
                    this.Bindings.Add("TrialExpire", licenseInfo.Expires.ToLocalTime().ToString());
                    if (!string.IsNullOrWhiteSpace(licenseInfo.PurchaseUrl))
                    {
                        //string url = string.Format("{0}{1}installationId={2}", licenseInfo.PurchaseUrl, (licenseInfo.PurchaseUrl.Contains('?') ? "&" : "?"), Composite.Core.Configuration.InstallationInformationFacade.InstallationId);
                        string url = licenseInfo.PurchaseUrl;
                        this.Bindings.Add("TrialPurchaseUrl", url);
                    }
                }
            }

            if (castedToken.CanBeUninstalled)
            {
                this.SetCustomToolbarDefinition(new FormDefinitionFileMarkupProvider(@"\Administrative\PackageElementProviderViewInstalledPackageInformationToolbar.xml"));
            }
        }