Ejemplo n.º 1
0
        // delegator that takes photo
        //public delegate void PhotoFilterHandler(Photo photo);

        //WE PASS DELEGATOR IN so any filter can be applied
        // using generic delegator Action<Photo> will do exactly the same thing as creating your own delegator
        public void Process(string path, Action <Photo> filterHandler)
        {
            var photo = Photo.Load(path);

            filterHandler(photo);
            photo.Save();
        }
        public void Process(string path, DelegatePhotoFilterHandler delegateFilterHandler)
        {
            var photo = Photo.Load(path);

            delegateFilterHandler(photo);

            photo.Save();
        }
Ejemplo n.º 3
0
        public void Process(string path, PhotoProcessorHandler filterHandler)
        {
            var photo   = Photo.Load(path);
            var filters = new PhotoFilters();

            filterHandler(photo);
            photo.Save();
        }
Ejemplo n.º 4
0
        public void Process(string path, PhotoFilterHnadler filterHnadler)
        {
            var photo = Photo.Load(path);

            filterHnadler(photo);

            photo.Save();
        }
        public void Process2(string path, Action <Photo> delegateFilterHandler)
        {
            var photo = Photo.Load(path);

            delegateFilterHandler(photo);

            photo.Save();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Delegate that can hold a reference to a method or a group of methods that contain the below signature.
        /// </summary>
        /// <param name="photo"></param>
        //public delegate void PhotoFilterHandler(Photo photo);

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

            // this code does not know what filter will be apply...
            filterHandler(photo);

            photo.Save();
        }
Ejemplo n.º 7
0
        public void Process(string path, Action <Photo> filterHandler)
        {
            var photo = Photo.Load(path);

            //all the method points by the delegate called here..
            filterHandler.Invoke(photo);

            photo.Save();
        }
Ejemplo n.º 8
0
        //public delegate void PhotoFilterHandler(Photo photo);
        //public void Process(string path,PhotoFilterHandler filterHandler)
        //{
        //    //System.Action<>
        //    //System.Func<>
        //    // Func deleagte geri dönüş yapar. Action yapmaz
        //    var photo = Photo.Load(path);
        //    filterHandler(photo);
        //    photo.Save();
        //}
        public void Process(string path, Action <Photo> filterHandler)
        {
            //System.Action<>
            //System.Func<>
            // Func deleagte geri dönüş yapar. Action yapmaz
            var photo = Photo.Load(path);

            filterHandler(photo);
            photo.Save();
        }
Ejemplo n.º 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 void Process(string path, Action <Photo> 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();
        }
Ejemplo n.º 11
0
        public void Process3(string path, Func <Photo, string> delegateFilterHandler)
        {
            var photo = Photo.Load(path);

            var result = delegateFilterHandler(photo);

            Console.WriteLine(result);

            photo.Save();
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
0
        // public delegate void PhotoFilterHandler(Photo photo);

        public void Process(string path, Action <Photo> filterHandler)
        {
            // Action<> -> points to a function return void
            // System.Action<>
            // System.Func<> -> points to a funciton return a value

            var photo = Photo.Load(path);

            filterHandler(photo);

            photo.Save();
        }
Ejemplo n.º 14
0
        /*        public delegate void PhotoFilterHandler(Photo photo); - custom delegate
         *
         *      public void Process(string path, PhotoFilterHandler filterHandler)
         *      {
         *          var photo = Photo.Load(path);
         *
         *          filterHandler(photo);
         *
         *          photo.Save();
         *      }*/

        public void Process(string path, Action <Photo> filterHandler)
        {
            // System.Action<> -- .net's delegate (points to a method that returns void)
            // System.Func<> -- .net's delegate (points to a method that returns something)


            var photo = Photo.Load(path);

            filterHandler(photo);

            photo.Save();
        }
Ejemplo n.º 15
0
        //public delegate void PhotoFilterHandler(Photo photo);

        public void Processor(string path, Action <Photo> filterHandler)
        {
            var photo = Photo.Load(path);

            // Problem: cannot apply custom filter
            //var filters = new PhotoFilters();
            //filters.ApplyBrightness(photo);
            //filters.ApplyContrast(photo);
            //filters.Resize(photo);
            filterHandler(photo);

            photo.Save();
        }
Ejemplo n.º 16
0
        //public delegate void PhotoFilterHandler(Photo photo); // Responsible for calling the method/methods with this signature. Custom delegate


        // public void Process(string path, PhotoFilterHandler filterHandler)
        public void Process(string path, Action <Photo> filterHandler)
        {
            // Difference between Action and Func, is that Func points to methods that return a value,
            // whereas Action points at methods who returns void..

            //System.Action<>
            //System.Func<>
            var photo = Photo.Load(path);

            filterHandler(photo);

            photo.Save();
        }
Ejemplo n.º 17
0
        //public delegate void PhotoFilterHandler(Photo photo);

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

            filterHandler(photo);

            //var filters = new PhotoFilters();
            //filters.ApplyBrightness(photo);
            //filters.ApplyContrats(photo);
            //filters.Resize(photo);

            photo.Save();
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        public void Process(string path, Action <Photo> filterHandler)
        {
            //Delegates
            //System.Action<>
            //System.Func<>;

            var photo = Photo.Load(path);

            filterHandler(photo);
            //var filters = new PhotoFilters();
            //filters.ApplyBrightness(photo);
            //filters.ApplyContrast(photo);
            //filters.Resize(photo);
            photo.Save();
        }
Ejemplo n.º 20
0
        //public delegate void PhotoFilterHandler(Photo photo);
        //public void Processor(string path,PhotoFilterHandler filterHandler)
        //{
        //    var photo = Photo.Load(path);
        //   //System.Action, return void
        //   //System.Func, return value
        //    var filters = new PhotoFilters();
        //    filterHandler(photo);

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

        //    photo.Save();
        //}


        public void Processor(string path, Action <Photo> filterHandler)
        {
            var photo = Photo.Load(path);
            //System.Action, return void
            //System.Func, return value
            var filters = new PhotoFilters();

            filterHandler(photo);

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

            photo.Save();
        }
Ejemplo n.º 21
0
        //public delegate void PhotoFilterHandler(Photo photo);


        public void Process(string path, Action <Photo> filterHandler)
        {
            //Orignal not extensible.
            //Use Delegates so that filters may
            //be developed without having to
            //recompile and deploy all of the code.

            //System.Action<>; //Built in delegate points to a void method with up to 16params

            //System.Func<> //Built in delegate points to method that returns a type

            var photo = Photo.Load(path);

            filterHandler(photo);

            photo.Save();
        }
Ejemplo n.º 22
0
        /*
         *  A delegate to a group of methods which have the type void and take and argument of type Photo:
         *  public delegate void PhotoFilterHandler(Photo photo);
         *  When using this delegate we have to pass it in the method in which we want to use it.
         *
         *  There is no need for creating custom delegates, because we have built-in ones:
         *  System.Action<> <- points to functions that do not return any value (are of type void)
         *  System.Func<> <- points to functions that return value
         */
        public void Process(string path, Action <Photo> filterHandler)
        {
            var photo = Photo.Load(path);

            filterHandler(photo);

            /*
             *  Not extensible nor flexible code:
             *
             *  var filters = new PhotoFilters();
             *  filters.ApplyBrightness(photo);
             *  filters.ApplyContrast(photo);
             *  filters.Resize(photo);
             */

            photo.Save();
        }
Ejemplo n.º 23
0
        // 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();
        }