示例#1
0
        void OpenConnectDialog()
        {
            if (connectTimer != null) return;

            var dlg = new ConnectWindow();
            dlg.Owner = CommonUtil.GetTopWindow(this);
            if (dlg.ShowDialog() == true)
            {
                ConnectCmd(true);
            }
            else if (CommonManager.Instance.IsConnected == false)
            {
                InitializeClient();
            }
        }
示例#2
0
        bool ConnectCmd(bool reloadFlag)
        {
            ConnectWindow dlg = new ConnectWindow();
            PresentationSource topWindow = PresentationSource.FromVisual(this);
            if (topWindow != null)
            {
                dlg.Owner = (Window)topWindow.RootVisual;
            }
            if (dlg.ShowDialog() == true)
            {
                bool connected = false;
                String srvIP = Settings.Instance.NWServerIP;
                try
                {
                    foreach (IPAddress address in Dns.GetHostAddresses(srvIP))
                    {
                        srvIP = address.ToString();
                        if (CommonManager.Instance.NW.ConnectServer(srvIP, Settings.Instance.NWServerPort, Settings.Instance.NWWaitPort, OutsideCmdCallback, this) == true)
                        {
                            connected = true;
                            break;
                        }
                    }
                }
                catch
                {
                }

                if (connected == false)
                {
                    MessageBox.Show("サーバーへの接続に失敗しました");
                }
                else
                {
                    if (reloadFlag == true)
                    {
                        byte[] binData;
                        if (cmd.SendFileCopy("ChSet5.txt", out binData) == 1)
                        {
                            string filePath = SettingPath.SettingFolderPath;
                            System.IO.Directory.CreateDirectory(filePath);
                            filePath += "\\ChSet5.txt";
                            using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(System.IO.File.Create(filePath)))
                            {
                                w.Write(binData);
                                w.Close();
                            }
                            ChSet5.LoadFile();
                        }
                        CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.ReserveInfo);
                        CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.RecInfo);
                        CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.AutoAddEpgInfo);
                        CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.AutoAddManualInfo);
                        CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.EpgData);
                        CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.PlugInFile);
                        reserveView.UpdateReserveData();
                        epgView.UpdateReserveData();
                        tunerReserveView.UpdateReserveData();
                        autoAddView.UpdateAutoAddInfo();
                        recInfoView.UpdateInfo();
                        epgView.UpdateEpgData();
                    }

                    return true;
                }
            }
            return false;
        }
