public void InitChannels()
 {
     if (_dataChannel == null)
     {
         _dataChannel         = new ProcessChannel(1, "Global\\task_" + _channelId.ToString(), MAXDATASIZE);
         _contrCmdChannel     = new ProcessChannel(1, "Global\\contrcmd_" + _channelId.ToString(), MAXACKSIZE);
         _processorCmdChannel = new ProcessChannel(1, "Global\\proccmd_" + _channelId.ToString(), MAXACKSIZE);
     }
 }
Exemplo n.º 2
0
        //RunAsync is an "echo" type service which reads
        //one message and sends back to the server same data
        public static async Task RunAsync(string[] args)
        {
            using (var client = new ProcessChannel())
            {
                client.StartClient(args[1], args[2]);

                var    cs2 = new CancellationTokenSource();
                var    packetReceiveTask = client.ReceiveAsync(cs2.Token);
                Task[] taskToWait        = { packetReceiveTask, Task.Delay(5000) };
                //Wait up to 5 seconds for the server to call us and then reply back with the same data
                await Task.WhenAny(taskToWait);

                bool timedOut = !packetReceiveTask.IsCompleted;
                if (timedOut)
                {
                    cs2.Cancel();
                    try
                    {
                        await packetReceiveTask;
                    }
                    catch (OperationCanceledException)
                    {
                        // Ignore OperationCanceledException and TaskCanceledException exceptions
                    }
                    catch (AggregateException errors)
                    {
                        // Ignore OperationCanceledException and TaskCanceledException exceptions
                        errors.Handle(e => e is OperationCanceledException);
                    }
                }
                else
                {
                    var message = JsonUtility.FromString <JobRequestMessage>(packetReceiveTask.Result.Body);
                    await client.SendAsync(MessageType.NewJobRequest, JsonUtility.ToString(message), cs2.Token);
                }
            }
        }
Exemplo n.º 3
0
        //RunAsync is an "echo" type service which reads
        //one message and sends back to the server same data 
        public static async Task RunAsync(string[] args)
        {
            using (var client = new ProcessChannel())
            {
                client.StartClient(args[1], args[2]);

                var cs2 = new CancellationTokenSource();
                var packetReceiveTask = client.ReceiveAsync(cs2.Token);
                Task[] taskToWait = { packetReceiveTask, Task.Delay(30*1000)  };
                //Wait up to 5 seconds for the server to call us and then reply back with the same data
                await Task.WhenAny(taskToWait);
                bool timedOut = !packetReceiveTask.IsCompleted;
                if (timedOut)
                {
                    cs2.Cancel();
                    try
                    {
                        await packetReceiveTask;
                    }
                    catch (OperationCanceledException)
                    {
                        // Ignore OperationCanceledException and TaskCanceledException exceptions
                    }
                    catch (AggregateException errors)
                    {
                        // Ignore OperationCanceledException and TaskCanceledException exceptions
                        errors.Handle(e => e is OperationCanceledException);
                    }
                }
                else
                {
                    var message = JsonUtility.FromString<JobRequestMessage>(packetReceiveTask.Result.Body);
                    await client.SendAsync(MessageType.NewJobRequest, JsonUtility.ToString(message), cs2.Token);
                }
            }
        }
Exemplo n.º 4
0
 public void Dispose()
 {
     ProcessChannel?.Dispose();
     IsRunning = false;
     Exited?.Invoke(this, new ProcessExitedEventArgs(0));
 }
Exemplo n.º 5
0
        public async Task RunIPCEndToEnd()
        {
            using (var server = new ProcessChannel())
            {                
                JobRequestMessage result = null;                
                TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference();
                TimelineReference timeline = null;
                JobEnvironment environment = new JobEnvironment();
                List<TaskInstance> tasks = new List<TaskInstance>();
                Guid JobId = Guid.NewGuid();
                var jobRequest = new JobRequestMessage(plan, timeline, JobId, "someJob", environment, tasks);
                Process jobProcess;
                server.StartServer((p1, p2) =>
                {
                    string clientFileName = $"Test{IOUtil.ExeExtension}";
                    jobProcess = new Process();
                    jobProcess.StartInfo.FileName = clientFileName;
                    jobProcess.StartInfo.Arguments = "spawnclient " + p1 + " " + p2;
                    jobProcess.EnableRaisingEvents = true;                    
                    jobProcess.Start();
                });
                var cs = new CancellationTokenSource();                
                await server.SendAsync(MessageType.NewJobRequest, JsonUtility.ToString(jobRequest), cs.Token);
                var packetReceiveTask = server.ReceiveAsync(cs.Token);
                Task[] taskToWait = { packetReceiveTask, Task.Delay(30*1000) };
                await Task.WhenAny(taskToWait);
                bool timedOut = !packetReceiveTask.IsCompleted;

                // Wait until response is received
                if (timedOut)
                {
                    cs.Cancel();
                    try
                    {
                        await packetReceiveTask;
                    }
                    catch (OperationCanceledException)
                    {
                        // Ignore OperationCanceledException and TaskCanceledException exceptions
                    }
                    catch (AggregateException errors)
                    {
                        // Ignore OperationCanceledException and TaskCanceledException exceptions
                        errors.Handle(e => e is OperationCanceledException);
                    }
                }
                else
                {
                    result = JsonUtility.FromString<JobRequestMessage>(packetReceiveTask.Result.Body);                    
                }

                // Wait until response is received
                if (timedOut)
                {
                    Assert.True(false, "Test timed out.");
                }
                else
                {
                    Assert.True(jobRequest.JobId.Equals(result.JobId) && jobRequest.JobName.Equals(result.JobName));
                }
            }
        }
