Example #1
0
        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();
        }
Example #2
0
        private void stillImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (backgroundToggle.IsChecked ?? false)
            {
                if (e.ClickCount == 2)
                {
                    OpenFileDialog dialog = new OpenFileDialog();
                    dialog.Filter = "이미지 파일 (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg";

                    if (dialog.ShowDialog() ?? false)
                    {
                        string fileName = dialog.FileName;

                        stillImage.Source  = new BitmapImage(new Uri(fileName));
                        stillImage.Stretch = Stretch.UniformToFill;

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

                            DataKit.Realm.Write(() =>
                            {
                                monitorSetting.imgPath = fileName;
                            });
                        }).Start();
                    }
                }
            }
        }
Example #3
0
        private void solidColorContainer_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (solidToggle.IsChecked ?? false)
            {
                if (e.ClickCount == 2)
                {
                    System.Windows.Forms.ColorDialog dialog = new System.Windows.Forms.ColorDialog();

                    if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        int argb = dialog.Color.ToArgb();

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

                            DataKit.Realm.Write(() =>
                            {
                                monitorSetting.SolidColor = (argb & 0x00FFFFFF).ToString("X6");
                            });
                        }).Start();

                        BrushConverter bc = new BrushConverter();
                        solidColorContainer.Background = (Brush)bc.ConvertFrom("#" + (argb & 0x00FFFFFF).ToString("X6"));
                        Debug.WriteLine("OKOKOKOKOK");
                    }
                }
            }
        }
Example #4
0
        private void commentNameField_TextChanged(object sender, TextChangedEventArgs e)
        {
            string name = commentNameField.Text;

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

                DataKit.Realm.Write(() =>
                {
                    monitorSetting.Name = name;
                });
            }).Start();

            try
            {
                HangulKit.HANGUL_INFO partOfName = HangulKit.HangulJaso.DevideJaso(commentNameField.Text[commentNameField.Text.Length - 1]);
                if (partOfName.chars[2] == ' ')
                {
                    nameJongsungText.Content = "야, ";
                }
                else
                {
                    nameJongsungText.Content = "아, ";
                }
            }
            catch (NullReferenceException ee)
            {
            }
            catch (IndexOutOfRangeException ee)
            {
            }
        }
        private void UpdateDelayTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            updateDelayTimer.Stop();

            new Thread(() =>
            {
                var hangulClockCommonSetting = new DataKit().Realm.All <HangulClockCommonSetting>();

                if (hangulClockCommonSetting.Count() <= 0)
                {
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        updateText.Content = "업데이트 확인 실패.";
                    }));
                }
                else
                {
                    var hu = hangulClockCommonSetting.First().hu;

                    HttpWebRequest request      = (HttpWebRequest)WebRequest.Create(UPDATE_CHECK_URL);
                    request.Headers["hu"]       = hu;
                    request.Headers["platform"] = "windows";
                    request.Headers["version"]  = VersionKit.HANGULCLOCK_VERSION;

                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    Stream stream       = response.GetResponseStream();
                    StreamReader reader = new StreamReader(stream);

                    string result = reader.ReadToEnd();

                    stream.Close();
                    response.Close();

                    JObject obj = JObject.Parse(result);

                    bool isUpdateAvailable = (bool)obj["isUpdateAvailable"];

                    this.Dispatcher.Invoke(() =>
                    {
                        if (isUpdateAvailable)
                        {
                            updateText.Content = "업데이트 있음.";

                            Process p   = new Process();
                            p.StartInfo = new ProcessStartInfo("HangulClockUpdateManager");

                            p.Start();
                        }
                        else
                        {
                            updateText.Content = "업데이트 없음. 최신버전.";
                        }
                    });
                }
            }).Start();
        }
Example #6
0
        private void commentUseNameToggle_Unchecked(object sender, RoutedEventArgs e)
        {
            new Thread(() =>
            {
                var DataKit        = new DataKit();
                var monitorSetting = (from c in DataKit.Realm.All <CommentSettingsByMonitor>() where c.MonitorDeviceName == MainWindow.MonitorDeviceName select c).First();

                DataKit.Realm.Write(() =>
                {
                    monitorSetting.IsEnabledNameInComment = false;
                });
            }).Start();
        }
