Beispiel #1
0
        private static string SaveCheckRunArtifact(string fullPath, XDocument cra)
        {
            const string ArtifactFileNameExtension = "xml";
            const string ArtifactFileNameRoot      = "CheckRunArtifact";
            string       checkMethodRunGuid        = DataAccessors.GetCheckRunValue(cra, DataStringConstants.NameAttributeValues.CheckRunGuid);

            string fileName = string.Format(
                "{0}_{1}.{2}",
                ArtifactFileNameRoot,
                checkMethodRunGuid,
                ArtifactFileNameExtension);

            cra.Save(Path.Combine(fullPath, fileName));

            /// BEGIN DEBUG temporary debugging code follows
            /// save extra copy of the same file in
            //const string relativePathToTempCopy = @"..\..\tempcopy";
            //string tempPath = Path.Combine(fullPath, relativePathToTempCopy);
            //string[] pathComponents = fullPath.Split(Path.DirectorySeparatorChar);
            //int pathComponentCount = pathComponents.Length;
            //string tempFileName = string.Format("{0}_{1}_{3}.{2}", pathComponents[pathComponentCount - 2], pathComponents[pathComponentCount - 1], ArtifactFileNameExtension, fileCounter++);
            //cra.Save(Path.Combine(@"c:\t2", tempFileName), SaveOptions.None);
            /// END DEBUG

            return(fileName);
        }
Beispiel #2
0
        /// <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)
        {
            // This identifier is used for the named semaphore that synchronizes for the cross-process, cross-machine check run
            string uniqueLabelForCheckRunSegment = CheckRunDataHandles.CreateIdFromCrxXDocument(checkRunLaunch);
            string semaphoreServiceSideUser      = Environment.UserName;
            string semaphoreTimeoutString        = DataAccessors.GetCheckRunValue(checkRunLaunch, DataStringConstants.NameAttributeValues.SemaphoreTimeoutMilliseconds);

            int semaphoreTimeoutMS = 0;

            try
            {
                semaphoreTimeoutMS = int.Parse(semaphoreTimeoutString);
            }
            catch (Exception ex)
            {
                throw new CheckInfrastructureClientException(string.Format("Parse failed for the configured SemaphoreTimeoutMilliseconds string '{0}'. See InnerException", semaphoreTimeoutString), ex);
            }

            // Create semaphore with modification rights for the test user
            Semaphore checkRunSemaphore = MetaAutomationClientStLibrary.Synchronization.CreateAndGetNamedSemaphore(semaphoreServiceSideUser, uniqueLabelForCheckRunSegment);

            string startResult = m_MetaAutomationLocal.StartCheckRun(checkRunLaunch.ToString());


            if (startResult != MetaAutomationBaseStLibrary.DataStringConstants.StatusString.DefaultServiceSuccessMessage)
            {
                throw new CheckInfrastructureClientException(string.Format("StartCheckRun failed with error '{0}'", startResult));
            }

            bool receivedSignal = checkRunSemaphore.WaitOne(semaphoreTimeoutMS);

            string    resultString = null;
            XDocument resultCRA    = null;

            try
            {
                if (receivedSignal)
                {
                    resultString = m_MetaAutomationLocal.GetCheckRunArtifact(uniqueLabelForCheckRunSegment);

                    resultCRA = DataValidation.Instance.ValidateCheckRunArtifactIntoXDocument(resultString);
                }
                else
                {
                    throw new CheckRunException(string.Format("A semaphore waiting on completion of a sub-check timed out at the configured '{0}' milliseconds.", semaphoreTimeoutMS));
                }
            }
            catch (CheckInfrastructureClientException)
            {
                throw;
            }
            catch (Exception ex)
            {
                string abortMessage = m_MetaAutomationLocal.GetAbortMessage(uniqueLabelForCheckRunSegment);

                throw new CheckInfrastructureClientException(string.Format("Check run failed with error '{0}'. The abort message is '{1}'. See InnerException.", resultString, abortMessage), ex);
            }

            return(resultCRA);
        }
        public string StartCheckRun(XDocument checkRunLaunch)
        {
            string pathAndFileNameForExe = DataAccessors.GetCheckRunValue(checkRunLaunch, DataStringConstants.NameAttributeValues.PathAndFileToRunner);

            if (!Path.IsPathRooted(pathAndFileNameForExe))
            {
                // path is relative path. Add environment current directory
                pathAndFileNameForExe = Path.Combine(Environment.CurrentDirectory, pathAndFileNameForExe);
            }

            // Store the CRL temporarily on the local machine, because this is the server machine
            string uniqueLabelForCheckRunSegment = CrxDepot.Instance.SetCrlXDocument(checkRunLaunch);

            // STart the check run or sub-check run
            CheckRunLocal checkRunLocal = new CheckRunLocal();

            return(checkRunLocal.Start(uniqueLabelForCheckRunSegment, pathAndFileNameForExe));
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        // 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;
                }
            }
        }
