private void SelectedPrinterChangeEvent(object sender, SelectionChangedEventArgs e)
        {
            if (viewModel != null)
            {
                if (SelectedPrinterComboBox.SelectedIndex == 0)
                {
                    ShowPrinterDiscoveryWindow();
                }
                else
                {
                    if (printerDiscoveryWindow != null)
                    {
                        printerDiscoveryWindow.Close();
                        printerDiscoveryWindow = null;
                    }

                    if (PrinterTemplatesListView.Visibility == Visibility.Collapsed)
                    {
                        PrinterTemplatesListView.Visibility  = Visibility.Visible;
                        RefreshTemplates_MenuItem.Visibility = Visibility.Visible;
                        SetTemplateDir_MenuItem.Visibility   = Visibility.Visible;
                        TemplateGrid.Visibility = Visibility.Collapsed;
                    }

                    dynamic selectedItem = SelectedPrinterComboBox.SelectedItem;
                    if (!previousPrinters.ContainsKey(selectedItem.Address) && previousPrinters.Count >= 5)
                    {
                        string removeKey = viewModel.RecentlySelectedPrinters.Last.Value.Address;
                        previousPrinters.Remove(removeKey);
                        viewModel.RecentlySelectedPrinters.RemoveLast();
                    }

                    if (previousPrinters.ContainsKey(Properties.Settings.Default.IpAddress))
                    {
                        previousPrinters.Remove(Properties.Settings.Default.IpAddress);
                    }

                    previousPrinters.Add(Properties.Settings.Default.IpAddress, Properties.Settings.Default.Model);
                    Properties.Settings.Default.Model     = selectedItem.Model;
                    Properties.Settings.Default.IpAddress = selectedItem.Address;

                    if (previousPrinters.ContainsKey(selectedItem.Address))
                    {
                        previousPrinters.Remove(selectedItem.Address);
                    }

                    SetSelectedConnection(selectedItem);
                    if (viewModel.TemplateNames.Count == 0)
                    {
                        RefreshTemplates();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void ShowPrinterDiscovery()
        {
            if (PrinterFormatsListView.Items.Count > 0)
            {
                PrinterFormatsListView.Items.Clear();
            }

            printerDiscoveryWindow = new PrinterDiscoveryWindow()
            {
                Topmost = true
            };

            IsEnabled = false;
            printerDiscoveryWindow.Closed += PrinterDiscoveryWindow_Closed;

            if (printerDiscoveryWindow.ShowDialog() == false)
            {
                if (printerDiscoveryWindow != null)
                {
                    PrinterInfo selectedPrinter = printerDiscoveryWindow.SelectedPrinterInfo;
                    if (selectedPrinter.Address != null && selectedPrinter.FriendlyName != null)
                    {
                        LinkedListNode <PrinterInfo> node = recentlySelectedPrinters.First;
                        while (node != null)
                        {
                            PrinterInfo printerInfo = node.Value;
                            if (printerInfo.Address.Equals(selectedPrinter.Address))
                            {
                                if (!printerInfo.FriendlyName.Equals(selectedPrinter.FriendlyName))
                                {
                                    printerInfo.FriendlyName = selectedPrinter.FriendlyName;
                                    node.Value = printerInfo;
                                }
                                SelectedPrinterComboBox.SelectedItem = printerInfo;
                                return;
                            }
                            node = node.Next;
                        }

                        string previousPrinterIp = Properties.Settings.Default.IpAddress;
                        if (previousPrinterIp.Length > 0)
                        {
                            previousPrinters.Add(previousPrinterIp, Properties.Settings.Default.FriendlyName);
                        }

                        printerFriendlyName = selectedPrinter.FriendlyName;
                        printerIpAddress    = selectedPrinter.Address;
                        SetSelectedPrinter(printerFriendlyName, printerIpAddress);
                    }
                    printerDiscoveryWindow = null;
                }
            }
        }
Ejemplo n.º 3
0
        private void SelectedPrinterChangeEvent(object sender, SelectionChangedEventArgs e)
        {
            if (SelectedPrinterComboBox.SelectedIndex == 0)
            {
                ShowPrinterDiscovery();
            }
            else
            {
                if (printerDiscoveryWindow != null)
                {
                    printerDiscoveryWindow.Close();
                    printerDiscoveryWindow = null;
                }

                if (PrinterFormatsListView.Visibility == Visibility.Hidden)
                {
                    PrinterFormatsListView.Visibility = Visibility.Visible;
                    FormatGrid.Visibility             = Visibility.Hidden;
                }

                dynamic selectedItem = SelectedPrinterComboBox.SelectedItem;
                if (PrinterFormatsListView.Items.Count > 0)
                {
                    PrinterFormatsListView.Items.Clear();
                }

                if (!previousPrinters.ContainsKey(selectedItem.Address) && previousPrinters.Count >= 5)
                {
                    string removeKey = recentlySelectedPrinters.Last.Value.Address;
                    previousPrinters.Remove(removeKey);
                    recentlySelectedPrinters.RemoveLast();
                }

                if (previousPrinters.ContainsKey(Properties.Settings.Default.IpAddress))
                {
                    previousPrinters.Remove(Properties.Settings.Default.IpAddress);
                }

                previousPrinters.Add(Properties.Settings.Default.IpAddress, Properties.Settings.Default.FriendlyName);
                Properties.Settings.Default.FriendlyName = selectedItem.FriendlyName;
                Properties.Settings.Default.IpAddress    = selectedItem.Address;

                if (previousPrinters.ContainsKey(selectedItem.Address))
                {
                    previousPrinters.Remove(selectedItem.Address);
                }

                SetSelectedConnection(selectedItem);
            }
        }
        public void ShowPrinterDiscoveryWindow()
        {
            printerDiscoveryWindow = new PrinterDiscoveryWindow()
            {
                Topmost = true
            };

            if (printerDiscoveryWindow.ShowDialog() == false)
            {
                if (printerDiscoveryWindow != null)
                {
                    Util.PrinterInfo selectedPrinter = printerDiscoveryWindow.SelectedPrinterInfo;
                    if (selectedPrinter.Address != null && selectedPrinter.Model != null && viewModel != null)
                    {
                        LinkedListNode <Util.PrinterInfo> node = viewModel.RecentlySelectedPrinters.First;
                        while (node != null)
                        {
                            Util.PrinterInfo printerInfo = node.Value;
                            if (printerInfo.Address.Equals(selectedPrinter.Address))
                            {
                                if (!printerInfo.Model.Equals(selectedPrinter.Model))
                                {
                                    printerInfo.Model = selectedPrinter.Model;
                                    node.Value        = printerInfo;
                                }
                                SelectedPrinterComboBox.SelectedItem = printerInfo;
                                return;
                            }
                            node = node.Next;
                        }

                        string previousPrinterIp = Properties.Settings.Default.IpAddress;
                        if (previousPrinterIp.Length > 0)
                        {
                            previousPrinters.Add(previousPrinterIp, Properties.Settings.Default.Model);
                        }

                        viewModel.RecentlySelectedPrinters.AddAfter(viewModel.RecentlySelectedPrinters.First, selectedPrinter);
                        viewModel.SelectedPrinter = selectedPrinter;
                    }
                    printerDiscoveryWindow = null;
                }
            }
        }
Ejemplo n.º 5
0
        public MainWindow()
        {
            Closed += OnClosing;
            InitializeComponent();

            if (PrinterDiscoveryWindow.IsBluetoothSupported())
            {
                nfcHelper = new NFCHelper(this, SelectedPrinterComboBox);
                nfcHelper.SubscribeForNfcMessage();
            }

            formatInfo    = new List <Dictionary <string, string> >();
            attributeKeys = new List <string> {
                "drive",
                "name",
                "extension",
                "star"
            };

            recentlySelectedPrinters = new LinkedList <PrinterInfo>();
            selectAPrinterNode       = new LinkedListNode <PrinterInfo>(new PrinterInfo("Select a Printer", ""));
            recentlySelectedPrinters.AddFirst(selectAPrinterNode);

            if (!string.IsNullOrEmpty(Properties.Settings.Default.PreviousPrinters))
            {
                previousPrinters = JsonConvert.DeserializeObject <Dictionary <string, string> >(Properties.Settings.Default.PreviousPrinters);
                foreach (string address in previousPrinters.Keys)
                {
                    if (address.Length > 0)
                    {
                        recentlySelectedPrinters.AddAfter(selectAPrinterNode, new PrinterInfo(previousPrinters[address], address));
                    }
                }
            }

            SelectedPrinterComboBox.ItemsSource = recentlySelectedPrinters;
            if (previousPrinters == null)
            {
                previousPrinters = new Dictionary <string, string>();
            }
        }
Ejemplo n.º 6
0
        public BluetoothHelpWindow()
        {
            InitializeComponent();
            SupportedWindowsVersionsTextBlock.Text = supportedWindowsVersionsText;

            Run btSecurityTextBeginningRun = new Run()
            {
                Text = bluetoothSecurityTextBeginning
            };

            Run bluetoothSettingsRun = new Run()
            {
                Text = "Settings > Bluetooth"
            };

            Hyperlink bluetoothSettingsHyperlink = new Hyperlink(bluetoothSettingsRun)
            {
                NavigateUri = new Uri("ms-settings:bluetooth")
            };

            bluetoothSettingsHyperlink.RequestNavigate += BluetoothHyperlink_RequestNavigate;

            Run btSecurityTextEndRun = new Run()
            {
                Text = bluetoothSecurityTextEnding
            };

            BluetoothHelpTextBlock.Inlines.Add(btSecurityTextBeginningRun);
            if (PrinterDiscoveryWindow.IsBluetoothSupported())
            {
                BluetoothHelpTextBlock.Inlines.Add(bluetoothSettingsHyperlink);
            }
            else
            {
                BluetoothHelpTextBlock.Inlines.Add(bluetoothSettingsRun);
            }
            BluetoothHelpTextBlock.Inlines.Add(btSecurityTextEndRun);
        }