public IExplorerRepositoryResult DeleteItem(IExplorerItem itemToRename, Guid workSpaceId)
 {
     var controller = CommunicationControllerFactory.CreateController("DeleteItemService");
     var serializer = new Dev2JsonSerializer();
     controller.AddPayloadArgument("itemToDelete", serializer.SerializeToBuilder(itemToRename).ToString());
     return controller.ExecuteCommand<IExplorerRepositoryResult>(Connection, workSpaceId);
 }
Example #2
0
        public override IExplorerNode Creat(object sender, IExplorerItem item_attribute)
        {
            var  pck      = sender as DataPackageCollection;
            var  pck_menu = ContextMenuFactory.Creat(item_attribute);
            Node node_pck = new Node(pck.Name)
            {
                Image = Resources.LayoutDataDrivenPagesChangeToPage16,
                Tag   = pck_menu
            };

            foreach (var pck_child in pck.Children)
            {
                VariablesFolderItem atr_pck_child = new VariablesFolderItem();
                atr_pck_child.PropertyInfo = new SimplePropertyInfo(pck_child.Name, pck_child.GetType());
                var child_menu = ContextMenuFactory.Creat(atr_pck_child) as IPackageContextMemu;
                child_menu.Package = pck_child;
                Node node_child = new Node(pck_child.Name)
                {
                    Image = Resources.FolderWithGISData16,
                    Tag   = child_menu
                };
                node_pck.Nodes.Add(node_child);
            }

            return(node_pck);
        }
Example #3
0
        void CreateChildrenForFolder(IExplorerItem explorerItem, IEnumerable <string> childNames)
        {
            var resourceType = "EmailSource";

            foreach (var name in childNames)
            {
                if (i % 2 == 0)
                {
                    resourceType = "WorkflowService";
                }
                if (i % 3 == 0)
                {
                    resourceType = "DbService";
                }
                if (i % 4 == 0)
                {
                    resourceType = "WebSource";
                }
                var mockIExplorerItem = new Mock <IExplorerItem>();
                mockIExplorerItem.Setup(item => item.ResourceType).Returns(resourceType);
                var resourceName = explorerItem.DisplayName + " " + name;
                mockIExplorerItem.Setup(item => item.DisplayName).Returns(resourceName);
                mockIExplorerItem.Setup(item => item.ResourceId).Returns(Guid.NewGuid());
                mockIExplorerItem.Setup(item => item.Parent).Returns(explorerItem);
                mockIExplorerItem.Setup(item => item.ResourcePath).Returns(explorerItem.ResourcePath + "\\" + resourceName);
                explorerItem.Children.Add(mockIExplorerItem.Object);
                i++;
            }
        }
