Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            //## testing target : object
            // init.
            MyClassA o = new MyClassA();

            // dump
            txtMessage.AppendText("\r\nINITIAL ");
            o.Dump(txtMessage);

            AspectW.Define
                .Ignore()
                .Restore(new RestoreWhenFail(o, (v) => o = (MyClassA)v))
                .TraceException((ex) => txtMessage.AppendText("\r\nEXCEPTION : " + ex.Message + "\r\n"))
                .Do(() =>
                {
                    // change value
                    o.a = 111;
                    o.d = 5678.1234;
                    o.m = 123456789.123456789123456789M;
                    o.s = "我改變了。";

                    // dump
                    txtMessage.AppendText("\r\nCHANGE ");
                    o.Dump(txtMessage);

                    // make fail!
                    throw new ApplicationException("Make fail to trigger restore!");
                });

            // dump
            txtMessage.AppendText("\r\nRESTORE ");
            o.Dump(txtMessage);
        }
Ejemplo n.º 2
0
        private void button4_Click(object sender, EventArgs e)
        {
            //## testing target : object array
            // init.
            MyClassA[] oary = new MyClassA[] {new MyClassA(), new MyClassA(), new MyClassA() };

            // dump
            txtMessage.AppendText("====== INITIAL ====== \r\n");
            foreach (MyClassA o in oary)
                o.Dump(txtMessage);
            txtMessage.AppendText("\r\n");

            AspectW.Define
            .Ignore()
            .Restore(new RestoreWhenFail(oary, (v)=> oary = (MyClassA[])v)) // MyClassA 必須支援[Serializable]。
            .TraceException((ex) => txtMessage.AppendText("EXCEPTION : " + ex.Message + "\r\n\r\n"))
            .Do(() =>
            {
                // change value
                oary[0].a = 111;
                oary[0].d = 5678.1234;
                oary[0].m = 123456789.123456789123456789M;
                oary[0].s = "我改變了。";

                // change value
                oary[1].a = 111;
                oary[1].d = 5678.1234;
                oary[1].m = 123456789.123456789123456789M;
                oary[1].s = "我改變了。";

                // change value
                oary[2].a = 111;
                oary[2].d = 5678.1234;
                oary[2].m = 123456789.123456789123456789M;
                oary[2].s = "我改變了。";

                // dump
                txtMessage.AppendText("====== CHANGE ====== \r\n");
                foreach (MyClassA o in oary)
                    o.Dump(txtMessage);
                txtMessage.AppendText("\r\n");

                // make fail!
                throw new ApplicationException("Make fail to trigger restore!");
            });

            // dump
            txtMessage.AppendText("====== RESTORE ====== \r\n");
            foreach (MyClassA o in oary)
                o.Dump(txtMessage);
            txtMessage.AppendText("\r\n");
        }
Ejemplo n.º 3
0
        private void button3_Click(object sender, EventArgs e)
        {
            int a;
            string s;
            MyClassA o;

            for (int i = 1; i <= 5; i++)
            {
                // set value
                a = 90 + i;
                s = "我是字串" + i.ToString();
                o = new MyClassA();
                o.s = "ABCD" + i.ToString();

                // dump
                txtMessage.AppendText(a + Environment.NewLine);
                txtMessage.AppendText(s + Environment.NewLine);
                o.Dump(txtMessage);

                AspectW.Define
                    .Ignore()
                    .Restore(new RestoreWhenFail(a, (v) => a = (int)v),
                                new RestoreWhenFail(s, (v) => s = (string)v),
                                new RestoreWhenFail(o, (v)=> o = (MyClassA)v))
                    .TraceException((ex) => txtMessage.AppendText("<<FAIL!>>" + Environment.NewLine + Environment.NewLine))
                    .Do(()=>
                    {
                        // change
                        a = -77;
                        s = "我改變了";
                        o.a = 111;
                        o.d = 5678.1234;
                        o.m = 123456789.123456789123456789M;
                        o.s = "我改變了12345";
                        // dump
                        txtMessage.AppendText(a + Environment.NewLine);
                        txtMessage.AppendText(s + Environment.NewLine);
                        o.Dump(txtMessage);
                        // mail flal!
                        throw new ApplicationException("make FAIL!");
                    });

                // dump
                txtMessage.AppendText(a + Environment.NewLine);
                txtMessage.AppendText(s + Environment.NewLine);
                o.Dump(txtMessage);
                txtMessage.AppendText("=============================" + Environment.NewLine);
            }
        }
