Example #1
0
        private static void ConfigRead(FilesConfigSection config)
        {
            _directories = new List <string>(config.Directories.Count);
            _rules       = new List <Rule>();

            foreach (DirectoryItem dir in config.Directories)
            {
                _directories.Add(dir.Path);
            }

            foreach (RuleItem rule in config.Rules)
            {
                _rules.Add(new Rule
                {
                    FileTemplate = rule.FileTemplate,
                    ToFolder     = rule.ToFolder,
                    IsDateAdded  = rule.IsDateAdded,
                    IsOrderAdded = rule.IsOrderAdded
                });
            }

            CultureInfo.DefaultThreadCurrentCulture   = config.Culture;
            CultureInfo.DefaultThreadCurrentUICulture = config.Culture;
            CultureInfo.CurrentUICulture = config.Culture;
            CultureInfo.CurrentCulture   = config.Culture;
        }
Example #2
0
        public static void Main(string[] args)
        {
            try
            {
                FilesConfigSection config = ConfigurationManager.GetSection("filesConfigSection") as FilesConfigSection;

                if (config != null)
                {
                    ConfigRead(config);
                }
                else
                {
                    Console.WriteLine(Strings.ConfigNotFound);
                    return;
                }

                Console.WriteLine(config.Culture.DisplayName);

                ILogger logger = new Logger();
                _fileMover = new FileMover(_rules, config.Rules.DefaultDirectory, logger);
                var watcher = new FileWatcher(_directories, logger);

                watcher.Created += OnCreated;

                CancellationTokenSource source = new CancellationTokenSource();

                Console.CancelKeyPress += (o, e) =>
                {
                    watcher.Created -= OnCreated;
                    source.Cancel();
                };

                Task.Delay(TimeSpan.FromMilliseconds(-1), source.Token).Wait(source.Token);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }