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 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); } }
private int GetCurrentlyInstalledPackageVersion(string packageName) { var installedPackages = InstalledPackageService.GetInstalledPackages().OrderBy(p => p.PackageName).OrderByDescending(p => p.InstallDateTime); foreach (var installedPackage in installedPackages) { if (installedPackage.PackageName == packageName) { return(installedPackage.VersionId); } } return(-1); }
/// <summary> /// Operations to be performed during the upgrade process. /// </summary> public override void Up() { Sql( @"DELETE FROM [PluginMigration] WHERE [PluginAssemblyName] = 'org.sparkdevnetwork.PrayerRequestWorkflowAction'"); var installedPackages = InstalledPackageService.GetInstalledPackages(); if (installedPackages != null && installedPackages.Any(a => a.PackageId == 131)) { installedPackages.RemoveAll(a => a.PackageId == 131); var packageFile = HostingEnvironment.MapPath("~/App_Data/InstalledStorePackages.json"); var packagesAsJson = installedPackages.ToJson(); System.IO.File.WriteAllText(packageFile, packagesAsJson); } }
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()); } } } }
private void ProcessInstall(PurchaseResponse purchaseResponse) { if (purchaseResponse.PackageInstallSteps != null) { foreach (var installStep in purchaseResponse.PackageInstallSteps) { string appRoot = Server.MapPath("~/"); string rockShopWorkingDir = appRoot + "App_Data/RockShop"; string packageDirectory = string.Format("{0}/{1} - {2}", rockShopWorkingDir, purchaseResponse.PackageId, purchaseResponse.PackageName); string sourceFile = installStep.InstallPackageUrl; string destinationFile = string.Format("{0}/{1} - {2}.plugin", packageDirectory, installStep.VersionId, installStep.VersionLabel); // check that the RockShop directory exists if (!Directory.Exists(rockShopWorkingDir)) { Directory.CreateDirectory(rockShopWorkingDir); } // create package directory if (!Directory.Exists(packageDirectory)) { Directory.CreateDirectory(packageDirectory); } // download file try { WebClient wc = new WebClient(); wc.DownloadFile(sourceFile, destinationFile); } catch (Exception ex) { CleanUpPackage(destinationFile); lMessages.Text = string.Format("<div class='alert alert-warning margin-t-md'><strong>Error Downloading Package</strong> An error occurred while downloading package from the store. Please try again later. <br><em>Error: {0}</em></div>", ex.Message); return; } // process zip folder try { using (ZipArchive packageZip = ZipFile.OpenRead(destinationFile)) { // unzip content folder and process xdts foreach (ZipArchiveEntry entry in packageZip.Entries.Where(e => e.FullName.StartsWith("content/"))) { if (entry.FullName.EndsWith(_xdtExtension, StringComparison.OrdinalIgnoreCase)) { // process xdt string filename = entry.FullName.Replace("content/", ""); string transformTargetFile = appRoot + filename.Substring(0, filename.LastIndexOf(_xdtExtension)); // process transform using (XmlTransformableDocument document = new XmlTransformableDocument()) { document.PreserveWhitespace = true; document.Load(transformTargetFile); using (XmlTransformation transform = new XmlTransformation(entry.Open(), null)) { if (transform.Apply(document)) { document.Save(transformTargetFile); } } } } else { // process all content files string fullpath = Path.Combine(appRoot, entry.FullName.Replace("content/", "")); string directory = Path.GetDirectoryName(fullpath).Replace("content/", ""); // if entry is a directory ignore it if (entry.Length != 0) { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } entry.ExtractToFile(fullpath, true); } } } // process install.sql try { var sqlInstallEntry = packageZip.Entries.Where(e => e.FullName == "install/run.sql").FirstOrDefault(); if (sqlInstallEntry != null) { string sqlScript = System.Text.Encoding.Default.GetString(sqlInstallEntry.Open().ReadBytesToEnd()); if (!string.IsNullOrWhiteSpace(sqlScript)) { using (var context = new RockContext()) { context.Database.ExecuteSqlCommand(sqlScript); } } } } catch (Exception ex) { lMessages.Text = string.Format("<div class='alert alert-warning margin-t-md'><strong>Error Updating Database</strong> An error occurred while updating the database. <br><em>Error: {0}</em></div>", ex.Message); return; } // process deletefile.lst try { var deleteListEntry = packageZip.Entries.Where(e => e.FullName == "install/deletefile.lst").FirstOrDefault(); if (deleteListEntry != null) { string deleteList = System.Text.Encoding.Default.GetString(deleteListEntry.Open().ReadBytesToEnd()); string[] itemsToDelete = deleteList.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); foreach (string deleteItem in itemsToDelete) { if (!string.IsNullOrWhiteSpace(deleteItem)) { string deleteItemFullPath = appRoot + deleteItem; if (Directory.Exists(deleteItemFullPath)) { Directory.Delete(deleteItemFullPath, true); } if (File.Exists(deleteItemFullPath)) { File.Delete(deleteItemFullPath); } } } } } catch (Exception ex) { lMessages.Text = string.Format("<div class='alert alert-warning margin-t-md'><strong>Error Modifing Files</strong> An error occurred while modifing files. <br><em>Error: {0}</em></div>", ex.Message); return; } } } catch (Exception ex) { lMessages.Text = string.Format("<div class='alert alert-warning margin-t-md'><strong>Error Extracting Package</strong> An error occurred while extracting the contents of the package. <br><em>Error: {0}</em></div>", ex.Message); return; } // update package install json file InstalledPackageService.SaveInstall(purchaseResponse.PackageId, purchaseResponse.PackageName, installStep.VersionId, installStep.VersionLabel, purchaseResponse.VendorId, purchaseResponse.VendorName, purchaseResponse.InstalledBy); // Clear all cached items Rock.Web.Cache.RockMemoryCache.Clear(); // Clear the static object that contains all auth rules (so that it will be refreshed) Rock.Security.Authorization.Flush(); // show result message lMessages.Text = string.Format("<div class='alert alert-success margin-t-md'><strong>Package Installed</strong><p>{0}</p>", installStep.PostInstallInstructions); } } else { lMessages.Text = "<div class='alert alert-warning margin-t-md'><strong>Error</strong> Install package was not valid. Please try again later."; } }
/// <summary> /// SK: Add Campaign Connection /// </summary> private void AddCampaignConnection() { RockMigrationHelper.AddPage(true, "9CC19684-7AD2-4D4E-A7C4-10DAE56E7FA6", "D65F783D-87A9-4CC9-8110-E83466A0EADB", "Connection Campaigns", "", "B252FAA6-0E9D-41CD-A00D-E7159E881714", ""); // Site:Rock RMS RockMigrationHelper.AddPage(true, "B252FAA6-0E9D-41CD-A00D-E7159E881714", "D65F783D-87A9-4CC9-8110-E83466A0EADB", "Campaign Configuration", "", "A22133B5-B5C6-455A-A300-690F7926356D", ""); // Site:Rock RMS RockMigrationHelper.AddPageRoute("B252FAA6-0E9D-41CD-A00D-E7159E881714", "CampaignConfiguration", "57CEB84D-5EC7-4AE2-AA4C-CFE045F78456"); // for Page:Connection Campaigns RockMigrationHelper.UpdateBlockType("Add Campaign Requests", "Adds Campaign Connection Requests", "~/Blocks/Connection/AddCampaignRequests.ascx", "Connection Campaign", "11630BB9-E685-4582-91F8-620448AA34B0"); RockMigrationHelper.UpdateBlockType("Campaign Configuration", "Block used for Campaign Connection configuration which is also used by job.", "~/Blocks/Connection/CampaignConfiguration.ascx", "Connection Campaign", "9E6C4174-5F2B-4A78-9781-55D7DD209B6C"); RockMigrationHelper.UpdateBlockType("Campaign List", "Block for viewing list of campaign connection configurations.", "~/Blocks/Connection/CampaignList.ascx", "Connection Campaign", "6BA9D764-E30F-48D1-AB20-8991371B6316"); // Add Block to Page: Connections Site: Rock RMS RockMigrationHelper.AddBlock(true, "530860ED-BC73-4A43-8E7C-69533EF2B6AD".AsGuid(), null, "C2D29296-6A87-47A9-A753-EE4E9159C4C4".AsGuid(), "11630BB9-E685-4582-91F8-620448AA34B0".AsGuid(), "Add Campaign Requests", "Main", @"", @"", 0, "BF39BE49-B4F6-4A5B-BDA2-EB343FC80CCA"); // Add Block to Page: Connection Campaigns Site: Rock RMS RockMigrationHelper.AddBlock(true, "B252FAA6-0E9D-41CD-A00D-E7159E881714".AsGuid(), null, "C2D29296-6A87-47A9-A753-EE4E9159C4C4".AsGuid(), "6BA9D764-E30F-48D1-AB20-8991371B6316".AsGuid(), "Campaign List", "Main", @"", @"", 0, "3A62AD36-5031-4C62-BCC1-7800AE43F78B"); // Add Block to Page: Campaign Configuration Site: Rock RMS RockMigrationHelper.AddBlock(true, "A22133B5-B5C6-455A-A300-690F7926356D".AsGuid(), null, "C2D29296-6A87-47A9-A753-EE4E9159C4C4".AsGuid(), "9E6C4174-5F2B-4A78-9781-55D7DD209B6C".AsGuid(), "Campaign Configuration", "Main", @"", @"", 0, "5DC2943E-EFBD-4F25-B1D7-738CB86AB628"); // update block order for pages with new blocks if the page,zone has multiple blocks Sql(@"UPDATE [Block] SET [Order] = 0 WHERE [Guid] = 'BF39BE49-B4F6-4A5B-BDA2-EB343FC80CCA'"); // Page: Connections, Zone: Main, Block: Add Campaign Requests Sql(@"UPDATE [Block] SET [Order] = 1 WHERE [Guid] = '80710A2C-9B90-40AE-B887-B885AAA43538'"); // Page: Connections, Zone: Main, Block: My Connection Opportunities // Attrib for BlockType: Campaign List:Detail Page RockMigrationHelper.UpdateBlockTypeAttribute("6BA9D764-E30F-48D1-AB20-8991371B6316", "BD53F9C9-EBA9-4D3F-82EA-DE5DD34A8108", "Detail Page", "DetailPage", "", @"", 0, @"", "0932CBC5-11E8-40AC-8707-F0472D1BCD31"); // Attrib Value for Block:Campaign List, Attribute:Detail Page Page: Connection Campaigns, Site: Rock RMS RockMigrationHelper.AddBlockAttributeValue("3A62AD36-5031-4C62-BCC1-7800AE43F78B", "0932CBC5-11E8-40AC-8707-F0472D1BCD31", @"a22133b5-b5c6-455a-a300-690f7926356d"); // Attrib Value for Block:Campaign List, Attribute:core.CustomGridEnableStickyHeaders Page: Connection Campaigns, Site: Rock RMS RockMigrationHelper.AddBlockAttributeValue("3A62AD36-5031-4C62-BCC1-7800AE43F78B", "393DAC13-0626-47B1-ADB7-C7D3B481EFB1", @"False"); // Add Campaign Manager Job Sql(@" IF NOT EXISTS ( SELECT [Id] FROM [ServiceJob] WHERE [Guid] = '27D1BE06-1BC0-468D-8DE9-748BAFFF2F1A') BEGIN INSERT INTO [dbo].[ServiceJob] ( [IsSystem] ,[IsActive] ,[Name] ,[Description] ,[Class] ,[CronExpression] ,[NotificationStatus] ,[Guid] ) VALUES ( 0 ,1 ,'Campaign Manager' ,'Handles processing all configured campaigns, creating new connection requests and assigning them to connectors as needed.' ,'Rock.Jobs.CampaignManager' ,'0 0 7 1/1 * ? *' ,1 ,'27D1BE06-1BC0-468D-8DE9-748BAFFF2F1A' ) END"); Sql(@"DELETE FROM [PluginMigration] WHERE [PluginAssemblyName] = 'org.sparkdevnetwork.ConnectionCampaign'"); var installedPackages = InstalledPackageService.GetInstalledPackages(); if (installedPackages != null && installedPackages.Any(a => a.PackageId == 129)) { installedPackages.RemoveAll(a => a.PackageId == 129); string packageFile = HostingEnvironment.MapPath("~/App_Data/InstalledStorePackages.json"); string packagesAsJson = installedPackages.ToJson(); System.IO.File.WriteAllText(packageFile, packagesAsJson); } }
/// <summary> /// Sends to spark. /// </summary> /// <returns></returns> public static List <Notification> SendToSpark(RockContext rockContext) { var notifications = new List <Notification>(); var installedPackages = InstalledPackageService.GetInstalledPackages(); var sparkLinkRequest = new SparkLinkRequestV2(); sparkLinkRequest.RockInstanceId = Rock.Web.SystemSettings.GetRockInstanceId(); sparkLinkRequest.VersionIds = installedPackages.Select(i => i.VersionId).ToList(); sparkLinkRequest.RockVersion = VersionInfo.VersionInfo.GetRockSemanticVersionNumber(); var globalAttributes = GlobalAttributesCache.Get(); sparkLinkRequest.OrganizationName = globalAttributes.GetValue("OrganizationName"); sparkLinkRequest.PublicUrl = globalAttributes.GetValue("PublicApplicationRoot"); sparkLinkRequest.NumberOfActiveRecords = new PersonService(rockContext).Queryable(includeDeceased: false, includeBusinesses: false).Count(); // Fetch the organization address var organizationAddressLocationGuid = globalAttributes.GetValue("OrganizationAddress").AsGuid(); if (!organizationAddressLocationGuid.Equals(Guid.Empty)) { var location = new LocationService(rockContext).Get(organizationAddressLocationGuid); if (location != null) { sparkLinkRequest.OrganizationLocation = new SparkLinkLocation(location); } } var sparkLinkRequestJson = JsonConvert.SerializeObject(sparkLinkRequest); var client = new RestClient("https://www.rockrms.com/api/SparkLink/update"); //var client = new RestClient( "http://localhost:57822/api/SparkLink/update" ); var request = new RestRequest(Method.POST); request.AddParameter("application/json", sparkLinkRequestJson, ParameterType.RequestBody); IRestResponse response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted) { foreach (var notification in JsonConvert.DeserializeObject <List <Notification> >(response.Content)) { notifications.Add(notification); } } if (sparkLinkRequest.VersionIds.Any()) { client = new RestClient("https://www.rockrms.com/api/Packages/VersionNotifications"); //client = new RestClient( "http://localhost:57822/api/Packages/VersionNotifications" ); request = new RestRequest(Method.GET); request.AddParameter("VersionIds", sparkLinkRequest.VersionIds.AsDelimited(",")); response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted) { foreach (var notification in JsonConvert.DeserializeObject <List <Notification> >(response.Content)) { notifications.Add(notification); } } } return(notifications); }
/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> public virtual void Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; var groupGuid = dataMap.Get("NotificationGroup").ToString().AsGuid(); var rockContext = new RockContext(); var group = new GroupService(rockContext).Get(groupGuid); if (group != null) { var installedPackages = InstalledPackageService.GetInstalledPackages(); var sparkLinkRequest = new SparkLinkRequest(); sparkLinkRequest.RockInstanceId = Rock.Web.SystemSettings.GetRockInstanceId(); sparkLinkRequest.OrganizationName = GlobalAttributesCache.Value("OrganizationName"); sparkLinkRequest.VersionIds = installedPackages.Select(i => i.VersionId).ToList(); sparkLinkRequest.RockVersion = VersionInfo.VersionInfo.GetRockSemanticVersionNumber(); var notifications = new List <Notification>(); var sparkLinkRequestJson = JsonConvert.SerializeObject(sparkLinkRequest); var client = new RestClient("https://www.rockrms.com/api/SparkLink/update"); //var client = new RestClient( "http://localhost:57822/api/SparkLink/update" ); var request = new RestRequest(Method.POST); request.AddParameter("application/json", sparkLinkRequestJson, ParameterType.RequestBody); IRestResponse response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted) { foreach (var notification in JsonConvert.DeserializeObject <List <Notification> >(response.Content)) { notifications.Add(notification); } } if (sparkLinkRequest.VersionIds.Any()) { client = new RestClient("https://www.rockrms.com/api/Packages/VersionNotifications"); //client = new RestClient( "http://localhost:57822/api/Packages/VersionNotifications" ); request = new RestRequest(Method.GET); request.AddParameter("VersionIds", sparkLinkRequest.VersionIds.AsDelimited(",")); response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted) { foreach (var notification in JsonConvert.DeserializeObject <List <Notification> >(response.Content)) { notifications.Add(notification); } } } if (notifications.Count == 0) { return; } var notificationService = new NotificationService(rockContext); foreach (var notification in notifications.ToList()) { if (notificationService.Get(notification.Guid) == null) { notificationService.Add(notification); } else { notifications.Remove(notification); } } rockContext.SaveChanges(); var notificationRecipientService = new NotificationRecipientService(rockContext); foreach (var notification in notifications) { foreach (var member in group.Members) { if (member.Person.PrimaryAliasId.HasValue) { var recipientNotification = new Rock.Model.NotificationRecipient(); recipientNotification.NotificationId = notification.Id; recipientNotification.PersonAliasId = member.Person.PrimaryAliasId.Value; notificationRecipientService.Add(recipientNotification); } } } rockContext.SaveChanges(); } }