diff --git a/Cornea Cristian/L01/Tema.txt b/Cornea Cristian/L01/Tema.txt new file mode 100644 index 00000000..9bd99cb9 --- /dev/null +++ b/Cornea Cristian/L01/Tema.txt @@ -0,0 +1 @@ +Un serviciu pe care il folosesc foarte des este Spotify-ul, prin care pot face streaming la muzica. diff --git a/Cornea Cristian/L02/Controllers/StudentsController.cs b/Cornea Cristian/L02/Controllers/StudentsController.cs new file mode 100644 index 00000000..b30f6308 --- /dev/null +++ b/Cornea Cristian/L02/Controllers/StudentsController.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Repositories; +using Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace L02.Controllers +{ + [ApiController] + [Route("[controller]")] + public class StudentsController : ControllerBase + { + public StudentsController() + { + } + + public IEnumerable Get(){ + return StudentsRepo.Students; + } + + [HttpGet("{id}")] + public Students GetStudent(int id) + { + return StudentsRepo.Students.FirstOrDefault(s=>s.Id == id); + } + } +} \ No newline at end of file diff --git a/Cornea Cristian/L02/Controllers/WeatherForecastController.cs b/Cornea Cristian/L02/Controllers/WeatherForecastController.cs new file mode 100644 index 00000000..4ee7aa34 --- /dev/null +++ b/Cornea Cristian/L02/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace L02.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/Cornea Cristian/L02/L02.csproj b/Cornea Cristian/L02/L02.csproj new file mode 100644 index 00000000..d12c450b --- /dev/null +++ b/Cornea Cristian/L02/L02.csproj @@ -0,0 +1,8 @@ + + + + netcoreapp3.1 + + + + diff --git a/Cornea Cristian/L02/Models/Students.cs b/Cornea Cristian/L02/Models/Students.cs new file mode 100644 index 00000000..bd248248 --- /dev/null +++ b/Cornea Cristian/L02/Models/Students.cs @@ -0,0 +1,13 @@ +namespace Models +{ + public class Students + { + public int Id { get; set; } + + public string Faculty { get; set; } + + public string Name { get; set; } + + public int Year { get; set; } + } +} diff --git a/Cornea Cristian/L02/Program.cs b/Cornea Cristian/L02/Program.cs new file mode 100644 index 00000000..4b6626d7 --- /dev/null +++ b/Cornea Cristian/L02/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace L02 +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/Cornea Cristian/L02/Properties/launchSettings.json b/Cornea Cristian/L02/Properties/launchSettings.json new file mode 100644 index 00000000..6ec2572b --- /dev/null +++ b/Cornea Cristian/L02/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:35418", + "sslPort": 44344 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "L02": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Cornea Cristian/L02/Repositories/StudentsRepo.cs b/Cornea Cristian/L02/Repositories/StudentsRepo.cs new file mode 100644 index 00000000..1d6377f2 --- /dev/null +++ b/Cornea Cristian/L02/Repositories/StudentsRepo.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Models; +namespace Repositories{ + public static class StudentsRepo{ + + public static List Students = new List(){ + new Students(){Id=1, Faculty="AC", Name = "Bogdan", Year = 4}, + new Students(){Id=2, Faculty="ETc", Name = "Alexa", Year = 1} + }; + } +} \ No newline at end of file diff --git a/Cornea Cristian/L02/Startup.cs b/Cornea Cristian/L02/Startup.cs new file mode 100644 index 00000000..ff5c05f1 --- /dev/null +++ b/Cornea Cristian/L02/Startup.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace L02 +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Cornea Cristian/L02/WeatherForecast.cs b/Cornea Cristian/L02/WeatherForecast.cs new file mode 100644 index 00000000..0c25b27d --- /dev/null +++ b/Cornea Cristian/L02/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace L02 +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git a/Cornea Cristian/L02/appsettings.Development.json b/Cornea Cristian/L02/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/Cornea Cristian/L02/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Cornea Cristian/L02/appsettings.json b/Cornea Cristian/L02/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/Cornea Cristian/L02/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/Cornea Cristian/L03/L03.csproj b/Cornea Cristian/L03/L03.csproj new file mode 100644 index 00000000..edbcd4db --- /dev/null +++ b/Cornea Cristian/L03/L03.csproj @@ -0,0 +1,12 @@ + + + + Exe + net5.0 + + + + + + + diff --git a/Cornea Cristian/L03/L03.sln b/Cornea Cristian/L03/L03.sln new file mode 100644 index 00000000..efe32297 --- /dev/null +++ b/Cornea Cristian/L03/L03.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31702.278 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "L03", "L03.csproj", "{2C84BB6A-A07D-4486-B617-E5E02AC1DA76}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2C84BB6A-A07D-4486-B617-E5E02AC1DA76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C84BB6A-A07D-4486-B617-E5E02AC1DA76}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C84BB6A-A07D-4486-B617-E5E02AC1DA76}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C84BB6A-A07D-4486-B617-E5E02AC1DA76}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D9706B27-A7AC-4F49-A7EE-E2AD45A77BDE} + EndGlobalSection +EndGlobal diff --git a/Cornea Cristian/L03/Program.cs b/Cornea Cristian/L03/Program.cs new file mode 100644 index 00000000..48ab49f3 --- /dev/null +++ b/Cornea Cristian/L03/Program.cs @@ -0,0 +1,86 @@ +using System; +using System.IO; +using System.Net; +using System.Text; +using System.Threading; +using Google.Apis.Auth.OAuth2; +using Google.Apis.Drive.v3; +using Google.Apis.Util.Store; +using Newtonsoft.Json.Linq; + +namespace L03 +{ + class Program + { + private static string _token; + + static void Main() + { + Initialize(); + } + + static void Initialize() + { + string[] scopes = new string[]{ + DriveService.Scope.Drive, + DriveService.Scope.DriveFile + }; + var clientId = "1046461755374-0jeatkchhepp5kf3t922c30jv09lg0rp.apps.googleusercontent.com"; + var clientSecret = "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"; + var credential = GoogleWebAuthorizationBroker.AuthorizeAsync( + new ClientSecrets + { + ClientId = clientId, + ClientSecret = clientSecret + }, + scopes, + Environment.UserName, + CancellationToken.None, + new FileDataStore("Dainto.GoogleDrive.Auth.Store") + ).Result; + _token = credential.Token.AccessToken; + Console.WriteLine(_token); + GetAllFiles(); + UploadTxtFile(); + } + + static void GetAllFiles() + { + var request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/drive/v3/files?q='root'%20in%20parents"); + request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + _token); + using var response = request.GetResponse(); + using Stream data = response.GetResponseStream(); + using var reader = new StreamReader(data); + string text = reader.ReadToEnd(); + var myData = JObject.Parse(text); + foreach (var file in myData["files"]) + { + if (file["mimeType"].ToString() != "application/vnd.google-apps.folder") + { + Console.WriteLine("File name: " + file["name"]); + } + } + } + static void UploadTxtFile() + { + string path; + byte[] text; + Console.Write("Dati calea fisierului txt pe care doriti sa il incarcati pe drive: "); + path = Console.ReadLine(); + text = Encoding.ASCII.GetBytes("--not_so_random_boundary\nContent-Type: application/json; charset = utf-8\nContent-Disposition: form-data; name=\"metadata\"\n\n{\"name\":\""+Path.GetFileName(path)+"\",\"mimeType\":\"text/plain\"}\n--not_so_random_boundary\nContent-Type: text/plain\nContent-Disposition: form-data; name=\"file\"\n\n"+ File.ReadAllText(path) + "\n--not_so_random_boundary--"); + var request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"); + request.Method = WebRequestMethods.Http.Post; + request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + _token); + request.Headers.Add(HttpRequestHeader.ContentType, "multipart/related; boundary=not_so_random_boundary"); + request.Headers.Add(HttpRequestHeader.ContentLength, text.Length.ToString()); + Stream body = request.GetRequestStream(); + body.Write(text, 0, text.Length); + using var response = request.GetResponse(); + using Stream data = response.GetResponseStream(); + using var reader = new StreamReader(data); + string info = reader.ReadToEnd(); + var myData = JObject.Parse(info); + Console.WriteLine(myData); + } + } +} diff --git a/Cornea Cristian/L03/random.txt b/Cornea Cristian/L03/random.txt new file mode 100644 index 00000000..4c799646 --- /dev/null +++ b/Cornea Cristian/L03/random.txt @@ -0,0 +1 @@ +this text is also random \ No newline at end of file diff --git a/Cornea Cristian/L04/L04.csproj b/Cornea Cristian/L04/L04.csproj new file mode 100644 index 00000000..5a6157cd --- /dev/null +++ b/Cornea Cristian/L04/L04.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + + diff --git a/Cornea Cristian/L04/Program.cs b/Cornea Cristian/L04/Program.cs new file mode 100644 index 00000000..77071ca1 --- /dev/null +++ b/Cornea Cristian/L04/Program.cs @@ -0,0 +1,71 @@ +using System; +using System.Threading.Tasks; +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Table; +using Models; + +namespace L04 +{ + class Program + { + private static CloudTableClient tableClient; + + private static CloudTable studentsTable; + + static void Main(string[] args) + { + Task.Run(async () => { await Initialize(); }) + .GetAwaiter() + .GetResult(); + } + + static async Task Initialize() + { + string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=tema4cornea;AccountKey=eBPbPNhE+pOnBrNuypRsTH7WPp5e9QLs10SSuj4uGjSYjz9G58VzWx1MpOqZBZSZbC7W7Ay6EfEG8QAm+89qFg==;EndpointSuffix=core.windows.net"; + var account = CloudStorageAccount.Parse(storageConnectionString); + tableClient = account.CreateCloudTableClient(); + + studentsTable = tableClient.GetTableReference("studenti"); + + await studentsTable.CreateIfNotExistsAsync(); + + await AddNewStudent(); + await GetAllStudents(); + } + + private static async Task GetAllStudents() + { + Console.WriteLine("Universitate\tCNP\tNume\tEmail\tNumar telefon\tAn"); + TableQuery query = new TableQuery(); + + TableContinuationToken token = null; + do + { + TableQuerySegment resultSegment = await studentsTable.ExecuteQuerySegmentedAsync(query, token); + token = resultSegment.ContinuationToken; + + foreach (StudentEntity entity in resultSegment.Results) + { + Console.WriteLine("{0}\t{1}\t{2} {3}\t{4}\t{5}\t{6}", entity.PartitionKey, entity.RowKey, entity.FirstName, entity.LastName, + entity.Email, entity.PhoneNumber, entity.Year); + } + } while (token != null); + } + + private static async Task AddNewStudent() + { + var student = new StudentEntity("UPT", "1990215350085"); + + student.FirstName = "Cristian"; + student.LastName = "Cornea"; + student.Email = "cristi.1990.cristi@gmail.com"; + student.Year = 4; + student.PhoneNumber = "0711070122"; + student.Faculty = "AC"; + + var insertOperation = TableOperation.Insert(student); + + await studentsTable.ExecuteAsync(insertOperation); + } + } +} diff --git a/Cornea Cristian/L04/Student.cs b/Cornea Cristian/L04/Student.cs new file mode 100644 index 00000000..89306788 --- /dev/null +++ b/Cornea Cristian/L04/Student.cs @@ -0,0 +1,28 @@ +using Microsoft.WindowsAzure.Storage.Table; + +namespace Models +{ + public class StudentEntity : TableEntity + { + public StudentEntity(string university, string cnp) + { + this.PartitionKey = university; + this.RowKey = cnp; + } + + public StudentEntity() { } + + public string FirstName { get; set; } + + public string LastName { get; set; } + + public string Email { get; set; } + + public int Year { get; set; } + + public string PhoneNumber { get; set; } + + public string Faculty { get; set; } + + } +} \ No newline at end of file diff --git a/Cornea Cristian/L05/IMetricRepository.cs b/Cornea Cristian/L05/IMetricRepository.cs new file mode 100644 index 00000000..f8784086 --- /dev/null +++ b/Cornea Cristian/L05/IMetricRepository.cs @@ -0,0 +1,8 @@ + +namespace L05 +{ + interface IMetricRepository + { + public void GenerateMetric(); + } +} diff --git a/Cornea Cristian/L05/IStudentsRepository.cs b/Cornea Cristian/L05/IStudentsRepository.cs new file mode 100644 index 00000000..72d97432 --- /dev/null +++ b/Cornea Cristian/L05/IStudentsRepository.cs @@ -0,0 +1,11 @@ +using L05.Models; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace L05 +{ + public interface IStudentsRepository + { + Task> GetAllStudents(); + } +} diff --git a/Cornea Cristian/L05/L05.csproj b/Cornea Cristian/L05/L05.csproj new file mode 100644 index 00000000..380508ed --- /dev/null +++ b/Cornea Cristian/L05/L05.csproj @@ -0,0 +1,12 @@ + + + + Exe + net5.0 + + + + + + + diff --git a/Cornea Cristian/L05/L05.sln b/Cornea Cristian/L05/L05.sln new file mode 100644 index 00000000..a3463475 --- /dev/null +++ b/Cornea Cristian/L05/L05.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31112.23 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "L05", "L05.csproj", "{BBC33372-C4A6-434B-A6EC-EAFD5B066EA0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BBC33372-C4A6-434B-A6EC-EAFD5B066EA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BBC33372-C4A6-434B-A6EC-EAFD5B066EA0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BBC33372-C4A6-434B-A6EC-EAFD5B066EA0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BBC33372-C4A6-434B-A6EC-EAFD5B066EA0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F6C5DE1E-929C-4EDE-9FC9-2F7ED5674221} + EndGlobalSection +EndGlobal diff --git a/Cornea Cristian/L05/Models/MetricEntity.cs b/Cornea Cristian/L05/Models/MetricEntity.cs new file mode 100644 index 00000000..fdba0400 --- /dev/null +++ b/Cornea Cristian/L05/Models/MetricEntity.cs @@ -0,0 +1,16 @@ +using Microsoft.WindowsAzure.Storage.Table; + +namespace L05.Models +{ + class MetricEntity:TableEntity + { + public MetricEntity(string university, string timestamp) + { + this.PartitionKey = university; + this.RowKey = timestamp; + } + public MetricEntity() { } + public int Count { get; set; } + + } +} diff --git a/Cornea Cristian/L05/Models/StudentEntity.cs b/Cornea Cristian/L05/Models/StudentEntity.cs new file mode 100644 index 00000000..3881e3b0 --- /dev/null +++ b/Cornea Cristian/L05/Models/StudentEntity.cs @@ -0,0 +1,21 @@ +using Microsoft.WindowsAzure.Storage.Table; + +namespace L05.Models +{ + public class StudentEntity: TableEntity + { + public StudentEntity(string university, string cnp) + { + this.PartitionKey = university; + this.RowKey = cnp; + } + public StudentEntity() { } + public string FirstName { get; set; } + public string LastName { get; set; } + public string Email { get; set; } + public int Year { get; set; } + public string PhoneNumber { get; set; } + public string Faculty { get; set; } + + } +} diff --git a/Cornea Cristian/L05/Program.cs b/Cornea Cristian/L05/Program.cs new file mode 100644 index 00000000..6151ad56 --- /dev/null +++ b/Cornea Cristian/L05/Program.cs @@ -0,0 +1,18 @@ +using L05.Repository; + +namespace L05 +{ + class Program + { + private static IStudentsRepository _studentsRepository; + private static IMetricRepository _metricRepository; + + static void Main() + { + _studentsRepository = new StudentsRepository(); + _metricRepository = new MetricRepository(_studentsRepository.GetAllStudents().Result); + _metricRepository.GenerateMetric(); + + } + } +} diff --git a/Cornea Cristian/L05/Repository/MetricRepository.cs b/Cornea Cristian/L05/Repository/MetricRepository.cs new file mode 100644 index 00000000..2538aab3 --- /dev/null +++ b/Cornea Cristian/L05/Repository/MetricRepository.cs @@ -0,0 +1,72 @@ +using L05.Models; +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Table; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace L05.Repository +{ + class MetricRepository:IMetricRepository + { + private CloudTableClient _tableClient; + private CloudTable _metricTable; + private string _connectionString; + private List students; + private async Task InitializeTable() + { + var account = CloudStorageAccount.Parse(_connectionString); + _tableClient = account.CreateCloudTableClient(); + _metricTable = _tableClient.GetTableReference("metric"); + await _metricTable.CreateIfNotExistsAsync(); + } + private async Task InsertMetric(MetricEntity metric) + { + var insertOperation = TableOperation.Insert(metric); + await _metricTable.ExecuteAsync(insertOperation); + } + public MetricRepository(List _students) + { + students = _students; + _connectionString = "DefaultEndpointsProtocol=https;AccountName=laborator4danmircea;AccountKey=jnnBmoGcigMef3GK85zPFcnuDE7x5kC4KnzZqRYGzj1RvU6Tmk3QgxekDCR9aZDVilKFrVood2R/Tr1Zrg1jwQ==;EndpointSuffix=core.windows.net"; + Task.Run(async () => { await InitializeTable(); }) + .GetAwaiter() + .GetResult(); + } + public void GenerateMetric() + { + MetricEntity metric; + int count; + List facultati = new List(); + foreach (var student in students) + { + if (!facultati.Contains(student.PartitionKey)) + facultati.Add(student.PartitionKey); + } + foreach (var facultate in facultati) + { + count = 0; + foreach (var student in students) + { + if (student.PartitionKey == facultate) + count++; + } + metric = new MetricEntity(facultate, DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString()); + metric.Count = count; + Task.Run(async () => { await InsertMetric(metric); }) + .GetAwaiter() + .GetResult(); + } + count = 0; + foreach(var student in students) + { + count++; + } + metric = new MetricEntity("General", DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString()); + metric.Count = count; + Task.Run(async () => { await InsertMetric(metric); }) + .GetAwaiter() + .GetResult(); + } + } +} diff --git a/Cornea Cristian/L05/Repository/StudentsRepository.cs b/Cornea Cristian/L05/Repository/StudentsRepository.cs new file mode 100644 index 00000000..5cfa1566 --- /dev/null +++ b/Cornea Cristian/L05/Repository/StudentsRepository.cs @@ -0,0 +1,45 @@ +using L05.Models; +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Table; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace L05.Repository +{ + public class StudentsRepository:IStudentsRepository + { + private CloudTableClient _tableClient; + private CloudTable _studentsTable; + private string _connectionString; + + private async Task InitializeTable() + { + var account = CloudStorageAccount.Parse(_connectionString); + _tableClient = account.CreateCloudTableClient(); + _studentsTable = _tableClient.GetTableReference("studenti"); + await _studentsTable.CreateIfNotExistsAsync(); + } + + public StudentsRepository() + { + _connectionString = "DefaultEndpointsProtocol=https;AccountName=tema4cornea;AccountKey=eBPbPNhE+pOnBrNuypRsTH7WPp5e9QLs10SSuj4uGjSYjz9G58VzWx1MpOqZBZSZbC7W7Ay6EfEG8QAm+89qFg==;EndpointSuffix=core.windows.net"; + Task.Run(async () => { await InitializeTable(); }) + .GetAwaiter() + .GetResult(); + } + + public async Task> GetAllStudents() + { + var students = new List(); + TableQuery query = new TableQuery(); + TableContinuationToken token = null; + do + { + TableQuerySegment resultSegment = await _studentsTable.ExecuteQuerySegmentedAsync(query, token); + token = resultSegment.ContinuationToken; + students.AddRange(resultSegment); + } while (token != null); + return students; + } + } +} diff --git a/Cornea Cristian/L06/L06.csproj b/Cornea Cristian/L06/L06.csproj new file mode 100644 index 00000000..74abf5c9 --- /dev/null +++ b/Cornea Cristian/L06/L06.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/Cornea Cristian/L06/Program.cs b/Cornea Cristian/L06/Program.cs new file mode 100644 index 00000000..3751555c --- /dev/null +++ b/Cornea Cristian/L06/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!");