Ejemplo n.º 1
0
        public bool ProcessLink(ref ResourceProcessingStatus resource)
        {
            string linkUrl = resource.ResourceConfiguration.ResourceDomain + "/" + resource.TargetUrl;

            Console.WriteLine("Process link: " + linkUrl);

            //link has format ".../1011/SP1.csv", where 1011 is season 2010-2011
            string season = resource.TargetUrl.Substring(resource.TargetUrl.Length - 12, 4);

            //download file
            DataSourceFileLoader loader = new DataSourceFileLoader(resource.ResourceConfiguration.ResourceDomain);

            if (loader.DownloadFile("/" + resource.TargetUrl, season + ".csv"))
            {
                Console.WriteLine("Downloading file {0} succeed", linkUrl);
            }
            else
            {
                Console.WriteLine("Downloading file {0} failes", linkUrl);
                return(false);
            }

            FootballDataCSVParser parser = new FootballDataCSVParser();
            int processedGames;

            parser.ParseCsvAndSaveToDB(season + ".csv", season, out processedGames);

            resource.ProcessedMatches += processedGames;
            resource.Status            = resource.ProcessedMatches == 380 || resource.ProcessedMatches == 462 ? ProcessingStatus.Finished : ProcessingStatus.Start;
            return(processedGames > 0);
        }
        public bool AddResourceProcessingStatus(string targetUrl, ResourceConfiguration config)
        {
            if (Db.Database.Connection.State == System.Data.ConnectionState.Closed)
            {
                Db.Database.Connection.Open();
            }

            if ((from n in Db.ResourceProcessingStatus where n.TargetUrl == targetUrl select n).Any())
            {
                Console.WriteLine($"[AddResourceProcessingStatus] link({targetUrl}) already exist in DB");
                return(false);
            }

            ResourceProcessingStatus newStatus = new ResourceProcessingStatus
            {
                ResourceConfiguration   = config,
                ResourceConfigurationId = config.ResourceConfigurationId,
                Status           = ProcessingStatus.Start,
                ProcessedMatches = 0,
                TargetUrl        = targetUrl
            };

            Db.ResourceProcessingStatus.Add(newStatus);
            Db.SaveChanges();

            Db.Database.Connection.Close();
            return(true);
        }
        //update properties of ResourceProcessingStatus in DB
        public void UpdateResource(ResourceProcessingStatus status)
        {
            if (Db.Database.Connection.State == System.Data.ConnectionState.Closed)
            {
                Db.Database.Connection.Open();
            }

            var standingTableDb = (from n in Db.ResourceProcessingStatus where n.ResourceProcessingStatusId == status.ResourceProcessingStatusId select n).FirstOrDefault();

            if (standingTableDb != null)
            {
                standingTableDb.Status           = status.Status;
                standingTableDb.ProcessedMatches = status.ProcessedMatches;
                var repo = new LogRepository();
                repo.WriteLog(Database.SystemData.Severity.Information, "Update record in ResourceProcessingStatus table", nameof(SystemDataRepository),
                              "localhost", "[ResourceProcessingStatusId = " + status.ResourceProcessingStatusId + "]", "");
            }
            Db.SaveChanges();

            Db.Database.Connection.Close();
        }