Пример #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);
        }
Пример #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);
        }
Пример #3
0
        private async Task <bool> HandleValueReturn(NetRequest request)
        {
            if (request.Metadata != NetRequestMetadata.ValueReturn)
            {
                return(false);
            }

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

            if (!result)
            {
                CachedNetValues.Add(valueName, new Tuple <bool, object>(false, null));
                return(true);
            }

            CachedNetValues.Add(valueName, new Tuple <bool, object>(true, request.Data.Value[2]));

            await Task.FromResult(0);

            return(true);
        }
Пример #4
0
        private async Task <bool> HandleFunctionRequest(NetRequest request)
        {
            if (request.Metadata != NetRequestMetadata.FunctionRequest)
            {
                return(false);
            }

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

            object[] parameters = (object[])request.Data.Value[1];

            if (!Functions.ContainsKey(functionName))
            {
                try
                {
                    S.Send(new StorableValue <NetRequest>(new NetRequest(NetRequestMetadata.FunctionReturn, functionName, NetRequestResult.Invalid)).Bytes);
                }
                catch (SocketException)
                {
                    return(false);
                }

                return(true);
            }

            try
            {
                S.Send(new StorableValue <NetRequest>(new NetRequest(NetRequestMetadata.FunctionReturn, functionName, NetRequestResult.Completed, await Functions[functionName].Invoke(this, parameters))).Bytes);
            }
            catch (SocketException)
            {
                return(false);
            }

            await Task.FromResult(0);

            return(true);
        }
Пример #5
0
        private async Task <bool> HandleValueRequest(NetRequest request)
        {
            if (request.Metadata != NetRequestMetadata.ValueRequest)
            {
                return(false);
            }

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

            if (!Values.ContainsKey(valueName))
            {
                try
                {
                    S.Send(new StorableValue <NetRequest>(new NetRequest(NetRequestMetadata.ValueReturn, valueName,
                                                                         false)).Bytes);
                }
                catch (SocketException)
                {
                    return(false);
                }

                return(true);
            }

            try
            {
                S.Send(new StorableValue <NetRequest>(new NetRequest(NetRequestMetadata.ValueReturn, valueName, true,
                                                                     Values[valueName])).Bytes);
            }
            catch (SocketException)
            {
                return(false);
            }

            await Task.FromResult(0);

            return(true);
        }
Пример #6
0
        private async Task <bool> HandleInvocationRequest(NetRequest request)
        {
            if (request.Metadata != NetRequestMetadata.InvocationRequest)
            {
                return(false);
            }

            string netEvent = (string)request.Data.Value[0];

            if (!Events.ContainsKey(netEvent))
            {
                try
                {
                    S.Send(new StorableValue <NetRequest>(new NetRequest(NetRequestMetadata.InvocationReturn, netEvent, NetRequestResult.Incompleted)).Bytes);
                }
                catch
                {
                    return(false);
                }
            }

            object[] parameters = (object[])request.Data.Value[1];

            await Events[netEvent].Invoke(this, parameters);

            try
            {
                S.Send(new StorableValue <NetRequest>(new NetRequest(NetRequestMetadata.InvocationReturn, netEvent, NetRequestResult.Completed)).Bytes);
            }
            catch (SocketException)
            {
                return(false);
            }

            await Task.FromResult(0);

            return(true);
        }