Ejemplo n.º 1
0
        /// <summary>
        /// Loads an image map from a file containing the XML description of the
        /// segments inside.
        /// <param name="svc"></param>
        /// <param name="mmapFileName"></param>
        /// <param name="platform"></param>
        /// <returns></returns>
        public static MemoryMap_v1?LoadMemoryMapFromFile(IServiceProvider svc, string mmapFileName, IPlatform platform)
        {
            //$REFACTOR: move all this service stuff to the only caller.
            // change signature to use a simple Stream.
            var cfgSvc  = svc.RequireService <IConfigurationService>();
            var fsSvc   = svc.RequireService <IFileSystemService>();
            var diagSvc = svc.RequireService <IDiagnosticsService>();

            try
            {
                var filePath = cfgSvc.GetInstallationRelativePath(mmapFileName);
                var ser      = SerializedLibrary.CreateSerializer(
                    typeof(MemoryMap_v1),
                    SerializedLibrary.Namespace_v4);
                using (var stm = fsSvc.CreateFileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    var mmap = (MemoryMap_v1)ser.Deserialize(stm);
                    return(mmap);
                }
            }
            catch (Exception ex)
            {
                diagSvc.Error(ex, string.Format("Unable to open memory map file '{0}.", mmapFileName));
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads an image map from a <see cref="Stream"/> containing the XML description of the
        /// segments inside.
        public static MemoryMap_v1 Deserialize(Stream stm)
        {
            var ser = SerializedLibrary.CreateSerializer(
                typeof(MemoryMap_v1),
                SerializedLibrary.Namespace_v4);
            var mmap = (MemoryMap_v1)ser.Deserialize(stm);

            return(mmap);
        }
Ejemplo n.º 3
0
 public Project LoadProject(string filename, Stream stm)
 {
     var rdr = new XmlTextReader(stm);
     foreach (var fileFormat in supportedProjectFileFormats)
     {
         XmlSerializer ser = SerializedLibrary.CreateSerializer(fileFormat.Item1, fileFormat.Item2);
         if (ser.CanDeserialize(rdr))
         {
             var deser = new Deserializer(this, filename);
             return ((SerializedProject)ser.Deserialize(rdr)).Accept(deser);
         }
     }
     return null;
 }