Exemple #1
0
        /// <summary>
        /// Add sub folder with provided name
        /// </summary>
        /// <param name="folderName"></param>
        /// <returns></returns>
        public override RepositoryFolderBase AddSubFolder(string folderName)
        {
            string FullPath = Path.Combine(FolderFullPath, folderName);

            //add to folders cache
            string relativeFolder          = FolderRelativePath + Path.DirectorySeparatorChar + folderName;
            RepositoryFolder <T> subfolder = new RepositoryFolder <T>(SolutionRepository, mSolutionRepositoryItemInfo, ItemFilePattern, relativeFolder, ContainsRepositoryItems, null);

            PauseFileWatcher();
            //add to file system
            try
            {
                GetSubFolders();//calling it so it will find exisitng folders before adding new one
                Directory.CreateDirectory(PathHelper.GetLongPath(FullPath));
                GetSubFolders().Add(subfolder);
                subfolder.StartFileWatcher();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ResumeFileWatcher();
            }

            return(subfolder);
        }
Exemple #2
0
        /// <summary>
        /// Delete provided sub folder (recursive) and all of it items from file system and cache
        /// </summary>
        /// <param name="repositoryFolder"></param>
        /// <returns></returns>
        public bool DeleteSubFolder(RepositoryFolderBase repositoryFolder)
        {
            RepositoryFolder <T> subfolder = (RepositoryFolder <T>)repositoryFolder;

            if (subfolder != null)
            {
                //delete all sub folder inner items from file system and cache
                subfolder.DeleteFolderCacheItemsRecursive();

                //delete the folder from file system
                if (Directory.Exists(PathHelper.GetLongPath(subfolder.FolderFullPath)))
                {
                    PauseFileWatcher();
                    Directory.Delete(PathHelper.GetLongPath(subfolder.FolderFullPath), true);
                    ResumeFileWatcher();
                }
                else
                {
                    throw new Exception("Failed to delete the Folder- Path not found - " + subfolder.FolderFullPath);
                }

                //delete the folder from folders cache
                if (mSubFoldersCache != null)
                {
                    mSubFoldersCache.Remove(subfolder);
                }

                return(true);
            }

            return(false);
        }
Exemple #3
0
        private void FileWatcher_Renamed(object sender, RenamedEventArgs e)
        {
            try
            {
                // check if it is directory
                if (Directory.Exists(PathHelper.GetLongPath(e.FullPath)))
                {
                    string fn = Path.GetFileName(PathHelper.GetLongPath(e.OldFullPath));
                    RepositoryFolder <T> sf = GetSubFolder(fn);
                    sf.DisplayName        = e.Name;
                    sf.FolderRelativePath = ReplaceLastOccurrence(sf.FolderRelativePath, fn, e.Name);
                    return;
                }

                // this is single repository item
                RepositoryItemBase item = GetItemFromCacheByFileName(e.OldFullPath);
                item.FileName = e.FullPath;
                item.FilePath = e.FullPath;

                // set Folder item cache as it depends on the file name, so remove the old name and add with new name
                mFolderItemsCache.DeleteItem(e.OldFullPath);
                mFolderItemsCache[e.FullPath] = item;

                RepositoryItemBase item2 = GetItemFromCacheByFileName(e.FullPath);
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, "Exception thrown from ReposiotryFolder/FileWatcher", ex);
            }
        }
Exemple #4
0
        private void HandleDirecortyChange(FileSystemEventArgs e)
        {
            string fn = Path.GetFileName(PathHelper.GetLongPath(e.FullPath));

            switch (e.ChangeType)
            {
            case WatcherChangeTypes.Created:
                string relativeFolder          = FolderRelativePath + Path.DirectorySeparatorChar + e.Name;
                RepositoryFolder <T> subfolder = new RepositoryFolder <T>(SolutionRepository, mSolutionRepositoryItemInfo, ItemFilePattern, relativeFolder, ContainsRepositoryItems, null);
                GetSubFolders().Add(subfolder);
                break;

            case WatcherChangeTypes.Changed:
                // change happen when new file is added, for now we can ignore, as we will get also file added event
                break;

            case WatcherChangeTypes.Deleted:
                RepositoryFolder <T> sf2 = GetSubFolder(fn);
                sf2.DeleteFolderCacheItemsRecursive();

                //delete the folder from folders cache
                if (mSubFoldersCache != null)
                {
                    mSubFoldersCache.Remove(sf2);
                }

                break;
            }
            return;
        }
Exemple #5
0
        /// <summary>
        /// Recursive function to find the repositry item folder
        /// </summary>
        /// <param name="repositoryFolder"></param>
        /// <param name="folder"></param>
        /// <returns></returns>
        RepositoryFolder <T> GetRepositoryFolderParent(RepositoryFolderBase repositoryFolder, RepositoryFolder <T> folder = null)
        {
            if (folder == null)
            {
                folder = ItemRootReposiotryfolder;
            }

            foreach (RepositoryFolder <T> subfolder in folder.GetSubFolders())
            {
                if (subfolder.FolderFullPath.Trim().ToLower() == repositoryFolder.FolderFullPath.Trim().ToLower())
                {
                    return(folder);
                }
                else
                {
                    RepositoryFolder <T> sf = GetRepositoryFolderParent(repositoryFolder, subfolder);
                    if (sf != null)
                    {
                        return(sf);
                    }
                }
            }

            return(null);
        }
