Beispiel #1
0
        /// <summary>
        /// Adds all available language options to the main menu.
        /// </summary>
        private void SetupLanguageMenu()
        {
            // We need to instantiate a LocalizationExtension here
            // so that the can be sure that the localization data is initialized.
            LocalizationExtension _ = new LocalizationExtension();

            MenuItem languageMenu = this.FindControl <MenuItem>("menuLanguage");

            List <MenuItem> items = new List <MenuItem>();

            foreach (var lang in new MainMenuViewModel().LanguageMenuItems)
            {
                MenuItem item = new MenuItem()
                {
                    Header           = lang.Header,
                    Command          = lang.Command,
                    CommandParameter = lang.CommandParameter,
                    Icon             = lang.Icon
                };

                items.Add(item);
            }

            languageMenu.Items = items;
        }
Beispiel #2
0
        public static string LocalizeResource(this string resourceName)
        {
            var extention = new LocalizationExtension();

            extention.ResourceName = resourceName;
            return(extention.ProvideValue(null).ToString());
        }
Beispiel #3
0
        /// <summary>
        /// Make Http GET request to Amadeus
        /// </summary>
        /// <param name="searchParameters"></param>
        public List <SearchResults> HttRequestToAmadeusAPI(SearchParameters searchParameters)
        {
            PrepareSearchParametersForHttpRequest(searchParameters);
            ConstructUrl();

            Response flightResults = new Response();

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_AmadeusApiUrl);
                request.AutomaticDecompression = DecompressionMethods.GZip;

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            string json = reader.ReadToEnd();
                            flightResults = JsonConvert.DeserializeObject <Response>(json);

                            return(PrepareSearchResultsForView(flightResults));
                        }
            }
            catch (WebException webExc)
            {
                using (var stream = webExc.Response.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        _LowFlightFareHub.AmadeusWebError(LocalizationExtension.GetWebErrorMsg(reader.ReadToEnd()));
                        Debug.WriteLine(reader.ReadToEnd());
                    }
            }

            // If WebException occure empty list of Search results
            return(new List <SearchResults>(0));
        }
Beispiel #4
0
        protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
        {
            //TODO
            //Replace identity messages with localized messages

            //Set locale for current user
            LocalizationExtension.SetLang();

            return(base.BeginExecuteCore(callback, state));
        }
Beispiel #5
0
        public override void Initialize()
        {
            AvaloniaXamlLoader.Load(this);

            // This is here only to be able to manually load a specific translation
            // during development by setting CurrentLocalization it to something
            // like "en-US" or "de-DE";
            LocalizationExtension loc = new LocalizationExtension();

            LocalizationExtension.CurrentLocalization = LocalizationExtension.DEFAULT_LOC;
        }
Beispiel #6
0
        protected override void Application_Start()
        {
            base.Application_Start();

            LocalizationExtension.Configure(typeof(App_Start.AppLocale));

            AreaRegistration.RegisterAllAreas();

            WebFilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            WebRouteConfig.RegisterRoutes(RouteTable.Routes);
            WebBundleConfig.RegisterBundles(BundleTable.Bundles);
        }
        public MainWindow()
        {
            InitializeComponent();
            if (AvaloniaLocator.Current.GetService <MainWindow>() == null)
            {
                AvaloniaLocator.CurrentMutable.Bind <MainWindow>().ToConstant(this);
            }
            this.LocalizationService = new LocalizationExtension();
#if DEBUG
            this.AttachDevTools();
#endif
        }
Beispiel #8
0
        /// <summary>
        /// Adds all available language options to the main menu.
        /// </summary>
        private void SetupLanguageMenu()
        {
            // We need to instantiate a LocalizationExtension here
            // so that the can be sure that the localization data is initialized.
            LocalizationExtension loc = new LocalizationExtension();

            MenuItem languageMenu = this.FindControl <MenuItem>("menuLanguage");

            var             mmvm  = ((MainWindowViewModel)AvaloniaLocator.Current.GetService <MainWindow>().DataContext).MainMenu;
            List <MenuItem> items = loc.GetLanguageMenuItems(mmvm);

            languageMenu.Items = items;
        }
    public string Resolve(Mapping source, object destination, EntityInfo sourceMember, string destMember,
                          ResolutionContext context)
    {
        context.Items.TryGetValue("Language", out object languageObject);
        context.Items.TryGetValue("Repository", out object repositoryObject);
        ILocalizedPropertyRepository repository = repositoryObject as ILocalizedPropertyRepository;
        LanguageDTO language = languageObject as LanguageDTO;

        if (language == null || repository == null)
        {
            throw new ArgumentNullException($"Language and LocalizationRepository as AutoMapper Parameter");
        }
        if (source.Id == 0)
        {
            return(sourceMember.DefaultValue);
        }
        //Get the value from the DB
        return(LocalizationExtension.GetLocalized(sourceMember.LocaleKey, sourceMember.LocaleKeyGroup, sourceMember.DefaultValue, source.Id, language, repository));
    }
