/// <summary>
        /// Initializes a new instance of the <see cref="FormDialogSearchReplaceProgressFiles"/> class.
        /// </summary>
        /// <param name="crawler">An instance for the <see cref="DirectoryCrawler"/> class initialized elsewhere.</param>
        /// <param name="requestNextAction">A delegate for the <see cref="RequestNextAction"/> event as this class also unsubscribes the event handler.</param>
        public FormDialogSearchReplaceProgressFiles(DirectoryCrawler crawler, OnRequestNextAction requestNextAction)
        {
            InitializeComponent();

            DBLangEngine.DBName = "lang.sqlite"; // Do the VPKSoft.LangLib == translation..

            // initialize the language/localization database..
            DBLangEngine.InitializeLanguage("ScriptNotepad.Localization.Messages");

            // subscribe the disposed event..
            Disposed += FormDialogSearchReplaceProgressFiles_Disposed;

            // save the delegate for the RequestNextAction so it can be unsubscribed on this form's disposal..
            this.requestNextAction = requestNextAction;

            // subscribe the event with the delegate given in the parameter..
            RequestNextAction += requestNextAction;

            // subscribe to the ReportProgress event of the DirectoryCrawler instance..
            crawler.ReportProgress += Crawler_ReportProgress;

            // save the directory crawler instance..
            Crawler = crawler;

            // show this form as a dialog..
            ShowDialog();
        }
 void scanTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     scanTimer.Stop();
     this.viewModel.FolderScanCancellationToken = new System.Threading.CancellationTokenSource();
     Task.Factory.StartNew(() => DirectoryCrawler.Crawl(Settings.SettingsManager.DirectoryToScanPath, this.viewModel), this.viewModel.FolderScanCancellationToken.Token);
     scanTimer.Start();
 }
