Exemplo n.º 1
0
        private bool ExtractSOARoleMatrixRows(SOARole innerRole, SOARolePropertyRowCollection extractedRows)
        {
            bool extracted = false;

            SOARoleContext.DoAction(innerRole, SOARoleContext.CurrentProcess, (context) =>
            {
                SOARolePropertyRowCollection subRows = innerRole.Rows.Query(context.QueryParams);

                if (this.Role != null)
                {
                    if (((SOARole)this.Role).MatrixType == WfMatrixType.ActivityMatrix && innerRole.MatrixType != WfMatrixType.ActivityMatrix)
                    {
                        subRows = MergeActivityRowPropertiesByRows(subRows);
                    }

                    foreach (SOARolePropertyRow subRow in subRows)
                    {
                        SOARolePropertyRowCollection subExtractedRows = subRow.ExtractMatrixRows();

                        extractedRows.CopyFrom(subExtractedRows);
                    }
                }

                extracted = true;
            });

            return(extracted);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 转换为OpenXml的WorkBook
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        public static WorkBook ToExcelWorkBook(this SOARole role)
        {
            role.NullCheck("role");

            WorkBook workBook = WorkBook.CreateNew();

            FillFileInfo(workBook, role);

            WorkSheet workSheet = workBook.Sheets[WorkBook.DefaultSheetName];

            workSheet.Name = "Matrix";

            Row titleRow = new Row(1)
            {
                Height = 30d
            };

            titleRow.Style.Fill.SetBackgroundColor(Color.LightGray, ExcelFillStyle.Solid);
            titleRow.Style.Font.Size = 20;
            workSheet.Rows.Add(titleRow);

            workSheet.Cells[titleRow.Index, 1].Value = "角色属性";

            CreateHeaderRow(role, workSheet);

            FillSheetData(role, workSheet);

            return(workBook);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 得到OperationType为Role的角色信息
        /// </summary>
        /// <returns></returns>
        public SOARolePropertyRowRolesCollection GenerateRowsRolesDirectly()
        {
            SOARolePropertyRowRolesCollection result = new SOARolePropertyRowRolesCollection();

            foreach (SOARolePropertyRow row in this)
            {
                if (row.OperatorType == SOARoleOperatorType.Role)
                {
                    SOARolePropertyRowRoles rowRoles = new SOARolePropertyRowRoles(row);

                    //不考虑动态角色
                    if (rowRoles.Row.Operator.IndexOf(":") >= 0)
                    {
                        SOARole role = new SOARole(rowRoles.Row.Operator);

                        ExceptionHelper.DoSilentAction(() =>
                        {
                            //尝试读取一下,如果没有角色则吃掉异常
                            Trace.WriteLine(role.CodeName);

                            rowRoles.Roles.Add(role);
                        });
                    }

                    result.Add(rowRoles);
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据流程和角色创建SOARoleContext
        /// </summary>
        /// <param name="role"></param>
        /// <param name="process"></param>
        /// <returns></returns>
        public static SOARoleContext CreateContext(IRole role, IWfProcess process)
        {
            role.NullCheck("role");

            SOARole soaRole = (SOARole)SOARole.CreateWrapperObject(role);

            return(CreateContext(soaRole.PropertyDefinitions, process));
        }
Exemplo n.º 5
0
        private static void FillRoleUsers(string roleName, OguDataCollection <IUser> users)
        {
            SOARole role = new SOARole(roleName);

            WfRoleResourceDescriptor roleResource = new WfRoleResourceDescriptor(role);

            roleResource.FillUsers(users);
        }
Exemplo n.º 6
0
        public new static IRole CreateWrapperObject(IRole role)
        {
            IRole result = role;

            if (role is SOARole == false)
                result = new SOARole(role);

            return result;
        }
Exemplo n.º 7
0
 private static void FillFileInfo(WorkBook workBook, SOARole role)
 {
     try
     {
         workBook.FileDetails.Title   = role.Name;
         workBook.FileDetails.Subject = role.FullCodeName;
     }
     catch (System.Exception)
     {
     }
 }
Exemplo n.º 8
0
        public new static IRole CreateWrapperObject(IRole role)
        {
            IRole result = role;

            if (role is SOARole == false)
            {
                result = new SOARole(role);
            }

            return(result);
        }
Exemplo n.º 9
0
 private static void FillFileInfo(WorkBook workBook, SOARole role)
 {
     try
     {
         workBook.FileDetails.Title = role.Name;
         workBook.FileDetails.Subject = role.FullCodeName;
     }
     catch (System.Exception)
     {
     }
 }
        /// <summary>
        /// 根据roleID加载角色矩阵。role参数可以为空
        /// </summary>
        /// <param name="roleID"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public SOARolePropertyRowCollection LoadByRoleID(string roleID, IRole role)
        {
            roleID.CheckStringIsNullOrEmpty("roleID");

            if (role == null)
            {
                role = new SOARole()
                {
                    ID = roleID
                }
            }
            ;

            SOARolePropertyDefinitionCollection definition = SOARolePropertyDefinitionAdapter.Instance.GetByRoleID(roleID);

            return(LoadByRoleID(roleID, role, definition));
        }
		public void ProcessRequest(HttpContext context)
		{
			string roleID = context.Request["roleID"];
			if (string.IsNullOrEmpty(context.Request["roleID"]) == false)
			{
				SOARole role = new SOARole() { ID = roleID };

				SOARolePropertyDefinitionCollection rowsColl = SOARolePropertyDefinitionAdapter.Instance.LoadByRole(role);

				XDocument rolePropertiesDoc = new XDocument(new XDeclaration("1.0", "utf-8", "true"), new XElement("SOARoleProperties"));

				XElementFormatter formatter = new XElementFormatter();

				formatter.OutputShortType = false;

				XElement xeRoleProperties = formatter.Serialize(rowsColl);

				rolePropertiesDoc.Element("SOARoleProperties").Add(xeRoleProperties);

				context.Response.Clear();
				context.Response.ContentType = "text/xml";
				context.Response.ContentEncoding = Encoding.UTF8;

				string fileName = string.Empty;

				if (context.Request["roleName"].IsNotEmpty())
					fileName = string.Format("{0}", context.Request["roleName"]);

				if (fileName.IsNullOrEmpty() && context.Request["roleCode"].IsNotEmpty())
					fileName = string.Format("{0}", context.Request["roleCode"]);

				if (fileName.IsNullOrEmpty())
					fileName = roleID;

				fileName += "_Properties";

				context.Response.AppendHeader("content-disposition", string.Format("attachment;fileName={0}.xml", context.Response.EncodeFileNameInContentDisposition(fileName)));
				rolePropertiesDoc.Save(context.Response.OutputStream);
				context.Response.End();
			}
		}
Exemplo n.º 12
0
        private static void FillSheetData(SOARole role, WorkSheet ws)
        {
            int rowIndex = 4;
            SOARolePropertyRowCollection rows = SOARolePropertiesAdapter.Instance.LoadByRole(role, role.PropertyDefinitions);

            foreach (SOARolePropertyRow row in rows)
            {
                foreach (DefinedName name in ws.Names)
                {
                    SOARolePropertyValue propertyValue = row.Values.FindByColumnName(name.Name);

                    string dataValue = null;

                    if (propertyValue != null)
                    {
                        dataValue = propertyValue.Value;
                    }
                    else
                    {
                        switch (name.Name.ToLower())
                        {
                        case "operatortype":
                            dataValue = row.OperatorType.ToString();
                            break;

                        case "operator":
                            dataValue = row.Operator;
                            break;
                        }
                    }

                    if (dataValue != null)
                    {
                        ws.Cells[rowIndex, name.Address.StartColumn].Value = dataValue;
                    }
                }

                rowIndex++;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 展开内部角色的行
        /// </summary>
        /// <param name="innerRole"></param>
        /// <param name="extractedRows"></param>
        /// <returns></returns>
        private bool ExtractSOARoleRows(SOARole innerRole, SOARolePropertyRowCollection extractedRows)
        {
            bool extracted = false;

            if (innerRole.PropertyDefinitions.Count > 0)
            {
                SOARoleContext originalContext = SOARoleContext.Current;
                SOARoleContext.Current = null;
                try
                {
                    using (SOARoleContext innerContext = SOARoleContext.CreateContext(innerRole, originalContext.Process))
                    {
                        extracted = this.ExtractSOARoleMatrixRows(innerRole, extractedRows);
                    }
                }
                finally
                {
                    SOARoleContext.Current = originalContext;
                }
            }

            return(extracted);
        }
Exemplo n.º 14
0
        private static void CreateHeaderRow(SOARole role, WorkSheet ws)
        {
            Row headRow = new Row(3);

            headRow.Style.Fill.SetBackgroundColor(Color.Gold, ExcelFillStyle.Solid);
            headRow.Style.Border.Top.Style = ExcelBorderStyle.Thin;
            headRow.Style.Border.Top.Color.SetColor(Color.Black);
            headRow.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
            headRow.Style.Border.Bottom.Color.SetColor(Color.Black);
            headRow.Style.Border.Left.Style = ExcelBorderStyle.Thin;
            headRow.Style.Border.Left.Color.SetColor(Color.Black);
            headRow.Style.Font.Bold = true;
            ws.Rows.Add(headRow);

            int columnIndex = 1;

            foreach (SOARolePropertyDefinition dimension in role.PropertyDefinitions)
            {
                ws.Cells[headRow.Index, columnIndex].Value = dimension.Description.IsNotEmpty() ? dimension.Description : dimension.Name;
                ws.Names.Add(CellAddress.Parse(columnIndex, headRow.Index).ToString(), dimension.Name);

                columnIndex++;
            }
        }
        /// <summary>
        /// 上传属性定义
        /// </summary>
        /// <param name="file"></param>
        /// <param name="result"></param>
        protected void ImportSOARole_DoUploadProgress(HttpPostedFile file, UploadProgressResult result)
        {
            var fileType = Path.GetExtension(file.FileName).ToLower();

            if (string.Compare(fileType, ".xml", true) == 0)
            {
                StringBuilder logger = new StringBuilder();
                try
                {
                    CheckEditMode();

                    var xmlDoc = XDocument.Load(file.InputStream);
                    var wfProcesses = xmlDoc.Descendants("Root");
                    XElementFormatter formatter = new XElementFormatter();
                    UploadProgressStatus status = new UploadProgressStatus();

                    status.CurrentStep = 1;
                    status.MinStep = 0;
                    status.MaxStep = wfProcesses.Count() + 1;
                    logger.AppendFormat("开始导入角色属性定义...\n", file.FileName, status.MaxStep);

                    SOARole role = new SOARole { ID = this.DefinitionID };

                    SOARolePropertyDefinitionAdapter.Instance.Delete(role);

                    foreach (var wfProcess in wfProcesses)
                    {
                        SOARolePropertyDefinitionCollection rowsColl = (SOARolePropertyDefinitionCollection)formatter.Deserialize(wfProcess);

                        SOARolePropertyDefinitionAdapter.Instance.Update(role, rowsColl);

                        logger.Append("保存成功...\n");

                        status.CurrentStep++;
                        status.Response();
                    }
                    logger.AppendFormat("导入完成!", file.FileName);
                }
                catch (Exception ex)
                {
                    logger.AppendFormat("导入错误,{0},错误堆栈:{1}", ex.Message, ex.StackTrace);
                }

                result.DataChanged = true;
                result.CloseWindow = false;
                result.ProcessLog = logger.ToString();
            }
        }
        /// <summary>
        /// 根据roleID加载角色矩阵。role参数可以为空
        /// </summary>
        /// <param name="roleID"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public SOARolePropertyRowCollection LoadByRoleID(string roleID, IRole role)
        {
            roleID.CheckStringIsNullOrEmpty("roleID");

            if (role == null)
                role = new SOARole() { ID = roleID };

            SOARolePropertyDefinitionCollection definition = SOARolePropertyDefinitionAdapter.Instance.GetByRoleID(roleID);

            return LoadByRoleID(roleID, role, definition);
        }
Exemplo n.º 17
0
        private static void FillSheetData(SOARole role, WorkSheet ws)
        {
            int rowIndex = 4;
            SOARolePropertyRowCollection rows = SOARolePropertiesAdapter.Instance.LoadByRole(role, role.PropertyDefinitions);

            foreach (SOARolePropertyRow row in rows)
            {
                foreach (DefinedName name in ws.Names)
                {
                    SOARolePropertyValue propertyValue = row.Values.FindByColumnName(name.Name);

                    string dataValue = null;

                    if (propertyValue != null)
                        dataValue = propertyValue.Value;
                    else
                    {
                        switch (name.Name.ToLower())
                        {
                            case "operatortype":
                                dataValue = row.OperatorType.ToString();
                                break;
                            case "operator":
                                dataValue = row.Operator;
                                break;
                        }
                    }

                    if (dataValue != null)
                        ws.Cells[rowIndex, name.Address.StartColumn].Value = dataValue;
                }

                rowIndex++;
            }
        }
        public void Update(SOARole role)
        {
            role.NullCheck("role");

            Update(role.ID, role.Rows);
        }
Exemplo n.º 19
0
        private static void CreateHeaderRow(SOARole role, WorkSheet ws)
        {
            Row headRow = new Row(3);
            headRow.Style.Fill.SetBackgroundColor(Color.Gold, ExcelFillStyle.Solid);
            headRow.Style.Border.Top.Style = ExcelBorderStyle.Thin;
            headRow.Style.Border.Top.Color.SetColor(Color.Black);
            headRow.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
            headRow.Style.Border.Bottom.Color.SetColor(Color.Black);
            headRow.Style.Border.Left.Style = ExcelBorderStyle.Thin;
            headRow.Style.Border.Left.Color.SetColor(Color.Black);
            headRow.Style.Font.Bold = true;
            ws.Rows.Add(headRow);

            int columnIndex = 1;

            foreach (SOARolePropertyDefinition dimension in role.PropertyDefinitions)
            {
                ws.Cells[headRow.Index, columnIndex].Value = dimension.Description.IsNotEmpty() ? dimension.Description : dimension.Name;
                ws.Names.Add(CellAddress.Parse(columnIndex, headRow.Index).ToString(), dimension.Name);

                columnIndex++;
            }
        }
        private static string GetRoleFullCodeName(SOARole role)
        {
            string result = string.Empty;

            try
            {
                result = role.FullCodeName;
            }
            catch (System.Exception)
            {
            }

            return result;
        }
        private static void CheckImportSource(SOARole role, WorkBook workbook)
        {
            string roleFullCodeName = GetRoleFullCodeName(role);

            if (roleFullCodeName.IsNotEmpty())
            {
                string excelSource = workbook.FileDetails.Subject;

                if (excelSource.IsNotEmpty())
                {
                    if (string.Compare(roleFullCodeName, excelSource, true) != 0)
                        throw new InvalidOperationException(string.Format("导入的角色矩阵的来源是{0},和目标{1}不匹配。如果需要强制导入,请去掉\"校验导入的矩阵是否是相同的来源\"选择框",
                            excelSource, roleFullCodeName));
                }
            }
        }
        private SOARolePropertyRow GenerateMatrixRow(SOARole role, RowNode rowNode, NamedLocationCollection locations, int index)
        {
            SOARolePropertyRow mRow = new SOARolePropertyRow(role);

            mRow.RowNumber = index;

            int emptyCellCount = 0;

            foreach (var row in this.Definition)
            {
                CellLocation location = locations[row.Name];

                CellNode cell = rowNode.GetCellByIndex(location.Column);

                SOARolePropertyValue mCell = new SOARolePropertyValue(row);

                mCell.Value = cell.Data.InnerText.Trim();

                mRow.Values.Add(mCell);

                switch (row.Name)
                {
                    case "Operator":
                        mRow.Operator = cell.Data.InnerText;
                        break;
                    case "OperatorType":
                        SOARoleOperatorType opType = SOARoleOperatorType.User;
                        Enum.TryParse(cell.Data.InnerText, out opType);
                        mRow.OperatorType = opType;
                        break;
                    default:
                        if (mCell.Value.IsNullOrEmpty())
                            emptyCellCount++;
                        break;
                }
            }

            role.Rows.Add(mRow);

            return mRow;
        }
        /// <summary>
        /// 导入Open Xml格式的文件
        /// </summary>
        /// <param name="importStream"></param>
        /// <param name="notifier"></param>
        private void ImportFromExcel2007(Stream importStream, Action notifier)
        {
            WorkBook workbook = WorkBook.Load(importStream);

            SOARole role = null;

            ServiceBrokerContext.Current.SaveContextStates();

            try
            {
                ServiceBrokerContext.Current.UseLocalCache = false;
                ServiceBrokerContext.Current.UseServerCache = false;

                if (this.AppCodeName.IsNotEmpty() && this.RoleCodeName.IsNotEmpty())
                    role = new SOARole(this.AppCodeName + ":" + this.RoleCodeName);
                else
                    role = new SOARole(this.Definition) { ID = RoleID };

                if (NeedValidateSource)
                    CheckImportSource(role, workbook);

                DataTable dt = DocumentHelper.GetRangeValuesAsTable(workbook, "Matrix", "A3");

                role.Rows.Clear();

                int rowIndex = 0;
                foreach (DataRow row in dt.Rows)
                {
                    SOARolePropertyRow mRow = new SOARolePropertyRow(role) { RowNumber = rowIndex };

                    foreach (var dimension in this.Definition)
                    {
                        SOARolePropertyValue mCell = new SOARolePropertyValue(dimension);
                        mCell.Value = row[dimension.Name].ToString();

                        switch (dimension.Name)
                        {
                            case "Operator":
                                mRow.Operator = row[dimension.Name].ToString();
                                break;
                            case "OperatorType":
                                SOARoleOperatorType opType = SOARoleOperatorType.User;
                                Enum.TryParse(row[dimension.Name].ToString(), out opType);
                                mRow.OperatorType = opType;
                                break;
                            default:
                                break;
                        }
                        mRow.Values.Add(mCell);
                    }

                    if (notifier != null)
                    {
                        notifier();
                    }

                    rowIndex++;
                    role.Rows.Add(mRow);
                }

                //插入记录
                SOARolePropertiesAdapter.Instance.Update(role);
            }
            finally
            {
                ServiceBrokerContext.Current.RestoreSavedStates();
            }
        }
        /// <summary>
        /// 导入Excel Xml格式的文件
        /// </summary>
        /// <param name="stream"></param>
        private void ImportFromXml(Stream stream)
        {
            WorkbookNode workbook = new WorkbookNode();

            workbook.Load(stream);

            ExceptionHelper.FalseThrow(workbook.Worksheets.Contains("Matrix"),
                "The workbook must contains a 'Matrix' worksheet.");

            SOARole role = null;

            ServiceBrokerContext.Current.SaveContextStates();
            try
            {
                if (this.AppCodeName.IsNotEmpty() && this.RoleCodeName.IsNotEmpty())
                    role = new SOARole(this.AppCodeName + ":" + this.RoleCodeName);
                else
                    role = new SOARole(this.Definition) { ID = RoleID };

                role.Rows.Clear();

                NamedLocationCollection fieldLocations = workbook.Names.ToLocations();

                TableNode table = workbook.Worksheets["Matrix"].Table;

                int baseRowIndex = GetStartRow(fieldLocations);

                RowNode titleRow = table.GetRowByIndex(baseRowIndex);

                int currentRowIndex = table.Rows.IndexOf(titleRow) + 1;

                if (table.Rows.Count > currentRowIndex)
                {
                    UploadProgressStatus status = new UploadProgressStatus();

                    status.CurrentStep = 1;
                    status.MinStep = 0;
                    status.MaxStep = table.Rows.Count - currentRowIndex;

                    int currentVirtualRow = baseRowIndex;

                    for (int i = status.MinStep; i < status.MaxStep; i++)
                    {
                        RowNode row = table.Rows[currentRowIndex];

                        if (row.Index > 0)
                            currentVirtualRow = row.Index;
                        else
                            currentVirtualRow++;

                        GenerateMatrixRow(role, row, fieldLocations, i);

                        status.CurrentStep = i;
                        status.Response();

                        currentRowIndex++;
                    }

                    status.CurrentStep = status.MaxStep;
                    status.Response();
                }
                //插入记录
                SOARolePropertiesAdapter.Instance.Update(role);
            }
            finally
            {
                ServiceBrokerContext.Current.RestoreSavedStates();
            }
        }
        public void Delete(SOARole role)
        {
            role.NullCheck("role");

            this.Delete(role.ID);
        }
        public void Delete(SOARole role)
        {
            role.NullCheck("role");

            this.Delete(role.ID);
        }
		protected static void ExportOpenXmlSpreadsheet()
		{
			SOARole role = null;

			if (AppCode.IsNotEmpty() && RoleCode.IsNotEmpty())
			{
				role = new SOARole(AppCode + ":" + RoleCode);
			}
			else
			{
				SOARolePropertyDefinitionCollection definitions = SOARolePropertyDefinitionAdapter.Instance.LoadByRoleID(ExportRoleProperty.DefinitionID);
				role = new SOARole(definitions) { ID = RoleID };
			}

			WorkBook workBook = role.ToExcelWorkBook();

			workBook.Save(HttpContext.Current.Response.OutputStream);

			HttpContext.Current.Response.AppendExcelOpenXmlHeader(GetFileNameByRole(RoleID));
			HttpContext.Current.Response.End();
		}
		private void ExportExcelXPXml()
		{
			SOARolePropertyDefinitionCollection definition = SOARolePropertyDefinitionAdapter.Instance.LoadByRoleID(ExportRoleProperty.DefinitionID);
			string PropertySheetName = "Matrix";

			WorkbookNode workbook = ExportToExcelXml(definition, PropertySheetName);
			SOARole role = new SOARole(definition) { ID = RoleID };

			SOARolePropertyRowCollection rows = SOARolePropertiesAdapter.Instance.LoadByRole(role, definition);

			if (rows.Count > 0)
			{
				FillMatrixRowsToWorksheet(workbook, rows);
			}

			workbook.Response(GetFileNameByRole(RoleID));
		}
        public void Update(SOARole role)
        {
            role.NullCheck("role");

            Update(role.ID, role.Rows);
        }
		protected void btnConfirm_Click(object sender, EventArgs e)
		{
			if (this.Request.QueryString["editMode"] == "readOnly")
				throw new InvalidOperationException("只读模式不可以编辑");

			RoleID = MCS.Web.Library.WebUtility.GetRequestParamString("RoleID", string.Empty);
			SOARole role = new SOARole() { ID = RoleID };

			SOARolePropertyRowCollection rowsColl = SOARolePropertiesAdapter.Instance.LoadByRole(role);

			/*沈峥注释,不需要这个限制
			if (rowsColl.Count > 0)
			{
				WebUtility.ShowClientMessage("矩阵定义已经被使用,无法再修改!", "", "无法进行此操作");
				return;
			}
			*/

			var coll = detailGrid.InitialData as SOARolePropertyDefinitionCollection;
			SOARolePropertyDefinitionAdapter.Instance.Update(role, coll);

			Page.ClientScript.RegisterStartupScript(this.GetType(), "returnProcesses",
					string.Format("window.returnValue = true; top.close();"),
					true);
		}