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"));
            }
        }
        private void viewStateCodeActivity_Initialize_ExecuteCode(object sender, EventArgs e)
        {
            var  castedToken = (PackageElementProviderInstalledPackageItemEntityToken)this.EntityToken;
            Guid packageId   = castedToken.PackageId;

            if (castedToken.CanBeUninstalled)
            {
                this.SetCustomToolbarDefinition(new FormDefinitionFileMarkupProvider(CustomToolbarDefinitionPath));
            }

            if (this.BindingExist(BindingNames.InstalledPackageInformation))
            {
                return;
            }

            InstalledPackageInformation installedAddOnInformation =
                PackageManager.GetInstalledPackages().Single(info => info.Id == packageId);

            string   name             = installedAddOnInformation.Name;
            string   documentTitle    = GetDocumentTitle(name);
            DateTime installationDate = installedAddOnInformation.InstallDate.ToLocalTime();

            this.Bindings = new Dictionary <string, object>
            {
                { BindingNames.DocumentTitle, documentTitle },
                { BindingNames.InstalledPackageInformation, installedAddOnInformation },
                { BindingNames.InstallDate, installationDate.ToString() }
            };

            PackageDescription packageDescription = null;

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

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

            if (!string.IsNullOrEmpty(packageDescription?.ReadMoreUrl))
            {
                this.Bindings[BindingNames.ReadMoreUrl] = packageDescription.ReadMoreUrl;
            }

            var licenses      = GetRelatedLicenses(packageId, packageDescription);
            var actualLicense = licenses.OrderBy(l => l.HasExpired).ThenByDescending(l => l.IsSubscription).FirstOrDefault();

            if (actualLicense != null)
            {
                Bindings[BindingNames.LicenseExpirationDate] = actualLicense.ExpirationDate.ToLocalTime().ToString();
            }

            bool isTrial = actualLicense != null && actualLicense.IsTrial;

            this.Bindings[BindingNames.IsTrial] = isTrial;


            bool showPurchaseButton = false;

            if (isTrial && !string.IsNullOrWhiteSpace(actualLicense.PurchaseUrl))
            {
                string url = actualLicense.PurchaseUrl;
                this.Bindings[BindingNames.TrialPurchaseUrl] = url;

                showPurchaseButton = true;
            }
            this.Bindings[BindingNames.ShowPurchaseThisButton] = showPurchaseButton;

            bool isSubscription = actualLicense != null && actualLicense.IsSubscription;

            this.Bindings[BindingNames.IsSubscription] = isSubscription;
            if (isSubscription)
            {
                Bindings[BindingNames.SubscriptionName] = actualLicense.Name;
            }
        }
示例#3
0
 public static PackageDescription GetPackageDescription(Guid packageId)
 {
     return(PackageServerFacade.GetAllPackageDescriptions(Guid.Empty, CultureInfo.CreateSpecificCulture("en-us")).SingleOrDefault(p => p.Id == packageId));
 }