Example #4
0
        /// <summary>
        /// Invoked when the effective property value of the Source property changes.
        /// </summary>
        /// <param name="dependencyObject">The DependencyObject on which the property has changed value.</param>
        /// <param name="dependencyPropertyChangedEventArgs">Event data that is issued by any event that tracks changes to the effective value of this property.
        /// </param>
        private static void OnSourcePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // This will disable the navigation when the source URI is changed retroactively to the page navigation.  That is, when the journal, forward button,
            // backward button change the current page, the source URI is set after the fact in order to reflect the location of the selected page.  Conversly,
            // when a breadcrumb control or tree view changes the source URI, that should be taken as an instruction to navigate to the selected page.
            ViewPage viewPage  = dependencyObject as ViewPage;
            Uri      newSource = dependencyPropertyChangedEventArgs.NewValue as Uri;

            // When the source URI has changed we need a new data context for the new source URI.  This effectively chooses the items that appear in any one of the
            // views provided by this class by selecting the IExplorerItem as the data context for the page.
            if (newSource != null)
            {
                IExplorerItem rootItem      = viewPage.DataContext as IExplorerItem;
                IExplorerItem iExplorerItem = ExplorerHelper.FindExplorerItem(rootItem, newSource);
                if (iExplorerItem != null)
                {
                    IExplorerItem       parentItem         = iExplorerItem;
                    CompositeCollection compositCollection = new CompositeCollection();
                    compositCollection.Add(new CollectionContainer()
                    {
                        Collection = parentItem as IEnumerable
                    });
                    compositCollection.Add(new CollectionContainer()
                    {
                        Collection = parentItem.Leaves
                    });
                    viewPage.listBoxView.ItemsSource = compositCollection;
                }
            }
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of a CategoryNode object.
        /// </summary>
        /// <param name="productRow"></param>
        public Product(IExplorerItem parent, DataSet.ProductRow productRow)
        {
            // Validate the parameters.
            if (productRow == null)
            {
                throw new ArgumentNullException("productRow");
            }

            // Extract the values from the record.
            base.Name   = productRow.Name;
            base.Parent = parent;

            // This will locat and disassemble the folder icon and give us the basic image sizes supported by the application framework.
            Uri uri = new Uri("/Teraque.DataModel;component/Resources/Product.ico", UriKind.Relative);
            Dictionary <ImageSize, ImageSource> images = ImageHelper.DecodeIcon(uri);

            base.SmallImageSource      = images[ImageSize.Small];
            base.MediumImageSource     = images[ImageSize.Medium];
            base.LargeImageSource      = images[ImageSize.Large];
            base.ExtraLargeImageSource = images[ImageSize.ExtraLarge];

            this.Viewer = new Uri(String.Format(@"pack://application:,,,/Teraque.LicenseBook;component/LicenseDirectory.xaml?path=\Root\Product\{0}", productRow.Name));

            foreach (DataSet.LicenseRow licenseRow in productRow.GetLicenseRows())
            {
                this.Add(new License(this, licenseRow));
            }
        }
        /// <summary>
        /// Main Window of the License Generator application.
        /// </summary>
        public MainWindow()
        {
            // The IDE generated controls are initialized here.
            this.InitializeComponent();

            // The immutable command bindings are found here.
            this.CommandBindings.Add(new CommandBinding(LicenseCommand.GenerateLicense, this.OnGenerateLicense));

            this.GenerateSeedData();

            ObservableCollection <RootCollection> root = new ObservableCollection <RootCollection>();

            root.Add(new RootCollection());
            this.DataContext = root;

            Binding itemsSourceBinding = new Binding();

            itemsSourceBinding.Source = this.DataContext;
            BindingOperations.SetBinding(this, MainWindow.ItemsSourceProperty, itemsSourceBinding);

            // This will have the effect of setting the current path to the root of the given hierarchy.
            if (this.Items.Count != 0)
            {
                IExplorerItem iExplorerItem = this.Items[0] as IExplorerItem;
                if (iExplorerItem != null)
                {
                    this.Source = ExplorerHelper.GenerateSource(iExplorerItem);
                }
            }
        }
        /// <summary>
        /// Find the item in an Explorer Hierarchy having the given path.
        /// </summary>
        /// <param name="collection">The hierarchy to be searched.</param>
        /// <param name="sourceElements">An array of path elements.</param>
        /// <param name="level">The current depth of the search.</param>
        /// <returns>The IExplorerItem in the given hierarchy that matches the given URI.</returns>
        static IExplorerItem FindExplorerItem(IExplorerItem parentItem, String[] sourceElements, Int32 level)
        {
            // This will dig into the hierarchy level by level checking the current name of the item against the path element at the same level.  When all the path
            // elements have been examined and matched, then we have a match for the given source.
            foreach (IExplorerItem childItem in parentItem.Children)
            {
                if (childItem != null && childItem.Name == sourceElements[level])
                {
                    return(level == sourceElements.Length - 1 ? childItem : FindExplorerItem(childItem, sourceElements, level + 1));
                }
            }

            // Leaves are not the same as children when it comes to the hierarchy.  Children will appear in the navigator and breadcrumb bar, leaves do not.
            // However, they are legitimate targets for a search.  Note that there is no need to recurse into a leaf item.
            foreach (IExplorerItem leafItem in parentItem.Leaves)
            {
                if (leafItem.Name == sourceElements[level])
                {
                    return(leafItem);
                }
            }

            // At this point all the given source URI was not found in the hierarchy.
            return(null);
        }
Example #8
0
        public IExplorerRepositoryResult DeleteItem(IExplorerItem itemToDelete, Guid workSpaceId)
        {
            if (itemToDelete == null)
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, ErrorResource.ItemToDeleteWasNull));
            }
            if (itemToDelete.ResourceType == "Folder")
            {
                return(DeleteFolder(itemToDelete, workSpaceId));
            }
            var result = ResourceCatalogue.DeleteResource(workSpaceId, itemToDelete.ResourceId, itemToDelete.ResourceType);

            TestCatalog.DeleteAllTests(itemToDelete.ResourceId);
            if (result.Status == ExecStatus.Success)
            {
                var itemDeleted = Find(_root, itemToDelete.ResourceId);
                if (itemDeleted != null)
                {
                    var parent = Find(_root, item => item.ResourcePath == GetSavePath(itemDeleted));
                    if (parent != null)
                    {
                        parent.Children.Remove(itemDeleted);
                    }
                    else
                    {
                        _root.Children.Remove(itemDeleted);
                    }
                }
            }
            return(new ExplorerRepositoryResult(result.Status, result.Message));
        }
 private void MoveChildren(IExplorerItem itemToMove, string newPath)
 {
     if (itemToMove == null)
     {
         return;
     }
     if (itemToMove.IsFolder)
     {
         if (!string.IsNullOrWhiteSpace(itemToMove.ResourcePath))
         {
             itemToMove.ResourcePath = newPath + "\\" + itemToMove.DisplayName;
         }
         else
         {
             itemToMove.ResourcePath = itemToMove.ResourcePath.Replace(itemToMove.ResourcePath, newPath);
         }
         if (itemToMove.Children != null && itemToMove.Children.Count > 0)
         {
             itemToMove.Children.ForEach(item => MoveChildren(item, itemToMove.ResourcePath));
         }
     }
     else
     {
         MoveSingeItem(itemToMove, newPath, GlobalConstants.ServerWorkspaceID);
     }
 }
        public IExplorerRepositoryResult RenameItem(IExplorerItem itemToRename, string newName, Guid workSpaceId)
        {
            if (itemToRename == null)
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, ErrorResource.ItemToRenameIsNull));
            }
            if (itemToRename.ResourceType == "Folder")
            {
                var oldPath    = itemToRename.ResourcePath;
                var moveResult = RenameFolder(itemToRename.ResourcePath, newName, workSpaceId);
                if (moveResult.Status != ExecStatus.Success)
                {
                    return(new ExplorerRepositoryResult(moveResult.Status, moveResult.Message));
                }
                var item = Find(i => i.ResourcePath == itemToRename.ResourcePath);
                RenameChildren(item, oldPath, newName);
                var resourcesRenameResult = RenameChildrenPaths(oldPath, newName);
                itemToRename.DisplayName = newName;
                if (resourcesRenameResult.Status != ExecStatus.Success)
                {
                    return(new ExplorerRepositoryResult(resourcesRenameResult.Status, resourcesRenameResult.Message));
                }

                return(moveResult);
            }
            itemToRename.DisplayName = newName;
            return(RenameExplorerItem(itemToRename, workSpaceId));
        }
        private IExplorerItemModel MapData(IExplorerItem item, IEnvironmentRepository environmentRepository, Guid environmentId)
        {
            if (item == null)
            {
                return(null);
            }
            string displayname = item.DisplayName;
            // ReSharper disable ImplicitlyCapturedClosure
            // ReSharper disable RedundantAssignment
            IEnvironmentModel environmentModel = environmentRepository.FindSingle(model => GetEnvironmentModel(model, item, environmentId));

            if ((item.ResourceType == ResourceType.Server && environmentId != Guid.Empty) || (environmentId == Guid.Empty && displayname.ToLower() == Environment.MachineName.ToLower()))
            {
                environmentModel = environmentRepository.FindSingle(model => GetEnvironmentModel(model, item, environmentId));
                if (environmentModel != null && environmentModel.Connection != null)
                {
                    displayname = environmentModel.DisplayName;
                }
            }

            return(new ExplorerItemModel
            {
                Children = item.Children == null ? new ObservableCollection <IExplorerItemModel>() : new ObservableCollection <IExplorerItemModel>(item.Children.Select(i => MapData(i, environmentRepository, environmentId))),
                DisplayName = displayname,
                ResourceType = item.ResourceType,
                ResourceId = item.ResourceId,
                Permissions = item.Permissions,
                ResourcePath = item.ResourcePath,
                VersionInfo = item.VersionInfo
            });
            // ReSharper restore ImplicitlyCapturedClosure
        }
