157 lines
5.0 KiB
C#
157 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web.Http;
|
|
using C4IT.API.Contracts;
|
|
using C4IT.Logging;
|
|
using System.Reflection;
|
|
using System.Web.Http.Controllers;
|
|
using Matrix42.Pandora.Contracts;
|
|
using static C4IT.Logging.cLogManager;
|
|
using Matrix42.Pandora.Contracts.Internationalization;
|
|
using System.Security.Principal;
|
|
using update4u.SPS.DataLayer.Query.FunctionExpression;
|
|
using System.Net.Http;
|
|
using System.Net;
|
|
|
|
namespace C4IT.API
|
|
{
|
|
[RoutePrefix("api/c4it/customerpanel")]
|
|
|
|
public class CustomerPanelController : ApiController
|
|
{
|
|
private readonly CustomerPanelHelper _CPanelHelper = new CustomerPanelHelper();
|
|
|
|
public static bool IsInitialized { get; private set; } = false;
|
|
|
|
public IPandoraUserProfile UserProfile => _userProfile;
|
|
|
|
public ICultureConfuguration GlobalSettings => _globalSettings;
|
|
|
|
public LanguageInfo[] Languages => _languages ?? (_languages = GlobalSettings.GetLanguages());
|
|
|
|
private static Object initLock = new object();
|
|
internal static CustomerPanelController controller = null;
|
|
|
|
private readonly IPandoraUserProfile _userProfile;
|
|
private readonly ICultureConfuguration _globalSettings;
|
|
private LanguageInfo[] _languages = null;
|
|
public CustomerPanelController(IPandoraUserProfile pandoraUserProfile, ICultureConfuguration globalSettings)
|
|
{
|
|
controller = this;
|
|
_userProfile = pandoraUserProfile;
|
|
_globalSettings = globalSettings;
|
|
}
|
|
|
|
protected override void Initialize(HttpControllerContext controllerContext)
|
|
{
|
|
base.Initialize(controllerContext);
|
|
try
|
|
{
|
|
lock (initLock)
|
|
{
|
|
if (IsInitialized)
|
|
return;
|
|
|
|
var Ass = Assembly.GetExecutingAssembly();
|
|
var LM = cLogManagerFile.CreateInstance(LocalMachine: true, A: Ass);
|
|
var CM = MethodBase.GetCurrentMethod();
|
|
LogMethodBegin(CM);
|
|
cLogManager.DefaultLogger.LogAssemblyInfo(Ass);
|
|
|
|
CustomerPanelSecurePassword.Init();
|
|
PrivateCustomerPanelSecurePassword.Init();
|
|
|
|
IsInitialized = true;
|
|
LogMethodEnd(CM);
|
|
}
|
|
}
|
|
catch { };
|
|
}
|
|
|
|
[Route("version"), HttpGet]
|
|
public Version GetVersion()
|
|
{
|
|
return _CPanelHelper.getVersion();
|
|
}
|
|
|
|
[Route("closeallclients"), HttpGet]
|
|
public bool GetCloseAllClients()
|
|
{
|
|
return _CPanelHelper.GetCloseAllClients();
|
|
}
|
|
|
|
[Route("config"), HttpGet]
|
|
public CustomerPanelConfig GetConfig(bool noCache = false)
|
|
{
|
|
return _CPanelHelper.GetConfig(noCache);
|
|
}
|
|
|
|
[Route("tickets/{userid:guid}"), HttpGet]
|
|
public List<Ticket> GetTicketsByUserId(Guid userId)
|
|
{
|
|
return _CPanelHelper.GetTickets(userId);
|
|
}
|
|
[Route("tickets"), HttpGet]
|
|
public List<Ticket> GetTickets()
|
|
{
|
|
return _CPanelHelper.GetTickets(controller.UserProfile.UserId);
|
|
}
|
|
|
|
[Route("resetCache"), HttpGet]
|
|
public bool ResetCache()
|
|
{
|
|
return this._CPanelHelper.ResetCache();
|
|
}
|
|
|
|
[Route("announcements/{userid:guid}"), HttpGet]
|
|
public List<Contracts.Announcement> GetAnnouncementsByUserId(announcementType type, Guid userId, bool noCache = false)
|
|
{
|
|
return GetAnnouncementsInternal(type, userId, noCache);
|
|
}
|
|
|
|
[Route("announcements"), HttpGet]
|
|
public List<Contracts.Announcement> GetAnnouncements(announcementType type, bool noCache = false)
|
|
{
|
|
return GetAnnouncementsInternal(type, null, noCache);
|
|
}
|
|
|
|
[Route("isalive"), HttpGet]
|
|
public HttpResponseMessage isAlive()
|
|
{
|
|
return new HttpResponseMessage(HttpStatusCode.NoContent);
|
|
}
|
|
|
|
private List<Contracts.Announcement> GetAnnouncementsInternal(announcementType type, Guid? userId, bool noCache)
|
|
{
|
|
switch (type)
|
|
{
|
|
case announcementType.Regular:
|
|
return userId.HasValue
|
|
? this._CPanelHelper.GetRegularAnnouncements(userId.Value)
|
|
: this._CPanelHelper.GetRegularAnnouncements(controller.UserProfile.UserId);
|
|
case announcementType.Adhoc:
|
|
return this._CPanelHelper.GetAdHocAnnouncements(noCache);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
[Route("Encode"), HttpPost]
|
|
public string Encode(string str)
|
|
{
|
|
return this._CPanelHelper.Encode(str);
|
|
}
|
|
|
|
[Route("ApiCache"), HttpGet]
|
|
public Object GetApiCache()
|
|
{
|
|
return ApiCache.GetAllKeysInCache();
|
|
}
|
|
|
|
//[Route("JoinPool"), HttpGet]
|
|
//public void JoinHubPool()
|
|
//{
|
|
//}
|
|
}
|
|
}
|