- Timestamp:
- 01/03/17 18:21:40 (8 years ago)
- Location:
- branches/PersistenceOverhaul
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceOverhaul
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:ignore
-
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/Mapper.cs
r13358 r14537 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.PluginInfrastructure;26 25 using Google.ProtocolBuffers; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;28 26 29 27 namespace HeuristicLab.Persistence { … … 122 120 bundle.RootBoxId = mapper.GetBoxId(o); 123 121 bundle.AddRangeTransformerGuids(mapper.transformers.GetValues().Select(x => x.Guid).Select(x => ByteString.CopyFrom(x.ToByteArray()))); 124 bundle.AddRangeTypeGuids(mapper.types.GetValues().Select(x => StaticCache.GetGuid(x)).Select(x => ByteString.CopyFrom (x.ToByteArray())));122 bundle.AddRangeTypeGuids(mapper.types.GetValues().Select(x => StaticCache.GetGuid(x)).Select(x => ByteString.CopyFromUtf8(x))); 125 123 bundle.AddRangeStrings(mapper.strings.GetValues()); 126 124 bundle.AddRangeBoxes(mapper.boxes.GetValues()); … … 129 127 public static object ToObject(Bundle bundle) { 130 128 var mapper = new Mapper(); 131 mapper.types = new Index<Type>(bundle.TypeGuidsList.Select(x => new Guid(x.ToByteArray())).Select(x => StaticCache.GetType(x)));129 mapper.types = new Index<Type>(bundle.TypeGuidsList.Select(x => x.ToStringUtf8()).Select(x => StaticCache.GetType(x))); 132 130 mapper.strings = new Index<string>(bundle.StringsList); 133 131 mapper.boxes = new Index<Box>(bundle.BoxesList); -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/StaticCache.cs
r13407 r14537 34 34 private Dictionary<Guid, ITransformer> guid2Transformer; 35 35 private Dictionary<ITransformer, Guid> transformer2Guid; 36 private Dictionary< Guid, Type> guid2Type;37 private Dictionary<Type, Guid> type2Guid;36 private Dictionary<string, Type> guid2Type; 37 private Dictionary<Type, string> type2Guid; 38 38 private Dictionary<Type, TypeInfo> typeInfos; 39 39 private ExtensionRegistry extensionRegistry; … … 42 42 guid2Transformer = new Dictionary<Guid, ITransformer>(); 43 43 transformer2Guid = new Dictionary<ITransformer, Guid>(); 44 guid2Type = new Dictionary< Guid, Type>();45 type2Guid = new Dictionary<Type, Guid>();44 guid2Type = new Dictionary<string, Type>(); 45 type2Guid = new Dictionary<Type, string>(); 46 46 typeInfos = new Dictionary<Type, TypeInfo>(); 47 47 extensionRegistry = ExtensionRegistry.CreateInstance(); 48 48 49 foreach (var transformer in ApplicationManager.Manager.GetInstances<ITransformer>() .OrderBy(x => x.Priority))49 foreach (var transformer in ApplicationManager.Manager.GetInstances<ITransformer>()) 50 50 RegisterTransformer(transformer); 51 51 52 RegisterType(new Guid("94AD8522-3F55-4580-A6F8-2D2AAEDD4B8C"), typeof(bool)); 53 RegisterType(new Guid("4A1C0FD5-423D-4F96-AB22-A496578C25AC"), typeof(byte)); 54 RegisterType(new Guid("C4B00F0B-FED7-439F-B1B2-8A0048B64882"), typeof(sbyte)); 55 RegisterType(new Guid("9F451811-3DE1-43AB-8B74-D7E03851857B"), typeof(short)); 56 RegisterType(new Guid("46244D54-0145-49F7-9CF3-9CDB7FB5F240"), typeof(ushort)); 57 RegisterType(new Guid("1FDDE40C-09E3-491F-8FBB-32BB3C885E9E"), typeof(char)); 58 RegisterType(new Guid("EE3E0F9C-A5C2-4461-AF36-28BD8F26E6FB"), typeof(int)); 59 RegisterType(new Guid("69476D18-D285-43E9-BC7C-6CC9E9F2321E"), typeof(uint)); 60 RegisterType(new Guid("7C7BC5EC-F001-4BA0-9F85-50DCBAA9AE81"), typeof(long)); 61 RegisterType(new Guid("AC808D5A-63BB-457C-9B92-C9B83DA2B139"), typeof(ulong)); 62 RegisterType(new Guid("BF22653A-026C-4367-BBBA-2125AECF6C08"), typeof(float)); 63 RegisterType(new Guid("8B49821A-3ADC-4715-9DB1-08E2F3CFDF15"), typeof(double)); 64 RegisterType(new Guid("7BB386BF-6FD4-443D-A6C1-387096798C67"), typeof(DateTime)); 65 RegisterType(new Guid("724A2D49-7E7B-455B-BBA9-4214C64E8A21"), typeof(TimeSpan)); 66 RegisterType(new Guid("4DB2ED2B-D9F2-4695-B555-A2CF42740740"), typeof(Color)); 67 RegisterType(new Guid("9BC74087-D5C0-4C39-99B4-D7465F478492"), typeof(Point)); 68 RegisterType(new Guid("E84C326A-7E14-4F28-AEFF-BC16CC671655"), typeof(KeyValuePair<,>)); 69 RegisterType(new Guid("F0280B55-25E8-4981-B309-D675D081402A"), typeof(string)); 70 71 RegisterType(new Guid("D15AD28B-203A-460E-815C-F7230C4B1F75"), typeof(bool[])); 72 RegisterType(new Guid("EE318DC4-580D-4DB1-9AAD-988B0E50A3DB"), typeof(byte[])); 73 RegisterType(new Guid("326B9484-361F-46F8-B8A6-46C781A8C51F"), typeof(sbyte[])); 74 RegisterType(new Guid("C854783D-4C91-43C8-A19A-F96012494F8A"), typeof(short[])); 75 RegisterType(new Guid("C47FB329-2A1D-4EB7-AFB1-1CF72AB30E98"), typeof(ushort[])); 76 RegisterType(new Guid("9681D044-B50C-4907-B23E-BDFEBC6C3FFC"), typeof(char[])); 77 RegisterType(new Guid("0FC62D91-D63F-4507-8696-885D4C07285A"), typeof(int[])); 78 RegisterType(new Guid("C43A25A0-9B99-4DA4-9279-7495FE10428E"), typeof(uint[])); 79 RegisterType(new Guid("7AC4DDAC-0E13-428E-BF49-7BE7B76746CB"), typeof(long[])); 80 RegisterType(new Guid("8D9283A7-FE49-4AEA-A09F-D53CF3BE520A"), typeof(ulong[])); 81 RegisterType(new Guid("BB9CFA0B-DD29-4C44-85C6-3A6289C55448"), typeof(float[])); 82 RegisterType(new Guid("3B3AA69E-1641-4202-AE1D-7EEFF60FA355"), typeof(double[])); 83 RegisterType(new Guid("7DF325A6-2553-4915-B7C6-D98191107CB7"), typeof(string[])); 52 53 // ECC12A57-DA8D-43D9-9EC7-FCAC878A4D69 54 // E8348C94-9817-4164-9C98-377689F83F30 55 // 05551382-E894-4218-B860-FEE1D92CA07D 56 // 4CC0D44E-65B2-4DF1-A333-30F058CB78CA 57 // 5D451A64-EBD9-411F-A07E-232250B33784 58 // EEBD2D26-56CC-45EA-900A-DD29B9F598CE 59 // B8EEEFA7-8576-42DD-937C-AFBB66297B56 60 // 4C3C8E0A-7DCF-4814-B798-AECB86E1E4E3 61 // EAA4FF91-B90C-47CB-AC0F-66AB66D41186 62 // EB51B342-826F-4004-B2C6-F2A03A8C35C9 63 // 14138614-45DB-4A0D-9E59-AE9373241D6B 64 65 66 // RegisterType(new Guid("94AD8522-3F55-4580-A6F8-2D2AAEDD4B8C"), typeof(bool)); 67 // RegisterType(new Guid("4A1C0FD5-423D-4F96-AB22-A496578C25AC"), typeof(byte)); 68 // RegisterType(new Guid("C4B00F0B-FED7-439F-B1B2-8A0048B64882"), typeof(sbyte)); 69 // RegisterType(new Guid("9F451811-3DE1-43AB-8B74-D7E03851857B"), typeof(short)); 70 // RegisterType(new Guid("46244D54-0145-49F7-9CF3-9CDB7FB5F240"), typeof(ushort)); 71 // RegisterType(new Guid("1FDDE40C-09E3-491F-8FBB-32BB3C885E9E"), typeof(char)); 72 // RegisterType(new Guid("EE3E0F9C-A5C2-4461-AF36-28BD8F26E6FB"), typeof(int)); 73 // RegisterType(new Guid("69476D18-D285-43E9-BC7C-6CC9E9F2321E"), typeof(uint)); 74 // RegisterType(new Guid("7C7BC5EC-F001-4BA0-9F85-50DCBAA9AE81"), typeof(long)); 75 // RegisterType(new Guid("AC808D5A-63BB-457C-9B92-C9B83DA2B139"), typeof(ulong)); 76 // RegisterType(new Guid("BF22653A-026C-4367-BBBA-2125AECF6C08"), typeof(float)); 77 // RegisterType(new Guid("8B49821A-3ADC-4715-9DB1-08E2F3CFDF15"), typeof(double)); 78 // RegisterType(new Guid("7BB386BF-6FD4-443D-A6C1-387096798C67"), typeof(DateTime)); 79 // RegisterType(new Guid("724A2D49-7E7B-455B-BBA9-4214C64E8A21"), typeof(TimeSpan)); 80 // RegisterType(new Guid("4DB2ED2B-D9F2-4695-B555-A2CF42740740"), typeof(Color)); 81 // RegisterType(new Guid("9BC74087-D5C0-4C39-99B4-D7465F478492"), typeof(Point)); 82 // RegisterType(new Guid("E84C326A-7E14-4F28-AEFF-BC16CC671655"), typeof(KeyValuePair<,>)); 83 // RegisterType(new Guid("F0280B55-25E8-4981-B309-D675D081402A"), typeof(string)); 84 // 85 // RegisterType(new Guid("9CF55419-439B-4A90-B2ED-8C7F7768EB61"), typeof(Array)); 86 // RegisterType(new Guid("D15AD28B-203A-460E-815C-F7230C4B1F75"), typeof(bool[])); 87 // RegisterType(new Guid("EE318DC4-580D-4DB1-9AAD-988B0E50A3DB"), typeof(byte[])); 88 // RegisterType(new Guid("326B9484-361F-46F8-B8A6-46C781A8C51F"), typeof(sbyte[])); 89 // RegisterType(new Guid("C854783D-4C91-43C8-A19A-F96012494F8A"), typeof(short[])); 90 // RegisterType(new Guid("C47FB329-2A1D-4EB7-AFB1-1CF72AB30E98"), typeof(ushort[])); 91 // RegisterType(new Guid("9681D044-B50C-4907-B23E-BDFEBC6C3FFC"), typeof(char[])); 92 // RegisterType(new Guid("0FC62D91-D63F-4507-8696-885D4C07285A"), typeof(int[])); 93 // RegisterType(new Guid("C43A25A0-9B99-4DA4-9279-7495FE10428E"), typeof(uint[])); 94 // RegisterType(new Guid("7AC4DDAC-0E13-428E-BF49-7BE7B76746CB"), typeof(long[])); 95 // RegisterType(new Guid("8D9283A7-FE49-4AEA-A09F-D53CF3BE520A"), typeof(ulong[])); 96 // RegisterType(new Guid("BB9CFA0B-DD29-4C44-85C6-3A6289C55448"), typeof(float[])); 97 // RegisterType(new Guid("3B3AA69E-1641-4202-AE1D-7EEFF60FA355"), typeof(double[])); 98 // RegisterType(new Guid("7DF325A6-2553-4915-B7C6-D98191107CB7"), typeof(string[])); 99 // RegisterType(new Guid("DB2A785C-5803-42C7-A01F-E1FD845A83A1"), typeof(List<>)); 100 // RegisterType(new Guid("EB98A564-BEDC-458A-9E9B-4BF3CDAFB9BE"), typeof(Stack<>)); 101 // RegisterType(new Guid("D5E3118B-957A-43B5-A740-1BBAA0EAB666"), typeof(System.Collections.Stack)); 102 // RegisterType(new Guid("7E2F3277-7216-4295-A498-9ACA43527D5B"), typeof(HashSet<>)); 103 // RegisterType(new Guid("E92C35AD-32B1-4F37-B8D2-BE2F5FEB465B"), typeof(Dictionary<,>)); 104 105 106 RegisterTypeAndFullName(typeof(bool)); 107 RegisterTypeAndFullName(typeof(byte)); 108 RegisterTypeAndFullName(typeof(sbyte)); 109 RegisterTypeAndFullName(typeof(short)); 110 RegisterTypeAndFullName(typeof(ushort)); 111 RegisterTypeAndFullName(typeof(char)); 112 RegisterTypeAndFullName(typeof(int)); 113 RegisterTypeAndFullName(typeof(uint)); 114 RegisterTypeAndFullName(typeof(long)); 115 RegisterTypeAndFullName(typeof(ulong)); 116 RegisterTypeAndFullName(typeof(float)); 117 RegisterTypeAndFullName(typeof(double)); 118 RegisterTypeAndFullName(typeof(DateTime)); 119 RegisterTypeAndFullName(typeof(TimeSpan)); 120 RegisterTypeAndFullName(typeof(Color)); 121 RegisterTypeAndFullName(typeof(Point)); 122 RegisterTypeAndFullName(typeof(KeyValuePair<,>)); 123 RegisterTypeAndFullName(typeof(string)); 124 125 RegisterTypeAndFullName(typeof(Array)); 126 RegisterTypeAndFullName(typeof(bool[])); 127 RegisterTypeAndFullName(typeof(byte[])); 128 RegisterTypeAndFullName(typeof(sbyte[])); 129 RegisterTypeAndFullName(typeof(short[])); 130 RegisterTypeAndFullName(typeof(ushort[])); 131 RegisterTypeAndFullName(typeof(char[])); 132 RegisterTypeAndFullName(typeof(int[])); 133 RegisterTypeAndFullName(typeof(uint[])); 134 RegisterTypeAndFullName(typeof(long[])); 135 RegisterTypeAndFullName(typeof(ulong[])); 136 RegisterTypeAndFullName(typeof(float[])); 137 RegisterTypeAndFullName(typeof(double[])); 138 RegisterTypeAndFullName(typeof(string[])); 139 RegisterTypeAndFullName(typeof(List<>)); 140 RegisterTypeAndFullName(typeof(Stack<>)); 141 RegisterTypeAndFullName(typeof(System.Collections.Stack)); 142 RegisterTypeAndFullName(typeof(HashSet<>)); 143 RegisterTypeAndFullName(typeof(Dictionary<,>)); 144 145 84 146 foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { 85 147 foreach (var t in asm.GetTypes().Where(x => StorableClassAttribute.IsStorableClass(x))) 86 RegisterType(StorableClassAttribute.GetStorableClassAttribute(t).Guid, t); 148 RegisterTypeAndFullName(t); 149 } 150 151 var registeredTypes = type2Guid.Keys.ToArray(); 152 foreach (var t in registeredTypes) { 153 AddBaseTypesRec(t); 87 154 } 88 155 … … 97 164 RegisterExtension(BytesBox.Bytes); 98 165 RegisterExtension(BoolArrayBox.BoolArray); 166 RegisterExtension(ByteArrayBox.ByteArray); 99 167 RegisterExtension(IntArrayBox.IntArray); 100 168 RegisterExtension(LongArrayBox.LongArray); … … 108 176 RegisterExtension(IntMatrixBox.IntMatrix); 109 177 RegisterExtension(DictionaryBox.Dictionary); 178 RegisterExtension(StorableClassBox.StorableClass); 179 RegisterExtension(TypeBox.Type); 180 } 181 182 private void AddBaseTypesRec(Type t) { 183 foreach (var interfaceType in t.GetInterfaces()) { 184 RegisterTypeAndFullName(interfaceType); 185 AddBaseTypesRec(interfaceType); 186 } 187 if (t.BaseType != null) { 188 RegisterTypeAndFullName(t.BaseType); 189 AddBaseTypesRec(t.BaseType); 190 } 110 191 } 111 192 … … 116 197 } 117 198 } 118 public void RegisterType(Guid guid, Type type) { 119 lock (locker) { 120 guid2Type.Add(guid, type); 121 type2Guid.Add(type, guid); 199 // public void RegisterType(Guid guid, Type type) { 200 // lock (locker) { 201 // guid2Type.Add(guid, type); 202 // type2Guid.Add(type, guid); 203 // } 204 // } 205 public void RegisterTypeAndFullName(Type type) { 206 lock (locker) { 207 var key = type.AssemblyQualifiedName ?? type.Name; 208 if (!guid2Type.ContainsKey(key)) { 209 guid2Type.Add(key, type); 210 type2Guid.Add(type, key); 211 } 122 212 } 123 213 } … … 134 224 return transformer2Guid[transformer]; 135 225 } 136 public Type GetType( Guidguid) {226 public Type GetType(string guid) { 137 227 return guid2Type[guid]; 138 228 } 139 public GuidGetGuid(Type type) {229 public string GetGuid(Type type) { 140 230 return type2Guid[type]; 141 231 } … … 144 234 TypeInfo typeInfo; 145 235 if (!typeInfos.TryGetValue(type, out typeInfo)) { 146 var transformer = guid2Transformer.Values. First(x => x.CanTransformType(type));236 var transformer = guid2Transformer.Values.OrderBy(x => x.Priority).First(x => x.CanTransformType(type)); 147 237 typeInfo = new TypeInfo(type, transformer); 148 238 typeInfos.Add(type, typeInfo);
Note: See TracChangeset
for help on using the changeset viewer.