示例#1
0
        /// <summary>
        /// Add Noty based toast notification services
        /// </summary>
        /// <param name="mvcBuilder"></param>
        /// <param name="defaultOptions"></param>
        /// <param name="nToastNotifyOptions"></param>
        /// <returns></returns>
        public static IMvcCoreBuilder AddNToastNotifyToastr(this IMvcCoreBuilder mvcBuilder, ToastrOptions defaultOptions = null,
                                                            NToastNotifyOption nToastNotifyOptions = null)
        {
            nToastNotifyOptions = nToastNotifyOptions ?? new NToastNotifyOption();
            var library = Utils.GetLibraryDetails <ToastrLibrary>(nToastNotifyOptions, defaultOptions);

            return(mvcBuilder.AddNToastNotifyToMvcBuilder <ToastrNotification>(library, nToastNotifyOptions));
        }
        /// <summary>
        /// Add Noty based toast notification services
        /// </summary>
        /// <param name="mvcBuilder"></param>
        /// <param name="defaultOptions"></param>
        /// <param name="nToastNotifyOptions"></param>
        /// <returns></returns>
        public static IMvcBuilder AddNToastNotifyNoty(this IMvcBuilder mvcBuilder,
                                                      NotyOptions defaultOptions             = null,
                                                      NToastNotifyOption nToastNotifyOptions = null)
        {
            nToastNotifyOptions ??= new NToastNotifyOption();
            var library = Utils.GetLibraryDetails <NotyLibrary>(nToastNotifyOptions, defaultOptions);

            return(mvcBuilder.AddNToastNotifyToMvcBuilder <NotyNotification>(library, nToastNotifyOptions));
        }
示例#3
0
        public void ShouldCopyScriptSrc(string scriptSrc, string expected)
        {
            //Arrange
            var nToastNotifyOption = new NToastNotifyOption
            {
                ScriptSrc = scriptSrc
            };

            //Act
            var result = Utils.GetLibraryDetails <ToastrLibrary>(nToastNotifyOption, null);

            //Assert
            Assert.Equal(expected, result.ScriptSrc);
        }
示例#4
0
        public void ShouldCopyStyleHref(string styleHref, string expected)
        {
            //Arrange
            var nToastNotifyOption = new NToastNotifyOption
            {
                StyleHref = styleHref
            };

            //Act
            var result = Utils.GetLibraryDetails <ToastrLibrary>(nToastNotifyOption, null);

            //Assert
            Assert.Equal(expected, result.StyleHref);
        }
示例#5
0
        public static ILibrary GetLibraryDetails <T>(NToastNotifyOption nToastNotifyOptions, ILibraryOptions defaultOptions) where T : class, ILibrary, new()
        {
            var library = new T();

            if (nToastNotifyOptions != null)
            {
                if (!string.IsNullOrWhiteSpace(nToastNotifyOptions.ScriptSrc))
                {
                    library.ScriptSrc = nToastNotifyOptions.ScriptSrc;
                }
                if (!string.IsNullOrWhiteSpace(nToastNotifyOptions.StyleHref))
                {
                    library.StyleHref = nToastNotifyOptions.StyleHref;
                }
            }

            if (defaultOptions != null)
            {
                library.Options = defaultOptions;
            }
            return(library);
        }
示例#6
0
 public MessageContainerFactory(IHttpContextAccessor httpContextAccessor, ITempDataWrapper tempDataWrapper, NToastNotifyOption nToastNotifyOption)
 {
     _httpContextAccessor = httpContextAccessor;
     _tempDataWrapper     = tempDataWrapper;
     _nToastNotifyOption  = nToastNotifyOption;
 }
示例#7
0
 public ToastViewComponent(IToastNotification toastNotification, ILibraryOptions globalOption, NToastNotifyOption nToastNotifyOption, IFileProvider fileProvider)
 {
     _toastNotification  = toastNotification;
     _globalOption       = globalOption;
     _nToastNotifyOption = nToastNotifyOption;
 }