Example #7
0
        private void youtubeVideoCodeTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            string youtubeVideoCode = youtubeVideoCodeTextBox.Text;

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

                DataKit.Realm.Write(() =>
                {
                    monitorSetting.YoutubeURL = youtubeVideoCode;
                });
            }).Start();
        }
Example #8
0
        private void commentField_TextChanged(object sender, TextChangedEventArgs e)
        {
            string comment = commentField.Text;

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

                DataKit.Realm.Write(() =>
                {
                    monitorSetting.Comment = comment;
                });
            }).Start();
        }
Example #9
0
        private void clockColorToggle_Unchecked(object sender, RoutedEventArgs e)
        {
            bool isToggleChecked = !clockColorToggle.IsChecked ?? false;

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

                DataKit.Realm.Write(() =>
                {
                    monitorSetting.IsWhiteClock = isToggleChecked;
                });
            }).Start();
        }
Example #10
0
        private void clockSizeSlider_ValueChanged(object sender, EventArgs e)
        {
            int clockSize = Convert.ToInt32(clockSizeSlider.Value);

            clockSizeValueText.Content = String.Format(CLOCK_SIZE, clockSize);

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

                DataKit.Realm.Write(() =>
                {
                    monitorSetting.ClockSize = clockSize;
                });
            }).Start();
        }
Example #11
0
        private void solidToggle_Checked(object sender, RoutedEventArgs e)
        {
            solidImageBorder.Opacity = 1;

            new Thread(() =>
            {
                var DataKit        = new DataKit();
                var monitorSetting = (from c in DataKit.Realm.All <BackgroundSettingsByMonitor>() where c.MonitorDeviceName == MainWindow.MonitorDeviceName select c).First();
                DataKit.Realm.Write(() =>
                {
                    monitorSetting.backgroundType = BackgroundSettingsByMonitor.BackgroundType.SOLID;
                });
            }).Start();

            backgroundToggle.IsChecked = false;
            youtubeToggle.IsChecked    = false;
        }
Example #12
0
        private void commentSettingONToggle_Unchecked(object sender, RoutedEventArgs e)
        {
            new Thread(() =>
            {
                var DataKit        = new DataKit();
                var monitorSetting = (from c in DataKit.Realm.All <CommentSettingsByMonitor>() where c.MonitorDeviceName == MainWindow.MonitorDeviceName select c).First();

                DataKit.Realm.Write(() =>
                {
                    monitorSetting.IsEnabled = false;
                });
            }).Start();

            commentField.IsEnabled     = false;
            nameJongsungText.Opacity   = 0.3;
            commentNameField.IsEnabled = false;
        }
Example #13
0
        private void checkInitBackground()
        {
            if (!(backgroundToggle.IsChecked ?? false) && !(solidToggle.IsChecked ?? false) && !(youtubeToggle.IsChecked ?? false))
            {
                new Thread(() =>
                {
                    var DataKit        = new DataKit();
                    var monitorSetting = (from c in DataKit.Realm.All <BackgroundSettingsByMonitor>() where c.MonitorDeviceName == MainWindow.MonitorDeviceName select c).First();

                    DataKit.Realm.Write(() =>
                    {
                        monitorSetting.backgroundType = BackgroundSettingsByMonitor.BackgroundType.DEFAULT;
                    });
                }).Start();

                MainWindow.showToastMessage("배경화면 설정이 모두 해제되었습니다. '시스템에 설정된 배경화면' 으로 자동 설정됩니다.");
            }
        }
