internal int UnpackObject(object obj, ClassDescriptor desc, bool recursiveLoading, byte[] body, int offs, IPersistent po) { ClassDescriptor.FieldDescriptor[] all = desc.allFields; ReflectionProvider provider = ClassDescriptor.ReflectionProvider; int len; for (int i = 0, n = all.Length; i < n; i++) { ClassDescriptor.FieldDescriptor fd = all[i]; FieldInfo f = fd.field; if (f == null || obj == null) { switch (fd.type) { case ClassDescriptor.tpBoolean: case ClassDescriptor.tpByte: offs += 1; continue; case ClassDescriptor.tpChar: case ClassDescriptor.tpShort: offs += 2; continue; case ClassDescriptor.tpInt: case ClassDescriptor.tpFloat: case ClassDescriptor.tpObject: offs += 4; continue; case ClassDescriptor.tpLong: case ClassDescriptor.tpDouble: case ClassDescriptor.tpDate: offs += 8; continue; case ClassDescriptor.tpString: len = Bytes.Unpack4(body, offs); offs += 4; if (len > 0) { offs += len * 2; } else if (len < -1) { offs -= (len + 2); } continue; case ClassDescriptor.tpValue: offs = UnpackObject((object) null, fd.valueDesc, recursiveLoading, body, offs, po); continue; case ClassDescriptor.tpRaw: case ClassDescriptor.tpArrayOfByte: case ClassDescriptor.tpArrayOfBoolean: len = Bytes.Unpack4(body, offs); offs += 4; if (len > 0) { offs += len; } else if (len < -1) { offs += ClassDescriptor.Sizeof[-2 - len]; } continue; case ClassDescriptor.tpArrayOfShort: case ClassDescriptor.tpArrayOfChar: len = Bytes.Unpack4(body, offs); offs += 4; if (len > 0) { offs += len * 2; } continue; case ClassDescriptor.tpArrayOfInt: case ClassDescriptor.tpArrayOfFloat: case ClassDescriptor.tpArrayOfObject: case ClassDescriptor.tpLink: len = Bytes.Unpack4(body, offs); offs += 4; if (len > 0) { offs += len * 4; } continue; case ClassDescriptor.tpArrayOfLong: case ClassDescriptor.tpArrayOfDouble: case ClassDescriptor.tpArrayOfDate: len = Bytes.Unpack4(body, offs); offs += 4; if (len > 0) { offs += len * 8; } continue; case ClassDescriptor.tpArrayOfString: len = Bytes.Unpack4(body, offs); offs += 4; if (len > 0) { for (int j = 0; j < len; j++) { int strlen = Bytes.Unpack4(body, offs); offs += 4; if (strlen > 0) { offs += strlen * 2; } else if (strlen < -1) { offs -= (strlen + 2); } } } continue; case ClassDescriptor.tpArrayOfValue: len = Bytes.Unpack4(body, offs); offs += 4; if (len > 0) { ClassDescriptor valueDesc = fd.valueDesc; for (int j = 0; j < len; j++) { offs = UnpackObject((object) null, valueDesc, recursiveLoading, body, offs, po); } } continue; case ClassDescriptor.tpArrayOfRaw: len = Bytes.Unpack4(body, offs); offs += 4; if (len > 0) { for (int j = 0; j < len; j++) { int rawlen = Bytes.Unpack4(body, offs); offs += 4; if (rawlen > 0) { offs += rawlen; } else if (rawlen < -1) { offs += ClassDescriptor.Sizeof[-2 - rawlen]; } } } continue; } } else { switch (fd.type) { case ClassDescriptor.tpBoolean: provider.SetBoolean(f, obj, body[offs++] != 0); continue; case ClassDescriptor.tpByte: provider.SetByte(f, obj, body[offs++]); continue; case ClassDescriptor.tpChar: provider.SetChar(f, obj, (char) Bytes.Unpack2(body, offs)); offs += 2; continue; case ClassDescriptor.tpShort: provider.SetShort(f, obj, Bytes.Unpack2(body, offs)); offs += 2; continue; case ClassDescriptor.tpInt: provider.SetInt(f, obj, Bytes.Unpack4(body, offs)); offs += 4; continue; case ClassDescriptor.tpLong: provider.SetLong(f, obj, Bytes.Unpack8(body, offs)); offs += 8; continue; case ClassDescriptor.tpFloat: provider.SetFloat(f, obj, Bytes.UnpackF4(body, offs)); offs += 4; continue; case ClassDescriptor.tpDouble: provider.SetDouble(f, obj, Bytes.UnpackF8(body, offs)); offs += 8; continue; case ClassDescriptor.tpString: { len = Bytes.Unpack4(body, offs); offs += 4; string str = null; if (len >= 0) { char[] chars = new char[len]; for (int j = 0; j < len; j++) { chars[j] = (char) Bytes.Unpack2(body, offs); offs += 2; } str = new string(chars); } else if (len < -1) { if (encoding != null) { string tempStr; //UPGRADE_TODO: The differences in the Format of parameters for constructor 'java.lang.String.String' may cause compilation errors. tempStr = System.Text.Encoding.GetEncoding(encoding).GetString(body); str = new string(tempStr.ToCharArray(), offs, -2 - len); } else { str = new string(SupportClass.ToCharArray(body), offs, -2 - len); } offs -= (2 + len); } provider.Set(f, obj, str); continue; } case ClassDescriptor.tpDate: { long msec = Bytes.Unpack8(body, offs); offs += 8; //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL. DateTime date; // = null; if (msec >= 0) { //UPGRADE_TODO: Constructor 'java.util.Date.Date' was converted to 'DateTime.DateTime' which has a different behavior. date = new DateTime(msec); } else date = new DateTime(); provider.Set(f, obj, date); continue; } case ClassDescriptor.tpObject: { provider.Set(f, obj, Unswizzle(Bytes.Unpack4(body, offs), f.FieldType, recursiveLoading)); offs += 4; continue; } case ClassDescriptor.tpValue: { object val = fd.valueDesc.NewInstance(); offs = UnpackObject(val, fd.valueDesc, recursiveLoading, body, offs, po); provider.Set(f, obj, val); continue; } case ClassDescriptor.tpRaw: len = Bytes.Unpack4(body, offs); offs += 4; if (len >= 0) { System.IO.MemoryStream streamIn = new System.IO.MemoryStream(body, offs, len); BinaryFormatter formatter = new BinaryFormatter(); object val = formatter.Deserialize(streamIn); provider.Set(f, obj, val); streamIn.Close(); offs += len; } else if (len < 0) { object val = null; switch (-2 - len) { case ClassDescriptor.tpBoolean: val = Convert.ToBoolean(body[offs++]); break; case ClassDescriptor.tpByte: val = (byte) body[offs++]; break; case ClassDescriptor.tpChar: val = (char) Bytes.Unpack2(body, offs); offs += 2; break; case ClassDescriptor.tpShort: val = (short) Bytes.Unpack2(body, offs); offs += 2; break; case ClassDescriptor.tpInt: val = (Int32) Bytes.Unpack4(body, offs); offs += 4; break; case ClassDescriptor.tpLong: val = (long) Bytes.Unpack8(body, offs); offs += 8; break; case ClassDescriptor.tpFloat: val = Bytes.UnpackF4(body, offs); break; case ClassDescriptor.tpDouble: val = Bytes.UnpackF8(body, offs); offs += 8; break; case ClassDescriptor.tpDate: //UPGRADE_TODO: Constructor 'java.util.Date.Date' was converted to 'DateTime.DateTime' which has a different behavior. val = new DateTime(Bytes.Unpack8(body, offs)); offs += 8; break; case ClassDescriptor.tpObject: val = Unswizzle(Bytes.Unpack4(body, offs), typeof(Persistent), recursiveLoading); offs += 4; break; } provider.Set(f, obj, val); } continue; case ClassDescriptor.tpArrayOfByte: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { byte[] arr = new byte[len]; Array.Copy(body, offs, arr, 0, len); offs += len; provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfBoolean: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { bool[] arr = new bool[len]; for (int j = 0; j < len; j++) { arr[j] = body[offs++] != 0; } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfShort: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { short[] arr = new short[len]; for (int j = 0; j < len; j++) { arr[j] = Bytes.Unpack2(body, offs); offs += 2; } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfChar: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { char[] arr = new char[len]; for (int j = 0; j < len; j++) { arr[j] = (char) Bytes.Unpack2(body, offs); offs += 2; } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfInt: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { int[] arr = new int[len]; for (int j = 0; j < len; j++) { arr[j] = Bytes.Unpack4(body, offs); offs += 4; } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfLong: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { long[] arr = new long[len]; for (int j = 0; j < len; j++) { arr[j] = Bytes.Unpack8(body, offs); offs += 8; } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfFloat: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { float[] arr = new float[len]; for (int j = 0; j < len; j++) { arr[j] = Bytes.UnpackF4(body, offs); offs += 4; } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfDouble: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { double[] arr = new double[len]; for (int j = 0; j < len; j++) { arr[j] = Bytes.UnpackF8(body, offs); offs += 8; } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfDate: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { DateTime[] arr = new DateTime[len]; for (int j = 0; j < len; j++) { long msec = Bytes.Unpack8(body, offs); offs += 8; if (msec >= 0) { //UPGRADE_TODO: Constructor 'java.util.Date.Date' was converted to 'DateTime.DateTime' which has a different behavior. arr[j] = new DateTime(msec); } } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfString: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { string[] arr = new string[len]; for (int j = 0; j < len; j++) { int strlen = Bytes.Unpack4(body, offs); offs += 4; if (strlen >= 0) { char[] chars = new char[strlen]; for (int k = 0; k < strlen; k++) { chars[k] = (char) Bytes.Unpack2(body, offs); offs += 2; } arr[j] = new string(chars); } else if (strlen < -1) { if (encoding != null) { string tempStr2; //UPGRADE_TODO: The differences in the Format of parameters for constructor 'java.lang.String.String' may cause compilation errors. tempStr2 = System.Text.Encoding.GetEncoding(encoding).GetString(body); arr[j] = new string(tempStr2.ToCharArray(), offs, -2 - strlen); } else { arr[j] = new string(SupportClass.ToCharArray(body), offs, -2 - strlen); } offs -= (2 + strlen); } } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfObject: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { Type elemType = f.FieldType.GetElementType(); IPersistent[] arr = (IPersistent[]) System.Array.CreateInstance(elemType, len); for (int j = 0; j < len; j++) { arr[j] = Unswizzle(Bytes.Unpack4(body, offs), elemType, recursiveLoading); offs += 4; } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfValue: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { Type elemType = f.FieldType.GetElementType(); object[] arr = (object[]) System.Array.CreateInstance(elemType, len); ClassDescriptor valueDesc = fd.valueDesc; for (int j = 0; j < len; j++) { object val = valueDesc.NewInstance(); offs = UnpackObject(val, valueDesc, recursiveLoading, body, offs, po); arr[j] = val; } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpArrayOfRaw: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { Type elemType = f.FieldType.GetElementType(); object[] arr = (object[]) System.Array.CreateInstance(elemType, len); for (int j = 0; j < len; j++) { int rawlen = Bytes.Unpack4(body, offs); offs += 4; if (rawlen >= 0) { // TODOPORT: System.IO.MemoryStream streamIn = new System.IO.MemoryStream(body, offs, rawlen); //UPGRADE_TODO: Class 'java.io.ObjectInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. //System.IO.BinaryReader streamIn = new PersistentObjectInputStream(this, bin); //UPGRADE_WARNING: Method 'java.io.ObjectInputStream.readObject' was converted to 'SupportClass.Deserialize' which may throw an exception. BinaryFormatter formatter = new BinaryFormatter(); object val = formatter.Deserialize(streamIn); arr[j] = val; streamIn.Close(); offs += rawlen; } else { object val = null; switch (-2 - rawlen) { case ClassDescriptor.tpBoolean: val = Convert.ToBoolean(body[offs++]); break; case ClassDescriptor.tpByte: val = (byte) body[offs++]; break; case ClassDescriptor.tpChar: val = (char) Bytes.Unpack2(body, offs); offs += 2; break; case ClassDescriptor.tpShort: val = (short) Bytes.Unpack2(body, offs); offs += 2; break; case ClassDescriptor.tpInt: val = (Int32) Bytes.Unpack4(body, offs); offs += 4; break; case ClassDescriptor.tpLong: val = (long) Bytes.Unpack8(body, offs); offs += 8; break; case ClassDescriptor.tpFloat: val = Bytes.UnpackF4(body, offs); offs += 4; break; case ClassDescriptor.tpDouble: val = Bytes.UnpackF8(body, offs); offs += 8; break; case ClassDescriptor.tpDate: //UPGRADE_TODO: Constructor 'java.util.Date.Date' was converted to 'DateTime.DateTime' which has a different behavior. val = new DateTime(Bytes.Unpack8(body, offs)); offs += 8; break; case ClassDescriptor.tpObject: val = Unswizzle(Bytes.Unpack4(body, offs), typeof(Persistent), recursiveLoading); offs += 4; break; } arr[j] = val; } } provider.Set(f, obj, arr); } continue; case ClassDescriptor.tpLink: len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { provider.Set(f, obj, (object) null); } else { IPersistent[] arr = new IPersistent[len]; for (int j = 0; j < len; j++) { int elemOid = Bytes.Unpack4(body, offs); offs += 4; if (elemOid != 0) { arr[j] = new PersistentStub(this, elemOid); } } provider.Set(f, obj, new LinkImpl(arr, po)); } break; } } } return offs; }
public virtual void Close() { lock (backgroundGcMonitor) { Commit(); opened = false; } if (gcThread != null) { gcThread.Activate(); try { gcThread.Join(); } catch (System.Threading.ThreadInterruptedException) { } } if (IsDirty()) { Page pg = pool.PutPage(0); header.Pack(pg.data); pool.Flush(); pool.Modify(pg); header.dirty = false; header.Pack(pg.data); pool.Unfix(pg); pool.Flush(); } pool.Close(); // make GC easier pool = null; objectCache = null; classDescMap = null; bitmapPageAvailableSpace = null; dirtyPagesMap = null; descList = null; }
internal void RegisterClassDescriptor(ClassDescriptor desc) { classDescMap[desc.cls] = desc; desc.next = descList; descList = desc; CheckIfFinal(desc); StoreObject0(desc); header.root[1 - currIndex].classDescList = desc.Oid; modified = true; }
internal void ReloadScheme() { classDescMap.Clear(); int descListOid = header.root[1 - currIndex].classDescList; classDescMap[typeof(ClassDescriptor)] = new ClassDescriptor(this, typeof(ClassDescriptor)); classDescMap[typeof(ClassDescriptor.FieldDescriptor)] = new ClassDescriptor(this, typeof(ClassDescriptor.FieldDescriptor)); if (descListOid != 0) { ClassDescriptor desc; descList = FindClassDescriptor(descListOid); for (desc = descList; desc != null; desc = desc.next) { desc.Load(); } for (desc = descList; desc != null; desc = desc.next) { //UPGRADE_TODO: Method 'java.util.HashMap.get' was converted to 'System.Collections.Hashtable.Item' which has a different behavior. if (classDescMap[desc.cls] == desc) { desc.Resolve(); } CheckIfFinal(desc); } } else { descList = null; } }
internal int MarkObject(byte[] obj, int offs, ClassDescriptor desc) { ClassDescriptor.FieldDescriptor[] all = desc.allFields; for (int i = 0, n = all.Length; i < n; i++) { ClassDescriptor.FieldDescriptor fd = all[i]; switch (fd.type) { case ClassDescriptor.tpBoolean: case ClassDescriptor.tpByte: offs += 1; continue; case ClassDescriptor.tpChar: case ClassDescriptor.tpShort: offs += 2; continue; case ClassDescriptor.tpInt: case ClassDescriptor.tpFloat: offs += 4; continue; case ClassDescriptor.tpLong: case ClassDescriptor.tpDouble: case ClassDescriptor.tpDate: offs += 8; continue; case ClassDescriptor.tpString: { int strlen = Bytes.Unpack4(obj, offs); offs += 4; if (strlen > 0) { offs += strlen * 2; } else if (strlen < -1) { offs -= (strlen + 2); } continue; } case ClassDescriptor.tpObject: MarkOid(Bytes.Unpack4(obj, offs)); offs += 4; continue; case ClassDescriptor.tpValue: offs = MarkObject(obj, offs, fd.valueDesc); continue; case ClassDescriptor.tpRaw: { int len = Bytes.Unpack4(obj, offs); offs += 4; if (len > 0) { offs += len; } else if (len == -2 - ClassDescriptor.tpObject) { MarkOid(Bytes.Unpack4(obj, offs)); offs += 4; } else if (len < -1) { offs += ClassDescriptor.Sizeof[-2 - len]; } continue; } case ClassDescriptor.tpArrayOfByte: case ClassDescriptor.tpArrayOfBoolean: { int len = Bytes.Unpack4(obj, offs); offs += 4; if (len > 0) { offs += len; } continue; } case ClassDescriptor.tpArrayOfShort: case ClassDescriptor.tpArrayOfChar: { int len = Bytes.Unpack4(obj, offs); offs += 4; if (len > 0) { offs += len * 2; } continue; } case ClassDescriptor.tpArrayOfInt: case ClassDescriptor.tpArrayOfFloat: { int len = Bytes.Unpack4(obj, offs); offs += 4; if (len > 0) { offs += len * 4; } continue; } case ClassDescriptor.tpArrayOfLong: case ClassDescriptor.tpArrayOfDouble: case ClassDescriptor.tpArrayOfDate: { int len = Bytes.Unpack4(obj, offs); offs += 4; if (len > 0) { offs += len * 8; } continue; } case ClassDescriptor.tpArrayOfString: { int len = Bytes.Unpack4(obj, offs); offs += 4; while (--len >= 0) { int strlen = Bytes.Unpack4(obj, offs); offs += 4; if (strlen > 0) { offs += strlen * 2; } else if (strlen < -1) { offs -= (strlen + 2); } } continue; } case ClassDescriptor.tpArrayOfObject: case ClassDescriptor.tpLink: { int len = Bytes.Unpack4(obj, offs); offs += 4; while (--len >= 0) { MarkOid(Bytes.Unpack4(obj, offs)); offs += 4; } continue; } case ClassDescriptor.tpArrayOfValue: { int len = Bytes.Unpack4(obj, offs); offs += 4; ClassDescriptor valueDesc = fd.valueDesc; while (--len >= 0) { offs = MarkObject(obj, offs, valueDesc); } continue; } case ClassDescriptor.tpArrayOfRaw: { int len = Bytes.Unpack4(obj, offs); offs += 4; while (--len >= 0) { int rawlen = Bytes.Unpack4(obj, offs); offs += 4; if (rawlen >= 0) { offs += rawlen; } else if (rawlen == -2 - ClassDescriptor.tpObject) { MarkOid(Bytes.Unpack4(obj, offs)); offs += 4; } else if (rawlen < -1) { offs += ClassDescriptor.Sizeof[-2 - rawlen]; } continue; } continue; } } } return offs; }
internal int PackObject(object obj, ClassDescriptor desc, int offs, ByteBuffer buf, IPersistent po) { ClassDescriptor.FieldDescriptor[] flds = desc.allFields; for (int i = 0, n = flds.Length; i < n; i++) { ClassDescriptor.FieldDescriptor fd = flds[i]; FieldInfo f = fd.field; switch (fd.type) { case ClassDescriptor.tpByte: buf.Extend(offs + 1); buf.arr[offs++] = (byte) f.GetValue(obj); continue; case ClassDescriptor.tpBoolean: buf.Extend(offs + 1); buf.arr[offs++] = (byte) ((bool) f.GetValue(obj) ? 1 : 0); continue; case ClassDescriptor.tpShort: buf.Extend(offs + 2); Bytes.Pack2(buf.arr, offs, (short) f.GetValue(obj)); offs += 2; continue; case ClassDescriptor.tpChar: buf.Extend(offs + 2); Bytes.Pack2(buf.arr, offs, (short) f.GetValue(obj)); offs += 2; continue; case ClassDescriptor.tpInt: buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, (int) f.GetValue(obj)); offs += 4; continue; case ClassDescriptor.tpLong: buf.Extend(offs + 8); Bytes.Pack8(buf.arr, offs, (long) f.GetValue(obj)); offs += 8; continue; case ClassDescriptor.tpFloat: buf.Extend(offs + 4); Bytes.PackF4(buf.arr, offs, (float) f.GetValue(obj)); offs += 4; continue; case ClassDescriptor.tpDouble: buf.Extend(offs + 8); Bytes.PackF8(buf.arr, offs, (double) f.GetValue(obj)); offs += 8; continue; case ClassDescriptor.tpDate: { buf.Extend(offs + 8); DateTime d = (DateTime) f.GetValue(obj); //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL. //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior. long msec = (d == null) ? -1 : d.Ticks; Bytes.Pack8(buf.arr, offs, msec); offs += 8; continue; } case ClassDescriptor.tpString: offs = buf.PackString(offs, (string) f.GetValue(obj), encoding); continue; case ClassDescriptor.tpObject: { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, Swizzle((IPersistent) f.GetValue(obj))); offs += 4; continue; } case ClassDescriptor.tpValue: { object val = f.GetValue(obj); if (val == null) { throw new StorageError(StorageError.NULL_VALUE, fd.fieldName); } else if (val is IPersistent) { throw new StorageError(StorageError.SERIALIZE_PERSISTENT); } offs = PackObject(val, fd.valueDesc, offs, buf, po); continue; } case ClassDescriptor.tpRaw: offs = PackValue(f.GetValue(obj), offs, buf); continue; case ClassDescriptor.tpArrayOfByte: { byte[] arr = (byte[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4 + len); Bytes.Pack4(buf.arr, offs, len); offs += 4; Array.Copy(arr, 0, buf.arr, offs, len); offs += len; } continue; } case ClassDescriptor.tpArrayOfBoolean: { bool[] arr = (bool[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4 + len); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++, offs++) { buf.arr[offs] = (byte) (arr[j] ? 1 : 0); } } continue; } case ClassDescriptor.tpArrayOfShort: { short[] arr = (short[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4 + len * 2); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++) { Bytes.Pack2(buf.arr, offs, arr[j]); offs += 2; } } continue; } case ClassDescriptor.tpArrayOfChar: { char[] arr = (char[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4 + len * 2); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++) { Bytes.Pack2(buf.arr, offs, (short) arr[j]); offs += 2; } } continue; } case ClassDescriptor.tpArrayOfInt: { int[] arr = (int[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4 + len * 4); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++) { Bytes.Pack4(buf.arr, offs, arr[j]); offs += 4; } } continue; } case ClassDescriptor.tpArrayOfLong: { long[] arr = (long[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4 + len * 8); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++) { Bytes.Pack8(buf.arr, offs, arr[j]); offs += 8; } } continue; } case ClassDescriptor.tpArrayOfFloat: { float[] arr = (float[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4 + len * 4); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++) { Bytes.PackF4(buf.arr, offs, arr[j]); offs += 4; } } continue; } case ClassDescriptor.tpArrayOfDouble: { double[] arr = (double[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4 + len * 8); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++) { Bytes.PackF8(buf.arr, offs, arr[j]); offs += 8; } } continue; } case ClassDescriptor.tpArrayOfDate: { DateTime[] arr = (DateTime[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4 + len * 8); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++) { DateTime d = arr[j]; //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL. //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior. long msec = (d == null) ? -1 : d.Ticks; Bytes.Pack8(buf.arr, offs, msec); offs += 8; } } continue; } case ClassDescriptor.tpArrayOfString: { string[] arr = (string[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++) { offs = buf.PackString(offs, (string) arr[j], encoding); } } continue; } case ClassDescriptor.tpArrayOfObject: { IPersistent[] arr = (IPersistent[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4 + len * 4); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++) { Bytes.Pack4(buf.arr, offs, Swizzle(arr[j])); offs += 4; } } continue; } case ClassDescriptor.tpArrayOfValue: { object[] arr = (object[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, len); offs += 4; ClassDescriptor elemDesc = fd.valueDesc; for (int j = 0; j < len; j++) { object val = arr[j]; if (val == null) throw new StorageError(StorageError.NULL_VALUE, fd.fieldName); offs = PackObject(val, elemDesc, offs, buf, po); } } continue; } case ClassDescriptor.tpArrayOfRaw: { object[] arr = (object[]) f.GetValue(obj); if (arr == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { int len = arr.Length; buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++) { offs = PackValue(arr[j], offs, buf); } } continue; } case ClassDescriptor.tpLink: { LinkImpl link = (LinkImpl) f.GetValue(obj); if (link == null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { link.owner = po; int len = link.Size; buf.Extend(offs + 4 + len * 4); Bytes.Pack4(buf.arr, offs, len); offs += 4; for (int j = 0; j < len; j++) { Bytes.Pack4(buf.arr, offs, Swizzle(link.GetRaw(j))); offs += 4; } link.Unpin(); } continue; } } } return offs; }
internal static void CheckIfFinal(ClassDescriptor desc) { Type cls = desc.cls; for (ClassDescriptor next = desc.next; next != null; next = next.next) { next.Load(); if (cls.IsAssignableFrom(next.cls)) { desc.hasSubclasses = true; } else if (next.cls.IsAssignableFrom(cls)) { next.hasSubclasses = true; } } }
internal ClassDescriptor GetClassDescriptor(Type cls) { //UPGRADE_TODO: Method 'java.util.HashMap.get' was converted to 'System.Collections.Hashtable.Item' which has a different behavior. ClassDescriptor desc = (ClassDescriptor) classDescMap[cls]; if (desc == null) { desc = new ClassDescriptor(this, cls); RegisterClassDescriptor(desc); } return desc; }
public virtual void Open(IFile file, int pagePoolSize) { lock (this) { if (opened) { throw new StorageError(StorageError.STORAGE_ALREADY_OPENED); } if (lockFile) { if (!file.Lock()) { throw new StorageError(StorageError.STORAGE_IS_USED); } } Page pg; int i; int indexSize = initIndexSize; if (indexSize < dbFirstUserId) { indexSize = dbFirstUserId; } indexSize = (indexSize + dbHandlesPerPage - 1) & ~ (dbHandlesPerPage - 1); dirtyPagesMap = new int[dbDirtyPageBitmapSize / 4 + 1]; gcThreshold = Int64.MaxValue; backgroundGcMonitor = new object(); backgroundGcStartMonitor = new object(); gcThread = null; gcActive = false; gcDone = false; allocatedDelta = 0; nNestedTransactions = 0; nBlockedTransactions = 0; nCommittedTransactions = 0; scheduledCommitTime = Int64.MaxValue; transactionMonitor = new object(); transactionLock = new PersistentResource(); modified = false; objectCache = CreateObjectCache(cacheKind, pagePoolSize, objectCacheInitSize); //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. classDescMap = new Hashtable(); descList = null; header = new Header(); byte[] buf = new byte[Header.Sizeof]; int rc = file.Read(0, buf); if (rc > 0 && rc < Header.Sizeof) { throw new StorageError(StorageError.DATABASE_CORRUPTED); } header.Unpack(buf); if (header.curr < 0 || header.curr > 1) { throw new StorageError(StorageError.DATABASE_CORRUPTED); } if (pool == null) { pool = new PagePool(pagePoolSize / Page.pageSize); pool.Open(file); } if (!header.initialized) { header.curr = currIndex = 0; long used = Page.pageSize; header.root[0].index = used; header.root[0].indexSize = indexSize; header.root[0].indexUsed = dbFirstUserId; header.root[0].freeList = 0; used += indexSize * 8L; header.root[1].index = used; header.root[1].indexSize = indexSize; header.root[1].indexUsed = dbFirstUserId; header.root[1].freeList = 0; used += indexSize * 8L; header.root[0].shadowIndex = header.root[1].index; header.root[1].shadowIndex = header.root[0].index; header.root[0].shadowIndexSize = indexSize; header.root[1].shadowIndexSize = indexSize; int bitmapPages = (int) ((used + Page.pageSize * (dbAllocationQuantum * 8 - 1) - 1) / (Page.pageSize * (dbAllocationQuantum * 8 - 1))); long bitmapSize = (long) bitmapPages * Page.pageSize; int usedBitmapSize = (int) (SupportClass.URShift((used + bitmapSize), (dbAllocationQuantumBits + 3))); for (i = 0; i < bitmapPages; i++) { pg = pool.PutPage(used + (long) i * Page.pageSize); byte[] bitmap = pg.data; int n = usedBitmapSize > Page.pageSize ? Page.pageSize : usedBitmapSize; for (int j = 0; j < n; j++) { bitmap[j] = (byte) 0xFF; } usedBitmapSize -= Page.pageSize; pool.Unfix(pg); } int bitmapIndexSize = ((dbBitmapId + dbBitmapPages) * 8 + Page.pageSize - 1) & ~ (Page.pageSize - 1); byte[] index = new byte[bitmapIndexSize]; Bytes.Pack8(index, dbInvalidId * 8, dbFreeHandleFlag); for (i = 0; i < bitmapPages; i++) { Bytes.Pack8(index, (dbBitmapId + i) * 8, used | dbPageObjectFlag); used += Page.pageSize; } header.root[0].bitmapEnd = dbBitmapId + i; header.root[1].bitmapEnd = dbBitmapId + i; while (i < dbBitmapPages) { Bytes.Pack8(index, (dbBitmapId + i) * 8, dbFreeHandleFlag); i += 1; } header.root[0].size = used; header.root[1].size = used; usedSize = used; committedIndexSize = currIndexSize = dbFirstUserId; pool.Write(header.root[1].index, index); pool.Write(header.root[0].index, index); header.dirty = true; header.root[0].size = header.root[1].size; pg = pool.PutPage(0); header.Pack(pg.data); pool.Flush(); pool.Modify(pg); header.initialized = true; header.Pack(pg.data); pool.Unfix(pg); pool.Flush(); } else { int curr = header.curr; currIndex = curr; if (header.root[curr].indexSize != header.root[curr].shadowIndexSize) { throw new StorageError(StorageError.DATABASE_CORRUPTED); } if (IsDirty()) { if (listener != null) { listener.DatabaseCorrupted(); } Console.Error.WriteLine("Database was not normally closed: start recovery"); header.root[1 - curr].size = header.root[curr].size; header.root[1 - curr].indexUsed = header.root[curr].indexUsed; header.root[1 - curr].freeList = header.root[curr].freeList; header.root[1 - curr].index = header.root[curr].shadowIndex; header.root[1 - curr].indexSize = header.root[curr].shadowIndexSize; header.root[1 - curr].shadowIndex = header.root[curr].index; header.root[1 - curr].shadowIndexSize = header.root[curr].indexSize; header.root[1 - curr].bitmapEnd = header.root[curr].bitmapEnd; header.root[1 - curr].rootObject = header.root[curr].rootObject; header.root[1 - curr].classDescList = header.root[curr].classDescList; header.root[1 - curr].bitmapExtent = header.root[curr].bitmapExtent; pg = pool.PutPage(0); header.Pack(pg.data); pool.Unfix(pg); pool.Copy(header.root[1 - curr].index, header.root[curr].index, (header.root[curr].indexUsed * 8L + Page.pageSize - 1) & ~(Page.pageSize - 1)); if (listener != null) { listener.RecoveryCompleted(); } Console.Error.WriteLine("Recovery completed"); } currIndexSize = header.root[1 - curr].indexUsed; committedIndexSize = currIndexSize; usedSize = header.root[curr].size; } int bitmapSize2 = header.root[1 - currIndex].bitmapExtent == 0 ? dbBitmapPages : dbLargeBitmapPages; bitmapPageAvailableSpace = new int[bitmapSize2]; for (i = 0; i < bitmapPageAvailableSpace.Length; i++) { bitmapPageAvailableSpace[i] = Int32.MaxValue; } currRBitmapPage = currPBitmapPage = 0; currRBitmapOffs = currPBitmapOffs = 0; opened = true; ReloadScheme(); } }
internal int PackObject(XMLElement objElem, ClassDescriptor desc, int offs, ByteBuffer buf) { ClassDescriptor.FieldDescriptor[] flds = desc.allFields; for (int i = 0, n = flds.Length; i < n; i++) { ClassDescriptor.FieldDescriptor fd = flds[i]; string fieldName = fd.fieldName; XMLElement elem = (objElem != null) ? objElem.GetSibling(fieldName) : null; switch (fd.type) { case ClassDescriptor.tpByte: buf.Extend(offs + 1); if (elem != null) { if (elem.IsIntValue()) { buf.arr[offs] = (byte) elem.GetIntValue(); } else if (elem.IsRealValue()) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. buf.arr[offs] = (byte) elem.GetRealValue(); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } } offs += 1; continue; case ClassDescriptor.tpBoolean: buf.Extend(offs + 1); if (elem != null) { if (elem.IsIntValue()) { buf.arr[offs] = (byte) (elem.GetIntValue() != 0 ? 1 : 0); } else if (elem.IsRealValue()) { buf.arr[offs] = (byte) (elem.GetRealValue() != 0.0 ? 1 : 0); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } } offs += 1; continue; case ClassDescriptor.tpShort: case ClassDescriptor.tpChar: buf.Extend(offs + 2); if (elem != null) { if (elem.IsIntValue()) { Bytes.Pack2(buf.arr, offs, (short) elem.GetIntValue()); } else if (elem.IsRealValue()) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. Bytes.Pack2(buf.arr, offs, (short) elem.GetRealValue()); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } } offs += 2; continue; case ClassDescriptor.tpInt: buf.Extend(offs + 4); if (elem != null) { if (elem.IsIntValue()) { Bytes.Pack4(buf.arr, offs, (int) elem.GetIntValue()); } else if (elem.IsRealValue()) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. Bytes.Pack4(buf.arr, offs, (int) elem.GetRealValue()); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } } offs += 4; continue; case ClassDescriptor.tpLong: buf.Extend(offs + 8); if (elem != null) { if (elem.IsIntValue()) { Bytes.Pack8(buf.arr, offs, elem.GetIntValue()); } else if (elem.IsRealValue()) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. Bytes.Pack8(buf.arr, offs, (long) elem.GetRealValue()); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } } offs += 8; continue; case ClassDescriptor.tpFloat: buf.Extend(offs + 4); if (elem != null) { if (elem.IsIntValue()) { Bytes.PackF4(buf.arr, offs, (float) elem.GetIntValue()); } else if (elem.IsRealValue()) { Bytes.PackF4(buf.arr, offs, (float) elem.GetRealValue()); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } } offs += 4; continue; case ClassDescriptor.tpDouble: buf.Extend(offs + 8); if (elem != null) { if (elem.IsIntValue()) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. Bytes.PackF8(buf.arr, offs, (double) elem.GetIntValue()); } else if (elem.IsRealValue()) { Bytes.PackF8(buf.arr, offs, (double) elem.GetRealValue()); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } } offs += 8; continue; case ClassDescriptor.tpDate: buf.Extend(offs + 8); if (elem != null) { if (elem.IsIntValue()) { Bytes.Pack8(buf.arr, offs, elem.GetIntValue()); } else if (elem.IsNullValue()) { Bytes.Pack8(buf.arr, offs, -1); } else if (elem.IsStringValue()) { /* TODOPORT: //UPGRADE_ISSUE: Method 'java.text.DateFormat.parse' was not converted. DateTime date = httpFormatter.parse(elem.GetStringValue(), 0); //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL. if (date == null) { ThrowException("Invalid date"); } //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior. Bytes.Pack8(buf.arr, offs, date.Ticks); */ ThrowException("Not implemented"); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } } offs += 8; continue; case ClassDescriptor.tpString: if (elem != null) { string val = null; if (elem.IsIntValue()) { val = Convert.ToString(elem.GetIntValue()); } else if (elem.IsRealValue()) { val = elem.GetRealValue().ToString(); } else if (elem.IsStringValue()) { val = elem.GetStringValue(); } else if (elem.IsNullValue()) { val = null; } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } offs = buf.PackString(offs, val, storage.encoding); continue; } buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; continue; case ClassDescriptor.tpObject: { int oid = 0; if (elem != null) { XMLElement ref_Renamed = elem.GetSibling("ref"); if (ref_Renamed == null) { ThrowException("<ref> element expected"); } oid = MapId(GetIntAttribute(ref_Renamed, "id")); } buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, oid); offs += 4; continue; } case ClassDescriptor.tpValue: offs = PackObject(elem, fd.valueDesc, offs, buf); continue; case ClassDescriptor.tpRaw: case ClassDescriptor.tpArrayOfByte: offs = ImportBinary(elem, offs, buf, fieldName); continue; case ClassDescriptor.tpArrayOfBoolean: if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; buf.Extend(offs + 4 + len); Bytes.Pack4(buf.arr, offs, len); offs += 4; while (--len >= 0) { if (item.IsIntValue()) { buf.arr[offs] = (byte) (item.GetIntValue() != 0 ? 1 : 0); } else if (item.IsRealValue()) { buf.arr[offs] = (byte) (item.GetRealValue() != 0.0 ? 1 : 0); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } item = item.NextSibling; offs += 1; } } continue; case ClassDescriptor.tpArrayOfChar: case ClassDescriptor.tpArrayOfShort: if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; buf.Extend(offs + 4 + len * 2); Bytes.Pack4(buf.arr, offs, len); offs += 4; while (--len >= 0) { if (item.IsIntValue()) { Bytes.Pack2(buf.arr, offs, (short) item.GetIntValue()); } else if (item.IsRealValue()) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. Bytes.Pack2(buf.arr, offs, (short) item.GetRealValue()); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } item = item.NextSibling; offs += 2; } } continue; case ClassDescriptor.tpArrayOfInt: if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; buf.Extend(offs + 4 + len * 4); Bytes.Pack4(buf.arr, offs, len); offs += 4; while (--len >= 0) { if (item.IsIntValue()) { Bytes.Pack4(buf.arr, offs, (int) item.GetIntValue()); } else if (item.IsRealValue()) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. Bytes.Pack4(buf.arr, offs, (int) item.GetRealValue()); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } item = item.NextSibling; offs += 4; } } continue; case ClassDescriptor.tpArrayOfLong: if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; buf.Extend(offs + 4 + len * 8); Bytes.Pack4(buf.arr, offs, len); offs += 4; while (--len >= 0) { if (item.IsIntValue()) { Bytes.Pack8(buf.arr, offs, item.GetIntValue()); } else if (item.IsRealValue()) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. Bytes.Pack8(buf.arr, offs, (long) item.GetRealValue()); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } item = item.NextSibling; offs += 8; } } continue; case ClassDescriptor.tpArrayOfFloat: if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; buf.Extend(offs + 4 + len * 4); Bytes.Pack4(buf.arr, offs, len); offs += 4; while (--len >= 0) { if (item.IsIntValue()) { Bytes.PackF4(buf.arr, offs, (float) item.GetIntValue()); } else if (item.IsRealValue()) { Bytes.PackF4(buf.arr, offs, (float) item.GetRealValue()); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } item = item.NextSibling; offs += 4; } } continue; case ClassDescriptor.tpArrayOfDouble: if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; buf.Extend(offs + 4 + len * 8); Bytes.Pack4(buf.arr, offs, len); offs += 4; while (--len >= 0) { if (item.IsIntValue()) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. Bytes.PackF8(buf.arr, offs, (double) item.GetIntValue()); } else if (item.IsRealValue()) { Bytes.PackF8(buf.arr, offs, (double) item.GetRealValue()); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } item = item.NextSibling; offs += 8; } } continue; case ClassDescriptor.tpArrayOfDate: if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; buf.Extend(offs + 4 + len * 8); Bytes.Pack4(buf.arr, offs, len); offs += 4; while (--len >= 0) { if (item.IsNullValue()) { Bytes.Pack8(buf.arr, offs, -1); } else if (item.IsStringValue()) { /* TODOPORT: //UPGRADE_ISSUE: Method 'java.text.DateFormat.parse' was not converted. DateTime date = httpFormatter.parse(item.GetStringValue(), 0); //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL. if (date == null) { ThrowException("Invalid date"); } //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior. Bytes.Pack8(buf.arr, offs, date.Ticks); */ ThrowException("Not implemented"); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } item = item.NextSibling; offs += 8; } } continue; case ClassDescriptor.tpArrayOfString: if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, len); offs += 4; while (--len >= 0) { string val = null; if (item.IsIntValue()) { val = Convert.ToString(item.GetIntValue()); } else if (item.IsRealValue()) { val = item.GetRealValue().ToString(); } else if (item.IsStringValue()) { val = item.GetStringValue(); } else if (elem.IsNullValue()) { val = null; } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } offs = buf.PackString(offs, val, storage.encoding); item = item.NextSibling; } } continue; case ClassDescriptor.tpArrayOfObject: case ClassDescriptor.tpLink: if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; buf.Extend(offs + 4 + len * 4); Bytes.Pack4(buf.arr, offs, len); offs += 4; while (--len >= 0) { XMLElement ref_Renamed = item.GetSibling("ref"); if (ref_Renamed == null) { ThrowException("<ref> element expected"); } int oid = MapId(GetIntAttribute(ref_Renamed, "id")); Bytes.Pack4(buf.arr, offs, oid); item = item.NextSibling; offs += 4; } } continue; case ClassDescriptor.tpArrayOfValue: if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; Bytes.Pack4(buf.arr, offs, len); offs += 4; ClassDescriptor elemDesc = fd.valueDesc; while (--len >= 0) { offs = PackObject(item, elemDesc, offs, buf); item = item.NextSibling; } } continue; case ClassDescriptor.tpArrayOfRaw: if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; Bytes.Pack4(buf.arr, offs, len); offs += 4; while (--len >= 0) { offs = ImportBinary(item, offs, buf, fieldName); item = item.NextSibling; } } continue; } } return offs; }
internal int ExportObject(ClassDescriptor desc, byte[] body, int offs, int indent) { ClassDescriptor.FieldDescriptor[] all = desc.allFields; for (int i = 0, n = all.Length; i < n; i++) { ClassDescriptor.FieldDescriptor fd = all[i]; Indentation(indent); string fieldName = ExportIdentifier(fd.fieldName); writer.Write("<" + fieldName + ">"); switch (fd.type) { case ClassDescriptor.tpBoolean: writer.Write(body[offs++] != 0 ? "1" : "0"); break; case ClassDescriptor.tpByte: writer.Write(Convert.ToString((byte) body[offs++])); break; case ClassDescriptor.tpChar: writer.Write(Convert.ToString((char) Bytes.Unpack2(body, offs))); offs += 2; break; case ClassDescriptor.tpShort: writer.Write(Convert.ToString(Bytes.Unpack2(body, offs))); offs += 2; break; case ClassDescriptor.tpInt: writer.Write(Convert.ToString(Bytes.Unpack4(body, offs))); offs += 4; break; case ClassDescriptor.tpLong: writer.Write(Convert.ToString(Bytes.Unpack8(body, offs))); offs += 8; break; case ClassDescriptor.tpFloat: float flt = Bytes.UnpackF4(body, offs); writer.Write(flt.ToString()); offs += 4; break; case ClassDescriptor.tpDouble: double dbl = Bytes.UnpackF8(body, offs); writer.Write(dbl.ToString()); offs += 8; break; case ClassDescriptor.tpString: offs = ExportString(body, offs); break; case ClassDescriptor.tpDate: { long msec = Bytes.Unpack8(body, offs); offs += 8; if (msec >= 0) { //UPGRADE_TODO: Constructor 'java.util.Date.Date' was converted to 'DateTime.DateTime' which has a different behavior. // TODOPORT: writer.Write("\"" + SupportClass.FormatDateTime(XMLImporter.httpFormatter, new DateTime(msec)) + "\""); throw new NotImplementedException(); } else { writer.Write("null"); } break; } case ClassDescriptor.tpObject: ExportRef(Bytes.Unpack4(body, offs)); offs += 4; break; case ClassDescriptor.tpValue: writer.Write('\n'); offs = ExportObject(fd.valueDesc, body, offs, indent + 1); Indentation(indent); break; case ClassDescriptor.tpRaw: case ClassDescriptor.tpArrayOfByte: offs = ExportBinary(body, offs); break; case ClassDescriptor.tpArrayOfBoolean: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); writer.Write("<element>" + (body[offs++] != 0 ? "1" : "0") + "</element>\n"); } Indentation(indent); } break; } case ClassDescriptor.tpArrayOfChar: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); writer.Write("<element>" + (Bytes.Unpack2(body, offs) & 0xFFFF) + "</element>\n"); offs += 2; } Indentation(indent); } break; } case ClassDescriptor.tpArrayOfShort: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); writer.Write("<element>" + Bytes.Unpack2(body, offs) + "</element>\n"); offs += 2; } Indentation(indent); } break; } case ClassDescriptor.tpArrayOfInt: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); writer.Write("<element>" + Bytes.Unpack4(body, offs) + "</element>\n"); offs += 4; } Indentation(indent); } break; } case ClassDescriptor.tpArrayOfLong: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); writer.Write("<element>" + Bytes.Unpack8(body, offs) + "</element>\n"); offs += 8; } Indentation(indent); } break; } case ClassDescriptor.tpArrayOfFloat: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); writer.Write("<element>" + Bytes.UnpackF4(body, offs) + "</element>\n"); offs += 4; } Indentation(indent); } break; } case ClassDescriptor.tpArrayOfDouble: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); writer.Write("<element>" + Bytes.UnpackF8(body, offs) + "</element>\n"); offs += 8; } Indentation(indent); } break; } case ClassDescriptor.tpArrayOfDate: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); long msec = Bytes.Unpack8(body, offs); offs += 8; if (msec >= 0) { writer.Write("<element>\""); //UPGRADE_TODO: Constructor 'java.util.Date.Date' was converted to 'DateTime.DateTime' which has a different behavior. // TODOPORT: writer.Write(SupportClass.FormatDateTime(XMLImporter.httpFormatter, new DateTime(msec))); writer.Write("\"</element>\n"); throw new NotImplementedException(); } else { writer.Write("<element>null</element>\n"); } } } break; } case ClassDescriptor.tpArrayOfString: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); writer.Write("<element>"); offs = ExportString(body, offs); writer.Write("</element>\n"); } Indentation(indent); } break; } case ClassDescriptor.tpLink: case ClassDescriptor.tpArrayOfObject: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); int oid = Bytes.Unpack4(body, offs); if (oid != 0 && (exportedBitmap[oid >> 5] & (1 << (oid & 31))) == 0) { markedBitmap[oid >> 5] |= 1 << (oid & 31); } writer.Write("<element><ref id=\"" + oid + "\"/></element>\n"); offs += 4; } Indentation(indent); } break; } case ClassDescriptor.tpArrayOfValue: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); writer.Write("<element>\n"); offs = ExportObject(fd.valueDesc, body, offs, indent + 2); Indentation(indent + 1); writer.Write("</element>\n"); } Indentation(indent); } break; } case ClassDescriptor.tpArrayOfRaw: { int len = Bytes.Unpack4(body, offs); offs += 4; if (len < 0) { writer.Write("null"); } else { writer.Write('\n'); while (--len >= 0) { Indentation(indent + 1); writer.Write("<element>"); offs = ExportBinary(body, offs); writer.Write("</element>\n"); } Indentation(indent); } break; } } writer.Write("</" + fieldName + ">\n"); } return offs; }
internal void Resolve() { if (resolved) return; StorageImpl classStorage = (StorageImpl) Storage; ClassDescriptor desc = new ClassDescriptor(classStorage, cls); resolved = true; if (!desc.Equals(this)) classStorage.RegisterClassDescriptor(desc); }
public bool Equals(ClassDescriptor cd) { if (cd == null || allFields.Length != cd.allFields.Length) { return false; } for (int i = 0; i < allFields.Length; i++) { if (!allFields[i].Equals(cd.allFields[i])) { return false; } } return true; }