Esempio n. 1
0
        private void DoMoveToOrg(string orgKey, List <string> groupKeys, IList <object> errors)
        {
            try
            {
                PC.SCOrganization org = (PC.SCOrganization)DbUtil.GetEffectiveObject(orgKey, string.Format("指定的组织(ID:{0})无效", orgKey));
                var grps = DbUtil.LoadObjects(groupKeys.ToArray());

                foreach (PC.SCBase item in grps)
                {
                    try
                    {
                        if (item is PC.SCGroup && item.Status == SchemaObjectStatus.Normal)
                        {
                            PC.Executors.SCObjectOperations.InstanceWithPermissions.MoveObjectToOrganization(null, item, org);
                        }
                        else
                        {
                            errors.Add(string.Format("{0}不是有效的群组,已跳过", item.ToDescription()));
                        }
                    }
                    catch (Exception ex)
                    {
                        WebUtility.ShowClientError(ex);
                        errors.Add(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                WebUtility.ShowClientError(ex);
                errors.Add(ex);
            }

            this.InnerRefreshList();             // 必须的
        }
Esempio n. 2
0
        private void ImportRoleMembers(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations executor, Dictionary <object, object> mappings, PC.SCRole[] roles)
        {
            if (roles.Length > 0)
            {
                foreach (var r in roles)
                {
                    PC.SCRole role2 = r;
                    if (mappings.ContainsKey(r))
                    {
                        role2 = (PC.SCRole)mappings[r];
                    }

                    // 查找角色成员
                    var roleMemberIds = (from m in objectSet.Membership where m.ContainerSchemaType == "Roles" && m.ContainerID == r.ID select m.ID).ToArray();
                    if (roleMemberIds.Length > 0)
                    {
                        var roleMembers = DbUtil.LoadObjects(roleMemberIds);
                        foreach (PC.SCBase obj in roleMembers)
                        {
                            context.AppendLog("正在导入角色成员" + obj.DisplayName ?? obj.Name);
                            executor.AddMemberToRole(obj, role2);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private static void DeleteProgressNextStepDestroyUsers(PostProgressDoPostedDataEventArgs e, SCOrganization parent)
        {
            (e.Steps.Count > 0).FalseThrow <InvalidOperationException>("没有选择要删除的对象");

            var objectsToDelete = DbUtil.LoadObjects((from string id in e.Steps select id).ToArray());

            ProcessProgress.Current.Output.WriteLine("准备执行操作");
            PC.Executors.SCObjectOperations.InstanceWithPermissions.DeleteObjectsRecursively(objectsToDelete, parent);
            ProcessProgress.Current.Output.WriteLine("准备删除当前级别选定的人员……");

            foreach (var item in objectsToDelete)
            {
                if (item is PC.SCUser)
                {
                    try
                    {
                        PC.Executors.SCObjectOperations.InstanceWithPermissions.DeleteUser((PC.SCUser)item, null, false);
                        ProcessProgress.Current.Output.WriteLine("已删除用户{0}(ID:{1})", ((PC.SCUser)item).Name, item.ID);;
                    }
                    catch (Exception ex)
                    {
                        ProcessProgress.Current.Output.WriteLine("删除用户{0}(ID:{1})时发生错误:{2}", ((PC.SCUser)item).Name, item.ID, ex.ToString());;
                    }
                }
            }

            ProcessProgress.Current.Output.WriteLine("完毕");

            e.Result.CloseWindow = false;
            e.Result.ProcessLog  = ProcessProgress.Current.GetDefaultOutput();
        }
Esempio n. 4
0
        private void ProcessSubmit(HttpContext context)
        {
            string[] ids      = context.Request.Form.GetValues("ids");
            string   pptValue = context.Request.Form.Get("properties");
            var      output   = context.Response.Output;

            context.Response.Buffer = false;

            try
            {
                if (TimePointContext.Current.UseCurrentTime == false)
                {
                    throw new ApplicationException("只运行在“现在”时间上下文进行操作。");
                }

                if (ids != null && pptValue != null)
                {
                    PropertyValueCollection values = JSONSerializerExecute.Deserialize <PropertyValueCollection>(pptValue);

                    var objects = DbUtil.LoadObjects(ids);
                    for (int i = 0; i < ids.Length; i++)
                    {
                        ResponsePreparing(i, output);
                        if (objects.ContainsKey(ids[i]) == false)
                        {
                            ResponseNotFound(i, output);
                        }
                        else
                        {
                            var obj = objects[ids[i]];
                            try
                            {
                                foreach (var item in values)
                                {
                                    obj.Properties[item.Definition.Name].StringValue = item.StringValue;
                                }

                                PC.Executors.SCObjectOperations.InstanceWithPermissions.DoOperation(SCObjectOperationMode.Update, obj, null);

                                ResponseDone(i, output);
                            }
                            catch (Exception ex)
                            {
                                ResponseError(i, output, ex.Message, ex.StackTrace);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WebUtility.ShowClientError(ex.GetRealException());
            }
            finally
            {
                ResponseFinished(output);
                output.Flush();
            }
        }
Esempio n. 5
0
        private static void DeleteProgressNextStep(PostProgressDoPostedDataEventArgs e, SCOrganization parent)
        {
            (e.Steps.Count > 0).FalseThrow <InvalidOperationException>("没有选择要删除的对象");

            var objectsToDelete = DbUtil.LoadObjects((from string id in e.Steps select id).ToArray());

            ProcessProgress.Current.Output.WriteLine("准备执行操作");
            PC.Executors.SCObjectOperations.InstanceWithPermissions.DeleteObjectsRecursively(objectsToDelete, parent);
            ProcessProgress.Current.Output.WriteLine("完毕");

            e.Result.CloseWindow = false;
            e.Result.ProcessLog  = ProcessProgress.Current.GetDefaultOutput();
        }
Esempio n. 6
0
        /// <summary>
        /// 获取可用的操作类型
        /// </summary>
        /// <param name="keys"></param>
        /// <returns><see cref="TransferObjectType"/>的组合值</returns>
        internal static TransferObjectType GetAvailableOperation(string[] keys)
        {
            TransferObjectType result = TransferObjectType.None;

            if (keys != null)
            {
                var  relations    = DbUtil.LoadCurrentParentRelations(keys, SchemaInfo.FilterByCategory("Organizations").ToSchemaNames());
                bool existRootOrg = false;

                foreach (var r in relations)
                {
                    if (Util.IsOrganization(r.ChildSchemaType) && r.ParentID == PC.SCOrganization.RootOrganizationID)
                    {
                        existRootOrg = true; // 一级组织原则上不允许转移,如果含有一级组织,则什么都做不成
                        break;
                    }
                }

                if (existRootOrg == false)
                {
                    foreach (var item in DbUtil.LoadObjects(keys))
                    {
                        if (item is SCUser)
                        {
                            result |= TransferObjectType.Members;
                        }
                        else if (item is SCGroup)
                        {
                            result |= TransferObjectType.Groups;
                        }
                        else if (item is SCOrganization)
                        {
                            result |= TransferObjectType.Orgnizations;
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 7
0
        private void ImportRoleDefinitions(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, int count, int allCount, PC.SCRole role, PC.SCRole role2)
        {
            context.SetStatus(count, allCount, "正在查找并添加角色功能定义");
            context.AppendLogFormat("正在替 {0} 查找角色功能定义\r\n", role2.ToDescription());
            var permissionIds = (from p in objectSet.Relations where p.ParentID == role.ID && p.ChildSchemaType == "Permissions" select p.ID).ToArray();

            var permissions = permissionIds.Length > 0 ? DbUtil.LoadObjects(permissionIds) : null;

            if (permissions != null)
            {
                foreach (PC.SCPermission p in permissions)
                {
                    var relation = PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(role.ID, p.ID);
                    if (relation == null || relation.Status != SchemaObjectStatus.Normal)
                    {
                        string text = string.Format("正在替角色 {0} 指定功能 {1}\r\n", role.DisplayName ?? role.Name, p.DisplayName ?? p.Name);
                        context.SetStatus(count, allCount, text);
                        context.AppendLog(text);
                        exec.JoinRoleAndPermission(role, (PC.SCPermission)p);
                    }
                }
            }
        }
Esempio n. 8
0
        protected override void ValidateObjects()
        {
            WhereSqlClauseBuilder bd = new WhereSqlClauseBuilder();

            bd.AppendItem("Status", (int)SchemaObjectStatus.Normal);

            InSqlClauseBuilder inB = new InSqlClauseBuilder("ObjectID");

            inB.AppendItem(this.SourceKeys);

            InSqlClauseBuilder inC = new InSqlClauseBuilder("ParentSchemaType");

            inC.AppendItem(SchemaInfo.FilterByCategory("Organizations").ToSchemaNames());

            InSqlClauseBuilder inD = new InSqlClauseBuilder("Groups");

            inC.AppendItem(SchemaInfo.FilterByCategory("Groups").ToSchemaNames());

            this.relations = SchemaRelationObjectAdapter.Instance.Load(new ConnectiveSqlClauseCollection(bd, inB, inC, inD, VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder()), DateTime.MinValue);
            this.parents   = DbUtil.LoadObjects(this.relations.ToParentIDArray());

            base.ValidateObjects();
        }
Esempio n. 9
0
        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);
            this.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            PropertyEditorHelper.AttachToPage(this);
            if (this.IsPostBack == false && this.IsCallback == false)
            {
                string[] ids = Request.Params.GetValues("ids");
                if (ids != null)
                {
                    this.objNum.InnerText = ids.Length.ToString();
                    var objects = DbUtil.LoadObjects(ids);
                    HashSet <string> schemaTypes = GetSchemaTypes(objects);
                    HashSet <string> groupNames  = GetCommonGroups(schemaTypes);
                    List <SchemaPropertyDefineConfigurationElement> propertyDefines = GetPropertyDefines(groupNames);
                    SchemaPropertyValueCollection propertyValues = GetCommonValues(objects, propertyDefines);

                    HashSet <string> tabNames = GetTabNames(propertyDefines);
                    RenderTabs(schemaTypes, propertyValues, tabNames);

                    this.ViewState["ids"]         = ids;
                    this.ViewState["schemaTypes"] = schemaTypes;
                    this.objectDetails.Value      = JSONSerializerExecute.Serialize(objects);
                }
            }
            else
            {
                HashSet <string> schemaTypes = this.ViewState["schemaTypes"] as HashSet <string>;
                if (schemaTypes != null)
                {
                    HashSet <string> groupNames = GetCommonGroups(schemaTypes);
                    List <SchemaPropertyDefineConfigurationElement> propertyDefines = GetPropertyDefines(groupNames);
                }
            }
        }
Esempio n. 10
0
        public override SCObjectSet Execute(HttpRequest req)
        {
            string parentId = req.Form["ParentId"];

            if (string.IsNullOrEmpty(parentId))
            {
                throw new HttpException("当获取深度组织机构对象时,必须提供ParentId参数");
            }

            PC.SCOrganization parentObj = parentId == PC.SCOrganization.RootOrganizationID ? PC.SCOrganization.GetRoot() : (PC.SCOrganization)PC.Adapters.SchemaObjectAdapter.Instance.Load(parentId);
            if (parentObj == null || parentObj.Status != SchemaObjectStatus.Normal)
            {
                throw new HttpException("指定的父级对象不存在或者已删除");
            }

            List <string> ids;

            string[] requestIds = req.Form.GetValues("id");
            if (requestIds == null || requestIds.Length == 0)
            {
                PC.SCSimpleRelationObjectCollection allChildren = PC.Adapters.SchemaRelationObjectAdapter.Instance.LoadAllChildrenRelationsRecursively(parentObj);
                ids = new List <string>(allChildren.Count);
                allChildren.ForEach(so => ids.Add(so.ID));
            }
            else
            {
                PC.SCSimpleRelationObjectCollection allChildren = new PC.SCSimpleRelationObjectCollection();
                ids = new List <string>();

                var directRelations = ExportQueryHelper.LoadRelations(parentId, requestIds);

                foreach (var item in directRelations)
                {
                    ids.Add(item.ID);
                }

                var selectedObjects = DbUtil.LoadObjects(ids.ToArray());
                foreach (var item in selectedObjects)
                {
                    var subRelations = PC.Adapters.SchemaRelationObjectAdapter.Instance.LoadAllChildrenRelationsRecursively(item);
                    subRelations.ForEach(m => ids.Add(m.ID));
                }
            }

            SCObjectSet set = new SCObjectSet();

            if (ids.Count > 0)
            {
                set.Objects = DbUtil.LoadObjects(ids.ToArray());
                set.Objects.Distinct((m, n) => m.ID == n.ID);

                var objIds = set.Objects.ToIDArray();

                set.Relations = ExportQueryHelper.LoadFullRelations(objIds);
                set.Relations.Distinct((a, b) => a.ID == b.ID && a.ParentID == b.ParentID);

                set.Membership = ExportQueryHelper.LoadFullMemberships(objIds);
                set.Membership.Distinct((a, b) => a.ID == b.ID && a.ContainerID == b.ContainerID);

                set.Acls = ExportQueryHelper.LoadAclsFor(objIds);

                set.Conditions = ExportQueryHelper.LoadConditions(objIds);
            }

            set.Scope = "OguFull";
            return(set);
        }