예제 #1
0
        private void ShowProgress(object obj)
        {
            ProgramWindow window = (ProgramWindow)obj;
            bool          a      = true;

            while (isRunning)
            {
                window.WriteAll(plies2Path + "\n已记录:" + beanCount);
                if (a)
                {
                    a = false;
                    window.WriteLine(" *");
                }
                else
                {
                    a = true;
                    window.Write("\n");
                }
                window.Write("当前线程状态:" + thread.ThreadState);
                //窗口的刷新时间
                Thread.Sleep(300);
            }
        }
예제 #2
0
        public void AddOne(object obj)
        {
            DateTime startTime = DateTime.Now;

            Thread.Sleep(1000);
            object[]      objs          = (object[])obj;
            ProgramWindow programWindow = (ProgramWindow)objs[0];
            IncidentBean  bean          = (IncidentBean)objs[1];

            programWindow.WriteLine("初始化...");
            try
            {
                //处理事件
                bean.CreateTime = DateTime.Now;
                bean.State      = 1;
                incidentId      = IncidentMapper.AddOne(bean);
                isFirst         = IncidentMapper.IsFirstRecord();
                //第一次记录必须保证索引表为空
                if (isFirst)
                {
                    DirIndexMapper.CleanAll();
                }
                //新建记录表
                Extend.BuildTable(incidentId, isFirst);
                programWindow.WriteLine("开始记录硬盘使用空间...");
                programWindow.WriteLine("(建议此时不要修改硬盘上的文件,以免影响最终的分析结果)");
                programWindow.Freeze();
                isRunning = true;
                Thread showProgress = new Thread(ShowProgress)
                {
                    Name = "showProgress"
                };
                showProgress.Start(programWindow);
                DriveInfo[] drives = DriveInfo.GetDrives();
                //遍历分区
                foreach (DriveInfo drive in drives)
                {
                    DirectoryInfo rootDir = new DirectoryInfo(drive.Name);
                    SeeDirectory(rootDir, 0);
                }
                isRunning = false;
                programWindow.WriteAll("记录完成,建立索引...\n");
                Extend.BuildIndex(incidentId);
                //收尾工作
                long count = RecordMapper.Count(incidentId);
                IncidentMapper.SetStateById(incidentId, 0);
                if (isFirst)
                {
                    //删除以前记录失败的作废表格
                    Extend.DeleteErrorTable(incidentId);
                }
                TimeSpan consumption = DateTime.Now - startTime;
                Log.Info(string.Format("数据记录完成, 记录:{0}({1}), 耗时:{2}", count, beanCount, consumption));
                programWindow.WriteLine(string.Format("数据记录完成,耗时:{0}小时{1}分。",
                                                      consumption.Days * 24 + consumption.Hours, consumption.Minutes));
                programWindow.RunOver();
            }
            catch (Exception e)
            {
                Log.Add(e);
                isRunning = false;
                programWindow.WriteLine("\n错误:");
                programWindow.WriteLine(e.Message);
                programWindow.RunOver();
                //throw e;
            }
        }