Example #1
0
        /// <summary>
        /// Configure the repository manager to use InMemory repositories
        /// </summary>
        /// <param name="builder">Application builder</param>
        /// <param name="filesLocation">The direction that the files are stored in.</param>
        /// <param name="repositoriesAssembly">The name of the assembly containing the repositories
        /// <remarks>The assembly name should not contain the extension.</remarks></param>
        /// <param name="config">The configuration object to be passed to the repositories</param>
        /// <returns>Application builder</returns>
        public static T UseFileRepositories <T>(this T builder, string filesLocation, string repositoriesAssembly,
                                                RepositoryConfigurations config = null) where T : IApplicationBuilder
        {
            builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.InMemoryRepositoryBuildAction((container) =>
            {
                if (!container.IsRegistered <IRepositoryManager>())
                {
                    throw new ApplicationBuildException("RepositoryManager is not registered. call UseSingletonRepositoryManager or UseTransientRepositoryManager to configuration the repository manager.");
                }

                var repositoryManager = container.Resolve <IRepositoryManager>();

                repositoryManager.AddRepositoryInitializer(new FileRepositoryInitializer(filesLocation, container.Resolve <IObjectMapper>(), config));
                repositoryManager.RegisterRepositories(repositoriesAssembly);

                var logger = container.Resolve <ILogger>();
                container.RegisterInstance <IRepositoryManager>(repositoryManager);

                foreach (var repository in repositoryManager.GetRepositories())
                {
                    logger.Log(EventsSource,
                               $"Registering repository of type {repository.GetType().Name}",
                               LogRecordTypes.Debug);
                    container.RegisterInstance(repository.ImplementedInterface, repository);
                }
            }));
            return(builder);
        }
Example #2
0
 /// <summary>
 /// Initialize <see cref="ILocalizationManager"/> service.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="resourceManagerFullPath">Resource files location <remarks>example "HR.Clients.WPF.Properties.Resources"</remarks></param>
 /// <param name="resourceManagerAssembly">The name of the assembly containing the resources <remarks>Example "HR.Clients.WPF.exe"</remarks></param>
 /// <param name="supportedCultures">The available cultures in the resource files <remarks>Example new[] {"ar-SY", "en-US"}</remarks></param>
 /// <param name="defaultCluture">The default culture used in the application <remarks>Example "en-US"</remarks></param>
 /// <returns></returns>
 public static IApplicationBuilder UseLocalization(
     this IApplicationBuilder builder,
     string resourceManagerFullPath,
     string resourceManagerAssembly,
     string[] supportedCultures,
     string defaultCluture = "en-US")
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.LocalizationBuildAction((container) =>
     {
         var localizationManager = container.Resolve <ILocalizationManager>();
         localizationManager.SetCulture(defaultCluture);
         var values = new Dictionary <string, Dictionary <string, string> >();
         var res    = new ResourceManager(resourceManagerFullPath,
                                          Assembly.LoadFrom(Path.Combine(AppDomain.CurrentDomain
                                                                         .BaseDirectory,
                                                                         resourceManagerAssembly)));
         foreach (var culture in supportedCultures)
         {
             foreach (DictionaryEntry val in
                      res.GetResourceSet(new CultureInfo(culture), true, true))
             {
                 if (!values.ContainsKey(val.Key.ToString()))
                 {
                     values[val.Key.ToString()] = new Dictionary <string, string>();
                 }
                 values[val.Key.ToString()][culture] = val.Value.ToString();
             }
         }
         localizationManager.AddValues(values);
     }));
     return(builder);
 }
Example #3
0
        /// <summary>
        /// Sets a default shell for the WPF application
        /// </summary>
        /// <returns></returns>
        public static IApplicationBuilder UseNavigation(
            this IApplicationBuilder builder,
            params INavigationItem[] navigationItems)
        {
            builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.NavigationBuildAction((container) =>
            {
                var navs = new List <INavigationItem>();
                var nav  = container.Resolve <INavigationService>();
                var gud  = container.Resolve <IGlobalVariablesService>().GetVariable <UsingDefaultShellGlobalVariable>();
                if (gud.IsValueSet && gud.GetValue())
                {
                    var homeNav = new NavigationItem(container.Resolve <IDefaultShellViewModel>().GetMainContent(),
                                                     "Home",
                                                     "M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z");
                    DefaultNavigations.Home = homeNav;

                    navs.Add(homeNav);
                    navs.AddRange(navigationItems);

                    nav.Initialize(DefaultRegions.NavbarRegion,
                                   DefaultRegions.ApplicationMainRegion,
                                   navs);
                }
                else
                {
                    navs.AddRange(navigationItems);
                    nav.Initialize(DefaultRegions.NavbarRegion,
                                   DefaultRegions.ApplicationMainRegion,
                                   navs);
                }
            }));
            return(builder);
        }
