tr
This commit is contained in:
30
ChatController/Utilities/Constants.cs
Normal file
30
ChatController/Utilities/Constants.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ChatController.Utilities
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public static readonly List<string> ImageFileExtensions = new List<string> { ".JPG", ".JPE", ".BMP", ".GIF", ".PNG", ".JPEG" };
|
||||
public static readonly List<string> DocumentFileExtension = new List<string> { ".TXT", ".PPT", ".XLS", ".DOC", ".PDF" };
|
||||
|
||||
public static readonly string TeamDefaultImagePath = "pack://application:,,,/ChatController;component/Ressourcen/team_default.png";
|
||||
public static readonly string EmployeeDefaultImagePath = "pack://application:,,,/ChatController;component/Ressourcen/employee_default.png";
|
||||
public static readonly string CustomerDefaultImagePath = "pack://application:,,,/ChatController;component/Ressourcen/client_default.png";
|
||||
public static readonly string NormalGroupDefaultImagePath = "pack://application:,,,/ChatController;component/Ressourcen/mitarbeiter-team-avatar.png";
|
||||
|
||||
public static readonly string Token = "Token";
|
||||
public static readonly string CustomerId = "CustomerID";
|
||||
|
||||
public static readonly string MaxUploadFileSizeUrl = "/api/ownchat/uploadmaxsize";
|
||||
public static readonly string LoginWithChatCodeUrl = "/api/user/loginwithchatcode";
|
||||
public static readonly string GetChatGroupsUrl = "/api/chat/groups";
|
||||
public static readonly string LoadMessagesForGroupUrl = "/api/chat/messages?groupid=";
|
||||
public static readonly string LoadOwnChatNewsUrl = "/api/ownchat/news/";
|
||||
|
||||
public static readonly string UrlPageParameter = "&page=";
|
||||
|
||||
public static readonly string ConfigFile = "ownChat.txt";
|
||||
public static readonly string CompanyName = "beyondSoft";
|
||||
public static readonly string ApplicationFolderName = "OwnChat";
|
||||
}
|
||||
}
|
||||
146
ChatController/Utilities/Utils.cs
Normal file
146
ChatController/Utilities/Utils.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace ChatController.Utilities
|
||||
{
|
||||
public class Utils
|
||||
{
|
||||
public static ImageSource AvatarToImageSourceConverter(string pAvatarPath, bool pIsEmployee)
|
||||
{
|
||||
return CreateImageSourceFromPath(pAvatarPath, false, pIsEmployee);
|
||||
}
|
||||
|
||||
public static ImageSource CreateChatGroupPictureImageSource(string pPicturePath, bool pIsGroup, bool pIsEmployee)
|
||||
{
|
||||
return CreateImageSourceFromPath(pPicturePath, pIsGroup, pIsEmployee);
|
||||
}
|
||||
|
||||
private static ImageSource GetDefaultImageSource(bool pIsGroup, bool pIsEmployee)
|
||||
{
|
||||
var defaultImage = Constants.EmployeeDefaultImagePath;
|
||||
|
||||
if (pIsGroup)
|
||||
{
|
||||
defaultImage = pIsEmployee ? Constants.TeamDefaultImagePath : Constants.NormalGroupDefaultImagePath;
|
||||
}
|
||||
else if (!pIsEmployee)
|
||||
{
|
||||
defaultImage = Constants.CustomerDefaultImagePath;
|
||||
}
|
||||
|
||||
var resultBitmapImage = new BitmapImage();
|
||||
|
||||
resultBitmapImage.BeginInit();
|
||||
resultBitmapImage.UriSource = new Uri(defaultImage);
|
||||
resultBitmapImage.EndInit();
|
||||
|
||||
return resultBitmapImage;
|
||||
}
|
||||
|
||||
public static ImageSource CreateImageSourceFromPath(string pPathToImageFile, bool pIsGroup = false, bool pIsEmployee = false)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(pPathToImageFile))
|
||||
{
|
||||
Bitmap bitmap;
|
||||
var request = WebRequest.Create(pPathToImageFile);
|
||||
using (var response = request.GetResponse())
|
||||
{
|
||||
using (var stream = response.GetResponseStream())
|
||||
{
|
||||
if (stream != null)
|
||||
{
|
||||
bitmap = new Bitmap(stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetDefaultImageSource(pIsGroup, pIsEmployee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
bitmap.Save(memoryStream, ImageFormat.Png);
|
||||
|
||||
memoryStream.Position = 0;
|
||||
|
||||
var bitmapImage = new BitmapImage();
|
||||
|
||||
bitmapImage.BeginInit();
|
||||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||
bitmapImage.StreamSource = memoryStream;
|
||||
bitmapImage.EndInit();
|
||||
|
||||
memoryStream.Dispose();
|
||||
memoryStream.Close();
|
||||
|
||||
return bitmapImage;
|
||||
}
|
||||
}
|
||||
|
||||
return GetDefaultImageSource(pIsGroup, pIsEmployee);
|
||||
}
|
||||
|
||||
public static ImageSource CreateImageSourceFromSmallerImage(string pUri)
|
||||
{
|
||||
Bitmap bitmap;
|
||||
var request = WebRequest.Create(pUri);
|
||||
using(var response = request.GetResponse())
|
||||
{
|
||||
using(var stream = response.GetResponseStream())
|
||||
{
|
||||
if(stream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
bitmap = new Bitmap(stream);
|
||||
}
|
||||
}
|
||||
|
||||
using(var memoryStream = new MemoryStream())
|
||||
{
|
||||
bitmap.Save(memoryStream, ImageFormat.Png);
|
||||
memoryStream.Position = 0;
|
||||
|
||||
var bitmapImage = new BitmapImage();
|
||||
|
||||
bitmapImage.BeginInit();
|
||||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||
bitmapImage.StreamSource = memoryStream;
|
||||
bitmapImage.EndInit();
|
||||
|
||||
memoryStream.Dispose();
|
||||
memoryStream.Close();
|
||||
|
||||
return bitmapImage;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReadStream(WebResponse response)
|
||||
{
|
||||
var dataStream = response.GetResponseStream();
|
||||
|
||||
if (dataStream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var reader = new StreamReader(dataStream);
|
||||
var responseFromServer = reader.ReadToEnd();
|
||||
|
||||
dataStream.Dispose();
|
||||
reader.Dispose();
|
||||
|
||||
dataStream.Close();
|
||||
reader.Close();
|
||||
|
||||
return responseFromServer;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user