Beispiel #10
0
        public override void Initialize()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ||
                RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                if (!SystemAndShellUtils.IsAdmin())
                {
                    bool nogo = true;

                    // If platform is Linux we can throw a hail mary and try to elevate the program by using the
                    // polkit protocol via pkexe, see: https://www.freedesktop.org/software/polkit/docs/0.105/pkexec.1.html
                    // In short, the pkexec application allows you to request authorization and impersonation rights
                    // for an application. In order for this to work, you need to have an application specific policy
                    // installed in the application (see Platform/Linux/Installer).

                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                    {
                        Log.Information("Launched on Linux without sudo, trying to re-launch using PolicyKit");
                        nogo = !SystemAndShellUtils.LaunchInstallerUsingPolKit(copyCurrentProcessExecutable: true);
                    }

                    if (nogo)
                    {
                        rootBail = true;
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }

            Log.Information($"Current executable path: {Process.GetCurrentProcess().MainModule.FileName}");
            AvaloniaXamlLoader.Load(this);

            // This is here only to be able to manually load a specific translation
            // during development by setting CurrentLocalization it to something
            // like "en-US" or "de-DE";
            LocalizationExtension loc = new LocalizationExtension();

            LocalizationExtension.CurrentLocalization = LocalizationExtension.DEFAULT_LOC;
        }
Beispiel #11
0
 /// <summary>
 /// Creates a new <c>App</c> instance.
 /// </summary>
 public App() : base()
 {
     this.Localization = new LocalizationExtension();
     SQRL.StartCPSServer();
     SQRL.CPS.CPSRequestReceived += CPSRequestReceived;
 }
Beispiel #12
0
 protected static void RegisterResource(Type resourceType)
 {
     LocalizationExtension.Configure(resourceType);
 }
Beispiel #13
0
        public MainWindow()
        {
            InitializeComponent();
            if (AvaloniaLocator.Current.GetService <MainWindow>() == null)
            {
                AvaloniaLocator.CurrentMutable.Bind <MainWindow>().ToConstant(this);
            }
            this.LocalizationService = new LocalizationExtension();
#if DEBUG
            this.AttachDevTools();
#endif

            // Set up and configure the notification icon
            // Get the type of the platform-specific implementation
            Type type = Implementation.ForType <INotifyIcon>();
            if (type != null)
            {
                // If we have one, create an instance for it
                NotifyIcon = (INotifyIcon)Activator.CreateInstance(type);
            }

            if (NotifyIcon != null)
            {
                NotifyIcon.ToolTipText = "SQRL .NET Client";
                NotifyIcon.IconPath    = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
                                         "resm:SQRLDotNetClientUI.Assets.SQRL_icon_normal_16.png" :
                                         RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
                                         @"resm:SQRLDotNetClientUI.Assets.sqrl_icon_normal_256.ico":
                                         @"resm:SQRLDotNetClientUI.Assets.sqrl_icon_normal_256_32_icon.ico";


                NotifyIcon.DoubleClick += (s, e) =>
                {
                    RestoreWindow();
                };

                _NotifyIconContextMenu = new ContextMenu();
                List <object> menuItems = new List <object>();
                menuItems.AddRange(new[] {
                    new MenuItem()
                    {
                        Header  = LocalizationService.GetLocalizationValue("NotifyIconContextMenuItemHeaderRestore"),
                        Command = ReactiveCommand.Create(RestoreWindow)
                    },
                    new MenuItem()
                    {
                        Header  = LocalizationService.GetLocalizationValue("NotifyIconContextMenuItemHeaderExit"),
                        Command = ReactiveCommand.Create(Exit)
                    }
                });
                _NotifyIconContextMenu.Items = menuItems;
                NotifyIcon.ContextMenu       = _NotifyIconContextMenu;
                NotifyIcon.Visible           = true;
            }

            // Prevent the main window from closing. Just hide it instead
            // if we have a notify icon, or minimize it otherwise.
            this.Closing += (s, e) =>
            {
                if (_reallyClose)
                {
                    return;
                }

                if (NotifyIcon != null)
                {
                    Log.Information("Hiding main window");
                    Dispatcher.UIThread.Post(() =>
                    {
                        ((Window)s).Hide();
                    });
                    NotifyIcon.Visible = true;
                }
                else
                {
                    Log.Information("Minimizing main window");
                    Dispatcher.UIThread.Post(() =>
                    {
                        ((Window)s).WindowState = WindowState.Minimized;
                    });
                }
                e.Cancel = true;
            };

            this.Closed += (s, e) =>
            {
                // Remove the notify icon when the main window closes
                if (NotifyIcon != null)
                {
                    NotifyIcon?.Remove();
                }
            };
        }
Beispiel #14
0
 /// <summary>
 /// Creates a new <c>App</c> instance.
 /// </summary>
 public App() : base()
 {
     this.Localization = new LocalizationExtension();
 }