mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Change the way data is uploaded to the server.
This commit is contained in:
1
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
1
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
@@ -1802,7 +1802,6 @@
|
|||||||
</e>
|
</e>
|
||||||
</e>
|
</e>
|
||||||
<e p="DiscImageChef.Server" t="IncludeRecursive">
|
<e p="DiscImageChef.Server" t="IncludeRecursive">
|
||||||
<e p="App.config" t="Include" />
|
|
||||||
<e p="App_Start" t="Include">
|
<e p="App_Start" t="Include">
|
||||||
<e p="Ata.cs" t="Include" />
|
<e p="Ata.cs" t="Include" />
|
||||||
<e p="RouteConfig.cs" t="Include" />
|
<e p="RouteConfig.cs" t="Include" />
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using DiscImageChef.CommonTypes.Metadata;
|
using DiscImageChef.CommonTypes.Metadata;
|
||||||
@@ -126,22 +127,19 @@ namespace DiscImageChef.Core
|
|||||||
DiscImageChef.Console.DicConsole.DebugWriteLine("Submit stats", "Uploading device report");
|
DiscImageChef.Console.DicConsole.DebugWriteLine("Submit stats", "Uploading device report");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MemoryStream jsonStream = new MemoryStream();
|
string json = JsonConvert.SerializeObject(report, Formatting.Indented,
|
||||||
StreamWriter jsonSw = new StreamWriter(jsonStream);
|
new JsonSerializerSettings
|
||||||
|
{
|
||||||
jsonSw.Write(JsonConvert.SerializeObject(report, Formatting.Indented,
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
new JsonSerializerSettings
|
});
|
||||||
{
|
byte[] jsonBytes = Encoding.UTF8.GetBytes(json);
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
WebRequest request = WebRequest.Create("http://discimagechef.claunia.com/api/uploadreportv2");
|
||||||
}));
|
|
||||||
jsonStream.Seek(0, SeekOrigin.Begin);
|
|
||||||
WebRequest request = WebRequest.Create("http://discimagechef.claunia.com/api/uploadreportv2");
|
|
||||||
((HttpWebRequest)request).UserAgent = $"DiscImageChef {typeof(Version).Assembly.GetName().Version}";
|
((HttpWebRequest)request).UserAgent = $"DiscImageChef {typeof(Version).Assembly.GetName().Version}";
|
||||||
request.Method = "POST";
|
request.Method = "POST";
|
||||||
request.ContentLength = jsonStream.Length;
|
request.ContentLength = jsonBytes.Length;
|
||||||
request.ContentType = "application/json";
|
request.ContentType = "application/json";
|
||||||
Stream reqStream = request.GetRequestStream();
|
Stream reqStream = request.GetRequestStream();
|
||||||
jsonStream.CopyTo(reqStream);
|
reqStream.Write(jsonBytes, 0, jsonBytes.Length);
|
||||||
reqStream.Close();
|
reqStream.Close();
|
||||||
WebResponse response = request.GetResponse();
|
WebResponse response = request.GetResponse();
|
||||||
|
|
||||||
@@ -153,8 +151,6 @@ namespace DiscImageChef.Core
|
|||||||
reader.ReadToEnd();
|
reader.ReadToEnd();
|
||||||
data.Close();
|
data.Close();
|
||||||
response.Close();
|
response.Close();
|
||||||
jsonSw.Close();
|
|
||||||
jsonStream.Close();
|
|
||||||
}
|
}
|
||||||
catch(WebException)
|
catch(WebException)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using DiscImageChef.CommonTypes.Interop;
|
using DiscImageChef.CommonTypes.Interop;
|
||||||
@@ -609,23 +610,21 @@ namespace DiscImageChef.Core
|
|||||||
DiscImageChef.Console.DicConsole.DebugWriteLine("Submit stats", "Uploading statistics");
|
DiscImageChef.Console.DicConsole.DebugWriteLine("Submit stats", "Uploading statistics");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MemoryStream jsonStream = new MemoryStream();
|
string json = JsonConvert.SerializeObject(dto, Formatting.Indented,
|
||||||
StreamWriter jsonSw = new StreamWriter(jsonStream);
|
new JsonSerializerSettings
|
||||||
|
{
|
||||||
jsonSw.Write(JsonConvert.SerializeObject(dto, Formatting.Indented,
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
new JsonSerializerSettings
|
});
|
||||||
{
|
byte[] jsonBytes = Encoding.UTF8.GetBytes(json);
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
WebRequest request = WebRequest.Create("http://discimagechef.claunia.com/api/uploadstatsv2");
|
||||||
}));
|
|
||||||
jsonStream.Seek(0, SeekOrigin.Begin);
|
|
||||||
WebRequest request = WebRequest.Create("http://discimagechef.claunia.com/api/uploadstatsv2");
|
|
||||||
((HttpWebRequest)request).UserAgent =
|
((HttpWebRequest)request).UserAgent =
|
||||||
$"DiscImageChef {typeof(Version).Assembly.GetName().Version}";
|
$"DiscImageChef {typeof(Version).Assembly.GetName().Version}";
|
||||||
request.Method = "POST";
|
request.Method = "POST";
|
||||||
request.ContentLength = jsonStream.Length;
|
request.ContentLength = jsonBytes.Length;
|
||||||
request.ContentType = "application/json";
|
request.ContentType = "application/json";
|
||||||
Stream reqStream = request.GetRequestStream();
|
Stream reqStream = request.GetRequestStream();
|
||||||
jsonStream.CopyTo(reqStream);
|
reqStream.Write(jsonBytes, 0, jsonBytes.Length);
|
||||||
|
//jsonStream.CopyTo(reqStream);
|
||||||
reqStream.Close();
|
reqStream.Close();
|
||||||
WebResponse response = request.GetResponse();
|
WebResponse response = request.GetResponse();
|
||||||
|
|
||||||
@@ -634,11 +633,11 @@ namespace DiscImageChef.Core
|
|||||||
Stream data = response.GetResponseStream();
|
Stream data = response.GetResponseStream();
|
||||||
StreamReader reader = new StreamReader(data ?? throw new InvalidOperationException());
|
StreamReader reader = new StreamReader(data ?? throw new InvalidOperationException());
|
||||||
|
|
||||||
reader.ReadToEnd();
|
string result = reader.ReadToEnd();
|
||||||
data.Close();
|
data.Close();
|
||||||
response.Close();
|
response.Close();
|
||||||
jsonSw.Close();
|
|
||||||
jsonStream.Close();
|
if(result != "ok") return;
|
||||||
|
|
||||||
if(ctx.Commands.Any(c => !c.Synchronized))
|
if(ctx.Commands.Any(c => !c.Synchronized))
|
||||||
foreach(string nvs in ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name)
|
foreach(string nvs in ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name)
|
||||||
|
|||||||
Reference in New Issue
Block a user