예제 #1
0
        public void FilteredNavigationViewModel_WhereFilterReset_Expects_OriginalExpandState()
        {
            IExplorerItemModel resourceVM = null;

            var reset = new AutoResetEvent(false);

            ThreadExecuter.RunCodeAsSTA(reset,
                                        () =>
            {
                Init(false, true);
                resourceVM = _vm.FindChild(_mockResourceModel.Object);
                IExplorerItemModel resourceVM2_1 = _vm.FindChild(_mockResourceModel1.Object);
                IExplorerItemModel resourceVM2_2 = _vm.FindChild(_mockResourceModel2.Object);

                Assert.IsTrue(resourceVM.Parent.IsExplorerExpanded == false);
                Assert.IsTrue(resourceVM2_1.Parent.IsExplorerExpanded == false);
                Assert.IsTrue(resourceVM2_2.Parent.IsExplorerExpanded == false);

                _vm.UpdateSearchFilter("Mock2");

                _vm.UpdateSearchFilter("");
            });
            reset.WaitOne();

            Assert.IsTrue(resourceVM.Parent.IsExplorerExpanded == false);
        }
예제 #2
0
        void MoveResource(IExplorerItemModel model, string newPath)
        {
            if (model.ResourcePath == newPath + "\\" + model.DisplayName && model.ResourcePath != model.DisplayName)
            {
                return;
            }
            switch (model.ResourceType)
            {
            case ResourceType.Folder:
                break;

            case ResourceType.Server:
                break;

            case ResourceType.Version:
                return;

            default:
                model.Children = new ObservableCollection <IExplorerItemModel>();
                break;
            }
            model.UpdateCategoryIfOpened(newPath + "\\" + model.DisplayName);
            var result = GetExplorerProxy(model.EnvironmentId).MoveItem(MapData(model), newPath, Guid.Empty);

            if (result.Status != ExecStatus.Success)
            {
                throw new Exception(result.Message);
            }
            model.Parent.RemoveChild(model);
            model.ResourcePath = newPath;
            ItemAddedMessageHandler(new ServerExplorerItem(model.DisplayName, model.ResourceId, model.ResourceType, null, model.Permissions, newPath + "\\" + model.DisplayName));

            RefreshVersionHistory(model.EnvironmentId, model.ResourceId);
        }
예제 #3
0
        /// <summary>
        /// Selects the and expand the correct node from the from initial navigation item view model.
        /// </summary>
        private void SelectAndExpandFromInitialValue()
        {
            IExplorerItemModel navigationItemViewModel = null;

            if (_initialItemResourceID != Guid.Empty)
            {
                navigationItemViewModel = StudioResourceRepository.FindItem(model => model.EnvironmentId == _initialItemEnvironmentID && model.ResourceId == _initialItemResourceID);
            }

            if (navigationItemViewModel == null)
            {
                return;
            }

            //
            // Select and expand the initial node
            //
            navigationItemViewModel.IsChecked = true;

            var parent = navigationItemViewModel.Parent;

            if (parent != null)
            {
                parent.IsDeploySourceExpanded = true;
            }
        }
