Example #1
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();
         * }
         */
        // initially we can use the above commented method. But when we use delegate we can do :

        public void Process(string path, PhotoFilterHandler filterHandler)
        {
            var photo = Photo.Load(path);

            filterHandler(photo);
            photo.Save();
        }
        public void Process(string photoPath, PhotoFilterHandler filterHandler)
        {
            var photo = new Photo(photoPath);

            filterHandler(photo); //this executes the group of functions pointed to by the delegat
            //so long as they have the signature defined above
        }
Example #3
0
        public void Process(string path, PhotoFilterHandler photoFilterHandler)
        {/* Pass a delegate */
            var photo = Photo.Load(path);

            /* Using delegates. Instead of having these hardcoded */
            photoFilterHandler(photo); // This delegate points to the methods.
            photo.Save();
        }
Example #4
0
        public void Process(PhotoFilterHandler filterHandler)
        {
            var photo = new Photo();

            filterHandler(photo);

            photo.Save();
        }
Example #5
0
        public void Process(string path, PhotoFilterHandler filterHandler)
        {
            var photo = new Photo();

            photo.Name = "Photo Alex";

            filterHandler(photo);
        }
Example #6
0
        //Now this method doesn't know what filters will be applied, it's the responsibility of client to decide what filters to apply
        //So this framework doesn't have to be recompiled and redeployed for applying new filter/any number of filters which makes it extensible
        public void Process(string path, PhotoFilterHandler filterHandler)
        {
            var photo = Photo.Load(path);

            // Calling the method here through this delegate instance, the caller will pass pointers to method, and we're calling it here like method(args)
            filterHandler(photo);

            photo.Save();
        }
        public static void Demo()
        {
            var processor = new PhotoProcessor();
            var filters   = new PhotoFilters();
            PhotoFilterHandler handler = filters.ApplyContrast;

            handler += filters.AdjustBrightness;
            handler += SomeOtherFilter;
            processor.Process("123.jpg", handler);
        }
        public void Process(string path, PhotoFilterHandler filterHandler)
        {
            var photo = Photo.Load(path);

            // By calling the filterHandler this method doesn't know which photo process will be applied
            // It's up to the client to define this
            filterHandler(photo);

            photo.Save();
        }
Example #9
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);
        }
        public delegate void PhotoFilterHandler(Photo photo); //A delegate is a class derived from System.MulticastDelegate

        public void Process(string path, PhotoFilterHandler filterHandler)
        {
            //System.Action<> //Action points to a method that returns void
            //System.Func<>//Func points to a method that returns a value (out TResult)

            var photo = Photo.Load(path);

            filterHandler(photo);

            photo.Save();
        }
Example #11
0
        public string Process(string path, PhotoFilterHandler filterHander, string TBH)
        {
            var photo = Photo.Load(path);

            photo.PhotoMessage += "Photo Class Hit \n";
            photo.PhotoMessage += "Photo Class Contains a Delegate Call PhotoFilterHandler \n";
            photo.PhotoMessage += "Processing Filters Using Delegate Now \n";
            filterHander(photo);
            TBH += photo.PhotoMessage;

            return(TBH);
        }
        public delegate void PhotoFilterHandler(Photo photo); // refer to all methods that return void and have a parameter type of photo


        public void Process(string path, PhotoFilterHandler filterHandler)
        {
            var photo = Photo.Load(path);

            //var filter = new PhotoFilters();
            //filter.ApplyBrightness(photo);
            //filter.ApplyContrast(photo);
            //filter.Resize(photo);

            filterHandler(photo);

            photo.Save();
        }
Example #13
0
        public delegate void PhotoFilterHandler(Photo photo); // delegate method


        public void Process(string path, PhotoFilterHandler photofilterHandler0)
        {
            Photo photo = Photo.Load(path);  // invoke the Photo.Load method passed in path

            photofilterHandler0(photo);

            //PhotoFilters photoFilters = new PhotoFilters();
            //photoFilters.ApplyBrightness(photo);
            //photoFilters.ApplyContrast(photo);
            //photoFilters.Resize(photo);

            photo.Save();
        }
Example #14
0
        //Pass in delegate to this function using custom delegates
        public void Process(string path, PhotoFilterHandler filterHandler)
        {
            Photo photo = new Photo();

            photo = Photo.Load(path);

            //This code means that this does not know what filters will be applied.
            //Filters will be applied by client who is using this framework or
            //application. May be they only want to call one method. Also with delegate
            //clients will not have to recompile the code. They can create and add and call
            //methods they want.
            //In this example, review Program.cs for code example on client(Consumer or developer of the frameowkr)
            //that will use this delegate to call methods.
            filterHandler(photo);
        }
Example #15
0
        public delegate void PhotoFilterHandler(Photo photo);  //need define signature of method you're responsible for calling

        //we could use a generic delegate
        //no need to delcare
        //I put an example called SuperProcess


        public void Process(string path, PhotoFilterHandler filterHandler)
        {

            //built in delegates
            //System.Action - points to void method
            //System.Func<> - returns a value
            var photo = Photo.Load(path);
            filterHandler(photo);
            

            photo.Save();

            
       
        }
        // 2, Give an delegate as argument to the method
        public void Process(string path, PhotoFilterHandler filterHandler)
        {
            var photo = Photo.Load(path);

            // 3 - Pass the photo to the filter
            // it means that this code doesn't know any longer what filter will be applied
            // it is now the responsability of the client of this code

            filterHandler(photo);


            /* ------------- code before delegate ----------*/
            //var filters = new PhotoFilters();
            //filters.ApplyBrightness(photo);
            //filters.ApplyContrast(photo);
            //filters.Resize(photo);

            photo.Save();
        }
Example #17
0
 public void Process(string path, PhotoFilterHandler filehandler)
 {
     Console.WriteLine("Processing");
     filehandler(new Photo());
 }
 public void Process(Photo photo, PhotoFilterHandler filterHandler)
 {
     filterHandler(photo);
 }
Example #19
0
 public void Process(string path,PhotoFilterHandler photoFilterHandler)
 {
     var photo = new Photo();
     photoFilterHandler(photo);
 }