Example #12
0
        public override IExplorerNode Creat(object package, IExplorerItem item_attribute)
        {
            var pck       = package as IPackage;
            var pck_menu  = ContextMenuFactory.Creat(item_attribute);
            var propinfos = pck.GetType().GetProperties();

            pck_menu.ExplorerItem = item_attribute;
            (pck_menu as IPackageContextMemu).Package = pck;

            Node pck_node = new Node(pck.Name)
            {
                Image = pck.Icon,
                Tag   = pck_menu
            };

            if (pck.State == ModelObjectState.Standby || pck.State == ModelObjectState.Error)
            {
                pck_node.Image = Resources.PkgInfo_File16;
            }
            foreach (var pr in propinfos)
            {
                var atr = pr.GetCustomAttributes(typeof(DisplayablePropertyItem), true);
                if (atr.Length > 0)
                {
                    var dp_item = atr[0] as DisplayablePropertyItem;
                    dp_item.PropertyInfo = pr;
                    var  prop_nodecreator = this.NodeFactory.Select(dp_item);
                    Node prop_node        = prop_nodecreator.Creat(pck, dp_item) as Node;
                    pck_node.Nodes.Add(prop_node);
                }
            }
            return(pck_node);
        }
Example #13
0
        public IExplorerRepositoryResult AddItem(IExplorerItem itemToAdd, Guid workSpaceId)
        {
            var controller = CommunicationControllerFactory.CreateController("AddFolderService");
            var serializer = new Dev2JsonSerializer();

            controller.AddPayloadArgument("itemToAdd", serializer.SerializeToBuilder(itemToAdd).ToString());
            return(controller.ExecuteCommand <IExplorerRepositoryResult>(Connection, workSpaceId));
        }
 public IExplorerItem Load(Guid workSpaceId, bool reload = false)
 {
     if (_root == null || reload)
     {
         _root = ExplorerItemFactory.CreateRootExplorerItem(EnvironmentVariables.GetWorkspacePath(workSpaceId), workSpaceId);
     }
     return(_root);
 }
        public IExplorerRepositoryResult AddItem(IExplorerItem itemToAdd, Guid workSpaceId)
        {
            if (itemToAdd == null)
            {
                Dev2Logger.Info("Invalid Item");
                return(new ExplorerRepositoryResult(ExecStatus.Fail, ErrorResource.ItemToAddIsNull));
            }
            var resourceType = itemToAdd.ResourceType;

            if (resourceType == "Folder")
            {
                try
                {
                    string dir = $"{DirectoryStructureFromPath(itemToAdd.ResourcePath)}\\";

                    if (Directory.Exists(dir))
                    {
                        return(new ExplorerRepositoryResult(ExecStatus.Fail, ErrorResource.RequestedFolderAlreadyExists));
                    }
                    Directory.CreateIfNotExists(dir);
                    if (itemToAdd.ResourcePath.Contains("\\"))
                    {
                        var idx          = itemToAdd.ResourcePath.LastIndexOf("\\", StringComparison.InvariantCultureIgnoreCase);
                        var pathToSearch = itemToAdd.ResourcePath.Substring(0, idx);
                        var parent       = Find(item => item.ResourcePath.ToLowerInvariant().TrimEnd('\\') == pathToSearch.ToLowerInvariant().TrimEnd('\\'));
                        parent?.Children.Add(itemToAdd);
                    }
                    else
                    {
                        _root.Children.Add(itemToAdd);
                    }
                    _sync.AddItemMessage(itemToAdd);
                    return(new ExplorerRepositoryResult(ExecStatus.Success, ""));
                }
                catch (Exception err)
                {
                    Dev2Logger.Error("Add Folder Error", err);
                    return(new ExplorerRepositoryResult(ExecStatus.Fail, err.Message));
                }
            }
            if (resourceType != null && resourceType != "Unknown" && resourceType != "ReservedService")
            {
                try
                {
                    _sync.AddItemMessage(itemToAdd);

                    return(new ExplorerRepositoryResult(ExecStatus.Success, ""));
                }
                catch (Exception err)
                {
                    Dev2Logger.Error("Add Item Error", err);
                    return(new ExplorerRepositoryResult(ExecStatus.Fail, err.Message));
                }
            }
            return(new ExplorerRepositoryResult(ExecStatus.Fail, ErrorResource.OnlyUserResourcesCanBeAdded));
        }
        public EntryViewModel(IExplorerItem entry, EntryViewModel parent)
        {
            this.entry  = entry;
            this.parent = parent;

            this.DeleteCommand     = new DelegateCommand(OnDelete);
            this.NewFolderCommand  = new DelegateCommand(OnNewFolder);
            this.NewLinkCommand    = new DelegateCommand(OnNewLink);
            this.PropertiesCommand = new DelegateCommand(OnProperties, () => false);
        }
