fix: lazy resolve Matrix42 services
This commit is contained in:
@@ -2,12 +2,7 @@
|
|||||||
<host xmlns="urn:m42/host.config">
|
<host xmlns="urn:m42/host.config">
|
||||||
<modules>
|
<modules>
|
||||||
<module assembly="Matrix42.DataLayer.Persistence" />
|
<module assembly="Matrix42.DataLayer.Persistence" />
|
||||||
<module assembly="Matrix42.Pandora.Persistence" />
|
|
||||||
<module assembly="Matrix42.Pandora.ServiceStore" />
|
|
||||||
<module assembly="Matrix42.Pandora.BizLogic" />
|
|
||||||
<module assembly="Matrix42.Pandora.Services" />
|
|
||||||
<module assembly="Matrix42.ServiceManager.BizLogic" />
|
<module assembly="Matrix42.ServiceManager.BizLogic" />
|
||||||
<module assembly="C4ITF4SDM42WebApi" />
|
|
||||||
</modules>
|
</modules>
|
||||||
<sections></sections>
|
<sections></sections>
|
||||||
</host>
|
</host>
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Web.Http;
|
|
||||||
using System.Web.Http.Description;
|
|
||||||
|
|
||||||
using Matrix42.Hosting.Contracts;
|
|
||||||
|
|
||||||
namespace C4IT.F4SD.Properties
|
|
||||||
{
|
|
||||||
public sealed class DependencyRegistrator : DependencyRegistratorBase, IDependencyRegistrator
|
|
||||||
{
|
|
||||||
public void Register(IDependencyContainer container, IDependencyResolver resolver)
|
|
||||||
{
|
|
||||||
container.RegisterSingletonType<IApiExplorer>((Type _) => new ApiExplorer(new HttpConfiguration()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||||
<M42ExtensionId>6673a25d-33d6-4072-91d9-abed4be1a966</M42ExtensionId>
|
<M42ExtensionId>6673a25d-33d6-4072-91d9-abed4be1a966</M42ExtensionId>
|
||||||
<M42AssemblyPattern>C4ITF4SD*.*</M42AssemblyPattern>
|
<M42AssemblyPattern>C4ITF4SD*.*</M42AssemblyPattern>
|
||||||
<M42PackageVersion>1.4.0.8</M42PackageVersion>
|
<M42PackageVersion>1.4.0.9</M42PackageVersion>
|
||||||
<M42BuildPackage>true</M42BuildPackage>
|
<M42BuildPackage>true</M42BuildPackage>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@@ -46,6 +46,10 @@
|
|||||||
<HintPath>M42Libraries\26.1\Matrix42.Pandora.Contracts.dll</HintPath>
|
<HintPath>M42Libraries\26.1\Matrix42.Pandora.Contracts.dll</HintPath>
|
||||||
<Private>false</Private>
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Matrix42.Persistence.Contracts">
|
||||||
|
<HintPath>M42Libraries\26.1\Matrix42.Persistence.Contracts.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Matrix42.Services.Description.Contracts">
|
<Reference Include="Matrix42.Services.Description.Contracts">
|
||||||
<HintPath>M42Libraries\26.1\Matrix42.Services.Description.Contracts.dll</HintPath>
|
<HintPath>M42Libraries\26.1\Matrix42.Services.Description.Contracts.dll</HintPath>
|
||||||
<Private>false</Private>
|
<Private>false</Private>
|
||||||
@@ -62,10 +66,6 @@
|
|||||||
<HintPath>M42Libraries\26.1\System.Net.Http.Formatting.dll</HintPath>
|
<HintPath>M42Libraries\26.1\System.Net.Http.Formatting.dll</HintPath>
|
||||||
<Private>false</Private>
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Web.Http">
|
|
||||||
<HintPath>M42Libraries\26.1\System.Web.Http.dll</HintPath>
|
|
||||||
<Private>false</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="update4u.SPS.DataLayer">
|
<Reference Include="update4u.SPS.DataLayer">
|
||||||
<HintPath>M42Libraries\26.1\update4u.SPS.DataLayer.dll</HintPath>
|
<HintPath>M42Libraries\26.1\update4u.SPS.DataLayer.dll</HintPath>
|
||||||
<Private>false</Private>
|
<Private>false</Private>
|
||||||
@@ -82,7 +82,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="cM42LogEntry.cs" />
|
<Compile Include="cM42LogEntry.cs" />
|
||||||
<Compile Include="DependencyRegistrator.cs" />
|
|
||||||
<Compile Include="F4SDHelperService.cs" />
|
<Compile Include="F4SDHelperService.cs" />
|
||||||
<Compile Include="F4SDM42WebApiController.cs" />
|
<Compile Include="F4SDM42WebApiController.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
@@ -1931,7 +1931,7 @@ namespace C4IT.F4SD
|
|||||||
{
|
{
|
||||||
await Task.Delay(0);
|
await Task.Delay(0);
|
||||||
List<cF4SDTicket.cTicketJournalItem> journalEntries = new List<cF4SDTicket.cTicketJournalItem>();
|
List<cF4SDTicket.cTicketJournalItem> journalEntries = new List<cF4SDTicket.cTicketJournalItem>();
|
||||||
var entries = F4SDM42WebApiController.defaultInstance._journalService.GetJournalList(activityEOID, false, 0, 50, "<a href=\"#\" class=\"mx-object-journal--link {0} {1}\">{2}</a>", 120);
|
var entries = F4SDM42WebApiController.defaultInstance.GetJournalService().GetJournalList(activityEOID, false, 0, 50, "<a href=\"#\" class=\"mx-object-journal--link {0} {1}\">{2}</a>", 120);
|
||||||
LogEntry($"{entries.Length} Journal entries found for ObjectID={activityEOID}", LogLevels.Debug);
|
LogEntry($"{entries.Length} Journal entries found for ObjectID={activityEOID}", LogLevels.Debug);
|
||||||
for (int i = 0; i < entries.Length; i++)
|
for (int i = 0; i < entries.Length; i++)
|
||||||
{
|
{
|
||||||
@@ -2618,18 +2618,6 @@ namespace C4IT.F4SD
|
|||||||
retVal.User = m42Users[0];
|
retVal.User = m42Users[0];
|
||||||
|
|
||||||
|
|
||||||
var user = F4SDM42WebApiController.defaultInstance._userProfile.GetInteractiveUserInfo(retVal.User.Id);
|
|
||||||
if (user != null)
|
|
||||||
{
|
|
||||||
retVal.User.Id = user.Id;
|
|
||||||
retVal.User.Currency = user.Currency;
|
|
||||||
retVal.User.Email = user.Email;
|
|
||||||
retVal.User.FirstName = user.FirstName;
|
|
||||||
retVal.User.LastName = user.LastName;
|
|
||||||
retVal.User.Phone = user.Phone;
|
|
||||||
retVal.User.Photo = user.Photo;
|
|
||||||
}
|
|
||||||
|
|
||||||
retVal.Roles = await getRoleMembershipById(retVal.User.Id);
|
retVal.Roles = await getRoleMembershipById(retVal.User.Id);
|
||||||
retVal.User.IsAdmin = retVal.Roles?.Where(i => i.Id == Administrators).FirstOrDefault() != null;
|
retVal.User.IsAdmin = retVal.Roles?.Where(i => i.Id == Administrators).FirstOrDefault() != null;
|
||||||
return retVal;
|
return retVal;
|
||||||
|
|||||||
@@ -5,11 +5,15 @@ using System.Linq;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Matrix42.Common;
|
using Matrix42.Common;
|
||||||
|
using Matrix42.Contracts.Common.Security;
|
||||||
using Matrix42.Contracts.ServiceManagement.ServiceContracts;
|
using Matrix42.Contracts.ServiceManagement.ServiceContracts;
|
||||||
|
using Matrix42.Hosting.Contracts;
|
||||||
using Matrix42.Pandora.Contracts;
|
using Matrix42.Pandora.Contracts;
|
||||||
|
using Matrix42.Persistence.Contracts;
|
||||||
using Matrix42.Services.Description.Contracts;
|
using Matrix42.Services.Description.Contracts;
|
||||||
using Matrix42.WebApi.Contracts;
|
using Matrix42.WebApi.Contracts;
|
||||||
using Matrix42.WebApi.Contracts.OData;
|
using Matrix42.WebApi.Contracts.OData;
|
||||||
@@ -33,24 +37,20 @@ namespace C4IT.F4SD
|
|||||||
internal readonly GlobalConfigurationProvider _globalConfigurationProvider;
|
internal readonly GlobalConfigurationProvider _globalConfigurationProvider;
|
||||||
//public readonly IObjectService _objectService;
|
//public readonly IObjectService _objectService;
|
||||||
//public readonly IFragmentService _fragmentService;
|
//public readonly IFragmentService _fragmentService;
|
||||||
public readonly IJournalService _journalService;
|
private readonly IDependencyResolver _resolver;
|
||||||
internal readonly IEntityDataService _entityDataService;
|
|
||||||
internal readonly IPandoraUserProfile _userProfile;
|
|
||||||
|
|
||||||
|
|
||||||
private readonly F4SDHelperService _f4stHelperService;
|
private readonly F4SDHelperService _f4stHelperService;
|
||||||
public string BaseUrl => Request?.RequestUri == null ? string.Empty : $"{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 string EndpointBaseUrl => $"{BaseUrl}/m42Services/api/c4itf4sdwebapi";
|
||||||
|
|
||||||
public F4SDM42WebApiController(IEntityDataService entityDataService, IJournalService journalService, IPandoraUserProfile userProfile)
|
public F4SDM42WebApiController(IDependencyResolver resolver)
|
||||||
{
|
{
|
||||||
|
_resolver = resolver ?? throw new ArgumentNullException(nameof(resolver));
|
||||||
defaultInstance = this;
|
defaultInstance = this;
|
||||||
_globalConfigurationProvider = GlobalConfigurationProvider.Instance;
|
_globalConfigurationProvider = GlobalConfigurationProvider.Instance;
|
||||||
_f4stHelperService = new F4SDHelperService();
|
_f4stHelperService = new F4SDHelperService();
|
||||||
EnsureInitialized();
|
EnsureInitialized();
|
||||||
_entityDataService = entityDataService ?? throw new ArgumentNullException(nameof(entityDataService));
|
|
||||||
_journalService = journalService ?? throw new ArgumentNullException(nameof(journalService));
|
|
||||||
_userProfile = userProfile ?? throw new ArgumentNullException(nameof(userProfile));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly object initLock = new object();
|
private static readonly object initLock = new object();
|
||||||
@@ -74,6 +74,25 @@ namespace C4IT.F4SD
|
|||||||
catch { };
|
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]
|
[Route("getDirectLinkCreateTicket"), HttpGet]
|
||||||
public async Task<F4SDHelperService.DirectLink> getDirectLinkCreateTicket(string sid = "", string assetname = "")
|
public async Task<F4SDHelperService.DirectLink> getDirectLinkCreateTicket(string sid = "", string assetname = "")
|
||||||
{
|
{
|
||||||
@@ -277,7 +296,7 @@ namespace C4IT.F4SD
|
|||||||
public async Task<HttpResponseMessage> getPickup(string name, [FromUri] EntityEnumerationVisibilityMode mode = EntityEnumerationVisibilityMode.None, [FromUri] Int32 group = -1)
|
public async Task<HttpResponseMessage> getPickup(string name, [FromUri] EntityEnumerationVisibilityMode mode = EntityEnumerationVisibilityMode.None, [FromUri] Int32 group = -1)
|
||||||
{
|
{
|
||||||
await Task.Delay(0);
|
await Task.Delay(0);
|
||||||
EntityEnumeration enumerationTemp = _entityDataService.GetEnumeration(name, mode);
|
EntityEnumeration enumerationTemp = GetEnumeration(name, mode);
|
||||||
var vals = enumerationTemp.Values;
|
var vals = enumerationTemp.Values;
|
||||||
|
|
||||||
if (group > -1)
|
if (group > -1)
|
||||||
@@ -303,8 +322,11 @@ namespace C4IT.F4SD
|
|||||||
[Route("getMyRoleMemberships"), HttpGet]
|
[Route("getMyRoleMemberships"), HttpGet]
|
||||||
public async Task<HttpResponseMessage> getMyRoleMemberships()
|
public async Task<HttpResponseMessage> getMyRoleMemberships()
|
||||||
{
|
{
|
||||||
var User = _userProfile.GetInteractiveUserInfo();
|
var userId = GetCurrentUserId();
|
||||||
var filter = AsqlHelper.BuildInCondition("ID", new Guid[] { User.Id });
|
if (userId == Guid.Empty)
|
||||||
|
return HttpResponseExtensions.CreateResponse(Request, HttpStatusCode.Unauthorized, "Cannot determine the interactive Matrix42 user.");
|
||||||
|
|
||||||
|
var filter = AsqlHelper.BuildInCondition("ID", new Guid[] { userId });
|
||||||
return HttpResponseExtensions.CreateResponse(Request, HttpStatusCode.OK, await _f4stHelperService.UserPermissionsInfo(filter));
|
return HttpResponseExtensions.CreateResponse(Request, HttpStatusCode.OK, await _f4stHelperService.UserPermissionsInfo(filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,6 +393,94 @@ namespace C4IT.F4SD
|
|||||||
public string Queues { get; set; }
|
public string Queues { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private EntityEnumeration GetEnumeration(string name, EntityEnumerationVisibilityMode mode)
|
||||||
|
{
|
||||||
|
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 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)
|
private static List<cApiM42TicketQueueInfo> ParseQueues(string queues)
|
||||||
{
|
{
|
||||||
return (queues ?? string.Empty)
|
return (queues ?? string.Empty)
|
||||||
|
|||||||
Reference in New Issue
Block a user