Пример #1
0
        /// <summary>
        /// Parses a given error file and translates the data to a list of ErrorWarningCodes objects.
        /// </summary>
        /// <param name="errorfilename"></param>
        /// <returns></returns>
        internal bool Parse(string errorfilename)
        {
            if (errorfilename == null)
            {
                MSBuildEngineCommonHelper.LogDiagnostic = "Error file was not specified";
                return(false);
            }

            try
            {
                XmlDocumentSW doc = new XmlDocumentSW();

                doc.Load(errorfilename);
                if (doc.DocumentElement.Name != Constants.ErrorRootElement)
                {
                    MSBuildEngineCommonHelper.LogError = "Invalid Error codes file.";
                    return(false);
                }

                Parse(doc.DocumentElement);
            }
            catch (XmlException xex)
            {
                MSBuildEngineCommonHelper.DisplayExceptionInformation(xex);
                return(false);
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Read Variation data based on xmlfile.
        /// </summary>
        /// <param name="xmldatafile"></param>
        /// <returns></returns>
        public virtual bool Read(string xmldatafile)
        {
            bool returnvalue = false;

            xmldatafile = CommonHelper.VerifyFileExists(xmldatafile);
            if (String.IsNullOrEmpty(xmldatafile))
            {
                throw new System.IO.FileNotFoundException(xmldatafile + " could not be found");
            }

            try
            {
                Console.WriteLine("Reading {0} file", xmldatafile);
                XmlDocumentSW defaultDoc = new XmlDocumentSW();
                defaultDoc.Load(xmldatafile);

                returnvalue = this.Read((XmlNodeSW)defaultDoc);
                UtilsLogger.LogDiagnostic = "Read returned value = " + returnvalue;
            }
            catch (XmlException xex)
            {
                UtilsLogger.LogDiagnostic = "Reading data file caused an Exception";
                throw xex;
            }

            return(returnvalue);
        }
Пример #3
0
        protected virtual void GenerateFile(ref XmlDocumentSW finalxmldocument)
        {
            // Unautorized exception can occur
            // Now vardoc only contains relevant data.
            XmlNodeReaderSW xnr = new XmlNodeReaderSW((XmlNode)finalxmldocument.InnerObject);
            XmlTextWriterSW xtr = null;

            Console.Write("Generating {0} file .", generatedFile);
            System.Text.Encoding currentencoding = System.Text.Encoding.ASCII;

            if (CommonHelper.FileModified)
            {
                currentencoding = System.Text.Encoding.Unicode;
            }

            xtr = new XmlTextWriterSW(generatedFile, currentencoding);

            // Generate file
            if (xtr != null)
            {
                Console.Write(".");
                xtr.Flush();
                xtr.Formatting  = Formatting.Indented;
                xtr.Indentation = 4;
                xtr.WriteNode((XmlNodeReader)xnr.InnerObject, true);
                xnr.Close();
                //				vardoc.GetElementsByTagName(Macros.TemplateDataElement)[0].WriteContentTo(xtr);
                xtr.Close();
                Console.WriteLine(". Done");
            }
        }
Пример #4
0
        /// <summary>
        /// Dispose objects that are not required anymore.
        /// </summary>
        public virtual void Dispose()
        {
            _dd             = null;
            scenarios       = null;
            _scenariolist   = null;
            currentScenario = null;

            canvasdoc       = null;
            placeholdernode = null;
            variationids    = null;
        }
Пример #5
0
        /// <summary>
        /// Read Scenarios from a file.
        /// </summary>
        /// <param name="xmlfile"></param>
        private void ReadScenarios(string xmlfile)
        {
            xmlfile = CommonHelper.VerifyFileExists(xmlfile);
            if (String.IsNullOrEmpty(xmlfile))
            {
                throw new FileNotFoundException(xmlfile + " could not be found");
            }

            XmlDocumentSW scenariosdoc = new XmlDocumentSW();

            scenariosdoc.Load(xmlfile);

            Console.WriteLine("Reading include Scenarios file {0}", xmlfile);

            ReadScenarios((XmlNode)scenariosdoc.DocumentElement);
        }
Пример #6
0
        /// <summary>
        /// Read input file for Variation steps.
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public bool Read(string filename)
        {
            filename = Microsoft.Test.MSBuildEngine.MSBuildEngineCommonHelper.VerifyFileExists(filename);
            if (filename == null)
            {
                throw new NullReferenceException("Input file name is null");
            }

            XmlDocumentSW xmldoc = new XmlDocumentSW();

            xmldoc.Load(filename);

            if (xmldoc.DocumentElement == null)
            {
                throw new ArgumentException("The file " + filename + " does not have a document element");
            }

            return(this.Read((XmlNode)xmldoc.DocumentElement));
        }
Пример #7
0
        /// <summary>
        /// Save Default document data from file into XmlNode.
        /// </summary>
        /// <param name="xmlfile"></param>
        private void LoadDocument(string xmlfile)
        {
            UtilsLogger.LogDiagnostic = "TemplateData: Read - Begin";
            string tempfile = CommonHelper.VerifyFileExists(xmlfile);

            if (tempfile == null)
            {
                throw new System.IO.FileNotFoundException(xmlfile + "Could not be found");
            }

            XmlDocumentSW temp = new XmlDocumentSW();

            temp.Load(tempfile);

            XmlNode defaultdatanode = (XmlNode)temp.DocumentElement;

            LoadDocument(defaultdatanode);

            temp            = null;
            defaultdatanode = null;
        }
Пример #8
0
        protected override void GenerateFile(ref XmlDocumentSW finalxmldocument)
        {
            if (finalxmldocument == null)
            {
                return;
            }

            if (finalxmldocument.DocumentElement.Name.ToLowerInvariant() == "project")
            {
                string commentdata = " Generated by XVariation. \n";
                commentdata += "Project File Commandline arguments = " + commandlineargs + "\n";
                commentdata += "Project File Expected Warnings Codes = " + warningcode + "\n";
                commentdata += "Project File Expected Errors Codes = " + errorcode + "\n";

                XmlComment commentelement = finalxmldocument.CreateComment(commentdata);
                finalxmldocument.AppendChild(commentelement);

                bisprojectfile = true;
            }

            base.GenerateFile(ref finalxmldocument);
        }
Пример #9
0
        /// <summary>
        /// Generates and compiles the application.
        /// </summary>
        /// <param name="xamlFiles">The first in this array is main page.</param>
        /// <param name="hostType">Host type. Could be Application</param>
        /// <param name="uiCulture"></param>
        /// <param name="extraFiles"></param>
        /// <param name="supportingAssemblies"></param>
        /// <param name="language"></param>
        /// <param name="additionalAppMarkup"></param>
        /// <param name="resources"></param>
        /// <param name="contents"></param>
        /// <param name="debugBaml"></param>
        public void CompileApp(string[] xamlFiles, string hostType, string uiCulture, List <string> extraFiles, List <string> supportingAssemblies, Languages language, string additionalAppMarkup, List <Resource> resources, List <Content> contents, bool debugBaml)
        {
            // Cleanup temp. Xaml file, if necessary.
            string _tempXamlFile = "__XamlTestRunnerTempFile.xaml";

            if (FileSW.Exists(_tempXamlFile))
            {
                FileSW.Delete(_tempXamlFile);
            }



            // Some Xaml files (e.g. those which contain events, <x:Code>, x:Name attributes etc.)
            // need to specify an x:Class attribute on the root tag. We add that here.
            string xClassName = "MySubclass";

            // Load the original Xaml file into a DOM tree, add x:Class attribute to the root element,
            // and then save the DOM tree into a temporary Xaml file
            XmlDocumentSW doc = new XmlDocumentSW();

            doc.PreserveWhitespace = true;
            doc.Load(xamlFiles[0]);


            XmlElement rootElement = doc.DocumentElement;

            if (AddClassAttribute)
            {
                rootElement.SetAttribute("Class", "http://schemas.microsoft.com/winfx/2006/xaml", xClassName);
            }

            if (rootElement.NamespaceURI.IndexOf("schemas.microsoft.com") != -1) //&& !verifierFound)
            {
                AutoCloseWindow = true;
            }

            doc.Save(_tempXamlFile);

            xamlFiles[0] = _tempXamlFile;

            GlobalLog.LogStatus("Start compilation...");

            // Generate app definition file.
            GlobalLog.LogStatus("Generate app definition file...");
            GenerateAppdef(_tempXamlFile, hostType, "winexe", language, additionalAppMarkup);


            CompilerParams compilerParams = new CompilerParams(true);

            //
            // Generate the 'proj' file.
            //
            GlobalLog.LogStatus("Generate project file...");
            foreach (string xamlFile in xamlFiles)
            {
                compilerParams.XamlPages.Add(xamlFile);
            }

            compilerParams.OutputType            = "winexe";
            compilerParams.ApplicationDefinition = _appDefFileName;
            compilerParams.AssemblyName          = _assemblyName;
            compilerParams.RootNamespace         = "Avalon.Test.CoreUI.Parser.MyName";
            compilerParams.Language = language;

            // Put debugging info (line,position) in Baml.
            if (debugBaml)
            {
                compilerParams.XamlDebuggingInformation = true;
            }

            if (uiCulture != null)
            {
                compilerParams.UICulture = uiCulture;
            }

            // Add extraFiles.  They should be either xaml files or code files.
            for (int i = 0; extraFiles != null && i < extraFiles.Count; i++)
            {
                string fileName = extraFiles[i];

                if (PathSW.GetExtension(fileName) == "xaml")
                {
                    compilerParams.XamlPages.Add(fileName);
                }
                else
                {
                    compilerParams.CompileFiles.Add(fileName);
                }
            }

            // Add code-behind files if they exist and they weren't in the extraFiles.
            // Always assume they should be added.
            for (int i = 0; i < compilerParams.XamlPages.Count; i++)
            {
                string fileName = compilerParams.XamlPages[i] + ".cs";

                if (FileSW.Exists(fileName) && !compilerParams.CompileFiles.Contains(fileName))
                {
                    compilerParams.CompileFiles.Add(fileName);
                }
            }

            // Add supporting assemblies, if any, as references
            if (null != supportingAssemblies)
            {
                string currentDirectory = EnvironmentSW.CurrentDirectory;
                for (int i = 0; i < supportingAssemblies.Count; i++)
                {
                    string assemblyName = supportingAssemblies[i];
                    compilerParams.References.Add(new Reference(assemblyName, currentDirectory + "\\" + assemblyName + ".dll"));
                }
            }


            if (References.Count > 0)
            {
                compilerParams.References.AddRange(References);
            }

            // Add Resources, if any
            if (null != resources)
            {
                foreach (Resource r in resources)
                {
                    compilerParams.Resources.Add(r);
                }
            }

            // Add Contents, if any
            if (null != contents)
            {
                foreach (Content c in contents)
                {
                    compilerParams.Contents.Add(c);
                }
            }

            // Also add any loose files specified by TestCaseInfo.SupportFiles
            //



            //TestDefinition td = TestDefinition.Current;
            //td.
            //if (currentTestCaseInfo != null)
            //{
            //    string[] currentSupportFiles = currentTestCaseInfo.SupportFiles;
            //    if (currentSupportFiles != null)
            //    {
            //        foreach (string fileName in currentSupportFiles)
            //        {
            //            compilerParams.Contents.Add(new Content(fileName, "Always"));
            //        }
            //    }
            //}

            //
            // Compile project.
            //
            GlobalLog.LogStatus("Compiling project...");
            Compiler compiler = new Compiler(compilerParams);
            List <ErrorWarningCode> buildErrorsAndWarnings = compiler.Compile(true);

            //
            // Check if Compiling project is successful by verifying that compiled app exists.
            //
            GlobalLog.LogStatus("Check if compiling project was successful...");
            GlobalLog.LogStatus("Check if the BAML and the compiled app both exist.");
            string bamlPath        = _objPath + PathSW.DirectorySeparatorChar + PathSW.ChangeExtension(xamlFiles[0], "baml");
            bool   compilerFailure = false;

            GlobalLog.LogStatus("Baml Path: " + bamlPath);
            if (!FileSW.Exists(bamlPath))
            {
                GlobalLog.LogEvidence("Baml file did not exist");
                compilerFailure = true;
            }
            GlobalLog.LogStatus("Compiled path: " + _compiledPath);
            if (!FileSW.Exists(_compiledPath))
            {
                GlobalLog.LogEvidence("Compiled path did not exist");
                compilerFailure = true;
            }

            if (compilerFailure)
            {
                //Save files to be used for debugging
                GlobalLog.LogStatus("Saving files used in compilation...");
                GlobalLog.LogFile("__CompilerServicesSave.proj");
                foreach (string file in compilerParams.XamlPages)
                {
                    GlobalLog.LogFile(file);
                }
                foreach (string file in compilerParams.CompileFiles)
                {
                    GlobalLog.LogFile(file);
                }
                // Get compilation error message
                string compileErrors   = "Errors: \n";
                string compileWarnings = "Warnings \n";
                if ((null != buildErrorsAndWarnings) && (buildErrorsAndWarnings.Count > 0))
                {
                    // The list contains both errors and warnings.
                    // Get the first error and get its description.
                    foreach (ErrorWarningCode errAndWarn in buildErrorsAndWarnings)
                    {
                        if (errAndWarn.Type == ErrorType.Error)
                        {
                            compileErrors += errAndWarn.Description + "\n";
                            GlobalLog.LogStatus("\nBuild Error Found - " + errAndWarn.Description + "\n");
                            break;
                        }
                        else
                        {
                            compileWarnings += errAndWarn.Description + "\n";
                            GlobalLog.LogStatus("\nWarning - " + errAndWarn.Description + "\n");
                        }
                    }
                }

                TestSetupException setupException = new TestSetupException("Compilation failed: " + compileErrors + compileWarnings);
                // Add the list of build errors and warnings as custom Exception data.
                // This can be used by callers to retrive the errors and warnings list.
                setupException.Data.Add("buildErrorsAndWarnings", buildErrorsAndWarnings);
                throw setupException;
            }
        }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xmldatafile"></param>
        public bool ReadPerfResultsFromFile(string xmldatafile)
        {
            if (String.IsNullOrEmpty(xmldatafile))
            {
                return(false);
            }

            FileStreamSW fs = new FileStreamSW(xmldatafile, System.IO.FileMode.Open);

            if (fs.Length == 0)
            {
                fs.Close();
                return(false);
            }
            fs.Close();

            XmlDocumentSW xmldoc = new XmlDocumentSW();

            xmldoc.Load(xmldatafile);

            XmlNode subresultnode = xmldoc.CreateElement(Constants.PerfSubResultElement);

            XmlAttribute attrib = xmldoc.CreateAttribute("NAME");

            string mainprojectfilename = null;

            for (int i = 0; i < xmldoc.DocumentElement.ChildNodes.Count; i++)
            {
                if (xmldoc.DocumentElement.ChildNodes[i].Name == PerfDatumElement)
                {
                    subresultnode.InnerXml += xmldoc.DocumentElement.ChildNodes[i].OuterXml;
                }

                if (xmldoc.DocumentElement.ChildNodes[i].NodeType == XmlNodeType.Comment)
                {
                    mainprojectfilename = xmldoc.DocumentElement.ChildNodes[i].Value;
                    attrib.Value        = "(" + ReportNode + ")";
                }
            }

            subresultnode.Attributes.Append(attrib);

            PerfSubResult psr = new PerfSubResult();

            psr.ReadSubResult(subresultnode);

            subresults = new Hashtable();
            subresults.Add(mainprojectfilename + psr.SubResultName, psr);

            XmlNodeList subresultslist = xmldoc.DocumentElement.GetElementsByTagName(Constants.PerfSubResultElement);

            if (subresultslist.Count == 0)
            {
                return(false);
            }

            List <string> projectslist = new List <string>();

            for (int i = 0; i < subresultslist.Count; i++)
            {
                psr = new PerfSubResult();
                if (psr.ReadSubResult(subresultslist[i]))
                {
                    subresults.Add(psr.SubResultName, psr);
                    if (projectslist.Contains(psr.ProjectFileName) == false)
                    {
                        projectslist.Add(psr.ProjectFileName);
                    }
                }
                psr = null;
            }

            perfresultslist = new Hashtable(projectslist.Count);

            for (int i = 0; i < projectslist.Count; i++)
            {
                PerfResult pr = new PerfResult();
                pr.projectname = projectslist[i];
                if (projectslist[i] == mainprojectfilename)
                {
                    bmainprojectfile = true;
                }

                IDictionaryEnumerator ide = subresults.GetEnumerator();
                while (ide.MoveNext())
                {
                    if (ide.Key.ToString().StartsWith(pr.projectname))
                    {
                        if (pr.subresults == null)
                        {
                            pr.subresults = new Hashtable();
                        }

                        pr.subresults.Add(ide.Key, ide.Value);
                    }
                }

                perfresultslist.Add(pr.projectname, pr);
            }

            return(true);
        }
Пример #11
0
        /// <summary>
        /// Apply a specific scenario to the current default data document.
        /// </summary>
        /// <param name="scenarioid"></param>
        /// <param name="desiredvariationids"></param>
        /// <returns></returns>
        internal bool ApplyScenario(string scenarioid, string[] desiredvariationids)
        {
            if (scenarioid == null)
            {
                UtilsLogger.LogDiagnostic = "Scenario ID is null";
                return(false);
            }

            if (_dd == null)
            {
                UtilsLogger.LogDiagnostic = "TemplateData object is null";
                return(false);
            }

            if (_dd.templatedataelement == null)
            {
                // Todo: ---
                UtilsLogger.LogDiagnostic = "TemplateData has not been tokenized";
                return(false);
            }

            if (scenarios == null)
            {
                UtilsLogger.LogDiagnostic = "Scenarios object is null";
                return(false);
            }

            canvasdoc = new XmlDocumentSW();
            string rootxml = null;

            if (_dd.rootelement != null)
            {
                tokendocumentnamespace = _dd.rootelement.NamespaceURI;

                rootxml  = "<" + Constants.TemplateDataElement;
                rootxml += " xmlns=\"" + tokendocumentnamespace + "\">";
                rootxml += "</" + Constants.TemplateDataElement + ">";
            }
            else
            {
                tokendocumentnamespace = "";
                rootxml  = "<" + Constants.TemplateDataElement + ">";
                rootxml += "</" + Constants.TemplateDataElement + ">";
            }

            if (_dd.bcontainsrootnodeelement)
            {
                if (_dd.templatedataelement.ChildNodes.Count != 1)
                {
                    throw new ApplicationException("No more than one RootNodeVariation can be specified");
                }

                tokendocumentnamespace = _dd.templatedataelement.ChildNodes[0].NamespaceURI;
            }

            canvasdoc.LoadXml(rootxml);
            canvasdoc.DocumentElement.InnerXml = _dd.templatedataelement.InnerXml;

            // Find the scenario ID from scenariolist.
            for (int i = 0; _scenariolist != null && i < _scenariolist.Count; i++)
            {
                if (_scenariolist[i].Case == scenarioid)
                {
                    currentScenario = _scenariolist[i];
                    break;
                }
            }

            if (currentScenario == null)
            {
                throw new ApplicationException("Could not find scenario with ID = " + scenarioid);
            }

            // Read variations relevant to that scenario.
            currentScenario.ReadVariations();

            variationids = new Hashtable();

            if (desiredvariationids != null && desiredvariationids.Length != 0)
            {
                for (int i = 0; i < desiredvariationids.Length; i++)
                {
                    variationids.Add(desiredvariationids[i], i);
                }
            }
            else
            {
                int count = 0;
                IDictionaryEnumerator enumerator = currentScenario.nodevariationList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    variationids.Add(((BaseVariation)enumerator.Value).ID, count++);
                }

                enumerator = currentScenario.textVariationList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    variationids.Add(((BaseVariation)enumerator.Value).ID, count++);
                }

                for (int i = 0; i < currentScenario.attributeVariationList.Count; i++)
                {
                    variationids.Add(((BaseVariation)currentScenario.attributeVariationList[i]).ID, count++);
                }
            }

            // Start applying those variations.
            if (canvasdoc.DocumentElement.ChildNodes.Count > 1)
            {
                List <XmlNode> nodelist = new List <XmlNode>(canvasdoc.DocumentElement.ChildNodes.Count);
                for (int i = 0; i < canvasdoc.DocumentElement.ChildNodes.Count; i++)
                {
                    nodelist.Add(canvasdoc.DocumentElement.ChildNodes[i]);
                }

                for (int i = 0; i < nodelist.Count; i++)
                {
                    RecurseTree(nodelist[i]);
                }

                nodelist = null;
            }
            else
            {
                RecurseTree(canvasdoc.DocumentElement);
            }

            if (currentScenario.unrecognizednodeslist != null && currentScenario.unrecognizednodeslist.Count > 0)
            {
                for (int i = 0; i < currentScenario.unrecognizednodeslist.Count; i++)
                {
                    if (ProcessUnRecognizedElements(currentScenario.unrecognizednodeslist[i]))
                    {
                        currentScenario.unrecognizednodeslist.Remove(currentScenario.unrecognizednodeslist[i]);
                        i--; // Reset back to one as one node was removed.
                    }
                }

                // Todo : Add code to specify that unrecognized code was found.
            }

            Cleanup();
            return(true);
        }
