/// <summary> /// This method can be used to "track" files count and currentPaths using threaded lists while iterating thourg big directory. /// </summary> /// <param name="files"></param> /// <param name="paths"></param> /// <param name="fileSearchPattern"></param> /// <param name="directorySearchPattern"></param> /// <param name="includeSubdirectories"></param> /// <returns>Item1: file list, Item 2: directory list</returns> public static Tuple <string[], string[]> TryGetFilesAndDirectories(ThreadedList <string> files, ThreadedList <string> paths, string fileSearchPattern = "*", string directorySearchPattern = "*", bool includeSubdirectories = true, ThreadedList <string> currentPaths = null) { if (files == null || paths == null) { throw new ArgumentNullException("Files and paths can't be null."); } if (paths.Count == 0) { return(new Tuple <string[], string[]>(files.ToArray(), new string[0])); } var _paths = paths.ToArray(); ThreadedList <string> subPaths = new ThreadedList <string>(); if (!_paths.IsNullOrEmpty()) { Parallel.ForEach(_paths, (path) => { if (path.IsNullOrEmpty()) { return; } try { subPaths.AddRange(Directory.GetDirectories(path, directorySearchPattern, SearchOption.TopDirectoryOnly)); } catch { } try { files.AddRange(Directory.GetFiles(path, fileSearchPattern, SearchOption.TopDirectoryOnly).ToList()); } catch { } }); } currentPaths?.AddRange(subPaths); if (includeSubdirectories) { paths.AddRange(TryGetFilesAndDirectories(files, subPaths.Clone(), fileSearchPattern, directorySearchPattern, true, currentPaths).Item2); } else { paths.AddRange(subPaths); } return(new Tuple <string[], string[]>(files.ToArray(), paths.ToArray())); }
public static string[] TryGetFiles(string path, string directorySearchPattern = "*", string fileSearchPattern = "*.*", bool includeSubdirectories = true) { var directories = TryGetDirectories(path, directorySearchPattern, includeSubdirectories); ThreadedList <string> files = new ThreadedList <string>(); Parallel.ForEach(directories, (directory) => { if (!path.IsNullOrEmpty()) { try { files.AddRange(Directory.GetFiles(directory, fileSearchPattern, SearchOption.TopDirectoryOnly).ToList()); } catch { } } }); return(files.ToArray()); }
public static string[] TryGetDirectories(ThreadedList <string> paths, string searchPattern = "*", bool includeSubdirectories = true) { if (paths.IsNullOrEmpty()) { return(new string[0]); } var _paths = paths.ToArray(); ThreadedList <string> subPaths = new ThreadedList <string>(); if (!_paths.IsNullOrEmpty()) { Parallel.ForEach(_paths, (path) => { if (!path.IsNullOrEmpty()) { try { subPaths.AddRange(Directory.GetDirectories(path, searchPattern, SearchOption.TopDirectoryOnly)); } catch { } } }); } if (includeSubdirectories) { paths.AddRange(TryGetDirectories(subPaths.Clone(), searchPattern, true)); } else { paths.AddRange(subPaths); } return(paths.ToArray()); }
private void RefreshStructure() { PlanStructure.BeginUpdate(); // save selected PlanNode selected = GetSelected(); // save visible while unloading List <ulong> visible = new List <ulong>(); foreach (TreeListNode node in PlanStructure.Nodes) { if (node.GetType() == typeof(PlanNode)) { UnloadNode((PlanNode)node, visible); } } NodeMap.Clear(); PlanStructure.Nodes.Clear(); // nodes ThreadedList <OpLink> roots = null; if (Trust.ProjectRoots.SafeTryGetValue(ProjectID, out roots)) { roots.LockReading(delegate() { foreach (OpLink root in roots) { if (Uplinks.Contains(root.UserID)) { PlanNode node = CreateNode(root); Plans.Research(root.UserID); LoadNode(node); GuiUtils.InsertSubNode(PlanStructure.virtualParent, node); ExpandPath(node, Uplinks); } if (root.IsLoopRoot && root.Downlinks.Count > 0 && Uplinks.Contains(root.Downlinks[0].UserID)) { foreach (OpLink downlink in root.Downlinks) { if (!root.IsLoopedTo(downlink)) { PlanNode node = CreateNode(downlink); Plans.Research(downlink.UserID); LoadNode(node); GuiUtils.InsertSubNode(PlanStructure.virtualParent, node); ExpandPath(node, Uplinks); } } } } }); } // restore visible foreach (ulong id in visible) { foreach (TreeListNode node in PlanStructure.Nodes) { if (node.GetType() == typeof(PlanNode)) { List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, ProjectID); uplinks.Add(id); VisiblePath((PlanNode)node, uplinks); } } } // restore selected if (selected != null) { if (NodeMap.ContainsKey(selected.Link.UserID)) { PlanStructure.Select(NodeMap[selected.Link.UserID]); } } PlanStructure.EndUpdate(); }
public uint CreateProject(string name) { uint id = (uint)Core.RndGen.Next(); ProjectNames.SafeAdd(id, name); LocalTrust.AddProject(id, true); ThreadedList<OpLink> roots = new ThreadedList<OpLink>(); roots.SafeAdd(LocalTrust.GetLink(id)); ProjectRoots.SafeAdd(id, roots); SaveLocal(); return id; }
private void AddRoot(OpLink link) { ThreadedList<OpLink> roots = null; if (!ProjectRoots.SafeTryGetValue(link.Project, out roots)) { roots = new ThreadedList<OpLink>(); ProjectRoots.SafeAdd(link.Project, roots); } if (!roots.SafeContains(link)) // possible it wasnt removed above because link might not be part of project locally but others think it does (uplink) roots.SafeAdd(link); }
public FundingsManager() { Fundings = new ThreadedList <Fundings>(); }
private void RefreshOperationTree() { BeginUpdate(); // save selected LinkNode selected = GetSelected(); // save visible while unloading List <ulong> visible = new List <ulong>(); foreach (TreeListNode node in Nodes) { if (node.GetType() == typeof(LinkNode)) { UnloadNode((LinkNode)node, visible); } } NodeMap.Clear(); Nodes.Clear(); // white space if (FirstLineBlank) { Nodes.Add(new LabelNode("")); } if (!Trust.ProjectRoots.SafeContainsKey(Project)) { EndUpdate(); return; } string rootname = Core.User.Settings.Operation; if (Project != 0) { rootname = Trust.GetProjectName(Project); } // operation ProjectNode = new ProjectNode(rootname, Project); ProjectNode.Font = TrustedFont; Nodes.Add(ProjectNode); // white space Nodes.Add(new LabelNode("")); // unlinked UnlinkedNode = new ProjectNode("Untrusted", 0); UnlinkedNode.Font = UntrustedFont; Nodes.Add(UnlinkedNode); // if forced, load specific node as root if (ForceRootID != 0) { OpLink root = Trust.GetLink(ForceRootID, Project); if (root != null) { SetupRoot(root); } } // get roots for specific project else { ThreadedList <OpLink> roots = null; if (Trust.ProjectRoots.SafeTryGetValue(Project, out roots)) { roots.LockReading(delegate() { foreach (OpLink root in roots) { SetupRoot(root); } }); } } // show unlinked if there's something to show if (Nodes.IndexOf(UnlinkedNode) + 1 == Nodes.Count) { UnlinkedNode.Text = ""; } else { UnlinkedNode.Text = "Untrusted"; } // restore visible foreach (ulong id in visible) { foreach (TreeListNode node in Nodes) { if (node.GetType() == typeof(LinkNode)) { List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, Project); uplinks.Add(id); VisiblePath((LinkNode)node, uplinks); } } } // restore selected if (selected != null) { if (NodeMap.ContainsKey(selected.Link.UserID)) { Select(NodeMap[selected.Link.UserID]); } } EndUpdate(); }