Пример #1
0
        public static void Main(string[] args)
        {
            Log.Info("Program start ================");

            bool.TryParse(ConfigurationManager.AppSettings["PerformMove"], out bool performMove);
            bool.TryParse(ConfigurationManager.AppSettings["ShowBadFilesOnly"], out bool showBadFilesOnly);

            string mediaDirectory = ConfigurationManager.AppSettings["MediaLocation"];
            string connString     = ConfigurationManager.AppSettings["ConnectionString"];

            IDatabaseMediaProvider  databaseMedia = new DatabaseMediaService(connString);
            IDiscBasedMediaProvider discMedia     = new DiscBasedMediaService(mediaDirectory);

            ICollection <string> filesInDb = databaseMedia.QueryMedia();
            CompareResult        result    = discMedia.CompareMedia(filesInDb, showBadFilesOnly);

            if (performMove)
            {
                string targetPath = ConfigurationManager.AppSettings["DropOffLocation"];
                string sourcePath = ConfigurationManager.AppSettings["MediaLocation"];
                discMedia.MoveMedia(result.DeleteList, sourcePath, targetPath);
            }

            Statistics statistics = result.Statistics;

            Log.Warn($"Stats: Out of {result.TotalFileCount} Physical files, {statistics.InDb} were found in DB, {statistics.NotInDb} were found to be orphaned ");
            Log.Info("Program end ================");
            Log.Info("\n Bye!");
        }
        public void GoodMediaLocationWithoutSlash()
        {
            try
            {
                string goodMediaLocation      = ConfigurationManager.AppSettings["MediaLocationWithoutEndSlash"];
                string goodDBConnectionString = ConfigurationManager.AppSettings["GoodConnectionString"];


                IDiscBasedMediaProvider discMedia     = new DiscBasedMediaService(goodMediaLocation);
                IDatabaseMediaProvider  databaseMedia = new DatabaseMediaService(goodDBConnectionString);

                CompareResult test = discMedia.CompareMedia(null, false);

                if (test.TotalFileCount == 0)
                {
                    Assert.Fail("Double check Media Location is valid, HashSet is empty");
                }

                ICollection <string> dbTest = databaseMedia.QueryMedia();
                Assert.IsTrue(dbTest.Count > 0);
            }
            catch (DirectoryNotFoundException)
            {
                Assert.Fail("Double check Media Location is valid");
            }
        }
        public void NoMediaInDirectory()
        {
            string badMediaLocation           = ConfigurationManager.AppSettings["NonExistantFileDirectory"];
            IDiscBasedMediaProvider discMedia = new DiscBasedMediaService(badMediaLocation);

            try
            {
                CompareResult test = discMedia.CompareMedia(null, false);
            }
            catch (FileNotFoundException)
            {
                return;
            }
            Assert.Fail("Bad directory supplied did not trigger DirectoryNotFoundException");
        }
        public void GoodMediaLocationWithSlash()
        {
            try
            {
                string goodMediaLocation          = ConfigurationManager.AppSettings["MediaLocationWithEndSlash"];
                IDiscBasedMediaProvider discMedia = new DiscBasedMediaService(goodMediaLocation);

                CompareResult test = discMedia.CompareMedia(new HashSet <string>(), false);

                if (test.TotalFileCount == 0)
                {
                    Assert.Fail("Double check Media Location is valid, HashSet is empty");
                }

                return;
            }
            catch (DirectoryNotFoundException)
            {
                Assert.Fail("Double check Media Location is valid");
            }
        }