Methode mit #if DEBUG gab im RELEASE keinen Wert zurück: gefixt.
This commit is contained in:
@@ -43,10 +43,6 @@ namespace ChatController.Utilities
|
||||
/// <param name="callback">Callback-Methode, die nach dem Herunterladen des Bildes aufgerufen wird und das Bild zurückgibt. Fügt das Bild der GUI hinzu.</param>
|
||||
private static void DownloadImage(string uri, Action<ImageSource> callback)
|
||||
{
|
||||
#if DEBUG
|
||||
Debug.WriteLine($"####{uri} wird heruntergeladen (Utils.DownloadImage) ...");
|
||||
#endif
|
||||
|
||||
var client = new RestClient(uri);
|
||||
var request = new RestRequest
|
||||
{
|
||||
@@ -386,7 +382,7 @@ namespace ChatController.Utilities
|
||||
return 100;
|
||||
}
|
||||
|
||||
private static readonly Regex _UrlRegex = new Regex(@"(?#Protocol)(http(?:s?)\:(\/\/|\\\\)|(w){3}(2|3)?\.{1})(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
private static readonly Regex UrlRegex = new Regex(@"(?#Protocol)(http(?:s?)\:(\/\/|\\\\)|(w){3}(2|3)?\.{1})(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static ObservableCollection<Inline> ConvertLinksToHyperlinks(string messageText)
|
||||
{
|
||||
@@ -400,7 +396,7 @@ namespace ChatController.Utilities
|
||||
var guidString = Guid.NewGuid().ToString();
|
||||
var replacementString = Guid.NewGuid().ToString();
|
||||
|
||||
var matches = _UrlRegex.Matches(messageText);
|
||||
var matches = UrlRegex.Matches(messageText);
|
||||
|
||||
var index2Link = new Dictionary<int, Hyperlink>();
|
||||
|
||||
@@ -427,7 +423,7 @@ namespace ChatController.Utilities
|
||||
index2Link[i] = hyperlink;
|
||||
}
|
||||
|
||||
var splitMessage = _UrlRegex.Replace(messageText, replacementString + guidString).Split(new[] { guidString }, StringSplitOptions.None);
|
||||
var splitMessage = UrlRegex.Replace(messageText, replacementString + guidString).Split(new[] { guidString }, StringSplitOptions.None);
|
||||
|
||||
var linkIndex = 0;
|
||||
foreach(var text in splitMessage)
|
||||
@@ -463,46 +459,8 @@ namespace ChatController.Utilities
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetUserIdFromProfilePictureUri(string uri)
|
||||
{
|
||||
#if DEBUG
|
||||
if(string.IsNullOrWhiteSpace(uri))
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
string userId = null;
|
||||
var splitUri = uri.Split('/');
|
||||
if(splitUri.Length <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var lastIndex = splitUri.Length - 1;
|
||||
var fileName = splitUri[lastIndex];
|
||||
var splitFileName = fileName.Split('_');
|
||||
|
||||
if(splitFileName.Length > 0)
|
||||
{
|
||||
userId = long.TryParse(splitFileName[0], out var unused) ? splitFileName[0] : fileName;
|
||||
}
|
||||
|
||||
return userId;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static ImageSource DownloadImageSync(string uri, long? userId, int? groupId)
|
||||
{
|
||||
var userOrGroup = "FEHLER: USER-ID UND GROUP-ID SIND NULL!";
|
||||
if(groupId.HasValue && userId is null)
|
||||
{
|
||||
userOrGroup = $"GroupId {groupId}";
|
||||
}
|
||||
else if(groupId is null && userId.HasValue)
|
||||
{
|
||||
userOrGroup = $"UserId {userId}";
|
||||
}
|
||||
|
||||
var cache = OwnChatCache.GetInstance();
|
||||
|
||||
if(cache.IsAvatarInCache(uri, userId, groupId))
|
||||
@@ -510,8 +468,6 @@ namespace ChatController.Utilities
|
||||
return cache.GetAvatar(uri, userId, groupId);
|
||||
}
|
||||
|
||||
Debug.WriteLine($"####Lade {uri} für {userOrGroup} herunter ...");
|
||||
|
||||
var request = WebRequest.Create(uri);
|
||||
request.Credentials = CredentialCache.DefaultCredentials;
|
||||
request.Headers[Constants.Token] = AuthToken;
|
||||
@@ -519,7 +475,7 @@ namespace ChatController.Utilities
|
||||
|
||||
using(var response = request.GetResponse())
|
||||
{
|
||||
var responseStream = response?.GetResponseStream();
|
||||
var responseStream = response.GetResponseStream();
|
||||
|
||||
if(responseStream is null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user