/// <summary> /// Writes a set of project invocation rules to a worksheet. /// </summary> /// <param name="ws">The worksheet to which the rules are to be written.</param> /// <param name="mode">The ExecutionMode to be written.</param> /// <param name="rules">The project invocation rules to be written.</param> public void Save(Excel.Worksheet ws, ExecutionMode mode, ProjectInvocationRule[] rules) { ws.Cells.ClearContents(); Helper.WriteCell(ws, 1, 1, mode.ToString()); var writer = new ProjectRuleDataWriter(); writer.Write(ws, rules, 2); }
/// <summary> /// Re-bases the unique identifiers assigned to a set of ProjectInvocationRule instances. /// </summary> /// <param name="rules">An array of ProjectInvocationRules whose identifiers are to be rationalised.</param> public void RationaliseIds(ProjectInvocationRule[] rules) { IList<int> list = GetImmutableIds(rules); var rulesToUpdate = rules.Where(r => !list.Contains(r.Id)).ToArray(); foreach (ProjectInvocationRule rule in rulesToUpdate) { int id = Helper.CreateId(list); rule.Id = id; list.Add(id); } }
/// <summary> /// Invokes those of the supplied project invocation rules that are valid and enabled. /// </summary> /// <param name="mode">The ExecutionMode to be used.</param> /// <param name="rules">The project invocation rules that are to be invoked.</param> public void Run(ExecutionMode mode, ProjectInvocationRule[] rules) { lock (m_runLock) { var d = new ProjectExecutionDialogue(); if (m_bounds.HasValue) { d.Bounds = m_bounds.Value; d.StartPosition = System.Windows.Forms.FormStartPosition.Manual; } PerformActiveAdapterAction(a => a.Run(mode, rules, m_manager, d)); m_bounds = d.Bounds; } }
/// <summary> /// Re-bases the unique identifiers assigned to a set of ProjectInvocationRule instances. /// </summary> /// <param name="rules">An array of ProjectInvocationRules whose identifiers are to be /// rationalised.</param> public void RationaliseIds(ProjectInvocationRule[] rules) { PerformActiveAdapterAction(a => a.RationaliseIds(rules)); }
/// <summary> /// Sets this ProjectConfigurationDialogue's collection of project invocation rules. /// </summary> /// <remarks> /// The supplied rules are cloned. This is because they are used as view-models in this dialogue /// and thus the user can change their states. If, subsequently, the user cancels this dialogue /// then any changes to individual ProjectInvocationRule instances can be discarded. /// </remarks> public void SetRules(ProjectInvocationRule[] rules) { rules = GetClones(rules); ConfigurationDialogueContent content = Content; content.SetRules(rules); }
/// <summary> /// Clones the supplied ProjectInvocationRule instances. /// </summary> private static ProjectInvocationRule[] GetClones(ProjectInvocationRule[] rules) { return rules == null ? null : rules.Select(r => r.Clone()).ToArray(); }
/// <summary> /// Loads project invocation rules for the active workbook. /// </summary> private void ReadRules() { Excel.Workbook workbook = ActiveWorkbook; Excel.Worksheet ws = GetRulesWorksheet(workbook); if (ws == null) { Mode = ExecutionMode.Synchronous; Rules = new ProjectInvocationRule[0]; } else { NamedRangeProvider nrp = NamedRangeProvider; nrp.Clear(); var prm = new PersistedRuleManager(); prm.Load(this, nrp, ws, out m_mode, out m_rules); RationaliseRuleIds(); UpdateExecutionState(); } }
private void AddRuleButton_Click(object sender, RoutedEventArgs e) { InvokeProvidersAction((wsp, nrp) => { int id = Helper.CreateId(m_rules.Select(r => r.Id)); var pir = new ProjectInvocationRule(wsp, nrp, id); Add(pir); pir.IsSelected = true; }); }
private void Add(ProjectInvocationRule rule) { m_rules.Add(rule); }
private static void PerformRuleAction(ProjectInvocationRule pir, Action<ProjectInvocationRule> action) { if (pir != null) { action(pir); } }
public void SetRules(ProjectInvocationRule[] rules) { m_rules.Clear(); if (rules != null) { foreach (ProjectInvocationRule rule in rules) { Add(rule); } SelectedRule = rules.FirstOrDefault(); } }
/// <summary> /// Clones this ProjectInvocationRule. /// </summary> /// <returns>A new ProjectInvocationRule instance representing a clone of this ProjectInvocationRule.</returns> public ProjectInvocationRule Clone() { var rule = new ProjectInvocationRule() { m_wsProvider = this.m_wsProvider, m_nrProvider = this.m_nrProvider, m_id = this.m_id, m_usesInput = this.m_usesInput, m_inputSheetKey = this.m_inputSheetKey, m_inputCellRange = this.m_inputCellRange, m_inputRangeOrder = this.m_inputRangeOrder, m_timeLimit = this.m_timeLimit, m_timeUnit = this.m_timeUnit, m_usesOutput = this.m_usesOutput, m_outputSheetKey = this.m_outputSheetKey, m_outputCellRange = this.m_outputCellRange, m_outputRangeOrder = this.m_outputRangeOrder, m_projectPath = this.m_projectPath, m_reloadProjectBeforeExecuting = this.m_reloadProjectBeforeExecuting, m_enabled = this.m_enabled, m_lastExecutionResult = this.m_lastExecutionResult }; rule.UpdateInputSheetRangeNames(); rule.UpdateOutputSheetRangeNames(); rule.UpdateValidity(true); return rule; }
/// <summary> /// Invokes those of the supplied project invocation rules that are valid and enabled. /// </summary> /// <param name="mode">The ExecutionMode to be used.</param> /// <param name="rules">The project invocation rules that are to be invoked.</param> /// <param name="manager">The IRuntimeManager with which to perform the underlying Absyntax project- /// loading and invocation activities.</param> /// <param name="coordinator">The IExecutionCoordinator needed to coordinate the execution sequence.</param> public void Run(ExecutionMode mode, ProjectInvocationRule[] rules, IRuntimeManager manager, IExecutionCoordinator coordinator) { UnloadProjectsWhereNecessary(rules, manager); ExecutionItem[] items = CreateExecutionItems(rules); coordinator.Start(mode, items, manager); lock (m_ruleState) { foreach (ExecutionItem item in items) { switch (item.State) { case ProjectExecutionState.Completed: case ProjectExecutionState.WriteDataErrors: if (!m_ruleState.ContainsKey(item.Id)) { m_ruleState[item.Id] = item.Detail; } break; case ProjectExecutionState.Ineligible: case ProjectExecutionState.Pending: // Do nothing break; default: m_ruleState.Remove(item.Id); break; } ProjectInvocationRule rule = rules.First(r => r.Id == item.Id); rule.LastExecutionResult = GetLastExecutionResult(item.State); } } }
/// <summary> /// Returns a list of ProjectInvocationRule ids that cannot be changed. /// </summary> /// <remarks> /// A ProjectInvocationRule's id cannot be changed if this WorkbookRuntimeAdapter is already /// managing an execution slot for it. /// </remarks> private IList<int> GetImmutableIds(ProjectInvocationRule[] rules) { lock (m_ruleState) { return new List<int>(rules.Select(r => r.Id).Intersect(m_ruleState.Keys)); } }
/// <summary> /// Reads a set of project invocation rules from a worksheet. /// </summary> /// <remarks> /// The worksheet is expected to store the execution mode in cell A1. Each invocation rule occupies /// its own row, starting at row 2: each column contains a field value and all such values are used /// collectively to rehydrate a rule. /// </remarks> /// <param name="wsProvider">An IWorksheetProvider implementation.</param> /// <param name="nrProvider">An INamedRangeProvider implementation.</param> /// <param name="ws">The worksheet containing the rules to be read.</param> /// <param name="mode">The ExecutionMode read from the worksheet.</param> /// <param name="rules">The project invocation rules read from the worksheet.</param> public void Load(IWorksheetProvider wsProvider, INamedRangeProvider nrProvider, Excel.Worksheet ws, out ExecutionMode mode, out ProjectInvocationRule[] rules) { mode = Helper.ReadCell<ExecutionMode>(ws, 1, 1); var reader = new ProjectRuleDataReader(wsProvider, nrProvider); rules = reader.Read(ws, 2); }