Exemple #6
0
        /// <summary>
        /// Recursive function to find the repositry item folder
        /// </summary>
        /// <param name="repositoryItem"></param>
        /// <param name="folder"></param>
        /// <returns></returns>
        RepositoryFolder <T> GetRepositoryFolder(RepositoryItemBase repositoryItem, RepositoryFolder <T> folder = null)
        {
            if (folder == null)
            {
                folder = ItemRootReposiotryfolder;
            }

            if (folder.FolderFullPath.Trim().ToLower() == repositoryItem.ContainingFolderFullPath.Trim().ToLower())
            {
                return(folder);
            }
            else
            {
                foreach (RepositoryFolder <T> subfolder in folder.GetSubFolders())
                {
                    if (subfolder.FolderRelativePath == repositoryItem.ContainingFolder)
                    {
                        return(subfolder);
                    }
                    else
                    {
                        RepositoryFolder <T> sf = GetRepositoryFolder(repositoryItem, subfolder);
                        if (sf != null)
                        {
                            return(sf);
                        }
                    }
                }
            }

            return(null);
        }
        private void HandleDirecortyChange(FileSystemEventArgs e)
        {
            string fn = Path.GetFileName(PathHelper.GetLongPath(e.FullPath));

            switch (e.ChangeType)
            {
            case WatcherChangeTypes.Created:
                string relativeFolder          = FolderRelativePath + Path.DirectorySeparatorChar + e.Name;
                RepositoryFolder <T> subfolder = new RepositoryFolder <T>(SolutionRepository, mSolutionRepositoryItemInfo, ItemFilePattern, relativeFolder, ContainsRepositoryItems, null);
                GetSubFolders().Add(subfolder);
                break;

            case WatcherChangeTypes.Changed:
                // change happen when new file is added, for now we can ignore, as we will get also file added event

                //if the folder is deleted(shift + del) by the user from the file system and not from Ginger
                //it comes as changed first then goes to deledted so need to stop/pause file watcher so that the folder should get deleted from the file system
                RepositoryFolder <T> repositoryFolder = GetSubFolder(fn);

                if (repositoryFolder != null)
                {
                    repositoryFolder.PauseFileWatcher();
                    if (Directory.Exists(e.FullPath))
                    {
                        repositoryFolder.ResumeFileWatcher();
                    }
                }

                break;

            case WatcherChangeTypes.Deleted:
                RepositoryFolder <T> repositoryFolder1 = GetSubFolder(fn);
                if (repositoryFolder1 != null)
                {
                    repositoryFolder1.DeleteFolderCacheItemsRecursive();

                    //delete the folder from folders cache
                    if (mSubFoldersCache != null)
                    {
                        mSubFoldersCache.Remove(repositoryFolder1);
                    }
                }

                break;
            }
            SolutionRepository.RefreshParentFoldersSoucerControlStatus(e.FullPath);
            return;
        }
Exemple #8
0
        private ObservableList <RepositoryFolder <T> > GetDirectorySubFolders(RepositoryFolder <T> Folder, bool ContainsRepositoryItems)
        {
            ObservableList <RepositoryFolder <T> > list = new ObservableList <RepositoryFolder <T> >();
            string FullPath = SolutionRepository.GetFolderFullPath(Folder.FolderRelativePath);

            string[] folders = FileSystem.GetDirectorySubFolders(FullPath);
            foreach (string subFolder in folders)
            {
                //string DisplayName = Path.GetFileName(subFolder);
                string relativePath     = Path.Combine(FolderRelativePath, Path.GetFileName(PathHelper.GetLongPath(subFolder)));
                RepositoryFolder <T> sf = new RepositoryFolder <T>(SolutionRepository, mSolutionRepositoryItemInfo, Folder.ItemFilePattern, relativePath, ContainsRepositoryItems); // Each sub folder is like it's parent type
                sf.StartFileWatcher();
                //sf.FolderFullPath = Path.Combine(FullPath, subFolder);
                list.Add(sf);
            }
            return(list);
        }
Exemple #9
0
        /// <summary>
        /// Delete the Repository Item folder and it sub folders from file system and cache
        /// </summary>
        /// <param name="repositoryFolder"></param>
        public override void DeleteRepositoryItemFolder(RepositoryFolderBase repositoryFolder)
        {
            RepositoryFolder <T> itemRepositoryParentFolder = GetRepositoryFolderParent(repositoryFolder);

            itemRepositoryParentFolder.DeleteSubFolder(repositoryFolder);
        }