Пример #1
0
        static void Main(string[] args)
        {
            // Example 1
            var            processor     = new PhotoProcessor();
            var            filters       = new PhotoFilters();
            Action <Photo> filterHandler = filters.ApplyBrightness;

            filterHandler += RemoveRedEyeFilter;
            filterHandler += filters.ApplyContrast;

            processor.Process("photo.jpg", filterHandler);

            // Example 2
            var video = new Video()
            {
                Title = "Video 1"
            };
            var videoEncoder = new VideoEncoder();   // publisher
            var mailService  = new MailService();    // subscriber
            var msgService   = new MessageService(); // subscriber

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += msgService.OnVideoEncoded;
            videoEncoder.Encode(video);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var processor = new PhotoProcessor();
            var filters   = new PhotoFilters();

            //PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness;
            Action <Photo> filterHandler = filters.ApplyBrightness;

            filterHandler += filters.ApplyContrats;
            filterHandler += RemoveRedEyeFilter;

            var path = "path/to/file";

            processor.Process(path, filterHandler);

            //Other generic delegates + lamda expressions
            Func <double, double> circumference = r => 3.12 * r * r;

            Action <string> MyAction = s => Console.Write(s);

            Func <string, bool> CheckGreater = n => n.Length > 10;

            Predicate <String> CheckGreaterThan5 = x => x.Length > 5;

            var list = new List <string>();

            list.Add("Shiv123");

            var str = list.Find(CheckGreaterThan5);

            Console.ReadKey();
        }
Пример #3
0
        static void Main(string[] args)
        {
            PhotoProcessor photoProcessor = new PhotoProcessor();
            PhotoFilters   filters        = new PhotoFilters();

            PhotoProcessor.DelegatePhotoFilterHandler filterHandlerDelegate = filters.ApplyBrightness;
            filterHandlerDelegate += filters.ApplyConstrast;
            filterHandlerDelegate += filters.Resize;
            filterHandlerDelegate += RemoveRedEyerFilter;
            photoProcessor.Process("photo.jpg", filterHandlerDelegate);

            Console.WriteLine();

            Action <Photo> filterHandlerDelegateAction = filters.ApplyBrightness;

            filterHandlerDelegateAction += filters.ApplyConstrast;
            filterHandlerDelegateAction += filters.Resize;
            filterHandlerDelegateAction += RemoveRedEyerFilter;
            photoProcessor.Process2("photo.jpg", filterHandlerDelegateAction);

            Console.WriteLine();

            Func <Photo, string> filterHandlerDelegateFunc = filters.Test;

            photoProcessor.Process3("photo.jpg", filterHandlerDelegateFunc);

            Console.ReadLine();
        }
Пример #4
0
        static void Main(string[] args)
        {
            // Delegates
            // -  An object that knows how to call a method (or a group of methods)
            // -  A reference to a function


            // Why  do we need delegates?

            // - For designing extensible and flexible applications (eg frameworks)



            var processor = new PhotoProcessor();
            var filters   = new PhotoFilters();
            //PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness;
            Action <Photo> filterHandler = filters.ApplyBrightness;

            //Multi CastDelegate
            filterHandler += filters.Resize;
            filterHandler += RemoveRedEyeFilter;


            processor.Process("photo.jpg", filterHandler);
        }
Пример #5
0
        public static void Main(string[] args)
        {
            var processor = new Photoprocessor();
            var filters   = new PhotoFilters();

            Photoprocessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness;
            filterHandler += filters.ApplyContrast;
            filterHandler += RemoveRedEyeFilter;

            Console.WriteLine("============================");
            Console.WriteLine("Running with custom delegate");
            processor.Process("photo.jpg", filterHandler);

            // Now let's use the .NET framework delegates instead of a custom one
            var processorDotNet = new PhotoProcessorDotNet();
            var filtersDotNet   = new PhotoFilters();

            Action <Photo> filterHandlerDotNet = filters.ApplyBrightness;

            filterHandlerDotNet += filters.ApplyContrast;
            filterHandlerDotNet += RemoveRedEyeFilter;

            Console.WriteLine("============================");
            Console.WriteLine("Running with DotNet delegate");
            processorDotNet.Process("photo.jpg", filterHandlerDotNet);
        }