예제 #4
0
        /// <summary>
        /// Recalculates
        /// </summary>
        private void CalculateStats(bool updateSuccess = true)
        {
            if (updateSuccess)
            {
                DeploySuccessfull = false;
            }

            if (Source != null && Source.ExplorerItemModels != null && Source.ExplorerItemModels.Count > 0)
            {
                Source.ClearConflictingNodesNodes();
                IExplorerItemModel explorerItemModel = Source.ExplorerItemModels[0];
                if (explorerItemModel != null)
                {
                    var items = explorerItemModel.Descendants().Where(model => model.IsChecked.GetValueOrDefault(false)).ToList();
                    _deployStatsCalculator.ConflictingResources = new ObservableCollection <DeployDialogTO>();

                    _deployStatsCalculator.CalculateStats(items, _sourceStatPredicates, _sourceStats, out _sourceDeployItemCount);
                    _deployStatsCalculator.CalculateStats(items, _targetStatPredicates, _targetStats, out _destinationDeployItemCount);

                    RaiseDeployCommandCanExecuteChanged();
                }
            }
            NotifyOfPropertyChange(() => CanDeploy);
            NotifyOfPropertyChange(() => SourceItemsSelected);
        }
        protected static StudioResourceRepository CreateModels(bool isChecked, out IEnvironmentModel environmentModel, out IExplorerItemModel resourceVm)
        {
            Mock<IContextualResourceModel> resourceModel = Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, Guid.NewGuid());

            var connection = new Mock<IEnvironmentConnection>();

            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            mockEnvironmentModel.Setup(e => e.Connection).Returns(connection.Object);
            var env = Dev2MockFactory.SetupEnvironmentModel(resourceModel, new List<IResourceModel>());
            env.Setup(a => a.AuthorizationService).Returns(new Mock<IAuthorizationService>().Object);
            environmentModel = env.Object;
            var serverItemModel = new ExplorerItemModel { DisplayName = "localhost", ResourceType = Common.Interfaces.Data.ResourceType.Server, EnvironmentId = environmentModel.ID, ResourceId = Guid.NewGuid(), ResourcePath = "" };

            ExplorerItemModel workflowsFolder = new ExplorerItemModel { DisplayName = "WORKFLOWS", ResourceType = Common.Interfaces.Data.ResourceType.Folder, ResourcePath = "WORKFLOWS", ResourceId = Guid.NewGuid(), EnvironmentId = mockEnvironmentModel.Object.ID };

            serverItemModel.Children.Add(workflowsFolder);

            var studioResourceRepository = new StudioResourceRepository(serverItemModel, Invoke);
            resourceModel.Setup(model => model.Category).Returns("WORKFLOWS\\" + resourceModel.Object.DisplayName);
            TestEnvironmentRespository testEnvironmentRespository = new TestEnvironmentRespository(environmentModel);
            // ReSharper disable ObjectCreationAsStatement
            new EnvironmentRepository(testEnvironmentRespository);
            // ReSharper restore ObjectCreationAsStatement
            IEnvironmentModel internalEnvironmentModel = environmentModel;
            studioResourceRepository.GetCurrentEnvironment = () => internalEnvironmentModel.ID;
            studioResourceRepository.AddResouceItem(resourceModel.Object);
            resourceVm = workflowsFolder.Children[0];
            resourceVm.IsChecked = isChecked;
            return studioResourceRepository;
        }
        public void DeleteFolder(IExplorerItemModel item)
        {
            Dev2Logger.Log.Info(String.Format("Delete Folder Resource: {0} Id:{1}", item.DisplayName, item.EnvironmentId));
            VerifyArgument.IsNotNull("item", item);
            IExplorerItemModel parentItem = item.Parent;

            if (parentItem != null)
            {
                var found = parentItem.Children.FirstOrDefault(a => a.ResourcePath == item.ResourcePath && a.ResourceType == ResourceType.Folder);
                if (found != null)
                {
                    item = found;
                }
                if (parentItem.Children.Remove(item))
                {
                    try
                    {
                        var result = GetExplorerProxy(item.EnvironmentId).DeleteItem(MapData(item), Guid.Empty);
                        if (result.Status != ExecStatus.Success)
                        {
                            throw new Exception(result.Message);
                        }
                    }
                    catch (Exception)
                    {
                        parentItem.Children.Add(item);

                        throw;
                    }

                    parentItem.OnChildrenChanged();
                }
            }
        }
        public void RenameItem(IExplorerItemModel item, string newName)
        {
            VerifyArgument.IsNotNull("item", item);
            VerifyArgument.IsNotNullOrWhitespace("newName", newName);
            Dev2Logger.Log.Info(String.Format("Rename Item Resource: {0} New name :{1} Id:{2}", item.DisplayName, newName, item.EnvironmentId));
            if (item.DisplayName == newName)
            {
                return;
            }

            var result = GetExplorerProxy(item.EnvironmentId).RenameItem(MapData(item), newName, Guid.Empty);

            if (result.Status != ExecStatus.Success)
            {
                throw new Exception(result.Message);
            }

            var explorerItemModel = FindItem(i => i.EnvironmentId == item.EnvironmentId && i.ResourceId == item.ResourceId);

            RefreshVersionHistory(item.EnvironmentId, item.ResourceId);

            if (!item.Equals(explorerItemModel))
            {
                explorerItemModel.SetDisplay(newName);
            }
        }
        public void AddItem(IExplorerItemModel item)
        {
            VerifyArgument.IsNotNull("item", item);
            VerifyArgument.IsNotNull("parent", item.Parent);
            Dev2Logger.Log.Info(String.Format("AddItem Name: {0} Type:{1}", item.DisplayName, item.ResourceType));
            var explorerItem = MapData(item);

            if (explorerItem != null)
            {
                try
                {
                    var result = GetExplorerProxy(item.EnvironmentId).AddItem(explorerItem, item.Parent.EnvironmentId);

                    if (result.Status != ExecStatus.Success)
                    {
                        throw new Exception(result.Message);
                    }
                }
                catch (Exception)
                {
                    item.Parent.Children.Remove(item);
                    item.OnChildrenChanged();
                    throw;
                }
            }
        }
예제 #9
0
        void SetTreeStateBack(IEnumerable <IExplorerItemModel> expandedList, IExplorerItemModel selectedItem)
        {
            if (expandedList != null)
            {
                IStudioResourceRepository studioResourceRepository = StudioResourceRepository;
                foreach (var item in expandedList)
                {
                    var environment = studioResourceRepository.FindItemById(item.EnvironmentId);
                    if (environment != null)
                    {
                        IExplorerItemModel explorerItem = environment;
                        if (!string.IsNullOrEmpty(item.ResourcePath))
                        {
                            var strings = item.ResourcePath.Split('\\');
                            foreach (var s in strings)
                            {
                                if (explorerItem != null)
                                {
                                    explorerItem = explorerItem.Children.FirstOrDefault(c => c.DisplayName == s);
                                }
                            }
                        }
                        if (explorerItem != null)
                        {
                            explorerItem.IsExplorerExpanded = true;
                        }
                    }
                }
            }

            if (selectedItem != null)
            {
                BringItemIntoView(selectedItem.EnvironmentId, selectedItem.ResourceId);
            }
        }