Example #14
0
        private void commentPositionBottomContainer_MouseLeave(object sender, MouseEventArgs e)
        {
            new Thread(() =>
            {
                var DataKit        = new DataKit();
                var monitorSetting = (from c in DataKit.Realm.All <CommentSettingsByMonitor>() where c.MonitorDeviceName == MainWindow.MonitorDeviceName select c).First();

                int commentDirection = monitorSetting.DirectionOfComment;

                this.Dispatcher.Invoke(new Action(() =>
                {
                    if (commentDirection != CommentSettingsByMonitor.CommentDirection.BOTTOM)
                    {
                        setButtonHoverOutEvent(commentPositionBottomContainer);
                    }
                }));
            }).Start();
        }
        public async void loadInitData()
        {
            /* if (hangulClockONOFFToggle.IsChecked == true)
             * {
             *  useText.Content = "사용중이야.";
             * }
             * else
             * {
             *  useText.Content = "사용중이지 않아.";
             * }
             *
             * Process[] hangulClockRendererProcesses = Process.GetProcessesByName("HangulClockRenderer");
             *
             * if (hangulClockRendererProcesses.Length > 0)
             * {
             *  useText.Content = "사용중이야.";
             *  hangulClockONOFFToggle.IsChecked = true;
             * }
             * else
             * {
             *  useText.Content = "사용중이지 않아.";
             *  hangulClockONOFFToggle.IsChecked = false;
             * } */

            MainWindow.showToastMessage("해당 모니터에 해당하는 한글시계 설정값을 구성하고 있습니다...");

            await Task.Delay(1000);

            new Thread(() =>
            {
                var DataKit = new DataKit();

                var clockSetting = DataKit.Realm.All <ClockSettingsByMonitor>().Where(c => c.MonitorDeviceName == MainWindow.MonitorDeviceName).First();

                bool isEnabledClockCurrentMonitor = clockSetting.isUseHangulClock;

                this.Dispatcher.Invoke(() =>
                {
                    hangulClockONOFFToggle.IsChecked = isEnabledClockCurrentMonitor;

                    useText.Content = isEnabledClockCurrentMonitor ? "사용중이야." : "사용중이지 않아.";
                });
            }).Start();
        }
Example #16
0
        private void youtubeToggle_Checked(object sender, RoutedEventArgs e)
        {
            youtubeVideoCodeTextBox.Opacity   = 1;
            youtubeVideoCodeTextBox.IsEnabled = true;

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

                DataKit.Realm.Write(() =>
                {
                    monitorSetting.backgroundType = BackgroundSettingsByMonitor.BackgroundType.YOUTUBE_VIDEO;
                });
            }).Start();

            backgroundToggle.IsChecked = false;
            solidToggle.IsChecked      = false;
        }
        private static void RestartHangulClockRenderer()
        {
            screenModels.Clear();

            Process[] hangulClockRendererProcesses = Process.GetProcessesByName("HangulClockRenderer");

            foreach (var hangulClockRendererProcess in hangulClockRendererProcesses)
            {
                hangulClockRendererProcess.Kill();
            }

            var screens = System.Windows.Forms.Screen.AllScreens;

            new Thread(() =>
            {
                var DataKit = new DataKit();

                foreach (var item in screens.Select((value, i) => new { i, value }))
                {
                    var clockSettingQ = DataKit.Realm.All <ClockSettingsByMonitor>().Where(c => c.MonitorDeviceName == item.value.DeviceName);

                    if (clockSettingQ.Count() > 0)
                    {
                        var clockSetting = clockSettingQ.First();

                        if (clockSetting.isUseHangulClock)
                        {
                            Process hangulClockRendererProcess   = new Process();
                            hangulClockRendererProcess.StartInfo = new ProcessStartInfo("HangulClockRenderer.exe");

#if !DEBUG
                            hangulClockRendererProcess.StartInfo.WorkingDirectory = @"C:\Program Files\Hangul Clock";
#endif
                            hangulClockRendererProcess.StartInfo.Arguments       = $"/mindex {item.i}";
                            hangulClockRendererProcess.StartInfo.CreateNoWindow  = true;
                            hangulClockRendererProcess.StartInfo.UseShellExecute = false;

                            hangulClockRendererProcess.Start();
                        }
                    }
                }
            }).Start();
        }
        private void hangulClockONOFFToggle_Unchecked(object sender, RoutedEventArgs e)
        {
            useText.Content = "사용중이지 않아.";

            new Thread(() =>
            {
                var DataKit      = new DataKit();
                var clockSetting = DataKit.Realm.All <ClockSettingsByMonitor>().Where(c => c.MonitorDeviceName == MainWindow.MonitorDeviceName).First();

                DataKit.Realm.Write(() =>
                {
                    clockSetting.isUseHangulClock = false;

                    this.Dispatcher.Invoke(() =>
                    {
                        MainWindow.showToastMessage("해당 모니터에서 한글시계를 사용하지 않습니다.");
                    });
                });
            }).Start();
        }
Example #19
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();
        }
