Ejemplo n.º 1
0
        /// <summary>
        /// Parses the complete Mesh Section
        /// </summary>
        /// <param name="grps"></param>
        /// <param name="ct"></param>
        void ParseMeshSection(ImportedGroups grps, int ct)
        {
            for (int i = 0; i < ct; i++)
            {
                ImportedGroup g = this.PrepareGroup();


                //BoneLinks-----
                GmdcElement e = new GmdcElement(Gmdc);
                g.Elements.Add(e);
                e.Identity    = ElementIdentity.BoneAssignment;
                e.BlockFormat = BlockFormat.OneDword;
                e.SetFormat   = SetFormat.Secondary;

                //BoneWeights-----
                e = new GmdcElement(Gmdc);
                g.Elements.Add(e);
                e.Identity    = ElementIdentity.BoneWeights;
                e.BlockFormat = BlockFormat.OneFloat;
                e.SetFormat   = SetFormat.Secondary;

                //Read the Mesh Data
                ReadMeshDescription(g);
                int vertcount = ReadCount();
                for (int k = 0; k < vertcount; k++)
                {
                    ReadVertexData(g);
                }

                int vertnormcount = ReadCount();
                for (int k = 0; k < vertnormcount; k++)
                {
                    ReadVertexNormalData(g);
                }

                int facecount = ReadCount();
                for (int k = 0; k < facecount; k++)
                {
                    ReadFaceData(g);
                }

                RemoveDuplicates(g);
                grps.Add(g);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load in the basic group information passed in by the caller. Group is not saved
        /// unless the caller explecitely save the group.
        /// </summary>
        /// <param name="lookupContext">The lookup context.</param>
        /// <param name="groupKey">The group key.</param>
        /// <param name="name">The name.</param>
        /// <param name="createdDate">The created date.</param>
        /// <param name="type">The type.</param>
        /// <param name="parentGroupKey">The parent group key.</param>
        /// <param name="active">The active.</param>
        /// <returns></returns>
        private Group LoadGroupBasic(RockContext lookupContext, string groupKey, string name, string createdDate, string type, string parentGroupKey, string active, string description = "")
        {
            var   groupTypeId = LoadGroupTypeId(lookupContext, type);
            var   groupId = groupKey.AsType <int?>();
            Group group, parent;

            //
            // See if we have already imported it previously. Otherwise
            // create it as a new group.
            //
            group = ImportedGroups.FirstOrDefault(g => g.ForeignKey == groupKey);
            if (group == null)
            {
                group = new Group
                {
                    ForeignKey             = groupKey,
                    ForeignId              = groupId,
                    Name                   = name,
                    CreatedByPersonAliasId = ImportPersonAliasId,
                    GroupTypeId            = groupTypeId,
                    Description            = description
                };

                lookupContext.Groups.Add(group);
                ImportedGroups.Add(group);
            }
            else
            {
                lookupContext.Groups.Attach(group);
                lookupContext.Entry(group).State = EntityState.Modified;
            }

            //
            // Find and set the parent group. If not found it becomes a root level group.
            //
            parent = ImportedGroups.FirstOrDefault(g => g.ForeignKey == parentGroupKey);
            if (parent != null)
            {
                group.ParentGroupId = parent.Id;
            }

            //
            // Setup the date created/modified values from the data, if we have them.
            //
            group.CreatedDateTime  = ParseDateOrDefault(createdDate, ImportDateTime);
            group.ModifiedDateTime = ImportDateTime;

            //
            // Set the active state of this group.
            //
            if (active.ToUpper() == "NO")
            {
                group.IsActive = false;
            }
            else
            {
                group.IsActive = true;
            }

            return(group);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Maps the home group membership data.
        /// </summary>
        /// <param name="tableData">The table data.</param>
        /// <param name="totalRows">The total rows.</param>
        private void MapGroups(IQueryable <Row> tableData, long totalRows = 0)
        {
            var lookupContext        = new RockContext();
            var newGroupMembers      = new List <GroupMember>();
            var importedGroupMembers = lookupContext.GroupMembers.Count(gm => gm.ForeignKey != null && gm.Group.GroupTypeId == GeneralGroupTypeId);
            var groupRoleMember      = GroupTypeCache.Get(GeneralGroupTypeId).Roles.FirstOrDefault(r => r.Name.Equals("Member"));

            var archivedScheduleName = "Archived Attendance";
            var archivedScheduleId   = new ScheduleService(lookupContext).Queryable()
                                       .Where(s => s.Name.Equals(archivedScheduleName, StringComparison.OrdinalIgnoreCase))
                                       .Select(s => ( int? )s.Id).FirstOrDefault();

            if (!archivedScheduleId.HasValue)
            {
                var archivedSchedule = AddNamedSchedule(lookupContext, archivedScheduleName, null, null, null,
                                                        ImportDateTime, archivedScheduleName.RemoveSpecialCharacters(), true, ImportPersonAliasId);
                archivedScheduleId = archivedSchedule.Id;
            }

            var groupsParentName = "Archived Groups";
            var archivedGroups   = ImportedGroups.FirstOrDefault(g => g.ForeignKey.Equals(groupsParentName.RemoveWhitespace()));

            if (archivedGroups == null)
            {
                archivedGroups = AddGroup(lookupContext, GeneralGroupTypeId, null, groupsParentName, true, null, ImportDateTime, groupsParentName.RemoveWhitespace(), true, ImportPersonAliasId);
                ImportedGroups.Add(archivedGroups);
            }

            if (totalRows == 0)
            {
                totalRows = tableData.Count();
            }

            var completedItems = 0;
            var percentage     = (totalRows - 1) / 100 + 1;

            ReportProgress(0, string.Format("Verifying people groups import ({0:N0} found, {1:N0} already exist).", totalRows, importedGroupMembers));

            foreach (var row in tableData.Where(r => r != null))
            {
                var groupId      = row["Group_ID"] as int?;
                var groupName    = row["Group_Name"] as string;
                var individualId = row["Individual_ID"] as int?;
                var groupCreated = row["Created_Date"] as DateTime?;
                var groupType    = row["Group_Type_Name"] as string;

                // require at least a group id and name
                if (groupId.HasValue && !string.IsNullOrWhiteSpace(groupName) && !groupName.Equals("Delete", StringComparison.OrdinalIgnoreCase))
                {
                    var peopleGroup = ImportedGroups.FirstOrDefault(g => g.ForeignKey.Equals(groupId.ToString()));
                    if (peopleGroup == null)
                    {
                        int?campusId           = null;
                        var parentGroupId      = archivedGroups.Id;
                        var currentGroupTypeId = GeneralGroupTypeId;
                        if (!string.IsNullOrWhiteSpace(groupType))
                        {
                            // check for a campus on the grouptype
                            campusId = GetCampusId(groupType, true, SearchDirection.Ends);
                            if (campusId.HasValue)
                            {
                                groupType = StripSuffix(groupType, campusId);
                            }

                            // add the grouptype if it doesn't exist
                            var currentGroupType = ImportedGroupTypes.FirstOrDefault(t => t.ForeignKey.Equals(groupType, StringComparison.OrdinalIgnoreCase));
                            if (currentGroupType == null)
                            {
                                // save immediately so we can use the grouptype for a group
                                currentGroupType = AddGroupType(lookupContext, groupType, string.Format("{0} imported {1}", groupType, ImportDateTime), null,
                                                                null, null, true, true, true, true, typeForeignKey: groupType);
                                ImportedGroupTypes.Add(currentGroupType);
                            }

                            // create a placeholder group for the grouptype if it doesn't exist
                            var groupTypePlaceholder = ImportedGroups.FirstOrDefault(g => g.GroupTypeId == currentGroupType.Id && g.ForeignKey.Equals(groupType.RemoveWhitespace()));
                            if (groupTypePlaceholder == null)
                            {
                                groupTypePlaceholder = AddGroup(lookupContext, currentGroupType.Id, archivedGroups.Id, groupType, true, null, ImportDateTime,
                                                                groupType.RemoveWhitespace(), true, ImportPersonAliasId);
                                ImportedGroups.Add(groupTypePlaceholder);
                            }

                            parentGroupId      = groupTypePlaceholder.Id;
                            currentGroupTypeId = currentGroupType.Id;
                        }

                        // put the current group under a campus parent if it exists
                        campusId = campusId ?? GetCampusId(groupName);
                        if (campusId.HasValue)
                        {
                            // create a campus level parent for the home group
                            var campus      = CampusList.FirstOrDefault(c => c.Id == campusId);
                            var campusGroup = ImportedGroups.FirstOrDefault(g => g.ForeignKey.Equals(campus.ShortCode) && g.ParentGroupId == parentGroupId);
                            if (campusGroup == null)
                            {
                                campusGroup = AddGroup(lookupContext, currentGroupTypeId, parentGroupId, campus.Name, true, campus.Id, ImportDateTime, campus.ShortCode, true, ImportPersonAliasId);
                                ImportedGroups.Add(campusGroup);
                            }

                            parentGroupId = campusGroup.Id;
                        }

                        // add the group, finally
                        peopleGroup = AddGroup(lookupContext, currentGroupTypeId, parentGroupId, groupName, true, campusId, null, groupId.ToString(), true, ImportPersonAliasId, archivedScheduleId);
                        ImportedGroups.Add(peopleGroup);
                    }

                    // add the group member
                    var personKeys = GetPersonKeys(individualId, null);
                    if (personKeys != null)
                    {
                        newGroupMembers.Add(new GroupMember
                        {
                            IsSystem          = false,
                            GroupId           = peopleGroup.Id,
                            PersonId          = personKeys.PersonId,
                            GroupRoleId       = groupRoleMember.Id,
                            GroupMemberStatus = GroupMemberStatus.Active,
                            ForeignKey        = string.Format("Membership imported {0}", ImportDateTime)
                        });

                        completedItems++;
                    }

                    if (completedItems % percentage < 1)
                    {
                        var percentComplete = completedItems / percentage;
                        ReportProgress(percentComplete, string.Format("{0:N0} group members imported ({1}% complete).", completedItems, percentComplete));
                    }

                    if (completedItems % ReportingNumber < 1)
                    {
                        SaveGroupMembers(newGroupMembers);
                        ReportPartialProgress();

                        // Reset lists and context
                        lookupContext = new RockContext();
                        newGroupMembers.Clear();
                    }
                }
            }

            if (newGroupMembers.Any())
            {
                SaveGroupMembers(newGroupMembers);
            }

            lookupContext.Dispose();
            ReportProgress(100, string.Format("Finished people groups import: {0:N0} members imported.", completedItems));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Maps the activity group data.
        /// </summary>
        /// <param name="tableData">The table data.</param>
        /// <param name="totalRows">The total rows.</param>
        private void MapActivityGroup(IQueryable <Row> tableData, long totalRows = 0)
        {
            var lookupContext = new RockContext();
            var newGroups     = new List <Group>();

            if (totalRows == 0)
            {
                totalRows = tableData.Count();
            }

            var archivedScheduleName = "Archived Attendance";
            var archivedScheduleId   = new ScheduleService(lookupContext).Queryable()
                                       .Where(s => s.Name.Equals(archivedScheduleName, StringComparison.OrdinalIgnoreCase))
                                       .Select(s => ( int? )s.Id).FirstOrDefault();

            if (!archivedScheduleId.HasValue)
            {
                var archivedSchedule = AddNamedSchedule(lookupContext, archivedScheduleName, null, null, null,
                                                        ImportDateTime, archivedScheduleName.RemoveSpecialCharacters(), true, ImportPersonAliasId);
                archivedScheduleId = archivedSchedule.Id;
            }

            var completedItems = 0;
            var percentage     = (totalRows - 1) / 100 + 1;

            ReportProgress(0, string.Format("Verifying activity import ({0:N0} found, {1:N0} already exist).", totalRows, ImportedGroups.Count));

            foreach (var row in tableData.Where(r => r != null))
            {
                // get the group data
                var activityId        = row["Activity_ID"] as int?;
                var activityGroupId   = row["Activity_Group_ID"] as int?;
                var superGroupId      = row["Activity_Super_Group_ID"] as int?;
                var activityGroupName = row["Activity_Group_Name"] as string;
                var superGroupName    = row["Activity_Super_Group"] as string;
                var balanceType       = row["CheckinBalanceType"] as string;

                // get the top-level activity group
                if (activityId.HasValue && !activityGroupName.Equals("Delete", StringComparison.OrdinalIgnoreCase))
                {
                    var parentGroup = ImportedGroups.FirstOrDefault(g => g.ForeignKey.Equals(activityId.ToString()));
                    if (parentGroup != null)
                    {
                        // add a level for the super group activity if it exists
                        int?parentGroupId = parentGroup.Id;
                        if (superGroupId.HasValue && !string.IsNullOrWhiteSpace(superGroupName))
                        {
                            var superGroup = ImportedGroups.FirstOrDefault(g => g.ForeignKey.Equals(superGroupId.ToString()));
                            if (superGroup == null)
                            {
                                superGroup = AddGroup(lookupContext, parentGroup.GroupTypeId, parentGroupId, superGroupName, parentGroup.IsActive, parentGroup.CampusId, null, superGroupId.ToString(), true, ImportPersonAliasId, archivedScheduleId);
                                ImportedGroups.Add(superGroup);
                                // set parent guid to super group
                                parentGroupId = superGroup.Id;
                            }
                        }

                        // add the child activity group
                        if (activityGroupId.HasValue && !string.IsNullOrWhiteSpace(activityGroupName))
                        {
                            var activityGroup = ImportedGroups.FirstOrDefault(g => g.ForeignKey.Equals(activityGroupId.ToString()));
                            if (activityGroup == null)
                            {
                                // don't save immediately, we'll batch add later
                                activityGroup = AddGroup(null, parentGroup.GroupTypeId, parentGroupId, activityGroupName, parentGroup.IsActive, parentGroup.CampusId, null, activityGroupId.ToString(), false, ImportPersonAliasId, archivedScheduleId);
                                newGroups.Add(activityGroup);
                            }
                        }

                        // #TODO: if Rock ever supports room balancing, check the F1 BalanceType

                        completedItems++;
                        if (completedItems % percentage < 1)
                        {
                            var percentComplete = completedItems / percentage;
                            ReportProgress(percentComplete, string.Format("{0:N0} activities imported ({1}% complete).", completedItems, percentComplete));
                        }

                        if (completedItems % ReportingNumber < 1)
                        {
                            SaveGroups(newGroups);
                            ReportPartialProgress();
                            ImportedGroups.AddRange(newGroups);

                            // Reset lists and context
                            lookupContext = new RockContext();
                            newGroups.Clear();
                        }
                    }
                }
            }

            if (newGroups.Any())
            {
                SaveGroups(newGroups);
                ImportedGroups.AddRange(newGroups);
            }

            lookupContext.Dispose();
            ReportProgress(100, string.Format("Finished activity group import: {0:N0} activities imported.", completedItems));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Maps the activity ministry data.
        /// </summary>
        /// <param name="tableData">The table data.</param>
        /// <param name="totalRows">The total rows.</param>
        private void MapActivityMinistry(IQueryable <Row> tableData, long totalRows = 0)
        {
            var lookupContext = new RockContext();
            var newGroups     = new List <Group>();

            const string attendanceTypeName = "Attendance History";
            var          groupTypeHistory   = ImportedGroupTypes.FirstOrDefault(t => t.ForeignKey.Equals(attendanceTypeName));

            if (groupTypeHistory == null)
            {
                groupTypeHistory = AddGroupType(lookupContext, attendanceTypeName, string.Format("{0} imported {1}", attendanceTypeName, ImportDateTime), null,
                                                null, GroupTypeCheckinTemplateId, true, true, true, true, typeForeignKey: attendanceTypeName);
                ImportedGroupTypes.Add(groupTypeHistory);
            }

            const string groupsParentName     = "Archived Groups";
            var          archivedGroupsParent = ImportedGroups.FirstOrDefault(g => g.ForeignKey.Equals(groupsParentName.RemoveWhitespace()));

            if (archivedGroupsParent == null)
            {
                archivedGroupsParent = AddGroup(lookupContext, GeneralGroupTypeId, null, groupsParentName, true, null, ImportDateTime, groupsParentName.RemoveWhitespace(), true, ImportPersonAliasId);
                ImportedGroups.Add(archivedGroupsParent);
            }

            if (totalRows == 0)
            {
                totalRows = tableData.Count();
            }

            var completedItems = 0;
            var percentage     = (totalRows - 1) / 100 + 1;

            ReportProgress(0, string.Format("Verifying ministry import ({0:N0} found, {1:N0} already exist).", totalRows, ImportedGroupTypes.Count));

            foreach (var row in tableData.OrderBy(r => r["Ministry_ID"] as int?).ThenBy(r => r["Activity_ID"] as int?))
            {
                // get the ministry data
                var ministryId     = row["Ministry_ID"] as int?;
                var activityId     = row["Activity_ID"] as int?;
                var ministryName   = row["Ministry_Name"] as string;
                var activityName   = row["Activity_Name"] as string;
                var ministryActive = row["Ministry_Active"] as string;
                var activityActive = row["Activity_Active"] as string;
                int?campusId       = null;

                if (ministryId.HasValue && !string.IsNullOrWhiteSpace(ministryName) && !ministryName.Equals("Delete", StringComparison.OrdinalIgnoreCase))
                {
                    // check for a ministry group campus context
                    if (ministryName.Any(n => ValidDelimiters.Contains(n)))
                    {
                        campusId = campusId ?? GetCampusId(ministryName);
                        if (campusId.HasValue)
                        {
                            // strip the campus from the ministry name to use for grouptype (use the original name on groups though)
                            ministryName = StripPrefix(ministryName, campusId);
                        }
                    }

                    // add the new grouptype if it doesn't exist
                    var currentGroupType = ImportedGroupTypes.FirstOrDefault(t => t.ForeignKey.Equals(ministryName));
                    if (currentGroupType == null)
                    {
                        // save immediately so we can use the grouptype for a group
                        currentGroupType = AddGroupType(lookupContext, ministryName, string.Format("{0} imported {1}", ministryName, ImportDateTime), groupTypeHistory.Id,
                                                        null, null, true, true, true, true, typeForeignKey: ministryName);
                        ImportedGroupTypes.Add(currentGroupType);
                    }

                    // create a campus level parent for the ministry group
                    var parentGroupId = archivedGroupsParent.Id;
                    if (campusId.HasValue)
                    {
                        var campus      = CampusList.FirstOrDefault(c => c.Id == campusId);
                        var campusGroup = ImportedGroups.FirstOrDefault(g => g.ForeignKey.Equals(campus.ShortCode) && g.ParentGroupId == parentGroupId);
                        if (campusGroup == null)
                        {
                            campusGroup = AddGroup(lookupContext, GeneralGroupTypeId, parentGroupId, campus.Name, true, campus.Id, ImportDateTime, campus.ShortCode, true, ImportPersonAliasId);
                            ImportedGroups.Add(campusGroup);
                        }

                        parentGroupId = campusGroup.Id;
                    }

                    // add a ministry group level if it doesn't exist
                    var ministryGroup = ImportedGroups.FirstOrDefault(g => g.ForeignKey.Equals(ministryId.ToString()));
                    if (ministryGroup == null)
                    {
                        // save immediately so we can use the group as a parent
                        ministryGroup = AddGroup(lookupContext, currentGroupType.Id, parentGroupId, ministryName, ministryActive.AsBoolean(), campusId, null, ministryId.ToString(), true, ImportPersonAliasId);
                        ImportedGroups.Add(ministryGroup);
                    }

                    // check for an activity group campus context
                    if (!string.IsNullOrWhiteSpace(activityName) && activityName.Any(n => ValidDelimiters.Contains(n)))
                    {
                        campusId = campusId ?? GetCampusId(activityName);
                        if (campusId.HasValue)
                        {
                            activityName = StripPrefix(activityName, campusId);
                        }
                    }

                    // add the child activity group if it doesn't exist
                    var activityGroup = ImportedGroups.FirstOrDefault(g => g.ForeignKey.Equals(activityId.ToString()));
                    if (activityGroup == null && activityId.HasValue && !string.IsNullOrWhiteSpace(activityName) && !activityName.Equals("Delete", StringComparison.OrdinalIgnoreCase))
                    {
                        // don't save immediately, we'll batch add later
                        activityGroup = AddGroup(lookupContext, currentGroupType.Id, ministryGroup.Id, activityName, activityActive.AsBoolean(), campusId, null, activityId.ToString(), false, ImportPersonAliasId);
                        newGroups.Add(activityGroup);
                    }

                    completedItems++;

                    if (completedItems % percentage < 1)
                    {
                        var percentComplete = completedItems / percentage;
                        ReportProgress(percentComplete, string.Format("{0:N0} ministries imported ({1}% complete).", completedItems, percentComplete));
                    }

                    if (completedItems % ReportingNumber < 1)
                    {
                        SaveGroups(newGroups);
                        ReportPartialProgress();
                        ImportedGroups.AddRange(newGroups);

                        // Reset lists and context
                        lookupContext = new RockContext();
                        newGroups.Clear();
                    }
                }
            }

            if (newGroups.Any())
            {
                SaveGroups(newGroups);
                ImportedGroups.AddRange(newGroups);
            }

            lookupContext.Dispose();
            ReportProgress(100, string.Format("Finished ministry import: {0:N0} ministries imported.", completedItems));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Load in the basic group information passed in by the caller. Group is not saved
        /// unless the caller explecitely save the group.
        /// </summary>
        /// <param name="lookupContext">The lookup context.</param>
        /// <param name="groupKey">The group key.</param>
        /// <param name="name">The name.</param>
        /// <param name="createdDate">The created date.</param>
        /// <param name="type">The type.</param>
        /// <param name="parentGroupKey">The parent group key.</param>
        /// <param name="active">The active.</param>
        /// <returns></returns>
        private Group LoadGroupBasic(RockContext lookupContext, string groupKey, string name, string createdDate, string type, string parentGroupKey, string active, string description = "")
        {
            var   groupTypeId = LoadGroupTypeId(lookupContext, type);
            var   groupId = groupKey.AsType <int?>();
            Group group, parent;

            //
            // See if we have already imported it previously. Otherwise
            // create it as a new group.
            //
            group = ImportedGroups.FirstOrDefault(g => g.ForeignKey == groupKey);

            // Check if this was an existing group that needs foreign id added
            if (group == null)
            {
                var parentGroupId = ImportedGroups.FirstOrDefault(g => g.ForeignKey == parentGroupKey)?.Id;
                group = new GroupService(lookupContext).Queryable().Where(g => g.ForeignKey == null && g.GroupTypeId == groupTypeId && g.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && g.ParentGroupId == parentGroupId).FirstOrDefault();
            }

            if (group == null)
            {
                group = new Group
                {
                    ForeignKey             = groupKey,
                    ForeignId              = groupId,
                    Name                   = name,
                    CreatedByPersonAliasId = ImportPersonAliasId,
                    GroupTypeId            = groupTypeId,
                    Description            = description
                };

                lookupContext.Groups.Add(group);
                ImportedGroups.Add(group);
            }
            else
            {
                if (string.IsNullOrWhiteSpace(group.ForeignKey))
                {
                    group.ForeignKey = groupKey;
                    group.ForeignId  = groupId;

                    if (!ImportedGroups.Any(g => g.ForeignKey.Equals(groupKey, StringComparison.OrdinalIgnoreCase)))
                    {
                        ImportedGroups.Add(group);
                    }
                }

                lookupContext.Groups.Attach(group);
                lookupContext.Entry(group).State = EntityState.Modified;
            }

            //
            // Find and set the parent group. If not found it becomes a root level group.
            //
            parent = ImportedGroups.FirstOrDefault(g => g.ForeignKey == parentGroupKey);
            if (parent != null)
            {
                group.ParentGroupId = parent.Id;
            }

            //
            // Setup the date created/modified values from the data, if we have them.
            //
            group.CreatedDateTime  = ParseDateOrDefault(createdDate, ImportDateTime);
            group.ModifiedDateTime = ImportDateTime;

            //
            // Set the active state of this group.
            //
            if (active.ToUpper() == "NO")
            {
                group.IsActive = false;
            }
            else
            {
                group.IsActive = true;
            }

            return(group);
        }