internal Document(Connection conn, string collection, string id, IOTType type = null) { _inflightFetches = new ConcurrentQueue <TaskCompletionSource <bool> >(); _conn = conn; Collection = collection; Id = id; Version = -1; Type = type; }
void IDocumentInternal.HandleFetch(ShareDBException ex, int version, string type, JToken ops) { if (!_inflightFetches.TryDequeue(out TaskCompletionSource <bool> tcs)) { return; } if (ex != null) { tcs.SetException(ex); } else { IOTType otType = null; if (type != null && !OTTypes.TryGetType(type, out otType)) { tcs.SetException(new ShareDBException($"Unregistered type {type}.", 4008)); } if (Type == null) { Type = otType; } if (otType != null && Type != otType) { tcs.SetException(new ShareDBException("The document type does not match the retrieved data type.", 4101)); } else { Version = version; if (ops != null) { Data = (T)Type.Deserialize(ops); IsLoaded = true; tcs.SetResult(true); } else { tcs.SetResult(false); } } } }
public static bool TryGetType(Type dataType, out IOTType type) { return(_dataTypes.TryGetValue(dataType, out type)); }
public static bool TryGetType(string id, out IOTType type) { return(_types.TryGetValue(id, out type)); }
public static void Register(IOTType type) { _types[type.Name] = type; _types[type.Uri.ToString()] = type; _dataTypes[type.DataType] = type; }