Example #4
0
        /// <summary>
        /// Adds MogonRepositories to the repository manager
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="connection">The database connection string</param>
        /// <param name="databaseName">The database name</param>
        /// <param name="repositoriesAssembly">The assembly that contains the repositories</param>
        /// <param name="registerTheRepositoresInContainer">If set to true the repositories will be registered in the dependency container.</param>
        /// <returns></returns>
        public static IApplicationBuilder UseMongoDBRepositories(
            this IApplicationBuilder builder,
            string connection,
            string databaseName,
            string repositoriesAssembly,
            bool registerTheRepositoresInContainer)
        {
            builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.MongoRepositoryBuildAction((container) =>
            {
                if (!container.IsRegistered <IRepositoryManager>())
                {
                    throw new ApplicationBuildException("RepositoryManager is not registered. call UseSingletonRepositoryManager or UseTransientRepositoryManager to configuration the repository manager.");
                }

                var repositoryManager = container.Resolve <IRepositoryManager>();

                repositoryManager.AddRepositoryInitializer(new  MongoRepositoryInitializer(new MongoDBManager(connection, databaseName), container.Resolve <IObjectMapper>()));
                repositoryManager.RegisterRepositories(repositoriesAssembly);

                var logger = container.Resolve <ILogger>();
                container.RegisterInstance <IRepositoryManager>(repositoryManager);
                if (registerTheRepositoresInContainer)
                {
                    foreach (var repository in repositoryManager.GetRepositories())
                    {
                        logger.Log(EventsSource,
                                   $"Registering repository of type {repository.GetType().Name}",
                                   LogRecordTypes.Debug);
                        container.RegisterInstance(repository.ImplementedInterface, repository);
                    }
                }
            }));
            return(builder);
        }
Example #5
0
 /// <summary>
 /// Set the default global variables values.
 /// </summary>
 protected void ConfigureGlobalVariables()
 {
     BuildActionsCoordinator.AddAction(DefaultBuildActions.ConfigureGlobalVariablesBuildAction(container =>
     {
         _container.Resolve <IGlobalVariablesService>().GetVariable <ApplicationNameGlobalVariable>().SetValue(_app.ApplicationName);
     }));
 }
Example #6
0
 /// <summary>
 /// Use the IL object mapper
 /// </summary>
 public static IApplicationBuilder UseILMapper(this IApplicationBuilder builder)
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.MapperBuildAction((container) =>
     {
         container.RegisterInstance <IObjectMapper, ILObjectsMapper>();
     }));
     return(builder);
 }
Example #7
0
 /// <summary>
 /// Sets the application theme colors
 /// </summary>
 /// <returns></returns>
 public static IApplicationBuilder UseTheme(this IApplicationBuilder builder, ApplicationColors colors)
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.ApplicationThemeAction((container) =>
     {
         ApplicationTheme.SetTheme(colors);
     }));
     return(builder);
 }
Example #8
0
 /// <summary>
 /// Set the application entry point
 /// </summary>
 /// <param name="builder"></param>
 /// <typeparam name="T">The class containing the entry point</typeparam>
 /// <returns></returns>
 public static IApplicationBuilder UseMain <T>(this IApplicationBuilder builder) where T : IEntryPointClass
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.ConsoleMainBuildAction((container) =>
     {
         container.Resolve <T>().Start(container);
     }));
     return(builder);
 }
Example #9
0
 /// <summary>
 /// Use the basic object mapper
 /// </summary>
 public static TBuilder UseBasicMapper <TBuilder>(this TBuilder builder) where TBuilder : IApplicationBuilder
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.MapperBuildAction((container) =>
     {
         container.RegisterInstance <IObjectMapper, BasicObjectMapper>();
     }));
     return(builder);
 }
Example #10
0
 /// <summary>
 /// Configure the application to use a <see cref="TransientRepositoryManager"/> that returns the a new repository instance on each call.
 /// </summary>
 public static T UseTransientRepositoryManager <T>(this T builder) where T : IApplicationBuilder
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.RepositoryManagerBuildAction((container) =>
     {
         container.RegisterInstance <IRepositoryManager, TransientRepositoryManager>();
     }));
     return(builder);
 }
