//Set current culture and update UI fields public void SetLanguage() { Properties.Settings.Default.Language = Language; Properties.Settings.Default.Save(); switch (Language) { default: Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); break; case 1: Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("ru-RU"); break; } Title = ResourceHandler.GetResource("Title"); NameString = ResourceHandler.GetResource("NameString"); Retrieve = ResourceHandler.GetResource("Retrieve"); Clear = ResourceHandler.GetResource("Clear"); LanguageLabel = ResourceHandler.GetResource("LanguageLabel"); FrequencyLabel = ResourceHandler.GetResource("FrequencyLabel"); LambdaLabel = ResourceHandler.GetResource("LambdaLabel"); SignalTypeLabel = ResourceHandler.GetResource("SignalTypeLabel"); CommentLabel = ResourceHandler.GetResource("CommentLabel"); Positions.Clear(); Positions.Add(ResourceHandler.GetResource("JuniorResearcher")); Positions.Add(ResourceHandler.GetResource("Researcher")); Positions.Add(ResourceHandler.GetResource("SeniorResearcher")); }
/// <summary> /// Displays a error message for the passed <see cref="Exception"/>. /// </summary> /// <param name="ex">The <see cref="Exception"/> that was thrown.</param> /// <param name="viewModel">The view model which caused the <see cref="Exception"/>.</param> /// <param name="callerName">The name of the method which caused the <see cref="Exception"/>.</param> public static void DisplayError(Exception ex, object viewModel, [CallerMemberName] string callerName = null) { if (_handler == null) { throw new MessageHandlerNotRegisterdException("There is no registered message handler!"); } string viewName = ViewManager.GetViewForViewModel(viewModel).GetType().Name; string exName = ex.GetType().Name; Match viewNameMatch = _viewNameRegex.Match(viewName); Match exNameMatch = _exceptionNameRegex.Match(exName); if (viewNameMatch.Success) { viewName = viewNameMatch.Groups["Name"].Value; } if (exNameMatch.Success) { exName = exNameMatch.Groups["Name"].Value; } string messageKey = GetResourceKey(_messageDefinition, viewName, exName, callerName); string messageTitleKey = GetResourceKey(_messageTitleDefinition, viewName, exName, callerName); string message = ResourceHandler.GetResource(messageKey); string messageTitle = ResourceHandler.GetResource(messageTitleKey); _handler.DisplayError(viewModel, ReplaceExceptionInformations(messageTitle, ex), ReplaceExceptionInformations(message, ex)); }
private void Start() { ResourceHandler resourceHandler = ResourceHandler.Instance; foreach (ResourceStartAmount startAmount in startAmounts) { resourceHandler.GetResource(startAmount.Type).Amount = startAmount.StartAmount; } }
/// <summary> /// Trying to connect to server and receive data /// </summary> /// <param name="name"></param> /// <param name="position"></param> public static async Task ConnectToServer(string name, int position) { TestingData data = null; //recollecting connection data from settings var host = Properties.Settings.Default.TestingDataHost; var port = Properties.Settings.Default.TestingDataPort; try { //Turning TLS authorization off AppContext.SetSwitch( "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); using var channel = GrpcChannel.ForAddress($"{host}:{port}"); var client = new TestingDataRetriever.TestingDataRetrieverClient(channel); //Async connection testingData = await client.GetTestingDataAsync( new ClientCredentials() { Name = name, ClientType = (ClientType)position + 1 }); testingData.Comment = new StringBuilder() .Append(ResourceHandler.GetResource("TestingDatawaspresentedfor")) .Append(name) .Append(ResourceHandler.GetResource("at")) .Append(DateTime.Now.ToString()) .ToString(); } //If this is gRPC error, we know how to present it to user catch (RpcException ex) { testingData = new TestingData() { Comment = ex.Message }; ex.Data.Add("UserMessage", $"{ResourceHandler.GetResource("Anerroroccurredwhen")} {host}:{port}. RPC:" + ((StatusCode)(ex.StatusCode))); throw ex; } catch (Exception e) { testingData = new TestingData() { Comment = e.Message }; } }
private void SetResource(Type type, object control, string controlName, Type viewType) { TextResourceKeyRule rule = RuleProvider.GetTextResourceKeyRule(type); if (rule == null) { return; } PropertyInfo pInfo = type.GetProperty(rule.ResourcePropertyName); if (pInfo == null) { return; } pInfo.SetValue(control, ResourceHandler.GetResource(rule.GetResourceKey(viewType, controlName), true)); }