예제 #10
0
        /// <summary>
        ///     The predicate used to detemine which resources are going to be overridden
        /// </summary>
        public bool DeploySummaryPredicateExisting(IExplorerItemModel node,
                                                   DeployNavigationViewModel targetNavViewModel)
        {
            var vm = node;

            if (vm == null || !vm.IsChecked.GetValueOrDefault(false))
            {
                return(false);
            }

            if (targetNavViewModel != null && targetNavViewModel.Environment != null)
            {
                IEnvironmentModel targetEnvironment = targetNavViewModel.Environment;
                if (targetEnvironment == null || targetEnvironment.ResourceRepository == null)
                {
                    return(false);
                }


                var conflictingItems = targetEnvironment.ResourceRepository.All()
                                       .Where(r => r.ID == vm.ResourceId)
                                       .Select(r => new Tuple <IResourceModel, IContextualResourceModel, IExplorerItemModel, DeployNavigationViewModel>(r, r as IContextualResourceModel, node, targetNavViewModel))
                                       .ToList();

                conflictingItems.ForEach(AddConflictingResources);

                return(targetEnvironment.ResourceRepository.All()
                       .Any(r => r.ID == vm.ResourceId));
            }
            return(false);
        }
 private static IExplorerItem MapData(IExplorerItemModel item)
 {
     return(new ServerExplorerItem(item.DisplayName, item.ResourceId, item.ResourceType,
                                   item.Children == null
                                       ? null
                                       : item.Children.Select(MapData).ToList(),
                                   item.Permissions, item.ResourcePath));
 }
 void UpdateExplorerItemModelOnUiThread(IExplorerItemModel explorerItemModel, int index)
 {
     Execute.OnUIThread(() =>
     {
         ExplorerItemModels.RemoveAt(index);
         ExplorerItemModels.Insert(index, explorerItemModel);
     });
 }
예제 #13
0
 private static bool HasNoChildren(IExplorerItemModel source, IExplorerItemModel destination)
 {
     if (destination.ResourceType == ResourceType.Folder || destination.ResourceType == ResourceType.Server)
         return destination.Children == null || 
                destination.Children.Any(
                    a => a.DisplayName == source.DisplayName && a.ResourceType != ResourceType.Folder);
     return source.ResourcePathWithoutName != destination.ResourcePathWithoutName &&
            destination.Parent.Children.Any(a=>a.DisplayName == source.DisplayName && a.ResourceType!= ResourceType.Folder);
 }
예제 #14
0
 public void RecusiveExplorerExpandParent(IExplorerItemModel parent)
 {
     if (parent != null)
     {
         if (parent.Parent != null)
         {
             RecusiveExplorerExpandParent(parent.Parent);
         }
         parent.IsExplorerExpanded = true;
     }
 }
예제 #15
0
        public void BringItemIntoView(Guid environmentId, Guid resourceId)
        {
            IStudioResourceRepository studioResourceRepository = StudioResourceRepository;
            IExplorerItemModel        item = studioResourceRepository.FindItemByIdAndEnvironment(resourceId, environmentId);

            if (item != null)
            {
                item.IsExplorerSelected = true;
                RecusiveExplorerExpandParent(item.Parent);
            }
        }
        private bool ContainsChild(Func <IExplorerItemModel, bool> filter, IExplorerItemModel root)
        {
            if (root.Children == null)
            {
                return(false);
            }

            bool desc = root.Children.Any(filter);

            return(desc || root.Children.Any(a => ContainsChild(filter, a)));
        }
예제 #17
0
 private static bool HasNoChildren(IExplorerItemModel source, IExplorerItemModel destination)
 {
     if (destination.ResourceType == ResourceType.Folder || destination.ResourceType == ResourceType.Server)
     {
         return(destination.Children == null ||
                destination.Children.Any(
                    a => a.DisplayName == source.DisplayName && a.ResourceType != ResourceType.Folder));
     }
     return(source.ResourcePathWithoutName != destination.ResourcePathWithoutName &&
            destination.Parent.Children.Any(a => a.DisplayName == source.DisplayName && a.ResourceType != ResourceType.Folder));
 }
        public void DeleteItem(IExplorerItemModel item)
        {
            VerifyArgument.IsNotNull("item", item);
            var tmpParent = item.Parent;

            if (item.Parent != null)
            {
                item.Parent.Children.Remove(item);
                tmpParent.OnChildrenChanged();
            }
        }
 private void ExplorerItemModelSetup(IExplorerItemModel explorerItemModel, Guid enviromentId)
 {
     if (explorerItemModel.Children != null)
     {
         foreach (var child in explorerItemModel.Children)
         {
             child.Parent        = explorerItemModel;
             child.EnvironmentId = enviromentId;
             ExplorerItemModelSetup(child, enviromentId);
         }
     }
 }
예제 #20
0
 private IExplorerItemModel FilterRec(Func <IExplorerItemModel, bool> filter, IExplorerItemModel root)
 {
     if (filter == null)
     {
         return(root);
     }
     if (!ContainsChild(filter, root))
     {
         return(null);
     }
     root.Children = root.Children.Where(a => FilterRec(filter, a) != null || filter(a)).ToObservableCollection();
     return(root);
 }
 private void UpdateCategory(IExplorerItemModel model, string newPath)
 {
     foreach (var child in model.Children)
     {
         if (child.ResourceType == ResourceType.Folder)
         {
             UpdateCategory(child, newPath + "\\" + child.DisplayName);
         }
         else
         {
             child.UpdateCategoryIfOpened(newPath + (newPath == "" ? "" : "\\") + child.DisplayName);
         }
     }
 }
예제 #22
0
 /// <summary>
 /// perform some kind of action on all children of a node. this can be moved onto the tree node interface if it is found to be needed elsewhere
 /// </summary>
 /// <param name="action"></param>
 /// <param name="node"></param>
 void Iterate(Action <IExplorerItemModel> action, IExplorerItemModel node)
 {
     if (node != null)
     {
         action(node);
         if (node.Children != null)
         {
             foreach (var child in node.Children)
             {
                 Iterate(action, child);
             }
         }
     }
 }
 private void LoadItemsToTree(Guid environmentId, IExplorerItemModel explorerItemModel, int indexToReplace)
 {
     if (explorerItemModel != null)
     {
         explorerItemModel.EnvironmentId = environmentId;
         explorerItemModel.IsConnected   = true;
         if (explorerItemModel.Children != null)
         {
             ExplorerItemModelSetup(explorerItemModel, environmentId);
         }
         explorerItemModel.IsRefreshing = ExplorerItemModels[indexToReplace].IsRefreshing;
         ExplorerItemModels.RemoveAt(indexToReplace);
         ExplorerItemModels.Insert(indexToReplace, explorerItemModel);
     }
 }