Example #11
0
 /// <summary>
 /// Sets the minimum log level to show to the user
 /// </summary>
 /// <returns></returns>
 public static IApplicationBuilder UseLogger(this IApplicationBuilder builder,
                                             LoggerOptions options)
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.LoggerBuildAction((container) =>
     {
         BuilderHelper.RegisterLoggers(options, container);
     }));
     return(builder);
 }
Example #12
0
 /// <summary>
 /// Initialize the configuration manager
 /// </summary>
 public static IApplicationBuilder UseConfigurationFile(
     this IApplicationBuilder builder,
     string fileLocation)
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.ConfigFileBuildAction((container) =>
     {
         var config = container.Resolve <IConfigurationManager>();
         config.Initialize(fileLocation, new ConfigurationFile("config", Path.Combine(fileLocation, "config.cfg")));
     }));
     return(builder);
 }
Example #13
0
 /// <summary>
 /// Use Dialog service
 /// </summary>
 /// <returns></returns>
 public static IApplicationBuilder UseDialogs(this IApplicationBuilder builder,
                                              Region dialogRegion)
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.DialogServiceBuildAction(
                                                   (container) =>
     {
         container.Resolve <IDialogService>().Initialize(dialogRegion);
         container.Resolve <IDialogExplorer>().Initialize();
     }));
     return(builder);
 }
Example #14
0
 /// <summary>
 /// Configure the <see cref="ILocalizationManager"/> service.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="defaultCluture"></param>
 /// <returns></returns>
 public static IApplicationBuilder UseLocalization(
     this IApplicationBuilder builder,
     string defaultCluture = "en-US")
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.LocalizationBuildAction((container) =>
     {
         var localizationManager = container.Resolve <ILocalizationManager>();
         localizationManager.SetCulture(defaultCluture);
     }));
     return(builder);
 }
Example #15
0
 /// <summary>
 /// Initialize the configuration manager
 /// </summary>
 /// <param name="builder">the application builder.</param>
 /// <param name="fileLocation"></param>
 /// <param name="defaultFile">The default configurations file.</param>
 public static IApplicationBuilder UseConfigurationFile(
     this IApplicationBuilder builder,
     string fileLocation,
     IConfigurationFile defaultFile = null)
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.ConfigFileBuildAction((container) =>
     {
         var config = container.Resolve <IConfigurationManager>();
         config.Initialize(fileLocation, defaultFile);
     }));
     return(builder);
 }
Example #16
0
 /// <summary>
 /// Sets the application MainNavigationPage
 /// </summary>
 public static IXamarinApplicationBuilder UseNavigationMainPage <TMain>(
     this IXamarinApplicationBuilder builder)
     where TMain : IPresentableViewModel
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.MainPageAction((container) =>
     {
         var app      = Application.Current;
         var main     = container.Resolve <TMain>();
         app.MainPage = new NavigationPage((Page)main.GetView());
         main.Initialize();
     }));
     return(builder);
 }
Example #17
0
 /// <summary>
 /// Sets a custom shell for the WPF application
 /// </summary>
 /// <returns></returns>
 public static IApplicationBuilder UseCustomShellWithLogin <TShellViewModel, TLogin>(this IApplicationBuilder builder,
                                                                                     Action <Window> config = null)
     where TShellViewModel : IShellViewModel
     where TLogin : ILoginViewModel
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.ShellBuildAction((container) =>
     {
         var wpfApplication = container.Resolve <WPFApplication>();
         var shellViewModel = BuildCustomShell <TShellViewModel>(config, container);
         var loginViewModel = container.Resolve <TLogin>();
         BuildLogin(container, wpfApplication, shellViewModel, loginViewModel);
     }));
     return(builder);
 }
Example #18
0
 /// <summary>
 /// Sets a custom shell for the WPF application
 /// </summary>
 /// <typeparam name="TShellViewModel"></typeparam>
 /// <returns></returns>
 public static IApplicationBuilder UseCustomShell <TShellViewModel>(this IApplicationBuilder builder,
                                                                    Action <Window> config = null)
     where TShellViewModel : IShellViewModel
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.ShellBuildAction((container) =>
     {
         var wpfApplication = container.Resolve <WPFApplication>();
         var shellViewModel = BuildCustomShell <TShellViewModel>(config, container);
         shellViewModel.Initialize().ContinueWith((t) =>
         {
             container.Resolve <IEventDispatcher>().GetEvent <ApplicationStartedEvent>().Raise(wpfApplication);
         });
         wpfApplication.ShowWindow();
     }));
     return(builder);
 }