Example #17
0
 public void AddItemMessage(IExplorerItem addedItem)
 {
     if (addedItem != null)
     {
         addedItem.ServerId = HostSecurityProvider.Instance.ServerID;
         var item = _serializer.Serialize(addedItem);
         var hubCallerConnectionContext = Clients;
         hubCallerConnectionContext.Others.ItemAddedMessage(item);
     }
 }
 private void OnRename(object sender, RoutedEventArgs e)
 {
     ExplorerItem  expItem = ((MenuItem)sender).DataContext as ExplorerItem;
     IExplorerItem item    = expItem?.Content;
     IEntry        entry   = item as IEntry;
     //if (entry != null)
     //{
     //    entry.Delete();
     //}
 }
        public IExplorerRepositoryResult AddItem(IExplorerItem itemToAdd, Guid workSpaceId)
        {
            if (itemToAdd == null)
            {
                Dev2Logger.Log.Info("Invalid Item");
                return(new ExplorerRepositoryResult(ExecStatus.Fail, "Item to add was null"));
            }
            switch (itemToAdd.ResourceType)
            {
            case ResourceType.Folder:
            {
                try
                {
                    string dir = string.Format("{0}\\", DirectoryStructureFromPath(itemToAdd.ResourcePath));

                    if (Directory.Exists(dir))
                    {
                        return(new ExplorerRepositoryResult(ExecStatus.Fail, "Requested folder already exists on server."));
                    }
                    Directory.CreateIfNotExists(dir);
                    _sync.AddItemMessage(itemToAdd);
                    return(new ExplorerRepositoryResult(ExecStatus.Success, ""));
                }
                catch (Exception err)
                {
                    Dev2Logger.Log.Error("Add Folder Error", err);
                    return(new ExplorerRepositoryResult(ExecStatus.Fail, err.Message));
                }
            }

            case ResourceType.DbSource:
            case ResourceType.EmailSource:
            case ResourceType.WebSource:
            case ResourceType.ServerSource:
            case ResourceType.PluginService:
            case ResourceType.WebService:
            case ResourceType.DbService:
            case ResourceType.WorkflowService:
            {
                try
                {
                    _sync.AddItemMessage(itemToAdd);
                    return(new ExplorerRepositoryResult(ExecStatus.Success, ""));
                }
                catch (Exception err)
                {
                    Dev2Logger.Log.Error("Add Item Error", err);
                    return(new ExplorerRepositoryResult(ExecStatus.Fail, err.Message));
                }
            }

            default:
                return(new ExplorerRepositoryResult(ExecStatus.Fail, "Only user resources can be added from this repository"));
            }
        }
Example #20
0
        public override IExplorerNode Creat(object sender, IExplorerItem item_attribute)
        {
            var mat_atr     = item_attribute as StaticVariableItem;
            var pck         = sender as IPackage;
            var folder_item = new VariablesFolderItem()
            {
                PropertyInfo = item_attribute.PropertyInfo
            };
            var folder_menu = ContextMenuFactory.Creat(folder_item);
            var value       = pck.GetType().GetProperty(item_attribute.PropertyInfo.Name).GetValue(pck);
            var dc          = value as IDataCubeObject;

            folder_menu.EneableAll(false);
            folder_menu.Enable(VariablesFolderContextMenu._AT, true);
            folder_menu.Enable(VariablesFolderContextMenu._OP, false);
            (folder_menu as IPackageContextMemu).Package = pck;

            Node node_folder = new Node(item_attribute.PropertyInfo.Name)
            {
                Image = Resources.FolderWithGISData16,
                Tag   = folder_menu
            };

            if (dc != null)
            {
                folder_item.Variables = new string[dc.Size[0]];
                for (int i = 0; i < dc.Size[0]; i++)
                {
                    StaticVariableItem item = new StaticVariableItem("")
                    {
                        VariableIndex = i,
                        VariableName  = dc.Variables[i], //string.Format("{0} {1}{2}", item_attribute.PropertyInfo.Name, mat_atr.Prefix, i + 1),
                        PropertyInfo  = item_attribute.PropertyInfo
                    };
                    folder_item.Variables[i] = item.VariableName;
                    StaticVariableContextMenu elei = new StaticVariableContextMenu()
                    {
                        Package       = pck,
                        VariableIndex = i,
                        ExplorerItem  = item
                    };
                    elei.Initialize();
                    Node ndmat = new Node(item.VariableName)
                    {
                        Image = Resources.LayerRaster_B_16,
                        Tag   = elei
                    };
                    node_folder.Nodes.Add(ndmat);
                }
            }
            else
            {
            }
            return(node_folder);
        }
