예제 #1
0
        private void Log_LogEventsAreSet_LogDelegateIsCalled()
        {
            using (IMagickImage image = new MagickImage(Files.SnakewarePNG))
            {
                int count = 0;
                EventHandler <LogEventArgs> logDelegate = (sender, arguments) =>
                {
                    Assert.IsNull(sender);
                    Assert.IsNotNull(arguments);
                    Assert.AreNotEqual(LogEvents.None, arguments.EventType);
                    Assert.IsNotNull(arguments.Message);
                    Assert.AreNotEqual(0, arguments.Message.Length);

                    count++;
                };

                MagickNET.Log += logDelegate;

                MagickNET.SetLogEvents(LogEvents.Detailed);

                image.Flip();
                Assert.AreNotEqual(0, count);

                MagickNET.Log -= logDelegate;
                count          = 0;

                image.Flip();
                Assert.AreEqual(0, count);
            }
        }
예제 #2
0
            private void ShouldCallLogDelegateWhenLogEventsAreSet()
            {
                using (var image = new MagickImage(Files.SnakewarePNG))
                {
                    int count = 0;
                    void LogDelegate(object sender, LogEventArgs arguments)
                    {
                        Assert.Null(sender);
                        Assert.NotNull(arguments);
                        Assert.NotEqual(LogEvents.None, arguments.EventType);
                        Assert.NotNull(arguments.Message);
                        Assert.NotEqual(0, arguments.Message.Length);

                        count++;
                    }

                    MagickNET.Log += LogDelegate;

                    MagickNET.SetLogEvents(LogEvents.Detailed);

                    image.Flip();

                    MagickNET.Log -= LogDelegate;

                    Assert.NotEqual(0, count);
                    count = 0;

                    image.Flip();
                    Assert.Equal(0, count);
                }
            }
예제 #3
0
        public void Test_Log()
        {
            using (IMagickImage image = new MagickImage(Files.SnakewarePNG))
            {
                int count = 0;
                EventHandler <LogEventArgs> logDelegate = delegate(object sender, LogEventArgs arguments)
                {
                    Assert.IsNull(sender);
                    Assert.IsNotNull(arguments);
                    Assert.AreNotEqual(LogEvents.None, arguments.EventType);
                    Assert.IsNotNull(arguments.Message);
                    Assert.AreNotEqual(0, arguments.Message.Length);

                    count++;
                };

                MagickNET.Log += logDelegate;

                image.Flip();
                Assert.AreEqual(0, count);

                MagickNET.SetLogEvents(LogEvents.All);

                image.Flip();
                Assert.AreNotEqual(0, count);

                MagickNET.Log -= logDelegate;
                count          = 0;

                image.Flip();
                Assert.AreEqual(0, count);
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            MagickNET.SetLogEvents(LogEvents.All);
            MagickNET.Log += MagickNET_Log;
            string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            MagickNET.SetGhostscriptDirectory(path);
            string fileName = Path.Combine(path, "480x600.jpg");

            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("File not found", fileName);
            }
            string pdfFileName = Path.Combine(path, "test.pdf");

            if (File.Exists(pdfFileName))
            {
                File.Delete(pdfFileName);
            }
            using (var images = new MagickImageCollection()) {
                images.Add(new MagickImage(fileName));
                images.Write(pdfFileName);
                if (!File.Exists(pdfFileName))
                {
                    throw new FileNotFoundException("Pdf creation failed", pdfFileName);
                }
            }
        }
예제 #5
0
        public static void ReadImage()
        {
            // Log all events
            MagickNET.SetLogEvents(LogEvents.All);
            // Set the log handler (all threads use the same handler)
            MagickNET.Log += MagickNET_Log;

            using (var image = new MagickImage())
            {
                // Trace logging checks if this is set to true.
                image.Settings.Debug = true;

                // Reading the image will send all log events to the log handler
                image.Read(SampleFiles.SnakewarePng);
            }
        }
예제 #6
0
            private void ShouldStopCallingLogDelegateWhenLogDelegateIsRemoved()
            {
                using (var image = new MagickImage(Files.SnakewarePNG))
                {
                    int count = 0;
                    void LogDelegate(object sender, LogEventArgs arguments)
                    {
                        count++;
                    }

                    MagickNET.Log += LogDelegate;

                    MagickNET.SetLogEvents(LogEvents.Detailed);

                    MagickNET.Log -= LogDelegate;

                    image.Flip();
                    Assert.Equal(0, count);
                }
            }
예제 #7
0
        private void Log_LogDelegateIsRemove_LogDelegateIsNoLongerCalled()
        {
            using (IMagickImage image = new MagickImage(Files.SnakewarePNG))
            {
                int count = 0;
                EventHandler <LogEventArgs> logDelegate = (sender, arguments) =>
                {
                    count++;
                };

                MagickNET.Log += logDelegate;

                MagickNET.SetLogEvents(LogEvents.Detailed);

                MagickNET.Log -= logDelegate;

                image.Flip();
                Assert.AreEqual(0, count);
            }
        }
예제 #8
0
            private void ShouldStopCallingLogDelegateWhenLogDelegateIsRemoved()
            {
                using (var image = new MagickImage(Files.SnakewarePNG))
                {
                    int count = 0;
                    EventHandler <LogEventArgs> logDelegate = (sender, arguments) =>
                    {
                        count++;
                    };

                    MagickNET.Log += logDelegate;

                    MagickNET.SetLogEvents(LogEvents.Detailed);

                    MagickNET.Log -= logDelegate;

                    image.Flip();
                    Assert.Equal(0, count);
                }
            }
예제 #9
0
            private void ShouldLogTraceEventsWhenLogEventsIsSetToAll()
            {
                int traceEvents = 0;
                EventHandler <LogEventArgs> logDelegate = (sender, arguments) =>
                {
                    if (arguments.EventType == LogEvents.Trace)
                    {
                        traceEvents++;
                    }
                };

                MagickNET.SetLogEvents(LogEvents.All);

                MagickNET.Log += logDelegate;

                using (var image = new MagickImage(Files.SnakewarePNG))
                {
                }

                MagickNET.Log -= logDelegate;

                Assert.AreNotEqual(0, traceEvents);
            }
예제 #10
0
            private void ShouldLogTraceEventsWhenLogEventsIsSetToAll()
            {
                int traceEvents = 0;

                void LogDelegate(object sender, LogEventArgs arguments)
                {
                    if (arguments.EventType == LogEvents.Trace)
                    {
                        traceEvents++;
                    }
                }

                MagickNET.SetLogEvents(LogEvents.All);

                MagickNET.Log += LogDelegate;

                using (var image = new MagickImage(Files.SnakewarePNG))
                {
                }

                MagickNET.Log -= LogDelegate;

                Assert.NotEqual(0, traceEvents);
            }