Пример #12
0
        public bool Read(XmlNodeSW datanode)
        {
            try
            {
                XmlDocumentSW defaultDoc = new XmlDocumentSW();
                defaultDoc.LoadXml(datanode.OuterXml);

                if (defaultDoc.DocumentElement.Name != Constants.XMLVariationTemplateElement)
                {
                    throw new ApplicationException(defaultDoc.DocumentElement.Name + " is not a supported root element");
                }

                // Check for Include Elements first
                // In this case if there are default data and Scenario elements they get ignored.
                if (defaultDoc.HasChildNodes == false && defaultDoc.DocumentElement.HasChildNodes)
                {
                    UtilsLogger.LogError = "Empty document specified";
                    return(false);
                }

                bool defaultdatafilespecified = false;
                bool scenariosfilespecified   = false;

                // Loop through the elements under the Document element and get information.
                // If there are duplicates found or there are overrides found do the right thing.
                for (int i = 0; i < defaultDoc.DocumentElement.ChildNodes.Count; i++)
                {
                    XmlNode currentnode = defaultDoc.DocumentElement.ChildNodes[i];
                    switch (currentnode.Name)
                    {
                    case Constants.IncludeElement:
                        // There are 2 types of Includes.
                        // Include - TemplateData & Scenarios.
                        // If both these are specified parse the files they point to.
                        // If duplicates are specified or more than one error out.
                        if (currentnode.Attributes.Count > 0)
                        {
                            if (currentnode.Attributes[Constants.TypeAttribute] == null)
                            {
                                UtilsLogger.LogError = "Include element does not have Attribute Type";
                                return(false);
                            }

                            string file = null;

                            // Read the Item attribute on the element which means the file to include.
                            if (currentnode.Attributes[Constants.TypeAttribute].Value == Constants.TemplateDataElement ||
                                currentnode.Attributes[Constants.TypeAttribute].Value == Constants.ScenariosElement)
                            {
                                // If current node contains attribute "TemplateData" or "Scenarios" get
                                // value of "Item" attribute which is a path to an xml file and load the xml.
                                string includefile = currentnode.Attributes["Item"].Value;
                                if (includefile == null)
                                {
                                    UtilsLogger.LogError = "Item attribute not specified on Include element";
                                    return(false);
                                }

                                file = CommonHelper.VerifyFileExists(includefile);
                                if (file == null)
                                {
                                    // Filenot found
                                    throw new FileNotFoundException("Could not find file - " + includefile);
                                }
                            }
                            else
                            {
                                UtilsLogger.LogError = "Use Either TemplateData or Scenarios.";
                                throw new NotSupportedException("Unsupported type - " + currentnode.Attributes[Constants.TypeAttribute].Value + " value.");
                            }

                            // Depending on Type attribute value get the defaultdatalist or scenariosdoc.
                            switch (currentnode.Attributes[Constants.TypeAttribute].Value)
                            {
                            case Constants.TemplateDataElement:
                                if (defaultdatafilespecified == false)
                                {
                                    ReadTemplateData(file);
                                    defaultdatafilespecified = true;
                                }
                                else
                                {
                                    throw new NotSupportedException("Cannot have multipe TemplateData include elements");
                                }
                                break;

                            case Constants.ScenariosElement:
                                if (scenariosfilespecified == false)
                                {
                                    ReadScenarios(file);
                                    scenariosfilespecified = true;
                                }
                                else
                                {
                                    throw new NotSupportedException("Cannot have multiple Scenario include elements");
                                }
                                break;

                            default:
                                Console.WriteLine("Include attribute equals {0}", currentnode.Attributes[Constants.TypeAttribute].Value);
                                throw new NotSupportedException("Include attribute Type does not equal \"TemplateData\" or \"Scenarios\".");
                            }
                        }
                        else
                        {
                            // Time for another error.
                            Console.WriteLine("No attributes found on the Include element");
                            return(false);
                        }
                        break;

                    case Constants.TemplateDataElement:
                        // Check if there was an include that already read the default data.

                        if (defaultdatafilespecified == false)
                        {
                            ReadTemplateData(currentnode);
                        }
                        else
                        {
                            Console.WriteLine("Ignoring TemplateData section in Xml document");
                        }
                        break;

                    case Constants.ScenariosElement:
                        // Check if there was an include that already read the Scenarios.
                        if (scenariosfilespecified == false)
                        {
                            ReadScenarios(currentnode);
                        }
                        else
                        {
                            Console.WriteLine("Ignoring Scenarios section in Xml document");
                        }
                        break;
                    }
                }

                if (_dd == null)
                {
                    throw new ApplicationException("No TemplateData node was found.");
                }

                if (scenarios == null)
                {
                    throw new ApplicationException("No Scenarios node was found.");
                }

                if (_dd != null && scenarios != null)
                {
                    DoDeepCopy();
                }
            }
            catch (XmlException ex)
            {
                // Get Exception Message and print.
                UtilsLogger.DisplayExceptionInformation(ex);
                return(false);
            }

            return(true);
        }
