添加项目文件。
This commit is contained in:
172
WPFMonitorRevitAPI-master/DoWork/ProgressViewModel.cs
Normal file
172
WPFMonitorRevitAPI-master/DoWork/ProgressViewModel.cs
Normal file
@@ -0,0 +1,172 @@
|
||||
namespace Utils.Basis.ViewModel
|
||||
{
|
||||
using Autodesk.Revit.DB;
|
||||
using Utils.Basis;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
public class ProgressViewModel : ViewModelBase
|
||||
{
|
||||
private BackgroundWorker _backgroundWorker = new BackgroundWorker();
|
||||
private bool _canceled;
|
||||
private DelegateCommand _cancelProcess;
|
||||
private int _count;
|
||||
private ProgressViewModel.DoWorkDelegate _doWorkDelegate;
|
||||
private int _maxCount = 100;
|
||||
private bool _progressBarActive;
|
||||
private Transaction _transaction;
|
||||
private string _windowTitle = "Selecting Elements";
|
||||
|
||||
public ProgressViewModel(ProgressViewModel.DoWorkDelegate doWorkDelegate)
|
||||
{
|
||||
this._doWorkDelegate = doWorkDelegate;
|
||||
this._backgroundWorker.DoWork += this._backgroundWorker_DoWork;
|
||||
this._backgroundWorker.RunWorkerCompleted += this._backgroundWorker_RunWorkerCompleted;
|
||||
this._backgroundWorker.WorkerSupportsCancellation = true;
|
||||
this._cancelProcess = new DelegateCommand(new Action(this.Cancel));
|
||||
}
|
||||
|
||||
public delegate void DoWorkDelegate();
|
||||
|
||||
public bool Canceled
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._canceled;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._canceled = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DelegateCommand CancelProcess
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._cancelProcess;
|
||||
}
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._count;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._count = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int IntPercentage
|
||||
{
|
||||
get
|
||||
{
|
||||
int result;
|
||||
try
|
||||
{
|
||||
result = Convert.ToInt32(Math.Round((double)this.Count / (double)this.MaxCount * 100.0, 1));
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsBusy { get; set; }
|
||||
|
||||
public int MaxCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._maxCount;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._maxCount = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ProgressBarActive
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._progressBarActive;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._progressBarActive = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ProgressViewModel.DoWorkDelegate SetDelegate
|
||||
{
|
||||
set
|
||||
{
|
||||
this._doWorkDelegate = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string StringPercentage
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.IntPercentage.ToString() + "%";
|
||||
}
|
||||
}
|
||||
|
||||
public Transaction Transaction
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._transaction;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._transaction = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string WindowTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._windowTitle;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._windowTitle = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
this.Canceled = true;
|
||||
this.IsBusy = false;
|
||||
this._backgroundWorker.CancelAsync();
|
||||
if (this._transaction != null)
|
||||
{
|
||||
this._transaction.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void RunWorker()
|
||||
{
|
||||
this._backgroundWorker.RunWorkerAsync();
|
||||
}
|
||||
|
||||
private void _backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
this._doWorkDelegate();
|
||||
}
|
||||
|
||||
private void _backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
this.IsBusy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
WPFMonitorRevitAPI-master/DoWork/ProgressWindow.xaml
Normal file
26
WPFMonitorRevitAPI-master/DoWork/ProgressWindow.xaml
Normal file
@@ -0,0 +1,26 @@
|
||||
<Window
|
||||
x:Class="Utils.Basis.Controls.ProgressWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:basic="clr-namespace:Utils.Basis.Controls"
|
||||
Title="{Binding ProgressVM.WindowTitle}"
|
||||
Width="308.2"
|
||||
Height="96.2"
|
||||
MinWidth="300"
|
||||
Closing="Window_Closing"
|
||||
ResizeMode="NoResize"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<Grid>
|
||||
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<ProgressBar
|
||||
Height="30"
|
||||
HorizontalAlignment="Stretch"
|
||||
DataContext="{Binding ProgressVM}" />
|
||||
<Button
|
||||
Margin="200,3,3,3"
|
||||
Click="Button_Click"
|
||||
Command="{Binding ProgressViewModel.CancelProcess}"
|
||||
Content="Cancel" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
27
WPFMonitorRevitAPI-master/DoWork/ProgressWindow.xaml.cs
Normal file
27
WPFMonitorRevitAPI-master/DoWork/ProgressWindow.xaml.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace Utils.Basis.Controls
|
||||
{
|
||||
using System.CodeDom.Compiler;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
|
||||
[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
|
||||
public partial class ProgressWindow
|
||||
{
|
||||
public ProgressWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
base.Close();
|
||||
}
|
||||
|
||||
private void Window_Closing(object sender, CancelEventArgs e)
|
||||
{
|
||||
this.IsOpen = false;
|
||||
}
|
||||
|
||||
public bool IsOpen = true;
|
||||
}
|
||||
}
|
||||
28
WPFMonitorRevitAPI-master/DoWork/ViewModelBase.cs
Normal file
28
WPFMonitorRevitAPI-master/DoWork/ViewModelBase.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace Utils.Basis
|
||||
{
|
||||
using System.ComponentModel;
|
||||
|
||||
public abstract class ViewModelBase : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected bool Set<T>(ref T field, T newValue = default(T), [System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (System.Collections.Generic.EqualityComparer<T>.Default.Equals(field, newValue))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
field = newValue;
|
||||
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user