Exemplo n.º 1
0
 private void OnJobCompleted(object sender, JobCompletedEventArgs jobCompletedEventArgs)
 {
     if (!jobCompletedEventArgs.Completed)
     {
         CentipedeSerializer.Serialize(ClientStream, false);
     }
     ClientStream.Close();
     _messagePipe.Close();
     System.Windows.Forms.Application.Exit();
 }
Exemplo n.º 2
0
        protected override void DoAction()
        {
            CentipedeSerializer.Serialize(ClientStream, true);
            //ClientStream.WaitForPipeDrain();
            try
            {
                if (!String.IsNullOrWhiteSpace(OutVars))
                {
                    var variables = this.OutVars.Split(',').Select(s => s.Trim()).ToList();
                    CentipedeSerializer.Serialize(ClientStream, variables.Count);

                    foreach (var variable in variables)
                    {
                        object o = Variables[variable];
                        try
                        {
                            CentipedeSerializer.Serialize(ClientStream, o);
                        }
                        catch (SerializationException e)
                        {
                            var message =
                                string.Format(
                                    "Cannot send variable {0} to parent job, type {1} is not supported.",
                                    variable,
                                    o.GetType());

                            throw new FatalActionException(message, e, this);
                        }
                    }
                }
                else
                {
                    CentipedeSerializer.Serialize(ClientStream, 0);
                }
            }
            catch (IOException e)
            {
                OnMessage(new MessageEventArgs
                {
                    Message = string.Format(
                        "Sending variables to parent raised IOException: {0}",
                        e.Message),
                    Level = MessageLevel.Debug
                });
            }
            finally
            {
                ClientStream.Close();
            }
        }
Exemplo n.º 3
0
        protected override void DoAction()
        {
            Stream stream = new MemoryStream();

            var variable = Variables[InVar];

            CentipedeSerializer.Serialize(stream, variable);

            stream.Seek(0, SeekOrigin.Begin);

            string text = new StreamReader(stream).ReadToEnd();

            if (!String.IsNullOrEmpty(OutVar))
            {
                Variables[OutVar] = text;
            }
            else
            {
                MessageBox.Show(text);
            }
        }
Exemplo n.º 4
0
        protected override void DoAction()
        {
            this._process = new Process
            {
                StartInfo =
                {
                    FileName        = this.JobFileName,

                    Verb            = "Run",
                    UseShellExecute = true
                }
            };

            this._process.Start();

            this._serverStream = new Socket(AddressFamily.InterNetwork,
                                            SocketType.Stream,
                                            ProtocolType.IP);
            this._serverStream.Bind(new IPEndPoint(IPAddress.Loopback, PortNumber));

            this._bgw = new BackgroundWorker();
            this._bgw.WorkerSupportsCancellation = true;
            this._bgw.DoWork += BgwOnDoWork;

            this._bgw.RunWorkerAsync();


            Socket connection = null;

            try
            {
                this._serverStream.Listen(0);

                connection = this._serverStream.Accept();

                var ss = new SocketStream(connection);


                if (!String.IsNullOrWhiteSpace(this.InputVars))
                {
                    List <string> variables =
                        this.InputVars.Split(',').Select(s => s.Trim()).ToList();

                    //send number of variables
                    CentipedeSerializer.Serialize(ss, variables.Count);

                    try
                    {
                        foreach (var variable in variables)
                        {
                            object o = this.Variables[variable];
                            try
                            {
                                CentipedeSerializer.Serialize(ss, o);
                            }
                            catch (SerializationException e)
                            {
                                throw new FatalActionException(
                                          string.Format(
                                              "Cannot send variable {0} to subjob, type {1} is not supported.",
                                              variable,
                                              o.GetType()),
                                          e,
                                          this);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        throw new ActionException(e, this);
                    }
                }
                else
                {
                    //no variables to send
                    CentipedeSerializer.Serialize(ss, 0);
                }

                var subJobSuccess = (bool)CentipedeSerializer.Deserialize(ss);

                if (!subJobSuccess)
                {
                    throw new ActionException("Subjob was not completed", this);
                }


                //recieve vars, if any
                var varsToRecieve = CentipedeSerializer.Deserialize <int>(ss);

                var received = new List <object>(varsToRecieve);

                for (int i = 0; i < varsToRecieve; i++)
                {
                    received.Add(CentipedeSerializer.Deserialize(ss));
                }

                if (!String.IsNullOrWhiteSpace(this.OutputVars))
                {
                    List <string> outputVars =
                        this.OutputVars.Split(',').Select(s => s.Trim()).ToList();

                    if (varsToRecieve != outputVars.Count)
                    {
                        throw new FatalActionException(
                                  string.Format("Wrong number of variables, expected {0}, got {1}",
                                                outputVars.Count,
                                                varsToRecieve));
                    }

                    foreach (var tuple in outputVars.Zip(received, Tuple.Create))
                    {
                        this.Variables[tuple.Item1] = tuple.Item2;
                    }
                }
                else
                {
                    if (varsToRecieve != 0)
                    {
                        throw new ActionException(
                                  string.Format("Recieved {0} {1} from subjob, was not expecting any.",
                                                varsToRecieve,
                                                "variable".Pluralize(varsToRecieve)));
                    }
                }
            }
            finally
            {
                try
                {
                    this._serverStream.Close();
                    if (connection != null)
                    {
                        connection.Close();
                    }
                    this._messagePipe.Close();
                    if (!this._process.HasExited)
                    {
                        this._process.CloseMainWindow();
                        this._process.Close();
                        if (!this._process.WaitForExit(10000))
                        {
                            this._process.Kill();
                            this._process = null;
                        }
                    }
                }
                catch (Exception e)
                {
                    this.OnMessage(new MessageEventArgs
                    {
                        Message = e.Message,
                        Level   = MessageLevel.Debug
                    });
                }
            }
        }