Пример #13
0
        /// <summary>
        /// Encapsulated method - taking 3 input params
        /// Does the file generation.
        /// First based on inputs decides the final file name for the file to be generated.
        /// </summary>
        /// <param name="scenarioid"></param>
        /// <param name="variationstring"></param>
        private void GenerateFile(string scenarioid, string variationstring)
        {
            // If no scenarioid is defined set to all.
            if (scenarioid == null)
            {
                scenarioid = "_all";
            }

            // If newfiledata is null make a bunch of checks to come up with final name and fileextension.
            FileData tempfiledata = definedfiledata;

            if (String.IsNullOrEmpty(tempfiledata.FileName))
            {
                // Use default filename (defined in Attribute or element in TemplateData). Refer GetTemplateData method.
                tempfiledata.FileName = defaultfiledata.FileName;
            }

            if (String.IsNullOrEmpty(tempfiledata.FileExtension))
            {
                // Use default fileextension (defined in Attribute or element in TemplateData). Refer GetTemplateData method.
                tempfiledata.FileExtension = defaultfiledata.FileExtension;
            }

            // Generate XmlDocument with defaultdata document innerxml.
            if (base.canvasdoc == null)
            {
                UtilsLogger.LogError = "Variation document is null";
                return;
            }

            if (base.canvasdoc.GetElementsByTagName(Constants.TemplateDataElement) == null)
            {
                UtilsLogger.LogError = "Variation document did not contain TemplateData element";
                return;
            }

            if (base.canvasdoc.GetElementsByTagName(Constants.TemplateDataElement).Count > 1)
            {
                UtilsLogger.LogError = "Variation document contained more than one TemplateData element";
                return;
            }

            // Generated file name.
            if (_retainfilename == false)
            {
                if (variationstring != null)
                {
                    generatedFile = tempfiledata.FileName + "_Sc" + scenarioid + "_Var" + variationstring + tempfiledata.FileExtension;
                }
                else
                {
                    generatedFile = tempfiledata.FileName + "_Sc" + scenarioid + "_Var" + "all" + tempfiledata.FileExtension;
                }
            }
            else
            {
                generatedFile = tempfiledata.FileName + tempfiledata.FileExtension;
            }

            if (String.IsNullOrEmpty(_fileoutputdirectory) == false)
            {
                if (DirectorySW.Exists(_fileoutputdirectory))
                {
                    generatedFile = _fileoutputdirectory + PathSW.DirectorySeparatorChar + generatedFile;
                }
            }

            if (generatedFile.Contains(PathSW.DirectorySeparatorChar.ToString()))
            {
                string directoryname = PathSW.GetDirectoryName(generatedFile);
                if (string.IsNullOrEmpty(directoryname) == false)
                {
                    if (DirectorySW.Exists(directoryname) == false)
                    {
                        if (DirectorySW.Exists(directoryname) == false)
                        {
                            DirectorySW.CreateDirectory(directoryname);
                        }
                    }
                }
            }

            if (_isxmldocument)
            {
                XmlDocumentSW tempdoc = new XmlDocumentSW();
                tempdoc.LoadXml(base.canvasdoc.DocumentElement.InnerXml);

                GenerateFile(ref tempdoc);

                tempdoc = null;
            }
            else
            {
                GenerateFile(base.canvasdoc.DocumentElement.InnerText);
            }
        }