コード例 #1
0
        protected CUserEntity CreateUser(CUserEntity newUser)
        {
            try
            {
                COrganizeEntity organize = new COrganizeEntity(ConnString).Load(Usr_Organize);

                // create resource for user's folder
                CResourceEntity folderRes = new CResourceEntity(ConnString);
                folderRes.Res_Name   = "";
                folderRes.Res_Parent = organize.Org_Resource;
                folderRes.Res_Type   = (int)RESOURCETYPE.FOLDERRESOURCE;
                folderRes.Res_Id     = folderRes.Insert();

                folderRes.Res_Name = folderRes.Res_Id.ToString() + newUser.Usr_Member;
                folderRes.Update();

                // create user's folder
                String userPath = folderRes.MakeFullPath();
                Directory.CreateDirectory(userPath);

                // create user
                newUser.Usr_Resource = folderRes.Res_Id;
                newUser.ConnString   = ConnString;
                newUser.Usr_Id       = newUser.Insert();
                return(newUser);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
コード例 #2
0
        public void CutResource(int srcResId, int dstResId)
        {
            // copy resource
            CACLEntity acl = new CACLEntity(ConnString);

            acl.Acl_Resource  = srcResId;
            acl.Acl_Operation = (int)ACLOPERATION.WRITE;
            if (!CheckPrivilege(acl))
            {
                throw new Exception("没有写权限!");
            }
            acl.Acl_Resource  = dstResId;
            acl.Acl_Operation = (int)ACLOPERATION.WRITE;
            if (!CheckPrivilege(acl))
            {
                throw new Exception("没有写权限!");
            }

            CResourceEntity srcRes  = new CResourceEntity(ConnString).Load(srcResId);
            CResourceEntity dstRes  = new CResourceEntity(ConnString).Load(dstResId);
            String          srcPath = srcRes.MakeFullPath();

            if (dstRes.Res_Type != (int)RESOURCETYPE.FOLDERRESOURCE)
            {
                throw new Exception("粘贴的目标必须是目录!");
            }
            srcRes.MoveTo(dstRes);

            // cut folder/file
            String dstPath = dstRes.MakeFullPath();

            dstPath = Path.Combine(dstPath, srcRes.Res_Name);
            if (Directory.Exists(dstPath) || File.Exists(dstPath))
            {
                throw new Exception(dstPath + "与现有文件名冲突!");
            }
            if (srcRes.Res_Type == (int)RESOURCETYPE.FILERESOURCE)
            {
                File.Move(srcPath, dstPath);
            }
            else
            {
                Directory.Move(srcPath, dstPath);
            }
        }
コード例 #3
0
        // return new resource id
        public CResourceEntity CreateFile(int parentId, String fileName, out String filePath)
        {
            CACLEntity acl = new CACLEntity();

            acl.Acl_Resource  = parentId;
            acl.Acl_Operation = (int)ACLOPERATION.WRITE;
            if (!CheckPrivilege(acl))
            {
                throw new Exception("没有写权限");
            }

            // create folder
            CResourceEntity parent = new CResourceEntity(MidLayerSettings.ConnectionString).Load(parentId);

            if (parent == null)
            {
                throw new Exception("无法找到资源. ID=" + parentId);
            }

            String path = parent.MakeFullPath();

            if (!Directory.Exists(path))
            {
                throw new Exception("目录不存在: " + path);
            }
            path = Path.Combine(path, fileName);
            if (Directory.Exists(path) || File.Exists(path))
            {
                throw new Exception("名称冲突: " + path);
            }

            filePath = path;

            // create resource
            CResourceEntity res = new CResourceEntity(ConnString);

            res.Res_Name = fileName;
            res.Res_Type = (int)RESOURCETYPE.FILERESOURCE;
            parent.CreateChildResource(res);
            return(res);
        }
コード例 #4
0
        public override void Delete()
        {
            // delete all its acls
            String filter = "this.Acl_Creator=" + Usr_Id;

            new CACLEntity(ConnString).Delete(filter);

            filter = "this.Acl_Role=" + Usr_Id + " and this.Acl_RType=" + (int)ACLROLETYPE.USERROLE;
            new CACLEntity(ConnString).Delete(filter);

            // delete from all groups
            filter = "this.Urg_User=" + Usr_Id;
            new CUserGroupEntity(ConnString).Delete(filter);

            // delete all its resources
            CResourceEntity userDir = new CResourceEntity(ConnString).Load(Usr_Resource);
            String          path    = userDir.MakeFullPath();

            Directory.Delete(path, true);

            base.Delete();
        }
コード例 #5
0
        /// <summary>
        /// 更新文件——赵英武
        /// </summary>
        /// <param name="resId"></param>
        /// <param name="fileName"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public CResourceEntity UpdateFile(int resId, String fileName, out String filePath)
        {
            CACLEntity acl = new CACLEntity();

            acl.Acl_Resource  = resId;
            acl.Acl_Operation = (int)ACLOPERATION.WRITE;
            if (!CheckPrivilege(acl))
            {
                throw new Exception("没有写权限");
            }

            CResourceEntity res  = new CResourceEntity().Load(resId);
            string          path = res.MakeFullPath();

            if (!System.IO.File.Exists(path))
            {
                throw new Exception("要更新的文件不存在!");
            }

            filePath     = path;
            res.Res_Name = fileName;
            res.Update();
            return(res);
        }