Esempio n. 1
0
 public void FilterFiles()
 {
     FilesTree.BeginUpdate();
     try
     {
         ICollection <FileContainer> data = MappedData.Data.OfType <FileContainer>().ToArray();
         try
         {
             var expr = string.IsNullOrWhiteSpace(ActiveFilter) ? null : new Regex(ActiveFilter, _CaseInsensitiveFileSearch ? RegexOptions.IgnoreCase : RegexOptions.None, new TimeSpan(0, 0, 1));
             foreach (var f in data)
             {
                 f.Visible = (!_MappedOnly || f.IsMapped) &&
                             (!_CyrilicOnly || f.CyrilicCount > 0) &&
                             (!LetterOnly || f.ContainsLiteral()) &&
                             (expr == null || expr.IsMatch(f.Name));
             }
         }
         catch (Exception e)
         {
             Helpers.ConsoleWrite(e.ToString(), ConsoleColor.Blue);
         }
     }
     finally
     {
         FilesTree.EndUpdate();
     }
 }
Esempio n. 2
0
        /// <summary>
        /// A method to populate a TreeView with directories, subdirectories, etc
        /// </summary>
        /// <param name="dir">The path of the directory</param>
        /// <param name="node">The "master" node, to populate</param>
        public void PopulateTree(string dir, FilesTree node)
        {
            var directory = new DirectoryInfo(Request.MapPath(dir));

            if (node.children == null && directory.GetDirectories().Length > 0)
            {
                node.children = new List <FilesTree>();
            }
            // get the information of the directory

            // loop through each subdirectory
            foreach (var t in from d in directory.GetDirectories() let dirName = string.Format("{0}/{1}", dir, d.Name) select new FilesTree {
                attr = new FilesTreeAttribute {
                    id = dirName
                }, data = d.Name, state = "closed"
            } into t where node.children != null select t)
            {
                node.children.Add(t); // add the node to the "master" node
            }

            // lastly, loop through each file in the directory, and add these as nodes
            //foreach (var f in directory.GetFiles()) {
            //    // create a new node
            //    var t = new FilesTree {attr = new FilesTreeAttribute {id = f.FullName}, data = f.Name};
            //    // add it to the "master"
            //    node.children.Add(t);
            //}
        }
Esempio n. 3
0
 /// <summary>
 /// происходит при удалении папки или файла, вызывается асинхронно
 /// </summary>
 private void W_Deleted(object sender, FileSystemEventArgs e)
 {
     Helpers.mainCTX.Send(_ =>
     {
         //выпилим файл из разметки
         Helpers.ConsoleWrite(string.Format("[{0}]{1} : {2}", DateTime.Now.ToString(), e.FullPath, e.ChangeType));
         FilesTree.Remove(e.FullPath);
     }, null);
 }
Esempio n. 4
0
 /// <summary>
 /// происходит при изменении в папке или файле, вызывается асинхронно
 /// </summary>
 private void W_Changed(object sender, FileSystemEventArgs e)
 {
     Helpers.mainCTX.Send(_ =>
     {
         //попросим обновить файл, и т.к. событие может произойти несколько раз, установим флаг проверки даты изменения
         Helpers.ConsoleWrite(string.Format("[{0}]{1} : {2}", DateTime.Now.ToString(), e.FullPath, e.ChangeType));
         FilesTree.UpdateData(e.FullPath, true);
     }, null);
 }
Esempio n. 5
0
 private void W_Created(object sender, FileSystemEventArgs e)
 {
     Helpers.mainCTX.Send(_ =>
     {
         Helpers.ConsoleWrite(string.Format("[{0}]{1} : {2}", DateTime.Now.ToString(), e.FullPath, e.ChangeType));
         if (!IsIgnored(e.FullPath))
         {
             FilesTree.AddFile(e.FullPath);
         }
     }, null);
 }
Esempio n. 6
0
        public JsonResult GetTreeData(int mID)
        {
            SetModuleId(mID);
            var rootPath = PortalSettings.PortalFullPath;
            var rootNode = new FilesTree {
                attr = new FilesTreeAttribute {
                    id = rootPath
                }, data = rootPath
            };

            rootNode.attr.id = rootPath;
            PopulateTree(rootPath, rootNode);
            return(Json(rootNode));
        }