Ejemplo n.º 3
0
        private void LoadRoots()
        {
            //Get all expanded nodes
            List <ITreeItem> oldExpanded = new List <ITreeItem>();

            if (ExpandedNodes.Count > 0)
            {
                foreach (ITreeItem item in ExpandedNodes)
                {
                    oldExpanded.Add(item);
                }
                oldExpanded = new List <ITreeItem>(oldExpanded.OrderBy(x => x.Level));
            }

            //Clean tree
            foreach (ITreeItem item in nodeDict.Values)
            {
                UnSubscribeEvents(item);
            }
            nodeDict.Clear();
            ClearTree();

            //Get drives
            ActionResult <IEnumerable <DriveInfo> > diResult = DirectoryCrawler.GetDrivesReady();

            if (diResult.Successful)
            {
                foreach (DriveInfo item in diResult.Result)
                {
                    DriveTreeItemViewModel vm = new DriveTreeItemViewModel(item);
                    AddToTree(vm);
                    nodeDict.Add(vm.Path.ToLower(), vm);
                    vm.Expanded  += OnVmExpanded;
                    vm.Collapsed += OnVmCollapsed;
                    //create children for root nodes
                    CreateSubFolders(vm);
                }
            }
            //else
            //{
            //    logger.Log(LogFactory.CreateWarningMessage(diResult.GetComments()));
            //    return;
            //}

            if (oldExpanded.Count > 0)
            {
                foreach (ITreeItem item in oldExpanded)
                {
                    if (nodeDict.ContainsKey(item.Path.ToLower()))
                    {
                        nodeDict[item.Path.ToLower()].IsExpanded = true;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public JsonResult Repositories(string organization)
        {
            var crawler = new DirectoryCrawler();

            var repositories =
                crawler.GetRepositoriesByOrganization(organization);

            foreach (var repository in repositories)
            {
                repository.Path = Url.Action("Index", "Repository", new { path = repository.Name });
            }

            return(Json(
                       repositories,
                       JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
 public void ChangePath(string directoryPath)
 {
     RemoveAll();
     ActionResult<IEnumerable<DirectoryInfo>> actionResult = DirectoryCrawler.GetSubFolders(directoryPath, false);
     if (actionResult.Successful)
     {
         foreach (DirectoryInfo item in actionResult.Result)
         {
             FolderListItemViewModel vm = new FolderListItemViewModel(item);
             AddItem(vm);
         }
     }
     else
     {
         logger.Log(LogFactory.CreateWarningMessage(actionResult.GetComments()));
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Crawls the directory containing Hunspell dictionary and affix files.
        /// </summary>
        /// <param name="path">The path to search the dictionaries from.</param>
        /// <returns>List&lt;HunspellData&gt;.</returns>
        public static List <HunspellData> CrawlDirectory(string path)
        {
            // create a new instance of the DirectoryCrawler class by user given "arguments"..
            DirectoryCrawler crawler = new DirectoryCrawler(path, DirectoryCrawler.SearchTypeMatch.Regex,
                                                            "*.dic", true);

            // search for the Hunspell dictionary files (*.dic)..
            var files = crawler.GetCrawlResult();

            // initialize a return value..
            List <HunspellData> result = new List <HunspellData>();

            // loop through the found dictionary files (*.dic)..
            foreach (var file in files)
            {
                try
                {
                    // create a new HunspellData class instance..
                    var data = HunspellData.FromDictionaryFile(file);

                    // validate that there is a affix (*.aff) pair for the found dictionary file (*.dic)..
                    if (!File.Exists(data.DictionaryFile) || !File.Exists(data.AffixFile))
                    {
                        // ..if not, do continue..
                        continue;
                    }

                    // the validation was successful, so add the data to the result..
                    result.Add(data);
                }
                catch (Exception ex)
                {
                    // log the exception..
                    ExceptionLogAction?.Invoke(ex);
                }
            }

            // return the result..
            return(result);
        }
Ejemplo n.º 7
0
        private void CreateSubFolders(ITreeItem parent)
        {
            ActionResult <IEnumerable <DirectoryInfo> > actionResult =
                DirectoryCrawler.GetSubFolders(parent.Path, false);

            if (actionResult.Successful)
            {
                foreach (DirectoryInfo di in actionResult.Result)
                {
                    FolderTreeItemViewModel sub = new FolderTreeItemViewModel(di);
                    AddToTree(sub);
                    nodeDict.Add(sub.Path.ToLower(), sub);
                    sub.Expanded  += OnVmExpanded;
                    sub.Collapsed += OnVmCollapsed;
                    parent.AddChild(sub);
                }
            }
            //else
            //{
            //    logger.Log(LogMessageStatus.Warning, actionResult.GetComments());
            //}
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            bool             invalidFile  = true;
            var              path         = string.Empty;
            YamlDeserializer deserializer = null;
            var              message      = "Enter full path to the zone-pivot .yml definition file.";

            while (invalidFile)
            {
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine(message);
                Console.ResetColor();

                path = Console.ReadLine();
                if (path.EndsWith(".yml"))
                {
                    try
                    {
                        deserializer = new YamlDeserializer(path);
                        deserializer.DeserializeYaml();

                        Console.WriteLine();
                        Console.BackgroundColor = ConsoleColor.Black;
                        Console.ForegroundColor = ConsoleColor.Blue;
                        Console.WriteLine("-- Zone-pivot definition loaded successfully; displaying keys...");
                        Console.ResetColor();
                        Console.WriteLine();

                        foreach (string key in deserializer.ZoneGroupsKeyHash.Keys)
                        {
                            Console.WriteLine(key);
                        }
                        invalidFile = false;
                    }
                    catch (FileNotFoundException ex)
                    {
                        Console.WriteLine();
                        Console.BackgroundColor = ConsoleColor.Black;
                        Console.ForegroundColor = ConsoleColor.Blue;
                        message = "Error: file not found for zone-pivot .yml definition. Ensure your path is correct and enter again.";
                        Console.ResetColor();
                    }
                }
                else
                {
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ForegroundColor = ConsoleColor.Blue;
                    message = "Error: Path does not end in a .yml extension. Ensure your path is correct and enter again.";
                    Console.ResetColor();
                }
            }

            Console.WriteLine();
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Enter full path to the directory to run recursive validation against the zone-pivot definition .yml file.");
            Console.ResetColor();
            Console.WriteLine();

            var dirPath    = Console.ReadLine();
            var dirCrawler = new DirectoryCrawler(dirPath);

            dirCrawler.RecursiveCrawlFiles(deserializer);
        }
Ejemplo n.º 9
0
        public ActionResult Index()
        {
            var crawler = new DirectoryCrawler();

            return(View(crawler.GetOrganizations()));
        }
Ejemplo n.º 10
0
 public MainWindowViewModel(DirectoryCrawler directoryCrawler)
 {
     _directoryCrawler = directoryCrawler;
 }