Example #21
0
        private IExplorerItemViewModel CreateHierarchicalViewModel(IExplorerItem item)
        {
            var childItemViewModels = new Collection<IExplorerItemViewModel>();

            foreach (var childItem in item.ChildItems)
            {
                childItemViewModels.Add(CreateHierarchicalViewModel(childItem));
            }

            return _itemFactory.Create(item, childItemViewModels);
        }
        private void OnCreateFolder(object sender, RoutedEventArgs e)
        {
            ExplorerItem  expItem = ((MenuItem)sender).DataContext as ExplorerItem;
            IExplorerItem item    = expItem?.Content;
            IEntry        entry   = item as IEntry;

            if (entry != null)
            {
                entry.CreateFolder("NewFolder");
            }
        }
Example #23
0
        /// <summary>
        /// Opens the currently selected item in the view.
        /// </summary>
        /// <param name="sender">The object where the event handler is attached.</param>
        /// <param name="routedEventArgs">The event data.</param>
        void OnOpenItem(Object sender, RoutedEventArgs routedEventArgs)
        {
            // This will take the currently selected item, if it exists, and open it in a view.  Note that the opening isn't explicit, but is handled through a long
            // chain of binding where the application frame will be notified of a source URI change and then navigate to the new source URI.  In this manner setting
            // the source URI down here will fully integrate the new page into the browser journal, the breadcrumb bar and the navigator tree view.
            IExplorerItem iExplorerItem = this.listBoxView.SelectedItem as IExplorerItem;

            if (iExplorerItem != null)
            {
                Commands.OpenItem.Execute(iExplorerItem, null);
            }
        }
Example #24
0
        /// <summary>
        /// Find the item in an Explorer Hierarchy having the given path.
        /// </summary>
        /// <param name="collection">The hierarchy to be searched.</param>
        /// <param name="source">The URI to find.</param>
        /// <returns>The IExplorerItem in the given hierarchy that matches the given URI.</returns>
        public static IExplorerItem FindExplorerItem(IExplorerItem iExplorerItem, Uri source)
        {
            // Validate the parameters.
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            // This will split the URI into its components and look for them in the hierarchy.
            String[] sourceElements = source.OriginalString.Split(ExplorerHelper.separatorCharacter);
            return(sourceElements.Length == 1 ? null : FindExplorerItem(iExplorerItem, sourceElements, 1));
        }
Example #25
0
 void RenameChildren(IExplorerItem itemToRename, string oldPath, string newPath)
 {
     if (itemToRename == null)
     {
         return;
     }
     itemToRename.ResourcePath = !string.IsNullOrWhiteSpace(itemToRename.ResourcePath) ? itemToRename.ResourcePath.Replace(oldPath, newPath) : newPath;
     if ((itemToRename.IsFolder || itemToRename.ResourceType == "Folder") && (itemToRename.Children != null && itemToRename.Children.Count > 0))
     {
         itemToRename.Children.ForEach(item => RenameChildren(item, oldPath, newPath));
     }
 }
 public static bool GetEnvironmentModel(IEnvironmentModel model, IExplorerItem item, Guid environmentId)
 {
     if (item != null && model != null)
     {
         var found = model.ID == environmentId;
         if (found)
         {
             return(true);
         }
     }
     return(false);
 }
 public IExplorerItem Find(IExplorerItem item, Func <IExplorerItem, bool> predicate)
 {
     if (predicate(item))
     {
         return(item);
     }
     if (item.Children == null || item.Children.Count == 0)
     {
         return(null);
     }
     return(item.Children.Select(child => Find(child, predicate)).FirstOrDefault(found => found != null));
 }
Example #28
0
        public static async Task FileInfo(this IDialogService dialogService, IExplorerItem file)
        {
            KeyEventsAgregator.IsDisabled = true;

            var dialog = new FileInfoDialog(file)
            {
                Title = "Details", PrimaryButtonText = "Ok"
            };
            var result = await dialog.ShowAsync();

            KeyEventsAgregator.IsDisabled = false;
        }
        private string GetSavePath(IExplorerItem item)
        {
            var resourcePath      = item.ResourcePath;
            var savePath          = item.ResourcePath;
            var resourceNameIndex = resourcePath.LastIndexOf(item.DisplayName, StringComparison.InvariantCultureIgnoreCase);

            if (resourceNameIndex >= 0)
            {
                savePath = resourcePath.Substring(0, resourceNameIndex);
            }
            return(savePath.TrimEnd('\\'));
        }
 public IExplorerItem Find(IExplorerItem item, Guid itemToFind)
 {
     if (item.ResourceId == itemToFind)
     {
         return(item);
     }
     if (item.Children == null || item.Children.Count == 0)
     {
         return(null);
     }
     return(item.Children.Select(child => Find(child, itemToFind)).FirstOrDefault(found => found != null));
 }
