10 using System.Windows.Markup;
17 public partial class App : Application
22 private String localizationDirectory;
27 internal event EventHandler LanguageChangedEvent;
32 private int langDictId = -1;
47 FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
48 new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(
49 CultureInfo.CurrentCulture.IetfLanguageTag)));
59 Dispatcher.UnhandledException += Dispatcher_UnhandledException;
60 localizationDirectory =
System.IO.Path.GetDirectoryName(
61 System.Reflection.Assembly.GetExecutingAssembly().Location) +
@"\Localization";
68 protected override void OnStartup(StartupEventArgs e)
72 InitializeLanguageResource();
77 new Settings(),
new Action<string>(i => { SwitchLanguage(i); }));
78 mainViewModel.
Initialize(FindStringResource(
"new"),
79 Resources.MergedDictionaries[langDictId][
"ResourceDictionaryName"].ToString().Substring(4));
80 window.DataContext = mainViewModel;
91 internal string FindStringResource(
string key)
93 return FindResource(key).ToString().Trim();
100 private void InitializeLanguageResource()
104 CultureInfo.CurrentUICulture.Name :
107 SetLanguageResourceDictionary(GetLocXAMLFilePath(UICulture));
115 private string GetLocXAMLFilePath(
string inFiveCharLang)
117 string locXamlFile =
"LocalizationDictionary." + inFiveCharLang +
".xaml";
118 return Path.Combine(localizationDirectory, inFiveCharLang, locXamlFile);
125 private void SwitchLanguage(
string inFiveCharLang)
128 if (Resources.MergedDictionaries[langDictId][
"ResourceDictionaryName"]
129 .ToString().Substring(4).Equals(inFiveCharLang))
133 var ci =
new CultureInfo(inFiveCharLang);
134 Thread.CurrentThread.CurrentUICulture = ci;
139 SetLanguageResourceDictionary(GetLocXAMLFilePath(inFiveCharLang));
141 if (LanguageChangedEvent != null)
143 LanguageChangedEvent(
this,
new EventArgs());
152 private void SetLanguageResourceDictionary(String inFile)
156 if (!File.Exists(inFile))
158 if (inFile.Contains(
"cs-CZ"))
159 inFile = inFile.Replace(
"cs-CZ",
"sk-SK");
161 inFile = inFile.Replace(inFile.Substring(inFile.Length - 10, 5),
"en-US");
165 var languageDictionary =
new ResourceDictionary();
166 languageDictionary.Source =
new Uri(inFile);
170 for (
int i = 0; i < Resources.MergedDictionaries.Count; i++)
172 var md = Resources.MergedDictionaries[i];
175 if (md.Contains(
"ResourceDictionaryName"))
177 if (md[
"ResourceDictionaryName"].ToString().StartsWith(
"Loc-"))
184 if (langDictId == -1)
187 Resources.MergedDictionaries.Add(languageDictionary);
188 langDictId = Resources.MergedDictionaries.Count - 1;
193 Resources.MergedDictionaries[langDictId] = languageDictionary;
202 private void Dispatcher_UnhandledException(
object sender,
203 System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
205 MessageBox.Show(e.Exception.Message,
"Error",
206 MessageBoxButton.OK, MessageBoxImage.Error);
207 string path =
System.IO.Path.GetDirectoryName(
208 System.Reflection.Assembly.GetExecutingAssembly().Location);
210 using (StreamWriter streamWriter =
new StreamWriter(path,
true))
212 Exception ex = e.Exception;
213 streamWriter.WriteLine(DateTime.Now);
214 for (
int i = 0; ex != null; i++)
216 streamWriter.Write(i == 0 ?
"Exception " :
217 "\r\nInner Exception " + i +
": ");
218 streamWriter.WriteLine(e.Exception.Message);
219 streamWriter.WriteLine(
"Call stack:");
220 streamWriter.WriteLine(e.Exception.StackTrace);
221 ex = ex.InnerException;
223 streamWriter.WriteLine(
"----------------------------");
void Initialize(string newTopologyName, string languageOnStartup)
Creates new or open last opened geometric topology.
GUIInteractions logic for App.xaml
Class implementing ISetting interface using settings of visual studio application.
App()
Initialization of app.
Class implements IInteractions interface by message boxes or dialogs.
Main application viewmodel.
override void OnStartup(StartupEventArgs e)
Occurs on startup of application.