Exemplo n.º 1
0
        // 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)); ??
        }
Exemplo n.º 2
0
        // 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)); ??
        }
Exemplo n.º 3
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);
        }