Exemple #1
0
        private byte[] core_open_stream_channel(byte[] args)
        {
            List <byte> request          = new List <byte>(args);
            int         stream_id        = Struct.extractInt32(request);
            byte        passthrough_byte = Struct.extractByte(request);
            bool        passthrough      = false;

            if (passthrough_byte == 1)
            {
                passthrough = true;
            }

            // check if stream is present
            bool exists = this.hasStream(stream_id);

            if (!exists)
            {
                throw new Exception(String.Format("Stream with ID '{0}' doesn't exist", stream_id));
            }

            // create stream channel
            Stream        stream = this.getStream(stream_id);
            StreamChannel sc     = new StreamChannel(stream, this.callbackChannelOutputPresent, this.triggerProcessingNeeded, passthrough);

            //add stream channel to transport layer channels
            this.AddChannel(sc);

            //return stream id
            UInt32      result   = sc.ID;
            List <byte> response = Struct.packUInt32(result);

            return(response.ToArray());
        }
Exemple #2
0
        private byte[] core_create_proc(byte[] args)
        {
            List <byte> data = new List <byte>(args);

            // first byte indicates if STDIN, STDOUT and STDERR should be streamed to channels
            bool   use_channels  = (Struct.extractByte(data) != 0);
            string proc_filename = Struct.extractNullTerminatedString(data);
            string proc_args     = Struct.extractNullTerminatedString(data);

            ClientProcess proc = new ClientProcess(proc_filename, proc_args, use_channels, this.callbackChannelOutputPresent, this.triggerProcessingNeeded); //starts the process already

            proc.registerOnExitCallback(this.onProcessExit);


            if (use_channels)
            {
                this.AddChannel(proc.Ch_stdin);
                this.AddChannel(proc.Ch_stdout);
                this.AddChannel(proc.Ch_stderr);


                /*
                 * proc.Ch_stdin = this.tl.CreateChannel(Channel.Types.IN, Channel.Encodings.UTF8);
                 * proc.Ch_stdout = this.tl.CreateChannel(Channel.Types.OUT, Channel.Encodings.UTF8);
                 * proc.Ch_stderr = this.tl.CreateChannel(Channel.Types.OUT, Channel.Encodings.UTF8);
                 */
            }



            //generate method response
            List <byte> resp = Struct.packUInt32((UInt32)proc.Id);

            if (use_channels)
            {
                resp = Struct.packByte(1, resp);
                resp = Struct.packUInt32(proc.Ch_stdin.ID, resp);
                resp = Struct.packUInt32(proc.Ch_stdout.ID, resp);
                resp = Struct.packUInt32(proc.Ch_stderr.ID, resp);
            }
            else
            {
                resp = Struct.packByte(0, resp);
                resp = Struct.packUInt32(0, resp);
                resp = Struct.packUInt32(0, resp);
                resp = Struct.packUInt32(0, resp);
            }

            Monitor.Enter(this.pendingClientProcessesLock);
            this.pending_client_processes.Add(proc.Id, proc);
            Monitor.Exit(this.pendingClientProcessesLock);

            //throw new ClientMethodException(String.Format("Not implemented: Trying to start proc '{0}' with args: {1}", proc_filename, proc_args));
            return(resp.ToArray());
        }
        public override void EnqueueInput(byte[] data)
        {
            List <byte> data_list = new List <byte>(data);
            byte        data_type = Struct.extractByte(data_list);

            if (data_type == 0) //normal data
            {
                data = data_list.ToArray();
                this.stream.Write(data, 0, data.Length);
                Console.WriteLine(String.Format("Written to stream: {0}", data));
            }
            else
            {
                dispatchControlMessage(data_list);
            }
        }
Exemple #4
0
        /*
         * //REMOVE, obsolete
         * private byte[] core_create_filechannel(byte[] args)
         * {
         *  List<byte> request = new List<byte>(args);
         *  String local_filename = Struct.extractNullTerminatedString(request);
         *  String local_file_access_mode = Struct.extractNullTerminatedString(request);
         *  Byte local_file_target = Struct.extractByte(request); //0 = disc, 1 = in memory
         *  Byte local_file_force = Struct.extractByte(request); //0 = don't force, 1= force (if force is set, non existing file get overwritten on WRITE, and non existing files are created on READWRITE
         *
         *
         *  //create the file channel, on error an exception will be thrown and handled by the caller
         *  FileChannel fc = new FileChannel(this.tl.setOutputProcessingNeeded, local_filename, local_file_access_mode, local_file_target, (local_file_force == 1));
         *
         *  //String response = String.Format("Created file channel for '{0}', access '{1}', mode: {2}, force {3}", local_filename, local_file_access_mode, local_file_target, local_file_force);
         *
         *  //if we are here, channel creation succeded and we return the channel ID as response
         *  List<byte> response = Struct.packUInt32(fc.ID);
         *  return response.ToArray();
         * }
         */

        private byte[] core_fs_open_file(byte[] args)
        {
            List <byte> request  = new List <byte>(args);
            String      filename = Struct.extractNullTerminatedString(request);
            FileMode    fm       = (FileMode)Struct.extractByte(request);
            FileAccess  fa       = (FileAccess)Struct.extractByte(request);

            FileStream fs = File.Open(filename, fm, fa);

            this.addStream(fs);            //store this in global list of opened streams
            int result = fs.GetHashCode(); //return stream id

            //if we are here, channel creation succeded and we return the channel ID as response
            List <byte> response = Struct.packInt32(result);

            return(response.ToArray());
        }