Beispiel #1
0
        public void ErrorMustMatch(MsysgitResources.Definition resource, params object[] args)
        {
            var expected = string.Format(Resources[resource], args).Trim();
            var actual   = StdErr.Trim();

            Assert.AreEqual(expected, actual, "Git operation StdErr mismatch");
        }
Beispiel #2
0
 public CompileOptions(ArtifactsType artifactsType, string config, bool writeWaterMark = true, StdErr.IOutput stderr = null)
 {
     this.ArtifactsType = artifactsType;
     this.ProjectConfig = config;
     this.WriteWaterMark = writeWaterMark;
     if (stderr != null)
         this.StdError = stderr;
 }
Beispiel #3
0
 private int DisplayPreSize(IntPtr handle, IntPtr device, int width, int height, int raster, uint format)
 {
     try
     {
         ClearProgressiveImage();
     }
     catch (Exception e)
     {
         StdErr.Append(e);
         return(Native.gs_error_Fatal);
     }
     return(0);
 }
Beispiel #4
0
 private int DisplayPreClose(IntPtr handle, IntPtr device)
 {
     try
     {
         ClearProgressiveImage();
     }
     catch (Exception e)
     {
         StdErr.Append(e);
         return(Native.gs_error_Fatal);
     }
     return(0);
 }
Beispiel #5
0
 public void EndTarget(IObsoleteTask task, string name, IBounceCommand command, TaskResult result)
 {
     if (logOptions.ReportTargetEnd)
     {
         if (result == TaskResult.Success)
         {
             StdOut.WriteLine("{0} target: {1}", command.PastTense, name);
         }
         else
         {
             StdErr.WriteLine("failed to {0} target: {1}", command.InfinitiveTense, name);
         }
     }
 }
Beispiel #6
0
 public void EndTask(IObsoleteTask task, IBounceCommand command, TaskResult result)
 {
     if (logOptions.ReportTaskEnd && task.IsLogged && command.IsLogged)
     {
         if (result == TaskResult.Success)
         {
             StdOut.WriteLine("{0} task: {1}", command.PastTense, task);
         }
         else
         {
             StdErr.WriteLine("failed to {0} task: {1}", command.InfinitiveTense, task);
         }
     }
 }
Beispiel #7
0
            public int WaitForExitAndFinalize()
            {
                process.WaitForExit();

                if (StdOut != null)
                {
                    StdOut.Terminate();
                }
                if (StdErr != null)
                {
                    StdErr.Terminate();
                }
                return(process.ExitCode);
            }
Beispiel #8
0
 protected void WriteLogMessage()
 {
     Console.WriteLine("[" + _Status + "] " + Name + " [" + ElapsedTime.ToString() + "sec]");
     if (Status == Status_t.Fail)
     {
         if (StdOut.Length > 0)
         {
             Console.WriteLine(StringManip.IndentText(StdOut.ToString(), 4));
         }
         if (StdErr.Length > 0)
         {
             Console.WriteLine(StringManip.IndentText(StdErr.ToString(), 4));
         }
     }
 }
Beispiel #9
0
        private int DisplaySize(IntPtr handle, IntPtr device, int width, int height, int raster, uint format, IntPtr pimage)
        {
            try
            {
                // create the new source image
                _temporaryImage = new Bitmap(width, height, raster, PixelFormat.Format32bppRgb, pimage)
                {
                    Tag = true
                };

                // notify the update listeners
                Update?.Invoke(this, new GhostscriptRendererEventArgs(_temporaryImage));
            }
            catch (Exception e)
            {
                StdErr.Append(e);
                return(Native.gs_error_Fatal);
            }
            return(0);
        }
Beispiel #10
0
 public StringBuilder FormatError(StringBuilder sb)
 {
     if (sb == null)
     {
         sb = new StringBuilder();
     }
     sb.Append("Command [");
     if (viaShell)
     {
         sb.Append(psi.Arguments);
     }
     else
     {
         formatCmd(sb, psi.FileName, psi.Arguments);
     }
     sb.AppendFormat("] failed. Returncode={0}.", this.process.ExitCode);
     if (StdErr != null)
     {
         sb.Append("Error text: ");
         sb.Append(StdErr.ReadAll());
     }
     return(sb);
 }
Beispiel #11
0
        /// <summary>
        /// Release all process-related resources.
        /// The child process will be killed if still running
        /// </summary>
        public void Dispose()
        {
            try { Kill(); }
            catch (Win32Exception) { }

            StdErr.Dispose();
            StdOut.Dispose();
            StdIn.Dispose();

            var processMainThread = Interlocked.Exchange(ref _pi.hThread, IntPtr.Zero);

            if (processMainThread != IntPtr.Zero)
            {
                Kernel32.CloseHandle(processMainThread);
            }

            var processHandle = Interlocked.Exchange(ref _pi.hProcess, IntPtr.Zero);

            if (processHandle != IntPtr.Zero)
            {
                Kernel32.CloseHandle(processHandle);
            }
        }
