Skip to content
Permalink
Browse files

Merge pull request #3813 from ArchonMegalon/master

Changed Sharing-Link, no Admin-Rights are necessary anymore for launc…
  • Loading branch information...
ArchonMegalon committed Aug 12, 2019
2 parents f4ad54a + 7faff3d commit 686115c11441dbffe80912e11c99237515812c67
Showing with 3,289 additions and 211 deletions.
  1. +35 −9 Chummer/Program.cs
  2. +2 −0 ChummerHub.Client/Backend/MyMessageHandler.cs
  3. +12 −11 ChummerHub.Client/Model/CharacterExtended.cs
  4. +12 −0 ChummerHub.Client/SINnersClient/ISINnersClient.cs
  5. +20 −1 ChummerHub.Client/SINnersClient/Models/SINner.cs
  6. +1 −1 ChummerHub.Client/SINnersClient/Models/SINnerGroup.cs
  7. +1 −1 ChummerHub.Client/SINnersClient/Models/SINnerSearchGroup.cs
  8. +112 −0 ChummerHub.Client/SINnersClient/SINnersClient.cs
  9. +27 −0 ChummerHub.Client/SINnersClient/SINnersClientExtensions.cs
  10. +7 −21 ChummerHub.Client/UI/ucSINnerShare.Designer.cs
  11. +14 −14 ChummerHub.Client/UI/ucSINnerShare.cs
  12. +6 −3 ChummerHub.Client/UI/ucSINnersBasic.cs
  13. +72 −120 ChummerHub.Client/UI/ucSINnersOptions.Designer.cs
  14. +22 −22 ChummerHub.Client/UI/ucSINnersOptions.cs
  15. +2 −2 ChummerHub/ChummerHub.csproj
  16. +3 −1 ChummerHub/Controllers/V1/AccountController.cs
  17. +73 −0 ChummerHub/Controllers/V1/ChummerController.cs
  18. +5 −2 ChummerHub/Controllers/V1/SINnerController.cs
  19. +2 −0 ChummerHub/Data/ApplicationDbContext.cs
  20. +537 −0 ChummerHub/Migrations/20190812075504_Hash.Designer.cs
  21. +22 −0 ChummerHub/Migrations/20190812075504_Hash.cs
  22. +540 −0 ChummerHub/Migrations/20190812075955_Hash64.Designer.cs
  23. +38 −0 ChummerHub/Migrations/20190812075955_Hash64.cs
  24. +540 −0 ChummerHub/Migrations/20190812085624_hash8.Designer.cs
  25. +31 −0 ChummerHub/Migrations/20190812085624_hash8.cs
  26. +542 −0 ChummerHub/Migrations/20190812092443_lastdownload.Designer.cs
  27. +23 −0 ChummerHub/Migrations/20190812092443_lastdownload.cs
  28. +542 −0 ChummerHub/Migrations/20190812103509_hashnull.Designer.cs
  29. +17 −0 ChummerHub/Migrations/20190812103509_hashnull.cs
  30. +8 −1 ChummerHub/Migrations/ApplicationDbContextModelSnapshot.cs
  31. +21 −2 ChummerHub/Models/V1/SINner.cs