Esempio n. 7
0
        public JsonResult GetTreeData(string mID)
        {
            SetModuleId(Convert.ToInt32(mID));
            //var rootPath = PortalSettings.PortalFullPath;
            var rootPath = "/";
            var rootNode = new FilesTree {
                attr = new FilesTreeAttribute {
                    id = rootPath
                }, data = rootPath
            };

            rootNode.attr.id = rootPath;
            PopulateTree(rootPath, rootNode, true);
            return(Json(rootNode, JsonRequestBehavior.AllowGet));
        }
Esempio n. 8
0
        public JsonResult GetChildreenTree(string dir, int mID)
        {
            SetModuleId(mID);
            var rootNode = new FilesTree {
                attr = new FilesTreeAttribute {
                    id = dir
                }, data = dir.Substring(1)
            };
            var rootPath = dir;

            rootNode.attr.id = rootPath;
            PopulateTree(rootPath, rootNode, false);

            return(Json(rootNode.children));
        }
Esempio n. 9
0
        /// <summary>
        /// A method to populate a TreeView with directories, subdirectories, etc
        /// </summary>
        /// <param name="dir">The path of the directory</param>
        /// <param name="node">The "master" node, to populate</param>
        public void PopulateTree(string dir, FilesTree node, bool roottree)
        {
            var directory = new DirectoryInfo(Request.MapPath(dir));

            if (node.children == null && directory.GetDirectories().Length > 0)
            {
                node.children = new List <FilesTree>();
            }
            // get the information of the directory

            // loop through each subdirectory

            // Get list of folders to be render in left side folder tree
            var allowfolderlist = System.Configuration.ConfigurationManager.AppSettings["FileManager.AllowFolders.Tree"].ToString();
            var allowfolders    = allowfolderlist.Split('|');

            foreach (var t in from d in directory.GetDirectories() let dirName = string.Format("{0}/{1}", dir, d.Name) select new FilesTree {
                attr = new FilesTreeAttribute {
                    id = dirName
                }, data = d.Name, state = "closed"
            } into t where node.children != null select t)
            {
                if (roottree)
                {
                    foreach (var folder in allowfolders)
                    {
                        if (t.data == folder)
                        {
                            node.children.Add(t); // add the node to the "master" node
                        }
                    }
                }
                else
                {
                    node.children.Add(t); // add the node to the "master" node
                }
            }

            // lastly, loop through each file in the directory, and add these as nodes
            //foreach (var f in directory.GetFiles()) {
            //    // create a new node
            //    var t = new FilesTree {attr = new FilesTreeAttribute {id = f.FullName}, data = f.Name};
            //    // add it to the "master"
            //    node.children.Add(t);
            //}
        }
Esempio n. 10
0
 private void W_Renamed(object sender, RenamedEventArgs e)
 {
     Helpers.mainCTX.Send(_ =>
     {
         //попросим обновить файл, и т.к. событие может произойти несколько раз, установим флаг проверки даты изменения
         Helpers.ConsoleWrite(string.Format("[{0}]{1} => {2} : {3}", DateTime.Now.ToString(), e.OldFullPath, e.FullPath, e.ChangeType));
         if (!IsIgnored(e.OldFullPath) || !IsIgnored(e.FullPath))
         {
             if (_SolutionsFiles.Contains(e.OldFullPath))
             {
                 _SolutionsFiles.Remove(e.OldFullPath);
                 _SolutionsFiles.Add(e.FullPath);
             }
             FilesTree.Remove(e.OldFullPath);
             var f = FilesTree.AddFile(e.FullPath);
             if (string.Equals(Selected?.FullPath, e.FullPath, StringComparison.InvariantCultureIgnoreCase))
             {
                 Selected = f;
             }
         }
     }, null);
 }
Esempio n. 11
0
        void AddFiles(ICollection <string> files, Action <string, int> callback = null)
        {
            EditingEnabled = false;
            var cts = new CancellationTokenSource();

            FilesTree.BeginUpdate();
            try
            {
                callback?.Invoke(null, files.Count);
                int    cnt         = 0;
                string currentFile = string.Empty;
                Task.Run(() => {
                    while (!cts.IsCancellationRequested)
                    {
                        Task.Delay(1000);
                        callback?.Invoke(currentFile, cnt);
                    }
                });
                //System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
                //w.Start();
                foreach (var f in files)
                {
                    currentFile = f;
                    ++cnt;
                    FilesTree.AddFile(f);
                }
                //w.Stop();
            }
            finally
            {
                cts.Cancel();
                FilesTree.EndUpdate();
                EditingEnabled = true;
                FilterFiles();
                GC.Collect();
            }
        }