コード例 #1
0
        private void EventDeviceSelectionChanged(object sender, RoutedEventArgs e)
        {
            if (comboBoxDevices.SelectedIndex == -1)
            {
                return;
            }

            DeviceUpnp device = (DeviceUpnp)comboBoxDevices.SelectedItem;

            uglyNameTextBox.Text = ViewerManager.GetUglyName(device.Udn);
        }
コード例 #2
0
        private void EventOkButtonClicked(object sender, RoutedEventArgs e)
        {
            if (uglyNameTextBox.Text == "")
            {
                MessageBox.Show("You must enter an ugly name or select one from the text box", "No Device Selected",
                                MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            if (!ViewerManager.IsValidUglyName(uglyNameTextBox.Text))
            {
                ShowUglyNameParseError();
            }

            DialogResult = true;
            iUglyName    = uglyNameTextBox.Text;
            this.Close();
        }
コード例 #3
0
        public WindowMain()
        {
            InitializeComponent();
            bool instantiated;

            iInstanceMutex = new Mutex(false, "ViewerMutex", out instantiated);
            if (!instantiated)
            {
                MessageBox.Show("Another instance of Viewer is already running. Please close all other instances and try again.", "Viewer is already running", MessageBoxButton.OK, MessageBoxImage.Warning);
                Application.Current.Shutdown();
            }

            iDebugLevels = new SortedList <string, DebugLevelItem>();
            UInt32 debugLevel;

            iDebugLevels.Add("Store", new DebugLevelItem("Store", debugLevel            = 1));
            iDebugLevels.Add("Flash", new DebugLevelItem("Flash", debugLevel           *= 2));
            iDebugLevels.Add("Common", new DebugLevelItem("Common", debugLevel         *= 2));
            iDebugLevels.Add("Boot", new DebugLevelItem("Boot", debugLevel             *= 2));
            iDebugLevels.Add("Thread", new DebugLevelItem("Thread", debugLevel         *= 2));
            iDebugLevels.Add("Bsp", new DebugLevelItem("Bsp", debugLevel               *= 2));
            iDebugLevels.Add("Network", new DebugLevelItem("Network", debugLevel       *= 2));
            iDebugLevels.Add("Event", new DebugLevelItem("Event", debugLevel           *= 2));
            iDebugLevels.Add("SysLib", new DebugLevelItem("SysLib", debugLevel         *= 2));
            iDebugLevels.Add("UpnpDevice", new DebugLevelItem("UpnpDevice", debugLevel *= 2));
            iDebugLevels.Add("Sdp", new DebugLevelItem("Sdp", debugLevel               *= 2));
            iDebugLevels.Add("Ess", new DebugLevelItem("Ess", debugLevel               *= 2));
            iDebugLevels.Add("Power", new DebugLevelItem("Power", debugLevel           *= 2));
            iDebugLevels.Add("Http", new DebugLevelItem("Http", debugLevel             *= 2));
            iDebugLevels.Add("Upnp", new DebugLevelItem("Upnp", debugLevel             *= 2));
            iDebugLevels.Add("Preamp", new DebugLevelItem("Preamp", debugLevel         *= 2));
            iDebugLevels.Add("Logical", new DebugLevelItem("Logical", debugLevel       *= 2));
            iDebugLevels.Add("Viewer", new DebugLevelItem("Viewer", debugLevel         *= 2));
            iDebugLevels.Add("Ui", new DebugLevelItem("Ui", debugLevel               *= 2));
            iDebugLevels.Add("Isr", new DebugLevelItem("Isr", debugLevel             *= 2));
            iDebugLevels.Add("Core", new DebugLevelItem("Core", debugLevel           *= 2));
            iDebugLevels.Add("Media", new DebugLevelItem("Media", debugLevel         *= 2));
            iDebugLevels.Add("Dac", new DebugLevelItem("Dac", debugLevel             *= 2));
            iDebugLevels.Add("Products", new DebugLevelItem("Products", debugLevel   *= 2));
            iDebugLevels.Add("Mechanism", new DebugLevelItem("Mechanism", debugLevel *= 2));
            iDebugLevels.Add("Bonjour", new DebugLevelItem("Bonjour", debugLevel     *= 2));
            iDebugLevels.Add("Ssdp", new DebugLevelItem("Ssdp", debugLevel           *= 2));
            iDebugLevels.Add("Queue", new DebugLevelItem("Queue", debugLevel         *= 2));
            iDebugLevels.Add("Codec", new DebugLevelItem("Codec", debugLevel         *= 4)); //skipping deprecated option here.
            iDebugLevels.Add("Control", new DebugLevelItem("Control", debugLevel     *= 2));
            iDebugLevels.Add("Verbose", new DebugLevelItem("Verbose", debugLevel     *= 2));
            foreach (DebugLevelItem i in iDebugLevels.Values)
            {
                i.PropertyChanged += EventDebugLevelChanged;
            }
            listBoxDebugLevel.ItemsSource = iDebugLevels.Values;
            DisableDebugLevels();
            this.DataContext = this;

            iInitParams = new InitParams();
            iLibrary    = new Library();
            iLibrary.Initialise(ref iInitParams);
            iLibrary.StartCp();
            iSubnetList = new SubnetList(iInitParams, Dispatcher, iLibrary);
            iDeviceList = new DeviceListUpnp("linn.co.uk", "Volkano", 1, this.Dispatcher);

            comboBoxSubnets.ItemsSource       = iSubnetList;
            comboBoxSubnets.SelectionChanged += EventSubnetSelectionChanged;

            iActivityLightTimer.Interval  = iActivityLightTimerTimeout;
            iActivityLightTimer.Elapsed  += EventActivityLightTimerExpired;
            iActivityLightTimer.AutoReset = false;

            iDelayMutexReleaseTimer.Interval  = iDelayMutexReleaseTimerTimeout;
            iDelayMutexReleaseTimer.Elapsed  += EventDelayMutexReleaseTimerExpired;
            iDelayMutexReleaseTimer.AutoReset = false;

            iRetryConnectTimer.Interval  = iRetryConnectTimerTimeout;
            iRetryConnectTimer.Elapsed  += EventRetryConnectTimerExpired;
            iRetryConnectTimer.AutoReset = true;

            MainWindow.Closing += new CancelEventHandler(this.EventWindowMainClosing);

            iViewerManager = new ViewerManager();
            iViewerManager.ViewerOutputAvailable += EventViewerOutputAvailable;
            iViewerManager.ConnectionAccepted    += EventConnectionAccepted;
            iViewerManager.ConnectionClosed      += EventConnectionClosed;
            iViewerManager.ConnectionRefused     += EventConnectionRefused;
            iViewerManager.ServicesAvailable     += EventServicesAvailable;
            iViewerManager.ServicesUnavailable   += EventServicesUnavailable;

            terminal.MaxVisibleLinesCountChanged += EventMaxVisibleLinesCountChanged;

            if (!Directory.Exists(iAppDataDir))
            {
                Directory.CreateDirectory(iAppDataDir);
            }

            iMainLogFile     = iAppDataDir + "\\Viewer-log.txt";
            iMainLogFileCopy = iAppDataDir + "\\Viewer-log-copy.txt";
            iTempLogFile     = iAppDataDir + "\\Viewer-log-Temp.txt";
            iSettingsFile    = iAppDataDir + "\\Viewer-Settings.txt";

            //Wipe the log file clean.
            if (!File.Exists(iMainLogFile))
            {
                iLogFileMutex.WaitOne();
                File.WriteAllText(iMainLogFile, "", new System.Text.UTF8Encoding());
                iLogFileMutex.ReleaseMutex();
            }

            if (File.Exists(iSettingsFile))
            {
                try
                {
                    iUserSettings = UserSettings.ReadSettingsFromFile(iSettingsFile);
                }
                catch (InvalidOperationException)
                {
                    iUserSettings = new UserSettings();
                    AppendToMainWindow("Settings file is corrupt, deleting...");
                    File.WriteAllText(iSettingsFile, "", new System.Text.UTF8Encoding());
                }
                catch (FileFormatException)
                {
                    iUserSettings = new UserSettings();
                    AppendToMainWindow("Settings file is corrupt, deleting...");
                    File.WriteAllText(iSettingsFile, "", new System.Text.UTF8Encoding());
                }
            }
            else
            {
                iUserSettings = new UserSettings();
            }
            if (iUserSettings.SelectedSubnet >= iSubnetList.length)
            {
                iUserSettings.SelectedSubnet = iSubnetList.length - 1;
            }
            comboBoxSubnets.SelectedIndex = iUserSettings.SelectedSubnet;
            iLibrary.SetCurrentSubnet(((Subnet)comboBoxSubnets.SelectedItem).Handle);
            if (!iUserSettings.UglyName.Equals(""))
            {
                selectDeviceButton.Content = iUserSettings.UglyName;
            }
            Connect(iUserSettings.UglyName);
        }