I'm currently creating a WPF form which retrieve some manual information and then perform some activities through PowerShell.
Activity is a class that implement INotifyPropertyChanged in order to reflect property changes (for example when an activity fails, its status changes from "running" to "Error"). I've created a listView (datagrid) which itemsSource is an ObservableCollection named Sequence. Sequence is declared in mainWindows class.
Activity Class is that :
public class Activity : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private int step;
public int Step
{
get { return this.step; }
set
{
if (this.step != value)
{
this.step = value;
this.NotifyPropertyChanged("Step");
}
}
}
private String group;
public String Group
{
get { return this.group; }
set
{
if (this.group != value)
{
this.group = value;
this.NotifyPropertyChanged("Group");
}
}
}
private String activityName;
public String ActivityName
{
get { return this.activityName; }
set
{
if (this.activityName != value)
{
this.activityName = value;
this.NotifyPropertyChanged("ActivityName");
}
}
}
private Model.Status status;
public Model.Status Status
{
get { return this.status; }
set
{
if (this.status != value)
{
this.status = value;
this.NotifyPropertyChanged("Status");
}
}
}
private String cmdlet;
public String Cmdlet
{
get { return this.cmdlet; }
set
{
if (this.cmdlet != value)
{
this.cmdlet = value;
this.NotifyPropertyChanged("Cmdlet");
}
}
}
private Dictionary<String, Object> parameters;
public Dictionary<String, Object> Parameters
{
get { return this.parameters; }
set { this.parameters = value; }
}
public Activity(int _Step, String _ActivityName, String _Group , Model.Status _Status, String _Cmdlet, Dictionary<String, Object> _Parameters)
{
this.Step = _Step;
this.Group = _Group;
this.ActivityName = _ActivityName;
this.Status = _Status;
this.Cmdlet = _Cmdlet;
this.Parameters = _Parameters;
}
public void NotifyPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
internal void Run(ref Runspace _rs)
{
using (PowerShell ps = PowerShell.Create())
{
ps.Runspace = _rs;
//ps.AddCommand(this.cmdlet).AddParameter("Site", this._Selection.SelectedSite);
ps.AddCommand(this.cmdlet).AddParameters(this.Parameters);
Collection<PSObject> results = ps.Invoke();
if (results.Count > 0 && ps.HadErrors == false)
{
foreach (PSObject item in results)
{
this.status = (Model.Status)Enum.Parse(typeof(Model.Status), item.ToString(), true);
}
}
else
{
this.Status = Model.Status.Error;
}
}
}
}
Deployment start when I click on the Last "Next" button. A function Deploy is started :
private void DeploySite()
{
// Build list of activities
//
int i = 0;
Dictionary<String, Object> _params = new Dictionary<string,object>();
_params.Add("Site", this._Selection.SelectedSite);
this.Sequence.Add(new Model.Activity(i++, "Update System Discovery Method", "Configure Administration Node", Model.Status.NoStatus, "Update-SystemDiscoveryMethod", _params));
this.Sequence.Add(new Model.Activity(i++, "Update User Discovery Method", "Configure Administration Node", Model.Status.NoStatus, "Update-SystemDiscoveryMethod", _params));
// Start Execution of activities
//
foreach (Model.Activity activity in this.Sequence)
{
activity.Status = Model.Status.Running;
activity.Run(ref rs);
}
}
My problem is that the view is updated only when every activities are finished, in other words when the DeploySite() function ends.
I would like to view progression of each activities when there are executed.
Any help will be greatly appreciated.