コード例 #1
0
        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;
        }
コード例 #2
0
        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);
                    }
                }
            }
        }
コード例 #3
0
 public static bool TryGetType(Type dataType, out IOTType type)
 {
     return(_dataTypes.TryGetValue(dataType, out type));
 }
コード例 #4
0
 public static bool TryGetType(string id, out IOTType type)
 {
     return(_types.TryGetValue(id, out type));
 }
コード例 #5
0
 public static void Register(IOTType type)
 {
     _types[type.Name]           = type;
     _types[type.Uri.ToString()] = type;
     _dataTypes[type.DataType]   = type;
 }