public void Analyze() { foreach (Phase phase in matrix.Phases) { List <Queue <PhaseElement> > phaseSeqContainer = GetElemets(phase); if (phaseSeqContainer != null) { Queue <PhaseElement> phaseSequenceStartElements = phaseSeqContainer[0]; while (phaseSequenceStartElements.Count != 0) { PhaseElement startCandidate = phaseSequenceStartElements.Dequeue(); phase.StartPackageNumber = startCandidate.PhaseElementStartIndex; phase.EndPackageNumber = CheckSequence(phaseSeqContainer, startCandidate, phaseSeqContainer[1]); if (phase.EndPackageNumber != -1) { for (int i = phase.StartPackageNumber; i <= phase.EndPackageNumber; i++) { matrix.Set(phase.ElementId, i, true); } } else { phase.StartPackageNumber = -1; } } } } }
private int CheckSequence(List <Queue <PhaseElement> > list, PhaseElement sequenceCandidate, Queue <PhaseElement> nextElementQueue) { Queue <PhaseElement> tempNextElementQueue = new Queue <PhaseElement>(nextElementQueue); while (tempNextElementQueue.Count != 0) { PhaseElement nextSequenceCandidate = tempNextElementQueue.Dequeue(); if (nextSequenceCandidate.PhaseElementStartIndex > sequenceCandidate.PhaseElementStopIndex) { return(-1); } else { if ((nextSequenceCandidate.PhaseElementStartIndex >= sequenceCandidate.PhaseElementStartIndex) && (nextSequenceCandidate.PhaseElementStartIndex <= sequenceCandidate.PhaseElementStopIndex)) { int currentIndex = list.IndexOf(nextElementQueue); if (currentIndex < list.Count - 1) { return(CheckSequence(list, nextSequenceCandidate, list[currentIndex + 1])); } else { return(nextSequenceCandidate.PhaseElementStopIndex); } } } } return(-1); }
private List <Queue <PhaseElement> > GetElemets(Phase phase) { List <Queue <PhaseElement> > result = new List <Queue <PhaseElement> >(); Queue <PhaseElement> phaseElementSequences; foreach (MatrixElement phaseMatrixElement in phase.MatrixElements) { phaseElementSequences = new Queue <PhaseElement>(); PhaseElement phaseSequenceElement = new PhaseElement(phaseMatrixElement.ElementId); bool elementSequenceStarted = false; for (int i = 0; i < matrix.Packages.Count; i++) { if (matrix.GetMatrix[phaseMatrixElement.ElementId, i] == true) { elementSequenceStarted = true; if (phaseSequenceElement.PhaseElementStartIndex == -1) { phaseSequenceElement.PhaseElementStartIndex = i; } phaseSequenceElement.PhaseElementStopIndex = i; } else { if (elementSequenceStarted == true) { phaseElementSequences.Enqueue(phaseSequenceElement); phaseSequenceElement = new PhaseElement(phaseMatrixElement.ElementId); elementSequenceStarted = false; } } } if (elementSequenceStarted == true) { phaseElementSequences.Enqueue(phaseSequenceElement); phaseSequenceElement = new PhaseElement(phaseMatrixElement.ElementId); } if (phaseElementSequences.Count == 0) { result = null; break; } else { result.Add(phaseElementSequences); } } return(result); }
protected override ServiceOutcome DoWork() { // ---------------------- // PHASE HANDLER string phase = Instance.Configuration.Options["Phase"]; if (String.IsNullOrEmpty(phase)) throw new ConfigurationException( "'Phase' option was not passed to the service."); if (!Instance.Configuration.ExtendedElements.ContainsKey("Phases")) throw new ConfigurationException( "No phases defined in configuration, cannot run checksum."); PhaseElementCollection phasesList = (PhaseElementCollection)Instance.Configuration.ExtendedElements["Phases"]; PhaseElement phaseConfig = phasesList[phase]; if (phaseConfig == null) throw new ConfigurationException(String.Format( "Specified phase '{0}' is not defined in the configuration.", phase)); Type handlerType = Type.GetType(phaseConfig.HandlerType, false); if (handlerType == null) throw new ConfigurationException(String.Format( "Handler type for phase '{0}' was not found.", phase)); // Create the phase handler PhaseHandler handler; try { handler = (PhaseHandler) Activator.CreateInstance(handlerType); } catch (Exception ex) { throw new Exception( "Failed to create phase handler.", ex); } handler.Instance = this.Instance; // ---------------------- // TEST // Run all processing inside a single connection using (DataManager.Current.OpenConnection()) { // Get or create a new test Test test; string raw_testID = Instance.Configuration.Options["TestID"]; if (!String.IsNullOrEmpty(raw_testID)) { // Resume test Exception ex = ConfigurationException(String.Format( "Specified test ID {0} does not exist.", raw_testID)); int testID; try { testID = Int32.Parse(raw_testID); } catch { throw ex; } test = Test.GetByID(testID); if (test == null) throw ex; } else { // New test string testTypeName = Instance.Configuration.Options["TestType"]; TestType testType = TestType.GetByName(testTypeName); if (testType == null) throw new ConfigurationException(String.Format( "Specified test type '{0}' does not exist.", testTypeName)); test = new Test(testType); } // Init handler and add any metadata handler.Test = test; try { handler.Init(); } catch (Exception ex) { throw new Exception( "Failed to initialize the phase handler.", ex); } // Save the test to get a valid test ID try { test.Save(); } catch (Exception ex) { throw new Exception( "Failed to update the Test metadata.", ex); // Allow the handler to prepare any data it needs for processing try { handler.Prepare(); } catch (Exception ex) { throw new Exception( "Error while preparing the execution phase.", ex); } return ServiceOutcome.Failure; } } }