@@ -290,16 +290,42 @@ static void Main()
{
if (strArgs[i].Contains("/plugin"))
{
string whatplugin = strArgs[i].Substring(strArgs[i].IndexOf("/plugin") + 8);
//some external apps choose to add a '/' before a ':' even in the middle of an url...
whatplugin = whatplugin.TrimStart(':');
int endplugin = whatplugin.IndexOf(':');
string parameter = whatplugin.Substring(endplugin + 1);
whatplugin = whatplugin.Substring(0, endplugin);
var plugin = Program.PluginLoader.MyActivePlugins.FirstOrDefault(a => a.ToString() == whatplugin);
if (plugin != null)
if (GlobalOptions.PluginsEnabled == false)
{
showMainForm &= plugin.ProcessCommandLine(parameter);
string msg =
"Please enable Plugins to use command-line arguments invoking specific plugin-functions!";
Log.Warn(msg);
MessageBox.Show(msg, "Plugins not enabled", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
string whatplugin = strArgs[i].Substring(strArgs[i].IndexOf("/plugin") + 8);
//some external apps choose to add a '/' before a ':' even in the middle of an url...
whatplugin = whatplugin.TrimStart(':');
int endplugin = whatplugin.IndexOf(':');
string parameter = whatplugin.Substring(endplugin + 1);
whatplugin = whatplugin.Substring(0, endplugin);
var plugin =
Program.PluginLoader.MyActivePlugins.FirstOrDefault(a =>
a.ToString() == whatplugin);
if (plugin == null)
{
var notactive =
Program.PluginLoader.MyPlugins.FirstOrDefault(a =>
a.ToString() == whatplugin);
if (notactive != null)
{
string msg = "Plugin " + whatplugin + " is not enabled in the options!" + Environment.NewLine;
msg +=
"If you want to use command-line arguments, please enable this plugin and restart the program.";
Log.Warn(msg);
MessageBox.Show(msg, whatplugin + " not enabled", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
if (plugin != null)
{
showMainForm &= plugin.ProcessCommandLine(parameter);
}
}
}
});
@@ -7,6 +7,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Rest;
using NLog;

namespace ChummerHub.Client.Backend
@@ -54,6 +55,7 @@ public MyMessageHandler()
}
catch(Exception e)
{
e.Data.Add("request", request.AsFormattedString());
Log.Error(e);
throw;
}
@@ -183,12 +183,13 @@ internal List<Tag> PopulateTags()

public async Task<bool> Upload(ucSINnerShare.MyUserState myState = null, CustomActivity parentActivity = null)
{
try
using (var op_uploadChummer = Timekeeper.StartSyncron(
"Uploading Chummer", parentActivity,
CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
{
using (var op_uploadChummer = Timekeeper.StartSyncron(
"Uploading Chummer", parentActivity,
CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
try
{

using (new CursorWait(true, PluginHandler.MainForm))
{
HttpOperationResponse<ResultSinnerGetSINById> found = null;
@@ -217,7 +218,7 @@ public async Task<bool> Upload(ucSINnerShare.MyUserState myState = null, CustomA
}

var client = StaticUtils.GetClient();
found = await client.GetSINByIdWithHttpMessagesAsync(this.MySINnerFile.Id.Value);
found = await client.GetSINByIdWithHttpMessagesAsync(this.MySINnerFile.Id.GetValueOrDefault());
await Backend.Utils.HandleError(found, found.Body);
}

@@ -337,13 +338,13 @@ public async Task<bool> Upload(ucSINnerShare.MyUserState myState = null, CustomA

return false;
}

}
}
catch (Exception e)
{
await Backend.Utils.HandleError(e);
throw;
catch (Exception e)
{
op_uploadChummer?.tc?.TrackException(e);
await Backend.Utils.HandleError(e);
throw;
}
}
}

@@ -145,6 +145,18 @@ public partial interface ISINnersClient : IDisposable
/// </param>
Task<HttpOperationResponse<bool?>> LogoutWithHttpMessagesAsync(Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));

/// <param name='hash'>
/// </param>
/// <param name='apiVersion'>
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
Task<HttpOperationResponse> OpenWithHttpMessagesAsync(string hash, string apiVersion = default(string), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));

/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
@@ -21,11 +21,13 @@ public partial class SINner
/// <summary>
/// Initializes a new instance of the SINner class.
/// </summary>
public SINner(string editionNumber = default(string), string language = default(string), SINnerMetaData siNnerMetaData = default(SINnerMetaData), SINnerGroup myGroup = default(SINnerGroup), string alias = default(string), Guid? id = default(Guid?), string downloadUrl = default(string), DateTime? uploadDateTime = default(DateTime?), DateTime? lastChange = default(DateTime?), string fileName = default(string))
public SINner(string editionNumber = default(string), string myHash = default(string), string language = default(string), SINnerMetaData siNnerMetaData = default(SINnerMetaData), DateTime? lastDownload = default(DateTime?), SINnerGroup myGroup = default(SINnerGroup), string alias = default(string), Guid? id = default(Guid?), string downloadUrl = default(string), DateTime? uploadDateTime = default(DateTime?), DateTime? lastChange = default(DateTime?), string fileName = default(string))
{
EditionNumber = editionNumber;
MyHash = myHash;
Language = language;
SiNnerMetaData = siNnerMetaData;
LastDownload = lastDownload;
MyGroup = myGroup;
Alias = alias;
Id = id;
@@ -40,6 +42,11 @@ public SINner(string editionNumber = default(string), string language = default(
[JsonProperty(PropertyName = "editionNumber")]
public string EditionNumber { get; set; }

/// <summary>
/// </summary>
[JsonProperty(PropertyName = "myHash")]
public string MyHash { get; set; }

/// <summary>
/// </summary>
[JsonProperty(PropertyName = "language")]
@@ -50,6 +57,11 @@ public SINner(string editionNumber = default(string), string language = default(
[JsonProperty(PropertyName = "siNnerMetaData")]
public SINnerMetaData SiNnerMetaData { get; set; }

/// <summary>
/// </summary>
[JsonProperty(PropertyName = "lastDownload")]
public DateTime? LastDownload { get; set; }

/// <summary>
/// </summary>
[JsonProperty(PropertyName = "myGroup")]
@@ -97,6 +109,13 @@ public virtual void Validate()
throw new ValidationException(ValidationRules.MaxLength, "EditionNumber", 2);
}
}
if (this.MyHash != null)
{
if (this.MyHash.Length > 8)
{
throw new ValidationException(ValidationRules.MaxLength, "MyHash", 8);
}
}
if (this.Language != null)
{
if (this.Language.Length > 6)
@@ -75,7 +75,7 @@ public SINnerGroup(Guid? id = default(Guid?), Guid? myParentGroupId = default(Gu
/// <summary>
/// </summary>
[JsonProperty(PropertyName = "hasPassword")]
public bool? HasPassword { get; private set; }
public bool? HasPassword { get; set; }

/// <summary>
/// </summary>
@@ -93,7 +93,7 @@ public SINnerSearchGroup(IList<SINnerSearchGroup> mySINSearchGroups = default(IL
/// <summary>
/// </summary>
[JsonProperty(PropertyName = "hasPassword")]
public bool? HasPassword { get; private set; }
public bool? HasPassword { get; set; }

/// <summary>
/// </summary>
@@ -1533,6 +1533,118 @@ public async Task<HttpOperationResponse<ResultGroupGetSearchGroups>> GetSinnerAs
return _result;
}

/// <param name='hash'>
/// </param>
/// <param name='apiVersion'>
/// </param>
/// <param name='customHeaders'>
/// Headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
/// <return>
/// A response object containing the response body and response headers.
/// </return>
public async Task<HttpOperationResponse> OpenWithHttpMessagesAsync(string hash, string apiVersion = default(string), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (hash == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "hash");
}
// Tracing
bool _shouldTrace = ServiceClientTracing.IsEnabled;
string _invocationId = null;
if (_shouldTrace)
{
_invocationId = ServiceClientTracing.NextInvocationId.ToString();
Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
tracingParameters.Add("hash", hash);
tracingParameters.Add("apiVersion", apiVersion);
tracingParameters.Add("cancellationToken", cancellationToken);
ServiceClientTracing.Enter(_invocationId, this, "Open", tracingParameters);
}
// Construct URL
var _baseUrl = this.BaseUri.AbsoluteUri;
var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "Open/{Hash}").ToString();
_url = _url.Replace("{Hash}", Uri.EscapeDataString(hash));
List<string> _queryParameters = new List<string>();
if (apiVersion != null)
{
_queryParameters.Add(string.Format("api-version={0}", Uri.EscapeDataString(apiVersion)));
}
if (_queryParameters.Count > 0)
{
_url += "?" + string.Join("&", _queryParameters);
}
// Create HTTP transport objects
HttpRequestMessage _httpRequest = new HttpRequestMessage();
HttpResponseMessage _httpResponse = null;
_httpRequest.Method = new HttpMethod("GET");
_httpRequest.RequestUri = new Uri(_url);
// Set Headers
if (customHeaders != null)
{
foreach(var _header in customHeaders)
{
if (_httpRequest.Headers.Contains(_header.Key))
{
_httpRequest.Headers.Remove(_header.Key);
}
_httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
}
}

// Serialize Request
string _requestContent = null;
// Set Credentials
if (this.Credentials != null)
{
cancellationToken.ThrowIfCancellationRequested();
await this.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
}
// Send Request
if (_shouldTrace)
{
ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
}
cancellationToken.ThrowIfCancellationRequested();
_httpResponse = await this.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
if (_shouldTrace)
{
ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
}
HttpStatusCode _statusCode = _httpResponse.StatusCode;
cancellationToken.ThrowIfCancellationRequested();
string _responseContent = null;
if ((int)_statusCode != 302 && (int)_statusCode != 404)
{
var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
if (_shouldTrace)
{
ServiceClientTracing.Error(_invocationId, ex);
}
_httpRequest.Dispose();
if (_httpResponse != null)
{
_httpResponse.Dispose();
}
throw ex;
}
// Create Result
var _result = new HttpOperationResponse();
_result.Request = _httpRequest;
_result.Response = _httpResponse;
if (_shouldTrace)
{
ServiceClientTracing.Exit(_invocationId, _result);
}
return _result;
}

/// <param name='customHeaders'>
/// Headers that will be added to request.
/// </param>
@@ -293,6 +293,33 @@ public static async Task<ResultGroupGetSearchGroups> GetSinnerAsAdminAsync(this
}
}

/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='hash'>
/// </param>
/// <param name='apiVersion'>
/// </param>
public static void Open(this ISINnersClient operations, string hash, string apiVersion = default(string))
{
Task.Factory.StartNew(s => ((ISINnersClient)s).OpenAsync(hash, apiVersion), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
}

/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='hash'>
/// </param>
/// <param name='apiVersion'>
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
public static async Task OpenAsync(this ISINnersClient operations, string hash, string apiVersion = default(string), CancellationToken cancellationToken = default(CancellationToken))
{
await operations.OpenWithHttpMessagesAsync(hash, apiVersion, null, cancellationToken).ConfigureAwait(false);
}

/// <param name='operations'>
/// The operations group for this extension method.
/// </param>

0 comments on commit 686115c

Please sign in to comment.
You can’t perform that action at this time.