public void DeserializeTest() { using (var s = GetType().Assembly.GetManifestResourceStream(GetType(), "version")) { var i = ResourceSerializer.Deserialize <VS_VERSIONINFO>(s); var sfi = i.Children.OfType <StringFileInfo>().SingleOrDefault(); Assert.IsNotNull(sfi); var st = sfi.Children[0]; Assert.IsTrue(st.Children.Length > 0); } }
public void SerializeTest() { using (var s = GetType().Assembly.GetManifestResourceStream(GetType(), "version")) { var m = new MemoryStream(); s.CopyTo(m); m.Seek(0, SeekOrigin.Begin); var i = ResourceSerializer.Deserialize <VS_VERSIONINFO>(m); var m2 = new MemoryStream(); ResourceSerializer.Serialize(i, m2); var b = m.ToArray(); var b2 = m2.ToArray(); Assert.IsTrue(b.SequenceEqual(b2)); } }
private static IEnumerable <VS_VERSIONINFO> LoadVersions(ModuleDefMD moduleDef) { var resourceDirectory = moduleDef.MetaData.PEImage.Win32Resources.Root.FindDirectory(new ResourceName(16)); if (resourceDirectory == null) { yield break; } foreach (var resourceEntry in resourceDirectory.Directories) { foreach (var versionEntry in resourceEntry.Data) { var vi = ResourceSerializer.Deserialize <VS_VERSIONINFO>(versionEntry.ToDataStream()); vi.DirectoryName = resourceEntry.Name; vi.DataName = versionEntry.Name; yield return(vi); } } }
public void ClearSerializeTest() { using (var s = GetType().Assembly.GetManifestResourceStream(GetType(), "version")) { var m = new MemoryStream(); s.CopyTo(m); m.Seek(0, SeekOrigin.Begin); var i = ResourceSerializer.Deserialize <VS_VERSIONINFO>(m); ClearLengths(i); var m2 = new MemoryStream(); ResourceSerializer.Serialize(i, m2); var b = m.ToArray(); var b2 = m2.ToArray(); Assert.AreEqual(b.Length, b2.Length); for (int index = 0; index < b.Length; index++) { Assert.AreEqual(b[index], b2[index]); } } }
/// <summary> /// Runs media info and stores the output to a file /// </summary> /// <returns></returns> public override async Task Execute(AmeJob job) { Logger.Info("Starting MediaInfo job {0}...", job?.Id); try { if (job == null) { throw new ArgumentNullException(nameof(job)); } Logger.Debug("Job JSON: {0}", ResourceSerializer.Serialize(job)); // ensure this is a valid profile for this worker if (job.JobProfile.Label != "ExtractTechnicalMetadata") { throw new Exception($"JobProfile '{job.JobProfile.Label}' not accepted"); } // ensure the job specifies input and output locations if (job.JobInput["inputFile"] == null) { throw new Exception("Job does not specify an input location."); } // ensure the job specifies an output location if (job.JobInput["outputLocation"] == null) { throw new Exception("Job does not specify an output location."); } var serializedOutputLocation = job.JobInput["outputLocation"]?.ToString(); if (serializedOutputLocation == null) { throw new Exception("Failed to resolve jobInput[\"outputLocation\"]"); } Logger.Debug("Deserializing output location from {0}...", serializedOutputLocation); // get output locator var outputLocation = await ResourceSerializer.Deserialize <Locator>(serializedOutputLocation); var serializedInputFile = job.JobInput["inputFile"]?.ToString(); if (serializedInputFile == null) { throw new Exception("Failed to resolve jobInput[\"inputFile\"]"); } Logger.Debug("Deserializing input file path from {0}...", serializedInputFile); // get input locator var inputFile = await ResourceSerializer.Deserialize <Locator>(serializedInputFile); Logger.Debug("Getting url for input file that's accessible by MediaInfo..."); // get the url of the file MediaInfo should use (could be local, S3, etc) var accessibleUrl = await AccessibleLocationProvider.GetMediaInfoAccessibleLocation(inputFile); if (accessibleUrl == null) { throw new Exception("Input file is not accessible to MediaInfo."); } Logger.Debug("Getting location of MediaInfo binary..."); var mediaInfoLocation = ProcessLocator.GetMediaInfoLocation(); Logger.Debug("Running MediaInfo from {0} against input file {1}...", mediaInfoLocation, accessibleUrl); // run the media info process var result = await ProcessRunner.RunProcess(mediaInfoLocation, "--Output=EBUCore", accessibleUrl); if (!string.IsNullOrWhiteSpace(result.StdErr)) { throw new Exception($"MediaInfo returned one or more errors: {result.StdErr}."); } Logger.Debug("MediaInfo successfully ran against input file {0}. Converting output to JSON...", accessibleUrl); // convert output to JSON var mediaInfoJson = MediaInfoOutputConverter.GetJson(result.StdOut); Logger.Debug("Storing MediaInfo JSON for {0} to file...", accessibleUrl); // save JSON to file and store the resulting locator in the job output var outputLocator = await FileStorage.WriteTextToFile(outputLocation, Guid.NewGuid().ToString(), mediaInfoJson); job.JobOutput["outputFile"] = outputLocator; Logger.Debug("MediaInfo JSON stored to file. Locator = {0}", ResourceSerializer.Serialize(outputLocator)); Logger.Info("MediaInfo job {0} completed successfully.", job.Id); } catch (Exception ex) { Logger.Error("An error occurred running the MediaInfo job. Exception: {0}", ex); throw; } }
/// <summary> /// Deserializes an Annotation from the XmlReader passed in. /// </summary> /// <param name="reader">reader to deserialize from</param> /// <exception cref="ArgumentNullException">reader is null</exception> public void ReadXml(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } //fire trace event EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeserializeAnnotationBegin); XmlDocument doc = null; try { doc = new XmlDocument(); ReadAttributes(reader); if (!reader.IsEmptyElement) { reader.Read(); // Read the remainder of the "Annotation" start tag while (!(XmlNodeType.EndElement == reader.NodeType && AnnotationXmlConstants.Elements.Annotation == reader.LocalName)) { if (AnnotationXmlConstants.Elements.AnchorCollection == reader.LocalName) { CheckForNonNamespaceAttribute(reader, AnnotationXmlConstants.Elements.AnchorCollection); if (!reader.IsEmptyElement) { reader.Read(); // Reads the "Anchors" start tag while (!(AnnotationXmlConstants.Elements.AnchorCollection == reader.LocalName && XmlNodeType.EndElement == reader.NodeType)) { AnnotationResource anchor = (AnnotationResource)ResourceSerializer.Deserialize(reader); _anchors.Add(anchor); } } reader.Read(); // Reads the "Anchors" end tag (or whole tag if it was empty) } else if (AnnotationXmlConstants.Elements.CargoCollection == reader.LocalName) { CheckForNonNamespaceAttribute(reader, AnnotationXmlConstants.Elements.CargoCollection); if (!reader.IsEmptyElement) { reader.Read(); // Reads the "Cargos" start tag while (!(AnnotationXmlConstants.Elements.CargoCollection == reader.LocalName && XmlNodeType.EndElement == reader.NodeType)) { AnnotationResource cargo = (AnnotationResource)ResourceSerializer.Deserialize(reader); _cargos.Add(cargo); } } reader.Read(); // Reads the "Cargos" end tag (or whole tag if it was empty) } else if (AnnotationXmlConstants.Elements.AuthorCollection == reader.LocalName) { CheckForNonNamespaceAttribute(reader, AnnotationXmlConstants.Elements.AuthorCollection); if (!reader.IsEmptyElement) { reader.Read(); // Reads the "Authors" start tag while (!(AnnotationXmlConstants.Elements.AuthorCollection == reader.LocalName && XmlNodeType.EndElement == reader.NodeType)) { if (!(AnnotationXmlConstants.Elements.StringAuthor == reader.LocalName && XmlNodeType.Element == reader.NodeType)) { throw new XmlException(SR.Get(SRID.InvalidXmlContent, AnnotationXmlConstants.Elements.Annotation)); } XmlNode node = doc.ReadNode(reader); // Reads the entire "StringAuthor" tag if (!reader.IsEmptyElement) { _authors.Add(node.InnerText); } } } reader.Read(); // Reads the "Authors" end tag (or whole tag if it was empty) } else { // The annotation must contain some invalid content which is not part of the schema. throw new XmlException(SR.Get(SRID.InvalidXmlContent, AnnotationXmlConstants.Elements.Annotation)); } } } reader.Read(); // Read the end of the "Annotation" tag (or the whole tag if its empty) } finally { //fire trace event EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeserializeAnnotationEnd); } }
/// <summary> /// Executes a worker using the content provided in an HTTP request /// </summary> /// <param name="request"></param> /// <returns></returns> public async void DoWork(HttpRequest request) { await Worker.Execute(await ResourceSerializer.Deserialize <JobAssignment>(await new StreamReader(request.Body).ReadToEndAsync())); }