Example #19
0
 /// <summary>
 /// Sets a default shell for the WPF application
 /// </summary>
 /// <typeparam name="TContent">The main content type to be shown on startup</typeparam>
 /// <typeparam name="TLogin"></typeparam>
 /// <returns></returns>
 public static IApplicationBuilder UseDefaultShellWithLogin <TContent, TLogin>(
     this IApplicationBuilder builder,
     WindowState state      = WindowState.Maximized,
     Action <Window> config = null)
     where TContent : IPresentable
     where TLogin : ILoginViewModel
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.ShellBuildAction((container) =>
     {
         var wpfApplication = container.Resolve <WPFApplication>();
         var shellViewModel = BuildDefaultShell <TContent>(builder, state, config, container);
         var loginViewModel = container.Resolve <TLogin>();
         BuildLogin(container, wpfApplication, shellViewModel, loginViewModel);
     }));
     return(builder);
 }
Example #20
0
 /// <summary>
 /// Register LinQ repositories and adds a <see cref="LinqRepositoryInitializer"/> to the <see cref="IRepositoryManager"/>
 /// </summary>
 public static IApplicationBuilder UseLinqRepositories <TDBManager>(
     this IApplicationBuilder builder,
     LinqInitializerConfig config)
     where TDBManager : ILinqDBManager, new()
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.LinqRepositoryBuildAction((container) =>
     {
         var connectionString = config.DatabaseConnection(container);
         if (string.IsNullOrEmpty(connectionString))
         {
             config.ConnectionStringNotFound?.Invoke();
             return;
         }
         CreateRepositoryManager <TDBManager>(container, connectionString, config.RepositoriesAssembly, config.RepositoryConfigurations);
     }));
     return(builder);
 }
Example #21
0
 /// <summary>
 /// Add additional modules to the application.
 /// </summary>
 /// <param name="buillder"></param>
 /// <param name="modulesAssemblies">The names of the assemblies containing the modules.</param>
 /// <returns></returns>
 public static IApplicationBuilder UseModules(this IApplicationBuilder buillder, string assemblyLocation, params string[] modulesAssemblies)
 {
     buillder.BuildActionsCoordinator.AddAction(DefaultBuildActions.DiscoverModulesBuildAction(
                                                    container =>
     {
         var _modulesManager = container.Resolve <IWindowsApplicationModulesManager>();
         if (modulesAssemblies != null)
         {
             foreach (var assembly in modulesAssemblies)
             {
                 _modulesManager.RegisterModule(_modulesManager.DescoverModulesFromAssambles(assemblyLocation, assembly).ToArray());
             }
         }
         _modulesManager.InitializeAutoModules().GetAwaiter().GetResult();
     }));
     return(buillder);
 }
Example #22
0
 /// <summary>
 /// Sets a default shell for the WPF application
 /// </summary>
 /// <typeparam name="TContent">The main content type to be shown on startup</typeparam>
 /// <returns></returns>
 public static IApplicationBuilder UseDefaultShell <TContent>(
     this IApplicationBuilder builder,
     WindowState state      = WindowState.Maximized,
     Action <Window> config = null)
     where TContent : IPresentable
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.ShellBuildAction((container) =>
     {
         var wpfApplication = container.Resolve <WPFApplication>();
         var shellViewModel = BuildDefaultShell <TContent>(builder, state, config, container);
         shellViewModel.Initialize().ContinueWith((t) =>
         {
             container.Resolve <IEventDispatcher>().GetEvent <ApplicationStartedEvent>().Raise(wpfApplication);
         });
         wpfApplication.ShowWindow();
     }));
     return(builder);
 }