Example #31
0
        public IExplorerNodeCreator Select(IExplorerItem item)
        {
            var creator = from cc in Creators where cc.ItemType == item.GetType() select cc;

            if (creator.Count() > 0)
            {
                return(creator.First());
            }
            else
            {
                return(null);
            }
        }
Example #32
0
        /// <summary>
        /// Determines the proper image for the control based on how much room there is to display an icon.
        /// </summary>
        void SetImage()
        {
            // Select the image based on how much space is available.  Small Icons look terrible when they are magnified and large icons look terrible when they are
            // compressed.  This algorithm chooses the best looking image given how large it will be in the detail bar.
            IExplorerItem iExplorerItem = this.DataContext as IExplorerItem;

            if (iExplorerItem != null)
            {
                this.SetValue(
                    DetailBar.iconPropertyKey,
                    this.ActualHeight > DetailBar.minLargeImageHeight ? iExplorerItem.ExtraLargeImageSource : iExplorerItem.LargeImageSource);
            }
        }
 public IExplorerRepositoryResult RenameItem(IExplorerItem itemToRename, string newName, Guid workSpaceId)
 {
     var controller = CommunicationControllerFactory.CreateController("RenameItemService");
     if(itemToRename.Children != null)
     {
         var any = itemToRename.Children.Where(a => a.ResourceType == ResourceType.Version);
         itemToRename.Children = itemToRename.Children.Except(any).ToList();
     }
     var serializer = new Dev2JsonSerializer();
     controller.AddPayloadArgument("itemToRename", serializer.SerializeToBuilder(itemToRename).ToString());
     controller.AddPayloadArgument("newName", newName);
     return controller.ExecuteCommand<IExplorerRepositoryResult>(Connection, workSpaceId);
 }
        internal StudioResourceRepository(IExplorerItem explorerItem, Guid environmentId, Action<System.Action, DispatcherPriority> invoke)
        {
            ExplorerItemModelClone = a => a.Clone();
            ExplorerItemModels = new ObservableCollection<IExplorerItemModel>();
            _invoke = invoke;

            if(explorerItem != null)
            {
                var environmentRepository = GetEnvironmentRepository();
                var explorerItems = MapData(explorerItem, environmentRepository, environmentId);
                LoadItemsToTree(environmentId, explorerItems);
            }
            Instance = this;
        }
 public IExplorerRepositoryResult RenameItem(IExplorerItem itemToRename, string newName, Guid workSpaceId)
 {
     if(itemToRename == null)
     {
         return new ExplorerRepositoryResult(ExecStatus.Fail, "Item to rename was null");
     }
     switch(itemToRename.ResourceType)
     {
         case ResourceType.Folder:
             return RenameFolder(itemToRename.ResourcePath, newName, workSpaceId);
         default:
             {
                 itemToRename.DisplayName = newName;
                 return RenameExplorerItem(itemToRename, workSpaceId);
             }
     }
 }
Example #36
0
        private void AddChildren(IExplorerItem rootNode, IEnumerable<IResource> resourceList, ResourceType type)
        {
            // ReSharper disable PossibleMultipleEnumeration

            var children = resourceList.Where(a => GetResourceParent(a.ResourcePath) == rootNode.ResourcePath && a.ResourceType == type);
            // ReSharper restore PossibleMultipleEnumeration
            foreach(var node in rootNode.Children)
            {
                // ReSharper disable PossibleMultipleEnumeration
                AddChildren(node, resourceList, type);
                // ReSharper restore PossibleMultipleEnumeration
            }
            foreach(var resource in children)
            {
                var childNode = CreateResourceItem(resource);
                rootNode.Children.Add(childNode);
            }
        }