示例#8
0
        internal static IServiceCollection AddNToastNotifyToServiceCollection <TLibrary, TOption, TMessage, TNotificationImplementation>(this IServiceCollection services, TOption defaultLibOptions,
                                                                                                                                         NToastNotifyOption nToastNotifyOptions = null)
            where TLibrary : class, ILibrary <TOption>, new()
            where TOption : class, ILibraryOptions
            where TMessage : class, IToastMessage
            where TNotificationImplementation : class, IToastNotification
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }


            //Add the file provider to the Razor view engine
            var fileProvider = Utils.GetEmbeddedFileProvider();

            services.Configure <RazorViewEngineOptions>(options =>
            {
                options.FileProviders.Add(fileProvider);
            });
            services.AddSingleton <IFileProvider>(fileProvider);

            //Check if a TempDataProvider is already registered.
            var tempDataProvider = services.FirstOrDefault(d => d.ServiceType == typeof(ITempDataProvider));

            if (tempDataProvider == null)
            {
                //Add a tempdata provider when one is not already registered
                services.AddSingleton <ITempDataProvider, CookieTempDataProvider>();
            }

            //Add TempDataWrapper for accessing and adding values to tempdata.
            services.AddSingleton <ITempDataWrapper, TempDataWrapper>();

            //check if IHttpContextAccessor implementation is not registered. Add one if not.
            var httpContextAccessor = services.FirstOrDefault(d => d.ServiceType == typeof(IHttpContextAccessor));

            if (httpContextAccessor == null)
            {
                services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            }

            var library = new TLibrary();

            // Add the toast library default options that will be rendered by the viewcomponent
            services.AddSingleton <ILibraryOptions>(defaultLibOptions ?? library.Defaults);

            // Add the NToastifyOptions to the services container for DI retrieval
            //(options that are not rendered as they are not part of the plugin)
            nToastNotifyOptions = nToastNotifyOptions ?? new NToastNotifyOption();
            nToastNotifyOptions.LibraryDetails = library;
            services.AddSingleton(nToastNotifyOptions);
            services.AddSingleton <IMessageContainerFactory, MessageContainerFactory>();
            //Add the ToastNotification implementation
            services.AddScoped <IToastNotification, TNotificationImplementation>();
            services.AddScoped <NtoastNotifyMiddleware>();
            return(services);
        }
示例#9
0
        internal static IMvcCoreBuilder AddNToastNotifyToMvcBuilder <TLibrary, TOption, TMessage, TNotificationImplementation>(this IMvcCoreBuilder mvcCoreBuilder,
                                                                                                                               TOption defaultLibOptions,
                                                                                                                               NToastNotifyOption nToastNotifyOptions = null)
            where TLibrary : class, ILibrary <TOption>, new()
            where TOption : class, ILibraryOptions
            where TMessage : class, IToastMessage
            where TNotificationImplementation : class, IToastNotification
        {
            //This is a fix for Feature folders based project structure. Add the view location to ViewLocationExpanders.
            mvcCoreBuilder?.AddRazorViewEngine(o =>
            {
                o.ViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
            });

            var services = mvcCoreBuilder.Services;

            AddNToastNotifyToServiceCollection <TLibrary, TOption, TMessage, TNotificationImplementation>(services, defaultLibOptions, nToastNotifyOptions);
            return(mvcCoreBuilder);
        }
示例#10
0
 public static IMvcBuilder AddNToastNotify(this IMvcBuilder mvcBuilder, ToastrOptions defaultOptions = null, NToastNotifyOption nToastNotifyOptions = null)
 {
     return(AddNToastNotifyToMvcBuilder <ToastrLibrary, ToastrOptions, ToastrMessage, ToastrNotification>(mvcBuilder, defaultOptions, nToastNotifyOptions));
 }
 public NotyNotification(IMessageContainerFactory messageContainerFactory, NToastNotifyOption nToastNotifyOptions) : base(messageContainerFactory)
 {
     _defaultNtoastNotifyOptions = nToastNotifyOptions;
 }