Example #20
0
        private void saveCommentPosition(int direction)
        {
            new Thread(() =>
            {
                var DataKit        = new DataKit();
                var monitorSetting = (from c in DataKit.Realm.All <CommentSettingsByMonitor>() where c.MonitorDeviceName == MainWindow.MonitorDeviceName select c).First();

                DataKit.Realm.Write(() =>
                {
                    monitorSetting.DirectionOfComment = direction;
                });
            }).Start();

            BrushConverter bc = new BrushConverter();

            commentPositionTopContainer.Background    = (Brush)bc.ConvertFrom("#03FFFFFF");
            commentPositionLeftContainer.Background   = (Brush)bc.ConvertFrom("#03FFFFFF");
            commentPositionRightContainer.Background  = (Brush)bc.ConvertFrom("#03FFFFFF");
            commentPositionBottomContainer.Background = (Brush)bc.ConvertFrom("#03FFFFFF");

            if (direction == CommentSettingsByMonitor.CommentDirection.TOP)
            {
                commentPositionTopContainer.Background = (Brush)bc.ConvertFrom("#FFFFFF");
            }
            else if (direction == CommentSettingsByMonitor.CommentDirection.LEFT)
            {
                commentPositionLeftContainer.Background = (Brush)bc.ConvertFrom("#FFFFFF");
            }
            else if (direction == CommentSettingsByMonitor.CommentDirection.RIGHT)
            {
                commentPositionRightContainer.Background = (Brush)bc.ConvertFrom("#FFFFFF");
            }
            else
            {
                commentPositionBottomContainer.Background = (Brush)bc.ConvertFrom("#FFFFFF");
            }
        }
Example #21
0
    /// <summary>
    /// 入口
    /// </summary>
    /// <param name="tdb"></param>
    /// <param name="conn"></param>
    /// <param name="databaseName"></param>
    /// <param name="dkCall"></param>
    /// <returns></returns>
    static SharedResultVM Entry(SharedEnum.TypeDB tdb, string conn, string databaseName, Func <DataKit, object> dkCall)
    {
        var vm = new SharedResultVM();

        try
        {
            var dk = DataKit.Init(tdb, conn, databaseName);
            if (dk != null)
            {
                vm.Data = dkCall(dk);
                vm.Set(SharedEnum.RTag.success);
            }
            else
            {
                vm.Set(SharedEnum.RTag.error);
            }
        }
        catch (Exception ex)
        {
            vm.Set(ex);
        }

        return(vm);
    }
Example #22
0
        private void checkUpdate()
        {
            new Thread(() =>
            {
                var DataKit = new DataKit();
                var hangulClockCommonSetting = new DataKit().Realm.All <HangulClockCommonSetting>();

                if (hangulClockCommonSetting.Count() <= 0)
                {
                    if (MessageBox.Show("업데이트를 확인할 수 없습니다.\n유효성 검사를 실패하였습니다.", "업데이트 확인 오류", MessageBoxButton.OK, MessageBoxImage.Warning) == MessageBoxResult.OK)
                    {
                        Environment.Exit(0);
                    }
                }
                else
                {
                    var hu = hangulClockCommonSetting.First().hu;

                    HttpWebRequest request      = (HttpWebRequest)WebRequest.Create(UPDATE_CHECK_URL);
                    request.Headers["hu"]       = hu;
                    request.Headers["platform"] = "windows";
                    request.Headers["version"]  = VersionKit.HANGULCLOCK_VERSION;

                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    Stream stream       = response.GetResponseStream();
                    StreamReader reader = new StreamReader(stream);

                    string result = reader.ReadToEnd();

                    stream.Close();
                    response.Close();

                    JObject obj = JObject.Parse(result);

                    bool isUpdateAvailable = (bool)obj["isUpdateAvailable"];
                    string latestVersion   = obj["version"].ToString();
                    downloadURL            = obj["downloadURL"].ToString();
                    JArray changeLogs      = JArray.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(obj["changeLog"]));

                    this.Dispatcher.Invoke(() =>
                    {
                        if (isUpdateAvailable)
                        {
                            newVersionAvailable.Content = $"새로운 버전 {latestVersion}으로 업데이트 할 수 있습니다.";

                            for (var i = 0; i < changeLogs.Count; i++)
                            {
                                updateComment.Text += $" - {changeLogs[i].ToString()}\n";
                            }
                        }
                        else
                        {
                            newVersionAvailable.Content = "현재 버전이 최신버전입니다.";
                            updateButton.IsEnabled      = false;
                            updateComment.IsEnabled     = false;
                        }

                        loadingIndicator.Visibility = Visibility.Hidden;
                    });
                }
            }).Start();
        }
