Ejemplo n.º 1
0
        public void Load()
        {
            var stopwatch = Stopwatch.StartNew();

            Console.WriteLine("Loading projects..");

            var client = new DataSourceClient();

            var mostRecentInSource = client.GetMostRecentResource();
            var mostRecentInDb     = ResourceRepository.GetMostRecentResource();

            if (NoResourcesInDbYet(mostRecentInDb) ||
                WasNewResourceAdded(mostRecentInSource, mostRecentInDb) ||
                WasLastResourceUpdated(mostRecentInSource, mostRecentInDb))
            {
                Console.WriteLine("New or updated reasource found. Downloading..");

                var downloadedResource = client.DownloadResource(mostRecentInSource);
                var projectLoader      = new ProjectLoader(new OpenXmlResourceReader());

                Console.WriteLine("Reading resource..");

                var projectsInResource = projectLoader.Read(downloadedResource);
                var newProjects        = ProjectRepository.FilterAlreadyExistingProjects(projectsInResource);

                Console.WriteLine($"{newProjects.Count()} new projects found. Adding to DB..");

                ProjectRepository.AddOrUpdateMany(newProjects);
                ResourceRepository.AddOrUpdate(mostRecentInSource);

                client.DeleteTemporaryDirectory();

                Console.WriteLine("Loading projects done.");
            }
            else
            {
                Console.WriteLine("No project to add..");
            }

            stopwatch.Stop();
            Console.WriteLine($"Took {stopwatch.Elapsed}");
        }