Esempio n. 1
0
        private void InitialiseProviders(ProviderSettings settings)
        {
            log.Debug("Initialising ProviderFactory (currently only supports Functional Services)");
            // settings.Classes only returns functional services at the moment, but can easily be extended to other types of services.
            foreach (Type type in Classes)
            {
                log.Debug("Provider class to initialse: " + type.FullName);
                try
                {
                    ServiceClassInfo providerClassInfo = new ServiceClassInfo(type, Type.EmptyTypes);

                    if (!providerClassInfo.HasConstructor())
                    {
                        log.Error("The provider class " + type.FullName + " does not have a valid constructor. Must have a public constructor that takes no arguments.");
                        continue;
                    }

                    IFunctionalService provider = providerClassInfo.GetClassInstance() as IFunctionalService;

                    string providerName = provider.GetServiceName();

                    log.Info("Adding provider for '" + providerName + "', using provider class '" + provider.GetType().FullName + "'.");

                    // First add it to the standard request/response dictionary
                    providerClasses[providerName] = providerClassInfo;

                    // Add it to dictionary of providers
                    providers[providerName] = provider;

                    // Add it to dictionary of background threads
                    providerThreads[providerName] = new Thread(new ThreadStart(provider.Startup));
                    // Each thread is essentially a global instance of a service whose responsibility is to maintain the services using timed tasks etc. - it never recieves any REST calls.
                }
                catch (Exception ex)
                {
                    log.Error("Cannot create Provider Class " + type.FullName + ": " + ex.Message, ex);
                }
            }
        }