diff --git a/Ureche Constantin-Adrian/L01/Steam.txt b/Ureche Constantin-Adrian/L01/Steam.txt new file mode 100644 index 00000000..b8fcfed0 --- /dev/null +++ b/Ureche Constantin-Adrian/L01/Steam.txt @@ -0,0 +1,6 @@ +Steam este un serviciu de distributie digitala pentru jocuri video. +Acesta s-a extins si intr-o vitrina digitala online și mobila online. +Steam ofera servicii de gestionare a drepturilor digitale (DRM), gazduire server, streaming video si servicii de retele sociale . +De asemenea, ofera utilizatorului instalarea si actualizarea automata a jocurilor si caracteristici ale comunitatii, cum ar fi listele si grupurile de prieteni, stocarea în cloud și functionalitatea de voce si chat în joc. +Valve a inclus suport beta pentru Steam Cloud Play in mai 2020, pentru ca dezvoltatorii să permita utilizatorilor sa joace jocuri în biblioteca lor, pe care dezvoltatorii si editorii au optat sa le permita intr-un serviciu de jocuri cloud . +La lansare, Steam Cloud Play a functionat numai prin serviciul GeForce Now al Nvidia si s-ar conecta la alte servicii cloud în viitor. \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L02/.vscode/launch.json b/Ureche Constantin-Adrian/L02/.vscode/launch.json new file mode 100644 index 00000000..5c7247b4 --- /dev/null +++ b/Ureche Constantin-Adrian/L02/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L02/Controllers/StudentsController.cs b/Ureche Constantin-Adrian/L02/Controllers/StudentsController.cs new file mode 100644 index 00000000..7e0d0691 --- /dev/null +++ b/Ureche Constantin-Adrian/L02/Controllers/StudentsController.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Models; +using Repositories; + +namespace L02.Controllers +{ + [ApiController] + [Route("[controller]")] + public class StudentsController : ControllerBase + { + [HttpGet] + public IEnumerable Get() + { + return StudentsRepo.Students; + } + + [HttpGet("{id}")] + public Student GetStudent(int id) + { + return StudentsRepo.Students.FirstOrDefault(s => s.Id == id); + } + + [HttpPost] + public void Post([FromBody] Student student) + { + StudentsRepo.Students.Add(student); + } + + [HttpPut("{id}")] + public void Update(int id, [FromBody] Student student) + { + StudentsRepo.Students[StudentsRepo.Students.IndexOf(StudentsRepo.Students.FirstOrDefault(s => s.Id == id))] = student; + } + + [HttpDelete("{id}")] + public void Delete(int id) + { + StudentsRepo.Students.RemoveAt(StudentsRepo.Students.IndexOf(StudentsRepo.Students.FirstOrDefault(s => s.Id == id))); + } + } +} diff --git a/Ureche Constantin-Adrian/L02/Controllers/WeatherForecastController.cs b/Ureche Constantin-Adrian/L02/Controllers/WeatherForecastController.cs new file mode 100644 index 00000000..4ee7aa34 --- /dev/null +++ b/Ureche Constantin-Adrian/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/Ureche Constantin-Adrian/L02/L02.csproj b/Ureche Constantin-Adrian/L02/L02.csproj new file mode 100644 index 00000000..28847161 --- /dev/null +++ b/Ureche Constantin-Adrian/L02/L02.csproj @@ -0,0 +1,11 @@ + + + + net5.0 + + + + + + + diff --git a/Ureche Constantin-Adrian/L02/Models/Student.cs b/Ureche Constantin-Adrian/L02/Models/Student.cs new file mode 100644 index 00000000..3ee72761 --- /dev/null +++ b/Ureche Constantin-Adrian/L02/Models/Student.cs @@ -0,0 +1,13 @@ +namespace Models +{ + public class Student + { + public int Id {get; set;} + public string Nume {get; set;} + public string Prenume {get; set;} + public string Facultate {get; set;} + public int An {get; set;} + + } + +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L02/Program.cs b/Ureche Constantin-Adrian/L02/Program.cs new file mode 100644 index 00000000..4b6626d7 --- /dev/null +++ b/Ureche Constantin-Adrian/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/Ureche Constantin-Adrian/L02/Properties/launchSettings.json b/Ureche Constantin-Adrian/L02/Properties/launchSettings.json new file mode 100644 index 00000000..17ba0201 --- /dev/null +++ b/Ureche Constantin-Adrian/L02/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:41650", + "sslPort": 44342 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "L02": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Ureche Constantin-Adrian/L02/Repositories/StudentsRepo.cs b/Ureche Constantin-Adrian/L02/Repositories/StudentsRepo.cs new file mode 100644 index 00000000..bc19fe5e --- /dev/null +++ b/Ureche Constantin-Adrian/L02/Repositories/StudentsRepo.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using Models; + + +namespace Repositories +{ + public class StudentsRepo + { + public static List Students = new List{ + new Student() {Id = 1, Nume = "Popescu", Prenume = "Ion", Facultate = "AC", An = 2}, + new Student() {Id = 2, Nume = "Ionescu", Prenume = "Alin", Facultate = "ETC", An = 3}, + new Student() {Id = 3, Nume = "Basescu", Prenume = "Traian", Facultate = "Vietii", An = 5} + }; + } + +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L02/Startup.cs b/Ureche Constantin-Adrian/L02/Startup.cs new file mode 100644 index 00000000..c1d0a527 --- /dev/null +++ b/Ureche Constantin-Adrian/L02/Startup.cs @@ -0,0 +1,59 @@ +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; +using Microsoft.OpenApi.Models; + +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(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "L02", Version = "v1" }); + }); + } + + // 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.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "L02 v1")); + } + + //app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Ureche Constantin-Adrian/L02/WeatherForecast.cs b/Ureche Constantin-Adrian/L02/WeatherForecast.cs new file mode 100644 index 00000000..0c25b27d --- /dev/null +++ b/Ureche Constantin-Adrian/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/Ureche Constantin-Adrian/L02/appsettings.Development.json b/Ureche Constantin-Adrian/L02/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/Ureche Constantin-Adrian/L02/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Ureche Constantin-Adrian/L02/appsettings.json b/Ureche Constantin-Adrian/L02/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/Ureche Constantin-Adrian/L02/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/Ureche Constantin-Adrian/L03/.vscode/launch.json b/Ureche Constantin-Adrian/L03/.vscode/launch.json new file mode 100644 index 00000000..9eb9714d --- /dev/null +++ b/Ureche Constantin-Adrian/L03/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/net5.0/L03.dll", + "args": [], + "cwd": "${workspaceFolder}", + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L03/.vscode/tasks.json b/Ureche Constantin-Adrian/L03/.vscode/tasks.json new file mode 100644 index 00000000..f6ce6dca --- /dev/null +++ b/Ureche Constantin-Adrian/L03/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/L03.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/L03.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/L03.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L03/L03.csproj b/Ureche Constantin-Adrian/L03/L03.csproj new file mode 100644 index 00000000..9b82f441 --- /dev/null +++ b/Ureche Constantin-Adrian/L03/L03.csproj @@ -0,0 +1,12 @@ + + + + Exe + net5.0 + + + + + + + diff --git a/Ureche Constantin-Adrian/L03/Program.cs b/Ureche Constantin-Adrian/L03/Program.cs new file mode 100644 index 00000000..300de3c9 --- /dev/null +++ b/Ureche Constantin-Adrian/L03/Program.cs @@ -0,0 +1,107 @@ +using System.Net; +using Google.Apis.Auth.OAuth2; +using Google.Apis.Drive.v3; +using Google.Apis.Drive.v3.Data; +using Google.Apis.Services; +using Google.Apis.Util.Store; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; + +namespace DriveQuickstart +{ + class Program + { + private static DriveService _service; + private static string _token; + static void Main(string[] args) + { + Initialize(); + + Console.WriteLine("File upload response" + UploadFile(System.IO.File.Open("C:\\Users\\Adr\\OneDrive\\DATC\\L03\\random.txt",FileMode.Open),"random.txt","text/plain")); + } + + static void Initialize() + { + string[] scopes = new string[]{ + DriveService.Scope.Drive, + DriveService.Scope.DriveFile + }; + + var clientId = "47506398974-q081i9od0n6m98iii3652dbp5tho3e8o.apps.googleusercontent.com"; + var clientSectret = "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"; + + var credential = GoogleWebAuthorizationBroker.AuthorizeAsync( + new ClientSecrets + { + ClientId = clientId, + ClientSecret = clientSectret + }, + scopes, + Environment.UserName, + CancellationToken.None, + + new FileDataStore("Daimto.GoogleDrive.Auth.Store3") + ).Result; + + _service = new DriveService(new Google.Apis.Services.BaseClientService.Initializer() + { + HttpClientInitializer = credential + }); + + _token = credential.Token.AccessToken; + + Console.Write("Token: " + credential.Token.AccessToken); + + GetMyFiles(); + } + + static void GetMyFiles() + { + 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 string UploadFile(Stream file, string fileName, string fileMime) + { + + var driveFile = new Google.Apis.Drive.v3.Data.File(); + driveFile.Name = fileName; + // driveFile.Description = fileDescription; + driveFile.MimeType = fileMime; + //driveFile.Parents = new string[] { folder }; + + var request = _service.Files.Create(driveFile, file, fileMime); + request.Fields = "id"; + + var response = request.Upload(); + if (response.Status != Google.Apis.Upload.UploadStatus.Completed) + throw response.Exception; + + return request.ResponseBody.Id; + } + + } +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L04/.vscode/launch.json b/Ureche Constantin-Adrian/L04/.vscode/launch.json new file mode 100644 index 00000000..40c3da4d --- /dev/null +++ b/Ureche Constantin-Adrian/L04/.vscode/launch.json @@ -0,0 +1,35 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/net5.0/L04.dll", + "args": [], + "cwd": "${workspaceFolder}", + "stopAtEntry": false, + // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L04/.vscode/settings.json b/Ureche Constantin-Adrian/L04/.vscode/settings.json new file mode 100644 index 00000000..fad95218 --- /dev/null +++ b/Ureche Constantin-Adrian/L04/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "appService.deploySubpath": "publish" +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L04/.vscode/tasks.json b/Ureche Constantin-Adrian/L04/.vscode/tasks.json new file mode 100644 index 00000000..818d4de5 --- /dev/null +++ b/Ureche Constantin-Adrian/L04/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/L04.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/L04.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/L04.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L04/Controllers/StudentsController.cs b/Ureche Constantin-Adrian/L04/Controllers/StudentsController.cs new file mode 100644 index 00000000..886a3434 --- /dev/null +++ b/Ureche Constantin-Adrian/L04/Controllers/StudentsController.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Models; + +namespace L04.Controllers +{ + [ApiController] + [Route("[controller]")] + public class StudentsController : ControllerBase + { + private IStudentRepository _studentRepository; + + public StudentsController(IStudentRepository studentRepository) + { + _studentRepository = studentRepository; + } + + [HttpGet] + public async Task> Get() + { + return await _studentRepository.GetAllStudents(); + } + + [HttpGet("{PartitionKey}/{RowKey}")] + public async Task Get(string PartitionKey, string RowKey) + { + return await _studentRepository.GetStudent(PartitionKey, RowKey); + } + + // [HttpGet("{id}")] + // public Student GetStudent(int id) + // { + // return StudentsRepo.Students.FirstOrDefault(s => s.Id == id); + // } + + [HttpPost] + public async Task Post([FromBody] StudentEntity student) + { + try + { + await _studentRepository.CreateStudent(student); + } + catch (System.Exception) + { + + throw; + } + } + + [HttpPut("{PartitionKey}/{RowKey}")] + public async Task Update(string PartitionKey, string RowKey, [FromBody] StudentEntity student) + { + try + { + await _studentRepository.Modify(PartitionKey, RowKey, student); + } + catch (System.Exception) + { + + throw; + } + } + + + [HttpDelete("{PartitionKey}/{RowKey}")] + public async Task Delete(string PartitionKey, string RowKey) + { + try + { + await _studentRepository.Delete(PartitionKey, RowKey); + } + catch (System.Exception) + { + + throw; + } + } + } +} diff --git a/Ureche Constantin-Adrian/L04/IStudentRepository.cs b/Ureche Constantin-Adrian/L04/IStudentRepository.cs new file mode 100644 index 00000000..c3aa7f0c --- /dev/null +++ b/Ureche Constantin-Adrian/L04/IStudentRepository.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Models; + +public interface IStudentRepository{ + Task> GetAllStudents(); + + Task GetStudent(string partKey, string rowKey); + + Task Modify(string partKey, string rowKey, StudentEntity student); + + Task Delete(string partKey, string rowKey); + Task CreateStudent(StudentEntity student); +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L04/L04.csproj b/Ureche Constantin-Adrian/L04/L04.csproj new file mode 100644 index 00000000..5c1d7a6f --- /dev/null +++ b/Ureche Constantin-Adrian/L04/L04.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + + + + + + + + diff --git a/Ureche Constantin-Adrian/L04/Models/StudentEntity.cs b/Ureche Constantin-Adrian/L04/Models/StudentEntity.cs new file mode 100644 index 00000000..bd19ac01 --- /dev/null +++ b/Ureche Constantin-Adrian/L04/Models/StudentEntity.cs @@ -0,0 +1,23 @@ +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/Ureche Constantin-Adrian/L04/Program.cs b/Ureche Constantin-Adrian/L04/Program.cs new file mode 100644 index 00000000..fce82a88 --- /dev/null +++ b/Ureche Constantin-Adrian/L04/Program.cs @@ -0,0 +1,94 @@ +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; +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Table; +using Models; + +namespace L04 +{ + 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(); + }); + + + + // private static CloudTableClient tableClient; + // private static CloudTable studentsTable; + // public static void Main(string[] args) + // { + // Task.Run(async () => { await Initialize(); }) + // .GetAwaiter() + // .GetResult(); + + + // } + + + // static async Task Initialize() + // { + // string storageConnectionString = "DefaultEndpointsProtocol=https;" + // + "AccountName=azurestoragel4;" + // + "AccountKey=nlnYBvUdjFydTzfMteH2T9IrZqWAP3b5oRWskgJHOm9WjGmTadD6QdRM5Xa9zHA63Z8fPwqmOfFa6NnqPU4/zw==;" + // + "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 AddNewStudent() + // { + // var student = new StudentEntity("UVT", "1234567890"); + // student.FirstName = "Gigi"; + // student.LastName = "Becali"; + // student.Email = "oita.nebuna@fcsb.ro"; + // student.Year = -1; + // student.PhoneNumber = "0767777777"; + // student.Faculty = "AC"; + + // var insertOperation = TableOperation.Insert(student); + + // await studentsTable.ExecuteAsync(insertOperation); + // } + + // private static async Task GetAllStudents() + // { + // Console.WriteLine("UNIVERSITATE\tCNP\tNUME\tPRENUME\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}", entity.PartitionKey, entity.RowKey, entity.FirstName, entity.LastName, entity.PhoneNumber, entity.Year); + + // }while(token != null); + // } + } +} diff --git a/Ureche Constantin-Adrian/L04/Properties/launchSettings.json b/Ureche Constantin-Adrian/L04/Properties/launchSettings.json new file mode 100644 index 00000000..8913873f --- /dev/null +++ b/Ureche Constantin-Adrian/L04/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:45218", + "sslPort": 44338 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "L04": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Ureche Constantin-Adrian/L04/Startup.cs b/Ureche Constantin-Adrian/L04/Startup.cs new file mode 100644 index 00000000..af46682c --- /dev/null +++ b/Ureche Constantin-Adrian/L04/Startup.cs @@ -0,0 +1,60 @@ +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; +using Microsoft.OpenApi.Models; + +namespace L04 +{ + 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(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "L04", Version = "v1" }); + }); + services.AddScoped(); + } + + // 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.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "L04 v1")); + //} + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Ureche Constantin-Adrian/L04/StudentsRepo.cs b/Ureche Constantin-Adrian/L04/StudentsRepo.cs new file mode 100644 index 00000000..224a1d8d --- /dev/null +++ b/Ureche Constantin-Adrian/L04/StudentsRepo.cs @@ -0,0 +1,129 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Table; +using Models; + + +namespace L04 +{ + public class StudentsRepository : IStudentRepository + { + private CloudTableClient _tableClient; + + private CloudTable _studentsTable; + + private string _connectionString = "DefaultEndpointsProtocol=https;" + + "AccountName=azurestoragel4;" + + "AccountKey=nlnYBvUdjFydTzfMteH2T9IrZqWAP3b5oRWskgJHOm9WjGmTadD6QdRM5Xa9zHA63Z8fPwqmOfFa6NnqPU4/zw==;" + + "EndpointSuffix=core.windows.net"; + + public StudentsRepository(IConfiguration configuration) + { + _connectionString = "DefaultEndpointsProtocol=https;" + + "AccountName=azurestoragel4;" + + "AccountKey=nlnYBvUdjFydTzfMteH2T9IrZqWAP3b5oRWskgJHOm9WjGmTadD6QdRM5Xa9zHA63Z8fPwqmOfFa6NnqPU4/zw==;" + + "EndpointSuffix=core.windows.net"; + + Task.Run(async () => {await InitializeTable();}) + .GetAwaiter() + .GetResult(); + } + + public async Task CreateStudent(StudentEntity student) + { + var insertOperation = TableOperation.Insert(student); + + await _studentsTable.ExecuteAsync(insertOperation); + } + + 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.Results); + }while (token != null); + + return students; + + } + + public async Task GetStudent(string partKey, string rowKey) + { + var students = new StudentEntity(); + + TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partKey)).Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey)); + + TableContinuationToken token = null; + + do + { + TableQuerySegment resultSegment = await _studentsTable.ExecuteQuerySegmentedAsync(query, token); + token = resultSegment.ContinuationToken; + + students = resultSegment.Results[0]; + }while (token != null); + + return students; + + } + + public async Task Modify(string partKey, string rowKey, StudentEntity student) + { + TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partKey)).Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey)); + + TableContinuationToken token = null; + + do + { + TableQuerySegment resultSegment = await _studentsTable.ExecuteQuerySegmentedAsync(query, token); + token = resultSegment.ContinuationToken; + + var del = TableOperation.InsertOrReplace(student); + await _studentsTable.ExecuteAsync(del); + }while (token != null); + } + + public async Task Delete(string partKey, string rowKey) + { + TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partKey)).Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey)); + + TableContinuationToken token = null; + + do + { + TableQuerySegment resultSegment = await _studentsTable.ExecuteQuerySegmentedAsync(query, token); + token = resultSegment.ContinuationToken; + + var del = TableOperation.Delete(resultSegment.Results[0]); + await _studentsTable.ExecuteAsync(del); + }while (token != null); + } + + private async Task InitializeTable() + { + _connectionString = "DefaultEndpointsProtocol=https;" + + "AccountName=azurestoragel4;" + + "AccountKey=nlnYBvUdjFydTzfMteH2T9IrZqWAP3b5oRWskgJHOm9WjGmTadD6QdRM5Xa9zHA63Z8fPwqmOfFa6NnqPU4/zw==;" + + "EndpointSuffix=core.windows.net"; + + var account = CloudStorageAccount.Parse(_connectionString); + _tableClient = account.CreateCloudTableClient(); + + _studentsTable = _tableClient.GetTableReference("studenti"); + + await _studentsTable.CreateIfNotExistsAsync(); + } + } + +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L04/appsettings.Development.json b/Ureche Constantin-Adrian/L04/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/Ureche Constantin-Adrian/L04/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Ureche Constantin-Adrian/L04/appsettings.json b/Ureche Constantin-Adrian/L04/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/Ureche Constantin-Adrian/L04/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/Ureche Constantin-Adrian/L05/L05.csproj b/Ureche Constantin-Adrian/L05/L05.csproj new file mode 100644 index 00000000..380508ed --- /dev/null +++ b/Ureche Constantin-Adrian/L05/L05.csproj @@ -0,0 +1,12 @@ + + + + Exe + net5.0 + + + + + + + diff --git a/Ureche Constantin-Adrian/L05/Models/RaportEntity.cs b/Ureche Constantin-Adrian/L05/Models/RaportEntity.cs new file mode 100644 index 00000000..d33a8d38 --- /dev/null +++ b/Ureche Constantin-Adrian/L05/Models/RaportEntity.cs @@ -0,0 +1,21 @@ +using System; +using System.Globalization; +using Microsoft.WindowsAzure.Storage.Table; + +namespace Models +{ + public class RaportEntity : TableEntity + { + public RaportEntity(string university, int count) + { + this.PartitionKey = university; + this.RowKey = DateTime.Now.ToString("HH:mm:ss"); + this.Count = count; + } + + public RaportEntity(){} + public int Count {get; set;} + + } + +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L05/Models/StudentEntity.cs b/Ureche Constantin-Adrian/L05/Models/StudentEntity.cs new file mode 100644 index 00000000..bd19ac01 --- /dev/null +++ b/Ureche Constantin-Adrian/L05/Models/StudentEntity.cs @@ -0,0 +1,23 @@ +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/Ureche Constantin-Adrian/L05/Program.cs b/Ureche Constantin-Adrian/L05/Program.cs new file mode 100644 index 00000000..9f084697 --- /dev/null +++ b/Ureche Constantin-Adrian/L05/Program.cs @@ -0,0 +1,94 @@ +using System.Reflection.Emit; +using System.Data; +//using Internal; +using System.IO; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Table; +using Models; + +namespace L05 +{ + class Program + { + private static CloudTable _studentsTable; + private static CloudTable _raportTable; + + static async Task Main(string[] args) + { + await InitializeRaportTable(); + OpenStudentTable(); + + List students = await GetAllStudents(); + + var mapStud = new Dictionary(); + int cntGeneral = 0; + foreach(StudentEntity s in students) + { + if(mapStud.ContainsKey(s.PartitionKey)) + mapStud[s.PartitionKey]++; + else + mapStud[s.PartitionKey] = 1; + + cntGeneral++; + } + + Console.Write(DateTime.Now.ToString("HH:mm:ss") + ": "); + foreach(KeyValuePair s in mapStud) + { + RaportEntity raportEntity = new RaportEntity(s.Key, s.Value); + await CreateRaport(raportEntity); + Console.Write(s.Key + "->" + s.Value + "; "); + } + RaportEntity raportEntity2 = new RaportEntity("General", cntGeneral); + await CreateRaport(raportEntity2); + Console.WriteLine("General->" + cntGeneral.ToString()); + } + + + public static 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.Results); + }while (token != null); + + return students; + } + + public static async Task CreateRaport(RaportEntity raport) + { + var insertOperation = TableOperation.Insert(raport); + + await _raportTable.ExecuteAsync(insertOperation); + } + private static void OpenStudentTable() + { + string _connectionString = "DefaultEndpointsProtocol=https;" + + "AccountName=azurestoragel4;" + + "AccountKey=nlnYBvUdjFydTzfMteH2T9IrZqWAP3b5oRWskgJHOm9WjGmTadD6QdRM5Xa9zHA63Z8fPwqmOfFa6NnqPU4/zw==;" + + "EndpointSuffix=core.windows.net"; + + _studentsTable = CloudStorageAccount.Parse(_connectionString).CreateCloudTableClient().GetTableReference("studenti"); + } + private static async Task InitializeRaportTable() + { + string _connectionString = "DefaultEndpointsProtocol=https;AccountName=raportstoragel5;AccountKey=HcmheNNr2tLQszIdzdoS/ylPkWZCwC+vtEVvFteRtSXrmodZhKiijopnG5/o6os9BcyEohdLg27DUAtclAXjJQ==;EndpointSuffix=core.windows.net"; + + _raportTable = CloudStorageAccount.Parse(_connectionString).CreateCloudTableClient().GetTableReference("rapoarte"); + + await _raportTable.CreateIfNotExistsAsync(); + } + } +} diff --git a/Ureche Constantin-Adrian/L06-AzureFunction/.gitignore b/Ureche Constantin-Adrian/L06-AzureFunction/.gitignore new file mode 100644 index 00000000..ff5b00c5 --- /dev/null +++ b/Ureche Constantin-Adrian/L06-AzureFunction/.gitignore @@ -0,0 +1,264 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# Azure Functions localsettings file +local.settings.json + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/extensions.json b/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/extensions.json new file mode 100644 index 00000000..de991f40 --- /dev/null +++ b/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions", + "ms-dotnettools.csharp" + ] +} diff --git a/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/launch.json b/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/launch.json new file mode 100644 index 00000000..8d17a193 --- /dev/null +++ b/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to .NET Functions", + "type": "coreclr", + "request": "attach", + "processId": "${command:azureFunctions.pickProcess}" + } + ] +} diff --git a/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/settings.json b/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/settings.json new file mode 100644 index 00000000..08bfd7e9 --- /dev/null +++ b/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "azureFunctions.deploySubpath": "bin/Release/net5.0/publish", + "azureFunctions.projectLanguage": "C#", + "azureFunctions.projectRuntime": "~3", + "debug.internalConsoleOptions": "neverOpen", + "azureFunctions.preDeployTask": "publish (functions)" +} diff --git a/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/tasks.json b/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/tasks.json new file mode 100644 index 00000000..b50ad7f6 --- /dev/null +++ b/Ureche Constantin-Adrian/L06-AzureFunction/.vscode/tasks.json @@ -0,0 +1,69 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "clean (functions)", + "command": "dotnet", + "args": [ + "clean", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "type": "process", + "problemMatcher": "$msCompile" + }, + { + "label": "build (functions)", + "command": "dotnet", + "args": [ + "build", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "type": "process", + "dependsOn": "clean (functions)", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$msCompile" + }, + { + "label": "clean release (functions)", + "command": "dotnet", + "args": [ + "clean", + "--configuration", + "Release", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "type": "process", + "problemMatcher": "$msCompile" + }, + { + "label": "publish (functions)", + "command": "dotnet", + "args": [ + "publish", + "--configuration", + "Release", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "type": "process", + "dependsOn": "clean release (functions)", + "problemMatcher": "$msCompile" + }, + { + "type": "func", + "dependsOn": "build (functions)", + "options": { + "cwd": "${workspaceFolder}/bin/Debug/net5.0" + }, + "command": "host start", + "isBackground": true, + "problemMatcher": "$func-dotnet-watch" + } + ] +} diff --git a/Ureche Constantin-Adrian/L06-AzureFunction/CreateStudent.cs b/Ureche Constantin-Adrian/L06-AzureFunction/CreateStudent.cs new file mode 100644 index 00000000..a2b988dc --- /dev/null +++ b/Ureche Constantin-Adrian/L06-AzureFunction/CreateStudent.cs @@ -0,0 +1,25 @@ +using System.Runtime.Serialization; +using System; +using Microsoft.Azure.Functions.Worker; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Models; + +namespace Company.Function +{ + public static class CreateStudent + { + [Function("CreateStudent")] + [TableOutput("studenti")] + public static StudentEntity Run([QueueTrigger("students-queue", Connection = "azurestoragel4_STORAGE")] string myQueueItem, + FunctionContext context) + { + var logger = context.GetLogger("CreateStudent"); + logger.LogInformation($"C# Queue trigger function processed: {myQueueItem}"); + + var student = JsonConvert.DeserializeObject(myQueueItem); + + return student; + } + } +} diff --git a/Ureche Constantin-Adrian/L06-AzureFunction/L06 - Azure Function.csproj b/Ureche Constantin-Adrian/L06-AzureFunction/L06 - Azure Function.csproj new file mode 100644 index 00000000..e5482a32 --- /dev/null +++ b/Ureche Constantin-Adrian/L06-AzureFunction/L06 - Azure Function.csproj @@ -0,0 +1,24 @@ + + + net5.0 + v3 + Exe + L06___Azure_Function + + + + + + + + + + + PreserveNewest + + + PreserveNewest + Never + + + diff --git a/Ureche Constantin-Adrian/L06-AzureFunction/Program.cs b/Ureche Constantin-Adrian/L06-AzureFunction/Program.cs new file mode 100644 index 00000000..5f43cf8a --- /dev/null +++ b/Ureche Constantin-Adrian/L06-AzureFunction/Program.cs @@ -0,0 +1,19 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Azure.Functions.Worker.Configuration; + +namespace L06___Azure_Function +{ + public class Program + { + public static void Main() + { + var host = new HostBuilder() + .ConfigureFunctionsWorkerDefaults() + .Build(); + + host.Run(); + } + } +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L06-AzureFunction/StudentEntity.cs b/Ureche Constantin-Adrian/L06-AzureFunction/StudentEntity.cs new file mode 100644 index 00000000..17d7bbda --- /dev/null +++ b/Ureche Constantin-Adrian/L06-AzureFunction/StudentEntity.cs @@ -0,0 +1,23 @@ +using Microsoft.Azure.Cosmos.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/Ureche Constantin-Adrian/L06-AzureFunction/host.json b/Ureche Constantin-Adrian/L06-AzureFunction/host.json new file mode 100644 index 00000000..beb2e402 --- /dev/null +++ b/Ureche Constantin-Adrian/L06-AzureFunction/host.json @@ -0,0 +1,11 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + } +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L06/.gitignore b/Ureche Constantin-Adrian/L06/.gitignore new file mode 100644 index 00000000..ff5b00c5 --- /dev/null +++ b/Ureche Constantin-Adrian/L06/.gitignore @@ -0,0 +1,264 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# Azure Functions localsettings file +local.settings.json + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L06/.vscode/launch.json b/Ureche Constantin-Adrian/L06/.vscode/launch.json new file mode 100644 index 00000000..40c3da4d --- /dev/null +++ b/Ureche Constantin-Adrian/L06/.vscode/launch.json @@ -0,0 +1,35 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/net5.0/L04.dll", + "args": [], + "cwd": "${workspaceFolder}", + "stopAtEntry": false, + // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L06/.vscode/settings.json b/Ureche Constantin-Adrian/L06/.vscode/settings.json new file mode 100644 index 00000000..fad95218 --- /dev/null +++ b/Ureche Constantin-Adrian/L06/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "appService.deploySubpath": "publish" +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L06/.vscode/tasks.json b/Ureche Constantin-Adrian/L06/.vscode/tasks.json new file mode 100644 index 00000000..818d4de5 --- /dev/null +++ b/Ureche Constantin-Adrian/L06/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/L04.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/L04.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/L04.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L06/Controllers/StudentsController.cs b/Ureche Constantin-Adrian/L06/Controllers/StudentsController.cs new file mode 100644 index 00000000..886a3434 --- /dev/null +++ b/Ureche Constantin-Adrian/L06/Controllers/StudentsController.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Models; + +namespace L04.Controllers +{ + [ApiController] + [Route("[controller]")] + public class StudentsController : ControllerBase + { + private IStudentRepository _studentRepository; + + public StudentsController(IStudentRepository studentRepository) + { + _studentRepository = studentRepository; + } + + [HttpGet] + public async Task> Get() + { + return await _studentRepository.GetAllStudents(); + } + + [HttpGet("{PartitionKey}/{RowKey}")] + public async Task Get(string PartitionKey, string RowKey) + { + return await _studentRepository.GetStudent(PartitionKey, RowKey); + } + + // [HttpGet("{id}")] + // public Student GetStudent(int id) + // { + // return StudentsRepo.Students.FirstOrDefault(s => s.Id == id); + // } + + [HttpPost] + public async Task Post([FromBody] StudentEntity student) + { + try + { + await _studentRepository.CreateStudent(student); + } + catch (System.Exception) + { + + throw; + } + } + + [HttpPut("{PartitionKey}/{RowKey}")] + public async Task Update(string PartitionKey, string RowKey, [FromBody] StudentEntity student) + { + try + { + await _studentRepository.Modify(PartitionKey, RowKey, student); + } + catch (System.Exception) + { + + throw; + } + } + + + [HttpDelete("{PartitionKey}/{RowKey}")] + public async Task Delete(string PartitionKey, string RowKey) + { + try + { + await _studentRepository.Delete(PartitionKey, RowKey); + } + catch (System.Exception) + { + + throw; + } + } + } +} diff --git a/Ureche Constantin-Adrian/L06/IStudentRepository.cs b/Ureche Constantin-Adrian/L06/IStudentRepository.cs new file mode 100644 index 00000000..c3aa7f0c --- /dev/null +++ b/Ureche Constantin-Adrian/L06/IStudentRepository.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Models; + +public interface IStudentRepository{ + Task> GetAllStudents(); + + Task GetStudent(string partKey, string rowKey); + + Task Modify(string partKey, string rowKey, StudentEntity student); + + Task Delete(string partKey, string rowKey); + Task CreateStudent(StudentEntity student); +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L06/L04.csproj b/Ureche Constantin-Adrian/L06/L04.csproj new file mode 100644 index 00000000..06032303 --- /dev/null +++ b/Ureche Constantin-Adrian/L06/L04.csproj @@ -0,0 +1,14 @@ + + + + net5.0 + + + + + + + + + + diff --git a/Ureche Constantin-Adrian/L06/L06.csproj b/Ureche Constantin-Adrian/L06/L06.csproj new file mode 100644 index 00000000..bcdf58ae --- /dev/null +++ b/Ureche Constantin-Adrian/L06/L06.csproj @@ -0,0 +1,20 @@ + + + net5.0 + v3 + Exe + + + + + + + + PreserveNewest + + + PreserveNewest + Never + + + diff --git a/Ureche Constantin-Adrian/L06/Models/StudentEntity.cs b/Ureche Constantin-Adrian/L06/Models/StudentEntity.cs new file mode 100644 index 00000000..bd19ac01 --- /dev/null +++ b/Ureche Constantin-Adrian/L06/Models/StudentEntity.cs @@ -0,0 +1,23 @@ +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/Ureche Constantin-Adrian/L06/Program.cs b/Ureche Constantin-Adrian/L06/Program.cs new file mode 100644 index 00000000..47fa9ab7 --- /dev/null +++ b/Ureche Constantin-Adrian/L06/Program.cs @@ -0,0 +1,19 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Azure.Functions.Worker.Configuration; + +namespace L06 +{ + public class Program + { + public static void Main() + { + var host = new HostBuilder() + .ConfigureFunctionsWorkerDefaults() + .Build(); + + host.Run(); + } + } +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L06/Properties/launchSettings.json b/Ureche Constantin-Adrian/L06/Properties/launchSettings.json new file mode 100644 index 00000000..8913873f --- /dev/null +++ b/Ureche Constantin-Adrian/L06/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:45218", + "sslPort": 44338 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "L04": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Ureche Constantin-Adrian/L06/Startup.cs b/Ureche Constantin-Adrian/L06/Startup.cs new file mode 100644 index 00000000..af46682c --- /dev/null +++ b/Ureche Constantin-Adrian/L06/Startup.cs @@ -0,0 +1,60 @@ +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; +using Microsoft.OpenApi.Models; + +namespace L04 +{ + 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(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "L04", Version = "v1" }); + }); + services.AddScoped(); + } + + // 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.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "L04 v1")); + //} + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Ureche Constantin-Adrian/L06/StudentsRepo.cs b/Ureche Constantin-Adrian/L06/StudentsRepo.cs new file mode 100644 index 00000000..002164c8 --- /dev/null +++ b/Ureche Constantin-Adrian/L06/StudentsRepo.cs @@ -0,0 +1,144 @@ +using System.Security.AccessControl; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Table; +using Models; +using Newtonsoft.Json; +using Azure.Storage.Queues; + + +namespace L04 +{ + public class StudentsRepository : IStudentRepository + { + private CloudTableClient _tableClient; + + private CloudTable _studentsTable; + + private string _connectionString = "DefaultEndpointsProtocol=https;" + + "AccountName=azurestoragel4;" + + "AccountKey=nlnYBvUdjFydTzfMteH2T9IrZqWAP3b5oRWskgJHOm9WjGmTadD6QdRM5Xa9zHA63Z8fPwqmOfFa6NnqPU4/zw==;" + + "EndpointSuffix=core.windows.net"; + + public StudentsRepository(IConfiguration configuration) + { + _connectionString = "DefaultEndpointsProtocol=https;" + + "AccountName=azurestoragel4;" + + "AccountKey=nlnYBvUdjFydTzfMteH2T9IrZqWAP3b5oRWskgJHOm9WjGmTadD6QdRM5Xa9zHA63Z8fPwqmOfFa6NnqPU4/zw==;" + + "EndpointSuffix=core.windows.net"; + + Task.Run(async () => {await InitializeTable();}) + .GetAwaiter() + .GetResult(); + } + + public async Task CreateStudent(StudentEntity student) + { + //var insertOperation = TableOperation.Insert(student); + + //await _studentsTable.ExecuteAsync(insertOperation); + + var jsonStudent = JsonConvert.SerializeObject(student); + var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(jsonStudent); + var base64String = System.Convert.ToBase64String(plainTextBytes); + + QueueClient queueClient = new QueueClient( + _connectionString, + "students-queue" + ); + queueClient.CreateIfNotExists(); + + await queueClient.SendMessageAsync(base64String); + } + + 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.Results); + }while (token != null); + + return students; + + } + + public async Task GetStudent(string partKey, string rowKey) + { + var students = new StudentEntity(); + + TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partKey)).Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey)); + + TableContinuationToken token = null; + + do + { + TableQuerySegment resultSegment = await _studentsTable.ExecuteQuerySegmentedAsync(query, token); + token = resultSegment.ContinuationToken; + + students = resultSegment.Results[0]; + }while (token != null); + + return students; + + } + + public async Task Modify(string partKey, string rowKey, StudentEntity student) + { + TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partKey)).Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey)); + + TableContinuationToken token = null; + + do + { + TableQuerySegment resultSegment = await _studentsTable.ExecuteQuerySegmentedAsync(query, token); + token = resultSegment.ContinuationToken; + + var del = TableOperation.InsertOrReplace(student); + await _studentsTable.ExecuteAsync(del); + }while (token != null); + } + + public async Task Delete(string partKey, string rowKey) + { + TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partKey)).Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey)); + + TableContinuationToken token = null; + + do + { + TableQuerySegment resultSegment = await _studentsTable.ExecuteQuerySegmentedAsync(query, token); + token = resultSegment.ContinuationToken; + + var del = TableOperation.Delete(resultSegment.Results[0]); + await _studentsTable.ExecuteAsync(del); + }while (token != null); + } + + private async Task InitializeTable() + { + _connectionString = "DefaultEndpointsProtocol=https;" + + "AccountName=azurestoragel4;" + + "AccountKey=nlnYBvUdjFydTzfMteH2T9IrZqWAP3b5oRWskgJHOm9WjGmTadD6QdRM5Xa9zHA63Z8fPwqmOfFa6NnqPU4/zw==;" + + "EndpointSuffix=core.windows.net"; + + var account = CloudStorageAccount.Parse(_connectionString); + _tableClient = account.CreateCloudTableClient(); + + _studentsTable = _tableClient.GetTableReference("studenti"); + + await _studentsTable.CreateIfNotExistsAsync(); + } + } + +} \ No newline at end of file diff --git a/Ureche Constantin-Adrian/L06/appsettings.Development.json b/Ureche Constantin-Adrian/L06/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/Ureche Constantin-Adrian/L06/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Ureche Constantin-Adrian/L06/appsettings.json b/Ureche Constantin-Adrian/L06/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/Ureche Constantin-Adrian/L06/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/Ureche Constantin-Adrian/L06/host.json b/Ureche Constantin-Adrian/L06/host.json new file mode 100644 index 00000000..beb2e402 --- /dev/null +++ b/Ureche Constantin-Adrian/L06/host.json @@ -0,0 +1,11 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + } +} \ No newline at end of file