public MultiEnvironmentWorkflowDefinitionViewModel(MultiEnvironmentWorkflowDefinition item, ITFSConnectivity tfsConnectivity, ITFSBuild tfsBuild, ITFSLabEnvironment tfsLabEnvironment, ITFSTest tfsTest, IRegionManager regionManager, IEventAggregator eventAggregator)
        {
            this.Item = item;
            this.tfsConnectivity = tfsConnectivity;
            this.tfsBuild = tfsBuild;
            this.tfsLabEnvironment = tfsLabEnvironment;
            this.tfsTest = tfsTest;
            this.regionManager = regionManager;
            this.eventAggregator = eventAggregator;
            this.buildScheduleViewModel = new BuildScheduleViewModel(this.Item);

            this.AvailableTestSuites = new SelectableCollection<AssociatedTestSuite>();
            this.AvailableEnvironments = new SelectableCollection<AvailableEnvironmentViewModel>();
            
            this.GenerateBuildDefinitionsCommand = new DelegateCommand(GenerateBuildDefinitions, () => !HasErrors && !this.IsGeneratingBuildDefinitions);
            this.DeleteBuildDefinitionsCommand = new DelegateCommand(DeleteExistingBuildDefinitions, () => !this.IsGeneratingBuildDefinitions);
            this.AddDeploymentScriptCommand = new DelegateCommand(AddDeploymentScript);
            this.RemoveDeploymentScriptCommand = new DelegateCommand<DeploymentScript>(RemoveDeploymentScript);
            this.RefreshDataCommand = new DelegateCommand(InitializeData);

            CompositeApplicationCommands.RefreshCommand.RegisterCommand(this.RefreshDataCommand);

            this.Item.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName.Equals("Name") || args.PropertyName.Equals("IsDirty")) 
                    this.RaisePropertyChanged(() => this.HeaderInfo);
            };
            this.Item.MainLabWorkflowDefinition.SourceBuildDetails.PropertyChanged += (sender, args) => { if (args.PropertyName.Equals("QueueNewBuild")) { if (this.Item.MainLabWorkflowDefinition.SourceBuildDetails.QueueNewBuild) { this.Item.MainLabWorkflowDefinition.SourceBuildDetails.BuildUri = null; this.RaisePropertyChanged(() => this.SelectedBuildtoUse); } } };

            InitializeData();

        }
        public MultiEnvironmentWorkflowsViewModel(IWorkflowManagerStorage workflowManagerStorage, ITFSConnectivity tfsConnectivity, ITFSBuild tfsBuild, ITFSLabEnvironment tfsLabEnvironment, ITFSTest tfsTest, IRegionManager regionManager, IFileDialogService fileDialogService, IEventAggregator eventAggregator)
        {
            this.workflowManagerStorage = workflowManagerStorage;
            this.tfsConnectivity = tfsConnectivity;
            this.tfsBuild = tfsBuild;
            this.tfsLabEnvironment = tfsLabEnvironment;
            this.tfsTest = tfsTest;
            this.regionManager = regionManager;
            this.fileDialogService = fileDialogService;
            this.eventAggregator = eventAggregator;

            this.tfsConnectivity.PropertyChanged += (source, args) => { if (args.PropertyName.Equals("IsConnected")) { this.RaisePropertyChanged(() => this.IsConnectedToTfs); this.RaisePropertyChanged(() => this.CanEditDefinitions); } };
            this.tfsConnectivity.PropertyChanged += (source, args) => { if (args.PropertyName.Equals("TfsUri")) { this.RaisePropertyChanged(() => this.TeamProjectCollectionUri); } };
            this.tfsConnectivity.PropertyChanged += (source, args) => { if (args.PropertyName.Equals("TeamProjectName")) { this.RaisePropertyChanged(() => this.TeamProjectName); } };

            this.workflowManagerStorage.PropertyChanged += (source, args) => { if (args.PropertyName.Equals("Definitions")) { this.RaisePropertyChanged(() => this.Definitions); this.RaisePropertyChanged(() => this.CanEditDefinitions); } };
            this.workflowManagerStorage.PropertyChanged += (source, args) => { if (args.PropertyName.Equals("CurrentDefinitionFile")) { this.RaisePropertyChanged(() => this.CurrentWorkflowDefinitionFile); } };

            if (!string.IsNullOrWhiteSpace(this.CurrentWorkflowDefinitionFile))
            {
                this.workflowManagerStorage.Load(this.CurrentWorkflowDefinitionFile);
                this.RaisePropertyChanged(() => this.CurrentWorkflowDefinitionFile);
            }

            this.ConnectToTfsCommand = new DelegateCommand(ConnectToTfs, () => !this.tfsConnectivity.IsConnecting);
            this.AddNewDefinitionCommand = new DelegateCommand(AddNewDefinition);
            this.EditDefinitionCommand = new DelegateCommand<MultiEnvironmentWorkflowDefinition>(EditDefinition);
            this.NewCommand = new DelegateCommand(() => { string filepath; if (this.fileDialogService.SaveFile(out filepath)) { this.workflowManagerStorage.New(filepath); this.RaisePropertyChanged(() => this.CurrentWorkflowDefinitionFile); } });
            this.LoadCommand = new DelegateCommand(() => { string filepath; if (this.fileDialogService.OpenFile(out filepath)) { this.workflowManagerStorage.Load(filepath); this.RaisePropertyChanged(() => this.CurrentWorkflowDefinitionFile); } });
            this.SaveCommand = new DelegateCommand(() => this.workflowManagerStorage.Save(this.CurrentWorkflowDefinitionFile), () => !string.IsNullOrWhiteSpace(this.CurrentWorkflowDefinitionFile));
            this.SaveAsCommand = new DelegateCommand(() => { string filepath; if (this.fileDialogService.SaveFile(out filepath)) { this.workflowManagerStorage.Save(filepath); this.RaisePropertyChanged(() => this.CurrentWorkflowDefinitionFile); } }, () => !string.IsNullOrWhiteSpace(this.CurrentWorkflowDefinitionFile));
            this.DeleteDefinitionCommand = new DelegateCommand<MultiEnvironmentWorkflowDefinition>(DeleteDefinition);

            CompositeApplicationCommands.SaveAllCommand.RegisterCommand(this.SaveCommand);

            this.tfsConnectivity.PropertyChanged += (source, args) =>
            {
                if (args.PropertyName.Equals("IsConnecting"))
                {
                    ((DelegateCommand)this.ConnectToTfsCommand).RaiseCanExecuteChanged();
                    this.RaisePropertyChanged(() => this.IsConnecting);
                }
                else if (args.PropertyName.Equals("IsConnected"))
                {
                    this.RaisePropertyChanged(() => this.IsConnectedToTfs);
                    this.RaisePropertyChanged(() => this.TeamProjectCollectionUri);
                    this.RaisePropertyChanged(() => this.TeamProjectName);
                }
            };

            if (this.workflowManagerStorage.LastTFSConnection != null)
            {
                this.tfsConnectivity.Connect(this.workflowManagerStorage.LastTFSConnection.Uri, this.workflowManagerStorage.LastTFSConnection.Project);
            }

            this.eventAggregator.GetEvent<ApplicationClosingInterceptorEvent>().Subscribe(this.HandleApplicationClosing);
        }