public UpdateCalcValuesOutput Execute(UpdateCalcValuesInput input) { var output = new UpdateCalcValuesOutput(); // 循環依存のチェックを行う var circulationList = null as List <int>; if (ContainsCirculation(input.Data, out circulationList)) { var list = string.Join(",", circulationList.ToArray()); throw new Exception($"Contains Circulation{Environment.NewLine}{list}"); } // 稼働日数を演算 var totalValueOfPeriod = CalcTotalValueOfPeriod(input.StartDate, input.EndDate, input.RestDate, input.Holidays, input.Members); // 最早開始時刻を演算 var earliestStartValues = CalcEarliestStartValues(input.Data); // 最遅開始時刻を演算 var latestStartValues = CalcLatestStartValues(input.Data, totalValueOfPeriod); // 最早完了時刻を演算 var earliestFinishValues = CalcEarliestFinishValues(input.Data, earliestStartValues); // 最遅完了時刻を演算 var latestFinishValues = CalcLatestFinishValues(input.Data, latestStartValues); // トータルフロート(全余裕時間)を演算 var totalFloats = CalcTotalFloatValues(latestStartValues, earliestStartValues); // フリーフロート(自由余裕時間)を演算 var freeFloats = CalcFreeFloatValues(input.Data, earliestStartValues); // クリティカルパスを演算 var criticalFlags = CalcCriticalPath(totalFloats); output.CalcValues = input.Data.Select(x => { return(new UpdateCalcValuesOutput.CalcValue() { EdgeId = x.Id, EarliestStartTime = earliestStartValues[x.Id], LatestStartTime = latestStartValues[x.Id], EarliestFinishTime = earliestFinishValues[x.Id], LatestFinishTime = latestFinishValues[x.Id], TotalFloat = totalFloats[x.Id], FreeFloat = freeFloats[x.Id], IsCritical = criticalFlags[x.Id] }); }); return(output); }
public void Execute(object parameter) { var viewModel = parameter as PertPageViewModel; // 基本データの更新 foreach (var edge in viewModel.Edges) { var taskId = edge.TaskId; var task = this.appContext.Tasks.FirstOrDefault(x => x.TaskCd == taskId); if (task != null) { edge.ProcessId = task.ProcessCd; edge.FunctionId = task.FunctionCd; edge.PV = task.PlanValue; } else { edge.PV = 0.0; } } // 演算に必要なデータが入力済みであるかをチェックし、不足があれば演算を中止 if (CheckCalc() == false) { return; } // 計算データの更新 var input = new UpdateCalcValuesInput(); input.StartDate = appContext.PrjSettings.StartDate.Value; input.EndDate = appContext.PrjSettings.EndDate.Value; input.RestDate = appContext.WeekDays.Where(x => x.HolidayFlg).Select(x => x.WeekdayCd).ToArray(); input.Holidays = appContext.Holidays.Where(x => x.HolidayDate.HasValue).Select(x => x.HolidayDate.Value).ToArray(); input.Members = appContext.Members; input.Data = viewModel.Edges .Where(x => x.INode.HasValue && x.JNode.HasValue && x.PV.HasValue) .Select(x => new UpdateCalcValuesInput.ActivityData() { Id = x.Id, SrcNodeId = x.INode.Value, DstNodeId = x.JNode.Value, PlanValue = x.PV.Value, }).ToArray(); var output = null as UpdateCalcValuesOutput; try { output = this.businessLogic.Execute(input); } catch (Exception ex) { MessageBox.Show(ex.Message, "演算エラー", MessageBoxButton.OK, MessageBoxImage.Warning); return; } var vmEdges = viewModel.Edges.Where(x => x.INode.HasValue && x.JNode.HasValue && x.PV.HasValue).OrderBy(x => x.Id).ToArray(); var enEdges = output.CalcValues.OrderBy(x => x.EdgeId).ToArray(); var pairs = vmEdges.Zip(enEdges, (a, b) => new { Vm = a, CalcVal = b }).ToArray(); foreach (var pair in pairs) { var vmEdge = pair.Vm; var enEdge = pair.CalcVal; vmEdge.FastestStartValue = enEdge.EarliestStartTime; vmEdge.FastestEndValue = enEdge.EarliestFinishTime; vmEdge.LatestStartValue = enEdge.LatestStartTime; vmEdge.LatestEndValue = enEdge.LatestFinishTime; vmEdge.FreeFloat = enEdge.FreeFloat; vmEdge.TotalFloat = enEdge.TotalFloat; vmEdge.IsCritical = enEdge.IsCritical; this.appContext.PertEdges.First(x => x.SrcNodeCd == vmEdge.INode && x.DstNodeCd == vmEdge.JNode).IsCritical = vmEdge.IsCritical; } }