Ejemplo n.º 1
0
        public override WorkerResult Run(bool previousWorkersActive)
        {
            try
            {
                int    state;
                string message;

                if (Convert.ToBoolean(Enabled))
                {
                    if (RunIfPreviousWorkersActive || !previousWorkersActive)
                    {
                        WorkerResultStatus status = SyncUsers(out message, out state);
                        return(new WorkerResult(state, status, string.Format(Description), message));
                    }
                    else
                    {
                        return(new WorkerResult(STATE_OK, WorkerResultStatus.Abort, string.Format(Description), "Did not run because previous worker instance still active."));
                    }
                }
                else
                {
                    return(new WorkerResult(STATE_OK, WorkerResultStatus.Abort, string.Format(Description), "Did not run because worker not enabled."));
                }
            }
            catch (Exception e)
            {
                // handle special exceptions here...
                throw (e);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor to intialize with values including short and detailed messages.</summary>
 public WorkerResult(int state, WorkerResultStatus status, string shortMessage, string detailedMessage)
 {
     _state = state;
     _status = status;
     _shortMessage = shortMessage;
     _detailedMessage = detailedMessage;
 }
Ejemplo n.º 3
0
        public WorkerResultStatus ProcessXML(out string message, out int state)
        {
            Trace.Write("Starting ProcessXML Agent...\n");

            WorkerResultStatus workerResultStatus = WorkerResultStatus.Ok;

            message = string.Empty;
            state   = STATE_OK;

            try
            {
                message += CreateStaffXML();
                if (message != string.Empty)
                {
                    workerResultStatus = WorkerResultStatus.Warning;
                }
            }
            catch (Exception ex)
            {
                workerResultStatus = WorkerResultStatus.Warning;
                message            = "An error occured while generating Staff XML.\n\nMessage\n------------------------\n" + ex.Message + "\n\nStack Trace\n------------------------\n" + ex.StackTrace;
            }

            return(workerResultStatus);
        }
Ejemplo n.º 4
0
        public WorkerResultStatus ProcessGroups(out string message, out int state)
        {
            Trace.Write("Starting ProcessGroups Agent...\n");

            WorkerResultStatus workerResultStatus = WorkerResultStatus.Ok;

            message = string.Empty;
            state   = STATE_OK;

            try
            {
                Arena.Custom.CCV.SmallGroup.GroupCollection groups = new Arena.Custom.CCV.SmallGroup.GroupCollection();
                groups.LoadByClusterType(_clusterTypeId);

                foreach (Group group in groups)
                {
                    // Log the Leader
                    if (group.LeaderID != -1)
                    {
                        GroupMemberLog leaderLog = new GroupMemberLog();
                        leaderLog.PersonID = group.LeaderID;
                        leaderLog.GroupID  = group.GroupID;
                        leaderLog.Role     = new Lookup();
                        leaderLog.SaveGroupMemberLog(group);
                    }

                    // Save the Members
                    foreach (GroupMember groupMember in group.Members)
                    {
                        new GroupMemberLog(groupMember).SaveGroupMemberLog(group);
                    }
                }
            }
            catch (Exception ex)
            {
                workerResultStatus = WorkerResultStatus.Exception;
                message            = "An error occured while processing Group Status Update.\n\nMessage\n------------------------\n" + ex.Message + "\n\nStack Trace\n------------------------\n" + ex.StackTrace;
            }
            finally
            {
            }

            return(workerResultStatus);
        }
Ejemplo n.º 5
0
        public WorkerResultStatus ProcessActions(out string message, out int state)
        {
            WorkerResultStatus workerResultStatus = WorkerResultStatus.Ok;

            message = string.Empty;
            state   = STATE_OK;

            try
            {
                System.Text.StringBuilder sbErrors = new System.Text.StringBuilder();

                // Process Actions
                Arena.Custom.CCV.Data.ActionCollection actions = new Arena.Custom.CCV.Data.ActionCollection();
                actions.LoadAll();

                foreach (Arena.Custom.CCV.Data.Action action in actions)
                {
                    try
                    {
                        action.DoAction();
                    }
                    catch (Exception ex)
                    {
                        sbErrors.AppendFormat("Action Failed...\n\tAction Name: {0}\n\tAction Assembly: {1}\n\tError Message: {2}\n\n",
                                              action.Name, action.ActionAssembly, ex.Message);
                    }
                }

                if (sbErrors.Length > 0)
                {
                    throw new Arena.Exceptions.ArenaApplicationException("Data Update Processing encountered following problems:\n\n" + sbErrors.ToString());
                }
            }
            catch (Exception ex)
            {
                workerResultStatus = WorkerResultStatus.Exception;
                message            = "Error occurred while processing data update actions.\n\nMessage:\n" + ex.Message + "\n\nStack Trace\n------------------------" + ex.StackTrace;
            }

            return(workerResultStatus);
        }
Ejemplo n.º 6
0
        public WorkerResultStatus SendEmail(out string message, out int state)
        {
            WorkerResultStatus workerResultStatus = WorkerResultStatus.Ok;

            message = string.Empty;
            state   = STATE_OK;

            try
            {
                string day = DateTime.Today.DayOfWeek.ToString().ToLower();

                GroupClusterCollection clusters = new GroupClusterCollection();
                clusters.LoadChildClusterHierarchy(-1, _categoryId, _organizationId);
                RecurseClusters(clusters, day);
            }
            catch (Exception ex)
            {
                workerResultStatus = WorkerResultStatus.Exception;
                message            = "An error occured while processing ERA Loss Notifications.\n\nMessage\n------------------------\n" + ex.Message + "\n\nStack Trace\n------------------------\n" + ex.StackTrace;
            }

            return(workerResultStatus);
        }
Ejemplo n.º 7
0
        public WorkerResultStatus SyncUsers(out string message, out int state)
        {
            WorkerResultStatus workerResultStatus = WorkerResultStatus.Ok;

            message = string.Empty;
            state   = STATE_OK;

            try
            {
                System.Text.StringBuilder sbErrors = new System.Text.StringBuilder();

                Lookup pcoAccount = new Lookup(Convert.ToInt32(_PCOAccountLUID));
                Arena.Custom.CCV.PCO.People _pcoPeople = new People(_organizationId, pcoAccount, _publicArenaURL);

                List <int> editorRoleMembers         = new List <int>();
                Dictionary <int, Person> roleMembers = new Dictionary <int, Person>();

                foreach (var id in _editorRoleList.Split(','))
                {
                    if (id.Trim() != string.Empty)
                    {
                        Arena.Security.Role role = new Arena.Security.Role(Int32.Parse(id));
                        foreach (int memberID in role.RoleMemberIds)
                        {
                            if (!editorRoleMembers.Contains(memberID))
                            {
                                editorRoleMembers.Add(memberID);
                            }
                            if (!roleMembers.ContainsKey(memberID))
                            {
                                roleMembers.Add(memberID, new Person(memberID));
                            }
                        }
                    }
                }

                foreach (var id in _roleList.Split(','))
                {
                    if (id.Trim() != string.Empty)
                    {
                        Arena.Security.Role role = new Arena.Security.Role(Int32.Parse(id));
                        foreach (int memberID in role.RoleMemberIds)
                        {
                            if (!roleMembers.ContainsKey(memberID))
                            {
                                roleMembers.Add(memberID, new Person(memberID));
                            }
                        }
                    }
                }

                // Update existing users
                List <int> activeUsers = new List <int>();
                foreach (KeyValuePair <int, Person> member in roleMembers)
                {
                    activeUsers.Add(member.Key);
                    try
                    {
                        _pcoPeople.SyncPerson(member.Value, "PCOSync", editorRoleMembers.Contains(member.Key));
                    }
                    catch (Exception ex)
                    {
                        StringBuilder errorMessage = new StringBuilder();

                        System.Exception exception = ex;
                        while (exception != null)
                        {
                            errorMessage.AppendFormat("{0}\n\n", exception.Message);
                            exception = exception.InnerException;
                        }

                        sbErrors.AppendFormat("PCO Sync Failed...\n\tPerson: {0}\n\tError Message: {1}",
                                              member.Value.FullName, errorMessage.ToString());
                    }
                }

                // Disable Old Users
                _pcoPeople.Disable(activeUsers);

                if (sbErrors.Length > 0)
                {
                    throw new Arena.Exceptions.ArenaApplicationException("PCO Sync Processing encountered following problems:\n\n" + sbErrors.ToString());
                }
            }
            catch (Exception ex)
            {
                workerResultStatus = WorkerResultStatus.Exception;
                message            = "Error occurred while processing PCO Sync.\n\nMessage:\n" + ex.Message + "\n\nStack Trace\n------------------------" + ex.StackTrace;
            }

            return(workerResultStatus);
        }
        public WorkerResultStatus ProcessVisitors(out string message, out int state)
        {
            Trace.Write("Starting FirstTimeVisitAssignments Agent...\n");

            WorkerResultStatus workerResultStatus = WorkerResultStatus.Ok;

            message = string.Empty;
            state   = STATE_OK;

            try
            {
                //groupAssignmentType = new AssignmentType(GroupVisitAssignmentType);
                //if (groupAssignmentType.AssignmentTypeId == -1)
                //    throw new Exception("Invalid 'Neighborhood Group Assignment Type' setting");

                childAssignmentType = new AssignmentType(ChildVisitAssignmentType);
                if (childAssignmentType.AssignmentTypeId == -1)
                {
                    throw new Exception("Invalid 'Child Assignment Type' setting");
                }

                juniorHighAssignmentType = new AssignmentType(JuniorHighVisitAssignmentType);
                if (juniorHighAssignmentType.AssignmentTypeId == -1)
                {
                    throw new Exception("Invalid 'Junior High Assignment Type' setting");
                }

                highSchoolAssignmentType = new AssignmentType(HighSchoolVisitAssignmentType);
                if (highSchoolAssignmentType.AssignmentTypeId == -1)
                {
                    throw new Exception("Invalid 'High School Assignment Type' setting");
                }

                adultAssignmentType = new AssignmentType(AdultVisitAssignmentType);
                if (adultAssignmentType.AssignmentTypeId == -1)
                {
                    throw new Exception("Invalid 'Adult Assignment Type' setting");
                }

                //groupFamilyIDField = GetAssignmentTypeField(groupAssignmentType, "Family ID");
                //groupFirstVisitDateField = GetAssignmentTypeField(groupAssignmentType, "First Visit Date");

                childFamilyIDField       = GetAssignmentTypeField(childAssignmentType, "Family ID");
                childFirstVisitDateField = GetAssignmentTypeField(childAssignmentType, "First Visit Date");

                juniorHighFamilyIDField       = GetAssignmentTypeField(juniorHighAssignmentType, "Family ID");
                juniorHighFirstVisitDateField = GetAssignmentTypeField(juniorHighAssignmentType, "First Visit Date");

                highSchoolFamilyIDField       = GetAssignmentTypeField(highSchoolAssignmentType, "Family ID");
                highSchoolFirstVisitDateField = GetAssignmentTypeField(highSchoolAssignmentType, "First Visit Date");

                adultFamilyIDField       = GetAssignmentTypeField(adultAssignmentType, "Family ID");
                adultFirstVisitDateField = GetAssignmentTypeField(adultAssignmentType, "First Visit Date");

                Lookup child = new Lookup(SystemLookup.FamilyRole_Child);

                DateTime beginDate = DateTime.Today.Date.AddDays(-DaysBack);

                ArrayList lst = new ArrayList();
                lst.Add(new SqlParameter("@AttributeID", FirstTimeVisitAttributeID));
                lst.Add(new SqlParameter("@BeginDate", beginDate));
                //lst.Add(new SqlParameter("@GroupFamilyIDField", groupFamilyIDField.CustomFieldId));
                lst.Add(new SqlParameter("@ChildFamilyIDField", childFamilyIDField.CustomFieldId));
                lst.Add(new SqlParameter("@JuniorHighFamilyIDField", juniorHighFamilyIDField.CustomFieldId));
                lst.Add(new SqlParameter("@HighSchoolFamilyIDField", highSchoolFamilyIDField.CustomFieldId));
                lst.Add(new SqlParameter("@AdultFamilyIDField", adultFamilyIDField.CustomFieldId));

                Arena.DataLayer.Organization.OrganizationData oData = new Arena.DataLayer.Organization.OrganizationData();

                SqlDataReader rdr = oData.ExecuteReader("cust_ccv_recent_visitor_families", lst);

                while (rdr.Read())
                {
                    OccurrenceAttendanceCollection attendances = new OccurrenceAttendanceCollection();
                    //bool interestedInGroup = false;

                    Family family = new Family((int)rdr["family_id"]);

                    bool newFamily  = true;
                    int  childCount = 0;
                    int  adultCount = 0;
                    bool attendedHS = false;
                    bool attendedJH = false;

                    foreach (FamilyMember fm in family.FamilyMembers)
                    {
                        PersonAttribute pa = (PersonAttribute)fm.Attributes.FindByID(FirstTimeVisitAttributeID);
                        if (pa != null && !pa.DateValue.IsEmptyDate() && pa.DateValue < beginDate)
                        {
                            newFamily = false;
                        }

                        if (newFamily)
                        {
                            if (fm.FamilyRole.LookupID == child.LookupID)
                            {
                                childCount++;
                            }
                            else
                            {
                                adultCount++;
                            }

                            //pa = (PersonAttribute)fm.Attributes.FindByID(InterestedInGroupAttributeID);
                            //if (pa != null && pa.IntValue == 1)
                            //    interestedInGroup = true;

                            ArrayList lstOccurrence = new ArrayList();
                            lstOccurrence.Add(new SqlParameter("@PersonID", fm.PersonID));
                            SqlDataReader rdrOccurrence = oData.ExecuteReader("cust_ccv_recent_visitor_first_checkin", lstOccurrence);
                            if (rdrOccurrence.Read())
                            {
                                if (((DateTime)rdrOccurrence["first_attended"]).Date >= beginDate)
                                {
                                    OccurrenceAttendance oa = new OccurrenceAttendance((int)rdrOccurrence["occurrence_attendance_id"]);
                                    if (oa.Occurrence.OccurrenceType.OccurrenceTypeId == HighSchoolAttendanceTypeID)
                                    {
                                        attendedHS = true;
                                    }
                                    else if (oa.Occurrence.OccurrenceType.OccurrenceTypeId == JuniorHighAttendanceTypeID)
                                    {
                                        attendedJH = true;
                                    }

                                    attendances.Add(oa);
                                }
                            }
                            rdrOccurrence.Close();
                        }
                    }

                    if (newFamily)
                    {
                        _regionalPastorID = -1;

                        Assignment assignment = new Assignment();
                        assignment.Title             = family.FamilyName;
                        assignment.Description       = BuildDescription(family, attendances);
                        assignment.RequesterPersonId = family.FamilyHead.PersonID;

                        //if (interestedInGroup)
                        //{
                        //    assignment.AssignmentTypeId = groupAssignmentType.AssignmentTypeId;
                        //    assignment.PriorityId = groupAssignmentType.DefaultPriorityId;
                        //    assignment.StatusId = groupAssignmentType.DefaultStatusId;

                        //    AssignmentFieldValue familyIDField = new AssignmentFieldValue(groupFamilyIDField.CustomFieldId);
                        //    familyIDField.SelectedValue = family.FamilyID.ToString();
                        //    assignment.FieldValues.Add(familyIDField);

                        //    AssignmentFieldValue firstVisitDateField = new AssignmentFieldValue(groupFirstVisitDateField.CustomFieldId);
                        //    firstVisitDateField.SelectedValue = ((DateTime)rdr["first_visit"]).ToShortDateString();
                        //    assignment.FieldValues.Add(firstVisitDateField);

                        //    if (_regionalPastorID != -1)
                        //        assignment.SubmitAssignmentEntry(childAssignmentType.Owner != null ? adultAssignmentType.Owner : family.FamilyHead, "FirstTimeVisitAssignment Agent", _regionalPastorID);
                        //    else
                        //        assignment.SubmitAssignmentEntry(childAssignmentType.Owner != null ? adultAssignmentType.Owner : family.FamilyHead, "FirstTimeVisitAssignment Agent");
                        //}
                        //else
                        //{

                        if (attendedHS)
                        {
                            assignment.AssignmentTypeId = highSchoolAssignmentType.AssignmentTypeId;
                            assignment.PriorityId       = highSchoolAssignmentType.DefaultPriorityId;

                            AssignmentFieldValue familyIDField = new AssignmentFieldValue(highSchoolFamilyIDField.CustomFieldId);
                            familyIDField.SelectedValue = family.FamilyID.ToString();
                            assignment.FieldValues.Add(familyIDField);

                            AssignmentFieldValue firstVisitDateField = new AssignmentFieldValue(highSchoolFirstVisitDateField.CustomFieldId);
                            firstVisitDateField.SelectedValue = ((DateTime)rdr["first_visit"]).ToShortDateString();
                            assignment.FieldValues.Add(firstVisitDateField);

                            assignment.SubmitAssignmentEntry(highSchoolAssignmentType.Owner != null ? highSchoolAssignmentType.Owner : family.FamilyHead, "FirstTimeVisitAssignment Agent");
                        }
                        else if (attendedJH)
                        {
                            assignment.AssignmentTypeId = juniorHighAssignmentType.AssignmentTypeId;
                            assignment.PriorityId       = juniorHighAssignmentType.DefaultPriorityId;

                            AssignmentFieldValue familyIDField = new AssignmentFieldValue(juniorHighFamilyIDField.CustomFieldId);
                            familyIDField.SelectedValue = family.FamilyID.ToString();
                            assignment.FieldValues.Add(familyIDField);

                            AssignmentFieldValue firstVisitDateField = new AssignmentFieldValue(juniorHighFirstVisitDateField.CustomFieldId);
                            firstVisitDateField.SelectedValue = ((DateTime)rdr["first_visit"]).ToShortDateString();
                            assignment.FieldValues.Add(firstVisitDateField);

                            assignment.SubmitAssignmentEntry(highSchoolAssignmentType.Owner != null ? juniorHighAssignmentType.Owner : family.FamilyHead, "FirstTimeVisitAssignment Agent");
                        }
                        else if (childCount == 0)
                        {
                            assignment.AssignmentTypeId = adultAssignmentType.AssignmentTypeId;
                            assignment.PriorityId       = adultAssignmentType.DefaultPriorityId;

                            AssignmentFieldValue familyIDField = new AssignmentFieldValue(adultFamilyIDField.CustomFieldId);
                            familyIDField.SelectedValue = family.FamilyID.ToString();
                            assignment.FieldValues.Add(familyIDField);

                            AssignmentFieldValue firstVisitDateField = new AssignmentFieldValue(adultFirstVisitDateField.CustomFieldId);
                            firstVisitDateField.SelectedValue = ((DateTime)rdr["first_visit"]).ToShortDateString();
                            assignment.FieldValues.Add(firstVisitDateField);

                            assignment.SubmitAssignmentEntry(adultAssignmentType.Owner != null ? adultAssignmentType.Owner : family.FamilyHead, "FirstTimeVisitAssignment Agent");
                        }
                        else if (adultCount > 0)
                        {
                            assignment.AssignmentTypeId = childAssignmentType.AssignmentTypeId;
                            assignment.PriorityId       = childAssignmentType.DefaultPriorityId;

                            AssignmentFieldValue familyIDField = new AssignmentFieldValue(childFamilyIDField.CustomFieldId);
                            familyIDField.SelectedValue = family.FamilyID.ToString();
                            assignment.FieldValues.Add(familyIDField);

                            AssignmentFieldValue firstVisitDateField = new AssignmentFieldValue(childFirstVisitDateField.CustomFieldId);
                            firstVisitDateField.SelectedValue = ((DateTime)rdr["first_visit"]).ToShortDateString();
                            assignment.FieldValues.Add(firstVisitDateField);

                            assignment.SubmitAssignmentEntry(childAssignmentType.Owner != null ? childAssignmentType.Owner : family.FamilyHead, "FirstTimeVisitAssignment Agent");
                        }
                    }
                }
                rdr.Close();
            }
            catch (Exception ex)
            {
                workerResultStatus = WorkerResultStatus.Exception;
                message            = "An error occured while processing First Time Visitor Assignments.\n\nMessage\n------------------------\n" + ex.Message + "\n\nStack Trace\n------------------------\n" + ex.StackTrace;
            }
            finally
            {
            }

            return(workerResultStatus);
        }
Ejemplo n.º 9
0
        public WorkerResultStatus SendEmail(out string message, out int state)
        {
            WorkerResultStatus workerResultStatus = WorkerResultStatus.Ok;

            message = string.Empty;
            state   = STATE_OK;

            try
            {
                AreaOutreachCoordinatorCollection pastors = new AreaOutreachCoordinatorCollection();
                pastors.LoadByRole(1623);

                Arena.DataLayer.Organization.OrganizationData oData = new Arena.DataLayer.Organization.OrganizationData();

                string        query = "SELECT * FROM cust_ccv_era_losses WHERE processed = 1 AND send_email = 1 AND sent = 0";
                SqlDataReader rdr   = oData.ExecuteReader(query);
                while (rdr.Read())
                {
                    Family       family     = new Family((int)rdr["family_id"]);
                    FamilyMember familyHead = family.FamilyHead;

                    if (familyHead != null && familyHead.Emails.Count > 0)
                    {
                        Area area = familyHead.Area;
                        if (area != null)
                        {
                            Person pastor = null;
                            foreach (AreaOutreachCoordinator coord in pastors)
                            {
                                if (coord.AreaId == area.AreaID)
                                {
                                    pastor = new Person(coord.PersonId);
                                    break;
                                }
                            }

                            if (pastor != null)
                            {
                                Arena.Custom.CCV.Core.Communications.PotentialLossNotification lossNotification = new Arena.Custom.CCV.Core.Communications.PotentialLossNotification();
                                Dictionary <string, string> fields = new Dictionary <string, string>();
                                fields.Add("##RecipientFirstName##", familyHead.NickName);
                                fields.Add("##RecipientLastName##", familyHead.LastName);
                                fields.Add("##RecipientEmail##", familyHead.Emails.FirstActive);
                                fields.Add("##PastorName##", pastor.FullName);
                                fields.Add("##PastorEmail##", pastor.Emails.FirstActive);

                                PersonPhone bPhone = pastor.Phones.FindByType(SystemLookup.PhoneType_Business);
                                fields.Add("##PastorBusinessPhone##", bPhone != null ? bPhone.Number : string.Empty);
                                PersonPhone cPhone = pastor.Phones.FindByType(SystemLookup.PhoneType_Cell);
                                fields.Add("##PastorCellPhone##", cPhone != null ? cPhone.Number : string.Empty);

                                if (lossNotification.Send(familyHead.Emails.FirstActive, fields, familyHead.PersonID))
                                {
                                    string updateQuery = string.Format("UPDATE cust_ccv_era_losses SET sent = 1 WHERE family_id = {0}",
                                                                       family.FamilyID.ToString());
                                    oData.ExecuteNonQuery(updateQuery);
                                }
                            }
                        }
                    }
                }
                rdr.Close();
            }
            catch (Exception ex)
            {
                workerResultStatus = WorkerResultStatus.Exception;
                message            = "An error occured while processing ERA Loss Notifications.\n\nMessage\n------------------------\n" + ex.Message + "\n\nStack Trace\n------------------------\n" + ex.StackTrace;
            }

            return(workerResultStatus);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Constructor to intialize with values when there is an exception.</summary>
 public WorkerResult(int state, WorkerResultStatus status, string shortMessage, string detailedMessage, Exception workerException)
 {
     _state = state;
     _status = status;
     _shortMessage = shortMessage;
     _detailedMessage = detailedMessage;
     _workerException = workerException;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructor to intialize with minimal values.</summary>
 public WorkerResult(int state, WorkerResultStatus status)
 {
     _state = state;
     _status = status;
 }
Ejemplo n.º 12
0
        public void RecordJobFinished(JobComponentFinishedEventArgs args)
        {
            if (!args.JobComponentName.Equals(JobComponent))
                throw new ApplicationException("This is not the same job history object");

            this.Status = args.Result.Status;
            this.Details = args.Result.DetailedMessage;
            this.EndTime = args.Result.TimeFinished;
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Returns true if the specified result status is a status
 /// that warrants notification.</summary>
 protected virtual bool ShouldNotify(WorkerResultStatus status)
 {
     // compare the status to the notification statuses
     return (NotifyOnWorkerResultStatus & status) != 0;
 }