} // makeBatchOp() /// <summary> /// Run the next iteration of this batch operation /// </summary> public void runBatchOp(CswNbtObjClassBatchOp BatchNode) { try { if (BatchNode != null && BatchNode.OpNameValue == CswEnumNbtBatchOpName.FutureNodes) { BatchNode.start(); FutureNodesBatchData BatchData = new FutureNodesBatchData(BatchNode.BatchData.Text); if (BatchData.GeneratorNodeId != null && BatchData.NextStartDate != DateTime.MinValue) { CswNbtNode GenNode = _CswNbtResources.Nodes[BatchData.GeneratorNodeId]; if (null != GenNode) { CswNbtObjClassGenerator GeneratorNode = (CswNbtObjClassGenerator)GenNode; DateTime ThisDate = BatchData.NextStartDate; CswNbtActGenerateNodes CswNbtActGenerateNodes = new CswNbtActGenerateNodes(_CswNbtResources); CswNbtActGenerateNodes.MarkFuture = true; // Run this iteration bool Finished = false; if (ThisDate != DateTime.MinValue && ThisDate.Date <= BatchData.FinalDate.Date && (GeneratorNode.FinalDueDate.Empty || ThisDate.Date <= GeneratorNode.FinalDueDate.DateTimeValue.Date)) { Finished = CswNbtActGenerateNodes.makeNode(GenNode, ThisDate); //BatchNode.appendToLog( "Created future task for " + ThisDate.ToShortDateString() + "." ); } else { BatchNode.finish(); } // Setup for next iteration if (Finished) { BatchData.NextStartDate = GeneratorNode.DueDateInterval.getNextOccuranceAfter(ThisDate); if (BatchData.NextStartDate.Date == ThisDate.Date) // infinite loop guard { BatchNode.finish(); } BatchData.IterationCount += 1; } BatchNode.BatchData.Text = BatchData.ToString(); BatchNode.PercentDone.Value = getPercentDone(BatchNode); } // if( null != GenNode ) } // if( _BatchData.GeneratorNodeId != null && _BatchData.NextStartDate != DateTime.MinValue ) BatchNode.postChanges(false); } // if( BatchNode != null && BatchNode.OpNameValue == NbtBatchOpName.FutureNodes ) } catch (Exception ex) { BatchNode.error(ex); } } // runBatchOp()
private void _processGenerator(CswNbtResources CswNbtResources, CswNbtObjClassGenerator CurrentGenerator) { try { // case 28069 // It should not be possible to make more than 24 nodes per parent in a single day, // since the fastest interval is 1 hour, and we're not creating things into the past anymore. // Therefore, disable anything that is erroneously spewing things. if (CurrentGenerator.GeneratedNodeCount(DateTime.Today) >= (24 * CurrentGenerator.TargetParents.Count)) { string Message = "Disabled due to error: Generated too many " + CurrentGenerator.TargetType.SelectedNodeTypeNames() + " targets in a single day"; _StatusMessage += Message + "; "; CurrentGenerator.Enabled.Checked = CswEnumTristate.False; CurrentGenerator.RunStatus.AddComment(Message); CurrentGenerator.postChanges(false); } else { CswNbtActGenerateNodes CswNbtActGenerateNodes = new CswNbtActGenerateNodes(CswNbtResources); bool Finished = CswNbtActGenerateNodes.makeNode(CurrentGenerator.Node); if (Finished) // case 26111 { string Message = "Created all " + CurrentGenerator.TargetType.SelectedNodeTypeNames() + " target(s) for " + CurrentGenerator.NextDueDate.DateTimeValue.Date.ToShortDateString(); CurrentGenerator.RunStatus.AddComment(Message); CurrentGenerator.updateNextDueDate(ForceUpdate: true, DeleteFutureNodes: false); CurrentGenerator.postChanges(false); } _StatusMessage += CurrentGenerator.Description.Text + "; "; } // if-else( CurrentGenerator.GeneratedNodeCount( DateTime.Today ) >= 24 ) } //try catch (Exception Exception) { string Message = "Unable to process generator " + CurrentGenerator.Description.Text + ", which will now be disabled, due to the following exception: " + Exception.Message; _StatusMessage += Message + "; "; CurrentGenerator.Enabled.Checked = CswEnumTristate.False; CurrentGenerator.RunStatus.AddComment("Disabled due to exception: " + Exception.Message); CurrentGenerator.postChanges(false); CswNbtResources.logError(new CswDniException(Message)); } }