[1.6.0] HttpEndpoint added

This commit is contained in:
BlubbFish 2022-01-09 23:01:53 +01:00
parent 528dcabf59
commit 61f26e69af
7 changed files with 583 additions and 332 deletions

View File

@ -0,0 +1,173 @@
# Changelog
## 1.6.0 - 2022-01-09 - HttpEndpoint added
### New Features
* Add HttpEndpoint
### Bugfixes
### Changes
* Change Readme that its link to the normal repo
* Codingstyles
* Fixing history
## 1.5.0 - 2021-04-10 - Add GetEvent so you can call events by string; Add OwnSingeton class
### New Features
* More allowed Chars for Chapters in inifile
* Add Contribution, Licence and readme
* Adding netcore
* Add changelog
* Filedhelper to helpter
* CmdArgs improvements
* Make netcore to default
* Add OwnSingleton
### Bugfixes
* WriteLine in Programmlogger sometimes make nonesense
* Writeline event are wrong
### Changes
* Remove the binary files
* Move all Classes to subfolder
* Codingstyles
## 1.4.0 - 2018-11-27 - Add Helper to Utils
### New Features
* Add Helper
### Bugfixes
### Changes
## 1.1.3 - 2018-10-02 - Improve CmdArgs
### New Features
* CmdArgs now throw extensions if there is something wrong
### Bugfixes
### Changes
## 1.1.2 - 2018-09-11 - Tiny Codingstyles
### New Features
### Bugfixes
### Changes
* Codingstyles
## 1.1.1 - 2018-05-29 - ProgrammLogger neets to cleanup
### New Features
* Delete the Mess behind
### Bugfixes
### Changes
## 1.1.0 - 2018-05-15 - ProgrammLogger
### New Features
* Add Programmlogger
### Bugfixes
### Changes
* Codingstyles
## 1.0.7.0 - 2018-05-08 - Yet another IniReader improvemnt round again
### New Features
### Bugfixes
### Changes
* Move searchpath to its own function
## 1.0.6.0 - 2017-12-22 - Yet another IniReader improvemnt round
### New Features
* Posibillity to add complete sections to an ini file
### Bugfixes
### Changes
## 1.0.5.2 - 2017-09-26 - And Improve IniReader again
### New Features
* IniReader returns the Sections with or without Brackets now
### Bugfixes
### Changes
## 1.0.5.1 - 2017-09-24 - Improve IniReader again
### New Features
### Bugfixes
* IniReader now supports umlaute
* IniReader matches with Brackets and without
### Changes
## 1.0.5.0 - 2017-08-09 - Improve IniReader
### New Features
* IniReader can now return a whole segemt
### Bugfixes
### Changes
## 1.0.4.1 - 2017-08-08 - Cleanup OwnView
### New Features
### Bugfixes
### Changes
* remove Init from OwnView
## 1.0.4.0 - 2017-04-30 - More Updater
### New Features
* continue Development of Updater
### Bugfixes
### Changes
## 1.0.3.2 - 2017-04-26 - Next Updater
### New Features
* continue Development of Updater
### Bugfixes
### Changes
## 1.0.3.1 - 2017-04-25 - EventArgsHelper
### New Features
* Add EventArgsHelper
### Bugfixes
### Changes
* Codingstyles
* Moves LogEventArgs to EventArgsHelper
* Moves UpdaterEventArgs to EventArgsHelper
## 1.0.2.6 - 2017-04-24 - Better Updater
### New Features
* Add Updater
* Add Disposable Interface
* Using LogEventArgs now for Logging
* Make UpdaterEventArgs as Child of EventArgs
* Updater now using Ownobject as Parent
* Add VersionsInfo to Updater
* Updater spawns a Background Task to Check for Updates
### Bugfixes
### Changes
## 1.0.2.5 - 2017-04-19 - Logging in OwnObject
### New Features
* Add Logging to OwnObject
### Bugfixes
* Avoid nullpointer exception in FileMutex
### Changes
* Codingstyles
## 1.0.2.3 - 2017-04-16 - OwnModel better
### New Features
* Add Remove observer on OwnModel
### Bugfixes
### Changes
* Codingstyles
## 1.0.2.2 - 2017-03-09 - Make it nice
### New Features
### Bugfixes
### Changes
* Codingstyles
## 1.0.2.1 - 2017-03-09 - Filemutex
### New Features
* Add Filemutex
### Bugfixes
* Filelogger backet on wrong pos
### Changes
## 1.0.0.1 - 2016-12-03 - Filelogger improvements
### New Features
* Check Directory and if not exist add it
* Now logs with timestamp
* Can select logdir
* Add Abstract dispose to OwnController
### Bugfixes
### Changes
## 1.0.0.0 - 2015-11-16 - Init
### New Features
* Add CmdArgs, FileLogger, IniReader, OwnController, OwnModel, OwnObject, OwnView,
### Bugfixes
### Changes

