예제 #1
0
            public override void ExecuteEachOrganization(SCObjectSet objectSet, IImportContext context, IDictionary <string, PC.SchemaObjectBase> knownObjects, PC.SCOrganization org, Dictionary <string, IList <PC.SCOrganization> > orgToOrgRelations, Dictionary <string, IList <PC.SCUser> > orgToUserRelations, Dictionary <string, IList <PC.SCGroup> > orgToGroupRelations)
            {
                if (orgToGroupRelations.ContainsKey(org.ID))
                {
                    var groups = orgToGroupRelations[org.ID];

                    if (groups.Count > 0)
                    {
                        context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在查找 {0} 中的群组", org.ToDescription()));
                    }

                    for (int i = 0; i < groups.Count; i++)
                    {
                        var group = groups[i];
                        try
                        {
                            context.SetSubStatusAndLog(i + 1, groups.Count, string.Format("正在向组织 {0} 添加群组 {1}", org.Name, group.Name));

                            PC.Executors.SCObjectOperations.Instance.AddGroup(group, org);

                            knownObjects.Add(group.ID, group);

                            this.DoImportMembers(objectSet, context, knownObjects, group);

                            this.DoImportConditions(objectSet, context, group);
                        }
                        catch (Exception ex)
                        {
                            context.AppendLog(string.Format("向组织 {0} 导入群组 {1} 时出错:", org.ToDescription(), group.Name, ex.ToString()));
                        }
                    }
                }
            }
예제 #2
0
            public override void ExecuteEachOrganization(SCObjectSet objectSet, IImportContext context, IDictionary <string, PC.SchemaObjectBase> knownObjects, PC.SCOrganization org, Dictionary <string, IList <PC.SCOrganization> > orgToOrgRelations, Dictionary <string, IList <PC.SCUser> > orgToUserRelations, Dictionary <string, IList <PC.SCGroup> > orgToGroupRelations)
            {
                if (objectSet.HasAcls)
                {
                    context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在寻找 {0} 的ACL。", org.ToDescription()));

                    var allAcls = ImportService.Instance.FilterAcls(objectSet.Acls, acl => acl.ContainerID == org.ID && acl.Status == SchemaObjectStatus.Normal).ToList();

                    var summaryName = org.ToDescription();

                    try
                    {
                        var newContainer = new PC.Permissions.SCAclContainer(org);

                        foreach (var acl in allAcls)
                        {
                            ImportService.Instance.WithEffectObject <PC.SchemaObjectBase>(acl.MemberID, knownObjects, role =>
                            {
                                newContainer.Members.Add(acl.ContainerPermission, role);
                            }, null);
                        }

                        var oldMembers = PC.Adapters.SCAclAdapter.Instance.LoadByContainerID(org.ID, DateTime.MinValue);

                        if (oldMembers != null)
                        {
                            newContainer.Members.MergeChangedItems(oldMembers);
                        }

                        context.SetStatusAndLog(Owner.currentSteps, Owner.allSteps, string.Format("正在替换 {0} 的ACL:", summaryName));

                        PC.Adapters.SCAclAdapter.Instance.Update(newContainer);
                    }
                    catch (Exception ex)
                    {
                        context.AppendLogFormat("对象 {0} 的ACL操作失败,原因是:{1}\r\n", summaryName, ex.Message);
                    }
                }
            }
예제 #3
0
            public override void ExecuteEachOrganization(SCObjectSet objectSet, IImportContext context, IDictionary <string, PC.SchemaObjectBase> knownObjects, PC.SCOrganization org, Dictionary <string, IList <PC.SCOrganization> > orgToOrgRelations, Dictionary <string, IList <PC.SCUser> > orgToUserRelations, Dictionary <string, IList <PC.SCGroup> > orgToGroupRelations)
            {
                if (orgToUserRelations.ContainsKey(org.ID))
                {
                    var users = orgToUserRelations[org.ID];

                    if (users.Count > 0)
                    {
                        context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在查找 {0} 中的用户", org.ToDescription()));
                    }

                    for (int i = 0; i < users.Count; i++)
                    {
                        var user = users[i];
                        try
                        {
                            if (this.importedUsers.ContainsKey(user.ID) == false)
                            {
                                context.SetSubStatusAndLog(i + 1, users.Count, string.Format("正在向组织 {0} 导入用户 {1}", org.Name, user.Name));

                                PC.Executors.SCObjectOperations.Instance.AddUser(user, org);
                                this.importedUsers.Add(user.ID, user);

                                if (knownObjects.ContainsKey(user.ID) == false)
                                {
                                    knownObjects.Add(user.ID, user);
                                }
                            }
                            else
                            {
                                context.SetSubStatusAndLog(i + 1, users.Count, string.Format("正在向组织 {0} 添加用户 {1}", org.Name, user.Name));
                                PC.Executors.SCObjectOperations.Instance.AddUserToOrganization(user, org);

                                if (knownObjects.ContainsKey(user.ID) == false)
                                {
                                    knownObjects.Add(user.ID, user);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            context.AppendLog(string.Format("向组织 {0} 导入用户 {1} 时出错:", org.Name, user.Name, ex.ToString()));
                        }
                    }
                }
            }