Example #1
0
        public bool GetValueFromPayload(string payloadName, ProcessPayload <string> handler)
        {
            object pv = TryGetNonNullPayloadValue(payloadName);

            if (pv == null)
            {
                return(false);
            }

            if (pv is string sv)
            {
                handler(sv);
                return(true);
            }

            try
            {
                sv = Convert.ToString(pv);
                handler(sv);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #2
0
        public bool GetValueFromPayload(string payloadName, ProcessPayload <double> handler)
        {
            object pv = TryGetNonNullPayloadValue(payloadName);

            if (pv == null)
            {
                return(false);
            }

            double?value = null;

            switch (pv)
            {
            case double dv:
                value = dv;
                break;

            case float fv:
                value = fv;
                break;

            case byte bv:
                value = bv;
                break;

            case short sv:
                value = sv;
                break;

            case ushort usv:
                value = usv;
                break;

            case int iv:
                value = iv;
                break;

            case uint uiv:
                value = uiv;
                break;

            case long lv:
                value = lv;
                break;

            case ulong ulv:
                value = ulv;
                break;
            }

            if (value.HasValue)
            {
                handler(value.Value);
                return(true);
            }
            else
            {
                return(GetValueFromPayload <double>(payloadName, handler));
            }
        }
Example #3
0
 public void Start(int port, ProcessPayload handler)
 {
     _handler = handler;
     _port    = port;
     ThreadPool.SetMinThreads(50, 50);
     RunThread(Run);
 }
Example #4
0
            public ClientHandler(TcpClient ClientSocket, ProcessPayload payloadhandler)
            {
                ClientSocket.ReceiveTimeout = Config.SEND_TIMEOUT;
                ClientSocket.SendTimeout    = ClientSocket.ReceiveTimeout;

                this.ClientSocket = ClientSocket;
                networkStream     = ClientSocket.GetStream();
                bytes             = new byte[ClientSocket.ReceiveBufferSize];
                _ProcessPayload   = payloadhandler;
            }
Example #5
0
 public void Start(int port, ProcessPayload handler)
 {
     _handler = handler;
     _port    = port;
     ThreadPool.SetMinThreads(50, 50);
     System.Timers.Timer t = new System.Timers.Timer(1000);
     t.AutoReset = true;
     t.Start();
     t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
     Task.Factory.StartNew(() => Run(), TaskCreationOptions.AttachedToParent);
 }
        public static async Task <ProcessPayload> RunServer(DirectoryInfo directory, CancellationToken cancellationToken = default)
        {
            var payload       = new ProcessPayload();
            var serverCommand = getCommandInfo(directory);
            var logDir        = directory.CreateSubdirectory("server-process-info");
            var unused        = Task.Run(async() => await OperationSystemService.RunCommandAsync(serverCommand, payload, logDir, directory.FullName, cancellationToken: cancellationToken), cancellationToken);

            while (!payload.IsRunning())
            {
                await Task.Delay(100, cancellationToken);
            }
            return(payload);
        }
Example #7
0
        private bool GetValueFromPayloadMatchingType <T>(string payloadName, ProcessPayload <T> handler)
        {
            object pv = TryGetNonNullPayloadValue(payloadName);

            if (pv == null)
            {
                return(false);
            }

            if (pv is T tValue)
            {
                handler(tValue);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #8
0
        public bool GetValueFromPayload <T>(string payloadName, ProcessPayload <T> handler)
        {
            if (string.IsNullOrEmpty(payloadName))
            {
                return(false);
            }

            object p;

            if (!Payload.TryGetValue(payloadName, out p) || p == null)
            {
                return(false);
            }

            bool converted = false;
            T    value     = default(T);

            try
            {
                value     = (T)p;
                converted = true;
            }
            catch { }

            if (!converted)
            {
                try
                {
                    value     = (T)Convert.ChangeType(p, typeof(T));
                    converted = true;
                }
                catch { }
            }

            if (converted)
            {
                handler(value);
            }

            return(converted);
        }
Example #9
0
        public bool GetValueFromPayload(string payloadName, ProcessPayload <ulong> handler)
        {
            object pv = TryGetNonNullPayloadValue(payloadName);

            if (pv == null)
            {
                return(false);
            }

            ulong?value = null;

            switch (pv)
            {
            case ulong ulv:
                value = ulv;
                break;

            case uint uiv:
                value = uiv;
                break;

            case byte bv:
                value = bv;
                break;

            case ushort usv:
                value = usv;
                break;
            }

            if (value.HasValue)
            {
                handler(value.Value);
                return(true);
            }
            else
            {
                return(GetValueFromPayload <ulong>(payloadName, handler));
            }
        }
Example #10
0
        public static async Task <ProcessPayload> RunClient(DirectoryInfo directory, int port, ClientMode mode, int clientTimeout = 1000, CancellationToken cancellationToken = default)
        {
            Debug.WriteLine($"running client file in directory {directory.FullName} in mode {mode}");

            var payload = new ProcessPayload();

            var serverCommand = getCommandInfo(directory, port, mode, clientTimeout);
            var logDir        = directory.CreateSubdirectory($"client-{mode}-process-info");
            var unused        = Task.Run(async() => await OperationSystemService.RunCommandAsync(
                                             serverCommand,
                                             payload,
                                             logDir,
                                             directory.FullName,
                                             cancellationToken: cancellationToken), cancellationToken);

            while (!payload.IsRunning())
            {
                await Task.Delay(100, cancellationToken);
            }

            Debug.WriteLine($"returning payload of client file in directory {directory.FullName} in mode {mode}");
            return(payload);
        }
Example #11
0
        public bool GetValueFromPayload <T>(string payloadName, ProcessPayload <T> handler)
        {
            object pv = TryGetNonNullPayloadValue(payloadName);

            if (pv == null)
            {
                return(false);
            }

            bool converted = false;
            T    value     = default(T);

            try
            {
                value     = (T)pv;
                converted = true;
            }
            catch { }

            if (!converted)
            {
                try
                {
                    value     = (T)Convert.ChangeType(pv, typeof(T));
                    converted = true;
                }
                catch { }
            }

            if (converted)
            {
                handler(value);
            }

            return(converted);
        }
Example #12
0
 public void Start(int port, ProcessPayload handler)
 {
     _handler = handler;
     _port = port;
     ThreadPool.SetMinThreads(50, 50);
     System.Timers.Timer t = new System.Timers.Timer(1000);
     t.AutoReset = true;
     t.Start();
     t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
     Task.Factory.StartNew(() => Run(), TaskCreationOptions.AttachedToParent);
 }
Example #13
0
 public bool GetValueFromPayload(string payloadName, ProcessPayload <TimeSpan> handler)
 {
     return(GetValueFromPayloadMatchingType <TimeSpan>(payloadName, handler) ? true : GetValueFromPayload <TimeSpan>(payloadName, handler));
 }
Example #14
0
 public bool GetValueFromPayload(string payloadName, ProcessPayload <DateTimeOffset> handler)
 {
     return(GetValueFromPayloadMatchingType <DateTimeOffset>(payloadName, handler) ? true : GetValueFromPayload <DateTimeOffset>(payloadName, handler));
 }
Example #15
0
 public NetworkServer(int port, ProcessPayload callback)
 {
     _portNum        = port;
     _processPayload = callback;
 }