Example #23
0
        /// <summary>
        /// Add a console to the application
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="toggleCondition">A function that is executed on the shell KeyDown event show return true to toggle the console</param>
        /// <returns></returns>
        public static IApplicationBuilder UseCoddeeDebugTool(this IApplicationBuilder builder,
                                                             Func <KeyEventArgs, bool> toggleCondition)
        {
            builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.DebugToolBuildAction(async(container) =>
            {
                var shell = container.Resolve <IShell>();
                if (shell == null)
                {
                    throw new
                    ApplicationBuildException("The method must be called after the UseShell method");
                }
                var debugTool = container.Resolve <IDebugTool>();

                await debugTool.Initialize();

                debugTool.SetToggleCondition(toggleCondition);
            }));
            return(builder);
        }
        /// <summary>
        /// Register REST repositories and adds a <see cref="RESTRepositoryInitializer"/> to the <see cref="IRepositoryManager"/>
        /// </summary>
        public static TBuilder UseRESTRepositories <TBuilder>(
            this TBuilder builder,
            Func <IContainer, RESTInitializerConfig> config)
            where TBuilder : IApplicationBuilder
        {
            builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.RESTRepositoryBuildAction((container) =>
            {
                if (!container.IsRegistered <IRepositoryManager>())
                {
                    throw new ApplicationBuildException("RepositoryManager is not registered. call UseSingletonRepositoryManager or UseTransientRepositoryManager to configuration the repository manager.");
                }

                var repositoryManager = container.Resolve <IRepositoryManager>();

                var configRes = config(container);
                repositoryManager.AddRepositoryInitializer(new RESTRepositoryInitializer(configRes.ApiUrl, configRes.UnauthorizedRequestHandler, container.Resolve <IObjectMapper>()));

                if (!string.IsNullOrEmpty(configRes.RepositoriesAssembly))
                {
                    repositoryManager.RegisterRepositories(configRes.RepositoriesAssembly);
                }
                if (configRes.RepositoriesTypes != null)
                {
                    repositoryManager.RegisterRepositories(configRes.RepositoriesTypes);
                }

                var logger = container.Resolve <ILogger>();
                container.RegisterInstance <IRepositoryManager>(repositoryManager);
                if (configRes.RegisterTheRepositoresInContainer)
                {
                    foreach (var repository in repositoryManager.GetRepositories())
                    {
                        logger.Log(EventsSource,
                                   $"Registering repository of type {repository.GetType().Name}",
                                   LogRecordTypes.Debug);
                        container.RegisterInstance(repository.ImplementedInterface, repository);
                    }
                }
            }));
            return(builder);
        }
Example #25
0
        /// <summary>
        /// set the default application build steps.
        /// </summary>
        protected virtual void SetupDefaultBuildActions()
        {
            Log($"Setting up default build actions.");


            BuildActionsCoordinator.AddAction(DefaultBuildActions.RegisterDefaultModulesBuildAction(container =>
            {
                IApplicationModulesManager applicationModulesManager = CreateApplicationModuleManager(container);
                applicationModulesManager.RegisterModule(GetDefaultModules());
                applicationModulesManager.InitializeAutoModules().GetAwaiter().GetResult();
            }));

            if (!BuildActionsCoordinator.BuildActionExists(BuildActionsKeys.ConfigureGlobalVariabls))
            {
                ConfigureGlobalVariables();
            }

            BuildActionsCoordinator.AddAction(DefaultBuildActions.SetupViewModelBaseBuildAction(container =>
            {
                SetupViewModelBase();
            }));
        }
Example #26
0
        /// <summary>
        /// Add a console to the application
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="toggleCondition">A function that is executed on the shell KeyDown event show return true to toggle the console</param>
        /// <returns></returns>
        public static IApplicationBuilder UseApplicationConsole(this IApplicationBuilder builder,
                                                                Func <KeyEventArgs, bool> toggleCondition)
        {
            builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.AppConsoleBuildAction((container) =>
            {
                var shell = (ContentControl)container.Resolve <IShell>();
                if (shell == null)
                {
                    throw new ApplicationBuildException("The method must be called after the UseShell method");
                }

                var applicationConsole = container.Resolve <IApplicationConsole>();
                var logger             = (LogAggregator)container.Resolve <ILogger>();
                applicationConsole.Initialize(shell, logger.MinimumLevel);

                //Add the console logger to loggers collection
                logger.AddLogger(applicationConsole.GetLogger(), LoggerTypes.ApplicationConsole);

                //Sets the Shell KeyDown event handler to toggle the console visibility
                applicationConsole.SetToggleCondition(toggleCondition);
            }));
            return(builder);
        }
Example #27
0
 /// <summary>
 /// Set the application entry point
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="entryPoint">Application main method</param>
 /// <returns></returns>
 public static IApplicationBuilder UseMain(this IApplicationBuilder builder,
                                           Action <IContainer> entryPoint)
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.ConsoleMainBuildAction(entryPoint));
     return(builder);
 }
Example #28
0
 /// <summary>
 /// Set the application entry point
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="entryPoint">The class containing the entry point.</param>
 /// <returns></returns>
 public static IApplicationBuilder UseMain(this IApplicationBuilder builder,
                                           IEntryPointClass entryPoint)
 {
     builder.BuildActionsCoordinator.AddAction(DefaultBuildActions.ConsoleMainBuildAction(entryPoint.Start));
     return(builder);
 }