Example #37
0
 private void AddChildren(IExplorerItem rootNode, IEnumerable<IResource> resourceList)
 {
     // ReSharper disable PossibleMultipleEnumeration
     var children = resourceList.Where(a => GetResourceParent(a.ResourcePath).Equals(rootNode.ResourcePath, StringComparison.InvariantCultureIgnoreCase));
     // ReSharper restore PossibleMultipleEnumeration
     foreach(var node in rootNode.Children)
     {
         // ReSharper disable PossibleMultipleEnumeration
         AddChildren(node, resourceList);
         // ReSharper restore PossibleMultipleEnumeration
     }
     foreach(var resource in children)
     {
         if(resource.ResourceType == ResourceType.ReservedService)
         {
             continue;
         }
         var childNode = CreateResourceItem(resource);
         rootNode.Children.Add(childNode);
     }
 }
        IExplorerRepositoryResult RenameExplorerItem(IExplorerItem itemToRename, Guid workSpaceId)
        {

            IEnumerable<IResource> item =
                ResourceCatalogue.GetResourceList(workSpaceId)
                                 .Where(
                                     a =>
                                     (a.ResourceName == itemToRename.DisplayName.Trim()) &&
                                     (a.ResourcePath == itemToRename.ResourcePath.Trim()));
            if(item.Any())
            {
                return new ExplorerRepositoryResult(ExecStatus.Fail, "There is an item that exists with the same name and path");
            }
            ResourceCatalogResult result = ResourceCatalogue.RenameResource(workSpaceId, itemToRename.ResourceId, itemToRename.DisplayName);
            return new ExplorerRepositoryResult(result.Status, result.Message);
        }
 void MoveVersions(IExplorerItem itemToMove,string newPath)
 {
   VersionRepository.MoveVersions(itemToMove.ResourceId,newPath);
 }
        public IExplorerRepositoryResult MoveItem(IExplorerItem itemToMove, string newPath, Guid workSpaceId)
        {

            IEnumerable<IResource> item =
                ResourceCatalogue.GetResourceList(workSpaceId)
                                 .Where(
                                     a =>
                                     (a.ResourcePath == newPath));
            if (item.Any())
            {
                return new ExplorerRepositoryResult(ExecStatus.Fail, "There is an item that exists with the same name and path");
            }
            MoveVersions(itemToMove, newPath);
            ResourceCatalogResult result = ResourceCatalogue.RenameCategory(workSpaceId,itemToMove.ResourcePath , newPath,new List<IResource>{ResourceCatalogue.GetResource(workSpaceId,itemToMove.ResourceId)});
            _file.Delete(string.Format("{0}.xml", DirectoryStructureFromPath(itemToMove.ResourcePath)));
            
            return new ExplorerRepositoryResult(result.Status, result.Message);
        }
        public IExplorerRepositoryResult AddItem(IExplorerItem itemToAdd, Guid workSpaceId)
        {
            if(itemToAdd == null)
            {
                Dev2Logger.Log.Info("Invalid Item");
                return new ExplorerRepositoryResult(ExecStatus.Fail, "Item to add was null");
            }
            switch(itemToAdd.ResourceType)
            {
                case ResourceType.Folder:
                    {
                        try
                        {
                            string dir = string.Format("{0}\\", DirectoryStructureFromPath(itemToAdd.ResourcePath));

                            if(Directory.Exists(dir))
                            {
                                return new ExplorerRepositoryResult(ExecStatus.Fail, "Requested folder already exists on server.");
                            }
                            Directory.CreateIfNotExists(dir);
                            _sync.AddItemMessage(itemToAdd);
                            return new ExplorerRepositoryResult(ExecStatus.Success, "");
                        }
                        catch(Exception err)
                        {
                            Dev2Logger.Log.Error("Add Folder Error",err);
                            return new ExplorerRepositoryResult(ExecStatus.Fail, err.Message);
                        }
                    }
                case ResourceType.DbSource:
                case ResourceType.EmailSource:
                case ResourceType.WebSource:
                case ResourceType.ServerSource:
                case ResourceType.PluginService:
                case ResourceType.WebService:
                case ResourceType.DbService:
                case ResourceType.WorkflowService:
                    {
                        try
                        {
                            _sync.AddItemMessage(itemToAdd);
                            return new ExplorerRepositoryResult(ExecStatus.Success, "");
                        }
                        catch(Exception err)
                        {
                            Dev2Logger.Log.Error("Add Item Error", err);
                            return new ExplorerRepositoryResult(ExecStatus.Fail, err.Message);
                        }
                    }
                default:
                    return new ExplorerRepositoryResult(ExecStatus.Fail, "Only user resources can be added from this repository");
            }
        }
 public IExplorerRepositoryResult DeleteItem(IExplorerItem itemToDelete, Guid workSpaceId)
 {
     if(itemToDelete == null)
     {
         return new ExplorerRepositoryResult(ExecStatus.Fail, "Item to delete was null");
     }
     switch(itemToDelete.ResourceType)
     {
         case ResourceType.Folder:
             {
                 return DeleteFolder(itemToDelete.ResourcePath, true, workSpaceId);
             }
         default:
             ResourceCatalogResult result = ResourceCatalogue.DeleteResource(workSpaceId, itemToDelete.DisplayName, itemToDelete.ResourceType.ToString());
             return new ExplorerRepositoryResult(result.Status, result.Message);
     }
 }