예제 #24
0
        /// <summary>
        ///     The predicate used to detemine which resources are going to be overridden
        /// </summary>
        public bool DeploySummaryPredicateNew(IExplorerItemModel node, IEnvironmentModel targetEnvironment)
        {
            var vm = node;

            if (vm == null || !vm.IsChecked.GetValueOrDefault(false))
            {
                return(false);
            }
            if (node.ResourceType == ResourceType.Server || node.ResourceType == ResourceType.Folder)
            {
                return(false);
            }
            return(targetEnvironment != null && targetEnvironment.ResourceRepository != null &&
                   targetEnvironment.ResourceRepository.All().All(r => r.ID != vm.ResourceId));
        }
 private IExplorerItemModel FilterRec(Func <IExplorerItemModel, bool> filter, IExplorerItemModel root)
 {
     if (filter == null)
     {
         return(root);
     }
     if (!ContainsChild(filter, root))
     {
         return(null);
     }
     // ReSharper disable MaximumChainedReferences
     root.Children = root.Children.Where(a => FilterRec(filter, a) != null || filter(a)).ToObservableCollection();
     // ReSharper restore MaximumChainedReferences
     return(root);
 }
예제 #26
0
        public static IEnumerable <IExplorerItemModel> Descendants(this IExplorerItemModel root)
        {
            var nodes = new Stack <IExplorerItemModel>(new[] { root });

            while (nodes.Any())
            {
                IExplorerItemModel node = nodes.Pop();
                yield return(node);

                foreach (var n in node.Children)
                {
                    nodes.Push(n);
                }
            }
        }
예제 #27
0
        /// <summary>
        /// handle resource checked
        /// </summary>
        /// <param name="checkStateChangedArgs"></param>
        void OnCheckedStateChangedAction(CheckStateChangedArgs checkStateChangedArgs)
        {
            if (checkStateChangedArgs != null && checkStateChangedArgs.PreviousState && checkStateChangedArgs.NewState == false)
            {
                if (Target != null)
                {
                    if (checkStateChangedArgs.ResourceId != Guid.Empty)
                    {
                        if (SelectedDestinationServer != null)
                        {
                            if (SelectedDestinationServer.ResourceRepository != null)
                            {
                                var resourceModel = SelectedDestinationServer.ResourceRepository.FindSingle(model => model.ID == checkStateChangedArgs.ResourceId) as IContextualResourceModel;
                                if (resourceModel != null)
                                {
                                    Target.SetNodeOverwrite(resourceModel, false);
                                }
                            }
                        }
                    }
                }
            }
            if (checkStateChangedArgs != null && checkStateChangedArgs.UpdateStats)
            {
                CalculateStats();
            }
            if (checkStateChangedArgs != null && checkStateChangedArgs.NewState && checkStateChangedArgs.PreviousState == false)
            {
                if (Source != null && Source.ExplorerItemModels.Any())
                {
                    IExplorerItemModel explorerItemModel = Source.ExplorerItemModels[0];

                    var items           = explorerItemModel.Descendants().Where(model => model.IsChecked.GetValueOrDefault(false) && model.ResourceId == checkStateChangedArgs.ResourceId).ToList();
                    var namingConflicts = _deployStatsCalculator.CheckForNamingConflicts(items, Target).ToList();
                    if (namingConflicts.Any())
                    {
                        StringBuilder message = new StringBuilder("The following items exist on the Destination Server with the same path and a different ID. Please rename, move or delete on the destination server before deploying:" + Environment.NewLine);
                        foreach (var namingConflict in namingConflicts)
                        {
                            message.AppendLine(namingConflict.ResourcePath);
                            namingConflict.IsChecked = false;
                        }

                        PopupController.Show(message.ToString(), "Resource Conflicts", MessageBoxButton.OK, MessageBoxImage.Error, null);
                    }
                }
            }
        }
예제 #28
0
        protected bool OnMouseDown(IExplorerItemModel treenode, int clickCount)
        {
            if (treenode == null)
            {
                return(false);
            }

            //Select on rightclick
            if (SelectOnRightClick)
            {
                SetIsSelected(treenode, true);
            }

            //
            // Active environment logic
            //
            if (SetActiveEnvironmentOnClick)
            {
                IEnvironmentModel environment = EnvironmentRepository.Instance.FindSingle(environmentModel => environmentModel.ID == treenode.EnvironmentId);
                _eventPublisher.Publish(new SetActiveEnvironmentMessage(environment));
            }

            var model = treenode;

            if (model.Permissions < Permissions.View)
            {
                SetIsSelected(treenode, true);
                return(true);
            }

            //
            // Double click logic
            //
            if (OpenOnDoubleClick && clickCount == 2)
            {
                if (model.ResourceType >= ResourceType.Folder)
                {
                    SetIsExpanded(model);
                }
                if (model.CanEdit)
                {
                    model.EditCommand.Execute(null);
                }
            }

            SetIsSelected(treenode, true);
            return(true);
        }
