public void LoadXML(string xmlDocument) { try { _xmlDocument = xmlDocument; XNamespace ad = "urn:IEEE-1671.1:2009:TestDescription"; _document = XDocument.Load(new StringReader(_xmlDocument)); _testDescription = TestDescription.Deserialize(_xmlDocument); _sources.AddRange(_document.Descendants(ad + "Source")); _sensors.AddRange(_document.Descendants(ad + "Sensor")); _monitors.AddRange(_document.Descendants(ad + "Monitor")); foreach (SignalRequirementsSignalRequirement signalRequirement in _testDescription.SignalRequirements) { _requiredSignals.Add(signalRequirement.TsfClass); } foreach (ActionType action in _testDescription.DetailedTestInformation.Actions) { var operations = action.Behavior.Item as Operations1; if (operations != null) { foreach (OperationType operation in operations.Operation) { var setup = operation as OperationSetup; if (setup != null) { var source = setup.Item as OperationSetupSource; if (source != null) { LogManager.SourceTrace(ATMLAllocator.SOURCE, HttpUtility.HtmlEncode(source.Any.InnerXml.Trim())); XElement signal = XElement.Parse(source.Any.InnerXml.Trim()); LogManager.SourceTrace(ATMLAllocator.SOURCE, "{0}:{1}", signal.GetPrefixOfNamespace(signal.Name.Namespace), signal.Name.NamespaceName); } } } } } OnTestDescriptionChanged(_testDescription); } catch (Exception e) { LogManager.SourceError(ATMLAllocator.SOURCE, e); } }
private void LoadTestDescriptionFile(string fileName) { if (File.Exists(fileName)) { byte[] content = FileManager.ReadFile(fileName); var fi = new FileInfo(fileName); OnAtmlFileOpened(fi, content); try { _currentTestDescription = TestDescription.Deserialize(Encoding.UTF8.GetString(content)); //OnTestDescriptionCreated( testDescription ); OnTestDescriptionOpened(_currentTestDescription, Encoding.UTF8.GetString(content)); } catch (Exception e) { LogManager.SourceWarn(ATMLTranslator.SOURCE, "Failed to Deserialize Test Description \"{0}\"", fileName); } } }
public TestDescriptionReader(string xmlContent) { TestDescription td = TestDescription.Deserialize(xmlContent); _document = XDocument.Parse(xmlContent); XElement root = _document.Root; _tsfLibraries = root.Element(NameSpaceLibrary.tdns + "TsfLibraries"); _uut = root.Element(NameSpaceLibrary.tdns + "UUT"); _interfaceRequirements = root.Element(NameSpaceLibrary.tdns + "nterfaceRequirements"); _detailedTestInformation = root.Element(NameSpaceLibrary.tdns + "DetailedTestInformation"); _failureFaultData = root.Element(NameSpaceLibrary.tdns + "FailureFaultData"); StringReader stringReader = null; try { stringReader = new StringReader(_detailedTestInformation.ToString()); XmlReader reader = XmlReader.Create(stringReader); var nsmanager = new XmlNamespaceManager(reader.NameTable); nsmanager.AddNamespace("td", "urn:IEEE-1671.1:2009:TestDescription"); var serializer = new XmlSerializer(typeof(DetailedTestInformation)); var dti = ((DetailedTestInformation)(serializer.Deserialize(reader))); int x = 0; } finally { if ((stringReader != null)) { stringReader.Dispose(); } } DetailedTestInformation dt = DetailedTestInformation.Deserialize(_detailedTestInformation.ToString()); int i = 0; }
public void Translate() { try { LogManager.SourceTrace(ATMLTranslator.SOURCE, "Beginning Translation of the AIXML document to the 1671.1 Test Description..."); ProjectInfo pi = ProjectManager.ProjectInfo; if (pi == null || pi.TranslationInfo == null) { throw new TranslationException("Failed to obtain the Translation Configuration"); } string projectName = pi.ProjectName; string projectId = pi.Uuid; string uutName = pi.UutName; string uutId = pi.UutId; string testStation = pi.ClassName; bool isSegmented = pi.TranslationInfo.Segmented; DateTime startTime = DateTime.Now; string xmlPath = Path.Combine(ATMLContext.ProjectTranslatorAixmlPath, projectName + ".aixml.xml"); string atmlPath = ATMLContext.ProjectAtmlPath; //(String)ATMLContext.GetProperty("environment.atml.xml-path"); if (String.IsNullOrWhiteSpace(projectName)) { LogManager.SourceWarn(ATMLTranslator.SOURCE, "You must open a project with source code to translate."); } else { //string projectPath = ATMLContext.PROJECT_PATH;// Path.Combine( ATMLContext.TESTSET_PATH, projectName ); // xmlPath = xmlPath.Replace( "${FILENAME}", ProjectManager.ProjectName + ".atml" ) // .Replace( "${PROJECTPATH}", projectPath ); Document xslDocument = DocumentManager.GetDocument("D7F7A05B-DB5F-4E93-BF2C-F79CF72F6047"); //XSLT Translation Document //atmlPath = atmlPath.Replace( "${PROJECTPATH}", projectPath ); if (xslDocument != null) { try { var ok2Translate = true; var sb = new StringBuilder(); var settings = new XmlWriterSettings(); var fi = new FileInfo(Path.Combine(atmlPath, ProjectManager.ProjectName + ".1671.1.xml")); settings.Indent = true; settings.IndentChars = " "; settings.NewLineChars = "\r\n"; settings.NewLineHandling = NewLineHandling.Replace; var xslt = new XslCompiledTransform(); if (!File.Exists(xmlPath)) { throw new TranslationException("Translation Failed: Missing AIXML File."); } if (fi.Exists) { ok2Translate = MessageBox.Show( string.Format("A Test Description for {0} already exists, would you like to overwrite it?", ProjectManager.ProjectName), @"Overwrite Test Description", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes; } if (!ok2Translate) { LogManager.Trace("AIXML Translation to ATML 1671.1 has been canceled."); } else { using (XmlWriter writer = XmlWriter.Create(sb, settings)) { var xmlDocument = new XPathDocument(xmlPath); xslt.Load( XmlReader.Create( new StringReader(Encoding.UTF8.GetString(xslDocument.DocumentContent)))); var xslArg = new XsltArgumentList(); var obj = new TranslationLibrary(); xslArg.AddExtensionObject("urn:utrs.atml-translator-tools", obj); xslArg.XsltMessageEncountered += delegate(object sender, XsltMessageEncounteredEventArgs args) { LogManager.SourceError(ATMLTranslator.SOURCE, args.Message); }; xslt.Transform(xmlDocument, xslArg, writer, null); DateTime stopTime = DateTime.Now; TimeSpan diff = stopTime - startTime; LogManager.SourceTrace(ATMLTranslator.SOURCE, "Translation Time: {0}", diff.ToString()); } FileManager.WriteFile(fi.FullName, Encoding.UTF8.GetBytes(sb.ToString())); LogManager.SourceTrace(ATMLTranslator.SOURCE, "File \"{0}\" has been saved. ", fi.Name); try { TestDescription td = TestDescription.Deserialize(sb.ToString()); OnTranslated(td, sb.ToString()); Document document = DocumentManager.GetDocument(fi.Name, (int) dbDocument.DocumentType .TEST_DESCRIPTION); if (document == null) { document = new Document(); document.uuid = td.uuid; document.DocumentType = dbDocument.DocumentType.TEST_DESCRIPTION; document.ContentType = DocumentManager.DetermineContentType(fi.Name); document.DataState = BASEBean.eDataState.DS_ADD; } else { document.DataState = BASEBean.eDataState.DS_EDIT; } document.FileInfo = fi; document.name = fi.Name; document.Description = "Test Description for " + projectName; document.DocumentContent = Encoding.UTF8.GetBytes(sb.ToString()); document.version = td.version; DocumentManager.SaveDocument(document); } catch (Exception e) { OnTranslated(null, null); LogManager.SourceWarn(ATMLTranslator.SOURCE, "Failed to create a TestDescription object at this time."); LogManager.Debug(e); } } } catch (TranslationException e) { OnTranslated(null, null); LogManager.SourceError(ATMLTranslator.SOURCE, e.Message); } catch (Exception e) { OnTranslated(null, null); LogManager.SourceError(ATMLTranslator.SOURCE, e, "Error translating AIXML for Project: {0} XML Path: {1} ATML Path: {2}", projectName, xmlPath, atmlPath); } } } } catch (Exception e) { LogManager.SourceError(ATMLTranslator.SOURCE, e); } }
public string Analyze(string testDescriptionXml) { string xml = ""; try { var dao = new InstrumentDAO(); var testDescription = TestDescription.Deserialize(testDescriptionXml); var signalTypeLookup = new Dictionary <string, SignalAnalysisType>(); var signalList = new List <string>(); Dictionary <SignalRequirementsSignalRequirement, ICollection <object> > equips = Build(testDescription); foreach (SignalRequirementsSignalRequirement signalRequirement in testDescription.SignalRequirements) { string name = signalRequirement.TsfClass.tsfClassName; string id = signalRequirement.TsfClass.tsfLibraryID; SignalRole role = signalRequirement.role; if ("SHORT".Equals(name)) { continue; } if ("".Equals(name)) { continue; } SignalAnalysisType sat = null; if (!signalTypeLookup.ContainsKey(name)) { sat = new SignalAnalysisType(); sat.Type = name; signalTypeLookup.Add(name, sat); } sat = signalTypeLookup[name]; SignalInstance si = new SignalInstance(); si.Tsf = id; foreach ( SignalRequirementsSignalRequirementTsfClassAttribute tsfClassAttribute in signalRequirement.TsfClassAttribute) { SignalInstanceAttribute sia = new SignalInstanceAttribute(); sia.Name = tsfClassAttribute.Name.Value; sia.Value = tsfClassAttribute.Value.ToString(); if (tsfClassAttribute.Value.Item is DatumType) { object v = Datum.GetNominalDatumValue((DatumType)tsfClassAttribute.Value.Item); sia.NominalValue = v == null?null:v.ToString(); sia.Qualifier = ((DatumType)tsfClassAttribute.Value.Item).unitQualifier; } si.AddAttribute(sia); } if (!signalList.Contains(name + id + si)) { signalList.Add(name + id + si); sat.AddSignal(si); Console.WriteLine(name + si); } } SignalAnalysis signalAnalysis = new SignalAnalysis(); signalAnalysis.Uut = new Uut(); if (testDescription.UUT != null && testDescription.UUT.Description != null && testDescription.UUT.Description.Item != null) { var id = testDescription.UUT.Description.Item as ItemDescription; var docRef = testDescription.UUT.Description.Item as DocumentReference; if (docRef != null) { signalAnalysis.Uut.Name = docRef.DocumentName; signalAnalysis.Uut.Uuid = docRef.uuid; } else if (id != null) { signalAnalysis.Uut.Name = id.name; signalAnalysis.Uut.Uuid = id.Identification.ModelName; signalAnalysis.Uut.Version = id.version; } } signalAnalysis.Tps = ATMLContext.CurrentProjectName; signalAnalysis.RunDateTime = String.Format("{0:yyyy-dd-MM HH:mm:ss}", DateTime.Now); foreach (var testStation in ATMLAllocator.Instance.SelectedTestStations) { var tsa = new TestStationSignalAnalysis(); tsa.Name = testStation.name; tsa.Uuid = testStation.uuid; signalAnalysis.AddTestStation(tsa); foreach (SignalAnalysisType signalType in signalTypeLookup.Values) { SignalAnalysisType copy = signalType.Copy(); tsa.AddSignal(copy); foreach (var signalInstance in copy.SignalInstances) { foreach (var signalInstanceAttribute in signalInstance.Attributes) { try { if (signalInstanceAttribute.NominalValue != null) { bool isValid = dao.TestAttribute(testStation.uuid, signalInstanceAttribute.Name, signalInstanceAttribute.NominalValue, signalInstanceAttribute.Qualifier); signalInstanceAttribute.IsValid = isValid; } } catch (Exception err) { LogManager.SourceError(ATMLAllocator.SOURCE, err); } } } } } xml = XmlUtils.SerializeObject(signalAnalysis); } catch (Exception e) { LogManager.SourceError(ATMLAllocator.SOURCE, e); } return(xml); }