using Disco.Data.Repository;
using Disco.Models.BI.Config;
using Disco.Models.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
namespace Disco.Services.Plugins.Features.RepairProvider
{
[PluginFeatureCategory(DisplayName = "Repair Providers")]
public abstract class RepairProviderFeature : PluginFeature
{
///
/// The repairer identifier. Used to link this provider to any . This identifier is used to automatically set the RepairerName when a job is submitted using this plugin.
///
public abstract string ProviderId { get; }
#region Job Submission
///
/// Called when a user selects this plugin to repair and allows a plugin to inject a View to collect additional information.
///
/// A Tuple consisting of the Razor View type and a View Model
public virtual Tuple SubmitJobBegin(DiscoDataContext Database, Controller controller, Job Job, OrganisationAddress Address, User TechUser)
{
return null;
}
///
/// Called after the RepairDescription is completed and allows the plugin to parse any data collected from SubmitJobBegin.
///
/// A Dictionary of key/value items which are persisted throughout the submission and passed into the final SubmitJob method.
public virtual Dictionary SubmitJobParseProperties(DiscoDataContext Database, FormCollection form, Controller controller, Job Job, OrganisationAddress Address, User TechUser, string RepairDescription)
{
return null;
}
///
/// Plugins are required to disclose any information that will be transmitted to any external party. This method is expected to return a clear list all data which will be transmitted.
///
/// A Dictionary of key/value items which contain all information which will be disclosed to the plugin provider.
public abstract Dictionary SubmitJobDiscloseInfo(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string RepairDescription, Dictionary ProviderProperties);
///
/// Called when the plugin should submit the job to the external party.
///
/// A reference number/identifier from the external party which is stored in
public abstract string SubmitJob(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string RepairDescription, Dictionary ProviderProperties);
#endregion
#region Job Details
///
/// when additional Job Details are supported by the external party. When , JobDetailsViewModel must be implemented.
///
public abstract bool JobDetailsSupported { get; }
///
/// Called when a job repair information is shown. Allows a plugin to inject a View to display additional information.
///
/// A Tuple consisting of the Razor View type and a View Model
public virtual Tuple JobDetails(DiscoDataContext Database, Controller controller, Job Job)
{
return null;
}
#endregion
public static PluginFeatureManifest FindPluginFeature(string PluginIdOrRepairProviderId)
{
var defs = Plugins.GetPluginFeatures(typeof(RepairProviderFeature));
var def = defs.FirstOrDefault(d => d.PluginManifest.Id.Equals(PluginIdOrRepairProviderId, StringComparison.OrdinalIgnoreCase));
if (def != null)
return def;
else
foreach (var d in defs)
{
using (var providerInstance = d.CreateInstance())
{
if (providerInstance.ProviderId != null && providerInstance.ProviderId.Equals(PluginIdOrRepairProviderId, StringComparison.OrdinalIgnoreCase))
{
return d;
}
}
}
return null;
}
}
}