예제 #29
0
 public static bool ShouldNotMove(IExplorerItemModel source, IExplorerItemModel destination)
 {
     bool hasNoChildren = HasNoChildren(source, destination);
     if(source != null && (source == destination || destination.IsVersion || source.IsVersion || source.ResourcePath.Equals(destination.ResourcePath, StringComparison.OrdinalIgnoreCase)
         || hasNoChildren))
     {
         if (hasNoChildren)
         {
             CustomContainer.Get<IPopupController>()
                 .Show("Conflicting resources found in the destination", "Conflicting Resources",
                     MessageBoxButton.OK, MessageBoxImage.Error,"");
         }
         return true;
     }
     return false;
 }
예제 #30
0
        /// <summary>
        ///     The predicate used to detemine if an item should be deployed
        /// </summary>
        public bool SelectForDeployPredicateWithTypeAndCategories(IExplorerItemModel node,
                                                                  ResourceType type, List<string> inclusionCategories,
                                                                  List<string> exclusionCategories)
        {
            var vm = node;
            if(vm == null || !vm.IsChecked.GetValueOrDefault(false)) return false;

            return (type.HasFlag(vm.ResourceType))
                    && (
                        inclusionCategories.Count == 0
                        || inclusionCategories.Contains(vm.ResourcePath)
                       )
                    && (
                        exclusionCategories.Count == 0
                        || !exclusionCategories.Contains(vm.ResourcePath)
                       );
        }
예제 #31
0
        public static bool ShouldNotMove(IExplorerItemModel source, IExplorerItemModel destination)
        {
            bool hasNoChildren = HasNoChildren(source, destination);

            if (source != null && (source == destination || destination.IsVersion || source.IsVersion || source.ResourcePath.Equals(destination.ResourcePath, StringComparison.OrdinalIgnoreCase) ||
                                   hasNoChildren))
            {
                if (hasNoChildren)
                {
                    CustomContainer.Get <IPopupController>()
                    .Show("Conflicting resources found in the destination", "Conflicting Resources",
                          MessageBoxButton.OK, MessageBoxImage.Error, "");
                }
                return(true);
            }
            return(false);
        }
        public void MoveFolder(IExplorerItemModel item, string newName)
        {
            VerifyArgument.IsNotNull("item", item);
            VerifyArgument.IsNotNullOrWhitespace("newName", newName);
            Dev2Logger.Log.Info(String.Format("Move Folder Resource: {0} New name :{1} Id:{2}", item.DisplayName, newName, item.EnvironmentId));
            var oldResourcePath   = item.ResourcePath;
            var newPath           = newName;
            var environmentId     = item.EnvironmentId;
            var result            = GetExplorerProxy(environmentId).RenameFolder(oldResourcePath, newPath, Guid.Empty);
            var explorerItemModel = LoadEnvironment(environmentId);

            LoadItemsToTree(environmentId, explorerItemModel);
            if (result.Status != ExecStatus.Success)
            {
                EventPublishers.Aggregator.Publish(new DisplayMessageBoxMessage("Error Renaming Folder", "Conflicting resources found in destination folder.", MessageBoxImage.Warning));
            }
        }
        private void LoadItemsToTree(Guid environmentId, IExplorerItemModel explorerItemModel)
        {
            if (explorerItemModel != null)
            {
                var otherServers = ExplorerItemModels.Where(i => i.ResourceType == ResourceType.Server).ToList();
                otherServers.ForEach(i =>
                {
                    i.IsExplorerExpanded = false;
                    i.IsExplorerSelected = false;
                });

                explorerItemModel.IsExplorerSelected = explorerItemModel.IsExplorerExpanded = explorerItemModel.ResourceType == ResourceType.Server;

                explorerItemModel.EnvironmentId = environmentId;
                explorerItemModel.IsConnected   = true;
                if (explorerItemModel.Children != null)
                {
                    ExplorerItemModelSetup(explorerItemModel, environmentId);
                }
                if (ExplorerItemModels.Any(a => a.EnvironmentId == environmentId))
                {
                    var index = ExplorerItemModels.IndexOf(ExplorerItemModels.FirstOrDefault(a => a.EnvironmentId == environmentId));
                    if (index >= 0)
                    {
                        explorerItemModel.IsRefreshing = ExplorerItemModels[index].IsRefreshing;
                        UpdateExplorerItemModelOnUiThread(explorerItemModel, index);
                    }
                }
                else
                {
                    var index = ExplorerItemModels.IndexOf(ExplorerItemModels.FirstOrDefault(a => a.EnvironmentId == environmentId));
                    if (index >= 0)
                    {
                        explorerItemModel.IsRefreshing = ExplorerItemModels[index].IsRefreshing;
                        UpdateExplorerItemModelOnUiThread(explorerItemModel, index);
                    }
                    else
                    {
                        Execute.OnUIThread(() =>
                        {
                            ExplorerItemModels.Add(explorerItemModel);
                        });
                    }
                }
            }
        }
        public void MoveItem(IExplorerItemModel model, string newPath)
        {
            VerifyArgument.IsNotNull("model", model);
            VerifyArgument.IsNotNull("newPath", newPath);
            if ((model.ResourcePath == ""?"": Path.GetDirectoryName(model.ResourcePath)) != newPath)
            {
                switch (model.ResourceType)
                {
                case ResourceType.Folder:
                    MoveFolder(model, newPath + (newPath == ""?"":"\\") + model.DisplayName);
                    UpdateCategory(model, newPath + (newPath == "" ? "" : "\\") + model.DisplayName);
                    break;

                default:
                    MoveResource(model, newPath);
                    break;
                }
            }
        }
