/// <summary> /// 对指定进度操作对象及其子操作添加进度条改变、进度信息改变、执行结束、执行中止、执行异常事件的事件处理 /// </summary> /// <param name="opt"></param> /// <param name="isTopOperation"></param> protected new void BindEventByOneOpt(IProgressOperation opt, bool isTopOperation) { if (isTopOperation) { opt.OperationStart += ProgressOperation_OperationStart; opt.OperationFinished += ProgressOperation_OperationFinished; opt.OperationStoped += ProgressOperation_OperationStoped; opt.OperationError += ProgressOperation_OperationError; } if (MessageCtrl != null) { opt.Msgs.MessageChanged += ProgressOperation_MessageChanged; } if (GridView != null) { opt.Msgs.MessageChanged += ProgressOperation_MessageChanged_GridView; } if (ProgressBarCtrl != null) { opt.ProgressChanged += ProgressOperation_ProgressChanged; } if (ProgressBarCtrl != null) { opt.ProgressAdd += ProgressOperation_ProgressAdd; } opt.SubProgressOperations.ForEach(subOpt => BindEventByOneOpt(subOpt, false)); }
/// <summary> /// 对指定进度操作对象及其子操作添加进度条改变、进度信息改变、执行结束、执行中止、执行异常事件的事件处理 /// </summary> /// <param name="opt"></param> /// <param name="isTopOperation">标识是否为顶层进度操作(非子操作)</param> protected new void BindEventByOneOpt(IProgressOperation opt, bool isTopOperation) { if (isTopOperation)//只有顶层进度操作才绑定指定的开始、中止、结束、异常事件处理 { opt.OperationStart += ProgressOperation_OperationStart; opt.OperationStoped += ProgressOperation_OperationStoped; opt.OperationFinished += ProgressOperation_OperationFinished; opt.OperationError += ProgressOperation_OperationError; } else//子操作事件处理 { opt.OperationError += (sender, e) => { opt.Msgs.Error = e.OptException.ToString(); opt.Msgs.Info(e.OptException.Message); }; } if (MessageCtrl != null) { opt.Msgs.MessageChanged += ProgressOperation_MessageChanged; } if (GridCtrl != null) { opt.ProgressDataOuput += ProgressOperation_ProgressDataOuput; } if (ProgressBarCtrl != null) { opt.ProgressChanged += ProgressOperation_ProgressChanged; } if (ProgressBarCtrl != null) { opt.ProgressAdd += ProgressOperation_ProgressAdd; } opt.SubProgressOperations.ForEach(subOpt => BindEventByOneOpt(subOpt, false)); }
public ProgressWindow(IProgressOperation operation) { this._operation = operation; this._operation.ProgressChanged += new EventHandler(_operation_ProgressChanged); this._operation.ProgressTotalChanged += new EventHandler(_operation_TotalChanged); this._operation.Complete += new EventHandler(_operation_Complete); InitializeComponent(); this.Loaded += new RoutedEventHandler(ProgressWindow_Loaded); }
public ProgressWindow(IProgressOperation operation) { this._operation = operation; this._operation.ProgressChanged += new EventHandler(_operation_ProgressChanged); this._operation.ProgressTotalChanged += new EventHandler(_operation_TotalChanged); this._operation.Complete += new EventHandler(_operation_Complete); InitializeComponent(); this.Loaded += new RoutedEventHandler(ProgressWindow_Loaded); }
/// <summary> /// 将进度信息写入数据库中 /// </summary> /// <param name="dbConnection"></param> /// <param name="tableName"></param> public static void WriteLogDb(this IProgressOperation opt, DbHelper dbHelper, string tableName) { //var properties = opt.Msgs.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(v => v.CanWrite && v.CanWrite).ToArray(); //var propertyName = properties.Select(v => v.Name); //var fields = propertyName.Aggregate((a, b) => a + "," + b); //var values = properties.Select(v => v.GetValue(opt, null).ToString()); var m = opt.Msgs; var fields = $"{nameof(m.Id)},{nameof(m.Name)},{nameof(m.Description)},{nameof(m.Code)},{nameof(m.StartTime)},{nameof(m.EndTime)},{nameof(m.AssemblyName)},{nameof(m.AssemblyVersion)},{nameof(m.Error)},{nameof(m.AllMessage)}"; var values = $"{m.Id},'{m.Name}','{m.Description}','{m.Code}','{m.StartTime}','{m.EndTime}','{m.AssemblyName}','{m.AssemblyVersion}','{m.Error}','{m.AllMessage}'"; var sql = $"insert into {tableName} ({fields}) values ({values})"; dbHelper.ExcNonQuery(sql); }
public ProgressWindow(IProgressOperation operation, string fileName, string fileTitle) { _operation = operation; _fileName = fileName; _fileTitle = fileTitle; _operation.ProgressChanged += _operation_ProgressChanged; _operation.ProgressTotalChanged += _operation_TotalChanged; _operation.Complete += _operation_Complete; InitializeComponent(); Loaded += ProgressWindow_Loaded; }
public ProgressBar(IProgressOperation operation) { _operation = operation; _operation.ProgressChanged += _operation_ProgressChanged; _operation.ProgressTotalChanged += _operation_TotalChanged; _operation.Complete += _operation_Complete; _operation.MessageChanged += _operation_MessageChanged; InitializeComponent(); Loaded += ProgressWindow_Loaded; }
public ProgressWindow(IProgressOperation operation, string fileName, string fileTitle) { _operation = operation; _fileName = fileName; _fileTitle = fileTitle; _operation.ProgressChanged += _operation_ProgressChanged; _operation.ProgressTotalChanged += _operation_TotalChanged; _operation.Complete += _operation_Complete; InitializeComponent(); Loaded += ProgressWindow_Loaded; }
private void ButtonStart_Click(object sender, RoutedEventArgs e) { _operation = new FileConcater(((FileCounter) _operation).Files, _fileName, Total, _fileTitle); _operation.ProgressChanged += _operation_ProgressChanged; _operation.ProgressTotalChanged += _operation_TotalChanged; _operation.Complete += _operation_Complete; _operation.Start(); TextBlockProcessing.Text = "Обработано файлов:"; TextBlockOf.Visibility = Visibility.Visible; TextBlockCurrent.Visibility = Visibility.Visible; ButtonStart.Visibility = Visibility.Hidden; }
private void ButtonStart_Click(object sender, RoutedEventArgs e) { _operation = new FileConcater(((FileCounter)_operation).Files, _fileName, Total, _fileTitle); _operation.ProgressChanged += _operation_ProgressChanged; _operation.ProgressTotalChanged += _operation_TotalChanged; _operation.Complete += _operation_Complete; _operation.Start(); TextBlockProcessing.Text = "Обработано файлов:"; TextBlockOf.Visibility = Visibility.Visible; TextBlockCurrent.Visibility = Visibility.Visible; ButtonStart.Visibility = Visibility.Hidden; }
/// <summary> /// 生成日志文件,将处理信息写入日志文件 /// </summary> /// <param name="opt">进度信息</param> /// <param name="errMsg">异常信息</param> public void WriteLog(IProgressOperation opt, string errMsg = "") { StringBuilder sb = new StringBuilder(); AssemblyName assemblyName = Assembly.GetEntryAssembly().GetName(); sb.AppendLine("功能名称:" + opt.Name); sb.AppendLine("功能描述:" + opt.Description); sb.AppendLine("模块代码:" + opt.GetType().Name); sb.AppendLine("开始时间:" + opt.StartTime); sb.AppendLine("完成时间:" + opt.EndTime); sb.AppendLine("程序名称:" + assemblyName.Name); sb.AppendLine("程序版本:" + assemblyName.Version); sb.AppendLine("操作异常:" + errMsg); sb.AppendLine("\r\n\r\n\r\n---------------------------------------进程信息---------------------------------------"); sb.AppendLine(opt.Msgs.AllMessage); WriteLog(sb.ToString()); }
/// <summary> /// 生成日志文件,将处理信息写入日志文件 /// <para>日志文件格式示例:Log2019-10-11 10:01:21.txt</para> /// </summary> /// <param name="logDirectory">日志保存目录,值为null或空白时自动赋值为:[软件生成目录]\Log</param> /// <param name="logPrefix">日志文件名的前缀</param> public static void WriteLogFile(this IProgressOperation opt, string logDirectory = null, string logPrefix = "Log") { var Msgs = opt.Msgs; var sb = new StringBuilder(); sb.AppendLine("操作ID:" + Msgs.Id); sb.AppendLine("功能名称:" + Msgs.Name); sb.AppendLine("功能描述:" + Msgs.Description); sb.AppendLine("模块代码:" + Msgs.Code); sb.AppendLine("开始时间:" + Msgs.StartTime); sb.AppendLine("完成时间:" + Msgs.EndTime); sb.AppendLine("程序名称:" + Msgs.AssemblyName); sb.AppendLine("程序版本:" + Msgs.AssemblyVersion); sb.AppendLine("操作异常:" + Msgs.Error); sb.AppendLine("\r\n\r\n\r\n---------------------------------------进程信息---------------------------------------"); sb.AppendLine(Msgs.AllMessage); logDirectory = string.IsNullOrWhiteSpace(logDirectory) ? AppDomain.CurrentDomain.BaseDirectory + "Log" : logDirectory; Directory.CreateDirectory(logDirectory); string logFilePath = Path.Combine(logDirectory, logPrefix + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ".txt"); File.WriteAllText(logFilePath, sb.ToString()); }
void IWorkspaceWindow.ShowProgress(IProgressOperation progressOperation) { throw new NotImplementedException(); }