예제 #1
0
        public static XElement CreateXTestResult(TestResultType resultType, string message, Exception ex, params object[] xcontent)
        {
            XElement xresult = new XElement(XTestResultNames.TestResult
                                            , new XAttribute(XTestResultNames.ATestResultType, resultType)
                                            , new XAttribute(XTestResultNames.AExitCode, (int)resultType)
                                            , new XElement(XTestResultNames.ResultMessage, message ?? resultType.ToString())
                                            , ex == null ? null : XNames.CreateXError(ex)
                                            );

            xresult.Add(xcontent);

            return(xresult);
        }
예제 #2
0
        private void CompleteWithError(Exception ex)
        {
            Debug.Assert(ex != null);
            ErrorEx = ex;

            // Create the node and add it to our state xml
            var xerror = XNames.CreateXError(ex);

            XTaskState.Add(xerror);

            IsComplete = true;
            Status     = AppTaskStatus.Error;

            OnCompletedWithError();
        }
예제 #3
0
        public static XDocument ReadTestContainerInSeperateProcess(string assemblyLocation)
        {
            string assyXml;
            string errMsg;

            assemblyLocation = Path.GetFullPath(assemblyLocation);
            string assyFolderPath = Path.GetDirectoryName(assemblyLocation);

            if (!Directory.Exists(assyFolderPath))
            {
                assyXml = TestAssemblyReader.CreateXTestAssemblyPlaceholder(assemblyLocation).ToString();
                errMsg  = null;
            }
            else
            {
                using (Process p = new Process())
                {
                    p.StartInfo = new ProcessStartInfo(MCutToolsUtil.MCutExecutableFilePath)
                    {
                        WorkingDirectory       = assyFolderPath,
                        Arguments              = String.Format("getTestListFromAssembly \"{0}\"", Path.GetFileName(assemblyLocation)),
                        CreateNoWindow         = true,
                        UseShellExecute        = false,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true,
                    };
                    p.Start();

                    assyXml = p.StandardOutput.ReadToEnd();
                    errMsg  = p.StandardError.ReadToEnd();
                    p.WaitForExit();
                }
            }

            if (String.IsNullOrWhiteSpace(errMsg))
            {
                return(XDocument.Parse(assyXml, LoadOptions.SetLineInfo));
            }
            else
            {
                return(new XDocument(XNames.CreateXError(errMsg)));
            }
        }
예제 #4
0
        internal Session(Model model, string sessionFilePath, string backupFilename)
        {
            this.model = model;

            _filePath = sessionFilePath;
            string folderPath = Path.GetDirectoryName(_filePath);

            _backupFilePath = Path.Combine(folderPath, backupFilename);

            if (File.Exists(_filePath))
            {
                //if (new FileInfo(_filePath).IsReadOnly)
                //    Console.Error.WriteLine("session file (in current directory) must be writable");
                model.xdocument = XDocument.Load(_filePath);
            }
            else
            {
                model.xdocument = new XDocument(
                    new XElement(XSessionNames.Session
                                 , XNames.CreateXmlnsAttribute(true)
                                 , XSessionNames.CreateXmlnsAttribute(false)
                                 , XChessNames.CreateXmlnsAttribute(false)
                                 ));
                model.xdocument.Save(_filePath);
            }

            //var backupFile = new FileInfo(_backupFilePath);
            //if(backupFile.Exists && backupFile.IsReadOnly)
            //    Console.Error.WriteLine("session backup file (" + backupFilename + " in current directory) must be writable");

            ValidateSessionXml();

            // Setup entities for existing elements before given a chance for the UI to respond.
            XElement xsession = model.xdocument.Root;

            if (xsession.Name != XSessionNames.Session)
            {
                throw new Exception("Invalid session file.");
            }
            Entity = (SessionEntity)model.EntityBuilder.CreateEntityAndBindToElement(xsession);
            Entity.InitializeSessionEntity(_filePath);
            Entity.LoadChildren(true);
        }
예제 #5
0
        private static int WriteTestAssemblyXml(string assemblyFilePath)
        {
            XElement xtestAssy = null;

            try
            {
                var assyReader = new TestAssemblyReader(assemblyFilePath);
                xtestAssy = assyReader.Read();
            }
            catch (Exception ex)
            {
                xtestAssy = XNames.CreateXError(ex);
            }

            using (XmlWriter w = XmlWriter.Create(Console.Out))
            {
                if (xtestAssy != null)
                {
                    xtestAssy.WriteTo(w);
                }
            }

            return(0);
        }
예제 #6
0
        public bool TryLoadProjectFile()
        {
            // Remove our previous error
            // It's not in the try-catch because any error is due to other code, not due to a loading failure.
            if (ProjectLoadError != null)
            {
                ProjectLoadError.DataElement.Remove();
            }

            XElement xmsbProj = null;
            XElement xerror   = null;

            try
            {
                xmsbProj = MSBuildProject.ParseProjectFileToXElement(SourceFilePath);
                if (xmsbProj == null)
                {
                    xerror = XNames.CreateXError("Project file could not be found.");
                }

                // Replace existing element or add it
                // Note: The element isn't an entity
                if (_msbuildProj != null)
                {
                    // We replace so the order of the child elements are preserved (i.e. if a TestAssembly el also exists)
                    Debug.Assert(_msbuildProj.DataElement.Parent == this.DataElement);

                    // move the previous runs to the new project element
                    var prevRuns = _msbuildProj.DataElement.Elements(XSessionNames.BuildRun).ToArray();
                    foreach (var prevRun in prevRuns)
                    {
                        prevRun.Remove();
                        xmsbProj.Add(prevRun);
                    }

                    //
                    _msbuildProj.DataElement.ReplaceWith(xmsbProj);
                }
                else
                {
                    DataElement.Add(xmsbProj);
                }

                // create the new one
                _msbuildProj = new MSBuildProject(xmsbProj);
            }
            catch (Exception ex)
            {
                xerror = XNames.CreateXError("An error occurred trying to parse the project file.", ex);
            }

            if (xerror != null)
            {
                // Clear out the existing extra elements if they exist
                var elementsToRemove = DataElement.Elements(XSessionMSBuildNames.Project, XNames.TestAssembly, XNames.Include);
                foreach (var xel in elementsToRemove)
                {
                    xel.Remove();
                }

                // Add the error and then eject
                this.AddEntity <ErrorEntity>(xerror);
                return(false);
            }

            // Make sure we use the correct configuration name
            if (Configuration != null && !_msbuildProj.Configurations.Any(cfg => cfg.Configuration == Configuration))
            {
                Configuration = null; // Reset to use the default configuration
            }
            else  // Call the changed event manually so we get a new ProjectConfiguration obj that's part of the new MSBuildProject instance
            {
                OnConfigurationChanged();
            }

            return(true);
        }