Пример #6
0
        static void Main(string[] args)
        {
            var processor = new PhotoProcessor();
            var filters   = new PhotoFilters();

            PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness;
            processor.Process("Image.jpg", filterHandler);
        }
Пример #7
0
        public void Process(string path, Action <Photo> filterHandler)
        {
            var photo   = Photo.Load(path);
            var filters = new PhotoFilters();

            filterHandler(photo);
            photo.Save();
        }
Пример #8
0
        static void Main(string[] args)
        {
            var processor = new PhotoProcessor();
            var filters = new PhotoFilters();
            Action<Photo> filterHandler = filters.ApplyBrightness;
            filterHandler += filters.ApplyContrast;
            filterHandler += RemoveRedEyeFilter;

            processor.Process("photo.jpg", filterHandler);
        }
Пример #9
0
        static void Main(string[] args)
        {
            var processor = new PhotoProcessor();
            var filters   = new PhotoFilters();

            PhotoProcessor.PhotoFilterHnadler filterHnadler = filters.ApplyBrightness;
            filterHnadler += filters.ApplyContrast;
            filterHnadler += filters.RemoveRedEyeFilter;
            processor.Process("photo.jpg", filterHnadler);
        }
Пример #10
0
        static void Main(string[] args)
        {
            PhotoProcessor processor     = new PhotoProcessor();
            var            filter        = new PhotoFilters();
            Action <Photo> filterHandler = filter.ApplyBrightness;

            filterHandler += filter.ApplyContrast;
            filterHandler += RemoveRedEye;
            processor.Process("photo.jpg", filterHandler);
        }
Пример #11
0
        public void Process(string path, PhotoFilterHandler filterHandler)
        {
            var photo   = Photo.Load(path);
            var filters = new PhotoFilters();

            //filters.ApplyBrightness(photo);
            //filters.ApplyContrast(photo);
            //filters.Resize(photo);
            filterHandler(photo);
        }
Пример #12
0
        private static void Main(string[] args)
        {
            var            processor     = new PhotoProcessor();
            var            filters       = new PhotoFilters();
            Action <Photo> filterHandler = filters.ApplyBrightess;

            filterHandler += filters.AppyContrast;
            filterHandler += AppyRedEye;

            processor.Process("nekiImidz.jpg", filterHandler);
        }
Пример #13
0
        //public delegate void PhotoFilterHandler(Photo photo);
        //public void Process(string path, PhotoFilterHandler filterHandler)

        public void Process(string path, Action <Photo> filterHandler)
        {
            var photo   = new Photo();
            var filters = new PhotoFilters();

            filterHandler(photo);

            //filters.ApplyBrightness(photo);
            //filters.ApplyContrast(photo);
            //filters.Resize(photo);
        }
Пример #14
0
        static void Main(string[] args)
        {
            var            photoProcessor = new PhotoProcessor();
            var            filters        = new PhotoFilters();
            Action <Photo> filterHandler  = filters.ApplyBrighttness;

            filterHandler += filters.ApplyContrast;
            filterHandler += RemoveRedEyeFilter;

            photoProcessor.Process("letsgo", filterHandler);
        }
        static void Main(string[] args)
        {
            var filters = new PhotoFilters();

            PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness;
            filterHandler += filters.ApplyContrast;

            PhotoProcessor processor = new PhotoProcessor();

            processor.Process(new Photo(), filterHandler);
        }
Пример #16
0
        public void Process(string path)
        {
            var photo   = Photo.Load(path);
            var filters = new PhotoFilters();

            filters.ApplyBrightness(photo);
            filters.ApplyContrast(photo);
            filters.Resize(photo);

            photo.Save();
        }
Пример #17
0
        static void Main(string[] args)
        {
            var            processor     = new PhotoProcessor();
            var            filter        = new PhotoFilters();
            Action <Photo> filterHandler = filter.ApplyBrightness;

            filterHandler += filter.ApplyContrast;
            filterHandler += RedEyeFilter;
            processor.Process("", filterHandler);
            Console.ReadLine();
        }
