Beispiel #1
0
        public void loadInitData()
        {
            // clockSizeSlider.Value = 50;
            // clockSizeValueText.Content = String.Format(CLOCK_SIZE, clockSizeSlider.Value);

            new Thread(() =>
            {
                var DataKit             = new DataKit();
                var monitorSettingQuery = from c in DataKit.Realm.All <ClockSettingsByMonitor>() where c.MonitorDeviceName == MainWindow.MonitorDeviceName select c;
                ClockSettingsByMonitor monitorSetting = monitorSettingQuery.First();

                bool isWhiteClock = !monitorSetting.IsWhiteClock;
                int clockSize     = monitorSetting.ClockSize;

                this.Dispatcher.Invoke(new Action(() =>
                {
                    clockColorToggle.IsChecked = isWhiteClock;
                    clockSizeSlider.Value      = clockSize;
                    clockSizeValueText.Content = String.Format(CLOCK_SIZE, clockSizeSlider.Value);
                }));
            }).Start();
        }
Beispiel #2
0
        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)
                {
                }
            }
        }