Exemple #1
0
        static void Main(string[] args)
        {
            function fnc = new function(DateTime.Now, e_Direction.Fixed);
            Dependence dpn = new Dependence(DateTime.Now, e_Direction.Fixed, e_Dot.Start);
            dpn.SetDirection(fnc.GetDirection);
            dpn.SetDate(fnc.GetDate);
            #region Вспомогательные функции
            Action<string, string, string> dOut = (Obj, Old, New) =>
            {
                Console.WriteLine
                ("Dependance changed: {0}\noldValue: {1}\nnewValue: {2}", Obj, Old, New);
            };
            #endregion
            #region Функции для подписки
            Func<EventHandler<ea_ValueChange<e_Direction>>, Action> fncDir =
                (eHnd) =>
                {
                    fnc.event_DirectionChanged += eHnd;
                    return () => fnc.event_DirectionChanged -= eHnd;
                };
            Func<EventHandler<ea_ValueChange<DateTime>>, Action> fncDate =
                (eHnd) =>
                {
                    fnc.event_DateChanged += eHnd;
                    return () => fnc.event_DateChanged -= eHnd;
                };
            #endregion
            #region Автообновление зависимости
            dpn.setAutoupdate(fncDate, fncDir);
            #endregion
            #region отслеживание
            dpn.event_DependDotChanged += (s, e) =>
            { dOut("dependDot", e.OldValue.ToString(), e.NewValue.ToString()); };
            dpn.event_DateChanged += (s, e) =>
            { dOut("manageDate", e.OldValue.ToString(), e.NewValue.ToString()); };
            dpn.event_DirectionChanged += (s, e) =>
            { dOut("Direction", e.OldValue.ToString(), e.NewValue.ToString()); };
            #endregion

            #region testing
            fnc.SetDate(new DateTime(2000,1,1));
            fnc.SetDirection(e_Direction.Left);
            dpn.SetDependDot(e_Dot.Finish);
            Console.WriteLine("Unsuscribe...");
            fnc.SetDate(new DateTime(2001,10,12));
            #endregion

            #region default
            Console.WriteLine("\nPress Enter to exit...");
            Console.ReadLine();
            #endregion
        }
 public FunctionFactory()
 {
     _function = new function(Hlp.InitDate, e_Direction.Right);
 }