Beispiel #6
0
        /// <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)
        {
            // Always set the root CheckRunData/DataElement[@Name='OriginMachine'] to value EnvironmentMachineName,
            //  so it's clear on which machine/OS instance the named semaphore is stored
            string xPathToOriginMachineDataElement = string.Format(
                "{0}/{1}[@{2}='{3}']",
                DataStringConstants.ElementNames.CheckRunData,
                DataStringConstants.ElementNames.DataElement,
                DataStringConstants.AttributeNames.Name,
                DataStringConstants.NameAttributeValues.OriginMachine);

            // skip the null-checks because they are unnecessary; the schema enforces this
            XElement   originMachineElement = checkRunLaunch.Root.XPathSelectElement(xPathToOriginMachineDataElement);
            XAttribute originAttribute      = originMachineElement.Attribute(DataStringConstants.AttributeNames.Value);

            originAttribute.Value = Environment.MachineName;

            // This identifier is used for the named semaphore that synchronizes for the cross-process, cross-machine check run
            string uniqueLabelForCheckRunSegment = CheckRunDataHandles.CreateIdFromCrxXDocument(checkRunLaunch);
            string semaphoreServiceSideUser      = DataAccessors.GetCheckRunValue(checkRunLaunch, DataStringConstants.NameAttributeValues.ThreadPoolUserName);
            string semaphoreTimeoutString        = DataAccessors.GetCheckRunValue(checkRunLaunch, DataStringConstants.NameAttributeValues.SemaphoreTimeOutMilliseconds);

            int semaphoreTimeoutMS = 0;

            try
            {
                semaphoreTimeoutMS = int.Parse(semaphoreTimeoutString);
            }
            catch (Exception ex)
            {
                throw new CheckInfrastructureClientException(string.Format("Parse failed for the configured SemaphoreTimeOutMilliseconds string '{0}'. See InnerException", semaphoreTimeoutString), ex);
            }

            // Create semaphore with modification rights for the test user
            Semaphore checkRunSemaphore = MetaAutomationClientMtLibrary.Synchronization.CreateAndGetNamedSemaphore(semaphoreServiceSideUser, uniqueLabelForCheckRunSegment);

            string startResult = m_MetaAutomationServiceClient.StartCheckRun(checkRunLaunch.ToString());

            if (startResult != MetaAutomationBaseMtLibrary.DataStringConstants.StatusString.DefaultServiceSuccessMessage)
            {
                throw new CheckInfrastructureClientException(string.Format("StartCheckRun failed with error '{0}'", startResult));
            }

            bool receivedSignal = checkRunSemaphore.WaitOne(semaphoreTimeoutMS);

            string    resultString = null;
            XDocument resultCRA    = null;

            try
            {
                if (receivedSignal)
                {
                    resultString = m_MetaAutomationServiceClient.GetCheckRunArtifact(uniqueLabelForCheckRunSegment);

                    resultCRA = DataValidation.Instance.ValidateCheckRunArtifactIntoXDocument(resultString);
                }
                else
                {
                    throw new CheckRunException(string.Format("A semaphore waiting on completion of a sub-check timed out at the configured '{0}' milliseconds.", semaphoreTimeoutMS));
                }
            }
            catch (CheckInfrastructureClientException)
            {
                throw;
            }
            catch (Exception ex)
            {
                string abortMessage = m_MetaAutomationServiceClient.GetAbortMessage(uniqueLabelForCheckRunSegment);

                throw new CheckInfrastructureClientException(string.Format("Check run failed with error '{0}'. The abort message is '{1}'. See InnerException.", resultString, abortMessage), ex);
            }

            return(resultCRA);
        }
 public string GetDestinationMachineName(System.Xml.Linq.XDocument checkRun)
 {
     return(DataAccessors.GetCheckRunValue(checkRun, DataStringConstants.NameAttributeValues.DestinationMachine));
 }
        public bool IsDestinationMachineLocalInstance(System.Xml.Linq.XDocument checkRun)
        {
            string destinationMachine = DataAccessors.GetCheckRunValue(checkRun, DataStringConstants.NameAttributeValues.DestinationMachine);

            return(destinationMachine.ToUpper() == System.Net.Dns.GetHostName().ToUpper());
        }
        public bool IsOriginMachineLocalInstance(System.Xml.Linq.XDocument crl)
        {
            string originMachine = DataAccessors.GetCheckRunValue(crl, DataStringConstants.NameAttributeValues.OriginMachine);

            return(originMachine.ToUpper() == System.Net.Dns.GetHostName().ToUpper());
        }