private void DisplayPackageInfo()
        {
            string errorResponse = string.Empty;

            // check that store is configured
            if (StoreService.OrganizationIsConfigured())
            {
                PackageService packageService = new PackageService();
                var            package        = packageService.GetPackage(packageId, out errorResponse);

                // check for errors
                ErrorCheck(errorResponse);

                lPackageName.Text        = package.Name;
                lPackageDescription.Text = package.Description;

                lPackageImage.Text = String.Format(@"<div class=""margin-b-md"" style=""
                                background: url('{0}') no-repeat center;
                                width: 100%;
                                height: 140px;"">
                                </div>", package.PackageIconBinaryFile.ImageUrl);

                if (package.IsFree)
                {
                    lCost.Text           = "<div class='pricelabel free'><h4>Free</h4></div>";
                    lInstallMessage.Text = _installFreeMessage;
                }
                else
                {
                    lCost.Text           = string.Format("<div class='pricelabel cost'><h4>${0}</h4></div>", package.Price);
                    lInstallMessage.Text = string.Format(_installPurchaseMessage, package.Price.ToString());
                }

                if (package.IsPurchased)
                {
                    // check if it's installed
                    // determine the state of the install button (install, update, buy or installed)
                    InstalledPackage installedPackage = InstalledPackageService.InstalledPackageVersion(package.Id);

                    if (installedPackage == null)
                    {
                        lCost.Visible        = false;
                        lInstallMessage.Text = _installPreviousPurchase;
                    }
                    else
                    {
                        lCost.Visible        = false;
                        lInstallMessage.Text = _updateMessage;
                        btnInstall.Text      = "Update";
                    }
                }
            }
            else
            {
                var queryParams = new Dictionary <string, string>();
                queryParams.Add("ReturnUrl", Request.RawUrl);

                NavigateToLinkedPage("LinkOrganizationPage", queryParams);
            }
        }
Example #2
0
        protected void rptPurchasedProducts_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            var package       = e.Item.DataItem as Package;
            var lbInstall     = e.Item.FindControl("lbInstall") as LinkButton;
            var lVersionNotes = e.Item.FindControl("lVersionNotes") as Literal;

            InstalledPackage installedPackage = InstalledPackageService.InstalledPackageVersion(package.Id);
            PackageVersion   latestVersion    = null;

            // if package is installed
            if (installedPackage != null)
            {
                // check that latest version is installed
                if (package.Versions.Count > 0)
                {
                    RockSemanticVersion rockVersion = RockSemanticVersion.Parse(Rock.VersionInfo.VersionInfo.GetRockSemanticVersionNumber());
                    latestVersion = package.Versions.Where(v => v.RequiredRockSemanticVersion <= rockVersion).OrderByDescending(v => v.Id).FirstOrDefault();
                }

                if (installedPackage.VersionId != latestVersion.Id)
                {
                    lbInstall.Text = "Update";

                    lVersionNotes.Text = String.Format("<p><strong>Installed Version</strong><br/>{0}</p><p><strong>Latest Version</strong><br/>{1}</p>", installedPackage.VersionLabel, latestVersion.VersionLabel);
                }
                else
                {
                    lbInstall.Text = "Installed";
                    lbInstall.Attributes.Add("disabled", "disabled");
                    lbInstall.CssClass = "btn btn-default margin-b-md";

                    lVersionNotes.Text = String.Format("<p><strong>Installed Version</strong><br/>{0}</p>", installedPackage.VersionLabel);
                }
            }
        }
        private void ShowPackage()
        {
            string errorResponse = string.Empty;

            // get package id
            int packageId = -1;

            if (!string.IsNullOrWhiteSpace(PageParameter("PackageId")))
            {
                packageId = Convert.ToInt32(PageParameter("PackageId"));
            }

            PackageService packageService = new PackageService();
            var            package        = packageService.GetPackage(packageId, out errorResponse);

            string storeKey = StoreService.GetOrganizationKey();

            // check for errors
            ErrorCheck(errorResponse);

            lPackageName.Text         = package.Name;
            lPackageDescription.Text  = package.Description;
            lVendorName.Text          = package.Vendor.Name;
            imgPackageImage.ImageUrl  = package.PackageIconBinaryFile.ImageUrl;
            lbPackageLink.PostBackUrl = package.SupportUrl;
            lRatingSummary.Text       = string.Format("<div class='rating rating-{0} pull-left margin-r-sm'><small></small></div>", package.Rating.ToString().Replace(".", ""));

            lAuthorInfo.Text = string.Format("<a href='{0}'>{1}</a>", package.Vendor.Url, package.Vendor.Name);

            if (package.IsFree)
            {
                lCost.Text = "<div class='pricelabel free'><h4>Free</h4></div>";
            }
            else
            {
                lCost.Text = string.Format("<div class='pricelabel cost'><h4>${0}</h4></div>", package.Price);
            }

            // get latest version
            PackageVersion latestVersion = null;

            if (package.Versions.Count > 0)
            {
                RockSemanticVersion rockVersion = RockSemanticVersion.Parse(VersionInfo.GetRockSemanticVersionNumber());
                latestVersion = package.Versions.Where(v => v.RequiredRockSemanticVersion <= rockVersion).OrderByDescending(v => v.Id).FirstOrDefault();
            }

            // determine the state of the install button (install, update, buy or installed)
            InstalledPackage installedPackage = InstalledPackageService.InstalledPackageVersion(package.Id);

            if (installedPackage == null)
            {
                // it's not installed
                // todo add logic that it's not installed but has been purchased
                if (package.IsFree)
                {
                    // the package is free
                    lbInstall.Text = "Install";
                }
                else
                {
                    if (package.IsPurchased)
                    {
                        lbInstall.Text     = "Install";
                        lInstallNotes.Text = string.Format("<small>Purchased {0}</small>", package.PurchasedDate.ToShortDateString());

                        // set rating link button
                        lbRate.Visible     = true;
                        lbRate.PostBackUrl = string.Format("http://www.rockrms.com/Store/Rate?OrganizationKey={0}&PackageId={1}", storeKey, packageId.ToString());
                    }
                    else
                    {
                        lbInstall.Text = "Buy";
                    }
                }
            }
            else
            {
                if (installedPackage.VersionId == latestVersion.Id)
                {
                    // have the latest version installed
                    lbInstall.Text     = "Installed";
                    lbInstall.Enabled  = false;
                    lbInstall.CssClass = "btn btn-default btn-install";
                    lbInstall.Attributes.Add("disabled", "disabled");

                    // set rating link button
                    lbRate.Visible     = true;
                    lbRate.PostBackUrl = string.Format("http://www.rockrms.com/Store/Rate?OrganizationKey={0}&PackageId={1}&InstalledVersionId={2}", storeKey, packageId.ToString(), installedPackage.VersionId.ToString());
                }
                else
                {
                    // have a previous version installed
                    lbInstall.Text     = "Update";
                    lInstallNotes.Text = string.Format("<small>You have {0} installed</small>", installedPackage.VersionLabel);

                    // set rating link button
                    lbRate.Visible     = true;
                    lbRate.PostBackUrl = string.Format("http://www.rockrms.com/Store/Rate?OrganizationKey={0}&PackageId={1}&InstalledVersionId={2}", storeKey, packageId.ToString(), installedPackage.VersionId.ToString());
                }
            }

            if (latestVersion != null)
            {
                rptScreenshots.DataSource = latestVersion.Screenshots;
                rptScreenshots.DataBind();

                lLatestVersionLabel.Text       = latestVersion.VersionLabel;
                lLatestVersionDescription.Text = latestVersion.Description;

                // alert the user if a newer version exists but requires a rock update
                if (package.Versions.Where(v => v.Id > latestVersion.Id).Count() > 0)
                {
                    var lastVersion = package.Versions.OrderByDescending(v => v.RequiredRockSemanticVersion).FirstOrDefault();
                    lVersionWarning.Text = string.Format("<div class='alert alert-info'>A newer version of this item is available but requires Rock v{0}.{1}.</div>",
                                                         lastVersion.RequiredRockSemanticVersion.Minor.ToString(),
                                                         lastVersion.RequiredRockSemanticVersion.Patch.ToString());
                }

                lLastUpdate.Text          = latestVersion.AddedDate.ToShortDateString();
                lRequiredRockVersion.Text = string.Format("v{0}.{1}",
                                                          latestVersion.RequiredRockSemanticVersion.Minor.ToString(),
                                                          latestVersion.RequiredRockSemanticVersion.Patch.ToString());
                lDocumenationLink.Text = string.Format("<a href='{0}'>Support Link</a>", latestVersion.DocumentationUrl);

                // fill in previous version info
                rptAdditionalVersions.DataSource = package.Versions.Where(v => v.Id < latestVersion.Id);
                rptAdditionalVersions.DataBind();

                // get the details for the latest version
                PackageVersion latestVersionDetails = new PackageVersionService().GetPackageVersion(latestVersion.Id, out errorResponse);

                // check for errors
                ErrorCheck(errorResponse);
            }
            else
            {
                // hide install button
                lbInstall.Visible = false;

                // display info on what Rock version you need to be on to run this package
                if (package.Versions.Count > 0)
                {
                    var firstVersion = package.Versions.OrderBy(v => v.RequiredRockSemanticVersion).FirstOrDefault();
                    var lastVersion  = package.Versions.OrderByDescending(v => v.RequiredRockSemanticVersion).FirstOrDefault();

                    if (firstVersion == lastVersion)
                    {
                        lVersionWarning.Text = string.Format("<div class='alert alert-warning'>This item requires Rock version v{0}.{1}.</div>",
                                                             lastVersion.RequiredRockSemanticVersion.Minor.ToString(),
                                                             lastVersion.RequiredRockSemanticVersion.Patch.ToString());
                    }
                    else
                    {
                        lVersionWarning.Text = string.Format("<div class='alert alert-warning'>This item requires at least Rock version v{0}.{1} but the latest version requires v{2}.{3}.</div>",
                                                             firstVersion.RequiredRockSemanticVersion.Minor.ToString(),
                                                             firstVersion.RequiredRockSemanticVersion.Patch.ToString(),
                                                             lastVersion.RequiredRockSemanticVersion.Minor.ToString(),
                                                             lastVersion.RequiredRockSemanticVersion.Patch.ToString());
                    }
                }
            }
        }