Example #1
0
        public async Task AsStreamReturnsPipeWriterStream(WriteAsyncDelegate writeAsync)
        {
            byte[] helloBytes = Encoding.ASCII.GetBytes("Hello World");
            var    pipe       = new Pipe();
            Stream stream     = pipe.Writer.AsStream();

            await writeAsync(stream, helloBytes);

            ReadResult result = await pipe.Reader.ReadAsync();

            Assert.Equal(helloBytes, result.Buffer.ToArray());
            pipe.Reader.Complete();
            pipe.Writer.Complete();
        }
Example #2
0
        static NullableHandler()
        {
            UnderlyingType = Nullable.GetUnderlyingType(typeof(T));

            if (UnderlyingType == null)
            {
                return;
            }

            Read                 = NullableHandler.CreateDelegate <ReadDelegate <T> >(UnderlyingType, NullableHandler.ReadMethod);
            ReadAsync            = NullableHandler.CreateDelegate <ReadAsyncDelegate <T> >(UnderlyingType, NullableHandler.ReadAsyncMethod);
            ValidateAndGetLength = NullableHandler.CreateDelegate <ValidateAndGetLengthDelegate <T> >(UnderlyingType, NullableHandler.ValidateMethod);
            WriteAsync           = NullableHandler.CreateDelegate <WriteAsyncDelegate <T> >(UnderlyingType, NullableHandler.WriteAsyncMethod);
        }
Example #3
0
        public async Task WritingToPipeStreamWritesToUnderlyingPipeWriter(WriteAsyncDelegate writeAsync)
        {
            byte[] helloBytes = Encoding.ASCII.GetBytes("Hello World");
            var    pipe       = new Pipe();
            var    stream     = new PipeWriterStream(pipe.Writer, leaveOpen: false);

            await writeAsync(stream, helloBytes);

            ReadResult result = await pipe.Reader.ReadAsync();

            Assert.Equal(helloBytes, result.Buffer.ToArray());
            pipe.Reader.Complete();
            pipe.Writer.Complete();
        }
Example #4
0
        internal void Write(PadInt padInt, int val)
        {
            if (State.Equals(TransactionState.ABORTED))
            {
                Console.WriteLine("Write padint UID= " + padInt.UID + "denied because of server failer");
                return;
            }

            string remotePadIntURL = padInt.URL + "RemotePadInt";
            int    uid             = padInt.UID;

            IRemotePadInt remote = (IRemotePadInt)Activator.GetObject(
                typeof(IRemotePadInt), remotePadIntURL);

            write_lock = true;
            WriteAsyncDelegate RemoteDel      = new WriteAsyncDelegate(remote.Write);
            AsyncCallback      RemoteCallback = new AsyncCallback(WriteAsyncCallBack);
            IAsyncResult       RemAr          = RemoteDel.BeginInvoke(uid, TXID, val, PadiDstm.Client_Url, RemoteCallback, padInt);

            timerAlive(padInt.URL);
            while (write_lock)
            {
                Thread.Sleep(1);
            }

            resetTimer();

            //lock (freeze_lock) { freeze_lock.Remove(uid); }

            if (State.Equals(TransactionState.ABORTED))
            {
                Console.WriteLine("Write padint UID= " + padInt.UID + "denied because of server failer");
                return;
            }

            //  remote.Write(uid, TXID, val, PadiDstm.Client_Url);
            AddValue(uid, val);
            addAccessedServer(padInt.URL);
        }