Exemplo n.º 1
0
        public virtual void PrintOrder()
        {
            PrintHandler handler = delegate(string message)
            { Console.WriteLine("Делегат класу замовлення викликаний з результатом: " + message); };

            handler(ToString());
        }
        public HttpResponseMessage Get()
        {
            var printHandler = new PrintHandler();

            printHandler.ProcessRequest(HttpContext.Current);
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Exemplo n.º 3
0
    /// <summary>
    /// Executes the handler for an options object
    /// </summary>
    /// <param name="options"></param>
    /// <returns></returns>
    private static ExitCode ExecuteHandler(object options)
    {
        ExitCode code = ExitCode.Unset;

        switch (options)
        {
        case PrintOptions printOptions:
            var printHandler = new PrintHandler(ProjectService);
            code = printHandler.TryExecute(printOptions);
            break;

        case ExportOptions exportOptions:
            var exportHandler = new ExportHandler(ProjectService);
            code = exportHandler.TryExecute(exportOptions);
            break;

        case ExportAllOptions exportAllOptions:
            var exportAllHandler = new ExportAllHandler(ProjectService);
            code = exportAllHandler.TryExecute(exportAllOptions);
            break;

        case ImportOptions importOptions:
            var importHandler = new ImportHandler(ProjectService);
            code = importHandler.TryExecute(importOptions);
            break;

        case ImportAllOptions importAllOptions:
            var importAllHandler = new ImportAllHandler(ProjectService);
            code = importAllHandler.TryExecute(importAllOptions);
            break;
        }

        return(code);
    }
Exemplo n.º 4
0
        /// <summary>
        /// 使用基本的委托定义
        /// </summary>
        public void NoUseFCL()
        {
            AddHandler   add   = Add;
            PrintHandler print = PrintString;

            print(add(12, 13).ToString());
        }
Exemplo n.º 5
0
 public ZoneSpecification(
     HandleUncaughtErrorHandler handleUncaughtError = null,
     RunHandler run             = null,
     RunUnaryHandler runUnary   = null,
     RunBinaryHandler runBinary = null,
     RegisterCallbackHandler registerCallback             = null,
     RegisterUnaryCallbackHandler registerUnaryCallback   = null,
     RegisterBinaryCallbackHandler registerBinaryCallback = null,
     ErrorCallbackHandler errorCallback             = null,
     ScheduleMicrotaskHandler scheduleMicrotask     = null,
     CreateTimerHandler createTimer                 = null,
     CreatePeriodicTimerHandler createPeriodicTimer = null,
     PrintHandler print = null,
     ForkHandler fork   = null)
 {
     this.handleUncaughtError = handleUncaughtError;
     this.run                    = run;
     this.runUnary               = runUnary;
     this.runBinary              = runBinary;
     this.registerCallback       = registerCallback;
     this.registerUnaryCallback  = registerUnaryCallback;
     this.registerBinaryCallback = registerBinaryCallback;
     this.errorCallback          = errorCallback;
     this.scheduleMicrotask      = scheduleMicrotask;
     this.createTimer            = createTimer;
     this.createPeriodicTimer    = createPeriodicTimer;
     this.print                  = print;
     this.fork                   = fork;
 }
Exemplo n.º 6
0
 public static ZoneSpecification from(
     ZoneSpecification other,
     HandleUncaughtErrorHandler handleUncaughtError = null,
     RunHandler run             = null,
     RunUnaryHandler runUnary   = null,
     RunBinaryHandler runBinary = null,
     RegisterCallbackHandler registerCallback             = null,
     RegisterUnaryCallbackHandler registerUnaryCallback   = null,
     RegisterBinaryCallbackHandler registerBinaryCallback = null,
     ErrorCallbackHandler errorCallback             = null,
     ScheduleMicrotaskHandler scheduleMicrotask     = null,
     CreateTimerHandler createTimer                 = null,
     CreatePeriodicTimerHandler createPeriodicTimer = null,
     PrintHandler print = null,
     ForkHandler fork   = null)
 {
     return(new ZoneSpecification(
                handleUncaughtError: handleUncaughtError ?? other.handleUncaughtError,
                run: run ?? other.run,
                runUnary: runUnary ?? other.runUnary,
                runBinary: runBinary ?? other.runBinary,
                registerCallback: registerCallback ?? other.registerCallback,
                registerUnaryCallback:
                registerUnaryCallback ?? other.registerUnaryCallback,
                registerBinaryCallback:
                registerBinaryCallback ?? other.registerBinaryCallback,
                errorCallback: errorCallback ?? other.errorCallback,
                scheduleMicrotask: scheduleMicrotask ?? other.scheduleMicrotask,
                createTimer: createTimer ?? other.createTimer,
                createPeriodicTimer: createPeriodicTimer ?? other.createPeriodicTimer,
                print: print ?? other.print,
                fork: fork ?? other.fork
                ));
 }
Exemplo n.º 7
0
        public override void print(string line)
        {
            var          implementation = _print;
            ZoneDelegate parentDelegate = async_._parentDelegate(implementation.zone);
            PrintHandler handler        = implementation.function;

            handler(implementation.zone, parentDelegate, this, line);
        }
Exemplo n.º 8
0
        public void print(Zone zone, string line)
        {
            var          implementation = _delegationTarget._print;
            _Zone        implZone       = implementation.zone;
            PrintHandler handler        = implementation.function;

            handler(implZone, async_._parentDelegate(implZone), zone, line);
        }
Exemplo n.º 9
0
 private void RemoteServer_DataReceived(Client client, object data)
 {
     if (data is String)
     {
         String test = (String)data;
         Console.WriteLine(test);
         PrintHandler p = new PrintHandler(printClientInfo);
         this.Invoke(p, test);
     }
 }
        //Appelé avec un invoke d'un TimerHandler pour démarrer le serveur. En effet par exemple, ne pas utiliser d'invoke provoque des bugs au démarrage du timer.
        //Et comme on remet les scores à 0, on doit changer les labels donc on doit passer par un invoke
        private void startGameGridMe()
        {
            gridPlayerMe.start();
            btnReady.Enabled = false;
            btnReady.Text    = "In game";
            PrintHandler p = new PrintHandler(printScore);

            lblScoreMe.Text    = "score 0"; // + gridPlayerMe.score.ToString();
            lblScoreRival.Text = "score 0"; // + gridPlayerRival.score.ToString();
        }
Exemplo n.º 11
0
        public static void Print(RichTextBox tb, string msg)
        {
            //判斷這個TextBox的物件是否在同一個執行緒上
            if (tb.InvokeRequired)
            {
                //當InvokeRequired為true時,表示在不同的執行緒上,所以進行委派的動作!!
                PrintHandler ph = new PrintHandler(Print);
                tb.BeginInvoke(ph, tb, msg);
            }
            else
            {
                //表示在同一個執行緒上了,所以可以正常的呼叫到這個TextBox物件
                if (tb.Text.Length > 13000)
                {
                    tb.Text = tb.Text.Substring(tb.Text.Length - 7000);
                }
                tb.SelectionStart  = tb.TextLength;
                tb.SelectionLength = 0;


                if (msg.ToUpper().Contains("FIN"))
                {
                    tb.SelectionColor = Color.Green;
                }
                else if (msg.ToUpper().Contains("RECEIVE"))
                {
                    tb.SelectionColor = Color.Blue;
                }
                else if (msg.ToUpper().Contains("CMD") || msg.ToUpper().Contains("GET") || msg.ToUpper().Contains("SET"))
                {
                    tb.SelectionColor = Color.Coral;
                }
                else if (msg.ToUpper().Contains("MCR"))
                {
                    tb.SelectionColor = Color.Coral;
                }
                else if (msg.ToUpper().Contains("異常描述"))
                {
                    tb.SelectionColor = Color.Red;
                }
                else
                {
                    tb.SelectionColor = Color.DimGray;
                }

                tb.AppendText(msg);
                tb.ScrollToCaret();
                if (tb.Lines.Length > 10000)//只保留最後5千行
                {
                    tb.Select(0, tb.GetFirstCharIndexFromLine(tb.Lines.Length - 5000));
                    tb.SelectedText = "";
                }
            }
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            // Tilldening av första variabel: Skriver ut "Modo är inte bra"
            PrintHandler printHandler = text => Console.WriteLine(text);

            // Vi gör delegaten till multicast genom att tilldela ytterligare metod. Ger utskriften:
            // "Du skrev alltså: Modo är inte bra"
            printHandler += text => Console.WriteLine("Du skrev: alltså " + text);
            // Anropar vår multicast delegate
            printHandler("Modo är inte bra");
            Console.ReadLine();
        }
Exemplo n.º 13
0
        public static void StartMarked()
        {
            PrintHandler printer = new PrintHandler();

            printer.PrintWelcomeText();
            MarketPlaceFacade.Instance.Create();
            Console.WriteLine("\nPress enter to start");

            while (Console.ReadKey().Key != ConsoleKey.Enter)
            {
            }
            MarketPlaceFacade.Instance.Open();
        }
 public void Print(Label lb, string text)
 {
     //判斷這個TextBox的物件是否在同一個執行緒上
     if (lb.InvokeRequired)
     {
         //當InvokeRequired為true時,表示在不同的執行緒上,所以進行委派的動作!!
         PrintHandler ph = new PrintHandler(Print);
         lb.Invoke(ph, lb, text);
     }
     else
     {
         //表示在同一個執行緒上了,所以可以正常的呼叫到這個TextBox物件
         lb.Text = _model.MemberList.AllMemberList[0].Point.ToString();
     }
 }
Exemplo n.º 15
0
 //實做委派的內容
 private static void Print(TextBox tb, string text)
 {
     //判斷Textbox是否在同一個執行緒上
     if (tb.InvokeRequired)
     {
         //如果不在同一個執行緒的話,就觸發委派
         PrintHandler ph = new PrintHandler(Print);
         tb.Invoke(ph, tb, text);
     }
     else
     {
         //如果是的話,就直接顯示,通常不會這麼剛好
         tb.Text = tb.Text + text + Environment.NewLine;
     }
 }
Exemplo n.º 16
0
 public static void Print(RichTextBox tb, string text)
 {
     //判斷這個TextBox的物件是否在同一個執行緒上
     if (tb.InvokeRequired)
     {
         //當InvokeRequired為true時,表示在不同的執行緒上,所以進行委派的動作!!
         PrintHandler ph = new PrintHandler(Print);
         tb.Invoke(ph, tb, text);
     }
     else
     {
         //表示在同一個執行緒上了,所以可以正常的呼叫到這個TextBox物件
         tb.AppendText(text);
         tb.ScrollToCaret();
     }
 }
Exemplo n.º 17
0
 public static void Print(TextBox tb, string text)
 {
     //判斷這個TextBox的物件是否在同一個執行緒上
     if (tb.InvokeRequired)
     {
         //當InvokeRequired為true時,表示在不同的執行緒上,所以進行委派的動作!!
         PrintHandler ph = new PrintHandler(Print);
         tb.Invoke(ph, tb, text);
     }
     else
     {
         //表示在同一個執行緒上了,所以可以正常的呼叫到這個TextBox物件
         //tb.Text = tb.Text + text + Environment.NewLine;
         tb.Text = text;
     }
 }
Exemplo n.º 18
0
        public static void T()
        {
            AddHandler   add   = Add;
            PrintHandler print = Print;

            print(add(1, 2).ToString());

            Func <int, int, int> addFunc = Add;
            // Action has not return value
            Action <string> printAc = Print;

            printAc(addFunc(3, 4).ToString());

            AddFunc = Add;
            printAc(AddFunc(5, 6).ToString());
        }
Exemplo n.º 19
0
        public static void Print(RichTextBox tb, string msg, string DisplayName)
        {
            //判斷這個TextBox的物件是否在同一個執行緒上
            if (tb.InvokeRequired)
            {
                //當InvokeRequired為true時,表示在不同的執行緒上,所以進行委派的動作!!
                PrintHandler ph = new PrintHandler(Print);
                tb.BeginInvoke(ph, tb, msg, DisplayName);
            }
            else
            {
                //表示在同一個執行緒上了,所以可以正常的呼叫到這個TextBox物件
                if (tb.Text.Length > 13000)
                {
                    tb.Text = tb.Text.Substring(tb.Text.Length - 7000);
                }
                tb.SelectionStart  = tb.TextLength;
                tb.SelectionLength = 0;

                switch (DisplayName)
                {
                case "WARN":
                    tb.SelectionColor = Color.Orange;
                    break;

                case "DEBUG":
                    tb.SelectionColor = Color.Red;
                    break;

                case "INFO":
                    tb.SelectionColor = Color.Blue;
                    break;

                default:
                    tb.SelectionColor = Color.Black;
                    break;
                }

                tb.AppendText(msg);
                tb.ScrollToCaret();
                if (tb.Lines.Length > 10000)//只保留最後5千行
                {
                    tb.Select(0, tb.GetFirstCharIndexFromLine(tb.Lines.Length - 5000));
                    tb.SelectedText = "";
                }
            }
        }
 //Quand le score change
 private void onScoreChanged(object sender, EventArgs e)
 {
     if (sender is TetrisGrid)
     {
         PrintHandler p = new PrintHandler(printScore);
         //Le sender permet de savoir dans quel label mettre le score
         String strScore = "";
         if ((TetrisGrid)sender == gridPlayerMe)
         {
             strScore = "score " + gridPlayerMe.score.ToString();
             this.Invoke(p, lblScoreMe, strScore);
         }
         else if ((TetrisGrid)sender == gridPlayerRival)
         {
             strScore = "score " + gridPlayerRival.score.ToString();
             this.Invoke(p, lblScoreRival, strScore);
         }
     }
 }
Exemplo n.º 21
0
        public static void Print(RichTextBox tb, string text)
        {
            //判斷這個TextBox的物件是否在同一個執行緒上
            if (tb.InvokeRequired)
            {
                //當InvokeRequired為true時,表示在不同的執行緒上,所以進行委派的動作!!
                PrintHandler ph = new PrintHandler(Print);
                tb.BeginInvoke(ph, tb, text);
            }
            else
            {
                //表示在同一個執行緒上了,所以可以正常的呼叫到這個TextBox物件
                if (tb.Text.Length > 13000)
                {
                    tb.Text = tb.Text.Substring(tb.Text.Length - 7000);
                }
                tb.SelectionStart  = tb.TextLength;
                tb.SelectionLength = 0;


                if (text.ToUpper().Contains("ERROR"))
                {
                    tb.SelectionColor = Color.Red;
                }
                else if (text.ToUpper().Contains("INFO"))
                {
                    tb.SelectionColor = Color.Green;
                }
                else if (text.ToUpper().Contains("DEBUG"))
                {
                    tb.SelectionColor = Color.Blue;
                }
                else
                {
                    tb.SelectionColor = Color.Black;
                }

                tb.AppendText(text);
                tb.ScrollToCaret();
            }
        }
Exemplo n.º 22
0
        public static void Print(RichTextBox tb, string data)
        {
            //判斷這個TextBox的物件是否在同一個執行緒上
            if (tb.InvokeRequired)
            {
                //當InvokeRequired為true時,表示在不同的執行緒上,所以進行委派的動作!!
                PrintHandler ph = new PrintHandler(Print);
                tb.Invoke(ph, tb, data);
            }
            else
            {
                //表示在同一個執行緒上了,所以可以正常的呼叫到這個TextBox物件

                chat.Add(data);

                tb.AppendText(data);

                try
                {
                    foreach (string ifade in ifadeler.Keys)
                    {
                        while (tb.Text.Contains(ifade))
                        {
                            int ind = tb.Text.IndexOf(ifade);
                            tb.Select(ind, ifade.Length);
                            Clipboard.SetImage((Image)ifadeler[ifade]);
                            tb.Paste();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                data = String.Empty;
            }
        }
Exemplo n.º 23
0
 public ConsolePage(PrintHandler handler, T data, HotkeyBar hotkeybar)
 {
     this._printHandler = handler;
     this.DataProvider  = data;
     this.Hotkeys       = hotkeybar;
 }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            #region DELAGATES

            /*
             * Delegate metodlarin adreslerini dolayi yolla methodu saxlayan , isaret
             * eden strukturdur.
             *
             * Methodlar ozleride RAM da yaranan ve RAM-da adresleri olan struktura sahibdir.
             *
             * Delegate reference type-dir, yeni olardan instance alina biler.
             *
             * public delegate void MyDelegateHandler();
             *
             * Delegate-in temsil edeceyi method ile geri donus tipi ve parametr-leri eyni olmalidir.
             *
             * Delegate adlarinin sonuna adeten Handler elave edilir , mecburi deyil.
             *
             * Delegate eyni imzaya sahib methodlari saxlayir ve onlari sirasi ile ise salir.
             *
             * c# da olan delegate c, c++ da function pointer strukturuna benzeyir.
             *
             *
             * Niye istifade edilir ?
             *
             * Delegate umumilikde ram-da olan bir methodun bir hadiseye bagli ise salinmasi
             * ucun istifade edilmekdedir.
             *
             * WindowsFormApp de meselen bir buttona click olunan zaman bir methodun ise dusmesi,
             * db-dan bir datanin silinmesi zmaani her hansisa methodun ise dusmesi, bir file silinen
             * zaman her hansisa bir methodun ise dusmesi delegate vasitesi il edilir.
             *
             * form load olan zaman Form1.Designer.cs
             * this.Load += new System.EventHandler(this.Form1_Load);
             *
             *
             *
             */

            #endregion

            #region use: examples

            #region 1

            //DelegateHandler delegateHandler = new DelegateHandler(X);
            //DelegateHandler delegateHandler0 =X;
            //delegateHandler();==delegateHandler.Invoke();

            //delegateHandler();
            //delegateHandler.Invoke();
            #endregion

            #region 2

            CalculateHandler delegateHandler1 = new CalculateHandler(Sum);

            delegateHandler1 += Multiply;
            delegateHandler1 += Cixma;
            delegateHandler1(4, 5);
            //veya
            delegateHandler1.Invoke(2, 3);

            #region GetInvocationList

            //Delegate[] methods = delegateHandler.GetInvocationList();


            //foreach (var item in methods)
            //{
            //    Console.WriteLine(item.Method.Name);
            //}
            #endregion


            #region runtime += -=



            #endregion
            #endregion


            #region anonymous method : run time

            PrintHandler printHandler1 = new PrintHandler(Print1);

            printHandler1.Invoke("name", "surname");

            PrintHandler printHandler2 = new PrintHandler(delegate(string name, string surname)
            {
                Console.WriteLine($"{name} {surname}");
            });
            printHandler2("12121", "1212121212");
            // lambda
            PrintHandler printHandler3 = (name, surname) =>
            {
                Console.WriteLine($"{name} {surname}");
            };
            printHandler3("asasasa", "sasasasas");
            #endregion
            #endregion

            Console.ReadLine();
        }