示例#12
0
 public ToastrViewComponent(IToastNotification toastNotification, ToastOption globalOption, NToastNotifyOption nToastNotifyOption)
 {
     _toastNotification  = toastNotification;
     _globalOption       = globalOption;
     _nToastNotifyOption = nToastNotifyOption;
 }
 /// <summary>
 /// Add Noty based toast notification services
 /// </summary>
 /// <param name="mvcBuilder"></param>
 /// <param name="defaultOptions"></param>
 /// <param name="nToastNotifyOptions"></param>
 /// <returns></returns>
 public static IMvcCoreBuilder AddNToastNotifyToastr(this IMvcCoreBuilder mvcBuilder, ToastrOptions defaultOptions = null,
                                                     NToastNotifyOption nToastNotifyOptions = null)
 {
     return(mvcBuilder.AddNToastNotifyToMvcBuilder <ToastrLibrary, ToastrOptions, ToastrMessage, ToastrNotification>(defaultOptions ?? new ToastrOptions(), nToastNotifyOptions));
 }
示例#14
0
        internal static IServiceCollection AddNToastNotifyToServiceCollection <TNotificationImplementation>(this IServiceCollection services,
                                                                                                            ILibrary library,
                                                                                                            NToastNotifyOption nToastNotifyOptions)
            where TNotificationImplementation : class, IToastNotification
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            #region Framework Services
            //Check if a TempDataProvider is already registered.
            var tempDataProvider = services.FirstOrDefault(d => d.ServiceType == typeof(ITempDataProvider));
            if (tempDataProvider == null)
            {
                //Add a tempdata provider when one is not already registered
                services.AddSingleton <ITempDataProvider, CookieTempDataProvider>();
            }
            //check if IHttpContextAccessor implementation is not registered. Add one if not.
            var httpContextAccessor = services.FirstOrDefault(d => d.ServiceType == typeof(IHttpContextAccessor));
            if (httpContextAccessor == null)
            {
                services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            }

            #endregion

            #region Custom Services
            //Add TempDataWrapper for accessing and adding values to tempdata.
            services.AddSingleton <ITempDataWrapper, TempDataWrapper>();
            // Add MessageContainerFactory for creating MessageContainer instance
            services.AddSingleton <IMessageContainerFactory, MessageContainerFactory>();

            //Add the ToastNotification implementation
            services.AddScoped <IToastNotification, TNotificationImplementation>();
            //Middleware
            services.AddScoped <NtoastNotifyAjaxToastsMiddleware>();

            //Addes instances
            services.AddSingleton(library);
            // Add the NToastifyOptions to the services container for DI retrieval
            //(options that are not rendered as they are not part of the plugin)
            services.AddSingleton(nToastNotifyOptions);

            #endregion

            return(services);
        }
示例#15
0
        internal static IMvcCoreBuilder AddNToastNotifyToMvcBuilder <TNotificationImplementation>(this IMvcCoreBuilder mvcCoreBuilder,
                                                                                                  ILibrary library,
                                                                                                  NToastNotifyOption nToastNotifyOptions)
            where TNotificationImplementation : class, IToastNotification
        {
            if (mvcCoreBuilder == null)
            {
                return(null);
            }

            //This is a fix for Feature folders based project structure. Add the view location to ViewLocationExpanders.
            mvcCoreBuilder.AddRazorViewEngine(o =>
            {
                o.ViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
            });

            var services = mvcCoreBuilder.Services;

            AddNToastNotifyToServiceCollection <TNotificationImplementation>(services, library, nToastNotifyOptions);
            return(mvcCoreBuilder);
        }
 /// <summary>
 /// Add Noty based toast notification services
 /// </summary>
 /// <param name="mvcBuilder"></param>
 /// <param name="defaultOptions"></param>
 /// <param name="nToastNotifyOptions"></param>
 /// <returns></returns>
 public static IMvcCoreBuilder AddNToastNotifyNoty(this IMvcCoreBuilder mvcBuilder, NotyOptions defaultOptions = null,
                                                   NToastNotifyOption nToastNotifyOptions = null)
 {
     return(mvcBuilder.AddNToastNotifyToMvcBuilder <NotyLibrary, NotyOptions, NotyMessage, NotyNotification>(defaultOptions ?? new NotyOptions(), nToastNotifyOptions));
 }
示例#17
0
 public static IServiceCollection AddNToastNotify(this IServiceCollection services, ToastrOptions defaultOptions = null, NToastNotifyOption nToastNotifyOptions = null, IMvcBuilder mvcBuilder = null)
 {
     return(services);
 }