Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Refresh source control status of all parent folders
        /// </summary>
        /// <param name="folderPath"></param>
        public void RefreshParentFoldersSoucerControlStatus(string folderPath, bool pullParentFolder = false)
        {
            if (pullParentFolder)
            {
                FileAttributes attr;
                attr = File.GetAttributes(folderPath);

                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    folderPath = Directory.GetParent(folderPath).FullName;
                }
                else
                {
                    folderPath = Path.GetDirectoryName(folderPath);
                }
            }

            RepositoryFolderBase repoFolder = GetRepositoryFolderByPath(folderPath);

            if (repoFolder != null)
            {
                repoFolder.RefreshFolderSourceControlStatus();
                RefreshParentFoldersSoucerControlStatus(Directory.GetParent(folderPath).FullName);
            }
        }
Пример #4
0
        /// <summary>
        /// Save changes of exsiting Repository Item to file system
        /// </summary>
        /// <param name="repositoryItem"></param>
        public void SaveRepositoryItem(RepositoryItemBase repositoryItem)
        {
            if (String.IsNullOrEmpty(repositoryItem.ContainingFolder))
            {
                throw new Exception("Cannot save item, there is no containing folder defined - " + repositoryItem.GetType().FullName + ", " + repositoryItem.GetNameForFileName());
            }

            repositoryItem.UpdateBeforeSave();

            string txt              = RepositorySerializer.SerializeToString(repositoryItem);
            string filePath         = CreateRepositoryItemFileName(repositoryItem);
            RepositoryFolderBase rf = GetItemRepositoryFolder(repositoryItem);

            rf.SaveRepositoryItem(filePath, txt);
            repositoryItem.FileName = filePath;
            repositoryItem.FilePath = filePath;
            repositoryItem.RefreshSourceControlStatus();
            RefreshParentFoldersSoucerControlStatus(Path.GetDirectoryName(repositoryItem.FilePath));

            if (repositoryItem.DirtyStatus != Common.Enums.eDirtyStatus.NoTracked)
            {
                repositoryItem.SetDirtyStatusToNoChange();
            }
            repositoryItem.CreateBackup();
        }
Пример #5
0
        /// <summary>
        /// Delete the Repository Item from file system and removing it from cache
        /// </summary>
        /// <param name="repositoryItem"></param>
        public void DeleteRepositoryItem(RepositoryItemBase repositoryItem)
        {
            RepositoryFolderBase itemFolder = GetItemRepositoryFolder(repositoryItem);

            if (itemFolder != null)
            {
                itemFolder.DeleteRepositoryItem(repositoryItem);
            }
        }
Пример #6
0
        /// <summary>
        /// Refresh source control status of all parent folders
        /// </summary>
        /// <param name="folderPath"></param>
        public void RefreshParentFoldersSoucerControlStatus(string folderPath)
        {
            RepositoryFolderBase repoFolder = GetRepositoryFolderByPath(folderPath);

            if (repoFolder != null)
            {
                repoFolder.RefreshFolderSourceControlStatus();
                RefreshParentFoldersSoucerControlStatus(Directory.GetParent(folderPath)?.FullName);
            }
        }
Пример #7
0
        /// <summary>
        /// Get RepositoryItem by its path
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public RepositoryItemBase GetRepositoryItemByPath(string filePath)
        {
            RepositoryItemBase repoItem = null;
            ObservableList <RepositoryItemBase> repoItemList = new ObservableList <RepositoryItemBase>();
            RepositoryFolderBase repositoryFolderBase        = GetRepositoryFolderByPath(Path.GetDirectoryName(filePath));

            if (repositoryFolderBase != null)
            {
                repoItemList = repositoryFolderBase.GetFolderRepositoryItems();
            }
            repoItem = repoItemList.Where(x => Path.GetFullPath(x.FileName) == Path.GetFullPath(filePath)).FirstOrDefault();
            return(repoItem);
        }
Пример #8
0
        public void MoveItem(RepositoryItemBase repositoryItem, string targetFolder)
        {
            RepositoryFolderBase RF = GetItemRepositoryFolder(repositoryItem);


            SolutionRepositoryItemInfoBase SRII     = GetSolutionRepositoryItemInfo(repositoryItem.GetType());
            RepositoryFolderBase           rootRF   = SRII.GetItemRepositoryFolder(repositoryItem);
            RepositoryFolderBase           targetRF = rootRF.GetSubFolderByName(targetFolder);



            RF.MoveItem(repositoryItem, targetRF);
        }
