Exemplo n.º 1
0
        private void ImportOneGroup(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, SchemaObjectCollection parentObjects, SchemaObjectCollection memberObjects, int allCount, int count, SchemaObjectBase grp)
        {
            if (grp.SchemaType == "Groups")
            {
                try
                {
                    var summaryName = grp.Properties.GetValue <string>("Name", "未命名");
                    context.SetStatus(count, allCount, "正在导入对象:" + summaryName);

                    if (this.IncludeSelf)
                    {
                        SCRelationObject parentOrgRelation = (SCRelationObject)objectSet.Relations.Find(m => ((SCRelationObject)m).ParentSchemaType == "Organizations" && ((SCRelationObject)m).ChildSchemaType == "Groups" && ((SCRelationObject)m).ID == grp.ID);
                        if (parentOrgRelation == null)
                        {
                            throw new HttpException("未找到群组的父级组织");
                        }

                        var parentOrg = (SCOrganization)(parentObjects != null ? (from p in parentObjects where p.ID == parentOrgRelation.ParentID select p).FirstOrDefault() : null);
                        if (parentOrg == null || parentOrg.Status != SchemaObjectStatus.Normal)
                        {
                            throw new HttpException("群组的父级组织不存在或者已删除,未能导入群组。");
                        }

                        exec.AddGroup((SCGroup)grp, parentOrg);

                        context.AppendLog("已执行导入对象" + summaryName);
                    }

                    ImportMembers(objectSet, context, exec, memberObjects, grp);

                    ImportConditions(objectSet, context, grp);
                }
                catch (Exception ex)
                {
                    context.AppendLog("对项的操作失败,原因是:" + ex.Message);
                }
            }
            else
            {
                context.AppendLog("已跳过不是群组的项");
            }
        }