private void AddToMethodsList(DotNetMethodRegion methodRegion)
        {
            if (MethodsToRunList == null)
            {
                var pluginActions = ModelItem.GetProperty <ICollection <IPluginAction> >("MethodsToRun");
                if (pluginActions == null || pluginActions.Count == 0)
                {
                    var current    = pluginActions;
                    var actions    = current ?? new List <IPluginAction>();
                    var collection = new ObservableCollection <IPluginAction>();
                    collection.CollectionChanged += MethodsToRunListOnCollectionChanged;
                    collection.AddRange(actions);
                    MethodsToRunList = new ObservableCollection <IMethodToolRegion <IPluginAction> >();
                }
                else
                {
                    var actions = new ObservableCollection <IPluginAction>();
                    actions.CollectionChanged += MethodsToRunListOnCollectionChanged;
                    actions.AddRange(pluginActions);
                    var regionCollections = BuildRegionsFromActions(pluginActions);
                    MethodsToRunList = regionCollections;
                }
            }
            var methodRegions = new ObservableCollection <IMethodToolRegion <IPluginAction> >();

            methodRegions.AddRange(MethodsToRunList);
            methodRegions.Add(methodRegion);
            MethodsToRunList = methodRegions;
            NamespaceRegion.Dependants.Add(methodRegion);
        }
 private void DeleteAction(DotNetMethodRegion method)
 {
     if (method != null)
     {
         var newList           = new ObservableCollection <IMethodToolRegion <IPluginAction> >();
         var methodToolRegions = newList.AddRange(MethodsToRunList);
         methodToolRegions.Remove(method);
         MethodsToRunList = methodToolRegions.ToObservableCollection();
     }
 }
        private ObservableCollection <IMethodToolRegion <IPluginAction> > BuildRegionsFromActions(IEnumerable <IPluginAction> pluginActions)
        {
            var regionCollections = new ObservableCollection <IMethodToolRegion <IPluginAction> >();

            foreach (var pluginAction in pluginActions)
            {
                if (pluginAction == null)
                {
                    continue;
                }
                var dotNetMethodRegion = new DotNetMethodRegion(Model, ModelItem, _sourceRegion, _namespaceRegion)
                {
                    SelectedMethod = pluginAction
                };
                dotNetMethodRegion.PropertyChanged += DotNetMethodRegionOnPropertyChanged;
                regionCollections.Add(dotNetMethodRegion);
            }
            return(regionCollections);
        }
        private void CreateMethodRegion()
        {
            var methodRegion = new DotNetMethodRegion(Model, ModelItem, SourceRegion, NamespaceRegion)
            {
                SelectedMethod = null
            };

            methodRegion.SourceChangedAction = () =>
            {
                if (methodRegion.SelectedMethod != null)
                {
                    if (methodRegion.SelectedMethod.ID == Guid.Empty)
                    {
                        methodRegion.SelectedMethod.ID = Guid.NewGuid();
                    }
                    bool hasUnselectedValue = MethodsToRunList.Any(methodToolRegion => methodToolRegion.SelectedMethod == null);
                    if (!hasUnselectedValue)
                    {
                        CreateMethodRegion();
                    }
                }
            };
            methodRegion.PropertyChanged += DotNetMethodRegionOnPropertyChanged;
            methodRegion.ErrorsHandler   += (sender, list) =>
            {
                List <ActionableErrorInfo> errorInfos =
                    list.Select(error => new ActionableErrorInfo(new ErrorInfo
                {
                    ErrorType = ErrorType.Critical,
                    Message   = error
                }, () => { })).ToList();
                UpdateDesignValidationErrors(errorInfos);
                Errors = new List <IActionableErrorInfo>(errorInfos);
            };
            AddToMethodsList(methodRegion);
        }