/// <summary> /// Runs a check to completion, or throws an exception /// </summary> /// <param name="checkRunLaunch">The check run launch (CRL) object</param> /// <returns>The check run artifact (CRA)</returns> public XDocument Run(XDocument checkRunLaunch) { string targetCheckMethodGuid = DataAccessors.GetCheckRunValue(checkRunLaunch, DataStringConstants.NameAttributeValues.CheckMethodGuid); Type targetType = null; MethodInfo targetMethod = null; string methodNameGivenInAttribute = string.Empty; string checkAssemblyName = "CheckMethods.dll"; Assembly checkAssembly = Assembly.LoadFile(Path.Combine(Environment.CurrentDirectory, checkAssemblyName)); this.GetMethodAndType(targetCheckMethodGuid, checkAssembly.GetTypes(), out targetMethod, out targetType, out methodNameGivenInAttribute); // Create instance object testObject = Activator.CreateInstance(targetType); // Initialize MetaAutomation client lib CheckArtifact checkArtifact = Check.CheckArtifactInstance; checkArtifact.InitializeCheckRunFromCheckRunLaunch(checkRunLaunch); string methodStepName = string.Format("Method {0}", methodNameGivenInAttribute); try { checkArtifact.DoStep(methodStepName, delegate { // Run the test method synchronously targetMethod.Invoke(testObject, null); }); } catch (Exception ex) { checkArtifact.AddCheckExceptionInformation(ex); } XDocument craXdoc = checkArtifact.CompleteCheckRun(); return(craXdoc); }
// on server side: id -> CRL -> CRA -> returns through service // loads assembly, finds check method, invokes it public void Run(string[] argumentsFromServiceLaunch) { string uniqueLabelForCheckRunSegment = null; try { if ((argumentsFromServiceLaunch == null) || (argumentsFromServiceLaunch.Length == 0)) { throw new CheckRunException("Zero arguments received by Run method on the destination side. One is required: the CRI string to identify the check segment."); } uniqueLabelForCheckRunSegment = argumentsFromServiceLaunch[0]; string checkRunLaunchString = m_MetaAutomationLocal.GetCheckRunLaunch(uniqueLabelForCheckRunSegment); XDocument checkRunLaunch = DataValidation.Instance.ValidateCheckRunLaunchIntoXDocument(checkRunLaunchString); string targetCheckMethodGuid = DataAccessors.GetCheckRunValue(checkRunLaunch, DataStringConstants.NameAttributeValues.CheckMethodGuid); string checkAssemblyName = DataAccessors.GetCheckRunValue(checkRunLaunch, DataStringConstants.NameAttributeValues.CheckLibraryAssembly); Assembly checkAssembly = Assembly.LoadFile(Path.Combine(Environment.CurrentDirectory, checkAssemblyName)); Type targetType = null; MethodInfo targetMethod = null; string methodNameGivenInAttribute = string.Empty; this.GetMethodAndType(targetCheckMethodGuid, checkAssembly.GetTypes(), out targetMethod, out targetType, out methodNameGivenInAttribute); if ((targetMethod == null) || (targetType == null)) { string pathToLaunch = DataAccessors.GetCheckRunValue(checkRunLaunch, DataStringConstants.NameAttributeValues.PathAndFileToRunner); throw new CheckInfrastructureClientException(string.Format("The check method was not found. File path='{0}', current directory='{1}', check assembly='{2}', target type='{3}', method GUID='{4}'.", pathToLaunch, Environment.CurrentDirectory, checkAssemblyName, targetType, targetCheckMethodGuid)); } // Create instance object testObject = Activator.CreateInstance(targetType); // Initialize MetaAutomation client lib CheckArtifact checkArtifact = Check.CheckArtifactInstance; checkArtifact.InitializeCheckRunFromCheckRunLaunch(checkRunLaunch, new CheckConstants.RunSubCheckDelegate(Run)); string methodStepName = string.Format("Method {0}", methodNameGivenInAttribute); try { checkArtifact.DoStep(methodStepName, delegate { // Run the test method synchronously targetMethod.Invoke(testObject, null); }); } catch (Exception ex) { checkArtifact.AddCheckExceptionInformation(ex); } XDocument craXdoc = checkArtifact.CompleteCheckRun(); m_MetaAutomationLocal.CompleteCheckRun(craXdoc.ToString()); } catch (Exception ex) { if (uniqueLabelForCheckRunSegment != null) { m_MetaAutomationLocal.AbortCheckRun(uniqueLabelForCheckRunSegment, ex.ToString()); throw new CheckInfrastructureClientException("Check was aborted.", ex); } else { throw ex; } } }