Ejemplo n.º 1
0
        private async Task <bool> HandleInvocationReturn(NetRequest request)
        {
            if (request.Metadata != NetRequestMetadata.InvocationReturn)
            {
                return(false);
            }

            string           valueName = (string)request.Data.Value[0];
            NetRequestResult result    = (NetRequestResult)request.Data.Value[1];

            CachedNetEvents.Add(valueName, result);

            await Task.FromResult(0);

            return(true);
        }
Ejemplo n.º 2
0
        private async Task <bool> HandleFunctionReturn(NetRequest request)
        {
            if (request.Metadata != NetRequestMetadata.FunctionReturn)
            {
                return(false);
            }

            string           functionName = (string)request.Data.Value[0];
            NetRequestResult result       = (NetRequestResult)request.Data.Value[1];

            if (result != NetRequestResult.Completed)
            {
                CachedNetFunctions.Add(functionName, new Tuple <NetRequestResult, object>(result, null));
                return(true);
            }

            CachedNetFunctions.Add(functionName, new Tuple <NetRequestResult, object>(result, request.Data.Value[2]));

            await Task.FromResult(0);

            return(true);
        }
Ejemplo n.º 3
0
        public async Task <NetRequestResult> TryTriggerNetEvent(string netEventName, params object[] parameters)
        {
            while (Sending)
            {
                await Task.Delay(10);
            }

            Sending = true;
            S.Send(new StorableValue <NetRequest>(new NetRequest(NetRequestMetadata.InvocationRequest, netEventName, parameters)).Bytes);
            Sending = false;

            while (Receiving)
            {
                await Task.Delay(10);
            }

            Receiving = true;
            await Receive();

            Receiving = false;

            while (!CachedNetEvents.ContainsKey(netEventName) && !Closed)
            {
                await Task.Delay(10);
            }

            if (Closed)
            {
                return(NetRequestResult.Disconnected);
            }

            NetRequestResult result = CachedNetEvents[netEventName];

            CachedNetFunctions.Remove(netEventName);

            return(result);
        }