Beispiel #12
0
        private int DisplayUpdate(IntPtr handle, IntPtr device, int x, int y, int width, int height)
        {
            // ensure there are listeners and an image
            var update = Update;

            if (update != null && _temporaryImage != null)
            {
                try
                {
                    if (!(bool)_temporaryImage.Tag)
                    {
                        _temporaryImage.Tag = true;
                        update(this, new GhostscriptRendererEventArgs(_temporaryImage));
                    }
                }
                catch (Exception e)
                {
                    StdErr.Append(e);
                    return(Native.gs_error_Fatal);
                }
            }
            return(0);
        }
Beispiel #13
0
        private int DisplayPage(IntPtr handle, IntPtr device, int copies, int flush)
        {
            // return an error if display_size has not been called yet
            if (_temporaryImage == null)
            {
                return(Native.gs_error_undefinedresult);
            }

            // notify the page handler if any
            var page = Page;

            if (page != null)
            {
                try
                {
                    // store the resulting image
                    Bitmap image;
                    lock (_temporaryImage)
                    {
                        var rect = new Rectangle(Point.Empty, _temporaryImage.Size);
                        image = new Bitmap(rect.Width, rect.Height, PixelFormat.Format24bppRgb);
                        using (var gc = Graphics.FromImage(image))
                        {
                            gc.DrawImage(_temporaryImage, rect, rect, GraphicsUnit.Pixel);
                        }
                        image = new Bitmap(_temporaryImage);
                    }
                    page(this, new GhostscriptRendererEventArgs(image));
                }
                catch (Exception e)
                {
                    StdErr.Append(e);
                    return(Native.gs_error_Fatal);
                }
            }
            return(0);
        }
Beispiel #14
0
        /// <summary>
        /// Renders the instance as a JSON string.
        /// </summary>
        public override string ToString()
        {
            // Set [StdErrLines] and [StdOutLines] if necessary.

            if (!string.IsNullOrEmpty(StdErr))
            {
                StdErrLines = StdErr.ToLines().ToList();
            }
            else if (errors.Count > 0)
            {
                StdErrLines = errors;
            }

            if (!string.IsNullOrEmpty(StdOut))
            {
                StdOutLines = StdOut.ToLines().ToList();
            }
            else if (output.Count > 0)
            {
                StdOutLines = output;
            }

            return(NeonHelper.JsonSerialize(this, Formatting.Indented));
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            string StdOutFileCode = args[0];
            var    StdOutBytes    = Convert.FromBase64String(StdOutFileCode);
            string StdOutFileName = Encoding.UTF8.GetString(StdOutBytes);

            string StdErrFileCode = args[1];
            var    StdErrBytes    = Convert.FromBase64String(StdErrFileCode);
            string StdErrFileName = Encoding.UTF8.GetString(StdErrBytes);


            //string StdOutFileName = System.Environment.GetEnvironmentVariable("TAIL_STDOUT");
            //string StdErrFileName = System.Environment.GetEnvironmentVariable("TAIL_STDERR");

            if (IsEmptyOrWhite(StdOutFileName))
            {
                throw new ApplicationException("Missing valid value for environment variable TAIL_STDOUT.");
            }
            if (IsEmptyOrWhite(StdErrFileName))
            {
                throw new ApplicationException("Missing valid value for environment variable TAIL_STDERR.");
            }

            StreamReader StdOut = null;
            StreamReader StdErr = null;


            int   i = 0;
            State s = State.WaitingForFile;

            while (s != State.Terminating)
            {
                i++;

                if (File.Exists(StdErrFileName) && StdErr == null)
                {
                    StdErr = new StreamReader(
                        new FileStream(StdErrFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
                }


                if (s == State.WaitingForFile)
                {
                    if (File.Exists(StdOutFileName))
                    {
                        StdOut = new StreamReader(
                            new FileStream(StdOutFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));

                        s = State.Tailing;
                    }
                    else
                    {
                        // keep waiting

                        if (i <= 1)
                        {
                            Console.WriteLine("Waiting for Job to launch...");
                        }
                    }
                }
                else if (s == State.Tailing)
                {
                    Debug.Assert(StdOut != null);
                    for (string L = StdOut.ReadLine(); L != null; L = StdOut.ReadLine())
                    {
                        Console.WriteLine(L);
                    }

                    if (StdErr != null)
                    {
                        bool ch = false;
                        for (string L = StdErr.ReadLine(); L != null; L = StdErr.ReadLine())
                        {
                            ch = true;
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.BackgroundColor = ConsoleColor.Red;
                            Console.WriteLine(L);
                        }
                        if (ch)
                        {
                            Console.ResetColor();
                        }
                    }
                }


                Thread.Sleep(10000);
            }


            // termination
            // ===========

            {
                for (int j = 0; j < 10; j++)
                {
                    Console.WriteLine();
                }

                Console.WriteLine("Press any key to close this window.");
                Console.ReadKey(true);
                Console.WriteLine("Bye!");
                Thread.Sleep(5000);
            }
        }