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; } SolutionRepository.RefreshParentFoldersSoucerControlStatus(e.FullPath); return; }
private void HandleFileChange(FileSystemEventArgs e) { if (IsRepositoryFile(e.FullPath)) { RepositoryItemBase item = null; switch (e.ChangeType) { case WatcherChangeTypes.Changed: WaitforFileIsReadable(e.FullPath); // reLoad the object to mem updating fields item = GetItemFromCacheByFileName(e.FullPath); NewRepositorySerializer.ReloadObjectFromFile(item); item.RefreshSourceControlStatus(); break; case WatcherChangeTypes.Deleted: //remove from cache and list item = GetItemFromCacheByFileName(e.FullPath); RemoveItemFromLists(item); break; case WatcherChangeTypes.Created: WaitforFileIsReadable(e.FullPath); // add item to cache and list T newItem = LoadItemfromFile <T>(e.FullPath, Path.GetDirectoryName(e.FullPath)); AddItemtoCache(e.FullPath, newItem); mFolderItemsList.Add(newItem); break; } } SolutionRepository.RefreshParentFoldersSoucerControlStatus(Path.GetDirectoryName(e.FullPath)); }
// Generic handling for any RI type // This is recursive function which run in parallel for extreme speed, be carefull! private ObservableList <T> LoadFolderFiles <T>(string Folder = null) { // for each file we check if in cache return from cache else load from file system and cache the item string FullPath = SolutionRepository.GetFolderFullPath(Folder); if (FullPath == null || !Directory.Exists(PathHelper.GetLongPath(FullPath))) { throw new Exception("LoadFolderFiles: Invalid folder - " + Folder); } // TODO: move from here to better place string ContainingFolder = Folder.Replace(SolutionRepository.SolutionFolder, SolutionRepository.cSolutionRootFolderSign); ConcurrentBag <T> list = new ConcurrentBag <T>(); // Thread safe list string[] fileEntries = FileSystem.GetDirectoryFiles(FullPath, mSolutionRepositoryItemInfo.Pattern); Parallel.ForEach(fileEntries, FileName => { // Check if item exist in cache if yes use it, no need to load from file, yay! T item = (T)mFolderItemsCache[FileName]; if (item == null) { item = LoadItemfromFile <T>(FileName, ContainingFolder); AddItemtoCache(FileName, item); } list.Add(item); }); return(new ObservableList <T>(list)); //TODO: order by name .OrderBy(x => ((RepositoryItem)x).FilePath)); ?? }
public RepositoryFolder(SolutionRepository SolutionRepository, SolutionRepositoryItemInfo <T> solutionRepositoryItemInfo, string pattern, string FolderRelativePath, bool ContainsRepositoryItems = true, string DisplayName = null, bool isRootFolder = false) { this.SolutionRepository = SolutionRepository; mSolutionRepositoryItemInfo = solutionRepositoryItemInfo; this.FolderRelativePath = FolderRelativePath; //this.FolderFullPath = SolutionRepository.GetFolderFullPath(FolderRelativePath); this.DisplayName = DisplayName; this.ContainsRepositoryItems = ContainsRepositoryItems; this.ItemFilePattern = pattern; base.ItemType = typeof(T); IsRootFolder = isRootFolder; }
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; }
// Generic handling for any RI type // This is recursive function which run in parallel for extreme speed, be careful! private ObservableList <T> LoadFolderFiles(string Folder = null) { // for each file we check if in cache return from cache else load from file system and cache the item string FullPath = SolutionRepository.GetFolderFullPath(Folder); if (FullPath == null || !Directory.Exists(PathHelper.GetLongPath(FullPath))) { Reporter.ToLog(eLogLevel.ERROR, "RepositoryFolder/LoadFolderFiles- Invalid folder: " + Folder); return(null); } // TODO: move from here to better place string ContainingFolder = Folder.Replace(SolutionRepository.SolutionFolder, SolutionRepository.cSolutionRootFolderSign); ConcurrentBag <T> list = new ConcurrentBag <T>(); // Thread safe list string[] fileEntries = FileSystem.GetDirectoryFiles(FullPath, mSolutionRepositoryItemInfo.Pattern); Parallel.ForEach(fileEntries, FileName => { try { // Check if item exist in cache if yes use it, no need to load from file, yay! T item = (T)mFolderItemsCache[FileName]; if (item == null) { item = LoadItemfromFile(FileName, ContainingFolder); AddItemtoCache(FileName, item); } list.Add(item); } catch (Exception ex) { string error = string.Format("RepositoryFolder/LoadFolderFiles- Failed to load the Repository Item XML which in file: '{0}'.", FileName); if (Assembly.GetEntryAssembly().GetName().ToString().Contains("GingerRuntime") && ex.Message.Contains("Unable to create object for the class type")) { Reporter.ToLog(eLogLevel.DEBUG, error, ex); } else { Reporter.ToLog(eLogLevel.ERROR, error, ex); } } }); return(new ObservableList <T>(list)); //TODO: order by name .OrderBy(x => ((RepositoryItem)x).FilePath)); ?? }
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); }
/// <summary> /// Save the Repository Item to folder and add it to cache /// </summary> /// <param name="repositoryItem"></param> public override void AddRepositoryItem(RepositoryItemBase repositoryItem) { //save it repositoryItem.ContainingFolder = FolderRelativePath; repositoryItem.ContainingFolderFullPath = FolderFullPath; SolutionRepository.SaveNewRepositoryItem(repositoryItem); //add it to folder cache mFolderItemsCache[repositoryItem.FilePath] = repositoryItem; if (mFolderItemsList != null) { mFolderItemsList.Add((T)(object)repositoryItem); } //add it to general item cache if (!mSolutionRepositoryItemInfo.AllItemsCacheIsNull()) { mSolutionRepositoryItemInfo.AddItemToCache((T)(object)repositoryItem); } }
public void SolutionChanged(SolutionRepository solutionRepository) { mSolutionRepository = solutionRepository; //download missing plugins GetPackages(); if (mPluginPackages != null && mPluginPackages.Count > 0) { if (WorkSpace.Instance.RunningInExecutionMode) { DownloadMissingPlugins(); //need to download it before execution starts } else { Task.Run(() => { DownloadMissingPlugins(); //downloading the plugins async }); } } }
public PluginsManager(SolutionRepository solutionRepository) { mSolutionRepository = solutionRepository; GetPackages(); }
public void SolutionChanged(SolutionRepository solutionRepository) { mSolutionRepository = solutionRepository; GetPackages(); }
public void Init(SolutionRepository solutionRepository) { mSolutionRepository = solutionRepository; GetPackages(); }
public PluginsManager(SolutionRepository solutionRepository) { mSolutionRepository = solutionRepository; mPluginPackages = solutionRepository.GetAllRepositoryItems <PluginPackage>(); }