Exemplo n.º 1
0
 public int GetHashCode(IExplorerTreeItem obj)
 {
     unchecked
     {
         return(((obj.ResourcePath?.GetHashCode() ?? 0) * 397) ^ obj.ResourceId.GetHashCode());
     }
 }
Exemplo n.º 2
0
        public bool ShowDialog(out DsfActivityDropViewModel dropViewModel)
        {
            dropViewModel = new DsfActivityDropViewModel(SingleEnvironmentExplorerViewModel, _activityType);
            try
            {
                var selected = SelectedResource;
                if (SelectedResource != null && selected != null)
                {
                    dropViewModel.SelectedResourceModel =
                        _server.ResourceRepository.FindSingle(c => c.ID == selected.ResourceId, true) as
                        IContextualResourceModel;
                }

                var dropWindow = CreateDialog(dropViewModel);
                dropWindow.ShowDialog();
                if (dropViewModel.DialogResult == ViewModelDialogResults.Okay)
                {
                    var model = dropViewModel;
                    SelectedResource = model.SelectedExplorerItemModel;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Dev2Logger.Error(ex.Message, GlobalConstants.WarewolfError);
            }
            SelectedResource = null;
            return(false);
        }
 public void DeleteCommand(IExplorerTreeItem parent, IExplorerRepository explorerRepository, ExplorerItemViewModel explorerItemViewModel, IPopupController popupController, IServer server)
 {
     try
     {
         if (explorerItemViewModel.IsResourceVersion)
         {
             DeleteVersionCommand(explorerRepository, explorerItemViewModel, parent, explorerItemViewModel.ResourceName);
         }
         else
         {
             var messageBoxResult = popupController.Show(popupController.GetDeleteConfirmation(explorerItemViewModel.ResourceName));
             if (server != null && messageBoxResult == MessageBoxResult.Yes)
             {
                 _shellViewModel.CloseResource(explorerItemViewModel.ResourceId, server.EnvironmentID);
                 var deletedFileMetadata = explorerRepository.Delete(explorerItemViewModel);
                 if (deletedFileMetadata.IsDeleted)
                 {
                     if (explorerItemViewModel.ResourceType == @"ServerSource" || explorerItemViewModel.IsServer)
                     {
                         server.UpdateRepository.FireServerSaved(explorerItemViewModel.ResourceId, true);
                     }
                     parent?.RemoveChild(explorerItemViewModel);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         explorerItemViewModel.ShowErrorMessage(ex.Message, @"Delete not allowed");
     }
 }
        public bool ShowDialog(out DsfActivityDropViewModel dropViewModel)
        {
            //if(SingleEnvironmentExplorerViewModel != null)
            //todo:expand

            dropViewModel = new DsfActivityDropViewModel(SingleEnvironmentExplorerViewModel, _activityType);

            var selected = SelectedResource;

            if (SelectedResource != null && selected != null)
            {
                // environmentModel.ResourceRepository.FindSingle(c => c.ID == resourceId, true) as IContextualResourceModel;
                dropViewModel.SelectedResourceModel = _server.ResourceRepository.FindSingle(c => c.ID == selected.ResourceId, true) as IContextualResourceModel;
            }
            var dropWindow = CreateDialog(dropViewModel);

            dropWindow.ShowDialog();
            if (dropViewModel.DialogResult == ViewModelDialogResults.Okay)
            {
                DsfActivityDropViewModel model = dropViewModel;
                SelectedResource = model.SelectedExplorerItemModel;
                return(true);
            }
            SelectedResource = null;
            return(false);
        }
Exemplo n.º 5
0
        public ExplorerItemViewModel CreateExplorerItemFromResource(IServer server, IExplorerTreeItem parent, bool isDialog, bool isDeploy, IContextualResourceModel explorerItem)
        {
            var itemCreated = new ExplorerItemViewModel(server, parent, a => { SelectAction(a); }, _shellViewModel, _controller)
            {
                ResourceName       = explorerItem.ResourceName,
                ResourceId         = explorerItem.ID,
                ResourceType       = explorerItem.ServerResourceType,
                ResourcePath       = explorerItem.GetSavePath(),
                AllowResourceCheck = isDeploy,
                ShowContextMenu    = !isDeploy,
                IsFolder           = false,
                IsService          = explorerItem.ResourceType == Dev2.Studio.Interfaces.Enums.ResourceType.WorkflowService,
                IsSource           = explorerItem.ResourceType == Dev2.Studio.Interfaces.Enums.ResourceType.Source,
                IsServer           = explorerItem.ResourceType == Dev2.Studio.Interfaces.Enums.ResourceType.Server
            };

            if (string.IsNullOrWhiteSpace(itemCreated.ResourcePath))
            {
                itemCreated.ResourcePath = itemCreated.ResourceName;
            }

            if (isDeploy)
            {
                itemCreated.CanExecute = false;
                itemCreated.CanView    = false;
                itemCreated.CanEdit    = false;
            }
            itemCreated.SetPermissions(explorerItem.UserPermissions, isDeploy);
            if (isDialog)
            {
                SetPropertiesForDialog(itemCreated);
            }
            return(itemCreated);
        }
Exemplo n.º 6
0
        private ExplorerItemViewModel CreateExplorerItem(IServer server, IExplorerTreeItem parent, bool isDialog, bool isDeploy, IExplorerItem explorerItem)
        {
            var itemCreated = new ExplorerItemViewModel(server, parent, a => { SelectAction(a); }, _shellViewModel, _controller)
            {
                ResourceName       = explorerItem.DisplayName,
                ResourceId         = explorerItem.ResourceId,
                ResourceType       = explorerItem.ResourceType,
                ResourcePath       = explorerItem.ResourcePath,
                AllowResourceCheck = isDeploy,
                ShowContextMenu    = !isDeploy,
                IsService          = explorerItem.IsService,
                IsFolder           = explorerItem.IsFolder,
                IsSource           = explorerItem.IsSource,
                IsServer           = explorerItem.IsServer
            };

            if (isDeploy)
            {
                itemCreated.CanExecute = false;
                itemCreated.CanView    = false;
                itemCreated.CanEdit    = false;
            }
            itemCreated.SetPermissions(explorerItem.Permissions, isDeploy);
            if (isDialog)
            {
                SetPropertiesForDialog(itemCreated);
            }
            return(itemCreated);
        }
Exemplo n.º 7
0
        public async Task <bool> Move(IExplorerItemViewModel explorerItemViewModel, IExplorerTreeItem destination)
        {
            var res = await UpdateManagerProxy.MoveItem(explorerItemViewModel.ResourceId, destination.ResourcePath, explorerItemViewModel.ResourcePath).ConfigureAwait(true);

            if (res.Status == ExecStatus.Success)
            {
                return(true);
            }
            return(false);
        }
        void Select(IExplorerTreeItem explorerTreeItem)
        {
            var explorerItemViewModels = SelectedEnvironment?.AsList();
            var item = explorerItemViewModels?.FirstOrDefault(a => a.ResourceId == explorerTreeItem.ResourceId);

            if (item != null)
            {
                item.IsSelected = true;
            }
        }
 public void TryDeleteCommand(IExplorerTreeItem parent, IExplorerRepository explorerRepository, ExplorerItemViewModel explorerItemViewModel, IPopupController popupController, IServer server)
 {
     try
     {
         DeleteIfAllowed(parent, explorerRepository, explorerItemViewModel, popupController, server);
     }
     catch (Exception ex)
     {
         explorerItemViewModel.ShowErrorMessage(ex.Message, @"Delete not allowed");
     }
 }
 void DeleteIfAllowed(IExplorerTreeItem parent, IExplorerRepository explorerRepository, ExplorerItemViewModel explorerItemViewModel, IPopupController popupController, IServer server)
 {
     if (explorerItemViewModel.IsResourceVersion)
     {
         DeleteVersionCommand(explorerRepository, explorerItemViewModel, parent, explorerItemViewModel.ResourceName);
     }
     else
     {
         DeleteCommand(parent, explorerRepository, explorerItemViewModel, popupController, server);
     }
 }
        public void RollbackCommand(IExplorerRepository explorerRepository, IExplorerTreeItem parent, Guid resourceId, string versionNumber)
        {
            var output = explorerRepository.Rollback(resourceId, versionNumber);

            parent.AreVersionsVisible = true;
            parent.ResourceName       = output.DisplayName;
            if (parent.Server != null)
            {
                _shellViewModel.CloseResource(resourceId, parent.Server.EnvironmentID);
                _shellViewModel.OpenCurrentVersion(resourceId, parent.Server.EnvironmentID);
            }
        }
Exemplo n.º 12
0
        public void DeployStatsViewerViewModel_CheckDestinationPermissions_ExplorerItemViewModel_IsNull_ShouldBeTrue()
        {
            //-------------------------Arrange----------------------------
            var mockDeployDestinationExplorerViewModel = new Mock <IDeployDestinationExplorerViewModel>();
            var mockConnectControlViewModel            = new Mock <IConnectControlViewModel>();
            var mockExplorerItemViewModel = new Mock <IExplorerItemViewModel>();
            var mockExplorerTreeItem      = new Mock <IExplorerTreeItem>();
            var mockServer         = new Mock <IServer>();
            var mockShellViewModel = new Mock <IShellViewModel>();

            mockExplorerItemViewModel.Setup(o => o.ActivityName).Returns("tesssssss");
            mockExplorerItemViewModel.Setup(o => o.ResourceType).Returns(@"not_Folder");
            mockExplorerItemViewModel.Setup(o => o.ResourcePath).Returns(@"Category\Testing");
            mockExplorerItemViewModel.Setup(o => o.ResourceId).Returns(new Guid("00000000-0000-0000-0000-000000000000"));
            mockExplorerItemViewModel.Setup(o => o.IsResourceChecked).Returns(true);
            mockExplorerItemViewModel.Setup(o => o.Server).Returns(mockServer.Object);
            mockExplorerItemViewModel.Setup(o => o.Server.CanDeployTo).Returns(true);

            mockExplorerTreeItem.Setup(a => a.ResourceId).Returns(new Guid("00000000-0000-0000-0000-000000000001"));
            mockExplorerTreeItem.Setup(a => a.Server).Returns(mockServer.Object);
            mockExplorerTreeItem.Setup(a => a.Server.CanDeployFrom).Returns(false);
            mockExplorerTreeItem.Setup(a => a.Server.CanDeployTo).Returns(false);
            mockExplorerTreeItem.Setup(a => a.CanDeploy).Returns(true);

            mockDeployDestinationExplorerViewModel.Setup(o => o.ConnectControlViewModel).Returns(mockConnectControlViewModel.Object);
            mockDeployDestinationExplorerViewModel.Setup(o => o.SelectedEnvironment).Returns(new Mock <IEnvironmentViewModel>().Object);
            mockDeployDestinationExplorerViewModel.Setup(o => o.SelectedEnvironment.IsConnected).Returns(true);
            mockDeployDestinationExplorerViewModel.Setup(o => o.SelectedEnvironment.AsList()).Returns(new List <IExplorerItemViewModel> {
                mockExplorerItemViewModel.Object
            });

            var deployStatsViewerViewModel = new DeployStatsViewerViewModel(new List <IExplorerTreeItem> {
                mockExplorerTreeItem.Object
            }, mockDeployDestinationExplorerViewModel.Object);

            //-------------------------Act--------------------------------
            deployStatsViewerViewModel.CheckDestinationPermissions();
            //-------------------------Assert-----------------------------
            mockServer.VerifyAll();
            mockShellViewModel.VerifyAll();
            mockConnectControlViewModel.VerifyAll();

            IExplorerTreeItem treeItem = mockExplorerTreeItem.Object;

            Assert.IsTrue(treeItem.CanDeploy);
            Assert.IsNull(deployStatsViewerViewModel.Status);
            Assert.IsNull(deployStatsViewerViewModel.RenameErrors);
        }
        void DeleteCommand(IExplorerTreeItem parent, IExplorerRepository explorerRepository, ExplorerItemViewModel explorerItemViewModel, IPopupController popupController, IServer server)
        {
            var messageBoxResult = popupController.Show(popupController.GetDeleteConfirmation(explorerItemViewModel.ResourceName));

            if (server != null && messageBoxResult == MessageBoxResult.Yes)
            {
                _shellViewModel.CloseResource(explorerItemViewModel.ResourceId, server.EnvironmentID);
                var deletedFileMetadata = explorerRepository.TryDelete(explorerItemViewModel);
                if (deletedFileMetadata.IsDeleted)
                {
                    if (explorerItemViewModel.ResourceType == @"ServerSource" || explorerItemViewModel.IsServer)
                    {
                        server.UpdateRepository.FireServerSaved(explorerItemViewModel.ResourceId, true);
                    }
                    parent?.RemoveChild(explorerItemViewModel);
                }
            }
        }
Exemplo n.º 14
0
 public bool Equals(IExplorerTreeItem x, IExplorerTreeItem y)
 {
     if (ReferenceEquals(x, y))
     {
         return(true);
     }
     if (ReferenceEquals(x, null))
     {
         return(false);
     }
     if (ReferenceEquals(y, null))
     {
         return(false);
     }
     if (x.GetType() != y.GetType())
     {
         return(false);
     }
     return(string.Equals(x.ResourcePath, y.ResourcePath) && x.ResourceId.Equals(y.ResourceId));
 }
Exemplo n.º 15
0
 private static bool IsSourceAndDestinationSameServer(IExplorerTreeItem currentItem, IExplorerItemViewModel explorerItemViewModel)
 {
     return(Equals(currentItem.Server, explorerItemViewModel.Server));
 }
 public TestDsfActivityDropViewModel(IExplorerViewModel explorerViewModel, enDsfActivityType dsfActivityType, object sender, IExplorerTreeItem e, IServerRepository @object)
     : base(explorerViewModel, dsfActivityType)
 {
 }
        public void DeleteVersionCommand(IExplorerRepository explorerRepository, ExplorerItemViewModel explorerItemViewModel, IExplorerTreeItem parent, string resourceName)
        {
            if (_popupController.ShowDeleteVersionMessage(resourceName) == MessageBoxResult.Yes)
            {
                explorerRepository.Delete(explorerItemViewModel);
                var parentChildren = new ObservableCollection <IExplorerItemViewModel>(parent.Children);

                var index = 0;
                for (var i = 0; i < parentChildren.Count; i++)
                {
                    if (parentChildren[i].ResourceName == resourceName)
                    {
                        index = i;
                        break;
                    }
                }

                parentChildren.RemoveAt(index);
                parent.Children = new ObservableCollection <IExplorerItemViewModel>(parentChildren);
            }
        }
        public void DeleteVersionCommand(IExplorerRepository explorerRepository, ExplorerItemViewModel explorerItemViewModel, IExplorerTreeItem parent, string resourceName)
        {
            if (_popupController.ShowDeleteVersionMessage(resourceName) == MessageBoxResult.Yes)
            {
                explorerRepository.TryDelete(explorerItemViewModel);
                var parentChildren = new ObservableCollection <IExplorerItemViewModel>(parent.Children);

                var index = 0;
                for (var i = 0; i < parentChildren.Count; i++)
                {
                    if (parentChildren[i].ResourceName == resourceName)
                    {
                        index = i;
                        break;
                    }
                }

                parentChildren.RemoveAt(index);
                parent.Children = new ObservableCollection <IExplorerItemViewModel>(parentChildren);
                if (parent.ChildrenCount == 0)
                {
                    parent.AreVersionsVisible = true;
                }
                if (parentChildren.Count == 0)
                {
                    parent.AreVersionsVisible = false;
                    parent.IsMergeVisible     = false;
                }
                _shellViewModel.UpdateExplorerWorkflowChanges(explorerItemViewModel.ResourceId);
            }
        }
Exemplo n.º 19
0
 public VersionViewModel(IServer server, IExplorerTreeItem parent, Action <IExplorerItemViewModel> selectAction, IShellViewModel shellViewModel, IPopupController popupController)
     : base(server, parent, selectAction, shellViewModel, popupController)
 {
 }
Exemplo n.º 20
0
        // ReSharper disable ParameterTypeCanBeEnumerable.Local
        public void CreateExplorerItemsSync(IList <IExplorerItem> explorerItems, IServer server, IExplorerTreeItem parent, bool isDialog = false, bool isDeploy = false)
        // ReSharper restore ParameterTypeCanBeEnumerable.Local
        {
            if (explorerItems == null)
            {
                return;
            }
            var explorerItemModels = CreateExplorerItemModels(explorerItems, server, parent, isDialog, isDeploy);

            if (parent != null)
            {
                parent.Children = explorerItemModels;
            }
            if (isDeploy)
            {
                ShowContextMenu = false;
            }
        }
Exemplo n.º 21
0
        public ObservableCollection <IExplorerItemViewModel> CreateExplorerItemModels(IEnumerable <IExplorerItem> explorerItems, IServer server, IExplorerTreeItem parent, bool isDialog, bool isDeploy)
        {
            var explorerItemModels = new ObservableCollection <IExplorerItemViewModel>();

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var explorerItem in explorerItems)
            {
                var existingItem = parent?.Children?.FirstOrDefault(model => model.ResourcePath.ToLowerInvariant() == explorerItem.ResourcePath.ToLower());
                if (existingItem != null)
                {
                    existingItem.SetPermissions(explorerItem.Permissions, isDeploy);
                    CreateExplorerItemsSync(explorerItem.Children, server, existingItem, isDialog, isDeploy);
                    explorerItemModels.Add(existingItem);
                }
                else
                {
                    var itemCreated = CreateExplorerItem(server, parent, isDialog, isDeploy, explorerItem);
                    CreateExplorerItemsSync(explorerItem.Children, server, itemCreated, isDialog, isDeploy);
                    explorerItemModels.Add(itemCreated);
                }
            }
            return(explorerItemModels);
        }
Exemplo n.º 22
0
 void SingleEnvironmentExplorerViewModel_SelectedItemChanged(object sender, IExplorerTreeItem e)
 {
     SelectedExplorerItemModel = e;
     OkCommand.RaiseCanExecuteChanged();
 }
 public TestDsfActivityDropViewModel(IExplorerViewModel explorerViewModel, enDsfActivityType dsfActivityType, object sender, IExplorerTreeItem @object) : this(explorerViewModel, dsfActivityType)
 {
     this.sender  = sender;
     this.@object = @object;
 }