Пример #9
0
        public void MoveItem(RepositoryItemBase repositoryItem, string targetFolder)
        {
            RepositoryFolderBase RF       = GetItemRepositoryFolder(repositoryItem);
            RepositoryFolderBase targetRF = GetRepositoryFolderByPath(targetFolder);

            if (RF != null && targetRF != null)
            {
                RF.DeleteRepositoryItem(repositoryItem);
                targetRF.AddRepositoryItem(repositoryItem);
            }
            else
            {
                Reporter.ToLog(eLogLevel.ERROR, string.Format("Failed to Move repository item because source or target folders failed to be identified for item '{0}' and target folder '{1}'.", repositoryItem.FilePath, targetFolder));
            }
        }
Пример #10
0
        /// <summary>
        /// Move existing shared repository item to PrevVersion folder. And remove it from cache
        /// </summary>
        /// <param name="repositoryItem"></param>
        public void MoveSharedRepositoryItemToPrevVersion(RepositoryItemBase repositoryItem)
        {
            if (repositoryItem.FileName != null && File.Exists(repositoryItem.FileName))
            {
                RepositoryFolderBase repostitoryRootFolder = GetItemRepositoryRootFolder(repositoryItem);

                string targetPath = Path.Combine(repostitoryRootFolder.FolderFullPath, "PrevVersions");
                if (!Directory.Exists(targetPath))
                {
                    repostitoryRootFolder.PauseFileWatcher();
                    //We do not want to file watcher track PrevVersions Folder. So creating it explicity using Create directory
                    Directory.CreateDirectory(targetPath);
                    repostitoryRootFolder.ResumeFileWatcher();
                }

                string dts = DateTime.Now.ToString("yyyyMMddHHmm");

                string targetFileName = repositoryItem.ItemName + "." + dts + "." + repositoryItem.ObjFileExt + ".xml";

                targetFileName = General.RemoveInvalidCharsCombinePath(targetPath, targetFileName);

                if (targetFileName.Length > 255)
                {
                    targetFileName = targetFileName.Substring(0, 250) + new Random().Next(1000).ToString();
                }

                try
                {
                    if (File.Exists(targetFileName))
                    {
                        File.Delete(targetFileName);
                    }
                    //We want to delete the item and remove it from cache. So first we copy it to destination and then delete using Repository Folder.
                    File.Copy(repositoryItem.FileName, targetFileName);
                    RepositoryFolderBase repositoryFolder = GetItemRepositoryFolder(repositoryItem);
                    repositoryFolder.DeleteRepositoryItem(repositoryItem);
                }
                catch (IOException ex)
                {
                    Reporter.ToLog(eLogLevel.ERROR, "Shared Repository moving item to PrevVersion", ex);
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Save changes of exsiting Repository Item to file system
        /// </summary>
        /// <param name="repositoryItem"></param>
        public void SaveRepositoryItem(RepositoryItemBase repositoryItem)
        {
            if (String.IsNullOrEmpty(repositoryItem.ContainingFolder))
            {
                throw new Exception("Cannot save item, there is no containing folder defined - " + repositoryItem.GetType().FullName + ", " + repositoryItem.GetNameForFileName());
            }

            repositoryItem.UpdateBeforeSave();

            string txt              = RepositorySerializer.SerializeToString(repositoryItem);
            string filePath         = CreateRepositoryItemFileName(repositoryItem);
            RepositoryFolderBase rf = GetItemRepositoryFolder(repositoryItem);

            rf.SaveRepositoryItem(filePath, txt);
            repositoryItem.FileName = filePath;
            repositoryItem.FilePath = filePath;
            //RI.isDirty = false;  //TODO: make is dirty to work
            SetDirtyStatusToNoChange(repositoryItem);
        }
Пример #12
0
        public override void MoveItem(RepositoryItemBase repositoryItem, RepositoryFolderBase targetRepositoryFolder)
        {
            // remove from current RF cache lists
            RemoveItemFromLists(repositoryItem);

            repositoryItem.RelativeFilePath = targetRepositoryFolder.FolderRelativePath;


            //move the item to target folder
            // Directory.Move(((RepositoryItemBase)nodeItemToCut).FileName, targetFileName);
            //set target folder path + file name
            //string targetFileName = CreateRepositoryItemFileName((repositoryItem), targetFolder);
            //repositoryItem.FileName = targetFileName;
            //repositoryItem.FilePath = targetFileName;

            repositoryItem.FilePath = null;
            targetRepositoryFolder.AddRepositoryItem(repositoryItem);
            // move the file in the file system
            // move the item to target cache
        }
Пример #13
0
 public override RepositoryFolderBase GetSubFolderByName(string name, bool recursive = false)
 {
     foreach (RepositoryFolder <T> RF in GetSubFolders())
     {
         if (RF.FolderRelativePath == name)
         {
             return(RF);
         }
         // Recursive scan down the tree
         if (recursive)
         {
             RepositoryFolderBase subRF = RF.GetSubFolderByName(name, true);
             if (subRF != null)
             {
                 return(subRF);
             }
         }
     }
     return(null);
 }
Пример #14
0
        /// <summary>
        /// Get the Repository Folder by its path
        /// </summary>
        /// <param name="folderPath"></param>
        /// <returns></returns>
        public RepositoryFolderBase GetRepositoryFolderByPath(string folderPath)
        {
            RepositoryFolderBase repoFolder = null;
            var inputURI = new Uri(folderPath + "\\"); // path must end with slash for isBaseOf to work correctly

            Parallel.ForEach(mSolutionRootFolders, folder =>
            {
                if (repoFolder == null)
                {
                    if (Path.GetFullPath(folderPath) == Path.GetFullPath(folder.FolderFullPath))
                    {
                        repoFolder = folder;
                    }
                    else if (new Uri(folder.FolderFullPath + "\\").IsBaseOf(inputURI))
                    {
                        string relPath = "~" + folderPath.Replace(SolutionFolder, "");
                        repoFolder     = folder.GetSubFolderByName(relPath, true);
                    }
                }
            });
            return(repoFolder);
        }
Пример #15
0
        /// <summary>
        /// Get the Repository Folder by its path
        /// </summary>
        /// <param name="folderPath"></param>
        /// <returns></returns>
        public RepositoryFolderBase GetRepositoryFolderByPath(string folderPath)
        {
            RepositoryFolderBase repoFolder = null;

            Parallel.ForEach(mSolutionRootFolders, folder =>
            {
                if (repoFolder == null)
                {
                    if (Path.GetFullPath(folderPath) == Path.GetFullPath(folder.FolderFullPath))
                    {
                        repoFolder = folder;
                    }
                    else if (Path.GetFullPath(folderPath).ToLower().Contains(Path.GetFullPath(folder.FolderFullPath).ToLower()))
                    {
                        Uri fullPath   = new Uri(folderPath, UriKind.Absolute);
                        Uri relRoot    = new Uri(SolutionFolder, UriKind.Absolute);
                        string relPath = "~\\" + Uri.UnescapeDataString(relRoot.MakeRelativeUri(fullPath).ToString().Replace("/", "\\"));
                        repoFolder     = folder.GetSubFolderByName(relPath, true);
                    }
                }
            });
            return(repoFolder);
        }
Пример #16
0
        /// <summary>
        /// Save changes of exsiting Repository Item to file system
        /// </summary>
        /// <param name="repositoryItem"></param>
        public void SaveRepositoryItem(RepositoryItemBase repositoryItem)
        {
            if (String.IsNullOrEmpty(repositoryItem.ContainingFolder))
            {
                throw new Exception("Cannot save item, there is no containing folder defined - " + repositoryItem.GetType().FullName + ", " + repositoryItem.GetNameForFileName());
            }

            repositoryItem.UpdateBeforeSave();

            string txt              = RepositorySerializer.SerializeToString(repositoryItem);
            string filePath         = CreateRepositoryItemFileName(repositoryItem);
            RepositoryFolderBase rf = GetItemRepositoryFolder(repositoryItem);

            rf.SaveRepositoryItem(filePath, txt);
            repositoryItem.FileName = filePath;
            repositoryItem.FilePath = filePath;
            //RI.isDirty = false;  //TODO: make is dirty to work
            if (repositoryItem.DirtyStatus == Common.Enums.eDirtyStatus.Modified)
            {
                repositoryItem.DirtyStatus = Common.Enums.eDirtyStatus.NoChange;
            }
            repositoryItem.OnPropertyChanged(nameof(RepositoryItemBase.SourceControlStatus));
        }
Пример #17
0
 /// <summary>
 /// Delete the Repository Item folder and it sub folders from file system and cache
 /// </summary>
 /// <param name="repositoryFolder"></param>
 public abstract void DeleteRepositoryItemFolder(RepositoryFolderBase repositoryFolder);
Пример #18
0
        /// <summary>
        /// Delete the Repository Item folder and it sub folders from file system and cache
        /// </summary>
        /// <param name="repositoryItemType"></param>
        /// <param name="folderPath"></param>
        /// <param name="recursive"></param>
        public void DeleteRepositoryItemFolder(RepositoryFolderBase repositoryFolder)
        {
            SolutionRepositoryItemInfoBase SRII = GetSolutionRepositoryItemInfo(repositoryFolder.ItemType);

            SRII.DeleteRepositoryItemFolder(repositoryFolder);
        }
Пример #19
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);
        }
Пример #20
0
 /// <summary>
 /// Move Repository item from current folder to another folder
 /// </summary>
 /// <param name="repositoryFolder"></param>
 public abstract void MoveItem(RepositoryItemBase repositoryItem, RepositoryFolderBase repositoryFolder);