Esempio n. 1
0
        protected void ParseTree(string name, Type type)
        {
            Children = new ObservableCollection <ObjectNodeKey>();
            _type    = type;
            _name    = name;

            PropertyInfo[] props = type.GetProperties();

            foreach (var p in props)
            {
                if (p.PropertyType.IsPublic)
                {
                    ReportStat rs = (ReportStat)Attribute.GetCustomAttribute(p, typeof(ReportStat));
                    if (rs != null)
                    {
                        if (p.PropertyType.IsInterface && p.PropertyType == typeof(ICollectionView))
                        {
                            Children.Add(new ObjectNodeKey(p.Name, p));
                        }
                        else
                        {
                            Children.Add(new ObjectNodeKey(p.Name, p.PropertyType));
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (this.txtLog.Text.Length / (float)this.txtLog.MaxLength > 0.95)
            {
                this.txtLog.Clear();
            }
            this.txtLog.AppendText("\r\n");
            ReportStat rs = (ReportStat)e.UserState;

            if (rs.step == 0) //开始处理
            {
                this.lblWork.Text    = rs.msg;
                this.lblPercent.Text = string.Format("{0}%", e.ProgressPercentage);
                this.lblCount.Text   = string.Format("{0}/{1}", rs.currentIndex + 1, _tcRows.Length);;
            }
            else if (rs.step == 1) //正常进行中----
            {
                this.progressBarControl1.Value = e.ProgressPercentage;
                this.lblPercent.Text           = string.Format("{0}%", e.ProgressPercentage);
                this.txtLog.AppendText("正处理。第------" + rs.currentIndex + "条记录" + rs.msg);
            }
            else if (rs.step == 2)//点了暂停按钮 后
            {
                this.btnPause.Enabled = true;
                this.btnPause.Text    = "继续";
            }
            else if (rs.step == 3)//点了继续 按钮后
            {
                this.btnPause.Enabled = true;
                this.btnPause.Text    = "暂停";
            }
            else if (rs.step == 4)
            {
                DialogResult dr = MessageBox.Show(this, "出错,忽略?终止?重试", "错误", MessageBoxButtons.AbortRetryIgnore);
                if (dr == DialogResult.Ignore)
                {
                    //忽略继续
                    _bPause = 0;
                    _semaPause.Release();
                }
                else if (dr == DialogResult.Abort)
                {
                    //设为暂停状态
                    this.btnPause.Enabled = true;
                    this.btnPause.Text    = "继续";
                }
                else
                {
                    //重试 i 减一 继续
                    Interlocked.Decrement(ref i);
                    _bPause = 0;
                    _semaPause.Release();
                }
                this.progressBarControl1.Value = e.ProgressPercentage;
                this.lblPercent.Text           = string.Format("{0}%", e.ProgressPercentage);
                this.txtLog.AppendText("出错:" + rs.msg);
            }
        }
Esempio n. 3
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            //_tcRows 存放要处理的数据
            for (i = 0; i < _tcRows.Length; Interlocked.Increment(ref i))
            {
                if (CheckState()) { e.Cancel = true; return; }

                ReportStat rs0 = new ReportStat();
                rs0.step = 0;
                rs0.currentIndex = i;
                rs0.msg = string.Format("正在处理:{0}。 获取数据...", _tcRows[i]["NAME"]);
                backgroundWorker1.ReportProgress(i * 100 / _tcRows.Length, rs0);

                ReportStat rs1;
                string strTcData = string.Empty;
                if (CheckState()) { e.Cancel = true; return; }
                try
                {
                    //正常处理信息,错误throw 抛出异常
                    //////
                    DoSomething(i, _tcRows[i]["ID"].ToString(), _tcRows[i]["NAME"].ToString());
                }
                catch (Exception ex)
                {
                    rs1 = new ReportStat();
                    if (!_bIgnoreError && i != _tcRows.Length)
                    {
                        int bOldPause = Interlocked.CompareExchange(ref _bPause, 1, 0);
                        rs1.step = 4;
                    }
                    else
                    {
                        rs1.step = 1;
                    }
                    rs1.currentIndex = i;
                    rs1.msg = ex.Message;
                    backgroundWorker1.ReportProgress((i + 1) * 100 / _tcRows.Length, rs1);
                    if (CheckState()) { e.Cancel = true; return; }

                    continue;
                }

                //成功
                rs1 = new ReportStat();
                rs1.step = 1;
                rs1.currentIndex = i;
                rs1.msg = "成功!";
                backgroundWorker1.ReportProgress((i + 1) * 100 / _tcRows.Length, rs1);

                _setErrorList.Remove((int)_tcRows[i]["ID"]);
            }
        }
Esempio n. 4
0
        private bool CheckState()
        {
            if (_bPause == 1)
            {
                ReportStat rs2 = new ReportStat();
                rs2.step = 2;
                backgroundWorker1.ReportProgress(0 * 100 / _tcRows.Length, rs2);
                _semaPause.WaitOne();
                rs2      = new ReportStat();
                rs2.step = 3;
                backgroundWorker1.ReportProgress(0 * 100 / _tcRows.Length, rs2);
            }
            if (_bCancel)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        private bool DoSomething(int nIndex, string id, string name)
        {
            ReportStat rs0 = new ReportStat();

            rs0.step         = 0;
            rs0.currentIndex = nIndex;
            rs0.msg          = string.Format("正在处理电文:{0}。 名称{1}...", id, name);
            backgroundWorker1.ReportProgress(nIndex * 100 / _tcRows.Length, rs0);
            bool error = false;

            if (name == "NAME8")
            {
                error = true;
            }
            if (error)
            {
                ApplicationException ae = new ApplicationException("发送错误...");
                throw ae;
            }
            return(true);
        }
Esempio n. 6
0
 private bool DoSomething(int nIndex,string id,string name)
 {
     ReportStat rs0 = new ReportStat();
     rs0.step = 0;
     rs0.currentIndex = nIndex;
     rs0.msg = string.Format("正在处理电文:{0}。 名称{1}...", id, name);
     backgroundWorker1.ReportProgress(nIndex * 100 / _tcRows.Length, rs0);
     bool error = false;
     if (name == "NAME8")
     {
         error = true;
     }
     if (error)
     {
         ApplicationException ae = new ApplicationException("发送错误...");
         throw ae;
     }
     return true;
 }
Esempio n. 7
0
        private bool CheckState()
        {
            if (_bPause == 1)
            {
                ReportStat rs2 = new ReportStat();
                rs2.step = 2;
                backgroundWorker1.ReportProgress(0 * 100 / _tcRows.Length, rs2);
                _semaPause.WaitOne();
                rs2 = new ReportStat();
                rs2.step = 3;
                backgroundWorker1.ReportProgress(0 * 100 / _tcRows.Length, rs2);
            }
            if (_bCancel)
                return true;

            return false;
        }
Esempio n. 8
0
    private IEnumerable <ReportStat> GetReportStats()
    {
        ReportStat[] statistics;
        try
        {
            statistics = (ReportStat[])Cache["ReportStatData"];
        }
        catch (InvalidCastException)
        {
            // This happens when default.aspx page is recompiled. Just Ignore the cache
            statistics = null;
        }

        if (statistics != null)
        {
            return(statistics);
        }

        using (OracleDataSource dsHits = new OracleDataSource())
        {
            dsHits.SelectSql             = @"
select t.report_id as report_id,
       MIN(t.query_seconds) as min_query_seconds,
       MAX(t.query_seconds) as max_query_seconds,
       ROUND(AVG(t.query_seconds), 4) as avg_query_seconds,
       MAX(t.hit_index) as hit_count
  from xreporter_report_hits t
  where t.application_name = :application_name
 group by t.report_id
";
            dsHits.SysContext.ModuleName = "DCMS Live 2009 Home";
            dsHits.ConnectionString      = ConfigurationManager.ConnectionStrings["DCMSLIVE"].ConnectionString;
            dsHits.ProviderName          = ConfigurationManager.ConnectionStrings["DCMSLIVE"].ProviderName;
            Parameter appName = new Parameter("application_name", DbType.String);
            appName.DefaultValue = ProfileManager.Provider.ApplicationName;
            dsHits.SelectParameters.Add(appName);
            try
            {
                statistics =
                    (from object stat in dsHits.Select(DataSourceSelectArguments.Empty)
                     select new ReportStat(DataBinder.Eval(stat, "report_id", "{0}"))
                {
                    MinQuerySeconds = DataBinder.Eval(stat, "min_query_seconds"),
                    MaxQuerySeconds = DataBinder.Eval(stat, "max_query_seconds"),
                    AverageQuerySeconds = DataBinder.Eval(stat, "avg_query_seconds"),
                    HitCount = DataBinder.Eval(stat, "hit_count")
                }).ToArray();
                Cache.Insert("ReportStatData", statistics, null, DateTime.UtcNow.AddHours(1),
                             System.Web.Caching.Cache.NoSlidingExpiration);
                __statUpdateTime = DateTime.Now;
            }
            catch (DbException ex)
            {
                Trace.Warn(ex.ToString());
                // Empty array
                statistics = new ReportStat[0];
                mvStats.ActiveViewIndex = 1;
                lblError.Text           = ex.Message;
            }
        }
        return(statistics);
    }
Esempio n. 9
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            //_tcRows 存放要处理的数据
            for (i = 0; i < _tcRows.Length; Interlocked.Increment(ref i))
            {
                if (CheckState())
                {
                    e.Cancel = true; return;
                }

                ReportStat rs0 = new ReportStat();
                rs0.step         = 0;
                rs0.currentIndex = i;
                rs0.msg          = string.Format("正在处理:{0}。 获取数据...", _tcRows[i]["NAME"]);
                backgroundWorker1.ReportProgress(i * 100 / _tcRows.Length, rs0);

                ReportStat rs1;
                string     strTcData = string.Empty;
                if (CheckState())
                {
                    e.Cancel = true; return;
                }
                try
                {
                    //正常处理信息,错误throw 抛出异常
                    //////
                    DoSomething(i, _tcRows[i]["ID"].ToString(), _tcRows[i]["NAME"].ToString());
                }
                catch (Exception ex)
                {
                    rs1 = new ReportStat();
                    if (!_bIgnoreError && i != _tcRows.Length)
                    {
                        int bOldPause = Interlocked.CompareExchange(ref _bPause, 1, 0);
                        rs1.step = 4;
                    }
                    else
                    {
                        rs1.step = 1;
                    }
                    rs1.currentIndex = i;
                    rs1.msg          = ex.Message;
                    backgroundWorker1.ReportProgress((i + 1) * 100 / _tcRows.Length, rs1);
                    if (CheckState())
                    {
                        e.Cancel = true; return;
                    }

                    continue;
                }

                //成功
                rs1              = new ReportStat();
                rs1.step         = 1;
                rs1.currentIndex = i;
                rs1.msg          = "成功!";
                backgroundWorker1.ReportProgress((i + 1) * 100 / _tcRows.Length, rs1);

                _setErrorList.Remove((int)_tcRows[i]["ID"]);
            }
        }