private void AddRequiredConfiguration()
        {
            var configManagerHelper = new NopConfigManagerHelper();

            // some of third party libaries that we use for WebHooks and Swagger use older versions
            // of certain assemblies so we need to redirect them to the once that nopCommerce uses
            configManagerHelper.AddBindingRedirects();

            // required by the WebHooks support
            configManagerHelper.AddConnectionString();

            var dataSettings = configManagerHelper.DataSettings;

            Microsoft.AspNet.WebHooks.Config.SettingsDictionary settings = new Microsoft.AspNet.WebHooks.Config.SettingsDictionary();
            settings.Add("MS_SqlStoreConnectionString", dataSettings.DataConnectionString);
            settings.Connections.Add("MS_SqlStoreConnectionString", new Microsoft.AspNet.WebHooks.Config.ConnectionSettings("MS_SqlStoreConnectionString", dataSettings.DataConnectionString));

            ILogger logger = new NopWebHooksLogger();

            Microsoft.AspNet.WebHooks.IWebHookStore store = new Microsoft.AspNet.WebHooks.SqlWebHookStore(settings, logger);

            Microsoft.AspNet.WebHooks.Services.CustomServices.SetStore(store);

            // This is required only in development.
            // It it is required only when you want to send a web hook to an https address with an invalid SSL certificate. (self-signed)
            // The code marks all certificates as valid.
            // We may want to extract this as a setting in the future.

            // NOTE: If this code is commented the certificates will be validated.
            System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
        }
        public IWebHookStore GetWebHookStore()
        {
            if (_webHookStore == null)
            {
                var dataSettings = _configManagerHelper.DataSettings;
                Microsoft.AspNet.WebHooks.Config.SettingsDictionary settings = new Microsoft.AspNet.WebHooks.Config.SettingsDictionary();
                settings.Add("MS_SqlStoreConnectionString", dataSettings.DataConnectionString);
                settings.Connections.Add("MS_SqlStoreConnectionString", new Microsoft.AspNet.WebHooks.Config.ConnectionSettings("MS_SqlStoreConnectionString", dataSettings.DataConnectionString));

                Microsoft.AspNet.WebHooks.IWebHookStore store = new Microsoft.AspNet.WebHooks.SqlWebHookStore(settings, _logger);

                Microsoft.AspNet.WebHooks.Services.CustomServices.SetStore(store);

                _webHookStore = CustomServices.GetStore();
            }

            return(_webHookStore);
        }
Пример #3
0
        public static void RegisterMef()
        {
            var container = ConfigureContainer();
            // use MEF for providing instances
            // RegistrationBuilder context = new RegistrationBuilder();

            // Install MEF dependency resolver for Web API
            var dependencyResolver = System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver;

            System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver = new MefDependencyResolver(container);
            //IDependencyScope
            //
            //https://weblog.west-wind.com/posts/2016/Dec/12/Loading-NET-Assemblies-out-of-Seperate-Folders
            Database.SetInitializer <WebHookStoreContext>(null);
            IDataProtector protector = Michal.Balador.Infrastructures.Security.DataSecurity.GetDataProtector(System.Configuration.ConfigurationManager.AppSettings["k"].ToString());
            ILogger        logger    = dependencyResolver.GetLogger();

            Microsoft.AspNet.WebHooks.Config.SettingsDictionary settings = dependencyResolver.GetSettings();

            string nameOrConnectionString = null;
            string schemaName             = null;
            string tableName = null;
            var    store     = new SqlWebHookStore(settings, protector, logger, nameOrConnectionString, schemaName, tableName);

            //it's singleton!!
            container.ComposeExportedValue <IWebHookStore>(store);
            var behaviors = new BehaviorItems <Behavior>();

            behaviors.Add(new ChangeMessageItemBehavior());
            behaviors.Add(new PostMessageItemBehavior());
            container.ComposeExportedValue(behaviors);

            //it's singleton!!
            //     var context = new BaladorContext();
            //  container.ComposeExportedValue<IBaladorContext>(context);
            //  container.ForType(typeof(ApplicationDbContext))
            //.Export(builder => builder.AsContractType(typeof(IUnitOfWork)))
            //.SetCreationPolicy(CreationPolicy.NonShared);
        }