简单的故障注入

来源:互联网 发布:哪个编程语言最好学 编辑:程序博客网 时间:2024/05/21 23:33
 private void button1_Click(object sender, EventArgs e)
        {
            long size = 0L;
            if (!File.Exists(textBox1.Text.Trim()))
            {
                try
                {
                    size = Convert.ToInt64(textBox2.Text.Trim());
                    using (FileStream fs = File.Create(textBox1.Text.Trim()))
                    {

                        long offset = fs.Seek(size - 1, SeekOrigin.Begin);
                        fs.WriteByte(new byte());
                    }
                    label3.Text = string.Empty;
                    label4.Text = string.Empty;
                }
                catch(Exception err)
                {
                    label4.Text = err.Message;
                }

                
            }
            else
            {
                label3.Text = "请在该磁盘下创建一个不存在的文件!";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            long size = 0L;
            try
            {
                size = Convert.ToInt64(textBox3.Text.Trim());
                Stack<int> dust = new Stack<int>();
                //指定消耗内存量
                //long  sum =Convert.ToInt64(0.2 * 1024 * 1024 * 1024 / 4);
                long sum = Convert.ToInt64(size / 7.8);
                for (int i = 0; i < sum; i++)
                {
                    int f = 0;
                    dust.Push(f);
                }
                label6.Text = string.Empty;
            }
            catch (Exception err)
            {
                label6.Text = err.ToString();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {

            int SAMPLING_COUNT = 200;
            const double PI = 3.14159;
            int TOTAL_AMPLITUDE = 300;//切片的时间
            try
            {
                 SAMPLING_COUNT = Convert.ToInt32(textBox4.Text.Trim());
                 TOTAL_AMPLITUDE = Convert.ToInt32(textBox5.Text.Trim());
            }
            catch
            {
                //return;
            }

            double[] busySpan = new double[SAMPLING_COUNT];
            int amplitude = TOTAL_AMPLITUDE / 2;
            double radian = 0.0;

            double radianIncreament = 2.0 / (double)SAMPLING_COUNT;
            for (int i = 0; i < SAMPLING_COUNT; i++)
            {
                busySpan[i] = (double)(amplitude + Math.Sin(PI * radian) * amplitude);
                radian += radianIncreament;
            }
            int startTick = Environment.TickCount;

            for (int j = 0; ; j = (j + 1) % SAMPLING_COUNT)
            {
                startTick = Environment.TickCount;
                while ((Environment.TickCount - startTick) < busySpan[j])
                {
                    //
                }

                System.Threading.Thread.Sleep(TOTAL_AMPLITUDE - (int)busySpan[j]);
            }
        }
原创粉丝点击