refactor: simplify export metadata construction
This commit is contained in:
@@ -0,0 +1,371 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Exporting;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Models.Services.Exporting;
|
||||
using Disco.Models.Services.Jobs;
|
||||
using Disco.Services.Exporting;
|
||||
using Disco.Services.Jobs.JobQueues;
|
||||
using Disco.Services.Plugins.Features.DetailsProvider;
|
||||
using Disco.Services.Tasks;
|
||||
using Disco.Services.Users;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Disco.Services.Jobs
|
||||
{
|
||||
public class JobExport : IExport<JobExportOptions, JobExportRecord>
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public bool TimestampSuffix { get; set; }
|
||||
public JobExportOptions Options { get; set; }
|
||||
|
||||
public string SuggestedFilenamePrefix { get; } = "JobExport";
|
||||
public string ExcelWorksheetName { get; } = "JobExport";
|
||||
public string ExcelTableName { get; } = "Jobs";
|
||||
|
||||
[JsonConstructor]
|
||||
private JobExport()
|
||||
{
|
||||
}
|
||||
|
||||
public JobExport(string name, string description, bool timestampSuffix, JobExportOptions options)
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
Name = name;
|
||||
Description = description;
|
||||
TimestampSuffix = timestampSuffix;
|
||||
Options = options;
|
||||
}
|
||||
|
||||
public JobExport(JobExportOptions options)
|
||||
: this("Job Export", null, true, options)
|
||||
{
|
||||
}
|
||||
|
||||
public ExportResult Export(DiscoDataContext database, IScheduledTaskStatus status)
|
||||
=> Exporter.Export(this, database, status);
|
||||
|
||||
private IQueryable<Job> BuildFilteredRecords(DiscoDataContext database)
|
||||
{
|
||||
var o = Options;
|
||||
|
||||
var q = database.Jobs.Where(j => j.OpenedDate >= o.FilterStartDate);
|
||||
if (o.FilterEndDate.HasValue)
|
||||
q = q.Where(j => j.OpenedDate <= o.FilterEndDate);
|
||||
|
||||
if (o.FilterJobTypeId != null)
|
||||
q = q.Where(j => j.JobTypeId == o.FilterJobTypeId);
|
||||
|
||||
if (o.FilterJobSubTypeIds?.Any() ?? false)
|
||||
q = q.Where(j => j.JobSubTypes.Any(st => o.FilterJobSubTypeIds.Contains(st.Id)));
|
||||
|
||||
if (o.FilterJobQueueId.HasValue)
|
||||
q = q.Where(j => j.JobQueues.Any(jq => !jq.RemovedDate.HasValue && jq.JobQueueId == o.FilterJobQueueId));
|
||||
|
||||
if (o.FilterJobStatusId != null)
|
||||
{
|
||||
if (o.FilterJobStatusId != Job.JobStatusIds.Closed)
|
||||
q = q.Where(j => j.ClosedDate == null);
|
||||
|
||||
switch (o.FilterJobStatusId)
|
||||
{
|
||||
case Job.JobStatusIds.Open:
|
||||
// already filtered
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingAccountingPayment:
|
||||
q = q.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.AccountingChargeAddedDate != null && j.JobMetaNonWarranty.AccountingChargePaidDate == null);
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingAccountingCharge:
|
||||
q = q.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.AccountingChargeRequiredDate == null && (j.JobMetaNonWarranty.AccountingChargePaidDate != null || j.JobMetaNonWarranty.AccountingChargeAddedDate != null));
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingDeviceReturn:
|
||||
q = q.Where(j => j.DeviceReadyForReturn != null && j.DeviceReturnedDate == null);
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingInsuranceProcessing:
|
||||
q = q.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.IsInsuranceClaim && j.JobMetaInsurance.ClaimFormSentDate == null);
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingRepairs:
|
||||
q = q.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.RepairerLoggedDate != null && j.JobMetaNonWarranty.RepairerCompletedDate == null);
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingUserAction:
|
||||
q = q.Where(j => j.WaitingForUserAction != null);
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingWarrantyRepair:
|
||||
q = q.Where(j => j.JobTypeId == JobType.JobTypeIds.HWar && j.JobMetaWarranty.ExternalLoggedDate != null && j.JobMetaWarranty.ExternalCompletedDate == null);
|
||||
break;
|
||||
case Job.JobStatusIds.Closed:
|
||||
q = q.Where(j => j.ClosedDate != null);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException($"Unknown Job Status Id: {o.FilterJobStatusId}", nameof(o.FilterJobStatusId));
|
||||
}
|
||||
}
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
public List<JobExportRecord> BuildRecords(DiscoDataContext database, IScheduledTaskStatus status)
|
||||
{
|
||||
database.Configuration.LazyLoadingEnabled = false;
|
||||
database.Configuration.ProxyCreationEnabled = false;
|
||||
|
||||
var query = BuildFilteredRecords(database);
|
||||
|
||||
// Update Users
|
||||
if (Options.UserDisplayName ||
|
||||
Options.UserSurname ||
|
||||
Options.UserGivenName ||
|
||||
Options.UserPhoneNumber ||
|
||||
Options.UserEmailAddress)
|
||||
{
|
||||
status.UpdateStatus(5, "Refreshing user details from Active Directory");
|
||||
var userIds = query.Where(d => d.UserId != null).Select(d => d.UserId).Distinct().ToList();
|
||||
foreach (var userId in userIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
UserService.GetUser(userId, database, true);
|
||||
}
|
||||
catch (Exception) { } // Ignore Errors
|
||||
}
|
||||
}
|
||||
|
||||
// Update Last Network Logon Date
|
||||
if (Options.DeviceLastNetworkLogon)
|
||||
{
|
||||
status.UpdateStatus(15, "Refreshing device last network logon dates from Active Directory");
|
||||
try
|
||||
{
|
||||
Interop.ActiveDirectory.ADNetworkLogonDatesUpdateTask.UpdateLastNetworkLogonDates(database, ScheduledTaskMockStatus.Create("UpdateLastNetworkLogonDates"));
|
||||
database.SaveChanges();
|
||||
}
|
||||
catch (Exception) { } // Ignore Errors
|
||||
}
|
||||
|
||||
status.UpdateStatus(25, "Extracting records from the database");
|
||||
|
||||
var records = query.Select(j => new JobExportRecord()
|
||||
{
|
||||
Job = j,
|
||||
JobTypeDescription = j.JobType.Description,
|
||||
JobSubTypeDescriptions = j.JobSubTypes.Select(st => st.Description),
|
||||
|
||||
LogCount = j.JobLogs.Count(),
|
||||
FirstLog = j.JobLogs.OrderBy(l => l.Id).FirstOrDefault(),
|
||||
LastLog = j.JobLogs.OrderByDescending(l => l.Id).FirstOrDefault(),
|
||||
|
||||
AttachmentsCount = j.JobAttachments.Count(),
|
||||
|
||||
QueueCount = j.JobQueues.Count(),
|
||||
QueueActiveCount = j.JobQueues.Count(q => !q.RemovedDate.HasValue),
|
||||
QueueLatestActive = j.JobQueues.Where(q => !q.RemovedDate.HasValue).OrderByDescending(q => q.Id).FirstOrDefault(),
|
||||
|
||||
JobMetaWarranty = j.JobMetaWarranty,
|
||||
JobMetaNonWarranty = j.JobMetaNonWarranty,
|
||||
JobMetaInsurance = j.JobMetaInsurance,
|
||||
|
||||
User = j.User,
|
||||
|
||||
Device = j.Device,
|
||||
|
||||
DeviceModelId = j.Device.DeviceModelId,
|
||||
DeviceModelDescription = j.Device.DeviceModel.Description,
|
||||
DeviceModelManufacturer = j.Device.DeviceModel.Manufacturer,
|
||||
DeviceModelModel = j.Device.DeviceModel.Model,
|
||||
DeviceModelType = j.Device.DeviceModel.ModelType,
|
||||
|
||||
DeviceBatchId = j.Device.DeviceBatchId,
|
||||
DeviceBatchName = j.Device.DeviceBatch.Name,
|
||||
DeviceBatchPurchaseDate = j.Device.DeviceBatch.PurchaseDate,
|
||||
DeviceBatchSupplier = j.Device.DeviceBatch.Supplier,
|
||||
DeviceBatchUnitCost = j.Device.DeviceBatch.UnitCost,
|
||||
DeviceBatchWarrantyValidUntilDate = j.Device.DeviceBatch.WarrantyValidUntil,
|
||||
DeviceBatchInsuredDate = j.Device.DeviceBatch.InsuredDate,
|
||||
DeviceBatchInsuranceSupplier = j.Device.DeviceBatch.InsuranceSupplier,
|
||||
DeviceBatchInsuredUntilDate = j.Device.DeviceBatch.InsuredUntil,
|
||||
|
||||
DeviceProfileId = j.Device.DeviceProfileId,
|
||||
DeviceProfileName = j.Device.DeviceProfile.Name,
|
||||
DeviceProfileShortName = j.Device.DeviceProfile.ShortName,
|
||||
}).ToList();
|
||||
|
||||
records.ForEach(r =>
|
||||
{
|
||||
if (Options.JobStatus)
|
||||
{
|
||||
r.JobStatus = JobExtensions.CalculateStatusId(
|
||||
r.Job.ClosedDate,
|
||||
r.Job.JobTypeId,
|
||||
r.JobMetaWarranty?.ExternalLoggedDate,
|
||||
r.JobMetaWarranty?.ExternalCompletedDate,
|
||||
r.JobMetaNonWarranty?.RepairerLoggedDate,
|
||||
r.JobMetaNonWarranty?.RepairerCompletedDate,
|
||||
r.JobMetaNonWarranty?.AccountingChargeRequiredDate,
|
||||
r.JobMetaNonWarranty?.AccountingChargeAddedDate,
|
||||
r.JobMetaNonWarranty?.AccountingChargePaidDate,
|
||||
r.JobMetaNonWarranty?.IsInsuranceClaim,
|
||||
r.JobMetaInsurance?.ClaimFormSentDate,
|
||||
r.Job.WaitingForUserAction,
|
||||
r.Job.DeviceReadyForReturn,
|
||||
r.Job.DeviceReturnedDate);
|
||||
}
|
||||
|
||||
if (Options.UserDetailCustom && r.User != null)
|
||||
{
|
||||
var detailsService = new DetailsProviderService(database);
|
||||
r.UserCustomDetails = detailsService.GetDetails(r.User);
|
||||
}
|
||||
});
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
public ExportMetadata<JobExportRecord> BuildMetadata(DiscoDataContext database, List<JobExportRecord> records, IScheduledTaskStatus status)
|
||||
{
|
||||
var metadata = new ExportMetadata<JobExportRecord>();
|
||||
metadata.IgnoreShortNames.Add("Job");
|
||||
metadata.IgnoreShortNames.Add("Job Details");
|
||||
|
||||
// Job
|
||||
metadata.Add(Options, o => o.JobId, r => r.Job.Id);
|
||||
metadata.Add(Options, o => o.JobStatus, r => Job.JobStatusIds.StatusDescriptions.TryGetValue(r.JobStatus, out var jobStatus) ? jobStatus : "Unknown");
|
||||
metadata.Add(Options, o => o.JobType, r => r.JobTypeDescription);
|
||||
metadata.Add(Options, o => o.JobSubTypes, r => string.Join(", ", r.JobSubTypeDescriptions));
|
||||
metadata.Add(Options, o => o.JobOpenedDate, r => r.Job.OpenedDate);
|
||||
metadata.Add(Options, o => o.JobOpenedUser, r => r.Job.OpenedTechUserId);
|
||||
metadata.Add(Options, o => o.JobExpectedClosedDate, r => r.Job.ExpectedClosedDate);
|
||||
metadata.Add(Options, o => o.JobClosedDate, r => r.Job.ClosedDate);
|
||||
metadata.Add(Options, o => o.JobClosedUser, r => r.Job.ClosedTechUserId);
|
||||
|
||||
// Job Details
|
||||
metadata.Add(Options, o => o.JobDeviceHeldDate, r => r.Job.DeviceHeld);
|
||||
metadata.Add(Options, o => o.JobDeviceHeldUser, r => r.Job.DeviceHeldTechUserId);
|
||||
metadata.Add(Options, o => o.JobDeviceHeldLocation, r => r.Job.DeviceHeldLocation);
|
||||
metadata.Add(Options, o => o.JobDeviceReadyForReturnDate, r => r.Job.DeviceReadyForReturn);
|
||||
metadata.Add(Options, o => o.JobDeviceReadyForReturnUser, r => r.Job.DeviceReadyForReturnTechUserId);
|
||||
metadata.Add(Options, o => o.JobDeviceReturnedDate, r => r.Job.DeviceReturnedDate);
|
||||
metadata.Add(Options, o => o.JobDeviceReturnedUser, r => r.Job.DeviceReturnedTechUserId);
|
||||
metadata.Add(Options, o => o.JobWaitingForUserActionDate, r => r.Job.WaitingForUserAction);
|
||||
|
||||
// Job Logs
|
||||
metadata.Add(Options, o => o.LogCount, r => r.LogCount);
|
||||
metadata.Add(Options, o => o.LogFirstDate, r => r.FirstLog?.Timestamp);
|
||||
metadata.Add(Options, o => o.LogFirstUser, r => r.FirstLog?.TechUserId);
|
||||
metadata.Add(Options, o => o.LogFirstContent, r => r.FirstLog?.Comments);
|
||||
metadata.Add(Options, o => o.LogLastDate, r => r.LastLog?.Timestamp);
|
||||
metadata.Add(Options, o => o.LogLastUser, r => r.LastLog?.TechUserId);
|
||||
metadata.Add(Options, o => o.LogLastContent, r => r.LastLog?.Comments);
|
||||
|
||||
// Attachments
|
||||
metadata.Add(Options, o => o.AttachmentsCount, r => r.AttachmentsCount);
|
||||
|
||||
// Job Queues
|
||||
metadata.Add(Options, o => o.JobQueueCount, r => r.QueueCount);
|
||||
metadata.Add(Options, o => o.JobQueueActiveCount, r => r.QueueActiveCount);
|
||||
metadata.Add(Options, o => o.JobQueueActiveLatest, r => r.QueueLatestActive?.JobQueueId == null ? null : JobQueueService.GetQueue(r.QueueLatestActive.JobQueueId).JobQueue.Name);
|
||||
metadata.Add(Options, o => o.JobQueueActiveLatestAddedDate, r => r.QueueLatestActive?.AddedDate);
|
||||
metadata.Add(Options, o => o.JobQueueActiveLatestAddedUser, r => r.QueueLatestActive?.AddedUserId);
|
||||
|
||||
// Warranty
|
||||
metadata.Add(Options, o => o.JobWarrantyExternalName, r => r.JobMetaWarranty?.ExternalName);
|
||||
metadata.Add(Options, o => o.JobWarrantyExternalReference, r => r.JobMetaWarranty?.ExternalReference);
|
||||
metadata.Add(Options, o => o.JobWarrantyExternalLoggedDate, r => r.JobMetaWarranty?.ExternalLoggedDate);
|
||||
metadata.Add(Options, o => o.JobWarrantyExternalCompletedDate, r => r.JobMetaWarranty?.ExternalCompletedDate);
|
||||
|
||||
// Non-Warranty
|
||||
metadata.Add(Options, o => o.JobNonWarrantyAccountingChargeRequiredDate, r => r.JobMetaNonWarranty?.AccountingChargeRequiredDate);
|
||||
metadata.Add(Options, o => o.JobNonWarrantyAccountingChargeAddedDate, r => r.JobMetaNonWarranty?.AccountingChargeAddedDate);
|
||||
metadata.Add(Options, o => o.JobNonWarrantyAccountingChargePaidDate, r => r.JobMetaNonWarranty?.AccountingChargePaidDate);
|
||||
metadata.Add(Options, o => o.JobNonWarrantyPurchaseOrderRaisedDate, r => r.JobMetaNonWarranty?.PurchaseOrderRaisedDate);
|
||||
metadata.Add(Options, o => o.JobNonWarrantyPurchaseOrderReference, r => r.JobMetaNonWarranty?.PurchaseOrderReference);
|
||||
metadata.Add(Options, o => o.JobNonWarrantyPurchaseOrderSentDate, r => r.JobMetaNonWarranty?.PurchaseOrderSentDate);
|
||||
metadata.Add(Options, o => o.JobNonWarrantyInvoiceReceivedDate, r => r.JobMetaNonWarranty?.InvoiceReceivedDate);
|
||||
metadata.Add(Options, o => o.JobNonWarrantyRepairerName, r => r.JobMetaNonWarranty?.RepairerName);
|
||||
metadata.Add(Options, o => o.JobNonWarrantyRepairerLoggedDate, r => r.JobMetaNonWarranty?.RepairerLoggedDate);
|
||||
metadata.Add(Options, o => o.JobNonWarrantyRepairerReference, r => r.JobMetaNonWarranty?.RepairerReference);
|
||||
metadata.Add(Options, o => o.JobNonWarrantyRepairerCompletedDate, r => r.JobMetaNonWarranty?.RepairerCompletedDate);
|
||||
|
||||
// Insurance
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceLossOrDamageDate, r => r.JobMetaInsurance?.LossOrDamageDate);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceEventLocation, r => r.JobMetaInsurance?.EventLocation);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceDescription, r => r.JobMetaInsurance?.Description);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceThirdPartyCausedName, r => r.JobMetaInsurance?.ThirdPartyCausedName);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceThirdPartyCausedWhy, r => r.JobMetaInsurance?.ThirdPartyCausedWhy);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceWitnessesNamesAddresses, r => r.JobMetaInsurance?.WitnessesNamesAddresses);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceBurglaryTheftMethodOfEntry, r => r.JobMetaInsurance?.BurglaryTheftMethodOfEntry);
|
||||
metadata.Add(Options, o => o.JobMetaInsurancePropertyLastSeenDate, r => r.JobMetaInsurance?.PropertyLastSeenDate);
|
||||
metadata.Add(Options, o => o.JobMetaInsurancePoliceNotifiedStation, r => r.JobMetaInsurance?.PoliceNotifiedStation);
|
||||
metadata.Add(Options, o => o.JobMetaInsurancePoliceNotifiedDate, r => r.JobMetaInsurance?.PoliceNotifiedDate);
|
||||
metadata.Add(Options, o => o.JobMetaInsurancePoliceNotifiedCrimeReportNo, r => r.JobMetaInsurance?.PoliceNotifiedCrimeReportNo);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceRecoverReduceAction, r => r.JobMetaInsurance?.RecoverReduceAction);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceOtherInterestedParties, r => r.JobMetaInsurance?.OtherInterestedParties);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceDateOfPurchase, r => r.JobMetaInsurance?.DateOfPurchase);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceClaimFormSentDate, r => r.JobMetaInsurance?.ClaimFormSentDate);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceInsurer, r => r.JobMetaInsurance?.Insurer);
|
||||
metadata.Add(Options, o => o.JobMetaInsuranceInsurerReference, r => r.JobMetaInsurance?.InsurerReference);
|
||||
|
||||
// User Management
|
||||
metadata.Add(Options, o => o.JobUserManagementFlags, r => r.Job.Flags?.ToString());
|
||||
|
||||
// User
|
||||
metadata.Add(Options, o => o.UserId, r => r.User?.UserId);
|
||||
metadata.Add(Options, o => o.UserDisplayName, r => r.User?.DisplayName);
|
||||
metadata.Add(Options, o => o.UserSurname, r => r.User?.Surname);
|
||||
metadata.Add(Options, o => o.UserGivenName, r => r.User?.GivenName);
|
||||
metadata.Add(Options, o => o.UserPhoneNumber, r => r.User?.PhoneNumber);
|
||||
metadata.Add(Options, o => o.UserEmailAddress, r => r.User?.EmailAddress);
|
||||
|
||||
// User Custom Details
|
||||
if (Options.UserDetailCustom)
|
||||
{
|
||||
var keys = records.Where(r => r.UserCustomDetails != null).SelectMany(r => r.UserCustomDetails.Keys).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
|
||||
foreach (var key in keys.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
metadata.Add(key, r => r.UserCustomDetails != null && r.UserCustomDetails.TryGetValue(key, out var value) ? value : null);
|
||||
}
|
||||
}
|
||||
|
||||
// Device
|
||||
metadata.Add(Options, o => o.DeviceSerialNumber, r => r.Device?.SerialNumber);
|
||||
metadata.Add(Options, o => o.DeviceAssetNumber, r => r.Device?.AssetNumber);
|
||||
metadata.Add(Options, o => o.DeviceLocation, r => r.Device?.Location);
|
||||
metadata.Add(Options, o => o.DeviceComputerName, r => r.Device?.DeviceDomainId);
|
||||
metadata.Add(Options, o => o.DeviceLastNetworkLogon, r => r.Device?.LastNetworkLogonDate);
|
||||
metadata.Add(Options, o => o.DeviceCreatedDate, r => r.Device?.CreatedDate);
|
||||
metadata.Add(Options, o => o.DeviceFirstEnrolledDate, r => r.Device?.EnrolledDate);
|
||||
metadata.Add(Options, o => o.DeviceLastEnrolledDate, r => r.Device?.LastEnrolDate);
|
||||
metadata.Add(Options, o => o.DeviceAllowUnauthenticatedEnrol, r => r.Device?.AllowUnauthenticatedEnrol);
|
||||
metadata.Add(Options, o => o.DeviceDecommissionedDate, r => r.Device?.DecommissionedDate);
|
||||
metadata.Add(Options, o => o.DeviceDecommissionedReason, r => r.Device?.DecommissionReason?.ToString());
|
||||
|
||||
// Model
|
||||
metadata.Add(Options, o => o.DeviceModelId, r => r.DeviceModelId);
|
||||
metadata.Add(Options, o => o.DeviceModelDescription, r => r.DeviceModelDescription);
|
||||
metadata.Add(Options, o => o.DeviceModelManufacturer, r => r.DeviceModelManufacturer);
|
||||
metadata.Add(Options, o => o.DeviceModelModel, r => r.DeviceModelModel);
|
||||
metadata.Add(Options, o => o.DeviceModelType, r => r.DeviceModelType);
|
||||
|
||||
// Batch
|
||||
metadata.Add(Options, o => o.DeviceBatchId, r => r.DeviceBatchId);
|
||||
metadata.Add(Options, o => o.DeviceBatchName, r => r.DeviceBatchName);
|
||||
metadata.Add(Options, o => o.DeviceBatchPurchaseDate, r => r.DeviceBatchPurchaseDate);
|
||||
metadata.Add(Options, o => o.DeviceBatchSupplier, r => r.DeviceBatchSupplier);
|
||||
metadata.Add(Options, o => o.DeviceBatchUnitCost, r => r.DeviceBatchUnitCost);
|
||||
metadata.Add(Options, o => o.DeviceBatchWarrantyValidUntilDate, r => r.DeviceBatchWarrantyValidUntilDate);
|
||||
metadata.Add(Options, o => o.DeviceBatchInsuredDate, r => r.DeviceBatchInsuredDate);
|
||||
metadata.Add(Options, o => o.DeviceBatchInsuranceSupplier, r => r.DeviceBatchInsuranceSupplier);
|
||||
metadata.Add(Options, o => o.DeviceBatchInsuredUntilDate, r => r.DeviceBatchInsuredUntilDate);
|
||||
|
||||
// Profile
|
||||
metadata.Add(Options, o => o.DeviceProfileId, r => r.DeviceProfileId);
|
||||
metadata.Add(Options, o => o.DeviceProfileName, r => r.DeviceProfileName);
|
||||
metadata.Add(Options, o => o.DeviceProfileShortName, r => r.DeviceProfileShortName);
|
||||
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,411 +0,0 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Exporting;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Models.Services.Exporting;
|
||||
using Disco.Models.Services.Jobs;
|
||||
using Disco.Services.Exporting;
|
||||
using Disco.Services.Jobs.JobQueues;
|
||||
using Disco.Services.Plugins.Features.DetailsProvider;
|
||||
using Disco.Services.Tasks;
|
||||
using Disco.Services.Users;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
|
||||
namespace Disco.Services.Jobs
|
||||
{
|
||||
using Metadata = ExportFieldMetadata<JobExportRecord>;
|
||||
|
||||
public class JobExportContext : IExportContext<JobExportOptions, JobExportRecord>
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public bool TimestampSuffix { get; set; }
|
||||
public JobExportOptions Options { get; set; }
|
||||
|
||||
public string SuggestedFilenamePrefix { get; } = "JobExport";
|
||||
public string ExcelWorksheetName { get; } = "JobExport";
|
||||
public string ExcelTableName { get; } = "Jobs";
|
||||
|
||||
[JsonConstructor]
|
||||
private JobExportContext()
|
||||
{
|
||||
}
|
||||
|
||||
public JobExportContext(string name, string description, bool timestampSuffix, JobExportOptions options)
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
Name = name;
|
||||
Description = description;
|
||||
TimestampSuffix = timestampSuffix;
|
||||
Options = options;
|
||||
}
|
||||
|
||||
public JobExportContext(JobExportOptions options)
|
||||
: this("Job Export", null, true, options)
|
||||
{
|
||||
}
|
||||
|
||||
public ExportResult Export(DiscoDataContext database, IScheduledTaskStatus status)
|
||||
=> Exporter.Export(database, this, status);
|
||||
|
||||
private IQueryable<Job> BuildFilteredRecords(DiscoDataContext database)
|
||||
{
|
||||
var o = Options;
|
||||
|
||||
var q = database.Jobs.Where(j => j.OpenedDate >= o.FilterStartDate);
|
||||
if (o.FilterEndDate.HasValue)
|
||||
q = q.Where(j => j.OpenedDate <= o.FilterEndDate);
|
||||
|
||||
if (o.FilterJobTypeId != null)
|
||||
q = q.Where(j => j.JobTypeId == o.FilterJobTypeId);
|
||||
|
||||
if (o.FilterJobSubTypeIds?.Any() ?? false)
|
||||
q = q.Where(j => j.JobSubTypes.Any(st => o.FilterJobSubTypeIds.Contains(st.Id)));
|
||||
|
||||
if (o.FilterJobQueueId.HasValue)
|
||||
q = q.Where(j => j.JobQueues.Any(jq => !jq.RemovedDate.HasValue && jq.JobQueueId == o.FilterJobQueueId));
|
||||
|
||||
if (o.FilterJobStatusId != null)
|
||||
{
|
||||
if (o.FilterJobStatusId != Job.JobStatusIds.Closed)
|
||||
q = q.Where(j => j.ClosedDate == null);
|
||||
|
||||
switch (o.FilterJobStatusId)
|
||||
{
|
||||
case Job.JobStatusIds.Open:
|
||||
// already filtered
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingAccountingPayment:
|
||||
q = q.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.AccountingChargeAddedDate != null && j.JobMetaNonWarranty.AccountingChargePaidDate == null);
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingAccountingCharge:
|
||||
q = q.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.AccountingChargeRequiredDate == null && (j.JobMetaNonWarranty.AccountingChargePaidDate != null || j.JobMetaNonWarranty.AccountingChargeAddedDate != null));
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingDeviceReturn:
|
||||
q = q.Where(j => j.DeviceReadyForReturn != null && j.DeviceReturnedDate == null);
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingInsuranceProcessing:
|
||||
q = q.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.IsInsuranceClaim && j.JobMetaInsurance.ClaimFormSentDate == null);
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingRepairs:
|
||||
q = q.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.RepairerLoggedDate != null && j.JobMetaNonWarranty.RepairerCompletedDate == null);
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingUserAction:
|
||||
q = q.Where(j => j.WaitingForUserAction != null);
|
||||
break;
|
||||
case Job.JobStatusIds.AwaitingWarrantyRepair:
|
||||
q = q.Where(j => j.JobTypeId == JobType.JobTypeIds.HWar && j.JobMetaWarranty.ExternalLoggedDate != null && j.JobMetaWarranty.ExternalCompletedDate == null);
|
||||
break;
|
||||
case Job.JobStatusIds.Closed:
|
||||
q = q.Where(j => j.ClosedDate != null);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException($"Unknown Job Status Id: {o.FilterJobStatusId}", nameof(o.FilterJobStatusId));
|
||||
}
|
||||
}
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
public List<JobExportRecord> BuildRecords(DiscoDataContext database, IScheduledTaskStatus status)
|
||||
{
|
||||
database.Configuration.LazyLoadingEnabled = false;
|
||||
database.Configuration.ProxyCreationEnabled = false;
|
||||
|
||||
var query = BuildFilteredRecords(database);
|
||||
|
||||
// Update Users
|
||||
if (Options.UserDisplayName ||
|
||||
Options.UserSurname ||
|
||||
Options.UserGivenName ||
|
||||
Options.UserPhoneNumber ||
|
||||
Options.UserEmailAddress)
|
||||
{
|
||||
status.UpdateStatus(5, "Refreshing user details from Active Directory");
|
||||
var userIds = query.Where(d => d.UserId != null).Select(d => d.UserId).Distinct().ToList();
|
||||
foreach (var userId in userIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
UserService.GetUser(userId, database);
|
||||
}
|
||||
catch (Exception) { } // Ignore Errors
|
||||
}
|
||||
}
|
||||
|
||||
// Update Last Network Logon Date
|
||||
if (Options.DeviceLastNetworkLogon)
|
||||
{
|
||||
status.UpdateStatus(15, "Refreshing device last network logon dates from Active Directory");
|
||||
try
|
||||
{
|
||||
Interop.ActiveDirectory.ADNetworkLogonDatesUpdateTask.UpdateLastNetworkLogonDates(database, ScheduledTaskMockStatus.Create("UpdateLastNetworkLogonDates"));
|
||||
database.SaveChanges();
|
||||
}
|
||||
catch (Exception) { } // Ignore Errors
|
||||
}
|
||||
|
||||
status.UpdateStatus(25, "Extracting records from the database");
|
||||
|
||||
var records = query.Select(j => new JobExportRecord()
|
||||
{
|
||||
Job = j,
|
||||
JobTypeDescription = j.JobType.Description,
|
||||
JobSubTypeDescriptions = j.JobSubTypes.Select(st => st.Description),
|
||||
|
||||
LogCount = j.JobLogs.Count(),
|
||||
FirstLog = j.JobLogs.OrderBy(l => l.Id).FirstOrDefault(),
|
||||
LastLog = j.JobLogs.OrderByDescending(l => l.Id).FirstOrDefault(),
|
||||
|
||||
AttachmentsCount = j.JobAttachments.Count(),
|
||||
|
||||
QueueCount = j.JobQueues.Count(),
|
||||
QueueActiveCount = j.JobQueues.Count(q => !q.RemovedDate.HasValue),
|
||||
QueueLatestActive = j.JobQueues.Where(q => !q.RemovedDate.HasValue).OrderByDescending(q => q.Id).FirstOrDefault(),
|
||||
|
||||
JobMetaWarranty = j.JobMetaWarranty,
|
||||
JobMetaNonWarranty = j.JobMetaNonWarranty,
|
||||
JobMetaInsurance = j.JobMetaInsurance,
|
||||
|
||||
User = j.User,
|
||||
|
||||
Device = j.Device,
|
||||
|
||||
DeviceModelId = j.Device.DeviceModelId,
|
||||
DeviceModelDescription = j.Device.DeviceModel.Description,
|
||||
DeviceModelManufacturer = j.Device.DeviceModel.Manufacturer,
|
||||
DeviceModelModel = j.Device.DeviceModel.Model,
|
||||
DeviceModelType = j.Device.DeviceModel.ModelType,
|
||||
|
||||
DeviceBatchId = j.Device.DeviceBatchId,
|
||||
DeviceBatchName = j.Device.DeviceBatch.Name,
|
||||
DeviceBatchPurchaseDate = j.Device.DeviceBatch.PurchaseDate,
|
||||
DeviceBatchSupplier = j.Device.DeviceBatch.Supplier,
|
||||
DeviceBatchUnitCost = j.Device.DeviceBatch.UnitCost,
|
||||
DeviceBatchWarrantyValidUntilDate = j.Device.DeviceBatch.WarrantyValidUntil,
|
||||
DeviceBatchInsuredDate = j.Device.DeviceBatch.InsuredDate,
|
||||
DeviceBatchInsuranceSupplier = j.Device.DeviceBatch.InsuranceSupplier,
|
||||
DeviceBatchInsuredUntilDate = j.Device.DeviceBatch.InsuredUntil,
|
||||
|
||||
DeviceProfileId = j.Device.DeviceProfileId,
|
||||
DeviceProfileName = j.Device.DeviceProfile.Name,
|
||||
DeviceProfileShortName = j.Device.DeviceProfile.ShortName,
|
||||
}).ToList();
|
||||
|
||||
records.ForEach(r =>
|
||||
{
|
||||
if (Options.JobStatus)
|
||||
{
|
||||
r.JobStatus = JobExtensions.CalculateStatusId(
|
||||
r.Job.ClosedDate,
|
||||
r.Job.JobTypeId,
|
||||
r.JobMetaWarranty?.ExternalLoggedDate,
|
||||
r.JobMetaWarranty?.ExternalCompletedDate,
|
||||
r.JobMetaNonWarranty?.RepairerLoggedDate,
|
||||
r.JobMetaNonWarranty?.RepairerCompletedDate,
|
||||
r.JobMetaNonWarranty?.AccountingChargeRequiredDate,
|
||||
r.JobMetaNonWarranty?.AccountingChargeAddedDate,
|
||||
r.JobMetaNonWarranty?.AccountingChargePaidDate,
|
||||
r.JobMetaNonWarranty?.IsInsuranceClaim,
|
||||
r.JobMetaInsurance?.ClaimFormSentDate,
|
||||
r.Job.WaitingForUserAction,
|
||||
r.Job.DeviceReadyForReturn,
|
||||
r.Job.DeviceReturnedDate);
|
||||
}
|
||||
|
||||
if (Options.UserDetailCustom && r.User != null)
|
||||
{
|
||||
var detailsService = new DetailsProviderService(database);
|
||||
r.UserCustomDetails = detailsService.GetDetails(r.User);
|
||||
}
|
||||
});
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
public List<Metadata> BuildMetadata(DiscoDataContext database, List<JobExportRecord> records, IScheduledTaskStatus status)
|
||||
{
|
||||
IEnumerable<string> userDetailCustomKeys = null;
|
||||
if (Options.UserDetailCustom)
|
||||
userDetailCustomKeys = records.Where(r => r.UserCustomDetails != null).SelectMany(r => r.UserCustomDetails.Keys).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
|
||||
|
||||
var allAccessors = BuildRecordAccessors(userDetailCustomKeys);
|
||||
|
||||
return typeof(JobExportOptions).GetProperties()
|
||||
.Where(p => p.PropertyType == typeof(bool))
|
||||
.Select(p => new
|
||||
{
|
||||
property = p,
|
||||
details = (DisplayAttribute)p.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault()
|
||||
})
|
||||
.Where(p => p.details != null && (bool)p.property.GetValue(Options))
|
||||
.SelectMany(p =>
|
||||
{
|
||||
var fieldMetadata = allAccessors[p.property.Name];
|
||||
fieldMetadata.ForEach(f =>
|
||||
{
|
||||
if (f.ColumnName == null)
|
||||
f.ColumnName = (p.details.ShortName == "Job" || p.details.ShortName == "Job Details") ? p.details.Name : $"{p.details.ShortName} {p.details.Name}";
|
||||
});
|
||||
return fieldMetadata;
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private static Dictionary<string, List<Metadata>> BuildRecordAccessors(IEnumerable<string> userDetailCustomKeys)
|
||||
{
|
||||
const string DateFormat = "yyyy-MM-dd";
|
||||
const string DateTimeFormat = DateFormat + " HH:mm:ss";
|
||||
|
||||
Func<object, string> csvStringEncoded = (o) => o == null ? null : $"\"{((string)o).Replace("\"", "\"\"")}\"";
|
||||
Func<object, string> csvToStringEncoded = (o) => o == null ? null : o.ToString();
|
||||
Func<object, string> csvCurrencyEncoded = (o) => ((decimal?)o).HasValue ? ((decimal?)o).Value.ToString("C") : null;
|
||||
Func<object, string> csvDateEncoded = (o) => ((DateTime)o).ToString(DateFormat);
|
||||
Func<object, string> csvDateTimeEncoded = (o) => ((DateTime)o).ToString(DateTimeFormat);
|
||||
Func<object, string> csvNullableDateEncoded = (o) => ((DateTime?)o).HasValue ? csvDateEncoded(o) : null;
|
||||
Func<object, string> csvNullableDateTimeEncoded = (o) => ((DateTime?)o).HasValue ? csvDateTimeEncoded(o) : null;
|
||||
|
||||
var metadata = new Dictionary<string, List<Metadata>>();
|
||||
|
||||
// Job
|
||||
metadata.Add(nameof(JobExportOptions.JobId), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobId), typeof(int), r => r.Job.Id, csvToStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobStatus), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobStatus), typeof(string), r => Job.JobStatusIds.StatusDescriptions.TryGetValue(r.JobStatus, out var status) ? status : "Unknown", csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobType), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobType), typeof(string), r => r.JobTypeDescription, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobSubTypes), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobSubTypes), typeof(string), r => string.Join(", ", r.JobSubTypeDescriptions), csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobOpenedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobOpenedDate), typeof(DateTime), r => r.Job.OpenedDate, csvDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobOpenedUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobOpenedUser), typeof(string), r => r.Job.OpenedTechUserId, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobExpectedClosedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobExpectedClosedDate), typeof(DateTime), r => r.Job.ExpectedClosedDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobClosedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobClosedDate), typeof(DateTime), r => r.Job.ClosedDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobClosedUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobClosedUser), typeof(string), r => r.Job.ClosedTechUserId, csvStringEncoded) });
|
||||
|
||||
// Job Details
|
||||
metadata.Add(nameof(JobExportOptions.JobDeviceHeldDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceHeldDate), typeof(DateTime), r => r.Job.DeviceHeld, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobDeviceHeldUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceHeldUser), typeof(string), r => r.Job.DeviceHeldTechUserId, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobDeviceHeldLocation), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceHeldLocation), typeof(string), r => r.Job.DeviceHeldLocation, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobDeviceReadyForReturnDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceReadyForReturnDate), typeof(DateTime), r => r.Job.DeviceReadyForReturn, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobDeviceReadyForReturnUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceReadyForReturnUser), typeof(string), r => r.Job.DeviceReadyForReturnTechUserId, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobDeviceReturnedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceReturnedDate), typeof(DateTime), r => r.Job.DeviceReturnedDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobDeviceReturnedUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceReturnedUser), typeof(string), r => r.Job.DeviceReturnedTechUserId, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobWaitingForUserActionDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobWaitingForUserActionDate), typeof(DateTime), r => r.Job.WaitingForUserAction, csvNullableDateTimeEncoded) });
|
||||
|
||||
// Job Logs
|
||||
metadata.Add(nameof(JobExportOptions.LogCount), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogCount), typeof(int), r => r.LogCount, csvToStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.LogFirstDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogFirstDate), typeof(DateTime), r => r.FirstLog?.Timestamp, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.LogFirstUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogFirstUser), typeof(string), r => r.FirstLog?.TechUserId, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.LogFirstContent), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogFirstContent), typeof(string), r => r.FirstLog?.Comments, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.LogLastDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogLastDate), typeof(DateTime), r => r.LastLog?.Timestamp, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.LogLastUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogLastUser), typeof(string), r => r.LastLog?.TechUserId, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.LogLastContent), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogLastContent), typeof(string), r => r.LastLog?.Comments, csvStringEncoded) });
|
||||
|
||||
// Attachments
|
||||
metadata.Add(nameof(JobExportOptions.AttachmentsCount), new List<Metadata>() { new Metadata(nameof(JobExportOptions.AttachmentsCount), typeof(int), r => r.AttachmentsCount, csvToStringEncoded) });
|
||||
|
||||
// Job Queues
|
||||
metadata.Add(nameof(JobExportOptions.JobQueueCount), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobQueueCount), typeof(int), r => r.QueueCount, csvToStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobQueueActiveCount), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobQueueActiveCount), typeof(int), r => r.QueueActiveCount, csvToStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobQueueActiveLatest), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobQueueActiveLatest), typeof(DateTime), r => r.QueueLatestActive?.JobQueueId == null ? null : JobQueueService.GetQueue(r.QueueLatestActive.JobQueueId).JobQueue.Name, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobQueueActiveLatestAddedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobQueueActiveLatestAddedDate), typeof(DateTime), r => r.QueueLatestActive?.AddedDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobQueueActiveLatestAddedUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobQueueActiveLatestAddedUser), typeof(string), r => r.QueueLatestActive?.AddedUserId, csvStringEncoded) });
|
||||
|
||||
// Warranty
|
||||
metadata.Add(nameof(JobExportOptions.JobWarrantyExternalName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobWarrantyExternalName), typeof(string), r => r.JobMetaWarranty?.ExternalName, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobWarrantyExternalReference), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobWarrantyExternalReference), typeof(string), r => r.JobMetaWarranty?.ExternalReference, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobWarrantyExternalLoggedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobWarrantyExternalLoggedDate), typeof(DateTime), r => r.JobMetaWarranty?.ExternalLoggedDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobWarrantyExternalCompletedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobWarrantyExternalCompletedDate), typeof(DateTime), r => r.JobMetaWarranty?.ExternalCompletedDate, csvNullableDateTimeEncoded) });
|
||||
|
||||
// Non-Warranty
|
||||
metadata.Add(nameof(JobExportOptions.JobNonWarrantyAccountingChargeRequiredDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyAccountingChargeRequiredDate), typeof(DateTime), r => r.JobMetaNonWarranty?.AccountingChargeRequiredDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobNonWarrantyAccountingChargeAddedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyAccountingChargeAddedDate), typeof(DateTime), r => r.JobMetaNonWarranty?.AccountingChargeAddedDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobNonWarrantyAccountingChargePaidDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyAccountingChargePaidDate), typeof(DateTime), r => r.JobMetaNonWarranty?.AccountingChargePaidDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderRaisedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderRaisedDate), typeof(DateTime), r => r.JobMetaNonWarranty?.PurchaseOrderRaisedDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderReference), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderReference), typeof(string), r => r.JobMetaNonWarranty?.PurchaseOrderReference, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderSentDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderSentDate), typeof(DateTime), r => r.JobMetaNonWarranty?.PurchaseOrderSentDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobNonWarrantyInvoiceReceivedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyInvoiceReceivedDate), typeof(DateTime), r => r.JobMetaNonWarranty?.InvoiceReceivedDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobNonWarrantyRepairerName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyRepairerName), typeof(string), r => r.JobMetaNonWarranty?.RepairerName, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobNonWarrantyRepairerLoggedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyRepairerLoggedDate), typeof(DateTime), r => r.JobMetaNonWarranty?.RepairerLoggedDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobNonWarrantyRepairerReference), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyRepairerReference), typeof(string), r => r.JobMetaNonWarranty?.RepairerReference, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobNonWarrantyRepairerCompletedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyRepairerCompletedDate), typeof(DateTime), r => r.JobMetaNonWarranty?.RepairerCompletedDate, csvNullableDateTimeEncoded) });
|
||||
|
||||
// Insurance
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceLossOrDamageDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceLossOrDamageDate), typeof(DateTime), r => r.JobMetaInsurance?.LossOrDamageDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceEventLocation), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceEventLocation), typeof(string), r => r.JobMetaInsurance?.EventLocation, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceDescription), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceDescription), typeof(string), r => r.JobMetaInsurance?.Description, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceThirdPartyCausedName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceThirdPartyCausedName), typeof(string), r => r.JobMetaInsurance?.ThirdPartyCausedName, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceThirdPartyCausedWhy), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceThirdPartyCausedWhy), typeof(string), r => r.JobMetaInsurance?.ThirdPartyCausedWhy, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceWitnessesNamesAddresses), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceWitnessesNamesAddresses), typeof(string), r => r.JobMetaInsurance?.WitnessesNamesAddresses, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceBurglaryTheftMethodOfEntry), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceBurglaryTheftMethodOfEntry), typeof(string), r => r.JobMetaInsurance?.BurglaryTheftMethodOfEntry, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsurancePropertyLastSeenDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsurancePropertyLastSeenDate), typeof(DateTime), r => r.JobMetaInsurance?.PropertyLastSeenDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedStation), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedStation), typeof(string), r => r.JobMetaInsurance?.PoliceNotifiedStation, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedDate), typeof(DateTime), r => r.JobMetaInsurance?.PoliceNotifiedDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedCrimeReportNo), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedCrimeReportNo), typeof(string), r => r.JobMetaInsurance?.PoliceNotifiedCrimeReportNo, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceRecoverReduceAction), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceRecoverReduceAction), typeof(string), r => r.JobMetaInsurance?.RecoverReduceAction, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceOtherInterestedParties), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceOtherInterestedParties), typeof(string), r => r.JobMetaInsurance?.OtherInterestedParties, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceDateOfPurchase), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceDateOfPurchase), typeof(DateTime), r => r.JobMetaInsurance?.DateOfPurchase, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceClaimFormSentDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceClaimFormSentDate), typeof(DateTime), r => r.JobMetaInsurance?.ClaimFormSentDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceInsurer), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceInsurer), typeof(string), r => r.JobMetaInsurance?.Insurer, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceInsurerReference), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceInsurerReference), typeof(string), r => r.JobMetaInsurance?.InsurerReference, csvStringEncoded) });
|
||||
|
||||
// User Management
|
||||
metadata.Add(nameof(JobExportOptions.JobUserManagementFlags), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobUserManagementFlags), typeof(string), r => r.Job.Flags, csvToStringEncoded) });
|
||||
|
||||
// User
|
||||
metadata.Add(nameof(JobExportOptions.UserId), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserId), typeof(string), r => r.User?.UserId, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.UserDisplayName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserDisplayName), typeof(string), r => r.User?.DisplayName, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.UserSurname), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserSurname), typeof(string), r => r.User?.Surname, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.UserGivenName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserGivenName), typeof(string), r => r.User?.GivenName, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.UserPhoneNumber), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserPhoneNumber), typeof(string), r => r.User?.PhoneNumber, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.UserEmailAddress), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserEmailAddress), typeof(string), r => r.User?.EmailAddress, csvStringEncoded) });
|
||||
if (userDetailCustomKeys != null)
|
||||
{
|
||||
var assignedUserDetailCustomFields = new List<Metadata>();
|
||||
foreach (var detailKey in userDetailCustomKeys.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
var key = detailKey;
|
||||
assignedUserDetailCustomFields.Add(new Metadata(detailKey, detailKey, typeof(string), r => r.UserCustomDetails != null && r.UserCustomDetails.TryGetValue(key, out var value) ? value : null, csvStringEncoded));
|
||||
}
|
||||
metadata.Add(nameof(JobExportOptions.UserDetailCustom), assignedUserDetailCustomFields);
|
||||
}
|
||||
|
||||
// Device
|
||||
metadata.Add(nameof(JobExportOptions.DeviceSerialNumber), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceSerialNumber), typeof(string), r => r.Device?.SerialNumber, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceAssetNumber), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceAssetNumber), typeof(string), r => r.Device?.AssetNumber, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceLocation), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceLocation), typeof(string), r => r.Device?.Location, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceComputerName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceComputerName), typeof(string), r => r.Device?.DeviceDomainId, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceLastNetworkLogon), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceLastNetworkLogon), typeof(DateTime), r => r.Device?.LastNetworkLogonDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceCreatedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceCreatedDate), typeof(DateTime), r => r.Device?.CreatedDate, csvDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceFirstEnrolledDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceFirstEnrolledDate), typeof(DateTime), r => r.Device?.EnrolledDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceLastEnrolledDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceLastEnrolledDate), typeof(DateTime), r => r.Device?.LastEnrolDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceAllowUnauthenticatedEnrol), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceAllowUnauthenticatedEnrol), typeof(bool), r => r.Device?.AllowUnauthenticatedEnrol, csvToStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceDecommissionedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceDecommissionedDate), typeof(DateTime), r => r.Device?.DecommissionedDate, csvNullableDateTimeEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceDecommissionedReason), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceDecommissionedReason), typeof(string), r => r.Device?.DecommissionReason, csvToStringEncoded) });
|
||||
|
||||
// Model
|
||||
metadata.Add(nameof(JobExportOptions.DeviceModelId), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceModelId), typeof(int), r => r.DeviceModelId, csvToStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceModelDescription), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceModelDescription), typeof(string), r => r.DeviceModelDescription, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceModelManufacturer), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceModelManufacturer), typeof(string), r => r.DeviceModelManufacturer, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceModelModel), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceModelModel), typeof(string), r => r.DeviceModelModel, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceModelType), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceModelType), typeof(string), r => r.DeviceModelType, csvStringEncoded) });
|
||||
|
||||
// Batch
|
||||
metadata.Add(nameof(JobExportOptions.DeviceBatchId), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchId), typeof(int), r => r.DeviceBatchId, csvToStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceBatchName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchName), typeof(string), r => r.DeviceBatchName, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceBatchPurchaseDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchPurchaseDate), typeof(DateTime), r => r.DeviceBatchPurchaseDate, csvNullableDateEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceBatchSupplier), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchSupplier), typeof(string), r => r.DeviceBatchSupplier, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceBatchUnitCost), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchUnitCost), typeof(decimal), r => r.DeviceBatchUnitCost, csvCurrencyEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceBatchWarrantyValidUntilDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchWarrantyValidUntilDate), typeof(DateTime), r => r.DeviceBatchWarrantyValidUntilDate, csvNullableDateEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceBatchInsuredDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchInsuredDate), typeof(DateTime), r => r.DeviceBatchInsuredDate, csvNullableDateEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceBatchInsuranceSupplier), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchInsuranceSupplier), typeof(string), r => r.DeviceBatchInsuranceSupplier, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceBatchInsuredUntilDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchInsuredUntilDate), typeof(DateTime), r => r.DeviceBatchInsuredUntilDate, csvNullableDateEncoded) });
|
||||
|
||||
// Profile
|
||||
metadata.Add(nameof(JobExportOptions.DeviceProfileId), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceProfileId), typeof(int), r => r.DeviceProfileId, csvToStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceProfileName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceProfileName), typeof(string), r => r.DeviceProfileName, csvStringEncoded) });
|
||||
metadata.Add(nameof(JobExportOptions.DeviceProfileShortName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceProfileShortName), typeof(string), r => r.DeviceProfileShortName, csvStringEncoded) });
|
||||
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user