Ejemplo n.º 1
0
        internal ResponsePerRepository GetInformationGit(string url)
        {
            ResponsePerRepository responsePerRepository = new ResponsePerRepository();

            WebClient    client      = new WebClient();
            Stream       data        = client.OpenRead(new Uri(url));
            StreamReader reader      = new StreamReader(data);
            string       htmlContent = reader.ReadToEnd();
            var          document    = new HtmlDocument();

            document.LoadHtml(htmlContent);
            responsePerRepository.Commit         = document.DocumentNode.SelectNodes("//a[@class=\"d-none js-permalink-shortcut\"]").ToList().SelectMany(a => a.Attributes).Where(a => a.Name == "href").FirstOrDefault().Value;
            responsePerRepository.NameRepository = document.DocumentNode.SelectNodes("//a[@data-pjax=\"#js-repo-pjax-container\"]").ToList().SelectMany(a => a.Attributes).Where(a => a.Name == "href").FirstOrDefault().Value;
            responsePerRepository.Commit         = responsePerRepository.Commit.Split('/')[responsePerRepository.Commit.Split('/').Length - 1];
            responsePerRepository.Status         = "PROCESSING";
            return(responsePerRepository);
        }
Ejemplo n.º 2
0
        public ResponsePerRepository GetTotal(string gitUrl)
        {
            ResponsePerRepository responsePerRepository = GetInformationGit(gitUrl);

            if (File.Exists(Path.Combine(tempPath, responsePerRepository.Commit)))
            {
                string stringFile = File.ReadAllText(Path.Combine(tempPath, responsePerRepository.Commit));
                ResponsePerRepository recovery = JsonConvert.DeserializeObject <ResponsePerRepository>(stringFile);
                return(recovery);
            }

            FileTools.SaveFile(responsePerRepository.Commit, Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(responsePerRepository)), tempPath);

            Task task = Task.Run(() => GetTotalProcessing(responsePerRepository, gitUrl));

            task.Wait(28000);

            return(responsePerRepository);
        }
Ejemplo n.º 3
0
        internal ResponsePerRepository GetTotalProcessing(ResponsePerRepository responsePerRepository, string gitUrl)
        {
            try
            {
                List <GitRow> gitRows = new List <GitRow>();

                GetNodesRowHeader(gitUrl, gitRows);

                List <Task> tasks = new List <Task>();
                foreach (var item in gitRows)
                {
                    Task task = Task.Run(() => GetFileInformation(item));
                    tasks.Add(task);
                }

                Task.WaitAll(tasks.ToArray());

                responsePerRepository.PerExtension = GetTotalPerGroupExtension(gitRows);
                responsePerRepository.TotalBytes   = responsePerRepository.PerExtension.Select(a => a.TotalBytes).Sum();
                responsePerRepository.TotalLines   = responsePerRepository.PerExtension.Select(a => a.TotalLines).Sum();
                responsePerRepository.TotalFiles   = responsePerRepository.PerExtension.Select(a => a.TotalFiles).Sum();
                responsePerRepository.Status       = "COMPLETE";
                FileTools.SaveFile(responsePerRepository.Commit, Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(responsePerRepository)), tempPath);
                Console.WriteLine("Save: " + responsePerRepository.Commit);
                return(responsePerRepository);
            }
            catch (Exception e)
            {
                string json = JsonConvert.SerializeObject(e, new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                    Formatting            = Newtonsoft.Json.Formatting.Indented,
                    NullValueHandling     = NullValueHandling.Ignore,
                    MissingMemberHandling = MissingMemberHandling.Ignore,
                });

                throw new Exception(json);
            }
        }