static void Main(string[] args)
        {
            Console.WriteLine(Translator.Instance.Translate("cat1", "test1"));
            Console.WriteLine(Translator.Instance.Translate("cat1", "test2"));
            Console.WriteLine(Translator.Instance.Translate("cat2", "test"));

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en");

            var translator = new Translator();

            translator.Apply();

            Console.WriteLine(Translator.Instance.Translate("cat1", "test1"));
            Console.WriteLine(Translator.Instance.Translate("cat1", "test2"));
            Console.WriteLine(Translator.Instance.Translate("cat2", "test"));

            Translator.Instance.Save();
        }
Example #2
0
        private void ChangeSettings(ToolStripMenuItem toolStripMenuItem)
        {
            toolStripMenuItem.Click += (sender, args) =>
            {
                var formProvider =
                    _sessionContext.ExtensionManager.TryGetTopFormProvider(ExtensionCatalog.GeneralSettings);

                if (null == formProvider)
                {
                    return;
                }

                var form = (SettingsForm)formProvider.GetForm(_sessionContext);

                form.Closed += (o, eventArgs) =>
                {
                    if (DialogResult.OK == form.DialogResult)
                    {
                        var settingsCopy = _sessionContext.Session.SettingsService.GetSettings();
                        var settings     = (ISettings)form.SelectedObject;

                        _sessionContext.Session.SettingsService.SetSettings(settings);
                        _sessionContext.Session.SettingsService.Save();

                        if (settingsCopy.Language != settings.Language)
                        {
                            LocalizationUtility.ApplyLanguage(settings.Language);

                            var translator = new Translator();
                            translator.Apply();

                            EventBroker.OnLanguageChanged();
                        }
                    }
                };

                form.Show(this);
            };
        }
Example #3
0
            public void should_change_message_payload()
            {
                var processor = new Translator(
                    m => string.Format("Got : {0}", ((Boo)m.Payload).A));

                var payload = new Boo {
                    A = 10
                };

                var message = new Message <Boo>(
                    "boo".ToMessageLabel(),
                    new Dictionary <string, object> {
                    { "This", "That" }
                },
                    payload);

                var result = processor.Apply(message).ToList();

                result.Should().HaveCount(1);
                result.Single().Label.Name.Should().Be("boo");
                result.Single().Payload.Should().Be("Got : 10");
            }
Example #4
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            LocalizationUtility.ApplyLanguage(LocalizationUtility.GetDefaultLanguage());

#if DEBUG
#else
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
            Application.ThreadException += ApplicationOnThreadException;
#endif
            Application.ApplicationExit += ApplicationOnApplicationExit;

            // Первичная инициализация
            if (string.IsNullOrEmpty(Settings.Default.InstallationReference))
            {
                bool omitPrecompilation;

                if (ApplicationUtility.IsRunningOnMono)
                {
                    omitPrecompilation = true;
                }
                else
                {
                    var omitPrecompilationValue = ConfigurationManager.AppSettings["OmitPrecompilation"];

                    if (null != omitPrecompilationValue)
                    {
                        bool.TryParse(omitPrecompilationValue, out omitPrecompilation);
                    }
                    else
                    {
                        omitPrecompilation = false;
                    }
                }

                var initializationForm = new InitializationForm(omitPrecompilation);

                if (DialogResult.Cancel == initializationForm.ShowDialog())
                {
                    return;
                }
            }

            SplashScreenForm splashScreen = null;

            if (!ApplicationUtility.IsRunningOnMono)
            {
                var autoResetEvent = new AutoResetEvent(false);

                var thread = new Thread(() =>
                {
                    splashScreen = new SplashScreenForm();
                    autoResetEvent.Set();
                    Application.Run(splashScreen);
                })
                {
                    IsBackground = true
                };

                thread.Start();
                autoResetEvent.WaitOne();
            }

            try
            {
                _extensionManager = new ExtensionManager(Application.StartupPath);
            }
            catch (Exception exception)
            {
                // Закрываем SplashScreen
                splashScreen?.SafeClose();

                Logger.Fatal(exception.Message, exception);

                MessageBox.Show(Resources.Program_Main_An_error_occurred_while_trying_to_load_the_extension_manager_,
                                Resources.Program_Main_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // CustomAssemblyResolving
            _extensionManager.ApplyCustomAssemblyResolving();

            // WebMoney.Services configuration
            IConfigurationService configurationService;

            try
            {
                configurationService = _extensionManager.CreateExtension <IConfigurationService>();
            }
            catch (Exception)
            {
                // Закрываем SplashScreen
                splashScreen?.SafeClose();

                throw;
            }

            configurationService.InstallationReference = Settings.Default.InstallationReference;

            IUnityContainer unityContainer = new UnityContainer();
            configurationService.RegisterServices(unityContainer);

            // Set session
            var enterContext = new EntranceContext(_extensionManager, unityContainer);

            // Закрываем SplashScreen
            splashScreen?.SafeClose();

            var sessionContextProvider = _extensionManager.GetSessionContextProvider();

            SessionContext sessionContext;

            try
            {
                sessionContext = sessionContextProvider.GetIdentifierContext(enterContext);
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);

                MessageBox.Show(Resources.Program_Main_An_error_occurred_while_attempting_to_create_the_new_session_, Resources.Program_Main_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (null == sessionContext)
            {
                return;
            }

            var session = sessionContext.Session;
            unityContainer.RegisterInstance(session);

            // Language
            var language = session.SettingsService.GetSettings().Language;
            LocalizationUtility.ApplyLanguage(language);

            var translator = new Translator();
            translator.Apply();

            // Run main form.
            var formProvider = _extensionManager.GetTopFormProvider(ExtensionCatalog.Main);
            var mainForm     = formProvider.GetForm(sessionContext);

            Application.Run(mainForm);
        }