Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tema Lab2 #9

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Palagesiu Bogdan/L01/Tema.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Niste servicii SAAS (software-as-a-service) pe care le folosesc foarte des sunt cele de streaming muzical si vizual fiind vorba de Netflix, Spotify si HBO Go.
29 changes: 29 additions & 0 deletions Palagesiu Bogdan/L02/Controllers/StudentsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Repositories;
using Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace L02.Controllers
{
[ApiController]
[Route("[controller]")]
public class StudentsController : ControllerBase
{
public StudentsController()
{
}

public IEnumerable<Students> Get(){
return StudentsRepo.Students;
}

[HttpGet("{id}")]
public Students GetStudent(int id)
{
return StudentsRepo.Students.FirstOrDefault(s=>s.Id == id);
}
}
}
39 changes: 39 additions & 0 deletions Palagesiu Bogdan/L02/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -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<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet]
public IEnumerable<WeatherForecast> 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();
}
}
}
8 changes: 8 additions & 0 deletions Palagesiu Bogdan/L02/L02.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>


</Project>
13 changes: 13 additions & 0 deletions Palagesiu Bogdan/L02/Models/Students.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Models
{
public class Students
{
public int Id { get; set; }

public string Faculty { get; set; }

public string Name { get; set; }

public int Year { get; set; }
}
}
26 changes: 26 additions & 0 deletions Palagesiu Bogdan/L02/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Startup>();
});
}
}
30 changes: 30 additions & 0 deletions Palagesiu Bogdan/L02/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:35418",
"sslPort": 44344
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"L02": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
11 changes: 11 additions & 0 deletions Palagesiu Bogdan/L02/Repositories/StudentsRepo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Models;
namespace Repositories{
public static class StudentsRepo{

public static List<Students> Students = new List<Students>(){
new Students(){Id=1, Faculty="AC", Name = "Cristi", Year = 4},
new Students(){Id=2, Faculty="Sport", Name = "Florin", Year = 2}
};
}
}
51 changes: 51 additions & 0 deletions Palagesiu Bogdan/L02/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace L02
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
15 changes: 15 additions & 0 deletions Palagesiu Bogdan/L02/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
9 changes: 9 additions & 0 deletions Palagesiu Bogdan/L02/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
10 changes: 10 additions & 0 deletions Palagesiu Bogdan/L02/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
12 changes: 12 additions & 0 deletions Palagesiu Bogdan/L03/L03.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Apis.Drive.v3" Version="1.55.0.2481" />
</ItemGroup>

</Project>
99 changes: 99 additions & 0 deletions Palagesiu Bogdan/L03/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Util.Store;
using Newtonsoft.Json.Linq;

namespace L03
{
class Program
{

private static DriveService _service;

private static string _token;
static void Main(string[] args)
{
Initialize();
}

static void Initialize()
{
string[] scopes = new string[]{
DriveService.Scope.Drive,
DriveService.Scope.DriveFile
};
var clientId = "560379851209-tjdtmhj12akvv3ebh5hjnpmpq8cubudn.apps.googleusercontent.com";
var clientSecret = "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";
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = clientId,
ClientSecret = clientSecret
},
scopes,
Environment.UserName,
CancellationToken.None,
new FileDataStore("Dainto.GoogleDrive.Auth.Store")
).Result;
_service = new DriveService(new Google.Apis.Services.BaseClientService.Initializer(){
HttpClientInitializer = credential
});
_token = credential.Token.AccessToken;
Console.WriteLine(_token);
GetAllFiles();
UploadTxtFile();
}

static void GetAllFiles()
{
var request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/drive/v3/files?q='root'%20in%20parents");
request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + _token);
using (var response = request.GetResponse())
{
using (Stream data = response.GetResponseStream())
using (var reader = new StreamReader(data))
{
string text = reader.ReadToEnd();
var myData = JObject.Parse(text);
foreach(var file in myData["files"])
{
if(file["mimeType"].ToString() != "application/vnd.google-apps.folder")
{
Console.WriteLine("File name: " + file["name"]);
}
}
}
}
}
static void UploadTxtFile()
{
string path;
byte[] text;
Console.Write("Dati calea fisierului txt pe care doriti sa il incarcati pe drive: ");
path = Console.ReadLine();
text = Encoding.ASCII.GetBytes("--not_so_random_boundary\nContent-Type: application/json; charset = utf-8\nContent-Disposition: form-data; name=\"metadata\"\n\n{\"name\":\""+Path.GetFileName(path)+"\",\"mimeType\":\"text/plain\"}\n--not_so_random_boundary\nContent-Type: text/plain\nContent-Disposition: form-data; name=\"file\"\n\n"+ File.ReadAllText(path) + "\n--not_so_random_boundary--");
var request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart");
request.Method = WebRequestMethods.Http.Post;
request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + _token);
request.Headers.Add(HttpRequestHeader.ContentType, "multipart/related; boundary=not_so_random_boundary");
request.Headers.Add(HttpRequestHeader.ContentLength, text.Length.ToString());
Stream body = request.GetRequestStream();
body.Write(text, 0, text.Length);
using (var response = request.GetResponse())
{
using (Stream data = response.GetResponseStream())
using (var reader = new StreamReader(data))
{
string info = reader.ReadToEnd();
var myData = JObject.Parse(info);
Console.WriteLine(myData);
}
}
}
}
}
1 change: 1 addition & 0 deletions Palagesiu Bogdan/L03/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fisier test pentru DATC JOI ora 18:15
12 changes: 12 additions & 0 deletions Palagesiu Bogdan/L04/L04.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
</ItemGroup>

</Project>
Loading