예제 #35
0
 /// <summary>
 ///     The predicate used to detemine which resources are going to be overridden
 /// </summary>
 public bool DeploySummaryPredicateNew(IExplorerItemModel node, IEnvironmentModel targetEnvironment)
 {
     var vm = node;
     if(vm == null || !vm.IsChecked.GetValueOrDefault(false)) return false;
     if (node.ResourceType == ResourceType.Server || node.ResourceType == ResourceType.Folder)
         return false;
     return targetEnvironment != null && targetEnvironment.ResourceRepository != null &&
            targetEnvironment.ResourceRepository.All().All(r => r.ID != vm.ResourceId);
 }
        public void MoveFolder(IExplorerItemModel item, string newName)
        {

            VerifyArgument.IsNotNull("item", item);
            VerifyArgument.IsNotNullOrWhitespace("newName", newName);
            Dev2Logger.Log.Info(String.Format("Move Folder Resource: {0} New name :{1} Id:{2}", item.DisplayName, newName, item.EnvironmentId));
            var oldResourcePath = item.ResourcePath;
            var newPath = newName;
            var environmentId = item.EnvironmentId;
            var result = GetExplorerProxy(environmentId).RenameFolder(oldResourcePath, newPath, Guid.Empty);
            var explorerItemModel = LoadEnvironment(environmentId);
            LoadItemsToTree(environmentId, explorerItemModel);
            if (result.Status != ExecStatus.Success)
            {
                EventPublishers.Aggregator.Publish(new DisplayMessageBoxMessage("Error Renaming Folder", "Conflicting resources found in destination folder.", MessageBoxImage.Warning));
            }
        }
 void UpdateExplorerItemModelOnUiThread(IExplorerItemModel explorerItemModel, int index)
 {
     Execute.OnUIThread(() =>
     {
         ExplorerItemModels.RemoveAt(index);
         ExplorerItemModels.Insert(index, explorerItemModel);
     });
 }
        private void UpdateCategory(IExplorerItemModel model, string newPath)
        {
            
            foreach(var child in model.Children)
            {
                if (child.ResourceType == ResourceType.Folder)
                    UpdateCategory(child, newPath + "\\" + child.DisplayName);
                else
                child.UpdateCategoryIfOpened(newPath + (newPath == "" ? "" : "\\") + child.DisplayName);  

            }
        }
        public void MoveItem(IExplorerItemModel model, string newPath)
        {
            VerifyArgument.IsNotNull("model", model);
            VerifyArgument.IsNotNull("newPath", newPath);
            if((model.ResourcePath==""?"": Path.GetDirectoryName(model.ResourcePath)) != newPath )
            switch (model.ResourceType)
            {
                case ResourceType.Folder:
                    MoveFolder(model, newPath+ (newPath==""?"":"\\")+model.DisplayName);
                    UpdateCategory(model, newPath + (newPath == "" ? "" : "\\") + model.DisplayName);
                    break;
                default:
                    MoveResource(model, newPath);
                    break;
            }
         

        }
 private void ExplorerItemModelSetup(IExplorerItemModel explorerItemModel, Guid enviromentId)
 {
     if(explorerItemModel.Children != null)
     {
         foreach(var child in explorerItemModel.Children)
         {
             child.Parent = explorerItemModel;
             child.EnvironmentId = enviromentId;
             ExplorerItemModelSetup(child, enviromentId);
         }
     }
 }
 /// <summary>
 /// perform some kind of action on all children of a node. this can be moved onto the tree node interface if it is found to be needed elsewhere
 /// </summary>
 /// <param name="action"></param>
 /// <param name="node"></param>
 void Iterate(Action<IExplorerItemModel> action, IExplorerItemModel node)
 {
     if(node != null)
     {
         action(node);
         if(node.Children != null)
         {
             foreach(var child in node.Children)
             {
                 Iterate(action, child);
             }
         }
     }
 }
 public void DeleteItem(IExplorerItemModel item)
 {
     VerifyArgument.IsNotNull("item", item);
     var tmpParent = item.Parent;
     if(item.Parent != null)
     {
         item.Parent.Children.Remove(item);
         tmpParent.OnChildrenChanged();
     }
 }
        static IExplorerItemModel SetupExplorerItemModelWithFolderAndOneChild(string displayName, Guid envID, Guid resourceId, out IExplorerItemModel resourceItem, IStudioResourceRepository rep, IAsyncWorker worker, IConnectControlSingleton connectControlSingleton)
        {
            var serverItem = new ExplorerItemModel(rep, worker, connectControlSingleton)
            {
                ResourceType = ResourceType.Server,
                DisplayName = displayName,
                ResourceId = Guid.Empty,
                Permissions = Permissions.Administrator,
                EnvironmentId = envID
            };
            var folderItem = new ExplorerItemModel(rep, worker, connectControlSingleton)
            {
                ResourceType = ResourceType.Folder,
                DisplayName = Guid.NewGuid().ToString(),
                ResourceId = Guid.Empty,
                Permissions = Permissions.Administrator,
                EnvironmentId = envID
            };

            resourceItem = new ExplorerItemModel(rep, worker, connectControlSingleton)
            {
                ResourceType = ResourceType.WorkflowService,
                DisplayName = Guid.NewGuid().ToString(),
                ResourceId = resourceId,
                Permissions = Permissions.Administrator,
                EnvironmentId = envID,
                ResourcePath = "Path",
                IsExplorerSelected = true,
                Parent = folderItem
            };
            folderItem.Children.Add(resourceItem);
            serverItem.Children.Add(folderItem);
            return serverItem;
        }
 public DeployResourcesMessage(IExplorerItemModel viewModel)
 {
     ViewModel = viewModel;
 }
        public void RenameItem(IExplorerItemModel item, string newName)
        {
            VerifyArgument.IsNotNull("item", item);
            VerifyArgument.IsNotNullOrWhitespace("newName", newName);
            Dev2Logger.Log.Info(String.Format("Rename Item Resource: {0} New name :{1} Id:{2}", item.DisplayName, newName, item.EnvironmentId));
            if(item.DisplayName == newName)
            {
                return;
            }

            var result = GetExplorerProxy(item.EnvironmentId).RenameItem(MapData(item), newName, Guid.Empty);

            if(result.Status != ExecStatus.Success)
            {
                throw new Exception(result.Message);
            }

            var explorerItemModel = FindItem(i => i.EnvironmentId == item.EnvironmentId && i.ResourceId == item.ResourceId);

            RefreshVersionHistory(item.EnvironmentId, item.ResourceId);

            if(!item.Equals(explorerItemModel))
            {
                explorerItemModel.SetDisplay(newName);
            }
        }
 static void AddChildItem(IExplorerItemModel parent, IExplorerItemModel explorerItem)
 {
     if(explorerItem != null)
     {
         if(explorerItem.ResourceId == Guid.Empty)
         {
             parent.Children.Add(explorerItem);
             parent.OnChildrenChanged();
         }
         else
          {
             var child = Instance.FindItem(i => i.ResourceId == explorerItem.ResourceId && i.Parent.ResourceId == parent.ResourceId && i.EnvironmentId == parent.EnvironmentId);
             if(child == null)
             {
                 parent.Children.Add(explorerItem);
                 parent.OnChildrenChanged();
             }
         }
     }
 }
        private void LoadItemsToTree(Guid environmentId, IExplorerItemModel explorerItemModel)
        {
            if(explorerItemModel != null)
            {
                var otherServers = ExplorerItemModels.Where(i => i.ResourceType == ResourceType.Server).ToList();
                otherServers.ForEach(i =>
                {
                    i.IsExplorerExpanded = false;
                    i.IsExplorerSelected = false;
                });

                explorerItemModel.IsExplorerSelected = explorerItemModel.IsExplorerExpanded = explorerItemModel.ResourceType == ResourceType.Server;

                explorerItemModel.EnvironmentId = environmentId;
                explorerItemModel.IsConnected = true;
                if(explorerItemModel.Children != null)
                {
                    ExplorerItemModelSetup(explorerItemModel, environmentId);
                }
                if(ExplorerItemModels.Any(a => a.EnvironmentId == environmentId))
                {
                    var index = ExplorerItemModels.IndexOf(ExplorerItemModels.FirstOrDefault(a => a.EnvironmentId == environmentId));
                    if (index >= 0)
                    {
                        explorerItemModel.IsRefreshing = ExplorerItemModels[index].IsRefreshing;
                        UpdateExplorerItemModelOnUiThread(explorerItemModel, index);
                    }
                }
                else
                {
                    var index = ExplorerItemModels.IndexOf(ExplorerItemModels.FirstOrDefault(a => a.EnvironmentId == environmentId));
                    if(index >= 0)
                    {
                        explorerItemModel.IsRefreshing = ExplorerItemModels[index].IsRefreshing;
                        UpdateExplorerItemModelOnUiThread(explorerItemModel, index);
                    }
                    else
                    {
                        Execute.OnUIThread(() =>
           {
               ExplorerItemModels.Add(explorerItemModel);
           });
                    }
                }
            }
        }
 private IExplorerItemModel DialogFilterRec(Func<IExplorerItemModel, bool> filter, IExplorerItemModel root, bool includeFolders = false)
 {
     if (filter == null)
     {
         return root;
     }
     var innerFilter = filter;
     if (includeFolders)
         innerFilter = a => filter(a) || a.ResourceType == ResourceType.Folder;
     root.Children = root.Children.Where(innerFilter).ToObservableCollection();
     foreach (var a in root.Children)
     {
         DialogFilterRec(filter, a);
     }
     return root;
 }
        private bool ContainsChild(Func<IExplorerItemModel, bool> filter, IExplorerItemModel root)
        {
            if (root.Children == null)
                return false;

            bool desc = root.Children.Any(filter);
            return desc || root.Children.Any(a => ContainsChild(filter, a));
        }
 private IExplorerItemModel FilterRec(Func<IExplorerItemModel, bool> filter, IExplorerItemModel root)
 {
     if (filter == null)
     {
         return root;
     }
     if (!ContainsChild(filter, root))
     {
         return null;
     }
     // ReSharper disable MaximumChainedReferences
     root.Children = root.Children.Where(a => FilterRec(filter, a) != null || filter(a)).ToObservableCollection();
     // ReSharper restore MaximumChainedReferences
     return root;
 }
        public void AddServerNode(IExplorerItemModel explorerItem)
        {
            var otherServers = ExplorerItemModels.Where(i => i.ResourceType == ResourceType.Server).ToList();
            otherServers.ForEach(i =>
            {
                i.IsExplorerExpanded = false;
                i.IsExplorerSelected = false;
            });

            var exists = ExplorerItemModels.FirstOrDefault(i => i.EnvironmentId == explorerItem.EnvironmentId && i.ResourceType == ResourceType.Server);
            if(exists == null)
            {
                explorerItem.IsExplorerSelected = true;
                ExplorerItemModels.Add(explorerItem);
            }
            else
            {
                exists.IsExplorerExpanded = true;
                exists.IsExplorerSelected = true;
            }
        }