Пример #18
0
        static void Main(string[] args)
        {
            var            proccessor    = new PhotoProcessor();
            var            filters       = new PhotoFilters();
            Action <Photo> filterHandler = filters.ApplyBrightness;

            filterHandler += filters.ApplyContrast;
            //so we can add and method later and add it to delegate
            filterHandler += RemoveRedEyeFilter;
            proccessor.Process("photo.jpg", filterHandler);
            Console.ReadLine();
        }
Пример #19
0
        static void Main(string[] args)
        {
            Photo newPhoto = new Photo("imagePath");

            var filters = new PhotoFilters();

            Action <Photo> filterDelegate = filters.Compress;

            filterDelegate += filters.Brighten;

            newPhoto.ApplyFilter(filterDelegate);
        }
Пример #20
0
        public void Process()
        {
            var photo = new Photo();

            var filters = new PhotoFilters();

            filters.ApplyBrightness(photo);
            filters.ApplyContrast(photo);
            filters.Resize(photo);

            photo.Save();
        }
Пример #21
0
        static void Main(string[] args)
        {
            var process = new PhotoProcessor();
            var filters = new PhotoFilters();
            // Setting our delegator || using .NET Action
            Action <Photo> filterHandler = filters.AddContrast;

            filterHandler += filters.GenericFilter;
            filterHandler += removeRedEye;

            //we pass filter here so itr will apply functions through delegators
            process.Process("photo.jpg", filterHandler);
        }
Пример #22
0
        public static void ExampleWithOriginalDelegate()
        {
            var processor = new PhotoProcessor();

            var filters = new PhotoFilters();

            PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness;
            filterHandler += filters.ApplyContrast;
            filterHandler += filters.Resize;
            filterHandler += RemoveRedEyeFilter; // exemplo de extensão

            processor.Process("photo.jpg", filterHandler);
        }
Пример #23
0
        static void Main_two(string[] args)
        {
            var photoProcessor = new PhotoProcessor();

            var filters = new PhotoFilters();
            // create delegate
            Action <Photo> filterHandler = filters.ApplyBrightness;

            filterHandler += filters.ApplyContrast;
            filterHandler += RemoveRedEye;

            photoProcessor.Process("photo.png", filterHandler);
        }
Пример #24
0
        static void Main(string[] args)
        {
            var processor = new PhotoProcessor();
            var filters   = new PhotoFilters();
            // Erzeugen des Handlers
            Action <Photo> filterHandler = filters.ApplyBrightness;

            filterHandler += filters.ApplyContrast;
            filterHandler += RemoveRedEyeFilter;

            // Übergeben des Handlers
            processor.Process("photo.jpg", filterHandler);
        }
Пример #25
0
        static void Main(string[] args)
        {
            var processor = new PhotoProcessor();
            var filters   = new PhotoFilters();
            ///Action is delegate here and filterhandler is pointer to method
            ///and Func is used when your delegate should return a value
            Action <Photo> filterHandler = filters.ApplyBrightness;

            filterHandler += filters.ApplyContrast;
            filterHandler += RemoveRedEyeFilter;

            processor.Process("photo.jpg", filterHandler);
        }
Пример #26
0
        public static void ExampleWithGenericDelegate()
        {
            var processor = new PhotoProcessorWithGenericDelegate();

            var filters = new PhotoFilters();

            Action <Photo> filterHandler = filters.ApplyBrightness;

            filterHandler += filters.ApplyContrast;
            filterHandler += filters.Resize;
            filterHandler += RemoveRedEyeFilter;

            processor.Process("photo.jpg", filterHandler);
        }
Пример #27
0
        static void Main(string[] args)
        {
            var processor = new PhotoProcessor();
            var filters   = new PhotoFilters();

            PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness;
            filterHandler += RemoveRedEyeFilter;
            filterHandler += filters.ApplyContrast;
            // Using filterHandler (delegate)
            processor.Processing("photo.jpg", filterHandler);

            // Using Action<Photo>
            processor.Process("image.jpg", filters.ApplyBrightness);
        }
