/[cits3200i]/branches/metadata-branch-rvvs89/UWAPlugins/MetadataPlugin/Source/MetadataListSerializer.cs


UCC Code Repository

Diff of /branches/metadata-branch-rvvs89/UWAPlugins/MetadataPlugin/Source/MetadataListSerializer.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 86 by rvvs89, Mon Oct 11 06:42:56 2010 UTC revision 87 by rvvs89, Mon Oct 11 21:19:18 2010 UTC
# Line 4  using System.IO; Line 4  using System.IO;
4  using System.Runtime.Serialization;  using System.Runtime.Serialization;
5  using System.Runtime.Serialization.Formatters.Binary;  using System.Runtime.Serialization.Formatters.Binary;
6  using System.Text;  using System.Text;
7    using System.Reflection;
8    
9  namespace MetadataPlugin.Source  namespace MetadataPlugin.Source
10  {  {
# Line 14  namespace MetadataPlugin.Source Line 15  namespace MetadataPlugin.Source
15          // NOTE: Increment this if the data storage mechanism changes          // NOTE: Increment this if the data storage mechanism changes
16          private static int SERIAL_VERSION = 0;          private static int SERIAL_VERSION = 0;
17    
18            static MetadataListSerializer()
19            {
20                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
21            }
22    
23            static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
24            {
25                string shortName = args.Name.Split(',')[0];
26                Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
27                foreach (Assembly assembly in assemblies)
28                {
29                    if (shortName == assembly.FullName.Split(',')[0])
30                    {
31                        return assembly;
32                    }
33                }
34                return null;
35            }
36    
37          public static MetadataList Deserialize(byte[] input)          public static MetadataList Deserialize(byte[] input)
38          {          {
39              if (input == null)              if (input == null || input.Length <= 0)
40              {              {
41                  return null;                  return null;
42              }              }
43              MemoryStream stream = new MemoryStream(input);              MemoryStream stream = new MemoryStream(input);
44              IFormatter formatter = new BinaryFormatter();              BinaryFormatter formatter = new BinaryFormatter();
45                formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full;
46              int version = (int)formatter.Deserialize(stream);              int version = (int)formatter.Deserialize(stream);
47              if (version != SERIAL_VERSION)              if (version != SERIAL_VERSION)
48              {              {

Legend:
Removed from v.86  
changed lines
  Added in v.87

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26