public DocContext(Database db, C4DocumentWrapper doc) : base(new FLSlice(), db.SharedStrings.SharedKeys) { Db = db; Doc = doc?.Retain <C4DocumentWrapper>(); SharedStrings = db.SharedStrings; }
public DocContext(Database db, C4Document *doc) : base(new FLSlice(), db.SharedStrings.SharedKeys) { Db = db; Doc = doc; SharedStrings = db.SharedStrings; }
/// <summary> /// Creates a database given a name and some configuration /// </summary> /// <param name="name">The name of the database</param> /// <param name="configuration">The configuration to open it with</param> public Database(string name, DatabaseConfiguration configuration = null) { Name = CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(name), name); Config = configuration?.Freeze() ?? new DatabaseConfiguration(true); Open(); FLSharedKeys *keys = null; ThreadSafety.DoLocked(() => keys = Native.c4db_getFLSharedKeys(_c4db)); _sharedStrings = new SharedStringCache(keys); }
public unsafe void Populate(FLArrayIterator iterator, SharedStringCache sharedStrings) { var i = iterator; var serializer = JsonSerializer.CreateDefault(); var count = Native.FLArrayIterator_GetCount(&i); Results = Activator.CreateInstance(_elementType.MakeArrayType(), (int)count); for (var index = 0U; index < count; index++) { using (var reader = new JsonFLValueReader(Native.FLArrayIterator_GetValueAt(&i, index), sharedStrings)) { (Results as IList)[(int)index] = serializer.Deserialize(reader); } } }
public unsafe void Populate(FLArrayIterator iterator, SharedStringCache sharedStrings) { var iter = iterator; var serializer = JsonSerializer.CreateDefault(); var parameters = new List <object>(); for (var i = 0U; i < Native.FLArrayIterator_GetCount(&iter); i++) { using (var reader = new JsonFLValueReader(Native.FLArrayIterator_GetValueAt(&iter, i), sharedStrings)) { var nextItem = serializer.Deserialize(reader, _constructor.GetParameters()[(int)i].ParameterType); parameters.Add(nextItem); } } Results = _constructor.Invoke(parameters.ToArray()); }
public unsafe void TestSharedstrings() { var now = DateTimeOffset.UtcNow; var nestedArray = new[] { 1L, 2L, 3L }; var nestedDict = new Dictionary <string, object> { ["foo"] = "bar" }; var masterData = new object[] { 1, "str", nestedArray, now, nestedDict }; var flData = new FLSliceResult(); Db.InBatch(() => { flData = masterData.FLEncode(); }); try { var context = new DocContext(Db, null); using (var mRoot = new MRoot(context)) { var flValue = NativeRaw.FLValue_FromTrustedData((FLSlice)flData); var mArr = new MArray(new MValue(flValue), mRoot); var sharedstrings = context.SharedStrings; FLEncoder *fLEncoder = Db.SharedEncoder; mRoot.FLEncode(fLEncoder); mRoot.Encode(); var isReadonly = mArr.IsReadOnly; isReadonly.Should().BeFalse(); #if !WINDOWS_UWP Assert.Throws <NotImplementedException>(() => mArr.IndexOf(now)); Assert.Throws <NotImplementedException>(() => mArr.Contains(now)); Assert.Throws <NotImplementedException>(() => mArr.Remove(now)); Assert.Throws <NotImplementedException>(() => mArr.CopyTo(new object[] { }, 12)); #endif var flDict = Native.FLValue_AsDict(flValue); var sharedStringCache = new SharedStringCache(); var sharedStringCache1 = new SharedStringCache(sharedStringCache); sharedStringCache1 = new SharedStringCache(sharedStringCache, flDict); var i = default(FLDictIterator); var iterKey = sharedStringCache1.GetDictIterKey(&i); sharedStringCache1.UseDocumentRoot(flDict); } } finally { Native.FLSliceResult_Free(flData); } }