예제 #1
0
        /// <summary>
        /// Exports the groups.
        /// </summary>
        /// <param name="selectedGroupTypes">The selected group types.</param>
        /// <param name="modifiedSince">The modified since.</param>
        /// <param name="perPage">The people per page.</param>
        public override void ExportGroups(List <int> selectedGroupTypes)
        {
            // write out the group types
            WriteGroupTypes(selectedGroupTypes);

            foreach (var groupType in GetGroupTypes().Where(g => selectedGroupTypes.Contains(g.Id)))
            {
                int parentGroupId = 90000000 + groupType.Id;

                ImportPackage.WriteToPackage(new Group()
                {
                    Id          = parentGroupId,
                    Name        = groupType.Name,
                    GroupTypeId = groupType.Id
                });
            }

            // Export F1 Activites
            if (selectedGroupTypes.Contains(99999904))
            {
                var dtActivityMembers = GetTableData(SQL_ACTIVITY_MEMBERS);

                // Add Group Ids for Break Out Groups
                foreach (var member in dtActivityMembers.Select("Group_Id is null"))
                {
                    MD5 md5Hasher = MD5.Create();
                    var hashed    = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(member.Field <string>("BreakoutGroup") + member.Field <string>("ParentGroupId")));
                    var groupId   = Math.Abs(BitConverter.ToInt32(hashed, 0));   // used abs to ensure positive number
                    if (groupId > 0)
                    {
                        member.SetField <int>("Group_Id", groupId);
                    }
                }

                using (var dtActivites = GetTableData(SQL_ACTIVITIES))
                {
                    foreach (DataRow row in dtActivites.Rows)
                    {
                        var importGroup = F1Group.Translate(row, dtActivityMembers);

                        if (importGroup != null)
                        {
                            ImportPackage.WriteToPackage(importGroup);
                        }
                    }
                }
            }

            using (var dtGroups = GetTableData(SQL_GROUPS))
            {
                var group_Type_Ids = string.Join(",", selectedGroupTypes.Select(n => n.ToString()).ToArray());

                var dtGroupMembers = GetTableData(SQL_GROUP_MEMBERS);

                foreach (DataRow row in dtGroups.Select("Group_Type_Id in(" + group_Type_Ids + ")"))
                {
                    var importGroup = F1Group.Translate(row, dtGroupMembers);

                    if (importGroup != null)
                    {
                        ImportPackage.WriteToPackage(importGroup);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Exports the groups.
        /// </summary>
        /// <param name="selectedGroupTypes">The selected group types.</param>
        /// <param name="modifiedSince">The modified since.</param>
        /// <param name="perPage">The people per page.</param>
        public override void ExportGroups(List <int> selectedGroupTypes)
        {
            // write out the group types
            WriteGroupTypes(selectedGroupTypes);

            // get groups
            try
            {
                int loopCounter = 0;

                foreach (var selectedGroupType in selectedGroupTypes)
                {
                    _client.Authenticator = OAuth1Authenticator.ForProtectedResource(ApiConsumerKey, ApiConsumerSecret, OAuthToken, OAuthSecret);
                    _request = new RestRequest(API_GROUPS + selectedGroupType.ToString() + "/groups", Method.GET);
                    _request.AddHeader("content-type", "application/xml");

                    var response = _client.Execute(_request);
                    ApiCounter++;

                    XDocument xdoc = XDocument.Parse(response.Content);

                    var groups = xdoc.Elements("groups");

                    if (groups.Elements().Any())
                    {
                        // since we don't have a group heirarchy to work with, add a parent
                        //  group for each group type for organizational purposes
                        int parentGroupId = 99 + groups.Elements().FirstOrDefault().Element("groupType").Attribute("id").Value.AsInteger();

                        ImportPackage.WriteToPackage(new Group()
                        {
                            Id          = parentGroupId,
                            Name        = groups.Elements().FirstOrDefault().Element("groupType").Element("name").Value,
                            GroupTypeId = groups.Elements().FirstOrDefault().Element("groupType").Attribute("id").Value.AsInteger(),
                            IsActive    = true
                        });

                        foreach (var groupNode in groups.Elements())
                        {
                            string groupId = groupNode.Attribute("id").Value;

                            _client.Authenticator = OAuth1Authenticator.ForProtectedResource(ApiConsumerKey, ApiConsumerSecret, OAuthToken, OAuthSecret);
                            _request = new RestRequest(API_GROUP_MEMBERS + groupId + "/members", Method.GET);
                            _request.AddHeader("content-type", "application/xml");

                            response = _client.Execute(_request);
                            ApiCounter++;

                            xdoc = XDocument.Parse(response.Content);

                            if (F1Api.DumpResponseToXmlFile)
                            {
                                xdoc.Save(Path.Combine(ImportPackage.PackageDirectory, $"API_GROUPS_ResponseLog_{loopCounter}.xml"));
                            }

                            var membersNode = xdoc.Elements("members");

                            var importGroup = F1Group.Translate(groupNode, parentGroupId, membersNode);

                            if (importGroup != null)
                            {
                                ImportPackage.WriteToPackage(importGroup);
                            }

                            // developer safety blanket (prevents eating all the api calls for the day)
                            if (loopCounter > loopThreshold)
                            {
                                break;
                            }
                            loopCounter++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }
        /// <summary>
        /// Internal method for ExportGroups().
        /// </summary>
        /// <param name="selectedGroupTypes">The selected group types.</param>
        private void ExportGroups_Internal(List <int> selectedGroupTypes)
        {
            // write out the group types
            WriteGroupTypes(selectedGroupTypes);

            foreach (var groupType in GetGroupTypes().Where(g => selectedGroupTypes.Contains(g.Id)))
            {
                int parentGroupId = 90000000 + groupType.Id;

                ImportPackage.WriteToPackage(new Group()
                {
                    Id          = parentGroupId,
                    Name        = groupType.Name,
                    GroupTypeId = groupType.Id
                });
            }

            // Export F1 Activites
            if (selectedGroupTypes.Contains(99999904))
            {
                using (var dtActivityMembers = GetTableData(SqlQueries.ACTIVITY_MEMBERS))
                {
                    // Add Group Ids for Break Out Groups
                    foreach (var member in dtActivityMembers.Select("Group_Id is null"))
                    {
                        MD5    md5Hasher   = MD5.Create();
                        string valueToHash = member.Field <string>("BreakoutGroup") + member.Field <string>("ParentGroupId");
                        var    hashed      = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(valueToHash));
                        var    groupId     = Math.Abs(BitConverter.ToInt32(hashed, 0)); // used abs to ensure positive number
                        if (groupId > 0)
                        {
                            member.SetField <int>("Group_Id", groupId);
                        }
                    }

                    using (var dtStaffing = GetTableData(SqlQueries.STAFFING))
                        using (var dtActivites = GetTableData(SqlQueries.ACTIVITIES))
                        {
                            foreach (DataRow row in dtActivites.Rows)
                            {
                                var importGroup = F1Group.Translate(row, dtActivityMembers, dtStaffing);

                                if (importGroup != null)
                                {
                                    ImportPackage.WriteToPackage(importGroup);
                                }
                            }

                            // Cleanup - Remember not to Clear() any cached tables.
                            dtStaffing.Clear();
                            dtActivites.Clear();
                        }

                    // Cleanup - Remember not to Clear() any cached tables.
                    dtActivityMembers.Clear();
                    GC.Collect();
                }
            }

            using (var dtGroups = GetTableData(SqlQueries.GROUPS))
                using (var dtGroupMembers = GetTableData(SqlQueries.GROUP_MEMBERS))
                {
                    var group_Type_Ids = string.Join(",", selectedGroupTypes.Select(n => n.ToString()).ToArray());

                    foreach (DataRow row in dtGroups.Select($"Group_Type_Id in({ group_Type_Ids })"))
                    {
                        var importGroup = F1Group.Translate(row, dtGroupMembers, null);

                        if (importGroup != null)
                        {
                            ImportPackage.WriteToPackage(importGroup);
                        }
                    }

                    // Cleanup - Remember not to Clear() any cached tables.
                    dtGroups.Clear();
                    dtGroupMembers.Clear();
                    GC.Collect();
                }
        }
예제 #4
0
        /// <summary>
        /// Internal method for ExportGroups().
        /// </summary>
        /// <param name="selectedGroupTypes">The selected group types.</param>
        private void ExportGroups_Internal(List <int> selectedGroupTypes)
        {
            // write out the group types
            WriteGroupTypes(selectedGroupTypes);

            foreach (var groupType in GetGroupTypes().Where(g => selectedGroupTypes.Contains(g.Id)))
            {
                int parentGroupId = 90000000 + groupType.Id;

                ImportPackage.WriteToPackage(new Group()
                {
                    Id          = parentGroupId,
                    Name        = groupType.Name,
                    GroupTypeId = groupType.Id
                });
            }

            // Export F1 Activites
            if (selectedGroupTypes.Contains(99999904))
            {
                var dvActivityAssignment = new DataView(_db.Table("ActivityAssignment").Data);

                dvActivityAssignment.RowFilter = "ISNULL(RLC_ID, 0) <> 0";
                var dtRlcGroupMembers = dvActivityAssignment.ToTable(true, "Individual_ID", "RLC_ID", "BreakoutGroupName");

                dvActivityAssignment.RowFilter = "ISNULL(BreakoutGroupName,'Null Column') <> 'Null Column'";
                var dtBreakoutGroupMembers = dvActivityAssignment.ToTable(true, "Individual_ID", "BreakoutGroupName", "RLC_ID", "Activity_ID");

                MD5 md5Hasher      = MD5.Create();
                var rlcAssignments = dtRlcGroupMembers.AsEnumerable().Select(r => new GroupMemberDTO
                {
                    IndividualId      = r.Field <int>("Individual_ID"),
                    GroupId           = r.Field <int>("RLC_ID"),
                    BreakoutGroupName = r.Field <string>("BreakoutGroupName"),
                    GroupMemberType   = "Member"
                });

                var breakoutGroupAssignments = dtBreakoutGroupMembers.AsEnumerable().Select(r => new GroupMemberDTO
                {
                    IndividualId      = r.Field <int>("Individual_ID"),
                    BreakoutGroupName = r.Field <string>("BreakoutGroupName"),
                    ParentGroupId     = r.Field <int?>("RLC_ID") ?? r.Field <int?>("Activity_ID"),
                    GroupMemberType   = "Member",
                    GroupIdHasher     = md5Hasher // Add Group Ids for Break Out Groups
                });

                var activityMembers = rlcAssignments.Concat(breakoutGroupAssignments).ToList();

                var dvActivityMinistry = new DataView(_db.Table("ActivityMinistry").Data);
                var dtMinistries       = dvActivityMinistry.ToTable(true, "Ministry_Name", "Ministry_ID", "Ministry_Active");
                var ministryGroups     = dtMinistries.AsEnumerable().Select(r => new GroupDTO
                {
                    GroupName     = r.Field <string>("Ministry_Name"),
                    GroupId       = r.Field <int>("Ministry_ID"),
                    GroupTypeId   = 99999904,
                    Description   = null,
                    IsActive      = !(r.Field <bool?>("Ministry_Active") == false),
                    StartDate     = null,
                    IsPublic      = false,
                    LocationName  = string.Empty,
                    ScheduleDay   = string.Empty,
                    StartHour     = null,
                    Address1      = string.Empty,
                    Address2      = string.Empty,
                    City          = string.Empty,
                    StateProvince = string.Empty,
                    PostalCode    = null,
                    Country       = string.Empty,
                    ParentGroupId = 0
                });

                var dtMinistryActivities   = dvActivityMinistry.ToTable(true, "Activity_Name", "Activity_ID", "Activity_Active", "Ministry_ID");
                var ministryActivityGroups = dtMinistryActivities.AsEnumerable().Select(r => new GroupDTO
                {
                    GroupName     = r.Field <string>("Activity_Name"),
                    GroupId       = r.Field <int>("Activity_ID"),
                    GroupTypeId   = 99999904,
                    Description   = null,
                    IsActive      = !(r.Field <bool?>("Activity_Active") == false),
                    StartDate     = null,
                    IsPublic      = false,
                    LocationName  = string.Empty,
                    ScheduleDay   = string.Empty,
                    StartHour     = null,
                    Address1      = string.Empty,
                    Address2      = string.Empty,
                    City          = string.Empty,
                    StateProvince = string.Empty,
                    PostalCode    = null,
                    Country       = string.Empty,
                    ParentGroupId = r.Field <int?>("Ministry_ID")
                });

                var dvActivityGroup = new DataView(_db.Table("Activity_Group").Data);
                var dtActivities    = dvActivityGroup.ToTable(true, "Activity_Group_Name", "Activity_Group_ID", "Activity_ID");
                var activityGroups  = dtActivities.AsEnumerable().Select(r => new GroupDTO
                {
                    GroupName     = r.Field <string>("Activity_Group_Name"),
                    GroupId       = r.Field <int>("Activity_Group_ID"),
                    GroupTypeId   = 99999904,
                    Description   = null,
                    IsActive      = true,
                    StartDate     = null,
                    IsPublic      = false,
                    LocationName  = string.Empty,
                    ScheduleDay   = string.Empty,
                    StartHour     = null,
                    Address1      = string.Empty,
                    Address2      = string.Empty,
                    City          = string.Empty,
                    StateProvince = string.Empty,
                    PostalCode    = null,
                    Country       = string.Empty,
                    ParentGroupId = r.Field <int?>("Activity_ID")
                });

                var dvRLC     = new DataView(_db.Table("RLC").Data);
                var dtRLC     = dvRLC.ToTable(true, "RLC_Name", "RLC_ID", "Is_Active", "Room_Name", "Activity_Group_ID", "Activity_ID");
                var rlcGroups = dtRLC.AsEnumerable().Select(r => new GroupDTO
                {
                    GroupName     = r.Field <string>("RLC_Name"),
                    GroupId       = r.Field <int>("RLC_ID"),
                    GroupTypeId   = 99999904,
                    Description   = null,
                    IsActive      = r.Field <bool>("Is_Active"),
                    StartDate     = null,
                    IsPublic      = false,
                    LocationName  = r.Field <string>("Room_Name"),
                    ScheduleDay   = string.Empty,
                    StartHour     = null,
                    Address1      = string.Empty,
                    Address2      = string.Empty,
                    City          = string.Empty,
                    StateProvince = string.Empty,
                    PostalCode    = null,
                    Country       = string.Empty,
                    ParentGroupId = r.Field <int?>("Activity_Group_ID") ?? r.Field <int?>("Activity_ID")
                });

                dvActivityAssignment.RowFilter = "ISNULL(BreakoutGroupName,'Null Column') <> 'Null Column'"; // This is already set, but it's good to have it here as a reminder.
                var dtActivityAssignmentGruops = dvActivityAssignment.ToTable(true, "BreakoutGroupName", "RLC_ID", "Activity_ID");
                var activityAssignmentGroups   = dtActivityAssignmentGruops.AsEnumerable().Select(r => new GroupDTO
                {
                    GroupName     = r.Field <string>("BreakoutGroupName"),
                    GroupId       = null,
                    GroupTypeId   = 99999904,
                    Description   = null,
                    IsActive      = true,
                    StartDate     = null,
                    IsPublic      = false,
                    LocationName  = string.Empty,
                    ScheduleDay   = string.Empty,
                    StartHour     = null,
                    Address1      = string.Empty,
                    Address2      = string.Empty,
                    City          = string.Empty,
                    StateProvince = string.Empty,
                    PostalCode    = null,
                    Country       = string.Empty,
                    ParentGroupId = r.Field <int?>("RLC_ID") ?? r.Field <int?>("Activity_ID")
                });

                var activities =
                    ministryGroups
                    .Concat(ministryActivityGroups)
                    .Concat(activityGroups)
                    .Concat(rlcGroups)
                    .Concat(activityAssignmentGroups)
                    .ToList();

                var dtStaffing = _db.Table("Staffing_Assignment").Data;
                foreach (var row in activities)
                {
                    var importGroup = F1Group.Translate(row, activityMembers, dtStaffing);

                    if (importGroup != null)
                    {
                        ImportPackage.WriteToPackage(importGroup);
                    }
                }
                // Cleanup.
                GC.Collect();
            }

            // Export F1 Groups
            var groupMembersQry = _db.Table("Groups").Data.AsEnumerable()
                                  .Select(r => new GroupMemberDTO
            {
                IndividualId    = r.Field <int>("Individual_ID"),
                GroupId         = r.Field <int?>("Group_Id"),
                GroupMemberType = r.Field <string>("Group_Member_Type")
            });

            var groupMembers = groupMembersQry.Distinct().ToList();

            var dvGroups            = new DataView(_db.Table("Groups").Data);
            var dtGroupsDistinct    = dvGroups.ToTable(true, "Group_Id", "Group_Type_Id", "Group_Name");
            var dtGroupsDescription = _db.Table("GroupsDescription").Data;

            var groups = (from table1 in dtGroupsDistinct.AsEnumerable()
                          join table2 in dtGroupsDescription.AsEnumerable()
                          on(int) table1["Group_ID"] equals(int) table2["Group_ID"]
                          into groupsWithDescriptions
                          from output in groupsWithDescriptions.DefaultIfEmpty()
                          where selectedGroupTypes.Contains(( int )table1["Group_Type_Id"])
                          select new GroupDTO
            {
                GroupName = table1.Field <string>("Group_Name"),
                GroupId = table1.Field <int>("Group_Id"),
                GroupTypeId = table1.Field <int>("Group_Type_Id"),
                IsActive = !(output?.Field <bool?>("is_open") == false),
                StartDate = output?.Field <DateTime>("start_date"),
                IsPublic = output?.Field <bool?>("is_open"),
                LocationName = output?.Field <string>("Location_Name"),
                ScheduleDay = output?.Field <string>("ScheduleDay"),
                StartHour = output?.Field <string>("StartHour"),
                Address1 = output?.Field <string>("Address1"),
                Address2 = output?.Field <string>("Address2"),
                City = output?.Field <string>("City"),
                StateProvince = output?.Field <string>("StProvince"),
                PostalCode = output?.Field <string>("PostalCode"),
                Country = output?.Field <string>("Country"),
                ParentGroupId = null
            }).ToList();

            foreach (var group in groups)
            {
                var importGroup = F1Group.Translate(group, groupMembers, null);

                if (importGroup != null)
                {
                    ImportPackage.WriteToPackage(importGroup);
                }
            }

            // Cleanup.
            GC.Collect();
        }