Merge branch 'master' of ssh://float.beyondsoft.de/git/beyondSoft/Chat
This commit is contained in:
@@ -45,6 +45,9 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="PresentationCore" />
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="PresentationFramework" />
|
<Reference Include="PresentationFramework" />
|
||||||
|
<Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\BeWo\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
@@ -140,6 +143,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="ownchat_favicon.ico" />
|
<Content Include="ownchat_favicon.ico" />
|
||||||
|
<None Include="packages.config" />
|
||||||
<None Include="Resources\oC-favico_NewMessage.ico" />
|
<None Include="Resources\oC-favico_NewMessage.ico" />
|
||||||
<Content Include="Resources\ownchat_favicon.ico" />
|
<Content Include="Resources\ownchat_favicon.ico" />
|
||||||
<Resource Include="Ressourcen\ownchat_favicon.ico" />
|
<Resource Include="Ressourcen\ownchat_favicon.ico" />
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ namespace ChatController.ChatKlassen
|
|||||||
{
|
{
|
||||||
public class ChatMessage
|
public class ChatMessage
|
||||||
{
|
{
|
||||||
|
public long FileSize { get; set; }
|
||||||
|
|
||||||
//Chat-Ansicht
|
//Chat-Ansicht
|
||||||
public ChatMessage(string username, string message, DateTime sendtime, bool isme, long pGroupId)
|
public ChatMessage(string username, string message, DateTime sendtime, bool isme, long pGroupId, long fileSize)
|
||||||
{
|
{
|
||||||
Username = username;
|
Username = username;
|
||||||
UserMessage = message;
|
UserMessage = message;
|
||||||
@@ -24,7 +26,7 @@ namespace ChatController.ChatKlassen
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Image-Ansicht
|
// Image-Ansicht
|
||||||
public ChatMessage(string username, string message, DateTime sendtime, bool isme, ImageSource image, string originalImage, string imageName, long pGroupId)
|
public ChatMessage(string username, string message, DateTime sendtime, bool isme, ImageSource image, string originalImage, string imageName, long pGroupId, long fileSize)
|
||||||
{
|
{
|
||||||
Username = username;
|
Username = username;
|
||||||
UserMessage = message;
|
UserMessage = message;
|
||||||
@@ -43,7 +45,7 @@ namespace ChatController.ChatKlassen
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Dokumenten-Ansicht
|
//Dokumenten-Ansicht
|
||||||
public ChatMessage(string pUsername, string pMessageText, DateTime pSendTime, string pSmallerImagePath, bool pIsLoggedInUsersMessage, string pUrl, long pGroupId)
|
public ChatMessage(string pUsername, string pMessageText, DateTime pSendTime, string pSmallerImagePath, bool pIsLoggedInUsersMessage, string pUrl, long pGroupId, long fileSize)
|
||||||
{
|
{
|
||||||
Username = pUsername;
|
Username = pUsername;
|
||||||
UserMessage = pMessageText;
|
UserMessage = pMessageText;
|
||||||
@@ -133,6 +135,11 @@ namespace ChatController.ChatKlassen
|
|||||||
|
|
||||||
public static bool IsHyperlink(string word)
|
public static bool IsHyperlink(string word)
|
||||||
{
|
{
|
||||||
|
if(word == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (word.IndexOfAny(@":.\/".ToCharArray()) != -1)
|
if (word.IndexOfAny(@":.\/".ToCharArray()) != -1)
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ namespace ChatController.HauptKlassen
|
|||||||
|
|
||||||
if (!string.IsNullOrEmpty(serverResponse))
|
if (!string.IsNullOrEmpty(serverResponse))
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine(serverResponse);
|
||||||
_UserMessages = JsonConvert.DeserializeObject<UserMessages>(serverResponse);
|
_UserMessages = JsonConvert.DeserializeObject<UserMessages>(serverResponse);
|
||||||
|
|
||||||
if (_UserMessages.Response.HasMorePages)
|
if (_UserMessages.Response.HasMorePages)
|
||||||
@@ -337,7 +338,8 @@ namespace ChatController.HauptKlassen
|
|||||||
{
|
{
|
||||||
var username = "";
|
var username = "";
|
||||||
|
|
||||||
var user = ChatDaten.AngemeldeterUser.Response.Values.FirstOrDefault();
|
//var user = ChatDaten.AngemeldeterUser.Response.Values.FirstOrDefault();
|
||||||
|
var user = ChatDaten.AngemeldeterUser.Response.User;
|
||||||
if(user != null)
|
if(user != null)
|
||||||
{
|
{
|
||||||
username = $"{user.Firstname} {user.Lastname}";
|
username = $"{user.Firstname} {user.Lastname}";
|
||||||
@@ -345,7 +347,7 @@ namespace ChatController.HauptKlassen
|
|||||||
|
|
||||||
var time = DateTime.Now;
|
var time = DateTime.Now;
|
||||||
|
|
||||||
Messages.Add(new ChatMessage(username, pMessage, time, true, pGroupId));
|
Messages.Add(new ChatMessage(username, pMessage, time, true, pGroupId, 0));
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -474,7 +476,7 @@ namespace ChatController.HauptKlassen
|
|||||||
|
|
||||||
filename = filename.Replace(".bmp", ".jpg");
|
filename = filename.Replace(".bmp", ".jpg");
|
||||||
|
|
||||||
Messages.Add(new ChatMessage(message.User_Name, filename, sendTime, true, bitmapImage, pFile, filename, pGroupId));
|
Messages.Add(new ChatMessage(message.User_Name, filename, sendTime, true, bitmapImage, pFile, filename, pGroupId, file.LongLength));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,7 +485,7 @@ namespace ChatController.HauptKlassen
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Messages.Add(new ChatMessage(message.User_Name, Path.GetFileName(pFile), sendTime, message.Smaller_Image, true, pFile, pGroupId));
|
Messages.Add(new ChatMessage(message.User_Name, Path.GetFileName(pFile), sendTime, message.Smaller_Image, true, pFile, pGroupId, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -516,11 +518,11 @@ namespace ChatController.HauptKlassen
|
|||||||
memoryStream.Close();
|
memoryStream.Close();
|
||||||
ImageSource logo = bitmapImage;
|
ImageSource logo = bitmapImage;
|
||||||
|
|
||||||
Messages.Add(new ChatMessage(message.User_Name, Path.GetFileName(pFileName), sendtime, true, logo, pFileName, Path.GetFileName(pFileName), pGroupId));
|
Messages.Add(new ChatMessage(message.User_Name, Path.GetFileName(pFileName), sendtime, true, logo, pFileName, Path.GetFileName(pFileName), pGroupId, memoryStream.Length));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Messages.Add(new ChatMessage(message.User_Name, Path.GetFileName(pFileName), sendtime, message.Smaller_Image, true, pFileName, pGroupId));
|
Messages.Add(new ChatMessage(message.User_Name, Path.GetFileName(pFileName), sendtime, message.Smaller_Image, true, pFileName, pGroupId, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1294,12 +1296,12 @@ namespace ChatController.HauptKlassen
|
|||||||
if (!string.IsNullOrEmpty(message.File))
|
if (!string.IsNullOrEmpty(message.File))
|
||||||
{
|
{
|
||||||
Messages.Add(Constants.ImageFileExtensions.Contains(Path.GetExtension(message.File).ToUpperInvariant()) ? //SmallerImage ist null
|
Messages.Add(Constants.ImageFileExtensions.Contains(Path.GetExtension(message.File).ToUpperInvariant()) ? //SmallerImage ist null
|
||||||
new ChatMessage(message.User_Name, messageText, formattedTime, isLoggedInUsersMessage, DownloadImage(message.Smaller_Image), message.File, message.Original_Filename, message.GroupId) :
|
new ChatMessage(message.User_Name, messageText, formattedTime, isLoggedInUsersMessage, DownloadImage(message.Smaller_Image), message.File, message.Original_Filename, message.GroupId, message.FileSize) :
|
||||||
new ChatMessage(message.User_Name, messageText, formattedTime, message.Smaller_Image, isLoggedInUsersMessage, message.File, message.GroupId));
|
new ChatMessage(message.User_Name, messageText, formattedTime, message.Smaller_Image, isLoggedInUsersMessage, message.File, message.GroupId, message.FileSize));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Messages.Add(new ChatMessage(message.User_Name, message.Text, formattedTime, isLoggedInUsersMessage, message.GroupId));
|
Messages.Add(new ChatMessage(message.User_Name, message.Text, formattedTime, isLoggedInUsersMessage, message.GroupId, message.FileSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using ChatController.LoginKlassen;
|
using ChatController.LoginKlassen;
|
||||||
using ChatController.Utilities;
|
using ChatController.Utilities;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using RestSharp;
|
||||||
|
|
||||||
namespace ChatController.HauptKlassen
|
namespace ChatController.HauptKlassen
|
||||||
{
|
{
|
||||||
public class Login
|
public class Login
|
||||||
{
|
{
|
||||||
private string _Url = "";
|
private string _Url = string.Empty;
|
||||||
|
|
||||||
private readonly string _NewUrl = "https://dict.ownchat.de/api/server/resolve/1/";
|
private const string _NewUrl = "https://dict.ownchat.de/api/server/resolve/1/";
|
||||||
|
|
||||||
public string ServerUrl { get; set; } = "";
|
public string ServerUrl { get; set; } = string.Empty;
|
||||||
private string _AuthToken = "";
|
private string _AuthToken = string.Empty;
|
||||||
|
|
||||||
private readonly string _UserName;
|
private readonly string _UserName;
|
||||||
private readonly string _Password;
|
private readonly string _Password;
|
||||||
@@ -80,16 +80,12 @@ namespace ChatController.HauptKlassen
|
|||||||
{
|
{
|
||||||
GetGroups();
|
GetGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (_gruppeholenverbindungsaufbauOK)
|
if (_gruppeholenverbindungsaufbauOK)
|
||||||
{
|
{
|
||||||
|
|
||||||
var maxUploadSize = GetMaiximumAllowedFileUploadSize(_AuthToken,_Tenant);
|
var maxUploadSize = GetMaiximumAllowedFileUploadSize(_AuthToken,_Tenant);
|
||||||
|
|
||||||
var ubergabe = new ChatDatenUebergabe(_serverconect, _LoggedInUser, _AllGroups, ServerUrl, _AuthToken, _UserId, _Tenant,_ApiKey, maxUploadSize);
|
return new ChatDatenUebergabe(_serverconect, _LoggedInUser, _AllGroups, ServerUrl, _AuthToken, _UserId, _Tenant, _ApiKey, maxUploadSize);
|
||||||
|
|
||||||
return ubergabe;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,85 +206,62 @@ namespace ChatController.HauptKlassen
|
|||||||
{
|
{
|
||||||
var endurl = _Url + "/api/user/loginwithchatcode";
|
var endurl = _Url + "/api/user/loginwithchatcode";
|
||||||
|
|
||||||
var postdaten = "";
|
var requestBody = postparameter.Keys.Aggregate(string.Empty, (current, key) => current + HttpUtility.UrlEncode(key) + "=" + HttpUtility.UrlEncode(postparameter[key]) + "&");
|
||||||
|
|
||||||
var i = 0;
|
var client = new RestClient(endurl);
|
||||||
foreach (var key in postparameter.Keys)
|
var request = new RestRequest(Method.POST);
|
||||||
|
|
||||||
|
request.AddHeader("content-type", "application/x-www-form-urlencoded");
|
||||||
|
request.AddParameter(Constants.CustomerId, _Tenant, ParameterType.HttpHeader);
|
||||||
|
request.AddParameter("application/x-www-form-urlencoded", requestBody, ParameterType.RequestBody);
|
||||||
|
|
||||||
|
var response = client.Post(request);
|
||||||
|
|
||||||
|
if (response.StatusCode == HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
postdaten += HttpUtility.UrlEncode(key) + "=" + HttpUtility.UrlEncode(postparameter[key]) + "&";
|
var userDaten = JsonConvert.DeserializeObject<UserDaten>(response.Content);
|
||||||
}
|
|
||||||
|
|
||||||
var webRequest = WebRequest.Create(endurl);
|
if(userDaten.Success)
|
||||||
|
|
||||||
webRequest.Method = "POST";
|
|
||||||
webRequest.ContentType = "application/x-www-form-urlencoded";
|
|
||||||
webRequest.Headers[Constants.CustomerId] = _Tenant;
|
|
||||||
|
|
||||||
var daten = Encoding.ASCII.GetBytes(postdaten);
|
|
||||||
|
|
||||||
webRequest.ContentLength = daten.Length;
|
|
||||||
|
|
||||||
var requestStream = webRequest.GetRequestStream();
|
|
||||||
|
|
||||||
requestStream.Write(daten, 0, daten.Length);
|
|
||||||
|
|
||||||
requestStream.Close();
|
|
||||||
|
|
||||||
var myHttpWebResponse = (HttpWebResponse)webRequest.GetResponse();
|
|
||||||
|
|
||||||
var responseStream = myHttpWebResponse.GetResponseStream();
|
|
||||||
|
|
||||||
var myStreamReader = new StreamReader(responseStream, Encoding.Default);
|
|
||||||
|
|
||||||
var pageContent = myStreamReader.ReadToEnd();
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(pageContent))
|
|
||||||
{
|
|
||||||
var jsonDaten = JsonConvert.DeserializeObject<UserDaten>(pageContent);
|
|
||||||
|
|
||||||
if (jsonDaten.Success)
|
|
||||||
{
|
{
|
||||||
foreach (var datev in jsonDaten.Response)
|
_AuthToken = userDaten.Response.User.Token;
|
||||||
{
|
_UserId = userDaten.Response.User.Oid;
|
||||||
_AuthToken = datev.Value.Token;
|
|
||||||
_UserId = datev.Value.Oid;
|
|
||||||
}
|
|
||||||
|
|
||||||
_LoggedInUser = jsonDaten;
|
_LoggedInUser = userDaten;
|
||||||
|
|
||||||
_ownchatVerbindungsaufbauOK = true;
|
_ownchatVerbindungsaufbauOK = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (jsonDaten.Errors.chatcode_failed != null)
|
if(userDaten.Errors.chatcode_failed != null)
|
||||||
{
|
{
|
||||||
if (_ShouldShowMessageBox)
|
if(_ShouldShowMessageBox)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Fehler: " + jsonDaten.Errors.chatcode_failed[0] + "\nBitte überprüfen Sie die Anmeldeinformationen.", "Info", MessageBoxButton.OK, MessageBoxImage.Error);
|
MessageBox.Show("Fehler: " + userDaten.Errors.chatcode_failed[0] + "\nBitte überprüfen Sie die Anmeldeinformationen.", "Info", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
}
|
|
||||||
}else if (jsonDaten.Errors.login_failed != null)
|
|
||||||
{
|
|
||||||
if (_ShouldShowMessageBox)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Fehler: " + jsonDaten.Errors.login_failed[0] + "\nBitte überprüfen Sie die Anmeldeinformationen.", "Info", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(userDaten.Errors.login_failed != null)
|
||||||
|
{
|
||||||
|
if(_ShouldShowMessageBox)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Fehler: " + userDaten.Errors.login_failed[0] + "\nBitte überprüfen Sie die Anmeldeinformationen.", "Info", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_ownchatVerbindungsaufbauOK = false;
|
_ownchatVerbindungsaufbauOK = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
myStreamReader.Close();
|
|
||||||
responseStream.Close();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
{
|
||||||
if (_ShouldShowMessageBox)
|
MessageBox.Show(response.Content, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
{
|
|
||||||
MessageBox.Show("Fehler:" + e.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (_ShouldShowMessageBox)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Fehler:" + e.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetGroups()
|
private void GetGroups()
|
||||||
@@ -306,7 +279,7 @@ namespace ChatController.HauptKlassen
|
|||||||
using (var response = request.GetResponse())
|
using (var response = request.GetResponse())
|
||||||
{
|
{
|
||||||
var serverResponse = Utils.ReadStream(response);
|
var serverResponse = Utils.ReadStream(response);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(serverResponse))
|
if (!string.IsNullOrEmpty(serverResponse))
|
||||||
{
|
{
|
||||||
var jsonDaten = JsonConvert.DeserializeObject<ChatGruppenDaten>(serverResponse);
|
var jsonDaten = JsonConvert.DeserializeObject<ChatGruppenDaten>(serverResponse);
|
||||||
|
|||||||
@@ -1,31 +1,33 @@
|
|||||||
using System.Collections.Generic;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace ChatController.LoginKlassen
|
namespace ChatController.LoginKlassen
|
||||||
{
|
{
|
||||||
public class UserDaten
|
public class UserDaten
|
||||||
{
|
{
|
||||||
public Dictionary<string, TestInput> Response { get; set; }
|
public string Token { get; set; }
|
||||||
|
|
||||||
|
public OwnChatLoginResponse Response { get; set; }
|
||||||
|
|
||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
|
|
||||||
public Tetserror Errors { get; set; }
|
public Tetserror Errors { get; set; }
|
||||||
|
|
||||||
public bool Success { get; set; }
|
public bool Success { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InputTest
|
public class InputTest
|
||||||
{
|
{
|
||||||
public TestInput User { get; set; }
|
public OwnChatLoginResponse User { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestInput
|
public class OwnChatLoginResponse
|
||||||
{
|
{
|
||||||
public long? Oid { get; set; }
|
[JsonProperty("file_upload_max_size")]
|
||||||
public string UserId { get; set; }
|
public long FileUploadMaxSize { get; set; }
|
||||||
public string Firstname { get; set; }
|
|
||||||
public string Lastname { get; set; }
|
|
||||||
public string Mobile { get; set; }
|
|
||||||
public string Picture { get; set; }
|
|
||||||
public bool Is_Employee { get; set; }
|
|
||||||
public string Token { get; set; }
|
public string Token { get; set; }
|
||||||
|
|
||||||
|
public OwnChatUser User { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Tetserror
|
public class Tetserror
|
||||||
@@ -33,4 +35,24 @@ namespace ChatController.LoginKlassen
|
|||||||
public string[] chatcode_failed{ get; set; }
|
public string[] chatcode_failed{ get; set; }
|
||||||
public string[] login_failed { get; set; }
|
public string[] login_failed { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class OwnChatUser
|
||||||
|
{
|
||||||
|
public long Oid { get; set; }
|
||||||
|
|
||||||
|
public string UserId { get; set; }
|
||||||
|
|
||||||
|
public string Firstname { get; set; }
|
||||||
|
|
||||||
|
public string Lastname { get; set; }
|
||||||
|
|
||||||
|
public string Mobile { get; set; }
|
||||||
|
|
||||||
|
public string Picture { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("is_employee")]
|
||||||
|
public bool IsEmployee { get; set; }
|
||||||
|
|
||||||
|
public string Token { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace ChatController.LoginKlassen
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace ChatController.LoginKlassen
|
||||||
{
|
{
|
||||||
public class UserMessages
|
public class UserMessages
|
||||||
{
|
{
|
||||||
@@ -31,5 +33,8 @@
|
|||||||
public string User_Name { get; set; }
|
public string User_Name { get; set; }
|
||||||
public string User_Picture { get; set; }
|
public string User_Picture { get; set; }
|
||||||
public long GroupId { get; set; }
|
public long GroupId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("file_size")]
|
||||||
|
public long FileSize { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ using System.Linq;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
using RestSharp;
|
||||||
using MessageBox = System.Windows.MessageBox;
|
using MessageBox = System.Windows.MessageBox;
|
||||||
using PixelFormat = System.Drawing.Imaging.PixelFormat;
|
using PixelFormat = System.Drawing.Imaging.PixelFormat;
|
||||||
|
|
||||||
@@ -55,40 +57,46 @@ namespace ChatController.Utilities
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(pPathToImageFile))
|
if (!string.IsNullOrEmpty(pPathToImageFile))
|
||||||
{
|
{
|
||||||
Bitmap bitmap;
|
Bitmap bitmap = null;
|
||||||
var request = WebRequest.Create(pPathToImageFile);
|
|
||||||
using (var response = request.GetResponse())
|
var client = new RestClient(pPathToImageFile);
|
||||||
|
var request = new RestRequest(Method.GET)
|
||||||
{
|
{
|
||||||
using (var stream = response.GetResponseStream())
|
ResponseWriter = stream =>
|
||||||
{
|
{
|
||||||
if (stream != null)
|
try
|
||||||
{
|
{
|
||||||
bitmap = new Bitmap(stream);
|
bitmap = new Bitmap(stream);
|
||||||
}
|
}
|
||||||
else
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
return GetDefaultImageSource(pIsGroup, pIsEmployee);
|
bitmap = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
using (var memoryStream = new MemoryStream())
|
client.DownloadData(request);
|
||||||
|
|
||||||
|
if (bitmap != null)
|
||||||
{
|
{
|
||||||
bitmap.Save(memoryStream, ImageFormat.Png);
|
using (var memoryStream = new MemoryStream())
|
||||||
|
{
|
||||||
|
bitmap.Save(memoryStream, ImageFormat.Png);
|
||||||
|
|
||||||
memoryStream.Position = 0;
|
memoryStream.Position = 0;
|
||||||
|
|
||||||
var bitmapImage = new BitmapImage();
|
var bitmapImage = new BitmapImage();
|
||||||
|
|
||||||
bitmapImage.BeginInit();
|
bitmapImage.BeginInit();
|
||||||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
bitmapImage.StreamSource = memoryStream;
|
bitmapImage.StreamSource = memoryStream;
|
||||||
bitmapImage.EndInit();
|
bitmapImage.EndInit();
|
||||||
|
|
||||||
memoryStream.Dispose();
|
memoryStream.Dispose();
|
||||||
memoryStream.Close();
|
memoryStream.Close();
|
||||||
|
|
||||||
return bitmapImage;
|
return bitmapImage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user