Esempio n. 1
0
        static void Backup()
        {
            List <Task> runners = new List <Task>();
            var         config  = ServiceConfigurationModel.Deserialize();

            // Iterate over all of the specified locations...create threads
            foreach (SearchLocation location in config.SearchLocations.Where(s => s.IsLocal))
            {
                var allDirectories = DirectoryHelper.ListAllDirectories(location.RootPath, location.Recurse).ToList();

                // Create a blocking collection consisting of the enumerated directories.
                BlockingCollection <String> collection = new BlockingCollection <String>();
                allDirectories.ForEach(s => collection.Add(s));

                // The runners will operate on this blocking collection.
                for (int i = 0; i < config.MaxThreads; i++)
                {
                    Task runner = Task.Run(() =>
                    {
                        String dir = null;

                        while ((collection.TryTake(out dir, TimeSpan.FromSeconds(1))) && dir != null)
                        {
                            var validFiles = Directory.EnumerateFiles(dir)
                                             .Where(s => s.IsValidFile(config));

                            foreach (var validFile in validFiles)
                            {
                                SearchType type = config.GetSearchTypeForFile(validFile);

                                Delegate del = Delegate.CreateDelegate(typeof(Action <String, SearchLocation, Archive>), typeof(Program),
                                                                       type.Handler);
                                if (del != null)
                                {
                                    del.DynamicInvoke(validFile, location, config.Archive);
                                }
                            }
                        }
                    });

                    runners.Add(runner);
                }
            }

            Task.WaitAll(runners.ToArray());
        }
Esempio n. 2
0
        public void TestJson()
        {
            var obj = ServiceConfigurationModel.Deserialize();

            Assert.IsNotNull(obj);
        }
Esempio n. 3
0
 public static bool IsValidFile(this String file, ServiceConfigurationModel model)
 {
     return(model.SearchTypes.Any(s => file.EndsWith(s.Extension, true, CultureInfo.InvariantCulture)) &&
            model.IgnoreTypes.Select(s => s.Pattern).None(file));
 }