Beispiel #1
0
        public async Task Set204StatusCodeWhenChannelComplete()
        {
            using (var factory = new ChannelFactory())
            {
                var connection = new Connection();
                connection.ConnectionId = Guid.NewGuid().ToString();
                var channel = new HttpChannel(factory);
                connection.Channel = channel;
                var context = new DefaultHttpContext();
                var poll    = new LongPolling(connection);

                channel.Output.CompleteWriter();

                await poll.ProcessRequestAsync(context);

                Assert.Equal(204, context.Response.StatusCode);
            }
        }
Beispiel #2
0
        public async Task NoFramingAddedWhenDataSent()
        {
            using (var factory = new ChannelFactory())
            {
                var connection = new Connection();
                connection.ConnectionId = Guid.NewGuid().ToString();
                var channel = new HttpChannel(factory);
                connection.Channel = channel;
                var context = new DefaultHttpContext();
                var ms      = new MemoryStream();
                context.Response.Body = ms;
                var poll = new LongPolling(connection);

                await channel.Output.WriteAsync(Encoding.UTF8.GetBytes("Hello World"));

                channel.Output.CompleteWriter();

                await poll.ProcessRequestAsync(context);

                Assert.Equal("Hello World", Encoding.UTF8.GetString(ms.ToArray()));
            }
        }
Beispiel #3
0
        public static SyncedHttpHandler.ISyncedRequestHandler GenericSyncedHandler(LongPolling.ConnectionList connectionList, HttpRequest request, string connectionID, Func<GenericPageFile> createCallback)
        {
            var customObjectName = request.QueryString[ PageFile.RqstFileID ];
            if( customObjectName == "" )
                customObjectName = null;
            GenericPageFile pageFileInstance;
            if( customObjectName != null )
            {
                // Try get the PageFile instance using the CustomObjectName
                pageFileInstance = (GenericPageFile)connectionList.GetConnectionCustomObject( connectionID, customObjectName );
                if( pageFileInstance != null )
                    // Found: Return it
                    return pageFileInstance;
            }
            // Not found => Create a new instance
            pageFileInstance = createCallback();

            if( customObjectName != null )
            {
                // Register it in the ConnectionList
                pageFileInstance.CustomObjectName = customObjectName;
                var obj = pageFileInstance.MessageHandler.ConnectionList.GetConnectionCustomObject( connectionID, pageFileInstance.CustomObjectName, ()=>pageFileInstance );
                CommonLibs.Utils.Debug.ASSERT( obj == pageFileInstance, System.Reflection.MethodInfo.GetCurrentMethod(), "The registration of this 'GenericPageFile' did not return this instance (another one already exists)" );
            }

            // And invoke the callback on the receiver class to give it the new instance
            var assemblyName = request.QueryString[ RqstUploadReceiverAssembly ];
            if( string.IsNullOrEmpty(assemblyName) )
                throw new ArgumentException( "GenericFileUpload failed: query parameter '" + RqstUploadReceiverAssembly + "' is missing" );
            var typeName = request.QueryString[ RqstUploadReceiverType ];
            if( string.IsNullOrEmpty(typeName) )
                throw new ArgumentException( "GenericFileUpload failed: query parameter '" + RqstUploadReceiverType + "' is missing" );
            var methodName = request.QueryString[ RqstUploadReceiverMethod ];
            if( string.IsNullOrEmpty(methodName) )
                throw new ArgumentException( "GenericFileUpload failed: query parameter '" + RqstUploadReceiverMethod + "' is missing" );

            var assembly = AppDomain.CurrentDomain.GetAssemblies().Where( v=>v.ManifestModule.Name == assemblyName ).Single();
            var type = assembly.GetType( typeName );
            var methodParameters = new Type[] {	typeof(LongPolling.ConnectionList),
                                                typeof(string),
                                                typeof(GenericPageFile),
                                                typeof(HttpRequest) };
            var method = type.GetMethod( methodName, System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Static, null, methodParameters, null );
            if( method == null )
                throw new ArgumentException( "GenericFileUpload failed: Could not find method '" + methodName + "()' in type '" + assemblyName+"."+typeName + "'" );
            method.Invoke( type, new object[]{connectionList, connectionID, pageFileInstance, request} );

            return pageFileInstance;
        }