public void loadInitData() { new Thread(() => { var DataKit = new DataKit(); var monitorSettingQuery = from c in DataKit.Realm.All <CommentSettingsByMonitor>() where c.MonitorDeviceName == MainWindow.MonitorDeviceName select c; CommentSettingsByMonitor monitorSetting = monitorSettingQuery.First(); bool isEnabled = monitorSetting.IsEnabled; bool isEnabledLoadFromServer = monitorSetting.IsEnabledLoadFromServer; string name = monitorSetting.Name; string comment = monitorSetting.Comment; int commentPosition = monitorSetting.DirectionOfComment; this.Dispatcher.Invoke(new Action(() => { commentSettingONToggle.IsChecked = isEnabled; commentFromServerToggle.IsChecked = isEnabledLoadFromServer; commentField.IsEnabled = commentSettingONToggle.IsChecked ?? false; nameJongsungText.Opacity = commentSettingONToggle.IsChecked ?? false ? 1 : 0.3; commentNameField.IsEnabled = commentSettingONToggle.IsChecked ?? false; commentNameField.Text = name; commentField.Text = comment; saveCommentPosition(commentPosition); })); }).Start(); }
public static void initFirstData() { new Thread(() => { var DataKit = new DataKit(); var hangulClockCommonSetting = DataKit.Realm.All <HangulClockCommonSetting>(); if (hangulClockCommonSetting.Count() <= 0) { var setting = new HangulClockCommonSetting(); setting.hu = RandomString(16); DataKit.Realm.Write(() => { DataKit.Realm.Add(setting); }); } var screens = System.Windows.Forms.Screen.AllScreens; foreach (var screen in screens) { var clockSetting = from c in DataKit.Realm.All <ClockSettingsByMonitor>() where c.MonitorDeviceName == screen.DeviceName select c; if (clockSetting.Count() <= 0) { var setting = new ClockSettingsByMonitor(); DataKit.Realm.Write(() => { setting.IsWhiteClock = true; setting.MonitorDeviceName = screen.DeviceName; setting.ClockSize = 100; setting.YoutubeURL = ""; DataKit.Realm.Add(setting); }); } var commentSetting = from c in DataKit.Realm.All <CommentSettingsByMonitor>() where c.MonitorDeviceName == screen.DeviceName select c; if (commentSetting.Count() <= 0) { var setting = new CommentSettingsByMonitor(); DataKit.Realm.Write(() => { setting.MonitorDeviceName = screen.DeviceName; setting.IsEnabled = false; setting.IsEnabledLoadFromServer = false; setting.Name = ""; setting.Comment = ""; DataKit.Realm.Add(setting); }); } var backgroundSetting = from c in DataKit.Realm.All <BackgroundSettingsByMonitor>() where c.MonitorDeviceName == screen.DeviceName select c; if (backgroundSetting.Count() <= 0) { var setting = new BackgroundSettingsByMonitor(); DataKit.Realm.Write(() => { setting.MonitorDeviceName = screen.DeviceName; setting.backgroundType = BackgroundSettingsByMonitor.BackgroundType.DEFAULT; DataKit.Realm.Add(setting); }); } } }).Start(); }
private static void MainThread() { while (true) { try { DataKit DataKit = new DataKit(); DataKit.Realm.Refresh(); ClockSettingsByMonitor clockSetting = DataKit.Realm.All <ClockSettingsByMonitor>().Where(c => c.MonitorDeviceName == MonitorDeviceName).First(); CommentSettingsByMonitor commentSetting = DataKit.Realm.All <CommentSettingsByMonitor>().Where(c => c.MonitorDeviceName == MonitorDeviceName).First(); int clockSize = clockSetting.ClockSize; bool isWhiteClick = clockSetting.IsWhiteClock; int clockDirection = commentSetting.DirectionOfComment; string name = commentSetting.Name; string comment = commentSetting.Comment; bool isEnabledCommentLoadFromServer = commentSetting.IsEnabledLoadFromServer; bool isUseCommentInName = commentSetting.IsEnabledNameInComment; if (isEnabledCommentLoadFromServer) { message = loadCommentFromServer(); } else { message = comment; lastCommentRequestTime = DateTime.MinValue; } try { if (isUseCommentInName) { HangulKit.HANGUL_INFO partOfName = HangulKit.HangulJaso.DevideJaso(name[name.Length - 1]); if (partOfName.chars[2] == ' ') { comment = string.Format("{0}야, {1}", name, message); } else { comment = string.Format("{0}아, {1}", name, message); } } else { comment = message; } } catch (Exception) { } hangulClockDesktop.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate { hangulClockDesktop.ucScale.ScaleX = (double)clockSize / 100; hangulClockDesktop.ucScale.ScaleY = (double)clockSize / 100; hangulClockDesktop.SetClockColor(isWhiteClick); if (clockDirection == CommentSettingsByMonitor.CommentDirection.TOP) { hangulClockDesktop.setTopCommentText(comment); } else if (clockDirection == CommentSettingsByMonitor.CommentDirection.LEFT) { hangulClockDesktop.setLeftCommentText(comment); } else if (clockDirection == CommentSettingsByMonitor.CommentDirection.RIGHT) { hangulClockDesktop.setRightCommentText(comment); } else { hangulClockDesktop.setBottomCommentText(comment); } })); Thread.Sleep(5000); } catch (ThreadInterruptedException) { } } }