예제 #52
0
 /// <summary>
 ///     The predicate used to detemine if an item should be deployed
 /// </summary>
 public bool SelectForDeployPredicate(IExplorerItemModel node)
 {
     var vm = node;
     return vm != null && vm.IsChecked.GetValueOrDefault(false) && vm.ResourceType != ResourceType.Folder && vm.ResourceType != ResourceType.Server;
 }
 public void DeleteFolder(IExplorerItemModel item)
 {
     Dev2Logger.Log.Info(String.Format("Delete Folder Resource: {0} Id:{1}", item.DisplayName, item.EnvironmentId));
     VerifyArgument.IsNotNull("item", item);
     IExplorerItemModel parentItem = item.Parent;
     if(parentItem != null)
     {
         var found = parentItem.Children.FirstOrDefault(a => a.ResourcePath == item.ResourcePath && a.ResourceType == ResourceType.Folder);
         if (found != null) item = found;
         if( parentItem.Children.Remove(item))
         {
             try
             {
                 var result = GetExplorerProxy(item.EnvironmentId).DeleteItem(MapData(item), Guid.Empty);
                 if(result.Status != ExecStatus.Success)
                 {
                     throw new Exception(result.Message);
                 }
             }
             catch(Exception)
             {
                 
                     parentItem.Children.Add(item);
                 
                 throw;
             }
           
                 parentItem.OnChildrenChanged();
             
         }
 }
 }
 private void LoadItemsToTree(Guid environmentId, IExplorerItemModel explorerItemModel, int indexToReplace)
 {
     if(explorerItemModel != null)
     {
         explorerItemModel.EnvironmentId = environmentId;
         explorerItemModel.IsConnected = true;
         if(explorerItemModel.Children != null)
         {
             ExplorerItemModelSetup(explorerItemModel, environmentId);
         }
         explorerItemModel.IsRefreshing = ExplorerItemModels[indexToReplace].IsRefreshing;
         ExplorerItemModels.RemoveAt(indexToReplace);
         ExplorerItemModels.Insert(indexToReplace, explorerItemModel);
     }
 }
        public void AddItem(IExplorerItemModel item)
        {

            VerifyArgument.IsNotNull("item", item);
            VerifyArgument.IsNotNull("parent", item.Parent);
            Dev2Logger.Log.Info(String.Format("AddItem Name: {0} Type:{1}", item.DisplayName, item.ResourceType));
            var explorerItem = MapData(item);

            if(explorerItem != null)
            {
                try
                {
                    var result = GetExplorerProxy(item.EnvironmentId).AddItem(explorerItem, item.Parent.EnvironmentId);

                    if(result.Status != ExecStatus.Success)
                    {
                        throw new Exception(result.Message);
                    }
                }
                catch(Exception)
                {
                    item.Parent.Children.Remove(item);
                    item.OnChildrenChanged();
                    throw;
                }
            }
        }
        void MoveResource(IExplorerItemModel model, string newPath)
        {
            if(model.ResourcePath == newPath +"\\"+model.DisplayName && model.ResourcePath != model.DisplayName)
            {
                return;
            }
            switch(model.ResourceType)
            {
                case ResourceType.Folder :
                    break;
                case ResourceType.Server :
                    break;
                case ResourceType.Version:
                    return;
                default :
                        model.Children = new ObservableCollection<IExplorerItemModel>();
                        break;
            }
            model.UpdateCategoryIfOpened(newPath + "\\" + model.DisplayName);
            var result = GetExplorerProxy(model.EnvironmentId).MoveItem(MapData(model), newPath, Guid.Empty);

            if(result.Status != ExecStatus.Success)
            {
                throw new Exception(result.Message);
            }
            model.Parent.RemoveChild(model);
            model.ResourcePath = newPath;
            ItemAddedMessageHandler(new ServerExplorerItem(model.DisplayName,model.ResourceId,model.ResourceType,null,model.Permissions,newPath+"\\"+model.DisplayName){ServerId = model.EnvironmentId});

            RefreshVersionHistory(model.EnvironmentId, model.ResourceId);
        }