Ejemplo n.º 4
0
        private void button5_Click(object sender, EventArgs e)
        {
            int a = 99;
            MyClassA o = new MyClassA();
            // dump
            txtMessage.AppendText(a + Environment.NewLine);
            o.Dump(txtMessage);
            txtMessage.AppendText("-----------------------------" + Environment.NewLine);

            AspectW.Define
                .Ignore()
                .Restore(new RestoreWhenFail(a, (v) => a = (int)v),
                            new RestoreWhenFail(o, (v) => o = (MyClassA)v))
                .TraceException((ex) => txtMessage.AppendText(ex.Message + Environment.NewLine + Environment.NewLine))
                .Do(() =>
                {
                    a = 77;
                    o.s = "我改變了,在B1。";
                    // dump
                    txtMessage.AppendText(a + Environment.NewLine);
                    o.Dump(txtMessage);
                    txtMessage.AppendText("-----------------------------" + Environment.NewLine);

                    //## mail flal at level 1 point A.
                    throw new ApplicationException("<<FAIL AT BLOCK 1>>");
                });

            // dump
            txtMessage.AppendText(a + Environment.NewLine);
            o.Dump(txtMessage);
            txtMessage.AppendText("-----------------------------" + Environment.NewLine);
            txtMessage.AppendText("-----------------------------" + Environment.NewLine);

            AspectW.Define
                .Ignore()
                .Restore(new RestoreWhenFail(a, (v) => a = (int)v),
                            new RestoreWhenFail(o, (v) => o = (MyClassA)v))
                .TraceException((ex) => txtMessage.AppendText(ex.Message + Environment.NewLine + Environment.NewLine))
                .Do(() =>
                {
                    a = 55;
                    o.s = "我改變了,在B2。";
                    // dump
                    txtMessage.AppendText(a + Environment.NewLine);
                    o.Dump(txtMessage);
                    txtMessage.AppendText("-----------------------------" + Environment.NewLine);

                    //## mail flal at level 2.
                    throw new ApplicationException("<<FAIL AT BLOCK 2>>");
                });

            // dump
            txtMessage.AppendText("final:" + Environment.NewLine);
            txtMessage.AppendText(a + Environment.NewLine);
            o.Dump(txtMessage);
            txtMessage.AppendText("=============================" + Environment.NewLine);
        }
Ejemplo n.º 5
0
        private void button4_Click(object sender, EventArgs e)
        {
            for (int round = 1; round <= 3; round++)
            {
                // show round.
                txtMessage.AppendText(string.Format("## ROUND {0} ==================", round) + Environment.NewLine);

                int a = 99;
                MyClassA o = new MyClassA();
                // dump
                txtMessage.AppendText(a + Environment.NewLine);
                o.Dump(txtMessage);
                txtMessage.AppendText("-----------------------------" + Environment.NewLine);

                AspectW.Define
                    .Ignore()
                    .Restore(new RestoreWhenFail(a, (v) => a = (int)v),
                                new RestoreWhenFail(o, (v) => o = (MyClassA)v))
                    .TraceException((ex) => txtMessage.AppendText(ex.Message + Environment.NewLine + Environment.NewLine))
                    .Do(() =>
                    {
                        a = 77;
                        o.s = "我改變了,在L1。";
                        // dump
                        txtMessage.AppendText(a + Environment.NewLine);
                        o.Dump(txtMessage);
                        txtMessage.AppendText("-----------------------------" + Environment.NewLine);

                        //## mail flal at level 1 point A.
                        if (round == 1)
                            throw new ApplicationException("<<FAIL AT LEVEL1A>>");

                        AspectW.Define
                            .Ignore()
                            .Restore(new RestoreWhenFail(a, (v) => a = (int)v),
                                        new RestoreWhenFail(o, (v) => o = (MyClassA)v))
                            .TraceException((ex) => txtMessage.AppendText(ex.Message + Environment.NewLine + Environment.NewLine))
                            .Do(() =>
                            {
                                a = 55;
                                o.s = "我改變了,在L2。";
                                // dump
                                txtMessage.AppendText(a + Environment.NewLine);
                                o.Dump(txtMessage);
                                txtMessage.AppendText("-----------------------------" + Environment.NewLine);

                                //## mail flal at level 2.
                                if (round == 2)
                                    throw new ApplicationException("<<FAIL AT LEVEL2>>");
                            });

                        //## mail flal at level 1 point B.
                        if (round == 3)
                            throw new ApplicationException("<<FAIL AT LEVEL1B>>");
                    });

                // dump
                txtMessage.AppendText("final:" + Environment.NewLine);
                txtMessage.AppendText(a + Environment.NewLine);
                o.Dump(txtMessage);
                txtMessage.AppendText("=============================" + Environment.NewLine);

            }
        }
