feat: migrate 26eac54 state to Matrix42 26.1
This commit is contained in:
@@ -1,25 +1,28 @@
|
||||
using C4IT.F4SDM;
|
||||
using C4IT.FASD.Base;
|
||||
using C4IT.Logging;
|
||||
using Matrix42.Common;
|
||||
using Matrix42.Contracts.ServiceManagement.ServiceContracts;
|
||||
using Matrix42.Pandora.Contracts;
|
||||
using Matrix42.Services.Description.Contracts;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.OData;
|
||||
using System.Web.OData.Query;
|
||||
|
||||
using Matrix42.Common;
|
||||
using Matrix42.Contracts.Common.Security;
|
||||
using Matrix42.Contracts.ServiceManagement.ServiceContracts;
|
||||
using Matrix42.Hosting.Contracts;
|
||||
using Matrix42.Pandora.Contracts;
|
||||
using Matrix42.Persistence.Contracts;
|
||||
using Matrix42.Services.Description.Contracts;
|
||||
using Matrix42.WebApi.Contracts;
|
||||
using Matrix42.WebApi.Contracts.OData;
|
||||
using update4u.SPS.Utility.GlobalConfiguration;
|
||||
using static C4IT.FASD.Base.cF4SDTicket;
|
||||
|
||||
using C4IT.F4SDM;
|
||||
using C4IT.FASD.Base;
|
||||
using C4IT.Logging;
|
||||
|
||||
using static C4IT.Logging.cLogManager;
|
||||
|
||||
namespace C4IT.F4SD
|
||||
@@ -28,47 +31,33 @@ namespace C4IT.F4SD
|
||||
public partial class F4SDM42WebApiController : ApiController
|
||||
{
|
||||
public static bool IsInitialized { get; private set; } = false;
|
||||
|
||||
public static F4SDM42WebApiController defaultInstance;
|
||||
//private readonly IIncidentService _incidentService;
|
||||
internal readonly GlobalConfigurationProvider _globalConfigurationProvider;
|
||||
public readonly IJournalService _journalService;
|
||||
//public readonly IObjectService _objectService;
|
||||
//public readonly IFragmentService _fragmentService;
|
||||
internal readonly IEntityDataService _entityDataService;
|
||||
internal readonly IPandoraUserProfile _userProfile;
|
||||
private readonly IDependencyResolver _resolver;
|
||||
|
||||
|
||||
private readonly F4SDHelperService _f4stHelperService;
|
||||
public string BaseUrl => $"{Request.RequestUri.Scheme}://{Request.RequestUri.Host}";
|
||||
public string BaseUrl => Request?.RequestUri == null ? string.Empty : $"{Request.RequestUri.Scheme}://{Request.RequestUri.Host}";
|
||||
public string EndpointBaseUrl => $"{BaseUrl}/m42Services/api/c4itf4sdwebapi";
|
||||
public F4SDM42WebApiController(
|
||||
//IObjectService objectService,
|
||||
//IIncidentService incidentService,
|
||||
IJournalService journalService
|
||||
//IFragmentService fragmentService,
|
||||
, IEntityDataService entityDataService
|
||||
, IPandoraUserProfile userProfile
|
||||
)
|
||||
{
|
||||
defaultInstance = this;
|
||||
//_objectService = objectService;
|
||||
//_fragmentService = fragmentService;
|
||||
//_incidentService = Guard.NullArgument(incidentService, "incidentService");
|
||||
|
||||
_entityDataService = entityDataService;
|
||||
_journalService = journalService;
|
||||
public F4SDM42WebApiController(IDependencyResolver resolver)
|
||||
{
|
||||
_resolver = resolver ?? throw new ArgumentNullException(nameof(resolver));
|
||||
defaultInstance = this;
|
||||
_globalConfigurationProvider = GlobalConfigurationProvider.Instance;
|
||||
_f4stHelperService = new F4SDHelperService();
|
||||
_userProfile = userProfile;
|
||||
EnsureInitialized();
|
||||
}
|
||||
|
||||
private static object initLock = new object();
|
||||
protected override void Initialize(HttpControllerContext controllerContext)
|
||||
private static readonly object initLock = new object();
|
||||
private static void EnsureInitialized()
|
||||
{
|
||||
base.Initialize(controllerContext);
|
||||
try
|
||||
{
|
||||
//System.Diagnostics.Debugger.Launch();
|
||||
lock (initLock)
|
||||
{
|
||||
if (IsInitialized || F4SDM42LogsWebApiController.IsInitialized)
|
||||
@@ -85,40 +74,80 @@ namespace C4IT.F4SD
|
||||
catch { };
|
||||
}
|
||||
|
||||
internal IJournalService GetJournalService()
|
||||
{
|
||||
return GetRequiredService<IJournalService>();
|
||||
}
|
||||
|
||||
private IEnumerationProvider GetEnumerationProvider()
|
||||
{
|
||||
return GetRequiredService<IEnumerationProvider>();
|
||||
}
|
||||
|
||||
private T GetRequiredService<T>() where T : class
|
||||
{
|
||||
var service = _resolver.TryGet<T>();
|
||||
if (service != null)
|
||||
return service;
|
||||
|
||||
throw new InvalidOperationException($"Required Matrix42 service is not registered: {typeof(T).FullName}");
|
||||
}
|
||||
|
||||
[Route("getDirectLinkCreateTicket"), HttpGet]
|
||||
public async Task<F4SDHelperService.DirectLink> getDirectLinkCreateTicket(string sid = "", string assetname = "")
|
||||
{
|
||||
await Task.Delay(0);
|
||||
return await _f4stHelperService.getDirectLinkCreateTicket(sid, assetname);
|
||||
}
|
||||
|
||||
[Route("getDirectLinkF4SD"), HttpGet]
|
||||
public async Task<string> getDirectLinkF4SD(Guid EOID, string Type)
|
||||
{
|
||||
return await _f4stHelperService.getDirectLinkF4SD(EOID, Type);
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
[Route("getTicketList"), HttpGet]
|
||||
public async Task<List<cF4SDTicketSummary>> getTicketList(
|
||||
string sid,
|
||||
int hours,
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
var decodedPairs = ParseQueues(queues);
|
||||
|
||||
// Nun weiterreichen an Service
|
||||
return await _f4stHelperService.getTicketListByUser(
|
||||
sid,
|
||||
hours,
|
||||
queueoption,
|
||||
public async Task<List<cF4SDTicketSummary>> getTicketList(
|
||||
string sid,
|
||||
int hours,
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
var decodedPairs = ParseQueues(queues);
|
||||
|
||||
// Nun weiterreichen an Service
|
||||
return await _f4stHelperService.getTicketListByUser(
|
||||
sid,
|
||||
hours,
|
||||
queueoption,
|
||||
decodedPairs
|
||||
);
|
||||
}
|
||||
|
||||
[Route("getTicketListForUser"), HttpGet]
|
||||
public async Task<List<cF4SDTicketSummary>> getTicketListForUser(
|
||||
Guid userId,
|
||||
int hours,
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
var decodedPairs = ParseQueues(queues);
|
||||
|
||||
// Nun weiterreichen an Service
|
||||
return await _f4stHelperService.getTicketListByUser(
|
||||
userId,
|
||||
hours,
|
||||
queueoption,
|
||||
decodedPairs
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
[Route("getTicketDetails"), HttpGet]
|
||||
public async Task<cF4SDTicket> getTicketDetails(Guid objectId)
|
||||
public async Task<F4SDHelperService.cF4SDTicket> getTicketDetails(Guid objectId)
|
||||
{
|
||||
var tickets = await _f4stHelperService.getTicketDetails(new List<Guid>() { objectId });
|
||||
if (tickets.Count > 0)
|
||||
@@ -127,73 +156,136 @@ namespace C4IT.F4SD
|
||||
return null;
|
||||
}
|
||||
|
||||
[Route("getTicketHistory"), HttpGet]
|
||||
public async Task<List<cTicketJournalItem>> getTicketHistory(Guid objectId)
|
||||
{
|
||||
return await _f4stHelperService.GetJournalEntries(objectId);
|
||||
}
|
||||
|
||||
[Route("getTicketOverviewCounts"), HttpGet]
|
||||
public async Task<F4SDHelperService.TicketOverviewCountsResult> getTicketOverviewCounts(
|
||||
string sid,
|
||||
string scope = "personal",
|
||||
string keys = "",
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
var parsedKeys = (keys ?? string.Empty)
|
||||
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(key => key.Trim())
|
||||
.Where(key => !string.IsNullOrWhiteSpace(key))
|
||||
.ToList();
|
||||
|
||||
var decodedQueues = ParseQueues(queues);
|
||||
return await _f4stHelperService.getTicketOverviewCounts(sid, scope, parsedKeys, queueoption, decodedQueues);
|
||||
}
|
||||
|
||||
[Route("getTicketOverviewCountsByRoles"), HttpPost]
|
||||
public async Task<F4SDHelperService.TicketOverviewCountsByRoleResult> getTicketOverviewCountsByRoles([FromBody] TicketOverviewCountsByRolesRequest request)
|
||||
{
|
||||
var parsedKeys = (request?.Keys ?? new List<string>())
|
||||
.Where(key => !string.IsNullOrWhiteSpace(key))
|
||||
.Select(key => key.Trim())
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var roleGuids = (request?.RoleGuids ?? new List<Guid>())
|
||||
.Where(roleId => roleId != Guid.Empty)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var decodedQueues = ParseQueues(request?.Queues ?? string.Empty);
|
||||
return await _f4stHelperService.getTicketOverviewCountsByRoles(
|
||||
request?.Sid,
|
||||
roleGuids,
|
||||
parsedKeys,
|
||||
request?.QueueOption ?? 0,
|
||||
decodedQueues
|
||||
);
|
||||
}
|
||||
|
||||
[Route("getTicketOverviewRelations"), HttpGet]
|
||||
public async Task<List<F4SDHelperService.TicketOverviewRelationDto>> getTicketOverviewRelations(
|
||||
string sid,
|
||||
string scope = "personal",
|
||||
string key = "",
|
||||
int count = 0,
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
var decodedQueues = ParseQueues(queues);
|
||||
return await _f4stHelperService.getTicketOverviewRelations(sid, scope, key, count, queueoption, decodedQueues);
|
||||
}
|
||||
/*
|
||||
[Route("updateActivitySolution/{objectId}"), HttpPost]
|
||||
public async Task<HttpResponseMessage> updateActivitySolution(Guid objectId, [FromBody] string SolutionHtml)
|
||||
{
|
||||
return new HttpResponseMessage
|
||||
[Route("getTicketHistory"), HttpGet]
|
||||
public async Task<List<F4SDHelperService.cF4SDTicket.cTicketJournalItem>> getTicketHistory(Guid objectId)
|
||||
{
|
||||
return await _f4stHelperService.GetJournalEntries(objectId);
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
[Route("getTicketOverviewCounts"), HttpGet]
|
||||
public async Task<F4SDHelperService.TicketOverviewCountsResult> getTicketOverviewCounts(
|
||||
string sid,
|
||||
string scope = "personal",
|
||||
string keys = "",
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
var parsedKeys = (keys ?? string.Empty)
|
||||
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(key => key.Trim())
|
||||
.Where(key => !string.IsNullOrWhiteSpace(key))
|
||||
.ToList();
|
||||
|
||||
var decodedQueues = ParseQueues(queues);
|
||||
return await _f4stHelperService.getTicketOverviewCounts(sid, scope, parsedKeys, queueoption, decodedQueues);
|
||||
}
|
||||
|
||||
|
||||
[Route("getTicketOverviewCountsForUser"), HttpGet]
|
||||
public async Task<F4SDHelperService.TicketOverviewCountsResult> getTicketOverviewCountsForUser(
|
||||
Guid userId,
|
||||
string scope = "personal",
|
||||
string keys = "",
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
var parsedKeys = (keys ?? string.Empty)
|
||||
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(key => key.Trim())
|
||||
.Where(key => !string.IsNullOrWhiteSpace(key))
|
||||
.ToList();
|
||||
|
||||
var decodedQueues = ParseQueues(queues);
|
||||
return await _f4stHelperService.getTicketOverviewCounts(userId, scope, parsedKeys, queueoption, decodedQueues);
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
[Route("getTicketOverviewCountsByRoles"), HttpPost]
|
||||
public async Task<F4SDHelperService.TicketOverviewCountsByRoleResult> getTicketOverviewCountsByRoles([FromBody] TicketOverviewCountsByRolesRequest request)
|
||||
{
|
||||
var parsedKeys = (request?.Keys ?? new List<string>())
|
||||
.Where(key => !string.IsNullOrWhiteSpace(key))
|
||||
.Select(key => key.Trim())
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var roleGuids = (request?.RoleGuids ?? new List<Guid>())
|
||||
.Where(roleId => roleId != Guid.Empty)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var decodedQueues = ParseQueues(request?.Queues ?? string.Empty);
|
||||
return await _f4stHelperService.getTicketOverviewCountsByRoles(
|
||||
request?.Sid,
|
||||
roleGuids,
|
||||
parsedKeys,
|
||||
request?.QueueOption ?? 0,
|
||||
decodedQueues
|
||||
);
|
||||
}
|
||||
|
||||
[Route("getTicketOverviewCountsByRolesForUser"), HttpPost]
|
||||
public async Task<F4SDHelperService.TicketOverviewCountsByRoleResult> getTicketOverviewCountsByRolesForUser([FromBody] TicketOverviewCountsByRolesForUserRequest request)
|
||||
{
|
||||
var parsedKeys = (request?.Keys ?? new List<string>())
|
||||
.Where(key => !string.IsNullOrWhiteSpace(key))
|
||||
.Select(key => key.Trim())
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var roleGuids = (request?.RoleGuids ?? new List<Guid>())
|
||||
.Where(roleId => roleId != Guid.Empty)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var decodedQueues = ParseQueues(request?.Queues ?? string.Empty);
|
||||
return await _f4stHelperService.getTicketOverviewCountsByRoles(
|
||||
request.userId,
|
||||
roleGuids,
|
||||
parsedKeys,
|
||||
request?.QueueOption ?? 0,
|
||||
decodedQueues
|
||||
);
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
[Route("getTicketOverviewRelations"), HttpGet]
|
||||
public async Task<List<F4SDHelperService.TicketOverviewRelationDto>> getTicketOverviewRelations(
|
||||
string sid,
|
||||
string scope = "personal",
|
||||
string key = "",
|
||||
int count = 0,
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
var decodedQueues = ParseQueues(queues);
|
||||
return await _f4stHelperService.getTicketOverviewRelations(sid, scope, key, count, queueoption, decodedQueues);
|
||||
}
|
||||
|
||||
[Route("getTicketOverviewRelationsForUser"), HttpGet]
|
||||
public async Task<List<F4SDHelperService.TicketOverviewRelationDto>> getTicketOverviewRelations(
|
||||
Guid userId,
|
||||
string scope = "personal",
|
||||
string key = "",
|
||||
int count = 0,
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
var decodedQueues = ParseQueues(queues);
|
||||
return await _f4stHelperService.getTicketOverviewRelations(userId, scope, key, count, queueoption, decodedQueues);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
[Route("updateActivitySolution/{objectId}"), HttpPost]
|
||||
public async Task<HttpResponseMessage> updateActivitySolution(Guid objectId, [FromBody] string SolutionHtml)
|
||||
{
|
||||
return new HttpResponseMessage
|
||||
{
|
||||
StatusCode = await _f4stHelperService.updateActivitySolution(objectId, SolutionHtml) ? HttpStatusCode.NoContent : HttpStatusCode.BadRequest,
|
||||
};
|
||||
@@ -201,10 +293,14 @@ namespace C4IT.F4SD
|
||||
*/
|
||||
[Route("getPickup/{name}"), HttpGet]
|
||||
//[CacheOutput(UseETAG = true)]
|
||||
public async Task<HttpResponseMessage> getPickup(string name, [FromUri] EntityEnumerationVisibilityMode mode = EntityEnumerationVisibilityMode.None, [FromUri] Int32 group = -1)
|
||||
public async Task<EntityEnumeration> getPickup(string name, [FromUri] EntityEnumerationVisibilityMode mode = EntityEnumerationVisibilityMode.None, [FromUri] Int32 group = -1)
|
||||
{
|
||||
await Task.Delay(0);
|
||||
EntityEnumeration enumerationTemp = _entityDataService.GetEnumeration(name, mode);
|
||||
var pickupName = ResolvePickupName(name);
|
||||
if (string.IsNullOrWhiteSpace(pickupName))
|
||||
throw new ArgumentException("Pickup name is required.", nameof(name));
|
||||
|
||||
EntityEnumeration enumerationTemp = GetEnumeration(pickupName, mode);
|
||||
var vals = enumerationTemp.Values;
|
||||
|
||||
if (group > -1)
|
||||
@@ -224,19 +320,22 @@ namespace C4IT.F4SD
|
||||
Values = vals.ToArray()
|
||||
};
|
||||
//CacheOutputAttribute.RegisterResponseEtag($"enum_{enumeration.Name}_{(int)mode}", $"{enumeration.Name}_{(int)mode}", cultureInvariant: false, userInvariant: true, val);
|
||||
return Request.CreateResponse(HttpStatusCode.OK, enumeration);
|
||||
return enumeration;
|
||||
}
|
||||
|
||||
[Route("getMyRoleMemberships", Order = 2), HttpGet]
|
||||
public async Task<HttpResponseMessage> getMyRoleMemberships()
|
||||
[Route("getMyRoleMemberships"), HttpGet]
|
||||
public async Task<object> getMyRoleMemberships()
|
||||
{
|
||||
var User = _userProfile.GetInteractiveUserInfo();
|
||||
var filter = AsqlHelper.BuildInCondition("ID", new Guid[] { User.Id });
|
||||
return Request.CreateResponse(HttpStatusCode.OK, await _f4stHelperService.UserPermissionsInfo(filter));
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == Guid.Empty)
|
||||
throw new UnauthorizedAccessException("Cannot determine the interactive Matrix42 user.");
|
||||
|
||||
var filter = AsqlHelper.BuildInCondition("ID", new Guid[] { userId });
|
||||
return await _f4stHelperService.UserPermissionsInfo(filter);
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("getRoleMemberships", Order = 1)]
|
||||
public async Task<HttpResponseMessage> getRoleMemberships([FromUri] GetRoleMembershipsRequest req)
|
||||
|
||||
[Route("getRoleMemberships"), HttpGet]
|
||||
public async Task<object> getRoleMemberships([FromUri] GetRoleMembershipsRequest req)
|
||||
{
|
||||
var filter = "";
|
||||
|
||||
@@ -255,7 +354,7 @@ namespace C4IT.F4SD
|
||||
|
||||
if (!string.IsNullOrEmpty(filter))
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.OK, await _f4stHelperService.UserPermissionsInfo(filter));
|
||||
return await _f4stHelperService.UserPermissionsInfo(filter);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -263,48 +362,190 @@ namespace C4IT.F4SD
|
||||
}
|
||||
}
|
||||
|
||||
public class GetRoleMembershipsRequest
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
public string Sid { get; set; }
|
||||
public string Upn { get; set; }
|
||||
public GetRoleMembershipsRequest() { }
|
||||
}
|
||||
|
||||
public class TicketOverviewCountsByRolesRequest
|
||||
{
|
||||
public string Sid { get; set; }
|
||||
public List<Guid> RoleGuids { get; set; } = new List<Guid>();
|
||||
public List<string> Keys { get; set; } = new List<string>();
|
||||
public int? QueueOption { get; set; }
|
||||
public string Queues { get; set; }
|
||||
}
|
||||
|
||||
private static List<cApiM42TicketQueueInfo> ParseQueues(string queues)
|
||||
{
|
||||
return (queues ?? string.Empty)
|
||||
.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(part =>
|
||||
{
|
||||
var segments = part.Split(':');
|
||||
if (segments.Length != 2)
|
||||
return null;
|
||||
|
||||
var name = HttpUtility.UrlDecode(segments[0]);
|
||||
var idStr = HttpUtility.UrlDecode(segments[1]);
|
||||
|
||||
return Guid.TryParse(idStr, out var guid)
|
||||
? new cApiM42TicketQueueInfo { QueueName = name, QueueID = guid }
|
||||
: null;
|
||||
})
|
||||
.Where(q => q != null)
|
||||
.ToList();
|
||||
}
|
||||
[Route("getRoleMemberships/{userId}"), HttpGet]
|
||||
public async Task<object> getRoleMembershipForUser(Guid userId)
|
||||
{
|
||||
var filter = AsqlHelper.BuildInCondition("ID", new Guid[] { userId });
|
||||
return await _f4stHelperService.UserPermissionsInfo(filter);
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public class GetRoleMembershipsRequest
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
public string Sid { get; set; }
|
||||
public string Upn { get; set; }
|
||||
public GetRoleMembershipsRequest() { }
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public class TicketOverviewCountsByRolesRequest
|
||||
{
|
||||
public string Sid { get; set; }
|
||||
public List<Guid> RoleGuids { get; set; } = new List<Guid>();
|
||||
public List<string> Keys { get; set; } = new List<string>();
|
||||
public int? QueueOption { get; set; }
|
||||
public string Queues { get; set; }
|
||||
}
|
||||
|
||||
public class TicketOverviewCountsByRolesForUserRequest
|
||||
{
|
||||
public Guid userId { get; set; }
|
||||
public List<Guid> RoleGuids { get; set; } = new List<Guid>();
|
||||
public List<string> Keys { get; set; } = new List<string>();
|
||||
public int? QueueOption { get; set; }
|
||||
public string Queues { get; set; }
|
||||
}
|
||||
|
||||
private EntityEnumeration GetEnumeration(string name, EntityEnumerationVisibilityMode mode)
|
||||
{
|
||||
name = name?.Trim();
|
||||
var dataTable = GetEnumerationProvider().GetEnumeration(name, GetVisibilityFilter(mode));
|
||||
if (dataTable == null)
|
||||
throw new InvalidOperationException($"Enumeration '{name}' was not found.");
|
||||
|
||||
var valueColumn = FindColumn(dataTable, "Value") ?? FindNumericColumn(dataTable);
|
||||
if (string.IsNullOrEmpty(valueColumn))
|
||||
throw new InvalidOperationException($"Enumeration '{name}' does not contain a numeric value column.");
|
||||
|
||||
var displayColumn = FindColumn(dataTable, "DisplayString")
|
||||
?? FindColumn(dataTable, "DisplayExpression")
|
||||
?? FindColumn(dataTable, "Name")
|
||||
?? valueColumn;
|
||||
var hiddenColumn = FindColumn(dataTable, "Hidden");
|
||||
|
||||
var values = dataTable.Rows.Cast<DataRow>()
|
||||
.Select(row => new EntityEnumerationValue
|
||||
{
|
||||
Value = ConvertHelper.ParseInt(row[valueColumn], 0),
|
||||
DisplayString = Convert.ToString(row[displayColumn]),
|
||||
Hidden = hiddenColumn != null && ConvertHelper.ParseInt(row[hiddenColumn], 0) == 1,
|
||||
Extentions = dataTable.Columns.Cast<DataColumn>()
|
||||
.ToDictionary(column => column.ColumnName, column => row[column])
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
return new EntityEnumeration
|
||||
{
|
||||
Name = name,
|
||||
Values = values
|
||||
};
|
||||
}
|
||||
|
||||
private string ResolvePickupName(string routeName)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(routeName))
|
||||
return routeName.Trim();
|
||||
|
||||
var pathSegment = Request?.RequestUri?.Segments?
|
||||
.LastOrDefault(segment => !string.IsNullOrWhiteSpace(segment) && segment != "/");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(pathSegment))
|
||||
return null;
|
||||
|
||||
return Uri.UnescapeDataString(pathSegment.Trim('/'));
|
||||
}
|
||||
|
||||
private static bool? GetVisibilityFilter(EntityEnumerationVisibilityMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case EntityEnumerationVisibilityMode.Visible:
|
||||
return true;
|
||||
case EntityEnumerationVisibilityMode.Hidden:
|
||||
return false;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static string FindColumn(DataTable dataTable, string columnName)
|
||||
{
|
||||
return dataTable.Columns.Cast<DataColumn>()
|
||||
.FirstOrDefault(column => string.Equals(column.ColumnName, columnName, StringComparison.OrdinalIgnoreCase))
|
||||
?.ColumnName;
|
||||
}
|
||||
|
||||
private static string FindNumericColumn(DataTable dataTable)
|
||||
{
|
||||
var excludedNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"Hidden",
|
||||
"Position",
|
||||
"StateGroup"
|
||||
};
|
||||
|
||||
return dataTable.Columns.Cast<DataColumn>()
|
||||
.FirstOrDefault(column => !excludedNames.Contains(column.ColumnName) && IsNumericType(column.DataType))
|
||||
?.ColumnName;
|
||||
}
|
||||
|
||||
private static bool IsNumericType(Type type)
|
||||
{
|
||||
return type == typeof(byte)
|
||||
|| type == typeof(short)
|
||||
|| type == typeof(int)
|
||||
|| type == typeof(long)
|
||||
|| type == typeof(sbyte)
|
||||
|| type == typeof(ushort)
|
||||
|| type == typeof(uint)
|
||||
|| type == typeof(ulong);
|
||||
}
|
||||
|
||||
private static Guid GetCurrentUserId()
|
||||
{
|
||||
var principal = Thread.CurrentPrincipal as IM42Principal;
|
||||
return principal?.InteractivePrincipal?.M42Identity?.UserFragmentID
|
||||
?? principal?.M42Identity?.UserFragmentID
|
||||
?? Guid.Empty;
|
||||
}
|
||||
|
||||
private static List<cApiM42TicketQueueInfo> ParseQueues(string queues)
|
||||
{
|
||||
return (queues ?? string.Empty)
|
||||
.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(part =>
|
||||
{
|
||||
var decodedPart = WebUtility.UrlDecode(part)?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(decodedPart))
|
||||
return null;
|
||||
|
||||
var name = decodedPart;
|
||||
string idStr = null;
|
||||
|
||||
var separatorIndex = decodedPart.IndexOf(':');
|
||||
if (separatorIndex >= 0)
|
||||
{
|
||||
name = decodedPart.Substring(0, separatorIndex).Trim();
|
||||
idStr = decodedPart.Substring(separatorIndex + 1).Trim();
|
||||
}
|
||||
|
||||
var queue = new cApiM42TicketQueueInfo();
|
||||
if (!string.IsNullOrWhiteSpace(name))
|
||||
queue.QueueName = name;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(idStr))
|
||||
{
|
||||
if (!Guid.TryParse(idStr, out var guid))
|
||||
return null;
|
||||
|
||||
queue.QueueID = guid;
|
||||
queue.QueueName = null;
|
||||
}
|
||||
|
||||
if (queue.QueueID == Guid.Empty && string.IsNullOrWhiteSpace(queue.QueueName))
|
||||
return null;
|
||||
|
||||
return queue;
|
||||
})
|
||||
.Where(q => q != null)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Route("isAlive"), HttpGet]
|
||||
public HttpResponseMessage isAlive()
|
||||
public IHttpActionResult isAlive()
|
||||
{
|
||||
return new HttpResponseMessage(HttpStatusCode.NoContent);
|
||||
return new StatusCodeResult(HttpStatusCode.NoContent);
|
||||
}
|
||||
|
||||
[Route("loglevel"), HttpGet]
|
||||
@@ -343,6 +584,7 @@ namespace C4IT.F4SD
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[RoutePrefix("api/C4ITF4SDWebApi/Logs")]
|
||||
public partial class F4SDM42LogsWebApiController : ApiController
|
||||
{
|
||||
@@ -350,10 +592,9 @@ namespace C4IT.F4SD
|
||||
|
||||
public static bool IsInitialized { get; private set; } = false;
|
||||
|
||||
private static object initLock = new object();
|
||||
protected override void Initialize(HttpControllerContext controllerContext)
|
||||
private static readonly object initLock = new object();
|
||||
private static void EnsureInitialized()
|
||||
{
|
||||
base.Initialize(controllerContext);
|
||||
try
|
||||
{
|
||||
lock (initLock)
|
||||
@@ -372,25 +613,18 @@ namespace C4IT.F4SD
|
||||
catch { };
|
||||
}
|
||||
|
||||
|
||||
|
||||
public F4SDM42LogsWebApiController()
|
||||
{
|
||||
_f4stHelperService = new F4SDHelperService();
|
||||
EnsureInitialized();
|
||||
}
|
||||
|
||||
[Route(""), HttpGet]
|
||||
[EnableQuery]
|
||||
public IEnumerable<cM42LogEntry> getLog2(ODataQueryOptions<cM42LogEntry> queryOptions)
|
||||
{
|
||||
try
|
||||
{
|
||||
IQueryable<cM42LogEntry> queryable = _f4stHelperService.privGetLog2().AsQueryable();
|
||||
if (queryOptions.Filter != null)
|
||||
{
|
||||
queryable = queryOptions.Filter.ApplyTo(queryable, new ODataQuerySettings()).Cast<cM42LogEntry>();
|
||||
}
|
||||
return queryable;
|
||||
return ApplyLogFilter(_f4stHelperService.privGetLog2(), queryOptions);
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
@@ -403,12 +637,7 @@ namespace C4IT.F4SD
|
||||
[HttpGet]
|
||||
public int Log2Count(ODataQueryOptions<cM42LogEntry> queryOptions)
|
||||
{
|
||||
IQueryable<cM42LogEntry> queryable = _f4stHelperService.privGetLog2().AsQueryable();
|
||||
if (queryOptions.Filter != null)
|
||||
{
|
||||
queryable = queryOptions.Filter.ApplyTo(queryable, new ODataQuerySettings()).Cast<cM42LogEntry>();
|
||||
}
|
||||
return queryable.Count();
|
||||
return ApplyLogFilter(_f4stHelperService.privGetLog2(), queryOptions).Count();
|
||||
}
|
||||
|
||||
[Route("{id}")]
|
||||
@@ -417,6 +646,28 @@ namespace C4IT.F4SD
|
||||
{
|
||||
return _f4stHelperService.privGetLog2(id);
|
||||
}
|
||||
|
||||
private static IEnumerable<cM42LogEntry> ApplyLogFilter(IEnumerable<cM42LogEntry> entries, ODataQueryOptions<cM42LogEntry> queryOptions)
|
||||
{
|
||||
var result = entries ?? Enumerable.Empty<cM42LogEntry>();
|
||||
var filter = queryOptions?.Filter;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(filter))
|
||||
{
|
||||
result = result.Where(entry =>
|
||||
(entry.Message?.IndexOf(filter, StringComparison.OrdinalIgnoreCase) ?? -1) >= 0 ||
|
||||
(entry.logLvl?.IndexOf(filter, StringComparison.OrdinalIgnoreCase) ?? -1) >= 0 ||
|
||||
(entry.Theme?.IndexOf(filter, StringComparison.OrdinalIgnoreCase) ?? -1) >= 0);
|
||||
}
|
||||
|
||||
if (queryOptions?.Skip != null)
|
||||
result = result.Skip(queryOptions.Skip.Value);
|
||||
|
||||
if (queryOptions?.Top != null)
|
||||
result = result.Take(queryOptions.Top.Value);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class cGetPropertyBody
|
||||
|
||||
Reference in New Issue
Block a user