예제 #57
0
        /// <summary>
        ///     The predicate used to detemine which resources are going to be overridden
        /// </summary>
        public bool DeploySummaryPredicateExisting(IExplorerItemModel node,
                                                   DeployNavigationViewModel targetNavViewModel)
        {
            var vm = node;
            if(vm == null || !vm.IsChecked.GetValueOrDefault(false)) return false;

            if(targetNavViewModel != null && targetNavViewModel.Environment != null)
            {
                IEnvironmentModel targetEnvironment = targetNavViewModel.Environment;
                if(targetEnvironment == null || targetEnvironment.ResourceRepository == null) return false;


                var conflictingItems = targetEnvironment.ResourceRepository.All()
                                        .Where(r => r.ID == vm.ResourceId)
                                        .Select(r => new Tuple<IResourceModel, IContextualResourceModel, IExplorerItemModel, DeployNavigationViewModel>(r, r as IContextualResourceModel, node, targetNavViewModel))
                                        .ToList();

                conflictingItems.ForEach(AddConflictingResources);

                return targetEnvironment.ResourceRepository.All()
                                        .Any(r => r.ID == vm.ResourceId);
            }
            return false;
        }
 public bool TestOnMouseDown(IExplorerItemModel treenode, int clickCount)
 {
     return OnMouseDown(treenode, clickCount);
 }
예제 #59
0
 public void RemoveChild(IExplorerItemModel child)
 {
     Children.Remove(child);
     OnChildrenChanged();
 }
        private static IExplorerItem MapData(IExplorerItemModel item)
        {
            return new ServerExplorerItem(item.DisplayName, item.ResourceId, item.ResourceType,
                                          item.Children == null
                                              ? null
                                              : item.Children.Select(MapData).ToList(),
                                          item.Permissions, item.ResourcePath);

        }