mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Send report V2 to server.
This commit is contained in:
@@ -36,6 +36,7 @@ using System.Net;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using DiscImageChef.CommonTypes.Metadata;
|
using DiscImageChef.CommonTypes.Metadata;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Version = DiscImageChef.CommonTypes.Metadata.Version;
|
using Version = DiscImageChef.CommonTypes.Metadata.Version;
|
||||||
|
|
||||||
namespace DiscImageChef.Core
|
namespace DiscImageChef.Core
|
||||||
@@ -99,5 +100,66 @@ namespace DiscImageChef.Core
|
|||||||
});
|
});
|
||||||
submitThread.Start();
|
submitThread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Submits a device report
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="report">Device report</param>
|
||||||
|
public static void SubmitReportV2(DeviceReportV2 report)
|
||||||
|
{
|
||||||
|
Thread submitThread = new Thread(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine("Uploading device report");
|
||||||
|
#else
|
||||||
|
DiscImageChef.Console.DicConsole.DebugWriteLine("Submit stats", "Uploading device report");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
MemoryStream xmlStream = new MemoryStream();
|
||||||
|
StreamWriter jsonSw = new StreamWriter(xmlStream);
|
||||||
|
|
||||||
|
jsonSw.Write(JsonConvert.SerializeObject(report, Formatting.Indented,
|
||||||
|
new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
|
}));
|
||||||
|
jsonSw.Close();
|
||||||
|
xmlStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
WebRequest request = WebRequest.Create("http://discimagechef.claunia.com/api/uploadreportv2");
|
||||||
|
((HttpWebRequest)request).UserAgent = $"DiscImageChef {typeof(Version).Assembly.GetName().Version}";
|
||||||
|
request.Method = "POST";
|
||||||
|
request.ContentLength = xmlStream.Length;
|
||||||
|
request.ContentType = "application/json";
|
||||||
|
Stream reqStream = request.GetRequestStream();
|
||||||
|
xmlStream.CopyTo(reqStream);
|
||||||
|
reqStream.Close();
|
||||||
|
WebResponse response = request.GetResponse();
|
||||||
|
|
||||||
|
if(((HttpWebResponse)response).StatusCode != HttpStatusCode.OK) return;
|
||||||
|
|
||||||
|
Stream data = response.GetResponseStream();
|
||||||
|
StreamReader reader = new StreamReader(data ?? throw new InvalidOperationException());
|
||||||
|
|
||||||
|
reader.ReadToEnd();
|
||||||
|
data.Close();
|
||||||
|
response.Close();
|
||||||
|
xmlStream.Close();
|
||||||
|
}
|
||||||
|
catch(WebException)
|
||||||
|
{
|
||||||
|
// Can't connect to the server, do nothing
|
||||||
|
}
|
||||||
|
// ReSharper disable once RedundantCatchClause
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
throw;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
});
|
||||||
|
submitThread.Start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,8 @@ namespace DiscImageChef.Commands
|
|||||||
|
|
||||||
if(!DetectOS.IsAdmin)
|
if(!DetectOS.IsAdmin)
|
||||||
{
|
{
|
||||||
DicConsole.ErrorWriteLine("Because of the commands sent to a device, device report must be run with administrative privileges.");
|
DicConsole
|
||||||
|
.ErrorWriteLine("Because of the commands sent to a device, device report must be run with administrative privileges.");
|
||||||
DicConsole.ErrorWriteLine("Not continuing.");
|
DicConsole.ErrorWriteLine("Not continuing.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -925,7 +926,7 @@ namespace DiscImageChef.Commands
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
//if(Settings.Settings.Current.ShareReports) Remote.SubmitReport(report);
|
if(Settings.Settings.Current.ShareReports) Remote.SubmitReportV2(report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user