Example #23
0
        public void loadInitData()
        {
            new Thread(() =>
            {
                var DataKit             = new DataKit();
                var monitorSettingQuery = from c in DataKit.Realm.All <BackgroundSettingsByMonitor>() where c.MonitorDeviceName == MainWindow.MonitorDeviceName select c;
                BackgroundSettingsByMonitor monitorSetting = monitorSettingQuery.First();

                int backgroundType      = monitorSetting.backgroundType;
                string imgPath          = monitorSetting.imgPath;
                string solidColor       = monitorSetting.SolidColor;
                string youtubeVideoCode = monitorSetting.YoutubeURL;

                this.Dispatcher.Invoke(new Action(() =>
                {
                    backgroundToggle.IsChecked = backgroundType == BackgroundSettingsByMonitor.BackgroundType.STILL_IMAGE;
                    solidToggle.IsChecked      = backgroundType == BackgroundSettingsByMonitor.BackgroundType.SOLID;
                    youtubeToggle.IsChecked    = backgroundType == BackgroundSettingsByMonitor.BackgroundType.YOUTUBE_VIDEO;

                    if (imgPath != "" && imgPath != null)
                    {
                        if (File.Exists(imgPath))
                        {
                            stillImage.Source  = new BitmapImage(new Uri(imgPath));
                            stillImage.Stretch = Stretch.UniformToFill;
                        }
                    }
                    else
                    {
                        stillImage.Source = null;
                    }

                    BrushConverter bc = new BrushConverter();
                    if (solidColor != null && solidColor != "")
                    {
                        solidColorContainer.Background = (Brush)bc.ConvertFrom("#" + solidColor);
                    }
                    else
                    {
                        solidColorContainer.Background = (Brush)bc.ConvertFrom("#10FFFFFF");
                    }

                    youtubeVideoCodeTextBox.Text = youtubeVideoCode;

                    if (!backgroundToggle.IsChecked ?? false)
                    {
                        stillImageBorder.Opacity = 0.3;
                    }
                    else
                    {
                        stillImageBorder.Opacity = 1;
                    }

                    if (!solidToggle.IsChecked ?? false)
                    {
                        solidImageBorder.Opacity = 0.3;
                    }
                    else
                    {
                        solidImageBorder.Opacity = 1;
                    }

                    if (!youtubeToggle.IsChecked ?? false)
                    {
                        youtubeVideoCodeTextBox.Opacity   = 0.3;
                        youtubeVideoCodeTextBox.IsEnabled = false;
                    }
                    else
                    {
                        youtubeVideoCodeTextBox.Opacity   = 1;
                        youtubeVideoCodeTextBox.IsEnabled = true;
                    }
                }));
            }).Start();
        }
        private async static void ServiceThread()
        {
            var DataKit = new DataKit();

            while (true)
            {
                try
                {
                    DataKit.Realm.Refresh();

                    if (screenModels.Count <= 0)
                    {
                        Console.WriteLine("[UPDATE] : Enum Monitor processing...");
                        foreach (var screen in System.Windows.Forms.Screen.AllScreens)
                        {
                            screenModels.Add(MakeScreenModel(screen));
                        }
                        Console.WriteLine("[UPDATE] : Enum Monitor process complete.");
                    }

                    var screens = System.Windows.Forms.Screen.AllScreens;
                    int index   = 0;

                    if (screens.Length != screenModels.Count) // 모니터의 개수가 줄었거나, 추가됬거나...
                    {
                        Console.WriteLine("[CHANGE] : Physical display device add / deleted. Restart HangulClockRenderer");

                        RestartHangulClockRenderer();
                    }
                    else
                    {
                        bool isNotChanged = true;
                        foreach (var screen in screens)
                        {
                            if (MakeScreenModel(screen) != screenModels[index])
                            {
                                isNotChanged = false;
                                break;
                            }

                            index++;
                        }

                        if (!isNotChanged) // 음... 머 어떤 모니터의 해상도라던지 위치 등이 변경된듯...?
                        {
                            Console.WriteLine("[CHANGE] : Monitor status changed. Restart HangulClockRenderer");
                            RestartHangulClockRenderer();
                        }
                        else
                        {
                            Process[] hangulClockRendererProcesses = Process.GetProcessesByName("HangulClockRenderer");

                            if (hangulClockRendererProcesses.Length <= 0) // 서비스는 실행됐는데 한글시계 프로세스가 1도 없으면...
                            {
                                Console.WriteLine("[CHECK] : Checking HangulClockRenderer process running...");
                                RestartHangulClockRenderer(); // 한글시계 프로세스 시작df
                            }
                            else // 근데... 머 하나는 실행되있고, 하나는 실행이 안되어있으면 이건 검사해야해
                            {
                                foreach (var item in System.Windows.Forms.Screen.AllScreens.Select((value, i) => new { i, value }))
                                {
                                    var clockSettingQ = DataKit.Realm.All <ClockSettingsByMonitor>().Where(c => c.MonitorDeviceName == item.value.DeviceName);

                                    if (clockSettingQ.Count() > 0)
                                    {
                                        var clockSetting = clockSettingQ.First();

                                        if (clockSetting.isUseHangulClock) // 해당 모니터에서 한글시계를 사용한다네...?
                                        {
                                            var isRunning = false;

                                            foreach (var hangulClockRendererProcess in hangulClockRendererProcesses)
                                            {
                                                if (GetCommandLine(hangulClockRendererProcess).Contains($"/mindex {item.i}"))
                                                {
                                                    isRunning = true;
                                                }
                                            }

                                            if (!isRunning)
                                            {
                                                Console.WriteLine($"[EXECUTE] : Starting HangulClockRenderer for monitor index {item.i}");

                                                Process hangulClockRendererProcess = new Process();
                                                hangulClockRendererProcess.StartInfo = new ProcessStartInfo("HangulClockRenderer.exe");
                                                hangulClockRendererProcess.StartInfo.WorkingDirectory = @"C:\Program Files\Hangul Clock";
                                                hangulClockRendererProcess.StartInfo.Arguments        = $"/mindex {item.i}";
                                                hangulClockRendererProcess.StartInfo.CreateNoWindow   = true;
                                                hangulClockRendererProcess.StartInfo.UseShellExecute  = false;

                                                hangulClockRendererProcess.Start();
                                            }
                                        }
                                        else // 해당 모니터에서는 한글시계를 사용 안한데
                                        {
                                            var isKilled = false;
                                            foreach (var hangulClockRendererProcess in hangulClockRendererProcesses)
                                            {
                                                if (GetCommandLine(hangulClockRendererProcess).Contains($"/mindex {item.i}"))
                                                {
                                                    Console.WriteLine($"[KILL] : Not use HangulClock (monitor index {item.i}). Killing...");
                                                    hangulClockRendererProcess.Kill();
                                                    isKilled = true;
                                                }
                                            }

                                            if (isKilled)
                                            {
                                                Process[] explorerProcesses = Process.GetProcessesByName("explorer");
                                                foreach (var explorerProcess in explorerProcesses)
                                                {
                                                    explorerProcess.Kill();
                                                }

                                                await Task.Delay(2000);

                                                string  explorer = string.Format("{0}\\{1}", Environment.GetEnvironmentVariable("WINDIR"), "explorer.exe");
                                                Process process  = new Process();
                                                process.StartInfo.FileName       = explorer;
                                                process.StartInfo.CreateNoWindow = true;
                                                // process.StartInfo.UseShellExecute = true;
                                                process.Start();

                                                var fileName          = Assembly.GetExecutingAssembly().Location;
                                                ProcessStartInfo info = new ProcessStartInfo();
                                                info.FileName       = fileName;
                                                info.CreateNoWindow = true;

                                                Process p = new Process();
                                                p.StartInfo = info;
                                                p.Start();

                                                Environment.Exit(0);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    Thread.Sleep(3000);
                }
                catch (Exception e)
                {
                }
            }
        }
Example #25
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 void CheckBackgroundChange()
        {
            var DataKit = new DataKit();

            while (true)
            {
                DataKit.Realm.Refresh();
                var backgroundSetting = DataKit.Realm.All <BackgroundSettingsByMonitor>().Where(c => c.MonitorDeviceName == HangulClockRenderer.MonitorDeviceName).First();

                bool isSolid   = backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.SOLID;
                bool isYoutube = backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.YOUTUBE_VIDEO;

                // caption-window;
                if (isYoutube)
                {
                    youtubeView.GetBrowser().MainFrame.EvaluateScriptAsync("if (typeof css === 'undefined') { var css = '.ytp-caption-window-bottom { display: none !important }', head = document.head, style = document.createElement('style'); style.type = 'text/css'; style.appendChild(document.createTextNode(css)); head.appendChild(style); }");
                    youtubeView.GetBrowser().MainFrame.EvaluateScriptAsync("if (typeof css2 === 'undefined') { var css2 = '.video-annotations { display: none !important }', head = document.head, style = document.createElement('style'); style.type = 'text/css'; style.appendChild(document.createTextNode(css2)); head.appendChild(style); }");
                }

                this.Dispatcher.Invoke(new Action(() =>
                {
                    if (!isSolid)
                    {
                        BrushConverter bc      = new BrushConverter();
                        overlayView.Background = (Brush)bc.ConvertFrom("#10000000");
                    }
                }));

                if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.DEFAULT)
                {
                    string path = DesktopWallpaperGenerator.GetBackgroud();

                    if (systemBackgroundPath != path)
                    {
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            backgroundImage.Source = new BitmapImage(new Uri(path));

                            youtubeView.Address    = "";
                            youtubeView.Visibility = Visibility.Hidden;
                        }));

                        systemBackgroundPath = path;
                        backgroundPath       = "";
                        youtubeVCode         = "";
                        solidColor           = "";
                    }
                }
                else if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.STILL_IMAGE)
                {
                    string path = backgroundSetting.imgPath;

                    if (File.Exists(path))
                    {
                        if (backgroundPath != path)
                        {
                            backgroundPath = backgroundSetting.imgPath;

                            this.Dispatcher.Invoke(new Action(() =>
                            {
                                if (File.Exists(backgroundPath))
                                {
                                    backgroundImage.Source = new BitmapImage(new Uri(backgroundPath));
                                }
                                else
                                {
                                    systemBackgroundPath   = DesktopWallpaperGenerator.GetBackgroud();
                                    backgroundImage.Source = new BitmapImage(new Uri(systemBackgroundPath));
                                }

                                BrushConverter bc      = new BrushConverter();
                                overlayView.Background = (Brush)bc.ConvertFrom("#10000000");

                                youtubeView.Address    = "";
                                youtubeView.Visibility = Visibility.Hidden;

                                systemBackgroundPath = "";
                                youtubeVCode         = "";
                                solidColor           = "";
                            }));
                        }
                    }
                    else
                    {
                        string spath = DesktopWallpaperGenerator.GetBackgroud();

                        if (systemBackgroundPath != spath)
                        {
                            this.Dispatcher.Invoke(new Action(() =>
                            {
                                backgroundImage.Source = new BitmapImage(new Uri(spath));

                                systemBackgroundPath = spath;

                                youtubeView.Address    = "";
                                youtubeView.Visibility = Visibility.Hidden;
                            }));

                            backgroundPath = "";
                            youtubeVCode   = "";
                            solidColor     = "";
                        }
                    }
                }
                else if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.SOLID)
                {
                    string solid = backgroundSetting.SolidColor;

                    if (solidColor != solid)
                    {
                        solidColor = solid;
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            // backgroundImage.Source = null;

                            BrushConverter bc      = new BrushConverter();
                            overlayView.Background = (Brush)bc.ConvertFrom("#" + solidColor);

                            youtubeView.Address    = "";
                            youtubeView.Visibility = Visibility.Hidden;

                            systemBackgroundPath = "";
                            backgroundPath       = "";
                            youtubeVCode         = "";
                        }));
                    }
                }
                else
                {
                    string youtubeVideo = backgroundSetting.YoutubeURL;

                    if (youtubeVCode != youtubeVideo)
                    {
                        youtubeVCode = youtubeVideo;
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            if (youtubeVideo == "" || youtubeVideo == null)
                            {
                                backgroundPath         = DesktopWallpaperGenerator.GetBackgroud();
                                backgroundImage.Source = new BitmapImage(new Uri(backgroundPath));
                            }
                            else
                            {
                                youtubeView.Visibility = Visibility.Visible;
                                youtubeView.Address    = String.Format("https://www.youtube.com/embed/{0}?controls=0&showinfo=0&rel=0&autoplay=1&loop=1&mute=1&cc_load_policy=3&playlist={0}", youtubeVCode);
                                // youtubeView.GetBrowser().MainFrame.EvaluateScriptAsync("setInterval(() => { document.getElementsByClassName('caption-window ytp-caption-window-bottom')[0].style.display = 'none'; console.clear(); }, 100);");
                            }

                            BrushConverter bc      = new BrushConverter();
                            overlayView.Background = (Brush)bc.ConvertFrom("#10000000");

                            systemBackgroundPath = "";
                            backgroundPath       = "";
                            solidColor           = "";
                        }));
                    }
                }

                // Console.WriteLine("Communicating HangulClock Data Kit...");

                try
                {
                    Thread.Sleep(5000);
                }
                catch (ThreadInterruptedException e)
                {
                }
            }
        }
        public HangulClockDesktop()
        {
            InitializeComponent();

            new Thread(() =>
            {
                var DataKit           = new DataKit();
                var backgroundSetting = DataKit.Realm.All <BackgroundSettingsByMonitor>().Where(c => c.MonitorDeviceName == HangulClockRenderer.MonitorDeviceName).First();

                if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.DEFAULT)
                {
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        systemBackgroundPath   = DesktopWallpaperGenerator.GetBackgroud();
                        backgroundImage.Source = new BitmapImage(new Uri(systemBackgroundPath));

                        youtubeView.Address    = "";
                        youtubeView.Visibility = Visibility.Hidden;
                    }));
                }
                else if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.STILL_IMAGE)
                {
                    backgroundPath = backgroundSetting.imgPath;

                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        if (File.Exists(backgroundPath))
                        {
                            backgroundImage.Source = new BitmapImage(new Uri(backgroundPath));
                        }
                        else
                        {
                            systemBackgroundPath   = DesktopWallpaperGenerator.GetBackgroud();
                            backgroundImage.Source = new BitmapImage(new Uri(systemBackgroundPath));
                        }

                        youtubeView.Address    = "";
                        youtubeView.Visibility = Visibility.Hidden;
                    }));
                }
                else if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.SOLID)
                {
                    solidColor = backgroundSetting.SolidColor;
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        // backgroundImage.Source = null;
                        BrushConverter bc = new BrushConverter();

                        if (solidColor != null && solidColor != "")
                        {
                            overlayView.Background = (Brush)bc.ConvertFrom("#" + solidColor);
                        }
                        else
                        {
                            overlayView.Background = (Brush)bc.ConvertFrom("#000000");
                        }

                        youtubeView.Address    = "";
                        youtubeView.Visibility = Visibility.Hidden;
                    }));
                }
                else
                {
                    youtubeVCode = backgroundSetting.YoutubeURL;
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        if (youtubeVCode == "" || youtubeVCode == null)
                        {
                            backgroundPath         = DesktopWallpaperGenerator.GetBackgroud();
                            backgroundImage.Source = new BitmapImage(new Uri(backgroundPath));
                        }
                        else
                        {
                            youtubeView.Visibility = Visibility.Visible;
                            youtubeView.Address    = String.Format("https://www.youtube.com/embed/{0}?controls=0&showinfo=0&rel=0&autoplay=1&loop=1&cc_load_policy=3&mute=1&playlist={0}", youtubeVCode);
                        }
                    }));
                }

                new Thread(CheckBackgroundChange).Start();
            }).Start();
        }
        private static void MainThread()
        {
            var DataKit = new DataKit();

            while (true)
            {
                try
                {
                    DataKit.Realm.Refresh();

                    var clockSetting   = DataKit.Realm.All <ClockSettingsByMonitor>().Where(c => c.MonitorDeviceName == MonitorDeviceName).First();
                    var 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 e)
                    {
                    }

                    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 e)
                {
                }
            }
        }