Exemplo n.º 6
0
        public async Task RunIPCEndToEnd()
        {
            using (var server = new ProcessChannel())
            {
                JobRequestMessage result            = null;
                TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference();
                TimelineReference   timeline        = null;
                JobEnvironment      environment     = new JobEnvironment();
                List <TaskInstance> tasks           = new List <TaskInstance>();
                Guid    JobId      = Guid.NewGuid();
                var     jobRequest = new JobRequestMessage(plan, timeline, JobId, "someJob", environment, tasks);
                Process jobProcess;
                server.StartServer((p1, p2) =>
                {
                    string clientFileName          = $"Test{IOUtil.ExeExtension}";
                    jobProcess                     = new Process();
                    jobProcess.StartInfo.FileName  = clientFileName;
                    jobProcess.StartInfo.Arguments = "spawnclient " + p1 + " " + p2;
                    jobProcess.EnableRaisingEvents = true;
                    jobProcess.Start();
                });
                var cs = new CancellationTokenSource();
                await server.SendAsync(MessageType.NewJobRequest, JsonUtility.ToString(jobRequest), cs.Token);

                var    packetReceiveTask = server.ReceiveAsync(cs.Token);
                Task[] taskToWait        = { packetReceiveTask, Task.Delay(5000) };
                await Task.WhenAny(taskToWait);

                bool timedOut = !packetReceiveTask.IsCompleted;

                // Wait until response is received
                if (timedOut)
                {
                    cs.Cancel();
                    try
                    {
                        await packetReceiveTask;
                    }
                    catch (OperationCanceledException)
                    {
                        // Ignore OperationCanceledException and TaskCanceledException exceptions
                    }
                    catch (AggregateException errors)
                    {
                        // Ignore OperationCanceledException and TaskCanceledException exceptions
                        errors.Handle(e => e is OperationCanceledException);
                    }
                }
                else
                {
                    result = JsonUtility.FromString <JobRequestMessage>(packetReceiveTask.Result.Body);
                }

                // Wait until response is received
                if (timedOut)
                {
                    Assert.True(false, "Test timed out.");
                }
                else
                {
                    Assert.True(jobRequest.JobId.Equals(result.JobId) && jobRequest.JobName.Equals(result.JobName));
                }
            }
        }
Exemplo n.º 7
0
        private InlineProcessingResult Execute(Packet request, Packet response)
        {
            var processChannel = default(ProcessChannel);
            var arguments      = request.Tlvs.TryGetTlvValueAsString(TlvType.StdapiProcessArguments);
            var executablePath = request.Tlvs.TryGetTlvValueAsString(TlvType.StdapiProcessPath);
            var flags          = (ProcessExecutionFlags)request.Tlvs.TryGetTlvValueAsDword(TlvType.StdapiProcessFlags);
            var parentPid      = request.Tlvs.TryGetTlvValueAsDword(TlvType.StdapiProcessParentProcessId);

            response.Result = PacketResult.Success;

            if (!string.IsNullOrEmpty(executablePath))
            {
                var newProcess = new Process
                {
                    StartInfo = new ProcessStartInfo(executablePath, arguments)
                    {
                        CreateNoWindow = flags.HasFlag(ProcessExecutionFlags.Hidden)
                    }
                };

                if (flags.HasFlag(ProcessExecutionFlags.Channelized))
                {
                    processChannel = new ProcessChannel(channelManager, newProcess);
                    this.channelManager.Manage(processChannel);
                }

                if (newProcess.Start())
                {
                    if (processChannel != null)
                    {
                        processChannel.ProcessStarted();
                    }

                    response.Add(TlvType.StdapiProcessId, newProcess.Id);
                    response.Add(TlvType.ChannelId, processChannel.ChannelId);
                }
                else
                {
                    response.Result = PacketResult.InvalidFunction;
                }
            }
            else
            {
                response.Result = PacketResult.BadArguments;
            }
#if THISISNOTATHING
            // If the channelized flag is set, create a pipe for stdin/stdout/stderr
            // such that input can be directed to and from the remote endpoint
            if (flags & PROCESS_EXECUTE_FLAG_CHANNELIZED)
            {
                SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
                PoolChannelOps      chops;
                Channel *           newChannel;

                // Allocate the channel context
                if (!(ctx = (ProcessChannelContext *)malloc(sizeof(ProcessChannelContext))))
                {
                    result = ERROR_NOT_ENOUGH_MEMORY;
                    break;
                }

                memset(&chops, 0, sizeof(PoolChannelOps));

                // Initialize the channel operations
                dprintf("[PROCESS] context address 0x%p", ctx);
                chops.native.context  = ctx;
                chops.native.write    = process_channel_write;
                chops.native.close    = process_channel_close;
                chops.native.interact = process_channel_interact;
                chops.read            = process_channel_read;

                // Allocate the pool channel
                if (!(newChannel = met_api->channel.create_pool(0, CHANNEL_FLAG_SYNCHRONOUS, &chops)))
                {
                    result = ERROR_NOT_ENOUGH_MEMORY;
                    break;
                }

                // Set the channel's type to process
                met_api->channel.set_type(newChannel, "process");

                // Allocate the stdin and stdout pipes
                if ((!CreatePipe(&in [0], &in [1], &sa, 0)) || (!CreatePipe(&out[0], &out[1], &sa, 0)))
Exemplo n.º 8
0
 public VideoTranfert()
 {
     // Crée un MMF pour contenir 512 frame de 1MB
     _pictureTransfert = new ProcessChannel(256, "VidplaycorderPciture", 2 * 1024 * 1024);
 }