protected void mdEnrollGroup_SaveClick(object sender, EventArgs e) { var groupId = pGroup.SelectedValueAsId(); if (!groupId.HasValue) { return; } RockContext rockContext = new RockContext(); CourseService courseService = new CourseService(rockContext); GroupService groupService = new GroupService(rockContext); var course = GetCourse(courseService); var group = groupService.Get(groupId.Value); if (!course.EnrolledGroups.Select(g => g.Id).Contains(groupId.Value)) { course.EnrolledGroups.Add(group); rockContext.SaveChanges(); } //The async code in the client doesn't play nice with Web Forms ¯\_(ツ)_/¯ Task.Run(() => { var riseClient = new RiseClient(); riseClient.Enroll(course, group); }); mdEnrollGroup.Hide(); BindGrid(); }
internal void Sync() { var person = Data.Submitter.GetRockPerson(); if (person == null) { throw new Exception("Could not find Rock person for Rise Id: " + Data.Submitter.Id); } RiseClient riseClient = new RiseClient(); var course = riseClient.SyncCourse(Data.Course); RockContext rockContext = new RockContext(); ExperienceService experienceService = new ExperienceService(rockContext); var experience = new Experience { PersonAliasId = person.PrimaryAliasId ?? 0, VerbValueId = xAPI.Utilities.VerbHelper.GetOrCreateVerb("http://activitystrea.ms/schema/1.0/author").Id, xObject = new ExperienceObject { EntityTypeId = EntityTypeCache.Get(typeof(Course)).Id, ObjectId = course.Id.ToString() }, Result = new ExperienceResult { IsComplete = true, WasSuccess = true } }; experienceService.Add(experience); rockContext.SaveChanges(); }
protected void btnGroupDelete_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e) { var groupId = e.RowKeyId; RockContext rockContext = new RockContext(); CourseService courseService = new CourseService(rockContext); GroupService groupService = new GroupService(rockContext); var course = GetCourse(courseService); var group = groupService.Get(groupId); if (course.EnrolledGroups.Select(g => g.Id).Contains(groupId)) { course.EnrolledGroups.Remove(course.EnrolledGroups.Where(g => g.Id == groupId).FirstOrDefault()); rockContext.SaveChanges(); } //The async code in the client doesn't play nice with Web Forms ¯\_(ツ)_/¯ Task.Run(() => { var riseClient = new RiseClient(); riseClient.Unenroll(course, group); }); BindGrid(); }
protected void btnSync_Click(object sender, EventArgs e) { System.Threading.Tasks.Task.Run(() => { RiseClient riseClient = new RiseClient(); var i = riseClient.SyncCourses(); }); maSync.Show(string.Format("Syncing courses has begun in the background."), Rock.Web.UI.Controls.ModalAlertType.Information); }
/// <summary>Executes the specified context.</summary> /// <param name="context">The context.</param> /// <param name="action">The action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public override bool Execute(RockContext context, WorkflowAction action, object entity, out List <string> errorMessages) { errorMessages = new List <string>(); RockContext rockContext = new RockContext(); PersonAliasService personAliasService = new PersonAliasService(rockContext); GroupService groupService = new GroupService(rockContext); var personAliasGuid = GetAttributeValue(action, "Person", true); var personAlias = personAliasService.Get(personAliasGuid.AsGuid()); if (personAlias == null) { action.AddLogEntry("Person attribute did not contain a person.", true); return(false); } var person = personAlias.Person; person.LoadAttributes(); var personRiseId = person.GetAttributeValue(Constants.PERSON_ATTRIBUTE_KEY_RISEID); if (personRiseId.IsNullOrWhiteSpace()) { action.AddLogEntry("Person is not currently in Rise. Person will by synced automatically when their Rise account is created.", true); return(true); //We didn't fail. } var groupGuid = GetAttributeValue(action, "Group", true); var group = groupService.Get(groupGuid.AsGuid()); if (group == null) { action.AddLogEntry("Group attribute did not contain a group.", true); return(false); } if (group.GroupTypeId != Constants.GetRiseGroupTypeId()) { action.AddLogEntry("Group was not a Rise group type.", true); return(false); } var task = Task.Run(() => //webforms doesn't play nice with async code { RiseClient riseClient = new RiseClient(); var riseGroup = riseClient.GetOrCreateGroup(group); riseGroup.RemoveMember(personRiseId); }); task.Wait(); return(true); }
public Course GetRockCourse(CourseService courseService) { var course = courseService.GetByCourseId(Id); if (course == null) { RiseClient riseClient = new RiseClient(); course = riseClient.SyncCourse(this, courseService); } return(course); }
protected void btnDelete_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e) { var id = ( string )e.RowKeyValue; var task = Task.Run(() => { RiseClient riseClient = new RiseClient(); riseClient.DeleteWebhook(id); }); task.Wait(1000 * 10); BindGrid(); }
protected void mdAddWebhook_SaveClick(object sender, EventArgs e) { var task = Task.Run(() => { RiseClient riseClient = new RiseClient(); riseClient.CreateWebhook(tbUrl.Text, new List <string> { ddlEventType.SelectedValue }); }); task.Wait(1000 * 10); mdAddWebhook.Hide(); BindGrid(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { //Async code does not work in the webforms main thread. var task = Task.Run(() => { RiseClient riseClient = new RiseClient(); var webhooks = riseClient.GetWebhooks().ToList(); gList.DataSource = webhooks; }); task.Wait(1000 * 10); gList.DataBind(); }
private void SetUpAccount() { pnlCreateAccount.Visible = true; //Load iframe in background var url = Request.RawUrl; if (url.Contains("?")) { url += "&" + PageParameterKeys.BackgroundReqest + "=true"; } else { url += "?" + PageParameterKeys.BackgroundReqest + "=true"; } ifBackground.Attributes.Add("src", url); Task.Run(() => { var i = 0; while (i < 10) { i++; Task.Delay(10 * 1000).Wait(); //try every 10 seconds RiseClient riseClient = new RiseClient(); if (riseClient.SyncPerson(CurrentPerson)) { _hubContext.Clients.All.receiveNotification(this.SignalRNotificationKey, "success"); return; } } _hubContext.Clients.All.receiveNotification(this.SignalRNotificationKey, "fail"); }); }
internal void SyncCompletions() { var xObject = GetExperienceObject(); var reports = ClientManager.GetSet <RiseCourseReport>(this.CourseId); foreach (var report in reports) { var person = RiseUser.GetPerson(report.UserId); if (person == null) { RiseClient riseClient = new RiseClient(); person = riseClient.GetUser(report.UserId).GetRockPerson(); } if (person != null) { var contextExtensions = new Dictionary <string, string> { { "http://id.tincanapi.com/extension/duration", report.Duration } }; UpdateCourseStatus(xObject, person, report.Status == "Complete", report.QuizScorePercent, contextExtensions); } } }