using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
//using Autodesk.Revit.DB;
namespace WallsArea
{
public partial class ProgressDlg : Form
{
public ProgressDlg()
{
InitializeComponent();
}
public Autodesk.Revit.DB.Document ActiveDocument { get; set; }
private void LogToFile(object sender, EventArgs e)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "log files (*.log)|*.log|All files (*.*)|*.*";
dlg.FilterIndex = 1;
dlg.RestoreDirectory = true;
if (DialogResult.OK != dlg.ShowDialog(this)) { return; }
using (StreamWriter writer = new StreamWriter(dlg.FileName)) {
writer.WriteLine(DateTime.Now + "\tЖурнал операций расчета площади стен");
writer.WriteLine();
string[] lines = m_log.Lines;
for (long i = 0; i < lines.Length; ++i) {
writer.WriteLine(lines[i]);
}
writer.Close();
}
}
private void CloseDlg(object sender, EventArgs e)
{
if (worker.IsBusy) { return; }
Close();
}
private void OnDoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
if (null == worker) { return; }
Autodesk.Revit.DB.Document doc = e.Argument as Autodesk.Revit.DB.Document;
if (null == doc) { return; }
CalcAreaAction act = new CalcAreaAction();
act.Execute(doc, worker);
e.Result = act.Log;
}
public void RunWorker()
{
m_close.Enabled = false;
m_logToFile.Enabled = false;
m_log.Enabled = false;
this.UseWaitCursor = true;
worker.RunWorkerAsync(ActiveDocument);
}
private void OnClosing(object sender, FormClosingEventArgs e)
{
if (worker.IsBusy) { e.Cancel = true; }
}
private void OnProgress(object sender, ProgressChangedEventArgs e)
{
m_progress.Value = e.ProgressPercentage;
this.Text = e.UserState as string;
}
private void OnWorkerComplete(object sender, RunWorkerCompletedEventArgs e)
{
m_log.Text = e.Result as string;
m_log.Enabled = true;
m_close.Enabled = true;
m_logToFile.Enabled = true;
this.UseWaitCursor = false;
}
private void ProgressDlg_Load(object sender, EventArgs e)
{
CalcAreaAction act = new CalcAreaAction();
act.Execute(ActiveDocument);
m_log.Text = act.Log;
m_close.Enabled = true;
m_logToFile.Enabled = true;
}
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
ProgressDlg dlg = new ProgressDlg();
dlg.ActiveDocument = commandData.Application.ActiveUIDocument.Document;
dlg.ShowDialog();
//dlg.RunWorker();
return Result.Succeeded;
}
}
}