public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { string requestBody = new StreamReader(req.Body).ReadToEnd(); Request <ISet <String> > request = JsonConvert.DeserializeObject <Request <ISet <String> > >(requestBody); try { using (SqlConnection con = new SqlConnection(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING"))) { con.Open(); // TOKEN überprüfen HttpResponseMessage message = FUNCTIONS <ISet <String> > .checkToken(request, con); if (message != null) { return(message); } foreach (String file in request.obj) { // Anfrage bearbeiten string sql = "insert imageNutzer values(@ID, @FNAME)"; using (SqlCommand com1 = new SqlCommand(sql, con)) { com1.Parameters.Add("@ID", System.Data.SqlDbType.Int); com1.Parameters.Add("@FNAME", System.Data.SqlDbType.NVarChar); com1.Parameters["@FNAME"].Value = file; com1.Parameters["@ID"].Value = request.Id; com1.ExecuteNonQuery(); } } } request.Success = true; } catch (SqlException e) { request.Success = false; request.Error = e.Message; request.Errorcode = e.ErrorCode; } return(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(request)) }); }
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { string requestBody = new StreamReader(req.Body).ReadToEnd(); Request <ISet <String> > request = JsonConvert.DeserializeObject <Request <ISet <String> > >(requestBody); try { using (SqlConnection con = new SqlConnection(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING"))) { con.Open(); // TOKEN überprüfen HttpResponseMessage message = FUNCTIONS <ISet <String> > .checkToken(request, con); if (message != null) { return(message); } // Anfrage bearbeiten request.obj = new HashSet <String>(); string sql = "Select * from imageNutzer where id_nutzer=" + request.Id; using (SqlCommand com1 = new SqlCommand(sql, con)) { using (SqlDataReader reader = com1.ExecuteReader()) { while (reader.Read()) { request.obj.Add(reader.GetString(1)); } } } } request.Success = true; } catch (SqlException e) { request.Success = false; request.Error = e.Message; request.Errorcode = e.ErrorCode; } return(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(request)) }); }
public static async System.Threading.Tasks.Task <HttpResponseMessage> runAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); Request <SpielHighscores> request = JsonConvert.DeserializeObject <Request <SpielHighscores> >(requestBody); try { using (SqlConnection con = new SqlConnection(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING"))) { con.Open(); // TOKEN überprüfen HttpResponseMessage message = FUNCTIONS <SpielHighscores> .checkToken(request, con); if (message != null) { return(message); } // Anfrage bearbeiten request.obj = new SpielHighscores(); string sql = "Select * from Spiel"; using (SqlCommand com1 = new SqlCommand(sql, con)) { using (SqlDataReader reader = com1.ExecuteReader()) { while (reader.Read()) { Spiel spiel = new Spiel(); request.obj.spiele.Add(reader.GetInt32(0), spiel); spiel.id_spiel = reader.GetInt32(0); spiel.spiel = reader.GetString(1); spiel.globaleBestzeit = reader.GetInt32(2); spiel.globalerDurschnitt = reader.GetInt32(3); spiel.rekordhalter = reader.GetString(5); if (spiel.globaleBestzeit == Int32.MaxValue) { spiel.rekordhalter = "Niemand"; spiel.globaleBestzeit = 0; } } } foreach (int key in request.obj.spiele.Keys) { sql = "Select * from Highscore where id_spiel=" + key + " and id_nutzer=" + request.Id; using (SqlCommand com2 = new SqlCommand(sql, con)) { using (SqlDataReader reader2 = com2.ExecuteReader()) { reader2.Read(); Spiel spiel = request.obj.spiele[reader2.GetInt32(1)]; spiel.bestzeit = reader2.GetInt32(2); spiel.schlechtesteZeit = reader2.GetInt32(3); spiel.durchschnitt = reader2.GetInt32(4); spiel.anzahl_gespielt = reader2.GetInt32(5); spiel.akummulierteSpielzeit = reader2.GetInt64(6); if (spiel.bestzeit == Int32.MaxValue) { spiel.bestzeit = 0; } } } } } } request.Success = true; } catch (SqlException e) { request.Success = false; request.Error = e.Message; request.Errorcode = e.ErrorCode; } return(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(request)) }); }
public static HttpResponseMessage run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { string requestBody = new StreamReader(req.Body).ReadToEnd(); Request <Spiel> request = JsonConvert.DeserializeObject <Request <Spiel> >(requestBody); try { using (SqlConnection con = new SqlConnection(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING"))) { con.Open(); // TOKEN überprüfen HttpResponseMessage message = FUNCTIONS <Spiel> .checkToken(request, con); if (message != null) { return(message); } // Anfrage bearbeiten string sql = "Update Highscore Set bestzeit=@BEST, schlechteste_Zeit=@BAD, durchschnitt=@AVERG, anzahl=@COU, kumulierteSpielzeit=@KUM Where id_Spiel=@SID and id_Nutzer=@NID"; using (SqlCommand com1 = new SqlCommand(sql, con)) { com1.Parameters.Add("@BEST", System.Data.SqlDbType.Int); com1.Parameters.Add("@BAD", System.Data.SqlDbType.Int); com1.Parameters.Add("@AVERG", System.Data.SqlDbType.Int); com1.Parameters.Add("@COU", System.Data.SqlDbType.Int); com1.Parameters.Add("@KUM", System.Data.SqlDbType.BigInt); com1.Parameters.Add("@SID", System.Data.SqlDbType.Int); com1.Parameters.Add("@NID", System.Data.SqlDbType.Int); com1.Parameters["@BEST"].Value = request.obj.bestzeit; com1.Parameters["@BAD"].Value = request.obj.schlechtesteZeit; com1.Parameters["@AVERG"].Value = request.obj.durchschnitt; com1.Parameters["@COU"].Value = request.obj.anzahl_gespielt; com1.Parameters["@KUM"].Value = request.obj.akummulierteSpielzeit; com1.Parameters["@SID"].Value = request.obj.id_spiel; com1.Parameters["@NID"].Value = request.Id; com1.ExecuteNonQuery(); } sql = "Select * from Spiel where id=" + request.obj.id_spiel; using (SqlCommand com1 = new SqlCommand(sql, con)) { using (SqlDataReader reader = com1.ExecuteReader()) { reader.Read(); request.obj.globaleBestzeit = reader.GetInt32(2); request.obj.globalerDurschnitt = reader.GetInt32(3); request.obj.rekordhalter = reader.GetString(5); } } } request.Success = true; } catch (SqlException e) { request.Success = false; request.Error = e.Message; request.Errorcode = e.ErrorCode; } return(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(request)) }); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { string requestBody = new StreamReader(req.Body).ReadToEnd(); Request <ISet <String> > request = JsonConvert.DeserializeObject <Request <ISet <String> > >(requestBody); try { using (SqlConnection con = new SqlConnection(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING"))) { con.Open(); // TOKEN überprüfen HttpResponseMessage message = FUNCTIONS <ISet <String> > .checkToken(request, con); if (message != null) { return(message); } ISet <String> blobs = await FUNCTIONS2.GetImages(); string blob = null; string sql = "Select blob from Nutzer where id=" + request.Id; using (SqlCommand com1 = new SqlCommand(sql, con)) { using (SqlDataReader reader = com1.ExecuteReader()) { while (reader.Read()) { blob = reader.GetString(0); } } } sql = "Select * from imageNutzer where id_nutzer=" + request.Id; using (SqlCommand com1 = new SqlCommand(sql, con)) { using (SqlDataReader reader = com1.ExecuteReader()) { while (reader.Read()) { if (blobs.Contains(reader.GetString(1))) { blobs.Remove(reader.GetString(1)); } } } } if (blobs.Count == 0) { request.Errorcode = -11; throw new Exception(""); } CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING")); var client = storageAccount.CreateCloudBlobClient(); var cbContainer = client.GetContainerReference("images"); var container = client.GetContainerReference(blob); //Blobs kopieren await FUNCTIONS2.CopyImages(cbContainer, container, blobs); FUNCTIONS2.writeToDb(blobs, request.Id, con); request.obj = blobs; } request.Success = true; } catch (SqlException e) { request.Success = false; request.Error = e.Message; request.Errorcode = e.ErrorCode; } catch (Exception e1) { request.Success = false; request.Error = "Ein Fehler ist aufgetreten"; } return(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(request)) }); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { string requestBody = new StreamReader(req.Body).ReadToEnd(); Request <ISet <string> > request = JsonConvert.DeserializeObject <Request <ISet <String> > >(requestBody); try { using (SqlConnection con = new SqlConnection(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING"))) { con.Open(); // TOKEN überprüfen HttpResponseMessage message = FUNCTIONS <ISet <String> > .checkToken(request, con); if (message != null) { return(message); } string blob = null; string sql = "Select blob from Nutzer where id=" + request.Id; using (SqlCommand com1 = new SqlCommand(sql, con)) { using (SqlDataReader reader = com1.ExecuteReader()) { while (reader.Read()) { blob = reader.GetString(0); } } } CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING")); var client = storageAccount.CreateCloudBlobClient(); var container = client.GetContainerReference(blob); CloudBlockBlob cloudBlockBlob; foreach (String file in request.obj) { cloudBlockBlob = container.GetBlockBlobReference(file); await cloudBlockBlob.DeleteIfExistsAsync(); sql = "Delete from imageNutzer where id_nutzer=@ID and nameOfFile=@FNAME"; using (SqlCommand com1 = new SqlCommand(sql, con)) { com1.Parameters.Add("@ID", System.Data.SqlDbType.Int); com1.Parameters.Add("@FNAME", System.Data.SqlDbType.NVarChar); com1.Parameters["@FNAME"].Value = file; com1.Parameters["@ID"].Value = request.Id; com1.ExecuteNonQuery(); } } } request.Success = true; } catch (SqlException e) { request.Success = false; request.Error = e.Message; request.Errorcode = e.ErrorCode; } return(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(request)) }); }