public static async Task <RepoStats> RetrieveEntityUsingPointQueryAsync(CloudTable table, string partitionKey, string rowKey) { try { TableOperation retrieveOperation = TableOperation.Retrieve <RepoStats>(partitionKey, rowKey); TableResult result = await table.ExecuteAsync(retrieveOperation); RepoStats customer = result.Result as RepoStats; if (customer != null) { Console.WriteLine("\t{0}\t{1}\t{2}", customer.PartitionKey, customer.RowKey, customer.RepoName); } if (result.RequestCharge.HasValue) { Console.WriteLine("Request Charge of Retrieve Operation: " + result.RequestCharge); } return(customer); } catch (StorageException e) { Console.WriteLine(e.Message); Console.ReadLine(); throw; } }
public static async Task <RepoStats> InsertOrMergeEntityAsync(CloudTable table, RepoStats entity) { if (entity == null) { throw new ArgumentNullException("entity"); } try { TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity); TableResult result = await table.ExecuteAsync(insertOrMergeOperation); RepoStats insertedCustomer = result.Result as RepoStats; if (result.RequestCharge.HasValue) { Console.WriteLine("Request Charge of InsertOrMerge Operation: " + result.RequestCharge); } return(insertedCustomer); } catch (StorageException e) { Console.WriteLine(e.Message); Console.ReadLine(); throw; } }
public static async Task Run(ILogger log, Microsoft.Azure.WebJobs.ExecutionContext context) { var client = new GitHubClient(new ProductHeaderValue("TrackRepos")); var basicAuth = new Credentials(Environment.GetEnvironmentVariable("GitHubToken")); client.Credentials = basicAuth; string storageConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage"); BlobServiceClient blobServiceClient = new BlobServiceClient(storageConnectionString); BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("repos"); BlobClient blobClient = containerClient.GetBlobClient("Repos.json"); BlobDownloadInfo download = await blobClient.DownloadAsync(); List <Campaign> campaigns = JsonConvert.DeserializeObject <List <Campaign> >(new StreamReader(download.Content).ReadToEnd()); List <RepoStats> stats = new List <RepoStats>(); foreach (Campaign campaign in campaigns) { if (!string.IsNullOrEmpty(campaign.CampaignName) && !string.IsNullOrEmpty(campaign.OrgName)) { foreach (Repo repo in campaign.Repos) { if (!string.IsNullOrEmpty(repo.RepoName)) { var views = await client.Repository.Traffic.GetViews(campaign.OrgName, repo.RepoName, new RepositoryTrafficRequest(TrafficDayOrWeek.Day)); var clones = await client.Repository.Traffic.GetClones(campaign.OrgName, repo.RepoName, new RepositoryTrafficRequest(TrafficDayOrWeek.Day)); foreach (var item in views.Views) { var stat = new RepoStats($"{campaign.CampaignName}{repo.RepoName}", item.Timestamp.UtcDateTime.ToShortDateString().Replace("/", "")) { OrgName = campaign.OrgName, CampaignName = campaign.CampaignName, RepoName = repo.RepoName, Date = item.Timestamp.UtcDateTime.ToShortDateString(), Views = item.Count, UniqueUsers = item.Uniques }; var clone = clones.Clones.Where(a => a.Timestamp.UtcDateTime.ToShortDateString() == item.Timestamp.UtcDateTime.ToShortDateString()).FirstOrDefault(); if (clone != null) { stat.Clones = clone.Count; stat.UniqueClones = clone.Uniques; } stats.Add(stat); } Thread.Sleep(5000); } } } } string tableName = "RepoStats"; CloudTable table = await TableStorageHelper.CreateTableAsync(tableName); foreach (var view in stats) { Console.WriteLine("Insert an Entity."); await TableStorageHelper.InsertOrMergeEntityAsync(table, view); } }