/// <inheritdoc /> protected BasicConsumer( Environment environment, IFrameworkSettings settings = null, ISessionService sessionService = null) : base(environment, settings, sessionService) { }
/// <summary> /// Create an instance based on the specified service. /// </summary> /// <param name="service">Service used for managing the object type.</param> /// <param name="settings">Provider settings. If null, Provider settings will be read from the SifFramework.config file.</param> /// <param name="sessionService">Provider session service. If null, the Provider session will be stored in the SifFramework.config file.</param> /// <exception cref="ArgumentNullException">service is null.</exception> protected Provider( IProviderService <TSingle, TMultiple> service, IFrameworkSettings settings = null, ISessionService sessionService = null) { Service = service ?? throw new ArgumentNullException(nameof(service)); ProviderSettings = settings ?? SettingsManager.ProviderSettings; this.sessionService = sessionService ?? SessionsManager.ProviderSessionService; if (EnvironmentType.DIRECT.Equals(ProviderSettings.EnvironmentType)) { AuthenticationService = new DirectAuthenticationService(new ApplicationRegisterService(), new EnvironmentService()); } else if (EnvironmentType.BROKERED.Equals(ProviderSettings.EnvironmentType)) { AuthenticationService = new BrokeredAuthenticationService( new ApplicationRegisterService(), new EnvironmentService(), ProviderSettings, this.sessionService); } AuthorisationService = new AuthorisationService(AuthenticationService); }
/// <inheritdoc /> protected BasicProvider( IBasicProviderService <T> service, IFrameworkSettings settings = null, ISessionService sessionService = null) : base(service, settings, sessionService) { }
/// <summary> /// Create a Consumer instance based upon the Environment passed. /// </summary> /// <param name="environment">Environment object.</param> /// <param name="settings">Consumer settings. If null, Consumer settings will be read from the SifFramework.config file.</param> protected Consumer(Model.Infrastructure.Environment environment, IFrameworkSettings settings = null) { ConsumerSettings = settings ?? SettingsManager.ConsumerSettings; environmentTemplate = EnvironmentUtils.MergeWithSettings(environment, ConsumerSettings); RegistrationService = new RegistrationService(ConsumerSettings, SessionsManager.ConsumerSessionService); }
public BrokeredAuthenticationService(IApplicationRegisterService applicationRegisterService, IEnvironmentService environmentService) { this.applicationRegisterService = applicationRegisterService; this.environmentService = environmentService; settings = SettingsManager.ProviderSettings; sessionService = SessionsManager.ProviderSessionService; }
/// <inheritdoc /> public StudentSchoolEnrollmentConsumer( Environment environment, IFrameworkSettings settings = null, ISessionService sessionService = null) : base(environment, settings, sessionService) { }
/// <inheritdoc /> protected BasicEventConsumer( Model.Infrastructure.Environment environment, IFrameworkSettings settings = null, ISessionService sessionService = null) : base(environment, settings, sessionService) { }
private void StartTimeout(IFrameworkSettings settings) { log.Info("Setting up job timeout..."); if (!settings.JobTimeoutEnabled) { log.Debug("Job timeout disabled in settings."); return; } int frequencyInSec = settings.JobTimeoutFrequency; if (frequencyInSec == 0) { log.Debug("Job timeout enabled, but timeout currently turned off (frequency=0)"); return; } int frequency = frequencyInSec * 1000; log.Info("Jobs timeout task will run every " + frequencyInSec + "s (" + frequency + "ms)."); timeoutTimer = new Timer((o) => { foreach (IFunctionalService service in providers.Values) { service.JobTimeout(); } }, null, 0, frequency); }
/// <summary> /// Register this SIF Provider with the EnvironmentProvider based upon settings defined in the SIF 3.0 /// Framework configuration, e.g. SifFramework.config. /// </summary> private void Register(IFrameworkSettings settings) { registrationService = RegistrationManager.GetProviderRegistrationService( settings, SessionsManager.ProviderSessionService); registrationService.Register(); }
/// <inheritdoc /> public StudentPersonalEventConsumer( Environment environment, IFrameworkSettings settings = null, ISessionService sessionService = null) : base(environment, settings, sessionService) { }
/// <summary> /// Create a Consumer instance based upon the Environment passed. /// </summary> /// <param name="environment">Environment object.</param> /// <param name="settings">Consumer settings. If null, Consumer settings will be read from the SifFramework.config file.</param> public FunctionalServiceConsumer(Environment environment, IFrameworkSettings settings = null) { ConsumerSettings = settings ?? SettingsManager.ConsumerSettings; environmentTemplate = EnvironmentUtils.MergeWithSettings(environment, ConsumerSettings); registrationService = new RegistrationService(ConsumerSettings, SessionsManager.ConsumerSessionService); }
/// <inheritdoc /> protected ObjectProvider( IObjectProviderService <TSingle, TMultiple> service, IFrameworkSettings settings = null, ISessionService sessionService = null) : base(service, settings, sessionService) { this.service = service; }
/*---------------------*/ /*-- Private Methods --*/ /*---------------------*/ private FunctionalServiceProviderFactory(IFrameworkSettings settings = null) { ProviderSettings = settings ?? SettingsManager.ProviderSettings; InitialiseProviders(); StartProviders(ProviderSettings); StartEventing(); StartTimeout(ProviderSettings); }
/** * Returns an lazy loaded instance of this provider factory. * * @return See Desc. */ public static FunctionalServiceProviderFactory GetInstance(IFrameworkSettings settings = null) { if (factory == null) { return(CreateFactory(settings)); } return(factory); }
/// <summary> /// Create a Consumer instance identified by the parameters passed. /// </summary> /// <param name="applicationKey">Application key.</param> /// <param name="instanceId">Instance ID.</param> /// <param name="userToken">User token.</param> /// <param name="solutionId">Solution ID.</param> /// <param name="settings">Consumer settings. If null, Consumer settings will be read from the SifFramework.config file.</param> public Consumer( string applicationKey, string instanceId = null, string userToken = null, string solutionId = null, IFrameworkSettings settings = null) : this(new Model.Infrastructure.Environment(applicationKey, instanceId, userToken, solutionId), settings) { }
public StudentSchoolEnrollmentConsumer( string applicationKey, string instanceId = null, string userToken = null, string solutionId = null, IFrameworkSettings settings = null) : base(applicationKey, instanceId, userToken, solutionId, settings) { }
/// <summary> /// Create a Consumer instance identified by the parameters passed. /// </summary> /// <param name="applicationKey">Application key.</param> /// <param name="instanceId">Instance ID.</param> /// <param name="userToken">User token.</param> /// <param name="solutionId">Solution ID.</param> /// <param name="settings">Consumer settings. If null, Consumer settings will be read from the SifFramework.config file.</param> public FunctionalServiceConsumer( string applicationKey, string instanceId = null, string userToken = null, string solutionId = null, IFrameworkSettings settings = null) : this(new Environment(applicationKey, instanceId, userToken, solutionId), settings) { }
/// <summary> /// <see cref="EventConsumer{TSingle,TMultiple,TPrimaryKey}">EventConsumer</see> /// </summary> protected BasicEventConsumer( string applicationKey, string instanceId = null, string userToken = null, string solutionId = null, IFrameworkSettings settings = null) : base(applicationKey, instanceId, userToken, solutionId, settings) { }
/// <inheritdoc /> public BasicConsumer( string applicationKey, string instanceId = null, string userToken = null, string solutionId = null, IFrameworkSettings settings = null, ISessionService sessionService = null) : base(applicationKey, instanceId, userToken, solutionId, settings, sessionService) { }
/// <summary> /// Create an Environment instance from properties defined in the framework settings. /// </summary> /// <param name="settings">Framework settings.</param> /// <returns>Environment instance.</returns> internal static Environment LoadFromSettings(IFrameworkSettings settings) { Environment merged = new Environment(); if (merged.ApplicationInfo == null) { merged.ApplicationInfo = new ApplicationInfo(); } if (string.IsNullOrWhiteSpace(settings.ApplicationKey)) { throw new ConfigurationErrorsException("An applicationKey must be defined in the Provider Environment template."); } else { merged.ApplicationInfo.ApplicationKey = settings.ApplicationKey; } if (!string.IsNullOrWhiteSpace(settings.SolutionId)) { merged.SolutionId = settings.SolutionId; } if (!string.IsNullOrWhiteSpace(settings.UserToken)) { merged.UserToken = settings.UserToken; } if (!string.IsNullOrWhiteSpace(settings.InstanceId)) { merged.InstanceId = settings.InstanceId; } if (!string.IsNullOrWhiteSpace(settings.AuthenticationMethod)) { merged.AuthenticationMethod = settings.AuthenticationMethod; } if (!string.IsNullOrWhiteSpace(settings.ConsumerName)) { merged.ConsumerName = settings.ConsumerName; } if (!string.IsNullOrWhiteSpace(settings.DataModelNamespace)) { merged.ApplicationInfo.DataModelNamespace = settings.DataModelNamespace; } if (!string.IsNullOrWhiteSpace(settings.SupportedInfrastructureVersion)) { merged.ApplicationInfo.SupportedInfrastructureVersion = settings.SupportedInfrastructureVersion; } return(merged); }
public BrokeredAuthenticationService( IApplicationRegisterService applicationRegisterService, IEnvironmentService environmentService, IFrameworkSettings settings, ISessionService sessionService) { this.applicationRegisterService = applicationRegisterService; this.environmentService = environmentService; this.settings = settings; this.sessionService = sessionService; }
/// <summary> /// Create an instance of this service. /// </summary> /// <param name="applicationRegisterService">Application register service.</param> /// <param name="environmentService">Environment service.</param> /// <param name="settings">Framework settings service.</param> /// <param name="sessionService">Session service.</param> /// <exception cref="ArgumentNullException">A passed parameter is null.</exception> public BrokeredAuthenticationService( IApplicationRegisterService applicationRegisterService, IEnvironmentService environmentService, IFrameworkSettings settings, ISessionService sessionService) { this.applicationRegisterService = applicationRegisterService ?? throw new ArgumentNullException(nameof(applicationRegisterService)); this.environmentService = environmentService ?? throw new ArgumentNullException(nameof(environmentService)); this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); this.sessionService = sessionService ?? throw new ArgumentNullException(nameof(sessionService)); }
/// <summary> /// Combine the passed in environment object with the equivalent properties defined in the framework settings /// (if present). Properties that already exist in the passed in the environment take precedence over the /// properties defined in the framework settings. /// </summary> /// <param name="environment">Environment object to check.</param> /// <param name="settings">Framework settings.</param> /// <returns>Environment object with merged properties.</returns> internal static Environment MergeWithSettings(Environment environment, IFrameworkSettings settings) { Environment merged; if (environment == null) { merged = new Environment(); } else { merged = environment; } if (merged.ApplicationInfo == null) { merged.ApplicationInfo = new ApplicationInfo(); } if (string.IsNullOrWhiteSpace(merged.ApplicationInfo.ApplicationKey) && settings.ApplicationKey != null) { merged.ApplicationInfo.ApplicationKey = settings.ApplicationKey; } if (string.IsNullOrWhiteSpace(merged.ApplicationInfo.ApplicationKey)) { throw new ArgumentException("An applicationKey must either be provided or defined in the Consumer Environment template.", "applicationKey"); } if (string.IsNullOrWhiteSpace(merged.AuthenticationMethod) && settings.AuthenticationMethod != null) { merged.AuthenticationMethod = settings.AuthenticationMethod; } if (string.IsNullOrWhiteSpace(merged.ConsumerName) && settings.ConsumerName != null) { merged.ConsumerName = settings.ConsumerName; } if (string.IsNullOrWhiteSpace(merged.ApplicationInfo.DataModelNamespace) && settings.DataModelNamespace != null) { merged.ApplicationInfo.DataModelNamespace = settings.DataModelNamespace; } if (string.IsNullOrWhiteSpace(merged.ApplicationInfo.SupportedInfrastructureVersion) && settings.SupportedInfrastructureVersion != null) { merged.ApplicationInfo.SupportedInfrastructureVersion = settings.SupportedInfrastructureVersion; } return(merged); }
public void TestRetrieveAppSettings() { IFrameworkSettings settings = SettingsManager.ConsumerSettings; Assert.AreEqual(settings.ApplicationKey, "Sif3DemoApp"); Assert.AreEqual(settings.AuthenticationMethod, "Basic"); Assert.AreEqual(settings.ConsumerName, "DemoConsumer"); Assert.AreEqual(settings.DataModelNamespace, "http://www.sifassociation.org/au/datamodel/1.4"); Assert.IsTrue(settings.DeleteOnUnregister); Assert.AreEqual(settings.EnvironmentUrl, "http://localhost:62921/api/environments/environment"); Assert.IsNull(settings.InstanceId); Assert.AreEqual(settings.SharedSecret, "SecretDem0"); Assert.IsNull(settings.SolutionId); Assert.AreEqual(settings.SupportedInfrastructureVersion, "3.0.1"); Assert.IsNull(settings.UserToken); }
private void StartProviders(IFrameworkSettings settings) { int delay = settings.StartupDelay; //delay between threads in seconds log.Debug("Start up delay between providers is: " + delay + " seconds"); int i = 0; foreach (string serviceName in providerThreads.Keys) { log.Debug("Starting thread for " + serviceName); Timer timer = new Timer((o) => { providerThreads[serviceName].Start(); }, null, (i * delay), Timeout.Infinite); i += 1000; } }
/// <summary> /// Create an instance. /// </summary> /// <param name="settings">Provider settings. If null, Provider settings will be read from the SifFramework.config file.</param> protected FunctionalServiceProvider(IFrameworkSettings settings = null) { ProviderSettings = settings ?? SettingsManager.ProviderSettings; if (EnvironmentType.DIRECT.Equals(ProviderSettings.EnvironmentType)) { authService = new DirectAuthenticationService(new ApplicationRegisterService(), new EnvironmentService()); } else if (EnvironmentType.BROKERED.Equals(ProviderSettings.EnvironmentType)) { authService = new BrokeredAuthenticationService( new ApplicationRegisterService(), new EnvironmentService(), settings, SessionsManager.ProviderSessionService); } }
/// <summary> /// Create an instance using the appropriate settings and service. /// </summary> /// <param name="settings">Framework settings.</param> /// <param name="sessionService">Service used for managing sessions.</param> public RegistrationService(IFrameworkSettings settings, ISessionService sessionService) { this.settings = settings; this.sessionService = sessionService; if (AuthenticationMethod.Basic.ToString().Equals(settings.AuthenticationMethod, StringComparison.OrdinalIgnoreCase)) { authorisationTokenService = new BasicAuthorisationTokenService(); } else if (AuthenticationMethod.SIF_HMACSHA256.ToString().Equals(settings.AuthenticationMethod, StringComparison.OrdinalIgnoreCase)) { authorisationTokenService = new HmacShaAuthorisationTokenService(); } else { authorisationTokenService = new BasicAuthorisationTokenService(); } Registered = false; }
/// <summary> /// Creates and configures the factory singleton instance. /// </summary> /// <returns>The factory singleton</returns> public static FunctionalServiceProviderFactory CreateFactory(IFrameworkSettings settings = null) { lock (locked) { log.Debug("Total Threads running before initialising provider Factory: " + Process.GetCurrentProcess().Threads.Count + " threads."); if (factory == null) { try { factory = new FunctionalServiceProviderFactory(settings); } catch (Exception ex) { log.Error("Failed to initialise provider factory. Provider won't run.", ex); factory = null; } } log.Debug("Total Threads running after initialising Provider Factory: " + Process.GetCurrentProcess().Threads.Count + " threads."); return(factory); } }
/// <summary> /// Create an Environment instance from properties defined in the framework settings. /// </summary> /// <param name="settings">Framework settings.</param> /// <returns>Environment instance.</returns> internal static Environment LoadFromSettings(IFrameworkSettings settings) { Environment merged = new Environment(); if (merged.ApplicationInfo == null) { merged.ApplicationInfo = new ApplicationInfo(); } if (String.IsNullOrWhiteSpace(settings.ApplicationKey)) { throw new ConfigurationErrorsException("An applicationKey must be defined in the Provider Environment template."); } else { merged.ApplicationInfo.ApplicationKey = settings.ApplicationKey; } if (!String.IsNullOrWhiteSpace(settings.AuthenticationMethod)) { merged.AuthenticationMethod = settings.AuthenticationMethod; } if (!String.IsNullOrWhiteSpace(settings.ConsumerName)) { merged.ConsumerName = settings.ConsumerName; } if (!String.IsNullOrWhiteSpace(settings.DataModelNamespace)) { merged.ApplicationInfo.DataModelNamespace = settings.DataModelNamespace; } if (!String.IsNullOrWhiteSpace(settings.SupportedInfrastructureVersion)) { merged.ApplicationInfo.SupportedInfrastructureVersion = settings.SupportedInfrastructureVersion; } return merged; }
/// <summary> /// New instance of the Provider registration service. /// </summary> /// <param name="settings">Application settings associated with the Provider.</param> /// <param name="sessionService">Service associated with Provider sessions.</param> public static IRegistrationService GetProviderRegistrationService( IFrameworkSettings settings, ISessionService sessionService) { IRegistrationService registrationService; switch (settings.EnvironmentType) { case EnvironmentType.BROKERED: registrationService = new RegistrationService(settings, sessionService); break; case EnvironmentType.DIRECT: registrationService = new NoRegistrationService(); break; default: throw new ConfigurationErrorsException("Environment Type (BROKERED or DIRECT) is not defined."); } return(registrationService); }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); IFrameworkSettings settings = GetSettings(); // URL Postfix Extension: Update the configuration to recognise postfix extensions and map known // extensions to MIME Types. Additional changes to WebApiConfig.cs are required to fully enable this // feature. GlobalConfiguration.Configuration.Formatters.JsonFormatter .AddUriPathExtensionMapping("json", "application/json"); GlobalConfiguration.Configuration.Formatters.XmlFormatter.AddUriPathExtensionMapping("xml", "text/xml"); // XML Serialisation: Define the specific XML serialiser to use to ensure that SIF Data Model Objects (as // defined by the SIF Specification with XML Schema Definitions (XSDs)) are serialised correctly. XmlMediaTypeFormatter xmlFormatter = GlobalConfiguration.Configuration.Formatters.XmlFormatter; xmlFormatter.UseXmlSerializer = true; // XML Serialisation: For each SIF Data Model Object used by each SIF Provider, the following entries are // required to define the root element for each collection object. var schoolInfosXmlRootAttribute = new XmlRootAttribute("SchoolInfos") { Namespace = settings.DataModelNamespace, IsNullable = false }; ISerialiser <List <SchoolInfo> > schoolInfosSerialiser = SerialiserFactory.GetXmlSerialiser <List <SchoolInfo> >(schoolInfosXmlRootAttribute); xmlFormatter.SetSerializer <List <SchoolInfo> >((XmlSerializer)schoolInfosSerialiser); var studentPersonalsXmlRootAttribute = new XmlRootAttribute("StudentPersonals") { Namespace = settings.DataModelNamespace, IsNullable = false }; ISerialiser <List <StudentPersonal> > studentPersonalsSerialiser = SerialiserFactory.GetXmlSerialiser <List <StudentPersonal> >(studentPersonalsXmlRootAttribute); xmlFormatter.SetSerializer <List <StudentPersonal> >((XmlSerializer)studentPersonalsSerialiser); var studentSchoolEnrollmentsXmlRootAttribute = new XmlRootAttribute("StudentSchoolEnrollments") { Namespace = settings.DataModelNamespace, IsNullable = false }; ISerialiser <List <StudentSchoolEnrollment> > studentSchoolEnrollmentsSerialiser = SerialiserFactory.GetXmlSerialiser <List <StudentSchoolEnrollment> >( studentSchoolEnrollmentsXmlRootAttribute); xmlFormatter.SetSerializer <List <StudentSchoolEnrollment> >( (XmlSerializer)studentSchoolEnrollmentsSerialiser); // Replacement custom JSON formatter (compliant with Goessner notation). var xmlToJsonFormatter = new XmlToJsonFormatter { UseXmlSerializer = true }; xmlToJsonFormatter.AddUriPathExtensionMapping("json", "application/json"); xmlToJsonFormatter.SetSerializer <List <SchoolInfo> >((XmlSerializer)schoolInfosSerialiser); xmlToJsonFormatter.SetSerializer <List <StudentPersonal> >((XmlSerializer)studentPersonalsSerialiser); xmlToJsonFormatter.SetSerializer <List <StudentSchoolEnrollment> >( (XmlSerializer)studentSchoolEnrollmentsSerialiser); GlobalConfiguration.Configuration.Formatters.Add(xmlToJsonFormatter); GlobalConfiguration.Configuration.Formatters.Remove( GlobalConfiguration.Configuration.Formatters.JsonFormatter); // Alternative 1. //var xmlRootAttribute = new XmlRootAttribute("StudentPersonals") //{ Namespace = settings.DataModelNamespace, IsNullable = false }; //xmlFormatter.SetSerializer<List<StudentPersonal>>( // new XmlSerializer(typeof(List<StudentPersonal>), xmlRootAttribute)); // Alternative 2. //var attributes = new XmlAttributes(); //attributes.XmlRoot = new XmlRootAttribute("StudentPersonals") //{ Namespace = settings.DataModelNamespace, IsNullable = false }; //var overrides = new XmlAttributeOverrides(); //overrides.Add(typeof(List<StudentPersonal>), attributes); //xmlFormatter // .SetSerializer<List<StudentPersonal>>(new XmlSerializer(typeof(List<StudentPersonal>), overrides)); // Configure global exception loggers for unexpected errors. GlobalConfiguration.Configuration.Services.Add(typeof(IExceptionLogger), new TraceExceptionLogger()); // Configure a global exception handler for unexpected errors. GlobalConfiguration.Configuration.Services .Replace(typeof(IExceptionHandler), new GlobalUnexpectedExceptionHandler()); Trace.TraceInformation("********** Application_Start **********"); Register(settings); }
public BrokeredAuthenticationService() { settings = SettingsManager.ProviderSettings; sessionService = SessionsManager.ProviderSessionService; }
/// <summary> /// Create an instance using the appropriate settings and service. /// </summary> /// <param name="settings">Framework settings.</param> /// <param name="sessionService">Service used for managing sessions.</param> public RegistrationService(IFrameworkSettings settings, ISessionService sessionService) { this.settings = settings; this.sessionService = sessionService; Registered = false; }
/// <summary> /// Combine the passed in environment object with the equivalent properties defined in the framework settings /// (if present). Properties that already exist in the passed in the environment take precedence over the /// properties defined in the framework settings. /// </summary> /// <param name="environment">Environment object to check.</param> /// <param name="settings">Framework settings.</param> /// <returns>Environment object with merged properties.</returns> internal static Environment MergeWithSettings(Environment environment, IFrameworkSettings settings) { Environment merged; if (environment == null) { merged = new Environment(); } else { merged = environment; } if (merged.ApplicationInfo == null) { merged.ApplicationInfo = new ApplicationInfo(); } if (String.IsNullOrWhiteSpace(merged.ApplicationInfo.ApplicationKey) && settings.ApplicationKey != null) { merged.ApplicationInfo.ApplicationKey = settings.ApplicationKey; } if (String.IsNullOrWhiteSpace(merged.ApplicationInfo.ApplicationKey)) { throw new ArgumentException("An applicationKey must either be provided or defined in the Consumer Environment template.", "applicationKey"); } if (String.IsNullOrWhiteSpace(merged.AuthenticationMethod) && settings.AuthenticationMethod != null) { merged.AuthenticationMethod = settings.AuthenticationMethod; } if (String.IsNullOrWhiteSpace(merged.ConsumerName) && settings.ConsumerName != null) { merged.ConsumerName = settings.ConsumerName; } if (String.IsNullOrWhiteSpace(merged.ApplicationInfo.DataModelNamespace) && settings.DataModelNamespace != null) { merged.ApplicationInfo.DataModelNamespace = settings.DataModelNamespace; } if (String.IsNullOrWhiteSpace(merged.ApplicationInfo.SupportedInfrastructureVersion) && settings.SupportedInfrastructureVersion != null) { merged.ApplicationInfo.SupportedInfrastructureVersion = settings.SupportedInfrastructureVersion; } return merged; }