Ejemplo n.º 6
0
        private void button2_Click(object sender, EventArgs e)
        {
            // show code
            //webBrowser1.DocumentText = "<HTML></HTML>"; // 一定要有這行。怪!!!
            webBrowser1.Document.OpenNew(true);
            webBrowser1.Document.Write(Properties.Resources.TextFile2);

            // declare variable
            int a = 99;
            MyClassA o = new MyClassA();
            // dump
            this.MyTrace("INIT:");
            this.MyTrace("a = {0}", a);
            o.Dump(txtMessage);
            this.MyTrace("-----------------------------");

            AspectW.Define
                .Ignore()
                .Restore(new RestoreWhenFail(a, (v) => a = (int)v),
                         new RestoreWhenFail(o, (v) => o = (MyClassA)v))
                .TraceException((ex) => this.MyTrace(ex.Message))
                .Do(() =>
                {
                    // change value
                    a = 77;
                    o.s = "我改變了,在L1。";
                    // dump
                    this.MyTrace("DO at L1:");
                    this.MyTrace("a = {0}", a);
                    o.Dump(txtMessage);
                    this.MyTrace("-----------------------------");

                    //## Make Fail Point 1.
                    if (chkMakeFail1.Checked)
                        throw new ApplicationException("\r\n<<FAIL AT LEVEL1A>>\r\n");

                    AspectW.Define
                        .Ignore()
                        .Restore(new RestoreWhenFail(a, (v)=> a = (int)v),
                                 new RestoreWhenFail(o, (v)=> o = (MyClassA)v))
                        .TraceException((ex) => this.MyTrace(ex.Message))
                        .Do(() =>
                        {
                            // change value
                            a = 55;
                            o.s = "我改變了,在L2。";
                            // dump
                            this.MyTrace("DO at L2:");
                            this.MyTrace("a = {0}", a);
                            o.Dump(txtMessage);
                            this.MyTrace("-----------------------------");

                            //## Make Fail Point 2.
                            if (chkMakeFail2.Checked)
                                throw new ApplicationException("\r\n<<FAIL AT LEVEL2>>\r\n");
                        });

                    //## Make Fail Point 3.
                    if (chkMakeFail3.Checked)
                        throw new ApplicationException("\r\n<<FAIL AT LEVEL1B>>\r\n");
                });

            // dump
            this.MyTrace("FINAL:");
            this.MyTrace("a = {0}", a);
            o.Dump(txtMessage);
            this.MyTrace("=============================\r\n");
        }
Ejemplo n.º 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            // show code
            //webBrowser1.DocumentText = "<HTML></HTML>"; // 一定要有這行。怪!!!
            webBrowser1.Document.OpenNew(true);
            webBrowser1.Document.Write(Properties.Resources.TextFile1);

            // declare variable
            int a;
            string s;
            MyClassA o;

            for (int i = 1; i <= 3; i++)
            {
                // set value
                a = 90 + i;
                s = "我是字串" + i.ToString();
                o = new MyClassA();
                o.s = "ABCD" + i.ToString();
                // dump
                this.MyTrace("SET VALUE:");
                this.MyTrace("a = {0}", a);
                this.MyTrace("s = {0}", s);
                o.Dump(txtMessage);
                this.MyTrace("-----------------------------");

                AspectW.Define
                    .Ignore()
                    .Restore(new RestoreWhenFail(a, (v) => a = (int)v),
                             new RestoreWhenFail(s, (v) => s = (string)v),
                             new RestoreWhenFail(o, (v) => o = (MyClassA)v))
                    .TraceException((ex) => this.MyTrace(ex.Message))
                    .Do(() =>
                    {
                        // change
                        a = -77;
                        s = "我改變了";
                        o.a = 111;
                        o.d = 5678.1234;
                        o.m = 123456789.123456789123456789M;
                        o.s = "我改變了ABCD";
                        // dump
                        this.MyTrace("DO:");
                        this.MyTrace("a = {0}", a);
                        this.MyTrace("s = {0}", s);
                        o.Dump(txtMessage);
                        this.MyTrace("-----------------------------");

                        //## Make Fail.
                        if(i == 1 && chkMakeFail1.Checked)
                            throw new ApplicationException("\r\n<<FAIL c1>>\r\n");
                        else if (i == 2 && chkMakeFail2.Checked)
                            throw new ApplicationException("\r\n<<FAIL c2>>\r\n");
                        else if (i == 3 && chkMakeFail3.Checked)
                            throw new ApplicationException("\r\n<<FAIL c3>>\r\n");
                    });

                // dump
                this.MyTrace("FINAL:");
                this.MyTrace("a = {0}", a);
                this.MyTrace("s = {0}", s);
                o.Dump(txtMessage);
                this.MyTrace("=============================\r\n");
            }
        }