Esempio n. 1
0
        public static ApplicationConfigurationBuilder UseCustomResourceHandler(this ApplicationConfigurationBuilder @this, Func <ResourceSchemeConfiguration> getConfig)
        {
            @this.Use(builder =>
            {
                return((runtime, props) => {
                    var config = getConfig.Invoke();
                    runtime.RegisterCustomResourceHandler(config);
                });
            }, ExtensionExecutePosition.Initialized);

            return(@this);
        }
Esempio n. 2
0
        public static ApplicationConfigurationBuilder ClearCacheFile(this ApplicationConfigurationBuilder @this)
        {
            //const string CACHE_DIR = "Cache";

            @this.Use(builder =>
            {
                builder.Properties[nameof(ClearCacheFile)] = true;



                return((runtime, props) => {
                    var cachePath = WinFormium.DefaultAppDataDirectory;

                    if (props.ContainsKey(nameof(UseApplicationDataDirectory)))
                    {
                        cachePath = (string)props[nameof(UseApplicationDataDirectory)];
                    }

                    cachePath = Path.Combine(cachePath);

                    if (Directory.Exists(cachePath))
                    {
                        try
                        {
                            Directory.Delete(cachePath, true);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }



                    WinFormium.GetLogger().Info("Cache has been cleared.");
                });
            }, ExtensionExecutePosition.MainProcessStartup);

            return(@this);
        }
        /// <summary>
        /// Allows application just run one instance.
        /// </summary>
        public static ApplicationConfigurationBuilder UseSingleInstance(this ApplicationConfigurationBuilder @this, Action onProcessAlreadyExists = null)
        {
            @this.Use(builder => {
                return((runtime, props) =>
                {
                    var thisProcess = Process.GetCurrentProcess();

                    foreach (var process in Process.GetProcessesByName(thisProcess.ProcessName))
                    {
                        if (process.Id != thisProcess.Id)
                        {
                            onProcessAlreadyExists?.Invoke();

                            Environment.Exit(0);
                            return;
                        }
                    }
                });
            }, ExtensionExecutePosition.MainProcessStartup);

            return(@this);
        }
Esempio n. 4
0
        public static ApplicationConfigurationBuilder UseProcessMessageBridgeHandler(this ApplicationConfigurationBuilder @this, Browser.ProcessMessageBridge.ProcessMessageBridgeHandler handler)
        {
            @this.Container.RegisterInstance(handler);

            return(@this);
        }
Esempio n. 5
0
        public static ApplicationConfigurationBuilder UseCustomResourceHandlerOptions(this ApplicationConfigurationBuilder @this, Action <ResourceSchemeOption> setOptionAction)
        {
            var options = @this.Container.GetInstance <ResourceSchemeOption>();

            if (options == null)
            {
                options = new ResourceSchemeOption();

                @this.Container.RegisterInstance(options);
            }

            setOptionAction?.Invoke(options);

            return(@this);
        }