private static void FillMatrixRowsToWorksheet(WorkbookNode workbook, WfMatrix matrix, bool roleAsPerson) { NamedLocationCollection locations = workbook.Names.ToLocations(); locations.SortByColumn(); WorksheetNode worksheet = workbook.Worksheets[GetWorksheet(locations)]; int startRowIndex = GetStartRow(locations); int currentRowIndex = -1; foreach (WfMatrixRow matrixRow in matrix.Rows) { RowNode row = new RowNode(); if (currentRowIndex == -1) { currentRowIndex = startRowIndex + 1; row.Index = currentRowIndex; } foreach (CellLocation location in locations) { CellNode cell = new CellNode(); WfMatrixCell mCell = matrixRow.Cells.Find(c => c.Definition.DimensionKey == location.Name); if (mCell != null) { cell.Data.Value = GetCellValue(roleAsPerson, mCell, matrixRow); } row.Cells.Add(cell); } worksheet.Table.Rows.Add(row); } }
/// <summary> /// 从ExcelXml中导入已经存在的矩阵 /// </summary> /// <param name="stream"></param> /// <param name="notifier"></param> /// <param name="processDescKey"></param> public static void ImportExistMatrixFromExcelXml(Stream stream, Action notifier, string processDescKey) { WfMatrix matrix = WfMatrixAdapter.Instance.LoadByProcessKey(processDescKey, true); matrix.Rows.Clear(); ImportExcelXml(stream, matrix, notifier); }
private static WfMatrixRow GenerateMatrixRow(WfMatrix matrix, RowNode rowNode, NamedLocationCollection locations, int index) { WfMatrixRow mRow = new WfMatrixRow(matrix); mRow.RowNumber = index; int emptyCellCount = 0; foreach (WfMatrixDimensionDefinition dd in matrix.Definition.Dimensions) { CellLocation location = locations[dd.DimensionKey]; CellNode cell = rowNode.GetCellByIndex(location.Column); WfMatrixCell mCell = new WfMatrixCell(dd); mCell.StringValue = cell.Data.InnerText.Trim(); mRow.Cells.Add(mCell); switch (dd.DimensionKey) { case "Operator": mRow.Operator = cell.Data.InnerText; break; case "OperatorType": WfMatrixOperatorType opType = WfMatrixOperatorType.Person; Enum.TryParse(cell.Data.InnerText, out opType); mRow.OperatorType = opType; break; default: if (mCell.StringValue.IsNullOrEmpty()) { emptyCellCount++; } break; } } if (emptyCellCount >= matrix.Definition.Dimensions.Count - 2) { //如果每一列都为空(不算Operator和OperatorType),那么认为整行都为空 mRow = null; } else { matrix.Rows.Add(mRow); } return(mRow); }
public static void ImportNewMatrixFromExcel2007(Stream stream, Action notifier, string processDescKey, WfMatrixDefinition matrixDef) { WfMatrix matrix = new WfMatrix(matrixDef) { MatrixID = Guid.NewGuid().ToString(), ProcessKey = processDescKey, CreatorID = DeluxeIdentity.CurrentUser.ID, CreatorName = DeluxeIdentity.CurrentUser.Name }; ImportExcel2007(stream, matrix, notifier, processDescKey); }
internal void GenerateCandidatesFromMatrix(WfMatrix matrix) { WfMatrixRowCollection rows = FilterRowsByActivity(matrix); WfMatrixRowUsersCollection rowsUsers = rows.GenerateRowsUsers(); foreach (WfMatrixRowUsers ru in rowsUsers) { this.Candidates.Add(ru.Users); } Candidates.Distinct((a1, a2) => string.Compare(a1.User.ID, a2.User.ID, true) == 0 && a1.AssigneeType == a2.AssigneeType); }
private static void ImportExcelXml(Stream stream, WfMatrix matrix, Action notifier) { WorkbookNode workbook = new WorkbookNode(); workbook.Load(stream); ExceptionHelper.FalseThrow(workbook.Worksheets.Contains("Matrix"), "The workbook must contains a 'Matrix' worksheet."); 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) { int currentVirtualRow = baseRowIndex; int count = table.Rows.Count - currentRowIndex; for (int i = 0; i < count; i++) { RowNode row = table.Rows[currentRowIndex]; if (row.Index > 0) { currentVirtualRow = row.Index; } else { currentVirtualRow++; } GenerateMatrixRow(matrix, row, fieldLocations, i); if (notifier != null) { notifier(); } currentRowIndex++; } } WfMatrixAdapter.Instance.DeleteByProcessKey(matrix.ProcessKey); WfMatrixAdapter.Instance.Update(matrix); }
private static void ImportExcel2007(Stream importStream, WfMatrix matrix, Action notifier, string processDescKey) { DataTable dt = DocumentHelper.GetRangeValuesAsTable(importStream, "Matrix", "A3"); int rowIndex = 0; foreach (DataRow row in dt.Rows) { WfMatrixRow matrixRow = new WfMatrixRow(matrix) { RowNumber = rowIndex }; foreach (var dimension in matrix.Definition.Dimensions) { WfMatrixCell matrixCell = new WfMatrixCell(dimension); matrixCell.StringValue = row[dimension.DimensionKey].ToString(); switch (dimension.DimensionKey) { case "Operator": matrixRow.Operator = row[dimension.DimensionKey].ToString(); break; case "OperatorType": WfMatrixOperatorType opType = WfMatrixOperatorType.Person; Enum.TryParse(row[dimension.DimensionKey].ToString(), out opType); matrixRow.OperatorType = opType; break; default: break; } matrixRow.Cells.Add(matrixCell); } if (notifier != null) { notifier(); } rowIndex++; matrix.Rows.Add(matrixRow); } WfMatrixAdapter.Instance.DeleteByProcessKey(matrix.ProcessKey); WfMatrixAdapter.Instance.Update(matrix); }
private WfMatrixRowCollection FilterRowsByActivity(WfMatrix matrix) { WfMatrixRowCollection result = new WfMatrixRowCollection(); if (matrix.Definition.Dimensions.ContainsKey("ActivityKey")) { foreach (WfMatrixRow row in matrix.Rows) { if (string.Compare(row.Cells.GetValue("ActivityKey", string.Empty), this.Descriptor.Key, true) == 0) { result.Add(row); } } } return(result); }
private void FillRoleTypeUsers(WfMatrixRowUsersCollection result) { foreach (var rowUsers in result) { if (rowUsers.Row.OperatorType == WfMatrixOperatorType.Role) { var users = WfMatrix.GetUsersInRole(rowUsers.Row.Operator); foreach (IUser userInRole in users) { if (rowUsers.Users.Exists(u => string.Compare(u.ID, userInRole.ID, true) == 0) == false) { rowUsers.Users.Add(userInRole); } } } } }
public WfMatrixRow(WfMatrix matrix) { matrix.NullCheck("matrix"); this.Matrix = matrix; }
public WfMatrixRowCollection(WfMatrix matrix) { matrix.NullCheck("matrix"); this._Matrix = matrix; }
public static IWfProcess StartWorkflow(WfProcessStartupParams startupParams) { startupParams.NullCheck <WfRuntimeException>("startupParams"); WfProcess process = new WfProcess(startupParams.ProcessDescriptor); FillProcessDescriptorProperties(startupParams, process.Descriptor); FillProcessInstanceProperties(startupParams, process); WfProcessContextCache.Instance.Add(process.ID, process); if (process.Creator == null && DeluxePrincipal.IsAuthenticated) { process.Creator = DeluxeIdentity.CurrentUser; } if (process.InitialActivity != null) { if (process.InitialActivity.Descriptor.Properties.GetValue("AutoGenerateCadidates", true)) { process.InitialActivity.GenerateCandidatesFromResources(); WfMatrix matrix = process.GetMatrix(); if (matrix != null) { ((WfActivityBase)process.InitialActivity).GenerateCandidatesFromMatrix(matrix); } } if (startupParams.CheckStartProcessUserPermission) { CheckStartProcessUserPermission(process); } if (startupParams.Assignees.Count == 0) { startupParams.Assignees.CopyFrom(process.InitialActivity.Candidates); } if (process.InitialActivity.Descriptor.Resources.Count == 0) { startupParams.Assignees.ToUsers().ForEach(u => process.InitialActivity.Descriptor.Resources.Add(new WfUserResourceDescriptor(u))); } WfSimulator.WriteSimulationInfo(process, WfSimulationOperationType.Startup); //如果自动启动第一个活动且存在活动点,则流转到第一个点 if (startupParams.AutoStartInitialActivity) { WfAssigneeCollection assignees = startupParams.Assignees; process.InitialActivity.Candidates.Clear(); process.InitialActivity.Candidates.CopyFrom(startupParams.Assignees); IWfActivity originalInitial = process.InitialActivity; WfRuntime.DecorateProcess(process); //修饰流程后,如果起始点发生了变化... if (originalInitial != process.InitialActivity) { assignees = process.InitialActivity.Candidates; } WfTransferParams transferParams = new WfTransferParams(process.InitialActivity.Descriptor); //设置初始节点子流程参数 process.InitialActivity.Descriptor.BranchProcessTemplates.ForEach(branchTemplate => { transferParams.BranchTransferParams.Add(new WfBranchProcessTransferParams(branchTemplate)); }); transferParams.Operator = startupParams.Creator; transferParams.Assignees.CopyFrom(assignees); process.MoveTo(transferParams); WfRuntime.ProcessContext.NormalizeTaskTitles(); } } WfRuntime.ProcessContext.AffectedProcesses.AddOrReplace(process); return(process); }