예제 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Executes the task.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void ExecuteTask()
        {
            Log(Level.Info, "Running {0}", Path.GetFileName(FixturePath));

            Thread outputThread = null;
            Thread errorThread  = null;

            try
            {
                // Start the external process
                var process = StartProcess();
                outputThread = new Thread(StreamReaderThread_Output);
                errorThread  = new Thread(StreamReaderThread_Error);

                m_StdOut   = process.StandardOutput;
                m_StdError = process.StandardError;

                outputThread.Start();
                errorThread.Start();

                // Wait for the process to terminate
                process.WaitForExit(TimeOut);

                // Wait for the threads to terminate
                outputThread.Join(2000);
                errorThread.Join(2000);

                if (!process.HasExited)
                {
                    try
                    {
                        process.Kill();
                    }
                    catch
                    {
                        // ignore possible exceptions that are thrown when the
                        // process is terminated
                    }

                    throw new BuildException(
                              String.Format("{0} did not finish in {1} milliseconds.",
                                            FixturePath,
                                            TimeOut),
                              Location);
                }

                MemoryStream.Position = 0;
                WriteXmlResultFile();
                MemoryWriter.Close();
                MemoryStream.Close();

                if (process.ExitCode != 0)
                {
                    throw new BuildException(
                              String.Format("{0} returned with exit code {1}",
                                            FixturePath,
                                            process.ExitCode),
                              Location);
                }
            }
            catch (BuildException e)
            {
                if (FailOnError)
                {
                    throw;
                }
                else
                {
                    Log(Level.Error, e.Message);
                }
            }
            catch (Exception e)
            {
                throw new BuildException(
                          string.Format(CultureInfo.InvariantCulture,
                                        "{0}: {1} had errors. ", GetType(), FixturePath),
                          Location,
                          e);
            }
            finally
            {
                // ensure outputThread is always aborted
                if (outputThread != null && outputThread.IsAlive)
                {
                    outputThread.Abort();
                }
                // ensure errorThread is always aborted
                if (errorThread != null && errorThread.IsAlive)
                {
                    errorThread.Abort();
                }
            }
        }
예제 #2
0
        public override byte [] ProcessDataReceived(byte [] rec, int length)
        {
            byte [] data = null;
            if (still != null)
            {
                data = new byte[length + still.Length];
                Buffer.BlockCopy(still, 0, data, 0, still.Length);
                Buffer.BlockCopy(rec, 0, data, still.Length, length);
            }
            else
            {
                data = rec;
            }
            #region State 0
            if (state == 0)              //	Wait for a command
            {
                if (data[2] == 0x1)      //	read
                {
                    state     = 1;
                    guid      = BitConverter.ToUInt64(data, 5);
                    character = (Character)World.FindMobileByGUID(guid);
                    if (character == null)
                    {
                        this.Send(new byte[] { 2, 0, 1, 0 }, 0, 4);                          //	character exist, ok to read
                    }
                    else
                    {
                        #region State 1, Read file
                        if (state == 1)
                        {
                            MemoryWriter mw = new MemoryWriter();
                            character.Serialize(mw);
                            mw.Close();
                            byte [] buffer = new byte[4098];

                            for (int t = 0; t < mw.buff.Length; t += 4096)
                            {
                                int offset = 0;
                                int rlen   = 0;
                                if (mw.buff.Length - t < 4096)
                                {
                                    rlen = mw.buff.Length - t;
                                }
                                else
                                {
                                    rlen = 4096;
                                }
                                Converter.ToBytes((ushort)rlen, buffer, ref offset);
                                Buffer.BlockCopy(mw.buff, t, buffer, 2, rlen);
                                this.Send(buffer, 0, rlen + 2);
                            }
                        }
                        #endregion
                    }
                    if (13 == length)
                    {
                        return(null);
                    }
                    still = data;
                }
                else
                if (data[2] == 0x2)                            //	save
                {
                    state = 2;

                    if (13 == length)
                    {
                        return(null);
                    }
                    still = data;
                }
            }
            #endregion


            return(null);
        }