Пример #28
0
        //Delegate in an object that know how to call a method or multiple method
        //a pointer to a function - that provies flexibility and Extensability
        static void Main(string[] args)
        {
            var processor = new PhotoProcessor();
            var filter    = new PhotoFilters();

            PhotoProcessor.PhotoFilterHandler filterHandler = filter.ApplyBrightness;
            filterHandler += filter.ApplyContrast;
            filterHandler += RemoveRedEyeFilter;
            processor.Process("photo.jpg", filterHandler);

            //Buildin delegates:
            //System.Action // for a method that not returns a value;
            //System.Func // for a method that returns value
        }
Пример #29
0
        static void Main(string[] args)
        {
            var processor = new PhotoProcessor();
            var filters   = new PhotoFilters();

            // Adds methods to the delegate, note that they all must have the same signature as defined in the delegate.
            // PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; // With custom delegate
            Action <Photo> filterHandler = filters.ApplyBrightness;

            filterHandler += filters.ApplyContrast;
            filterHandler += RemoveRedEyeFilter;

            processor.Process("photo.jpg", filterHandler);
        }
Пример #30
0
        // Delegate = Object that knows how to call a method or a group of methods
        // Help designing extensible and flexible applications
        static void Main(string[] args)
        {
            var processor = new PhotoProcessor();
            var filters   = new PhotoFilters();
            // PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness;
            Action <Photo> filterHandler = filters.ApplyBrightness;

            filterHandler += filters.ApplyContrast;
            filterHandler += RemoveRedEyeFilter;


            processor.Process("photo.jpg", filterHandler);

            Console.ReadKey();
        }
Пример #31
0
        static void Main(string[] args)
        {
            var photoProcessor = new PhotoProcessor();
            var filters        = new PhotoFilters();
            //PhotoProcessor.PhotoFilterHandler filterHanlder = filters.ApplyBrightness;
            Action <Photo> filterHanlder = filters.ApplyBrightness;

            filterHanlder += filters.ApplyContrast;
            filterHanlder += filters.Resize;
            filterHanlder += RemoveColor;   // Custom filter

            photoProcessor.Processor("C:\\image1.png", filterHanlder);

            Console.ReadKey();
        }
Пример #32
0
        static void Main(string[] args)
        {
            var process = new PhotoProcessor();

            //process.Process("photo.jpg");

            var filters = new PhotoFilters();
            //PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness;
            System.Action<Photo> filterHandler = filters.ApplyBrightness;
            filterHandler += filters.ApplyContrast;
            filterHandler += RemoveRedEyeFilter;

            process.Process("photo.jpg",filterHandler);

            Console.ReadLine();
        }
Пример #33
0
        static void Main(string[] args)
        {
            //a delegate is an object that knows how to call a method (or a group of methods)
            //simply -- a delegate is a reference to a method/function(s)

            //why?
            //For designing extensible and flexible applications (eg frameworks often used here)

            //multicast delegate lets us have multiple function pointers.
            //delegate is just one.

            PhotoProcessor proc = new PhotoProcessor();

            //interface vs delegate
            //some is personal taste
            //delegates event design pattern, caller doesn't need to access properties

            //if photoprocessor needed to access other properties or methods a delegate wouldn't work.


            //so what we've done here is we created an instance of the photofilters object so we could reference it's methods.
            //we created an instance of the delegate and then assigned the method from photofilters to it.
            PhotoFilters photofilters = new PhotoFilters();
            PhotoProcessor.PhotoFilterHandler filterHandler = photofilters.ApplyBrightness;

            //adding more points/methods
            filterHandler += photofilters.ApplyContrast;
            filterHandler += photofilters.Resize;
            filterHandler += Program.RemoveRedeye;
            proc.Process("path here", filterHandler);

            //when passing the reference to the delegate you don't need the () because you're not passing anything or calling the method.
            Action<Photo> filterHandler2 = photofilters.ApplyBrightness;
            filterHandler2 += RemoveRedeye;

            proc.SuperProces("photopath", filterHandler2);


        }