Example #43
0
        private IExplorerItem BuildStructureFromFilePathRoot(IDirectory directory, string path, IExplorerItem root)
        {

            root.Children = BuildStructureFromFilePath(directory, path, path);
            return root;
        }
        public void ItemAddedMessageHandler(IExplorerItem item)
        {
            var environmentId = item.ServerId;
            var explorerItem = MapData(item, GetEnvironmentRepository(), environmentId);
            var resourcePath = item.ResourcePath.Replace("\\\\", "\\");

            if(!String.IsNullOrEmpty(resourcePath))
            {
                resourcePath = resourcePath.Equals(item.DisplayName) ? "" : resourcePath.Substring(0, resourcePath.LastIndexOf("\\" + item.DisplayName, StringComparison.Ordinal));
            }

            // ReSharper disable ImplicitlyCapturedClosure
            var parent = FindItem(model => model.ResourcePath != null && model.ResourcePath.Equals(resourcePath) && model.EnvironmentId == environmentId);
            var alreadyAdded = FindItem(model =>  model.ResourcePath == item.ResourcePath && model.EnvironmentId == environmentId) != null;
            // ReSharper restore ImplicitlyCapturedClosure
            var environmentModel = EnvironmentRepository.Instance.Get(environmentId);
            var resourceRepository = environmentModel.ResourceRepository;
            // ReSharper disable ImplicitlyCapturedClosure
            var resourceModel = resourceRepository.FindSingle(model => model.ID == item.ResourceId);
            // ReSharper restore ImplicitlyCapturedClosure
            if(resourceModel == null && item.ResourceType != ResourceType.Folder)
            {
                if(item.ResourceType == ResourceType.ServerSource)
                {
                    resourceRepository.ReloadResource(item.ResourceId, Studio.Core.AppResources.Enums.ResourceType.Source, ResourceModelEqualityComparer.Current, true);
                }
                else if(item.ResourceType >= ResourceType.DbSource)
                {
                    resourceRepository.ReloadResource(item.ResourceId, Studio.Core.AppResources.Enums.ResourceType.Source, ResourceModelEqualityComparer.Current, true);
                }
                else if(item.ResourceType >= ResourceType.DbService && item.ResourceType < ResourceType.DbSource )
                {
                    resourceRepository.ReloadResource(item.ResourceId, Studio.Core.AppResources.Enums.ResourceType.Service, ResourceModelEqualityComparer.Current, true);
                }
                else if(item.ResourceType == ResourceType.WorkflowService)
                {
                    resourceRepository.ReloadResource(item.ResourceId, Studio.Core.AppResources.Enums.ResourceType.WorkflowService, ResourceModelEqualityComparer.Current, true);
                }
            }
            else
            {
                lock(_syncRoot)
                {
                    if(parent != null && !alreadyAdded )
                    {
                        explorerItem.EnvironmentId = parent.EnvironmentId;
                        explorerItem.Parent = parent;
                        if(parent.Children == null)
                        {
                            parent.Children = new ObservableCollection<IExplorerItemModel>();
                        }
                        if(_currentDispatcher == null)
                        {
                            AddChildItem(parent, explorerItem);
                        }
                        else
                        {
                            PerformUpdateOnDispatcher(() => AddChildItem(parent, explorerItem));

                        }
                    }
                }
            }
        }
 public JsonTreeNode(IExplorerItem explorerItem)
 {
     if(explorerItem.ResourceType == ResourceType.Server)
     {
         title = "Root";
         key = "root";
     }
     else
     {
         title = explorerItem.DisplayName;
         string name = Regex.Replace(explorerItem.ResourcePath.Replace(EnvironmentVariables.ApplicationPath + "\\", ""), @"\\", @"\\");
         key = name;
     }
     isFolder = true;
     isLazy = false;
     children = new List<JsonTreeNode>();
     foreach(var child in explorerItem.Children)
     {
         children.Add(new JsonTreeNode(child));
     }
 }
        private IExplorerItemModel MapData(IExplorerItem item, IEnvironmentRepository environmentRepository, Guid environmentId)
        {
            if(item == null)
            {
                return null;
            }
            string displayname = item.DisplayName;
            // ReSharper disable ImplicitlyCapturedClosure
            // ReSharper disable RedundantAssignment
            IEnvironmentModel environmentModel = environmentRepository.FindSingle(model => GetEnvironmentModel(model, item, environmentId));
            if((item.ResourceType == ResourceType.Server && environmentId != Guid.Empty) || (environmentId == Guid.Empty && displayname.ToLower() == Environment.MachineName.ToLower()))
            {
                environmentModel = environmentRepository.FindSingle(model => GetEnvironmentModel(model, item, environmentId));
                if(environmentModel != null && environmentModel.Connection != null)
                {
                    displayname = environmentModel.DisplayName;
                }
            }

            return new ExplorerItemModel
            {
                Children = item.Children == null ? new ObservableCollection<IExplorerItemModel>() : new ObservableCollection<IExplorerItemModel>(item.Children.Select(i => MapData(i, environmentRepository, environmentId))),
                DisplayName = displayname,
                ResourceType = item.ResourceType,
                ResourceId = item.ResourceId,
                Permissions = item.Permissions,
                ResourcePath = item.ResourcePath,
                VersionInfo = item.VersionInfo
            };
            // ReSharper restore ImplicitlyCapturedClosure
        }
 public static bool GetEnvironmentModel(IEnvironmentModel model, IExplorerItem item, Guid environmentId)
 {
     if(item != null && model != null)
     {
         var found = model.ID == environmentId;
         if(found)
         {
             return true;
         }
     }
     return false;
 }
Example #48
0
 public void AddExplorerItem(IExplorerItem item)
 {
     _explorerViewModel.ExplorerItemViewModels.Add(CreateHierarchicalViewModel(item));
 }
Example #49
0
 public IExplorerItemViewModel Create(IExplorerItem explorerItem, IEnumerable<IExplorerItemViewModel> childItemViewModels)
 {
     return new ExplorerItemViewModel(explorerItem, childItemViewModels);
 }
 public ExplorerItemViewModel(IExplorerItem explorerItem, IEnumerable<IExplorerItemViewModel> childItems)
     : this(explorerItem)
 {
     ChildItems = childItems;
 }
 public ExplorerItemViewModel(IExplorerItem explorerItem)
 {
     Name = explorerItem.Name;
     Action = explorerItem.Action;
     _canExecute = () => true;
 }