示例#3
0
        bool ConnectCmd(bool showDialog)
        {
            IniSetting.Instance.Clear();

            bool reconnect = true;

            if (showDialog == true)
            {
                ConnectWindow dlg = new ConnectWindow();
                PresentationSource topWindow = PresentationSource.FromVisual(this);
                if (topWindow != null)
                {
                    dlg.Owner = (Window)topWindow.RootVisual;
                }
                reconnect = dlg.ShowDialog() == true;
            }

            serviceMode = ServiceCtrlClass.ServiceIsInstalled("EpgTimer Service");
            if (reconnect)
            {
                Title = appName;

                DisconnectServer();

                CommonManager.Instance.DB.SetNoAutoReloadEPG(Settings.Instance.NgAutoEpgLoadNW);
                ChkRegistTCPTimerWork();

                if (Settings.Instance.NWMode == false)
                {
                    bool startExe = false;
                    try
                    {
                        if (System.Diagnostics.Process.GetProcessesByName("EpgTimerSrv").Count() == 0)
                        {
                            if (serviceMode == true)
                            {
                                if (ServiceCtrlClass.IsStarted("EpgTimer Service") == false)
                                {
                                    ServiceCtrlClass.StartService("EpgTimer Service");
                                    int count = 5;
                                    do
                                    {
                                        System.Threading.Thread.Sleep(1000);
                                    }
                                    while (ServiceCtrlClass.IsStarted("EpgTimer Service") == false && --count > 0);
                                    if (count == 0)
                                    {
                                        MessageBox.Show("サービスの開始に失敗しました。\r\nVista以降のOSでは、管理者権限で起動されている必要があります。");
                                    }
                                    else
                                    {
                                        startExe = true;
                                    }
                                }
                                else
                                {
                                    startExe = true;
                                }
                            }
                            else
                            {
                                String moduleFolder = SettingPath.ModulePath.TrimEnd('\\');
                                String exePath = moduleFolder + "\\EpgTimerSrv.exe";
                                if (System.IO.File.Exists(exePath))
                                {
                                    System.Diagnostics.Process process = System.Diagnostics.Process.Start(exePath);
                                    startExe = true;
                                }
                                else if (showDialog == true)
                                {
                                    MessageBox.Show("EpgTimerSrv.exeの起動ができませんでした");
                                }
                            }
                        }
                        else
                        {
                            startExe = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
                        serviceMode = false;
                        startExe = false;
                    }

                    if (startExe == true)
                    {
                        CommonManager.Instance.DB.SetNoAutoReloadEPG(false);
                        CommonManager.Instance.NWMode = false;
                        cmd.SetSendMode(false);

                        pipeServer = new PipeServer();
                        pipeServer.StartServer(pipeEventName, pipeName, (c, r) => OutsideCmdCallback(c, r, false));

                        ErrCode err = ErrCode.CMD_SUCCESS;
                        for (int i = 0; i < 150 && (err = cmd.SendRegistGUI((uint)System.Diagnostics.Process.GetCurrentProcess().Id)) != ErrCode.CMD_SUCCESS; i++)
                        {
                            Thread.Sleep(100);
                        }
                        CommonManager.Instance.IsConnected = (err == ErrCode.CMD_SUCCESS);
                    }
                    else
                    {
                        CommonManager.Instance.NWMode = true; // ローカル接続できないのでネットワークモードとして動作させる
                        cmd.SetSendMode(true);
                        CommonManager.Instance.IsConnected = false;
                    }
                }
                else
                {
                    try
                    {
                        foreach (var address in System.Net.Dns.GetHostAddresses(Settings.Instance.NWServerIP))
                        {
                            if (address.IsIPv6LinkLocal == false &&
                                CommonManager.Instance.NW.ConnectServer(address, Settings.Instance.NWServerPort, Settings.Instance.NWWaitPort, (c, r) => OutsideCmdCallback(c, r, true)) == true)
                            {
                                CommonManager.Instance.IsConnected = CommonManager.Instance.NW.IsConnected;
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                    if (CommonManager.Instance.IsConnected == false)
                    {
                        if (showDialog == true)
                        {
                            MessageBox.Show("サーバーへの接続に失敗しました");
                        }
                        cmd.SetNWSetting("", 0);
                    }
                }

                IniFileHandler.UpdateSrvProfileIniNW();

                CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.ReserveInfo);
                CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.RecInfo);
                CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.AutoAddEpgInfo);
                CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.AutoAddManualInfo);
                CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.EpgData);
                CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.PlugInFile);
                CommonManager.Instance.DB.ReloadReserveInfo();
                CommonManager.Instance.DB.ReloadEpgData();
                reserveView.UpdateInfo();
                tunerReserveView.UpdateInfo();
                autoAddView.UpdateAutoAddInfo();
                recInfoView.UpdateInfo();
                epgView.UpdateEpgData();
                SearchWindow.UpdatesInfo();
                recLogView.onConnected(this);
                searchLogView.onConnected(recLogView);
            }

            if (CommonManager.Instance.IsConnected)
            {
                ChSet5.Clear();

                if (CommonManager.Instance.NWMode)
                {
                    Title = appName + " - " + Settings.Instance.NWServerIP + ":" + Settings.Instance.NWServerPort.ToString();
                }
                else
                {
                    Title = appName + " - ローカル接続";
                }
            }
            else
            {
                Title = appName + " - 未接続";
            }
            return CommonManager.Instance.IsConnected;
        }