/* Below Methods are the Support methods which can not be moved to helper class * as they need to access the form elements */ /// <summary> /// Trying to populate Favorites drop down!! /// </summary> private void PopulateFavList() { Logger.Info("Populating Favorite list"); _allowCache = !checkBox2.Checked; Logger.Info("Does user want to cache the folder ? {0}",_allowCache); var config = new FavoritesFile(_configFile,_allowCache); var folderList = config.ReadFavoritesCache(); if (folderList.Count > 0) { Logger.Info("Cache folder count {0}",folderList.Count); folderList.Insert(0, "<< Select With Browse >>"); FavList.DataSource = folderList; SetDirectory(FolderName); // Not sure why setting here .. need to find it out !! } else { Logger.Info("Cache is empty, only browse available. Disabling Fav list."); FavList.Enabled = false; folderList.Insert(0, "Nothing Stored In Favorites, Disabling!!"); FavList.DataSource = folderList; SetDirectory(FolderName); } // label4.Text = string.Empty; }
static void Main(string[] args) { if (CommandLineHelper.IfAskedForHelp(Environment.GetCommandLineArgs())) ShowHelp(); // If valid args == 1 go ahead otherwise we have a problem if (!CommandLineHelper.ValidateArgs(Environment.GetCommandLineArgs())) { Logger.Error("Argument Validation failed..Exiting"); ShowHelp(); Environment.Exit(1); } Logger.Info("Summary : "); Logger.Info("Directory to be locked : {0}", CommandArgs.WDirectory); Logger.Info("User Action : {0}", CommandArgs.UAction); Logger.Info("Cache Directory : {0}", CommandArgs.CacheEntry); Logger.Info("Use Threads : {0}", CommandArgs.UseThreads); Logger.Info("Show Cache : {0}", CommandArgs.ShowCache); Logger.Info("Open Directory : {0}", CommandArgs.OpenDir); Logger.Info("Use directory from cache : {0}", CommandArgs.UseFromCache); // Generate Helper Object var nHelper = CommandArgs.UseThreads == "true" ? new Nebula.Common.Helper(true) : new Nebula.Common.Helper(false); string[] lockExts = { "*.bmp","*.jpg"}; string[] unlockExts = { "*.nylj", "*.nylb" }; var imageList = new List<string>(); switch (CommandArgs.UAction.ToLower()) { case "lock" : imageList = nHelper.GetImages(CommandArgs.WDirectory, lockExts); break; case "unlock" : imageList = nHelper.GetImages(CommandArgs.WDirectory, unlockExts); break; default: Logger.Error("Invalid Option...."); Environment.Exit(2); break; } nHelper.SetFileCountList(imageList.Count); if ( imageList.Count > 0 ) { var threadCnt = (int)nHelper.DoWork(imageList); var threadFinCnt = 0; while (threadCnt != threadFinCnt) { Logger.Info("Threads created [{0}] Threads Finished [{1}]", threadCnt, threadFinCnt); ProgressBarUpdater(nHelper.UpdateProgressBar()); threadFinCnt = nHelper.CheckCompletedThreadCnt(); Logger.Info("Sleeping for 1/5 sec before checking the status again"); Thread.Sleep(200); } var failedCnt = (Dictionary<string, string>)nHelper.GetFailedFiles(); var retCode = failedCnt.Count > 0 ? 2 : 0; CheckRCode(retCode, imageList.Count, CommandArgs.UAction); var allowCache = CommandArgs.CacheEntry == "true" ? true : false; var config = new FavoritesFile(ConfigFile,allowCache ); config.UpdateFavoriteCache(CommandArgs.WDirectory); if (CommandArgs.OpenDir == "true") System.Diagnostics.Process.Start("explorer", string.Format("{0}", CommandArgs.WDirectory)); } else { Logger.Info("There are NO files to be locked/unlocked in '{0}' directory!!",CommandArgs.WDirectory); Environment.Exit(0); } }
/// <summary> /// Do the action as suggested by action, locker & unlocker will set the extensions to use /// this method will perform the actions /// </summary> /// <param name="action">Lock / Unlock</param> private void CommonAction(string action) { Logger.Info(" "); Logger.Info("Performing the actual operation of {0}",action); bool isThreaded = checkBox1.Checked; Logger.Info("Is Threading enabled {0}",isThreaded); _allowCache = !checkBox2.Checked; var helper = new Helper(isThreaded); var config = new FavoritesFile(_configFile,_allowCache); progressBar1.Value = 1; progressBar1.Invalidate(); // label4.Text = string.Empty; ClearSummaryGrid(); _sw.Reset(); _sw.Start(); Logger.Info("Reseted the timer to 0"); if (!Directory.Exists(FolderName)) { helper.ThrowError(string.Format("{0} : Folder does not exist!!", FolderName)); return; } Logger.Info("{0} exists.",FolderName); _fileList = helper.GetImages(FolderName, Extenstion); helper.SetFileCountList(_fileList.Count); Logger.Info("Found {0} files to be {1}ed in {2} directory",_fileList.Count,action,FolderName); if (_fileList.Count > 0) { Enabled = false; // Disable elements on the form Logger.Info("Disabled the form controls, to avoid user clicking any other buttons!"); var threadCnt = (int)helper.DoWork(_fileList); Logger.Info("{0} threads created",threadCnt); var threadFinCnt = 0; Logger.Info("Checking if all threads finished the processing..."); while ( threadCnt != threadFinCnt) { Logger.Info("Threads created [{0}] Threads Finished [{1}]",threadCnt,threadFinCnt); ProgressBarUpdater(helper.UpdateProgressBar()); threadFinCnt = helper.CheckCompletedThreadCnt(); Logger.Info("Sleeping for 1/5 sec before checking the status again"); Thread.Sleep(200); } // Assume if finished thread count == started thread count ProgressBarUpdater(100); Logger.Info("All threads finished, completed thread count {0}",threadFinCnt); var failedCnt = (Dictionary<string, string>) helper.GetFailedFiles(); Logger.Info("Failed file count {0}",failedCnt.Count); var retCode = failedCnt.Count > 0 ? 2 : 0; CheckRCode(retCode, _fileList.Count, action); Logger.Info("Enabling the main window again"); Enabled = true; // Enable elements on the form config.UpdateFavoriteCache(FolderName); PopulateFavList(); progressBar1.Step = 0; progressBar1.PerformStep(); progressBar1.Refresh(); } else { Logger.Error("There are no files to be {0}ed",action); helper.ThrowError(string.Format("{0} : Has 0 files to {1}!!", FolderName,action.ToUpper())); } }