Exemple #1
0
        private static object ToObject(MValue mv, MCollection parent, ref bool cache)
        {
            var type = Native.FLValue_GetType(mv.Value);

            switch (type)
            {
            case FLValueType.Array:
                cache = true;
                return(parent?.MutableChildren == true ? new MutableArrayObject(mv, parent) : new ArrayObject(mv, parent));

            case FLValueType.Dict:
                cache = true;
                var context = parent?.Context as DocContext;
                var flDict  = Native.FLValue_AsDict(mv.Value);
                var subType = Native.FLValue_AsString(Native.FLDict_Get(flDict,
                                                                        Encoding.UTF8.GetBytes(ObjectTypeProperty)));
                var obj = CreateSpecialObject(subType, flDict, context);
                if (obj != null)
                {
                    return(obj);
                }

                return(parent?.MutableChildren == true
                        ? new MutableDictionaryObject(mv, parent)
                        : new DictionaryObject(mv, parent));

            default:
                return(FLSliceExtensions.ToObject(mv.Value));
            }
        }
        private static void DoOpen(C4Socket *socket, C4Address *address, C4Slice options)
        {
            var builder = new UriBuilder {
                Host   = address->hostname.CreateString(),
                Scheme = address->scheme.CreateString(),
                Port   = address->port,
                Path   = address->path.CreateString()
            };

            Uri uri;

            try {
                uri = builder.Uri;
            } catch (Exception) {
                Native.c4socket_closed(socket, new C4Error(C4ErrorCode.InvalidParameter));
                return;
            }

            if (uri == null)
            {
                Native.c4socket_closed(socket, new C4Error(C4ErrorCode.InvalidParameter));
                return;
            }

            var opts =
                FLSliceExtensions.ToObject(NativeRaw.FLValue_FromTrustedData((FLSlice)options)) as
                Dictionary <string, object>;
            var replicationOptions = new ReplicatorOptionsDictionary(opts);
            var socketWrapper      = new WebSocketWrapper(uri, socket, replicationOptions);
            var id = Interlocked.Increment(ref _NextID);

            socket->nativeHandle = (void *)id;
            Sockets[id]          = socketWrapper;
            socketWrapper.Start();
        }
Exemple #3
0
 private unsafe void TestRoundTrip <T>(T item)
 {
     using (var encoded = item.FLEncode()) {
         var flValue = NativeRaw.FLValue_FromData((FLSlice)encoded, FLTrust.Trusted);
         ((IntPtr)flValue).Should().NotBe(IntPtr.Zero);
         if (item is IEnumerable enumerable && !(item is string))
         {
             ((IEnumerable)FLSliceExtensions.ToObject(flValue)).Should().BeEquivalentTo(enumerable);
         }
        private static void DoOpen(C4Socket *socket, C4Address *address, FLSlice options, void *context)
        {
            var builder = new UriBuilder {
                Host   = address->hostname.CreateString(),
                Scheme = address->scheme.CreateString(),
                Port   = address->port,
                Path   = address->path.CreateString()
            };

            Uri uri;

            try {
                uri = builder.Uri;
            } catch (Exception) {
                Native.c4socket_closed(socket, new C4Error(C4ErrorCode.InvalidParameter));
                return;
            }

            if (uri == null)
            {
                Native.c4socket_closed(socket, new C4Error(C4ErrorCode.InvalidParameter));
                return;
            }

            var opts =
                FLSliceExtensions.ToObject(NativeRaw.FLValue_FromData((FLSlice)options, FLTrust.Trusted)) as
                Dictionary <string, object>;
            var replicationOptions = new ReplicatorOptionsDictionary(opts);

            var id = Interlocked.Increment(ref _NextID);

            Native.c4Socket_setNativeHandle(socket, (void *)id);
            var socketWrapper = new WebSocketWrapper(uri, socket, replicationOptions);
            var replicator    = GCHandle.FromIntPtr((IntPtr)context).Target as Replicator;

            replicator?.WatchForCertificate(socketWrapper);
            replicator?.CheckForCookiesToSet(socketWrapper);
            Sockets.AddOrUpdate(id, socketWrapper, (k, v) => socketWrapper);
            socketWrapper.Start();
        }