diff --git a/.gitignore b/.gitignore index dfcfd56f..2f1229f8 100644 --- a/.gitignore +++ b/.gitignore @@ -347,4 +347,4 @@ healthchecksdb MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder -.ionide/ +.ionide/ \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..de991f40 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions", + "ms-dotnettools.csharp" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..158208a9 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,36 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/Braila-Anamaria-Roxana/L06/TheAPI/bin/Debug/net5.0/TheAPI.dll", + "args": [], + "cwd": "${workspaceFolder}/Braila-Anamaria-Roxana/L06/TheAPI", + "stopAtEntry": false, + "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" + }, + { + "name": "Attach to .NET Functions", + "type": "coreclr", + "request": "attach", + "processId": "${command:azureFunctions.pickProcess}" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..2cef689a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "azureFunctions.deploySubpath": "Braila-Anamaria-Roxana\\L06\\AppFunction/bin/Release/net5.0/publish", + "azureFunctions.projectLanguage": "C#", + "azureFunctions.projectRuntime": "~3", + "debug.internalConsoleOptions": "neverOpen", + "azureFunctions.preDeployTask": "publish (functions)", + "azureFunctions.projectSubpath": "Braila-Anamaria-Roxana\\L06\\AppFunction\\bin\\Release\\net5.0\\publish" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..a01bceaf --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,118 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/Braila-Anamaria-Roxana/L02/L02.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/Braila-Anamaria-Roxana/L02/L02.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/Braila-Anamaria-Roxana/L02/L02.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "clean (functions)", + "command": "dotnet", + "args": [ + "clean", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "type": "process", + "problemMatcher": "$msCompile", + "options": { + "cwd": "${workspaceFolder}/Braila-Anamaria-Roxana\\L06\\AppFunction" + } + }, + { + "label": "build (functions)", + "command": "dotnet", + "args": [ + "build", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "type": "process", + "dependsOn": "clean (functions)", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$msCompile", + "options": { + "cwd": "${workspaceFolder}/Braila-Anamaria-Roxana\\L06\\AppFunction" + } + }, + { + "label": "clean release (functions)", + "command": "dotnet", + "args": [ + "clean", + "--configuration", + "Release", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "type": "process", + "problemMatcher": "$msCompile", + "options": { + "cwd": "${workspaceFolder}/Braila-Anamaria-Roxana\\L06\\AppFunction" + } + }, + { + "label": "publish (functions)", + "command": "dotnet", + "args": [ + "publish", + "--configuration", + "Release", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "type": "process", + "dependsOn": "clean release (functions)", + "problemMatcher": "$msCompile", + "options": { + "cwd": "${workspaceFolder}/Braila-Anamaria-Roxana\\L06\\AppFunction" + } + }, + { + "type": "func", + "dependsOn": "build (functions)", + "options": { + "cwd": "${workspaceFolder}/Braila-Anamaria-Roxana\\L06\\AppFunction/bin/Debug/net5.0" + }, + "command": "host start", + "isBackground": true, + "problemMatcher": "$func-dotnet-watch" + } + ] +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/.vscode/launch.json b/Braila-Anamaria-Roxana/.vscode/launch.json new file mode 100644 index 00000000..9e60528f --- /dev/null +++ b/Braila-Anamaria-Roxana/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "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 (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/L03/bin/Debug/net5.0/L03.dll", + "args": [], + "cwd": "${workspaceFolder}/L03", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/.vscode/tasks.json b/Braila-Anamaria-Roxana/.vscode/tasks.json new file mode 100644 index 00000000..3b267122 --- /dev/null +++ b/Braila-Anamaria-Roxana/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/L03/L03.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/L03/L03.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/L03/L03.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L01/Prezentare-SaaS.txt b/Braila-Anamaria-Roxana/L01/Prezentare-SaaS.txt new file mode 100644 index 00000000..3825f424 --- /dev/null +++ b/Braila-Anamaria-Roxana/L01/Prezentare-SaaS.txt @@ -0,0 +1,7 @@ +Pentru aceasta tema am hotarat sa prezint in cateva cuvinte GMAIL!! (Folosesc Gmail de mai bine de 2 ani, cred) +Gmail este o aplicatie web de email. Acest serviciu face parte din categoria SaaS (Software as a Service), iar furnizorul acestuia este Google. +Gestiunea acestei aplicatii (ce contine elemente precum: runtime, securitate si integritate, baze de date, servere, virtualizare, servere hardware, spatiu de stocare, retea) +nu reprezinta o ingrijorare pentru utilizatorul (in cazul de fata, eu), deoarece aceste serviciu vine cu un pachet complet, a carui interfata vine pregatita pentru a fi +utilizata in mod placut. Spre exemplu: scrierea de email-uri, trimiterea acestora, primirea unora etc. + +||heh..nu mai stiu ce sa zic:D|| diff --git a/Braila-Anamaria-Roxana/L02/.vscode/launch.json b/Braila-Anamaria-Roxana/L02/.vscode/launch.json new file mode 100644 index 00000000..a2eef202 --- /dev/null +++ b/Braila-Anamaria-Roxana/L02/.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/L02.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/Braila-Anamaria-Roxana/L02/.vscode/tasks.json b/Braila-Anamaria-Roxana/L02/.vscode/tasks.json new file mode 100644 index 00000000..f5ad8352 --- /dev/null +++ b/Braila-Anamaria-Roxana/L02/.vscode/tasks.json @@ -0,0 +1,42 @@ +/*{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/L02.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/L02.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/L02.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +}*/ \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L02/Controllers/StudentsController.cs b/Braila-Anamaria-Roxana/L02/Controllers/StudentsController.cs new file mode 100644 index 00000000..24b72771 --- /dev/null +++ b/Braila-Anamaria-Roxana/L02/Controllers/StudentsController.cs @@ -0,0 +1,65 @@ +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]/[action]")] + public class StudentsController : ControllerBase + { + [HttpGet] //READ operation + public IEnumerable Get() + { + return StudentsRepo.Students.OrderBy(x => x.Id); + } + [HttpGet("{id}")] //READ operation + public IActionResult Find(int id) + { + var studentsList = StudentsRepo.Students; + Student student = studentsList.Find(x => x.Id.Equals(id)); + if (student == null) + return NotFound(); + return Ok(student); + } + [HttpDelete("{id}")] //DELETE operation + public IActionResult Delete(int id) + { + var studentsList = StudentsRepo.Students; + Student student = studentsList.Find(x => x.Id.Equals(id)); + if (student == null) + return NotFound(); + return Ok(studentsList.Remove(student)); + } + [HttpPut] //UPDATE operation + public IActionResult Edit([FromBody] Student student) + { + var studentsList = StudentsRepo.Students; + Student status = studentsList.Find(x => x.Id.Equals(student.Id)); + if (status != null) + { + studentsList.RemoveAt(student.Id - 1); + studentsList.Add(student); + return Ok(); + } + return BadRequest(); + } + [HttpPost] //CREATE operation + public IActionResult Add([FromBody] Student student) + { + var studentsList = StudentsRepo.Students; + Student status = studentsList.Find(x => x.Id.Equals(student.Id)); + if (status == null) + { + studentsList.Add(student); + return Ok(); + } + return BadRequest(); + } + } +} diff --git a/Braila-Anamaria-Roxana/L02/Controllers/WeatherForecastController.cs b/Braila-Anamaria-Roxana/L02/Controllers/WeatherForecastController.cs new file mode 100644 index 00000000..4ee7aa34 --- /dev/null +++ b/Braila-Anamaria-Roxana/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/Braila-Anamaria-Roxana/L02/L02.csproj b/Braila-Anamaria-Roxana/L02/L02.csproj new file mode 100644 index 00000000..28847161 --- /dev/null +++ b/Braila-Anamaria-Roxana/L02/L02.csproj @@ -0,0 +1,11 @@ + + + + net5.0 + + + + + + + diff --git a/Braila-Anamaria-Roxana/L02/Models/Student.cs b/Braila-Anamaria-Roxana/L02/Models/Student.cs new file mode 100644 index 00000000..c7121732 --- /dev/null +++ b/Braila-Anamaria-Roxana/L02/Models/Student.cs @@ -0,0 +1,10 @@ +namespace Models +{ + public class Student + { + public int Id { get; set; } + public string Name { get; set; } + public string Faculty { get; set; } + public int Year { get; set; } + } +} diff --git a/Braila-Anamaria-Roxana/L02/Program.cs b/Braila-Anamaria-Roxana/L02/Program.cs new file mode 100644 index 00000000..4b6626d7 --- /dev/null +++ b/Braila-Anamaria-Roxana/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/Braila-Anamaria-Roxana/L02/Properties/launchSettings.json b/Braila-Anamaria-Roxana/L02/Properties/launchSettings.json new file mode 100644 index 00000000..798bf426 --- /dev/null +++ b/Braila-Anamaria-Roxana/L02/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:12827", + "sslPort": 44360 + } + }, + "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/Braila-Anamaria-Roxana/L02/Repositories/StudentsRepo.cs b/Braila-Anamaria-Roxana/L02/Repositories/StudentsRepo.cs new file mode 100644 index 00000000..c43a4d11 --- /dev/null +++ b/Braila-Anamaria-Roxana/L02/Repositories/StudentsRepo.cs @@ -0,0 +1,16 @@ +using Models; +using System.Collections.Generic; + +namespace Repositories +{ + public static class StudentsRepo + { + public static List Students = new List() + { + new Student(){Id=1, Name="Clarkson", Faculty="AC", Year=3}, + new Student(){Id=2, Name="Thompson", Faculty="MTP", Year=4}, + new Student(){Id=3, Name="Johnson", Faculty="EE", Year=3}, + new Student(){Id=4, Name="Bieber", Faculty="AC", Year=1} + }; + } +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L02/Startup.cs b/Braila-Anamaria-Roxana/L02/Startup.cs new file mode 100644 index 00000000..658da090 --- /dev/null +++ b/Braila-Anamaria-Roxana/L02/Startup.cs @@ -0,0 +1,62 @@ +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 Student Evidence Record"); + }); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Braila-Anamaria-Roxana/L02/WeatherForecast.cs b/Braila-Anamaria-Roxana/L02/WeatherForecast.cs new file mode 100644 index 00000000..0c25b27d --- /dev/null +++ b/Braila-Anamaria-Roxana/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/Braila-Anamaria-Roxana/L02/appsettings.Development.json b/Braila-Anamaria-Roxana/L02/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/Braila-Anamaria-Roxana/L02/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Braila-Anamaria-Roxana/L02/appsettings.json b/Braila-Anamaria-Roxana/L02/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/Braila-Anamaria-Roxana/L02/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/Braila-Anamaria-Roxana/L03/L03.csproj b/Braila-Anamaria-Roxana/L03/L03.csproj new file mode 100644 index 00000000..edbcd4db --- /dev/null +++ b/Braila-Anamaria-Roxana/L03/L03.csproj @@ -0,0 +1,12 @@ + + + + Exe + net5.0 + + + + + + + diff --git a/Braila-Anamaria-Roxana/L03/Program.cs b/Braila-Anamaria-Roxana/L03/Program.cs new file mode 100644 index 00000000..bfe8b253 --- /dev/null +++ b/Braila-Anamaria-Roxana/L03/Program.cs @@ -0,0 +1,99 @@ +using Google.Apis.Auth.OAuth2; +using Google.Apis.Drive.v3; +using Google.Apis.Services; +using Google.Apis.Util.Store; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Mime; +using System.Threading; +using System.Threading.Tasks; + +namespace L03 +{ + class Program + { + private static DriveService service; + private static string token; + static void Main(string[] args) + { + GetAccessToken(); + UploadFile(); + } + static void GetAccessToken() + { + var clientId = "369380080835-hf4mn9i2d4dvmb3uc1o3h86kevnf0jtn.apps.googleusercontent.com"; + var clientSecret = "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"; + + var clientSecrets = new ClientSecrets + { + ClientId = clientId, + ClientSecret = clientSecret + }; + + string[] scopes = new string[] + { + DriveService.Scope.Drive, + DriveService.Scope.DriveFile + }; + + var credential = GoogleWebAuthorizationBroker.AuthorizeAsync( + clientSecrets, + scopes, + Environment.UserName, + CancellationToken.None, + new FileDataStore("Daimto.GoogleDrive.Auth.Store") + ).Result; + + service = new DriveService(new Google.Apis.Services.BaseClientService.Initializer() + { HttpClientInitializer = credential }); + token = credential.Token.AccessToken; + Console.Write("Token: " + token); + + GetAllFiles(); + } + + 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 UploadFile() + { + using var stream = new MemoryStream(); + using var writer = new StreamWriter(stream); + writer.WriteLine("Token: ya29.a0ARrdaM9VK_x3V4dbvM7_6WwKNdybjvQ9JZKhBVZTesgBSckgeJBBc-t3ig8PrwbtyOl_zKeQv86zBTsMmZ-a6a6GeuFbs9wEduYCwQm2Jp2bpIL7cUXuoA15PlUCB7JsY64Qe02KzP7w_dywtCvyu_wr-Zbo"); + writer.Flush(); + stream.Position = 0; + + var file = new Google.Apis.Drive.v3.Data.File(); + file.Name = "Token.txt"; + file.Description = "The file contains a TOKEN"; + file.MimeType = MediaTypeNames.Text.Plain; + file.Parents = new string[] { "root" }; + var fileCreateRequest = service.Files.Create(file, stream, MediaTypeNames.Text.Plain); + fileCreateRequest.Upload(); + } + } +} diff --git a/Braila-Anamaria-Roxana/L04/Controllers/StudentsController.cs b/Braila-Anamaria-Roxana/L04/Controllers/StudentsController.cs new file mode 100644 index 00000000..c50553b9 --- /dev/null +++ b/Braila-Anamaria-Roxana/L04/Controllers/StudentsController.cs @@ -0,0 +1,58 @@ +using System.Dynamic; +using System.Net.Http; +using System.Collections; +using System; +using Microsoft.AspNetCore.Mvc; +using Models; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Net; + +namespace L04.Controllers +{ + [ApiController] + [Route("[controller]/[action]")] + public class StudentsController : ControllerBase + { + private IStudentRepository _studentRepository; + public StudentsController(IStudentRepository studentRepository) + { + _studentRepository = studentRepository; + } + [HttpGet] + public async Task> Get() + { + return await _studentRepository.GetAllStudents(); + } + [HttpGet("{university}/{cnp}")] // Search + public async Task Find(string university, string cnp) + { + var status = await _studentRepository.FindStudent(university, cnp); + if (status == null) + return NotFound(); + return Ok(status); + + } + [HttpPost] + public async Task Post([FromBody] StudentEntity student) + { + return await _studentRepository.CreateStudent(student).Match( + studentEntity => Ok(student), + error => (IActionResult)BadRequest()); + } + [HttpPut] + public async Task Edit([FromBody] StudentEntity student) + { + return await _studentRepository.EditStudent(student).Match( + studentEntity => Ok(student), + error => (IActionResult)BadRequest()); + } + [HttpDelete("{university}/{cnp}")] + public async Task Delete(string university, string cnp) + { + return await _studentRepository.DeleteStudent(university, cnp).Match( + unit => Ok(), + error => (IActionResult)BadRequest()); + } + } +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L04/Controllers/WeatherForecastController.cs b/Braila-Anamaria-Roxana/L04/Controllers/WeatherForecastController.cs new file mode 100644 index 00000000..9b78059d --- /dev/null +++ b/Braila-Anamaria-Roxana/L04/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 L04.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/Braila-Anamaria-Roxana/L04/L04.csproj b/Braila-Anamaria-Roxana/L04/L04.csproj new file mode 100644 index 00000000..69482c3a --- /dev/null +++ b/Braila-Anamaria-Roxana/L04/L04.csproj @@ -0,0 +1,10 @@ + + + net5.0 + + + + + + + \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L04/Models/StudentEntity.cs b/Braila-Anamaria-Roxana/L04/Models/StudentEntity.cs new file mode 100644 index 00000000..00b11b77 --- /dev/null +++ b/Braila-Anamaria-Roxana/L04/Models/StudentEntity.cs @@ -0,0 +1,25 @@ +using System; +using System.Net; +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 string PhoneNumber { get; set; } + public int Year { get; set; } + public string Faculty { get; set; } + } +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L04/Program.cs b/Braila-Anamaria-Roxana/L04/Program.cs new file mode 100644 index 00000000..2738bc4b --- /dev/null +++ b/Braila-Anamaria-Roxana/L04/Program.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +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; + +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(); + }); + } +} diff --git a/Braila-Anamaria-Roxana/L04/Properties/launchSettings.json b/Braila-Anamaria-Roxana/L04/Properties/launchSettings.json new file mode 100644 index 00000000..50419bd8 --- /dev/null +++ b/Braila-Anamaria-Roxana/L04/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:48127", + "sslPort": 44344 + } + }, + "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/Braila-Anamaria-Roxana/L04/Repositories/IStudentRepository.cs b/Braila-Anamaria-Roxana/L04/Repositories/IStudentRepository.cs new file mode 100644 index 00000000..8d816a8c --- /dev/null +++ b/Braila-Anamaria-Roxana/L04/Repositories/IStudentRepository.cs @@ -0,0 +1,17 @@ +using System.Runtime.CompilerServices; +using System.Dynamic; +using Models; +using Repositories; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using LanguageExt; + +public interface IStudentRepository +{ + Task> GetAllStudents(); + Task FindStudent(string university, string cnp); + TryAsync CreateStudent(StudentEntity student); + TryAsync EditStudent(StudentEntity student); + TryAsync DeleteStudent(string university, string cnp); +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L04/Repositories/StudentsRepository.cs b/Braila-Anamaria-Roxana/L04/Repositories/StudentsRepository.cs new file mode 100644 index 00000000..6902b2b5 --- /dev/null +++ b/Braila-Anamaria-Roxana/L04/Repositories/StudentsRepository.cs @@ -0,0 +1,78 @@ +using System.Data; +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Microsoft.WindowsAzure.Storage.Table; +using Models; +using System.Collections.Generic; +using Microsoft.WindowsAzure.Storage; +using System.Net; +using LanguageExt; + +namespace Repositories +{ + public class StudentsRepository : IStudentRepository + { + private CloudTableClient _tableClient; + private CloudTable _studentsTable; + private string _connectionString; + public StudentsRepository(IConfiguration configuration) + { + _connectionString = configuration.GetValue(typeof(string), "AzureStorageAccountConnectionString").ToString(); + Task.Run(async () => { await InitializeTable(); }) + .GetAwaiter() + .GetResult(); + } + public TryAsync CreateStudent(StudentEntity student) => async () => + { + var insertOperation = TableOperation.Insert(student); + var result = await _studentsTable.ExecuteAsync(insertOperation); + return (StudentEntity)result.Result; + }; + 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 FindStudent(string university, string cnp) + { + var partitionKey = university; + var rowKey = cnp; + + var query = TableOperation.Retrieve(partitionKey, rowKey); + var result = await _studentsTable.ExecuteAsync(query); + return (StudentEntity)result.Result; + } + public TryAsync EditStudent(StudentEntity student) => async () => + { + student.ETag = "*"; + + var editOperation = TableOperation.Merge(student); + var result = await _studentsTable.ExecuteAsync(editOperation); + return (StudentEntity)result.Result; + }; + public TryAsync DeleteStudent(string university, string cnp) => async () => + { + var deleteOperation = TableOperation.Delete(new TableEntity(university, cnp) { ETag = "*" }); + return await _studentsTable.ExecuteAsync(deleteOperation).ToUnit(); + }; + private async Task InitializeTable() + { + var account = CloudStorageAccount.Parse(_connectionString); + _tableClient = account.CreateCloudTableClient(); + _studentsTable = _tableClient.GetTableReference("studenti"); + + await _studentsTable.CreateIfNotExistsAsync(); + } + } +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L04/Startup.cs b/Braila-Anamaria-Roxana/L04/Startup.cs new file mode 100644 index 00000000..83046b6d --- /dev/null +++ b/Braila-Anamaria-Roxana/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; +using Repositories; + +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.AddSingleton(); + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "L04", 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", "L04 v1")); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Braila-Anamaria-Roxana/L04/StudentEntity.cs b/Braila-Anamaria-Roxana/L04/StudentEntity.cs new file mode 100644 index 00000000..e69de29b diff --git a/Braila-Anamaria-Roxana/L04/WeatherForecast.cs b/Braila-Anamaria-Roxana/L04/WeatherForecast.cs new file mode 100644 index 00000000..218a227f --- /dev/null +++ b/Braila-Anamaria-Roxana/L04/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace L04 +{ + 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/Braila-Anamaria-Roxana/L04/appsettings.Development.json b/Braila-Anamaria-Roxana/L04/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/Braila-Anamaria-Roxana/L04/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Braila-Anamaria-Roxana/L04/appsettings.json b/Braila-Anamaria-Roxana/L04/appsettings.json new file mode 100644 index 00000000..9818f95d --- /dev/null +++ b/Braila-Anamaria-Roxana/L04/appsettings.json @@ -0,0 +1,11 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "AzureStorageAccountConnectionString": "DefaultEndpointsProtocol=https;AccountName=azurestorageroxie;AccountKey=UJDHZBA32pLOOjw4WjLNkNcXKw2ds/pf8+cjbxfltTBJMVvwhLU6D0uKvtvM2vlt8T8vEBkDdtOMB408WTlDVQ==;EndpointSuffix=core.windows.net" +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L05/L05.csproj b/Braila-Anamaria-Roxana/L05/L05.csproj new file mode 100644 index 00000000..380508ed --- /dev/null +++ b/Braila-Anamaria-Roxana/L05/L05.csproj @@ -0,0 +1,12 @@ + + + + Exe + net5.0 + + + + + + + diff --git a/Braila-Anamaria-Roxana/L05/Models/MetricsEntity.cs b/Braila-Anamaria-Roxana/L05/Models/MetricsEntity.cs new file mode 100644 index 00000000..26dcfc3d --- /dev/null +++ b/Braila-Anamaria-Roxana/L05/Models/MetricsEntity.cs @@ -0,0 +1,20 @@ +using System; +using Microsoft.WindowsAzure.Storage.Table; + +namespace Models +{ + public class MetricsEntity : TableEntity + { + public MetricsEntity(string university, int count) + { + this.PartitionKey = university; + this.RowKey = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); + this.Count = count; + } + public MetricsEntity() + { + + } + public int Count { get; set; } + } +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L05/Models/StudentEntity.cs b/Braila-Anamaria-Roxana/L05/Models/StudentEntity.cs new file mode 100644 index 00000000..00b11b77 --- /dev/null +++ b/Braila-Anamaria-Roxana/L05/Models/StudentEntity.cs @@ -0,0 +1,25 @@ +using System; +using System.Net; +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 string PhoneNumber { get; set; } + public int Year { get; set; } + public string Faculty { get; set; } + } +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L05/Program.cs b/Braila-Anamaria-Roxana/L05/Program.cs new file mode 100644 index 00000000..87a80fa0 --- /dev/null +++ b/Braila-Anamaria-Roxana/L05/Program.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Table; +using Models; + +namespace L05 +{ + class Program + { + static async Task Main(string[] args) + { + string storageConnectionString = "DefaultEndpointsProtocol=https;" + + "AccountName=azurestorageroxie" + + ";AccountKey=UJDHZBA32pLOOjw4WjLNkNcXKw2ds/pf8+cjbxfltTBJMVvwhLU6D0uKvtvM2vlt8T8vEBkDdtOMB408WTlDVQ==" + + ";EndpointSuffix=core.windows.net"; + + var account = CloudStorageAccount.Parse(storageConnectionString); + var tableClient = account.CreateCloudTableClient(); + + var studentsTable = tableClient.GetTableReference("studenti"); + var studentsMetricsTable = tableClient.GetTableReference("metriciStudenti"); + + await studentsMetricsTable.CreateIfNotExistsAsync(); + + var students = new List(); + + TableQuery query = new TableQuery(); + TableContinuationToken token = null; + do + { + TableQuerySegment resultSegment = await studentsTable.ExecuteQuerySegmentedAsync(query, token); + token = resultSegment.ContinuationToken; + + } while (token != null); + + var metrics = from university in students.Select(a => a.PartitionKey).Distinct() + let count = students.Where(a => a.PartitionKey == university).Count() + select new MetricsEntity(university, count); + var tasks = from metric in metrics + let operation = TableOperation.Insert(metric) + select studentsMetricsTable.ExecuteAsync(operation); + await Task.WhenAll(tasks.Append(studentsMetricsTable.ExecuteAsync(TableOperation + .Insert(new MetricsEntity("General", students.Count))))); + } + + } +} diff --git a/Braila-Anamaria-Roxana/L05/publish.zip b/Braila-Anamaria-Roxana/L05/publish.zip new file mode 100644 index 00000000..ba01445d Binary files /dev/null and b/Braila-Anamaria-Roxana/L05/publish.zip differ diff --git a/Braila-Anamaria-Roxana/L06/AppFunction/.gitignore b/Braila-Anamaria-Roxana/L06/AppFunction/.gitignore new file mode 100644 index 00000000..ff5b00c5 --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/AppFunction/.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/Braila-Anamaria-Roxana/L06/AppFunction/AppFunction.csproj b/Braila-Anamaria-Roxana/L06/AppFunction/AppFunction.csproj new file mode 100644 index 00000000..851322bb --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/AppFunction/AppFunction.csproj @@ -0,0 +1,25 @@ + + + net5.0 + v3 + false + false + Exe + + + + + + + + + + + PreserveNewest + + + PreserveNewest + Never + + + \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L06/AppFunction/Program.cs b/Braila-Anamaria-Roxana/L06/AppFunction/Program.cs new file mode 100644 index 00000000..fcaf27c1 --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/AppFunction/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 AppFunction +{ + public class Program + { + public static void Main() + { + var host = new HostBuilder() + .ConfigureFunctionsWorkerDefaults() + .Build(); + + host.Run(); + } + } +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L06/AppFunction/QueueTrigger1.cs b/Braila-Anamaria-Roxana/L06/AppFunction/QueueTrigger1.cs new file mode 100644 index 00000000..a5a9a7c6 --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/AppFunction/QueueTrigger1.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.Azure.Functions.Worker; +using Microsoft.Extensions.Logging; +using Models; +using Newtonsoft.Json; + +namespace Company.Function +{ + public static class QueueTrigger1 + { + [Function("QueueTrigger1")] + [TableOutput("studenti")] + public static StudentEntity Run([QueueTrigger("students-q", Connection = "azurestorageroxie_STORAGE")] string myQueueItem, + FunctionContext context) + { + var logger = context.GetLogger("QueueTrigger1"); + logger.LogInformation($"C# Queue trigger function processed: {myQueueItem}"); + + var student = JsonConvert.DeserializeObject(myQueueItem); + return student; + } + } +} diff --git a/Braila-Anamaria-Roxana/L06/AppFunction/StudentEntity.cs b/Braila-Anamaria-Roxana/L06/AppFunction/StudentEntity.cs new file mode 100644 index 00000000..34e2250e --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/AppFunction/StudentEntity.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +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 string PhoneNumber { get; set; } + public int Year { get; set; } + public string Faculty { get; set; } + } +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L06/AppFunction/host.json b/Braila-Anamaria-Roxana/L06/AppFunction/host.json new file mode 100644 index 00000000..beb2e402 --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/AppFunction/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/Braila-Anamaria-Roxana/L06/TheAPI/Controllers/StudentsController.cs b/Braila-Anamaria-Roxana/L06/TheAPI/Controllers/StudentsController.cs new file mode 100644 index 00000000..dd89844e --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/Controllers/StudentsController.cs @@ -0,0 +1,56 @@ +using System.Dynamic; +using System.Net.Http; +using System.Collections; +using System; +using Microsoft.AspNetCore.Mvc; +using Models; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Net; + +namespace L06.Controllers +{ + [ApiController] + [Route("[controller]/[action]")] + public class StudentsController : ControllerBase + { + private IStudentRepository _studentRepository; + public StudentsController(IStudentRepository studentRepository) + { + _studentRepository = studentRepository; + } + [HttpGet] + public async Task> Get() + { + return await _studentRepository.GetAllStudents(); + } + [HttpGet("{university}/{cnp}")] // Search + public async Task Find(string university, string cnp) + { + var status = await _studentRepository.FindStudent(university, cnp); + if (status == null) + return NotFound(); + return Ok(status); + + } + [HttpPost] + public async Task Post([FromBody] StudentEntity student) + { + await _studentRepository.CreateStudent(student); + } + [HttpPut] + public async Task Edit([FromBody] StudentEntity student) + { + return await _studentRepository.EditStudent(student).Match( + studentEntity => Ok(student), + error => (IActionResult)BadRequest()); + } + [HttpDelete("{university}/{cnp}")] + public async Task Delete(string university, string cnp) + { + return await _studentRepository.DeleteStudent(university, cnp).Match( + unit => Ok(), + error => (IActionResult)BadRequest()); + } + } +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L06/TheAPI/Controllers/WeatherForecastController.cs b/Braila-Anamaria-Roxana/L06/TheAPI/Controllers/WeatherForecastController.cs new file mode 100644 index 00000000..463b0180 --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/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 TheAPI.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/Braila-Anamaria-Roxana/L06/TheAPI/Models/StudentEntity.cs b/Braila-Anamaria-Roxana/L06/TheAPI/Models/StudentEntity.cs new file mode 100644 index 00000000..00b11b77 --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/Models/StudentEntity.cs @@ -0,0 +1,25 @@ +using System; +using System.Net; +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 string PhoneNumber { get; set; } + public int Year { get; set; } + public string Faculty { get; set; } + } +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L06/TheAPI/Program.cs b/Braila-Anamaria-Roxana/L06/TheAPI/Program.cs new file mode 100644 index 00000000..fcacffdf --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/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 TheAPI +{ + 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/Braila-Anamaria-Roxana/L06/TheAPI/Properties/launchSettings.json b/Braila-Anamaria-Roxana/L06/TheAPI/Properties/launchSettings.json new file mode 100644 index 00000000..c068eaf3 --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:7539", + "sslPort": 44311 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "TheAPI": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Braila-Anamaria-Roxana/L06/TheAPI/Repositories/IStudentRepository.cs b/Braila-Anamaria-Roxana/L06/TheAPI/Repositories/IStudentRepository.cs new file mode 100644 index 00000000..e48fbe35 --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/Repositories/IStudentRepository.cs @@ -0,0 +1,17 @@ +using System.Runtime.CompilerServices; +using System.Dynamic; +using Models; +using Repositories; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using LanguageExt; + +public interface IStudentRepository +{ + Task> GetAllStudents(); + Task FindStudent(string university, string cnp); + Task CreateStudent(StudentEntity student); + TryAsync EditStudent(StudentEntity student); + TryAsync DeleteStudent(string university, string cnp); +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L06/TheAPI/Repositories/StudentsRepository.cs b/Braila-Anamaria-Roxana/L06/TheAPI/Repositories/StudentsRepository.cs new file mode 100644 index 00000000..98b3bdf2 --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/Repositories/StudentsRepository.cs @@ -0,0 +1,91 @@ +using System.Data; +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Microsoft.WindowsAzure.Storage.Table; +using Models; +using Repositories; +using System.Collections.Generic; +using Microsoft.WindowsAzure.Storage; +using System.Net; +using LanguageExt; +using Newtonsoft.Json; +using Azure.Storage.Queues; + +namespace Repositories +{ + public class StudentsRepository : IStudentRepository + { + private CloudTableClient _tableClient; + private CloudTable _studentsTable; + private string _connectionString; + public StudentsRepository(IConfiguration configuration) + { + _connectionString = configuration.GetValue(typeof(string), "AzureStorageAccountConnectionString").ToString(); + Task.Run(async () => { await InitializeTable(); }) + .GetAwaiter() + .GetResult(); + } + public async Task CreateStudent(StudentEntity student) + { + // var insertOperation = TableOperation.Insert(student); + // var result = await _studentsTable.ExecuteAsync(insertOperation); + // return (StudentEntity)result.Result; + 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-q" + ); + 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 FindStudent(string university, string cnp) + { + var partitionKey = university; + var rowKey = cnp; + + var query = TableOperation.Retrieve(partitionKey, rowKey); + var result = await _studentsTable.ExecuteAsync(query); + return (StudentEntity)result.Result; + } + public TryAsync EditStudent(StudentEntity student) => async () => + { + student.ETag = "*"; + + var editOperation = TableOperation.Merge(student); + var result = await _studentsTable.ExecuteAsync(editOperation); + return (StudentEntity)result.Result; + }; + public TryAsync DeleteStudent(string university, string cnp) => async () => + { + var deleteOperation = TableOperation.Delete(new TableEntity(university, cnp) { ETag = "*" }); + return await _studentsTable.ExecuteAsync(deleteOperation).ToUnit(); + }; + private async Task InitializeTable() + { + var account = CloudStorageAccount.Parse(_connectionString); + _tableClient = account.CreateCloudTableClient(); + _studentsTable = _tableClient.GetTableReference("studenti"); + + await _studentsTable.CreateIfNotExistsAsync(); + } + } +} \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L06/TheAPI/Startup.cs b/Braila-Anamaria-Roxana/L06/TheAPI/Startup.cs new file mode 100644 index 00000000..7aec09d9 --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/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; +using Repositories; + +namespace TheAPI +{ + 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.AddSingleton(); + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "TheAPI", 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", "TheAPI v1")); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Braila-Anamaria-Roxana/L06/TheAPI/TheAPI.csproj b/Braila-Anamaria-Roxana/L06/TheAPI/TheAPI.csproj new file mode 100644 index 00000000..cf69383f --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/TheAPI.csproj @@ -0,0 +1,12 @@ + + + net5.0 + + + + + + + + + \ No newline at end of file diff --git a/Braila-Anamaria-Roxana/L06/TheAPI/WeatherForecast.cs b/Braila-Anamaria-Roxana/L06/TheAPI/WeatherForecast.cs new file mode 100644 index 00000000..f126b567 --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace TheAPI +{ + 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/Braila-Anamaria-Roxana/L06/TheAPI/appsettings.Development.json b/Braila-Anamaria-Roxana/L06/TheAPI/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Braila-Anamaria-Roxana/L06/TheAPI/appsettings.json b/Braila-Anamaria-Roxana/L06/TheAPI/appsettings.json new file mode 100644 index 00000000..9818f95d --- /dev/null +++ b/Braila-Anamaria-Roxana/L06/TheAPI/appsettings.json @@ -0,0 +1,11 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "AzureStorageAccountConnectionString": "DefaultEndpointsProtocol=https;AccountName=azurestorageroxie;AccountKey=UJDHZBA32pLOOjw4WjLNkNcXKw2ds/pf8+cjbxfltTBJMVvwhLU6D0uKvtvM2vlt8T8vEBkDdtOMB408WTlDVQ==;EndpointSuffix=core.windows.net" +} \ No newline at end of file