View File

@ -43,7 +43,7 @@ namespace BlubbFish.Utils
_ = Directory.CreateDirectory(v);
logDir = v;
}
if (logDir.Substring(logDir.Length - 1) != Path.DirectorySeparatorChar.ToString()) {
if (logDir[^1..] != Path.DirectorySeparatorChar.ToString()) {
logDir += Path.DirectorySeparatorChar;
}
}

59
Utils/HttpEndpoint.cs Normal file
View File

@ -0,0 +1,59 @@
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace BlubbFish.Utils {
public class HttpEndpoint {
private readonly HttpClient client = new HttpClient();
private readonly String server = "";
public enum RequestMethod {
GET,
POST,
PUT
}
public HttpEndpoint(String server, String auth = null) {
this.server = server;
if(auth != null) {
this.client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(auth);
}
}
public HttpEndpoint(String server, (String scheme, String parameter) auth) {
this.server = server;
this.client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(auth.scheme, auth.parameter);
}
public async Task<String> RequestString(String address, String json = "", Boolean withoutput = true, RequestMethod method = RequestMethod.GET) {
String ret = null;
try {
HttpResponseMessage response = null;
if(method == RequestMethod.POST || method == RequestMethod.PUT) {
HttpContent content = new StringContent(json);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
//content.Headers.Add("Content-Type", "application/json");
if(method == RequestMethod.POST) {
response = await this.client.PostAsync(this.server + address, content);
} else if(method == RequestMethod.PUT) {
response = await this.client.PutAsync(this.server + address, content);
}
content.Dispose();
} else if(method == RequestMethod.GET) {
response = await this.client.GetAsync(this.server + address);
}
if(!response.IsSuccessStatusCode) {
throw new Exception(response.StatusCode + ": " + response.ReasonPhrase);
}
if(withoutput && response != null) {
ret = await response.Content.ReadAsStringAsync();
}
} catch(Exception e) {
throw new WebException(String.Format("Error while opening resource: \"{0}\" Method {1} Data {2} Fehler {3}", this.server + address, method, json, e.Message));
}
return ret;
}
}
}

View File

@ -96,7 +96,7 @@ namespace BlubbFish.Utils {
} else {
if (line != "" && cap != "") {
String key = line.Substring(0, line.IndexOf('='));
String value = line.Substring(line.IndexOf('=') + 1);
String value = line[(line.IndexOf('=') + 1)..];
sub.Add(key, value);
}
}

View File

@ -8,18 +8,37 @@
<Company>BlubbFish</Company>
<Authors>BlubbFish</Authors>
<PackageId>Utils.BlubbFish</PackageId>
<Copyright>Copyright © BlubbFish 2014 - 10.04.2021</Copyright>
<AssemblyVersion>1.5.0</AssemblyVersion>
<FileVersion>1.5.0</FileVersion>
<Copyright>Copyright © BlubbFish 2014 - 09.01.2022</Copyright>
<Version>1.6.0</Version>
<NeutralLanguage>de-DE</NeutralLanguage>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>http://git.blubbfish.net/vs_utils/Utils</PackageProjectUrl>
<RepositoryUrl>http://git.blubbfish.net/vs_utils/Utils.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>1.5.0</Version>
<PackageReleaseNotes>
1.6.0 HttpEndpoint added
1.5.0 Add GetEvent so you can call events by string; Add OwnSingeton class
1.4.0 Add Helper to Utils
1.1.3 Improve CmdArgs
1.1.2 Tiny Codingstyles
1.1.1 ProgrammLogger neets to cleanup
1.1.0 ProgrammLogger
1.0.7.0 Yet another IniReader improvemnt round again
1.0.6.0 Yet another IniReader improvemnt round
1.0.5.2 And Improve IniReader again
1.0.5.1 Improve IniReader again
1.0.5.0 Improve IniReader
1.0.4.1 Cleanup OwnView
1.0.4.0 More Updater
1.0.3.2 Next Updater
1.0.3.1 EventArgsHelper
1.0.2.6 Better Updater
1.0.2.5 Logging in OwnObject
1.0.2.3 OwnModel better
1.0.2.2 Make it nice
1.0.2.1 Filemutex
1.0.0.1 Filelogger improvements
1.0.0.0 Init
</PackageReleaseNotes>
</PropertyGroup>