diff --git a/ZSDK_DevDemos_.NET/App.config b/ZSDK_DevDemos_.NET/App.config new file mode 100644 index 0000000..9d2c7ad --- /dev/null +++ b/ZSDK_DevDemos_.NET/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/ZSDK_DevDemos_.NET/DeveloperDemo_Windows.csproj b/ZSDK_DevDemos_.NET/DeveloperDemo_Windows.csproj new file mode 100644 index 0000000..333e79c --- /dev/null +++ b/ZSDK_DevDemos_.NET/DeveloperDemo_Windows.csproj @@ -0,0 +1,308 @@ + + + + + Debug + AnyCPU + {8B42A994-831D-4EAF-B40F-436166CD5B6A} + WinExe + Zebra.Windows.DevDemo + DeveloperDemo_Windows + v4.7 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + Zebra\Windows\DevDemo\zebralogo.ico + + + app.manifest + + + + Sdk\BouncyCastle.Crypto.dll + + + Sdk\CoreFtp.dll + + + Sdk\CsvHelper.dll + + + Sdk\Microsoft.Extensions.Caching.Abstractions.dll + + + Sdk\Microsoft.Extensions.Caching.Memory.dll + + + Sdk\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + Sdk\Microsoft.Extensions.Logging.Abstractions.dll + + + Sdk\Microsoft.Extensions.Options.dll + + + Sdk\Microsoft.Extensions.Primitives.dll + + + False + Sdk\Newtonsoft.Json.dll + + + Sdk\SdkApi_Core.dll + + + Sdk\SdkApi_Desktop.dll + + + Sdk\SdkApi_Desktop_Usb.dll + + + + + + Sdk\System.Runtime.dll + + + False + Sdk\System.Runtime.WindowsRuntime.dll + + + + + + + + + 4.0 + + + False + Sdk\Windows.winmd + + + + + + + + MSBuild:Compile + Designer + + + ConnectionBuilderView.xaml + + + + + ImagePrintView.xaml + + + + ListFormatsView.xaml + + + + MagCardView.xaml + + + + PrinterStatusView.xaml + + + + ProfileView.xaml + + + + SendFileView.xaml + + + + + SettingsView.xaml + + + + SmartCardView.xaml + + + + + StoredFormatView.xaml + + + + AboutDialog.xaml + + + StoredFormatDialog.xaml + + + + + + + + ConnectionSelectorView.xaml + + + FileSelectorView.xaml + + + + + + + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + ConnectivityView.xaml + + + + DiscoveryView.xaml + + + + + MainWindow.xaml + Code + + + Designer + MSBuild:Compile + + + MSBuild:Compile + Designer + + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + Designer + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ZSDK_DevDemos_.NET/Properties/AssemblyInfo.cs b/ZSDK_DevDemos_.NET/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3758294 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("DeveloperDemo_Windows")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DeveloperDemo_Windows")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ZSDK_DevDemos_.NET/Properties/Resources.Designer.cs b/ZSDK_DevDemos_.NET/Properties/Resources.Designer.cs new file mode 100644 index 0000000..b2ccb05 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Zebra.Windows.DevDemo.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Zebra.Windows.DevDemo.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/ZSDK_DevDemos_.NET/Properties/Resources.resx b/ZSDK_DevDemos_.NET/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/ZSDK_DevDemos_.NET/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ZSDK_DevDemos_.NET/Properties/Settings.Designer.cs b/ZSDK_DevDemos_.NET/Properties/Settings.Designer.cs new file mode 100644 index 0000000..a841441 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Zebra.Windows.DevDemo.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/ZSDK_DevDemos_.NET/Properties/Settings.settings b/ZSDK_DevDemos_.NET/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/ZSDK_DevDemos_.NET/Resources/Images/Zebra_Logo_K.png b/ZSDK_DevDemos_.NET/Resources/Images/Zebra_Logo_K.png new file mode 100644 index 0000000..fd3a651 Binary files /dev/null and b/ZSDK_DevDemos_.NET/Resources/Images/Zebra_Logo_K.png differ diff --git a/ZSDK_DevDemos_.NET/Resources/Images/Zebra_Logo_W.png b/ZSDK_DevDemos_.NET/Resources/Images/Zebra_Logo_W.png new file mode 100644 index 0000000..e54838a Binary files /dev/null and b/ZSDK_DevDemos_.NET/Resources/Images/Zebra_Logo_W.png differ diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/App.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/App.xaml new file mode 100644 index 0000000..4b57360 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/App.xaml @@ -0,0 +1,59 @@ + + + + + + + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/App.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/App.xaml.cs new file mode 100644 index 0000000..1106bcf --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/App.xaml.cs @@ -0,0 +1,24 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Windows; + +namespace Zebra.Windows.DevDemo { + + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application { + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionBuilderView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionBuilderView.xaml new file mode 100644 index 0000000..d9efeb0 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionBuilderView.xaml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + Connection Builder + Address: + + Connection Prefix: + + Connection String: + + + + Log + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionBuilderView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionBuilderView.xaml.cs new file mode 100644 index 0000000..c4a9b08 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionBuilderView.xaml.cs @@ -0,0 +1,163 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Printer; +using Zebra.Windows.DevDemo.Utils; +using ZebraConnectionBuilder = Zebra.Sdk.Comm.ConnectionBuilder; +using ZebraPrinterStatus = Zebra.Sdk.Printer.PrinterStatus; + +namespace Zebra.Windows.DevDemo.Demos.ConnectionBuilder { + + /// + /// Interaction logic for ConnectionBuilderView.xaml + /// + public partial class ConnectionBuilderView : UserControl { + + private ConnectionBuilderViewModel viewModel; + private Connection connection = null; + + public ConnectionBuilderView() { + InitializeComponent(); + + viewModel = DataContext as ConnectionBuilderViewModel; + } + + private void TestConnectionString() { + Task.Run(() => { + try { + ClearProgress(); + connection = ZebraConnectionBuilder.Build(GetConnectionStringForSdk()); + PublishProgress("Connection string evaluated as class type " + connection.GetType().Name); + connection.Open(); + + PublishProgress("Connection opened successfully"); + + if (IsAttemptingStatusConnection()) { + ZebraPrinterLinkOs printer = ZebraPrinterFactory.GetLinkOsPrinter(connection); + PublishProgress("Created a printer, attempting to retrieve status"); + + ZebraPrinterStatus status = printer.GetCurrentStatus(); + PublishProgress("Is printer ready to print? " + status.isReadyToPrint); + } else { + ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection); + PublishProgress("Created a printer, attempting to print a config label"); + printer.PrintConfigurationLabel(); + } + + PublishProgress("Closing connection"); + } catch (ConnectionException) { + MessageBoxCreator.ShowError("Connection could not be opened", "Error"); + } catch (ZebraPrinterLanguageUnknownException) { + MessageBoxCreator.ShowError("Could not create printer", "Error"); + } finally { + if (connection != null) { + try { + connection.Close(); + } catch (ConnectionException) { } finally { + connection = null; + SetTestButtonState(true); + } + } else { + SetTestButtonState(true); + } + } + }); + } + + private void SetTestButtonState(bool state) { + Application.Current.Dispatcher.Invoke(() => { + testConnectionStringButton.IsEnabled = state; + }); + } + + private void ClearProgress() { + Application.Current.Dispatcher.Invoke(() => { + logData.Text = "Log:\nTesting string: " + GetConnectionStringForSdk() + "\n"; + }); + } + + private string GetConnectionStringForSdk() { + string finalConnectionString = ""; + Application.Current.Dispatcher.Invoke(() => { + string selectedPrefix = ""; + if (connectionPrefixDropdown.SelectedIndex > 0) { + selectedPrefix = connectionPrefixDropdown.SelectedValue + ":"; + } + + string userSuppliedDescriptionString = usbDriverIpAddress.Text; + finalConnectionString = selectedPrefix + userSuppliedDescriptionString; + }); + return finalConnectionString; + } + + private bool IsAttemptingStatusConnection() { + return connection.GetType().Name.Contains("Status"); + } + + private void PublishProgress(string progress) { + Application.Current.Dispatcher.Invoke(() => { + logData.Text = logData.Text + progress + Environment.NewLine; + }); + } + + private void ConnectionPrefixDropdown_SelectionChanged(object sender, SelectionChangedEventArgs e) { + connectionString.Text = GetConnectionStringForSdk(); + SetAddressTextBlock(); + } + + private void SetAddressTextBlock() { + switch(connectionPrefixDropdown.SelectedValue) { + case ConnectionPrefix.Tcp: + case ConnectionPrefix.TcpMulti: + case ConnectionPrefix.TcpStatus: + AddressTextBlock.Text = "IP Address:"; + break; + case ConnectionPrefix.Bluetooth: + case ConnectionPrefix.BluetoothMulti: + AddressTextBlock.Text = "BT Address:"; + break; + case ConnectionPrefix.Usb: + AddressTextBlock.Text = "USB Driver:"; + break; + case ConnectionPrefix.UsbDirect: + AddressTextBlock.Text = "Symbolic Name:"; + break; + default: + AddressTextBlock.Text = "Address:"; + break; + }; + } + + private void TestConnectionStringButton_Click(object sender, RoutedEventArgs e) { + try { + viewModel.LogData = "Log:\n\n"; + SetTestButtonState(false); + + TestConnectionString(); + } catch (Exception ex) { + MessageBoxCreator.ShowError(ex.Message, "Connection Builder Error"); + } + } + + private void UsbDriverIpAddress_KeyUp(object sender, KeyEventArgs e) { + connectionString.Text = GetConnectionStringForSdk(); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionBuilderViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionBuilderViewModel.cs new file mode 100644 index 0000000..1f0ed2a --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionBuilderViewModel.cs @@ -0,0 +1,56 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Collections.ObjectModel; +using Zebra.Windows.DevDemo.Utils; + +namespace Zebra.Windows.DevDemo.Demos.ConnectionBuilder { + + public class ConnectionBuilderViewModel : IDemoViewModel { + + private string logData; + + private ObservableCollection connectionPrefixes = new ObservableCollection() { + ConnectionPrefix.None, + ConnectionPrefix.TcpMulti, + ConnectionPrefix.Tcp, + ConnectionPrefix.TcpStatus, + ConnectionPrefix.Usb, + ConnectionPrefix.UsbDirect + }; + + public string LogData { + get => logData; + set { + if (logData != value) { + logData = value; + OnPropertyChanged(); + } + } + } + + public ObservableCollection ConnectionPrefixes { + get => connectionPrefixes; + } + + public ConnectionBuilderViewModel() { + Name = "Connection Builder"; + logData = "Log:\n\n"; + if(BluetoothHelper.IsBluetoothSupported()) { + connectionPrefixes.Add(ConnectionPrefix.Bluetooth); + connectionPrefixes.Add(ConnectionPrefix.BluetoothMulti); + } + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionPrefix.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionPrefix.cs new file mode 100644 index 0000000..5067e54 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ConnectionBuilder/ConnectionPrefix.cs @@ -0,0 +1,27 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +namespace Zebra.Windows.DevDemo.Demos.ConnectionBuilder { + + public class ConnectionPrefix { + public const string None = ""; + public const string TcpMulti = "TCP_MULTI"; + public const string Tcp = "TCP"; + public const string TcpStatus = "TCP_STATUS"; + public const string Usb = "USB"; + public const string UsbDirect = "USB_DIRECT"; + public const string Bluetooth = "BT"; + public const string BluetoothMulti = "BT_MULTI"; + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Connectivity/ConnectivityView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Connectivity/ConnectivityView.xaml new file mode 100644 index 0000000..4fb8832 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Connectivity/ConnectivityView.xaml @@ -0,0 +1,18 @@ + + + Connectivity + + + + Connection Status + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Connectivity/ConnectivityView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Connectivity/ConnectivityView.xaml.cs new file mode 100644 index 0000000..feee547 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Connectivity/ConnectivityView.xaml.cs @@ -0,0 +1,170 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Printer; +using Zebra.Sdk.Printer.Discovery; +using Zebra.Windows.DevDemo.Enums; + +namespace Zebra.Windows.DevDemo.Demos.Connectivity { + + /// + /// Interaction logic for Connectivity.xaml + /// + public partial class ConnectivityView : UserControl { + + public ConnectivityView() { + InitializeComponent(); + } + + private async void TestButton_Click(object sender, RoutedEventArgs e) { + SetTestButtonState(false); + Connection printerConnection = null; + if (connectionSelector.ConnectionType == ConnectionType.Network) { + try { + printerConnection = connectionSelector.GetConnection(); + } catch (ConnectionException) { + UpdateStatusBarOnGui("Invalid Address and/or Port", ConnectionState.Error); + await Task.Delay(1000); + UpdateStatusBarOnGui("Not Connected", ConnectionState.Error); + return; + } + } else if (connectionSelector.ConnectionType == ConnectionType.Bluetooth) { + try { + printerConnection = connectionSelector.GetConnection(); + } catch (ConnectionException) { + UpdateStatusBarOnGui("Invalid Mac Address", ConnectionState.Error); + await Task.Delay(1000); + UpdateStatusBarOnGui("Not Connected", ConnectionState.Error); + } + } else if (connectionSelector.SelectedUsbPrinter is DiscoveredPrinterDriver printer) { + try { + printerConnection = new DriverPrinterConnection(printer.PrinterName); + } catch (ConnectionException) { + return; + } + } else if (connectionSelector.ConnectionType == ConnectionType.UsbDirect) { + try { + printerConnection = connectionSelector.GetConnection(); + } catch (ConnectionException) { + UpdateStatusBarOnGui("Invalid Address", ConnectionState.Error); + await Task.Delay(1000); + UpdateStatusBarOnGui("Not Connected", ConnectionState.Error); + return; + } + } else { + return; + } + await Task.Run(async () => { + try { + UpdateStatusBarOnGui("Connecting...", ConnectionState.Progress); + await Task.Delay(1500); + + printerConnection.Open(); + + UpdateStatusBarOnGui("Connected", ConnectionState.Success); + await Task.Delay(1500); + + UpdateStatusBarOnGui("Determining Printer Language...", ConnectionState.Progress); + await Task.Delay(1500); + + PrinterLanguage printerLanguage = ZebraPrinterFactory.GetInstance(printerConnection).PrinterControlLanguage; + UpdateStatusBarOnGui("Printer Language " + printerLanguage.ToString(), ConnectionState.Info); + await Task.Delay(1500); + + UpdateStatusBarOnGui("Sending Data...", ConnectionState.Progress); + + printerConnection.Write(GetConfigLabel(printerLanguage)); + } catch (ConnectionException) { + UpdateStatusBarOnGui("Communications Error", ConnectionState.Error); + } catch (ZebraPrinterLanguageUnknownException) { + UpdateStatusBarOnGui("Invalid Printer Language", ConnectionState.Error); + } finally { + try { + await Task.Delay(1000); + UpdateStatusBarOnGui("Disconnecting...", ConnectionState.Progress); + if (printerConnection != null) { + printerConnection.Close(); + } + + await Task.Delay(1000); + UpdateStatusBarOnGui("Not Connected", ConnectionState.Error); + } catch (ConnectionException) { + } finally { + SetTestButtonState(true); + } + } + }); + } + + private void SetTestButtonState(bool state) { + Application.Current.Dispatcher.Invoke(() => { + testButton.IsEnabled = state; + }); + } + + private Brush GetBrushFromConnectionState(ConnectionState connectionState) { + switch (connectionState) { + case ConnectionState.Success: + return Brushes.Green; + + case ConnectionState.Progress: + return Brushes.Goldenrod; + + case ConnectionState.Info: + return Brushes.Blue; + + case ConnectionState.Error: + default: + return Brushes.Red; + } + } + + private void UpdateStatusBarOnGui(string statusMessage, ConnectionState connectionState) { + Application.Current.Dispatcher.Invoke(() => { + connectionStatus.Foreground = GetBrushFromConnectionState(connectionState); + connectionStatus.Text = statusMessage; + }); + } + + /* + * Returns the command for a test label depending on the printer control language + * The test label is a box with the word "TEST" inside of it + * + * _________________________ + * | | + * | | + * | TEST | + * | | + * | | + * |_______________________| + * + */ + private byte[] GetConfigLabel(PrinterLanguage printerLanguage) { + byte[] configLabel = null; + if (printerLanguage == PrinterLanguage.ZPL) { + configLabel = Encoding.UTF8.GetBytes("^XA^FO17,16^GB379,371,8^FS^FT65,255^A0N,135,134^FDTEST^FS^XZ"); + } else if (printerLanguage == PrinterLanguage.CPCL) { + string cpclConfigLabel = "! 0 200 200 406 1\r\n" + "ON-FEED IGNORE\r\n" + "BOX 20 20 380 380 8\r\n" + "T 0 6 137 177 TEST\r\n" + "PRINT\r\n"; + configLabel = Encoding.UTF8.GetBytes(cpclConfigLabel); + } + return configLabel; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Connectivity/ConnectivityViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Connectivity/ConnectivityViewModel.cs new file mode 100644 index 0000000..57ed3de --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Connectivity/ConnectivityViewModel.cs @@ -0,0 +1,24 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + + +namespace Zebra.Windows.DevDemo.Demos.Connectivity { + + public class ConnectivityViewModel : IDemoViewModel { + + public ConnectivityViewModel() { + Name = "Connectivity"; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Discovery/DiscoveryView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Discovery/DiscoveryView.xaml new file mode 100644 index 0000000..b5542f7 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Discovery/DiscoveryView.xaml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + Discovery + + + + + + + + + + + + + Discovery Method: + + + + + + + + IP Address: + + Number of Hops: + + Subnet Range: + + + + + + + + + + + + + + Discovered Printers + + + + + + + + + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Discovery/DiscoveryView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Discovery/DiscoveryView.xaml.cs new file mode 100644 index 0000000..b1efb09 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Discovery/DiscoveryView.xaml.cs @@ -0,0 +1,192 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; +using System.Windows; +using System.Windows.Controls; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Printer.Discovery; +using Zebra.Windows.DevDemo.Enums; +using Zebra.Windows.DevDemo.Utils; + +namespace Zebra.Windows.DevDemo.Demos.Discovery { + + /// + /// Interaction logic for Discovery.xaml + /// + public partial class DiscoveryView : UserControl { + + private DiscoveryViewModel viewModel; + + public DiscoveryView() { + InitializeComponent(); + + viewModel = DataContext as DiscoveryViewModel; + + discoveryMethodsDropdown.SelectedIndex = 0; + } + + private void ResetDiscoveredPrinterData() { + viewModel.DiscoveredPrinters.Clear(); + viewModel.DiscoveredPrinterInfo = ""; + } + + private void DiscoverPrintersButton_Click(object sender, RoutedEventArgs e) { + try { + ResetDiscoveredPrinterData(); + PerformDiscovery(); + } catch (Exception ex) { + ShowErrorMessage(ex.Message); + SetDiscoverButtonState(true); + } + } + + private void DiscoveryMethodsDropdown_SelectionChanged(object sender, SelectionChangedEventArgs e) { + var selectedItem = (sender as ComboBox).SelectedItem; + if (selectedItem != null) { + DiscoveryMethod discoveryMethod = (DiscoveryMethod)selectedItem; + ipAddressLabel.Visibility = discoveryMethod == DiscoveryMethod.DirectedBroadcast ? Visibility.Visible : Visibility.Collapsed; + ipAddressInput.Visibility = discoveryMethod == DiscoveryMethod.DirectedBroadcast ? Visibility.Visible : Visibility.Collapsed; + numberOfHopsLabel.Visibility = discoveryMethod == DiscoveryMethod.MulticastBroadcast ? Visibility.Visible : Visibility.Collapsed; + numberOfHopsInput.Visibility = discoveryMethod == DiscoveryMethod.MulticastBroadcast ? Visibility.Visible : Visibility.Collapsed; + subnetRangeLabel.Visibility = discoveryMethod == DiscoveryMethod.SubnetSearch ? Visibility.Visible : Visibility.Collapsed; + subnetRangeInput.Visibility = discoveryMethod == DiscoveryMethod.SubnetSearch ? Visibility.Visible : Visibility.Collapsed; + + ResetDiscoveredPrinterData(); + } + } + + private void DiscoveredPrintersList_SelectionChanged(object sender, SelectionChangedEventArgs e) { + ListBox discoveredPrintersList = sender as ListBox; + viewModel.DiscoveredPrinterInfo = ""; + + var selectedItem = discoveredPrintersList.SelectedItem; + if (selectedItem != null) { + DiscoveredPrinter printer = (DiscoveredPrinter)selectedItem; + Dictionary settings = printer.DiscoveryDataMap; + + StringBuilder sb = new StringBuilder(); + foreach (string key in settings.Keys) { + sb.AppendLine($"{key}: {settings[key]}"); + } + + viewModel.DiscoveredPrinterInfo = sb.ToString(); + } + } + + private void NumberOfHopsInput_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { + e.Handled = new Regex("[^0-9]+").IsMatch(e.Text); + } + + /// + /// + private void PerformDiscovery() { + DiscoveryHandlerImpl discoveryHandler = new DiscoveryHandlerImpl(this); + switch (discoveryMethodsDropdown.SelectedItem) { + case DiscoveryMethod.DirectedBroadcast: + NetworkDiscoverer.DirectedBroadcast(discoveryHandler, viewModel.IpAddress); + break; + + case DiscoveryMethod.FindPrintersNearMe: + NetworkDiscoverer.FindPrinters(discoveryHandler); + break; + + case DiscoveryMethod.LocalBroadcast: + NetworkDiscoverer.LocalBroadcast(discoveryHandler); + break; + + case DiscoveryMethod.MulticastBroadcast: + NetworkDiscoverer.Multicast(discoveryHandler, int.Parse(viewModel.NumberOfHops)); + break; + + case DiscoveryMethod.SubnetSearch: + NetworkDiscoverer.SubnetSearch(discoveryHandler, viewModel.SubnetRange); + break; + + case DiscoveryMethod.ZebraUsbDrivers: + try { + discoveryHandler = null; + discoverPrintersButton.IsEnabled = false; + viewModel.DiscoveredPrinters.Clear(); + + foreach (DiscoveredPrinterDriver printer in UsbDiscoverer.GetZebraDriverPrinters()) { + viewModel.DiscoveredPrinters.Add(printer); + } + } finally { + SetDiscoverButtonState(true); + } + break; + + case DiscoveryMethod.UsbDirect: + try { + discoveryHandler = null; + discoverPrintersButton.IsEnabled = false; + viewModel.DiscoveredPrinters.Clear(); + + foreach (DiscoveredUsbPrinter printer in UsbDiscoverer.GetZebraUsbPrinters()) { + viewModel.DiscoveredPrinters.Add(printer); + } + } finally { + SetDiscoverButtonState(true); + } + break; + + case DiscoveryMethod.Bluetooth: + BluetoothDiscoverer.FindPrinters(discoveryHandler); + break; + } + } + + private void SetDiscoverButtonState(bool state) { + Application.Current.Dispatcher.Invoke(() => { + discoverPrintersButton.IsEnabled = state; + }); + } + + private void ShowErrorMessage(string message) { + MessageBoxCreator.ShowError(message, "Discovery Error"); + } + + private void DiscoveredPrintersList_Click(object sender, RoutedEventArgs e) { + Clipboard.SetText(discoveredPrintersList.SelectedItem.ToString()); + } + + private class DiscoveryHandlerImpl : DiscoveryHandler { + + private DiscoveryView discoveryView; + + public DiscoveryHandlerImpl(DiscoveryView discoveryView) { + this.discoveryView = discoveryView; + discoveryView.SetDiscoverButtonState(false); + } + + public void DiscoveryError(string message) { + discoveryView.ShowErrorMessage(message); + } + + public void DiscoveryFinished() { + discoveryView.SetDiscoverButtonState(true); + } + + public void FoundPrinter(DiscoveredPrinter printer) { + Application.Current.Dispatcher.Invoke(() => { + discoveryView.viewModel.DiscoveredPrinters.Add(printer); + }); + } + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Discovery/DiscoveryViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Discovery/DiscoveryViewModel.cs new file mode 100644 index 0000000..7c839cc --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Discovery/DiscoveryViewModel.cs @@ -0,0 +1,92 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using Zebra.Sdk.Printer.Discovery; +using Zebra.Windows.DevDemo.Enums; +using Zebra.Windows.DevDemo.Utils; + +namespace Zebra.Windows.DevDemo.Demos.Discovery { + + public class DiscoveryViewModel : IDemoViewModel { + + private ObservableCollection discoveredPrinters = new ObservableCollection(); + private string discoveredPrinterInfo; + private string ipAddress; + private string numberOfHops; + private string subnetRange; + + public List DiscoveryMethods { + get { + List discoveryMethods = Enum.GetValues(typeof(DiscoveryMethod)).Cast().ToList(); + if(!BluetoothHelper.IsBluetoothSupported()) { + discoveryMethods.Remove(DiscoveryMethod.Bluetooth); + } + return discoveryMethods; + } + } + + public ObservableCollection DiscoveredPrinters { + get => discoveredPrinters; + } + + public string DiscoveredPrinterInfo { + get => discoveredPrinterInfo; + set { + if (discoveredPrinterInfo != value) { + discoveredPrinterInfo = value; + OnPropertyChanged(); + } + } + } + + public string IpAddress { + get => ipAddress; + set { + if (ipAddress != value) { + ipAddress = value; + OnPropertyChanged(); + } + } + } + + public string NumberOfHops { + get => numberOfHops; + set { + if (numberOfHops != value) { + numberOfHops = value; + OnPropertyChanged(); + } + } + } + + public string SubnetRange { + get => subnetRange; + set { + if (subnetRange != value) { + subnetRange = value; + OnPropertyChanged(); + } + } + } + + public DiscoveryViewModel() { + Name = "Discovery"; + NumberOfHops = "5"; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/IDemoViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/IDemoViewModel.cs new file mode 100644 index 0000000..5d91a16 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/IDemoViewModel.cs @@ -0,0 +1,30 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace Zebra.Windows.DevDemo.Demos { + + public class IDemoViewModel : INotifyPropertyChanged { + + public string Name { get; set; } + + public event PropertyChangedEventHandler PropertyChanged; + + public void OnPropertyChanged([CallerMemberName] string memberName = null) { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName)); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ImagePrint/ImagePrintView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ImagePrint/ImagePrintView.xaml new file mode 100644 index 0000000..f4849e4 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ImagePrint/ImagePrintView.xaml @@ -0,0 +1,40 @@ + + + + + + Image Print + + + + + + + + + + + + + + Image File: + + + + + + + + + + + + + Retrieved Files / Formats + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ListFormats/ListFormatsView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ListFormats/ListFormatsView.xaml.cs new file mode 100644 index 0000000..35a3fad --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ListFormats/ListFormatsView.xaml.cs @@ -0,0 +1,100 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Device; +using Zebra.Sdk.Printer; +using Zebra.Windows.DevDemo.Utils; + +namespace Zebra.Windows.DevDemo.Demos.ListFormats { + + /// + /// Interaction logic for ListFormatsView.xaml + /// + public partial class ListFormatsView : UserControl { + + private ListFormatsViewModel viewModel; + + public ListFormatsView() { + InitializeComponent(); + + viewModel = DataContext as ListFormatsViewModel; + } + + private async void RunFormatDemo(bool isFormat) { + await Task.Run(() => { + SetButtonStates(false); + PerformListFiles(isFormat); + SetButtonStates(true); + }); + } + + private void PerformListFiles(bool isFormat) { + Connection printerConnection = null; + try { + Application.Current.Dispatcher.Invoke(() => { + printerConnection = connectionSelector.GetConnection(); + }); + + printerConnection.Open(); + ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection); + + string[] formatExtensions; + if (printer.PrinterControlLanguage == PrinterLanguage.ZPL) { + formatExtensions = new string[] { "ZPL" }; + } else { + formatExtensions = new string[] { "FMT", "LBL" }; + } + + string[] formats = isFormat ? printer.RetrieveFileNames(formatExtensions) : printer.RetrieveFileNames(); + + Application.Current.Dispatcher.Invoke(() => { + foreach (string format in formats) { + viewModel.FormatsList.Add(format); + } + }); + } catch (ConnectionException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (ZebraIllegalArgumentException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (ZebraPrinterLanguageUnknownException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } finally { + if (printerConnection != null) { + printerConnection.Close(); + } + } + } + + private void SetButtonStates(bool enabled) { + Application.Current.Dispatcher.Invoke(() => { + retrieveFilesButton.IsEnabled = enabled; + retrieveFormatsButton.IsEnabled = enabled; + }); + } + + private void RetrieveFilesButton_Click(object sender, RoutedEventArgs e) { + viewModel.FormatsList.Clear(); + RunFormatDemo(false); + } + + private void RetrieveFormatsButton_Click(object sender, RoutedEventArgs e) { + viewModel.FormatsList.Clear(); + RunFormatDemo(true); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ListFormats/ListFormatsViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ListFormats/ListFormatsViewModel.cs new file mode 100644 index 0000000..e7121b2 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/ListFormats/ListFormatsViewModel.cs @@ -0,0 +1,31 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Collections.ObjectModel; + +namespace Zebra.Windows.DevDemo.Demos.ListFormats { + + class ListFormatsViewModel : IDemoViewModel { + + private ObservableCollection formatsList = new ObservableCollection(); + + public ObservableCollection FormatsList { + get => formatsList; + } + + public ListFormatsViewModel() { + Name = "List Formats"; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/MagCard/MagCardView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/MagCard/MagCardView.xaml new file mode 100644 index 0000000..7718262 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/MagCard/MagCardView.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + Mag Card + + + + Mag Card Data + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/MagCard/MagCardView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/MagCard/MagCardView.xaml.cs new file mode 100644 index 0000000..de700bf --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/MagCard/MagCardView.xaml.cs @@ -0,0 +1,106 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Device; +using Zebra.Sdk.Printer; +using Zebra.Windows.DevDemo.Utils; + +namespace Zebra.Windows.DevDemo.Demos.MagCard { + + /// + /// Interaction logic for MagCardView.xaml + /// + public partial class MagCardView : UserControl { + + private MagCardViewModel viewModel; + + public MagCardView() { + InitializeComponent(); + + viewModel = DataContext as MagCardViewModel; + } + + private void ReadMagCard() { + Connection connection = null; + Task t = Task.Run(() => { + try { + connection = connectionSelector.GetConnection(); + connection.Open(); + + ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection); + MagCardReader magCardReader = MagCardReaderFactory.Create(printer); + + if (magCardReader != null) { + UpdateMagCardOutput(""); + SetButtonText("Swipe Card Now"); + string[] trackData = magCardReader.Read(30000); + + if (trackData[0].Equals("") && trackData[1].Equals("") && trackData[2].Equals("")) { + MessageBoxCreator.ShowError("Connection timed out", "Mag Card Error"); + } else { + UpdateMagCardOutput(trackData[0] + "\r\n" + trackData[1] + "\r\n" + trackData[2]); + } + } else { + MessageBoxCreator.ShowError("Printer does not have a mag card reader", "Mag Card Error"); + } + } catch (ConnectionException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (ZebraPrinterLanguageUnknownException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } finally { + if (connection != null) { + try { + connection.Close(); + } catch (ConnectionException) { } + } + SetButtonText("Read Mag Card"); + SetButtonState(true); + } + }); + } + + private void UpdateMagCardOutput(string message) { + viewModel.MagCardData = message; + } + + delegate void ParametrizedMethodInvoker5(string arg); + + private void SetButtonText(string text) { + Application.Current.Dispatcher.Invoke(() => { + readMagCardButton.Content = text; + }); + } + + private void SetButtonState(bool state) { + Application.Current.Dispatcher.Invoke(() => { + readMagCardButton.IsEnabled = state; + }); + } + + private void ReadMagCardButton_Click(object sender, RoutedEventArgs e) { + try { + SetButtonState(false); + UpdateMagCardOutput(""); + ReadMagCard(); + } catch (Exception ex) { + MessageBoxCreator.ShowError(ex.Message, "Mag Card Data Error"); + } + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/MagCard/MagCardViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/MagCard/MagCardViewModel.cs new file mode 100644 index 0000000..97b65db --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/MagCard/MagCardViewModel.cs @@ -0,0 +1,35 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +namespace Zebra.Windows.DevDemo.Demos.MagCard { + + class MagCardViewModel : IDemoViewModel { + + private string magCardData; + + public string MagCardData { + get => magCardData; + set { + if (magCardData != value) { + magCardData = value; + OnPropertyChanged(); + } + } + } + + public MagCardViewModel() { + Name = "Mag Card"; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/PrinterStatus/PrinterStatusView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/PrinterStatus/PrinterStatusView.xaml new file mode 100644 index 0000000..fde4d34 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/PrinterStatus/PrinterStatusView.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + Printer Status + + + + Printer Status + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/PrinterStatus/PrinterStatusView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/PrinterStatus/PrinterStatusView.xaml.cs new file mode 100644 index 0000000..1e82247 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/PrinterStatus/PrinterStatusView.xaml.cs @@ -0,0 +1,106 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Printer; +using Zebra.Windows.DevDemo.Utils; +using ZebraPrinterStatus = Zebra.Sdk.Printer.PrinterStatus; + +namespace Zebra.Windows.DevDemo.Demos.PrinterStatus { + + /// + /// Interaction logic for PrinterStatusView.xaml + /// + public partial class PrinterStatusView : UserControl { + + public PrinterStatusView() { + InitializeComponent(); + } + + private void GetPrinterStatus() { + Connection printerConnection = null; + Task.Run(() => { + try { + printerConnection = connectionSelector.GetConnection(); + printerConnection.Open(); + + ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection); + ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(printer); + + ZebraPrinterStatus status = (linkOsPrinter != null) ? linkOsPrinter.GetCurrentStatus() : printer.GetCurrentStatus(); + + string[] printerStatusString = new PrinterStatusMessages(status).GetStatusMessage(); + List printerStatusPrefix = GetPrinterStatusPrefix(status); + + StringBuilder sb = new StringBuilder(); + foreach (string s in printerStatusPrefix) { + sb.AppendLine(s); + } + + foreach (string s in printerStatusString) { + sb.AppendLine(s); + } + + Application.Current.Dispatcher.Invoke(() => { + printerStatus.Text = sb.ToString(); + }); + } catch (ConnectionException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (ZebraPrinterLanguageUnknownException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } finally { + if (printerConnection != null) { + try { + printerConnection.Close(); + } catch (ConnectionException) { + } finally { + SetTestButtonState(true); + } + } else { + SetTestButtonState(true); + } + } + }); + } + + private List GetPrinterStatusPrefix(ZebraPrinterStatus printerStatus) { + bool ready = printerStatus != null ? printerStatus.isReadyToPrint : false; + string readyString = "Printer " + (ready ? "ready" : "not ready"); + string labelsInBatch = "Labels in batch: " + Convert.ToString(printerStatus.labelsRemainingInBatch); + string labelsInRecvBuffer = "Labels in buffer: " + Convert.ToString(printerStatus.numberOfFormatsInReceiveBuffer); + return new List { readyString, labelsInBatch, labelsInRecvBuffer }; + } + + private void GetPrinterStatusButton_Click(object sender, RoutedEventArgs e) { + try { + SetTestButtonState(false); + GetPrinterStatus(); + } catch (Exception ex) { + MessageBoxCreator.ShowError(ex.Message, "Printer Status Error"); + } + } + + private void SetTestButtonState(bool state) { + Application.Current.Dispatcher.Invoke(() => { + getPrinterStatusButton.IsEnabled = state; + }); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/PrinterStatus/PrinterStatusViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/PrinterStatus/PrinterStatusViewModel.cs new file mode 100644 index 0000000..de4f0e6 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/PrinterStatus/PrinterStatusViewModel.cs @@ -0,0 +1,23 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +namespace Zebra.Windows.DevDemo.Demos.PrinterStatus { + + public class PrinterStatusViewModel : IDemoViewModel { + + public PrinterStatusViewModel() { + Name = "Printer Status"; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Profile/ProfileView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Profile/ProfileView.xaml new file mode 100644 index 0000000..6be5fc3 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Profile/ProfileView.xaml @@ -0,0 +1,32 @@ + + + Profile + + + + + + + + + + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Profile/ProfileView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Profile/ProfileView.xaml.cs new file mode 100644 index 0000000..6ac4cbd --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Profile/ProfileView.xaml.cs @@ -0,0 +1,144 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using Microsoft.Win32; +using System; +using System.IO; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Device; +using Zebra.Sdk.Printer; +using Zebra.Windows.DevDemo.Utils; + +namespace Zebra.Windows.DevDemo.Demos.Profile { + + /// + /// Interaction logic for ProfileView.xaml + /// + public partial class ProfileView : UserControl { + + public ProfileView() { + InitializeComponent(); + } + + private void CreateProfile(string profilePath, Connection connection) { + if (connection != null) { + try { + connection.Open(); + ZebraPrinter genericPrinter = ZebraPrinterFactory.GetInstance(connection); + ZebraPrinterLinkOs printer = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter); + + if (printer != null) { + if (!profilePath.EndsWith(".zprofile")) { + profilePath += ".zprofile"; + } + printer.CreateProfile(profilePath); + MessageBoxCreator.ShowInformation($"Profile created successfully at location '{profilePath}'", "Profile Created Successfully"); + } else { + MessageBoxCreator.ShowError("Profile creation is only available on Link-OS(TM) printers", "Error"); + } + } catch (ConnectionException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (ZebraPrinterLanguageUnknownException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (IOException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (ZebraIllegalArgumentException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (Exception e) { + MessageBoxCreator.ShowError(e.Message, "Create Profile Error"); + } finally { + SetButtonStates(true); + try { + connection.Close(); + } catch (ConnectionException) { } + } + } + } + + private void UploadProfile(string profilePath, Connection connection) { + if (connection != null) { + try { + connection.Open(); + ZebraPrinter genericPrinter = ZebraPrinterFactory.GetInstance(connection); + ZebraPrinterLinkOs printer = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter); + + if (printer != null) { + printer.LoadProfile(profilePath, FileDeletionOption.NONE, false); + string printerAddress = connectionSelector.getConnectionAddress(); + MessageBoxCreator.ShowInformation($"Profile loaded successfully to printer {printerAddress}", "Profile Uploaded Successfully"); + } else { + MessageBoxCreator.ShowError("Profile loading is only available on Link-OS(TM) printers", "Error"); + } + } catch (ConnectionException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (ZebraPrinterLanguageUnknownException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (IOException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (Exception e) { + MessageBoxCreator.ShowError(e.Message, "Upload Profile Error"); + } finally { + SetButtonStates(true); + try { + connection.Close(); + } catch (ConnectionException) { } + } + } + } + + private void SetButtonStates(bool enabled) { + Application.Current.Dispatcher.Invoke(() => { + createProfileButton.IsEnabled = enabled; + uploadProfileButton.IsEnabled = enabled; + }); + } + + private async void CreateProfileButton_Click(object sender, RoutedEventArgs e) { + try { + SetButtonStates(false); + SaveFileDialog saveFileDialog = new SaveFileDialog(); + if (saveFileDialog.ShowDialog() == true) { + string profilePath = saveFileDialog.FileName; + Connection connection = connectionSelector.GetConnection(); + await Task.Run(() => CreateProfile(profilePath, connection)); + } else { + SetButtonStates(true); + } + } catch (Exception ex) { + MessageBoxCreator.ShowError(ex.Message, "Create Profile Error"); + SetButtonStates(true); + } + } + + private async void UploadProfileButton_Click(object sender, RoutedEventArgs e) { + try { + SetButtonStates(false); + OpenFileDialog openFileDialog = new OpenFileDialog(); + if (openFileDialog.ShowDialog() == true) { + string profilePath = openFileDialog.FileName; + Connection connection = connectionSelector.GetConnection(); + await Task.Run(() => UploadProfile(profilePath, connection)); + } else { + SetButtonStates(true); + } + } catch (Exception ex) { + MessageBoxCreator.ShowError(ex.Message, "Upload Profile Error"); + SetButtonStates(true); + } + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Profile/ProfileViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Profile/ProfileViewModel.cs new file mode 100644 index 0000000..00c052c --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Profile/ProfileViewModel.cs @@ -0,0 +1,23 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +namespace Zebra.Windows.DevDemo.Demos.Profile { + + class ProfileViewModel : IDemoViewModel { + + public ProfileViewModel() { + Name = "Profile"; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SendFile/SendFileView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SendFile/SendFileView.xaml new file mode 100644 index 0000000..7e7e333 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SendFile/SendFileView.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + Send File + + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SendFile/SendFileView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SendFile/SendFileView.xaml.cs new file mode 100644 index 0000000..fb604aa --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SendFile/SendFileView.xaml.cs @@ -0,0 +1,104 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.IO; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Printer; +using Zebra.Windows.DevDemo.Utils; + +namespace Zebra.Windows.DevDemo.Demos.SendFile { + + /// + /// Interaction logic for SendFileView.xaml + /// + public partial class SendFileView : UserControl { + + public SendFileView() { + InitializeComponent(); + } + + private void SendFileToPrinter() { + string filePath = null; + Connection printerConnection = null; + Task.Run(() => { + try { + printerConnection = connectionSelector.GetConnection(); + printerConnection.Open(); + ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection); + + filePath = CreateDemoFile(printer.PrinterControlLanguage); + printer.SendFileContents(filePath); + } catch (ConnectionException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (IOException e) { + MessageBoxCreator.ShowError(e.Message, "IO Error"); + } catch (ZebraPrinterLanguageUnknownException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (Exception e) { + MessageBoxCreator.ShowError(e.Message, "Send File Error"); + } finally { + try { + if (printerConnection != null) + printerConnection.Close(); + } catch (ConnectionException) { } + + if (filePath != null) { + try { + new FileInfo(filePath).Delete(); + } catch { } + } + + SetSendFileButtonState(true); + } + }); + } + + private string CreateDemoFile(PrinterLanguage pl) { + string tempFilePath = $"{Path.GetTempPath()}TEST_ZEBRA.LBL"; + using (FileStream tmpFile = new FileStream(tempFilePath, FileMode.Create)) { + byte[] configLabel = null; + if (pl == PrinterLanguage.ZPL) { + configLabel = Encoding.UTF8.GetBytes("^XA^FO17,16^GB379,371,8^FS^FT65,255^A0N,135,134^FDTEST^FS^XZ"); + } else if (pl == PrinterLanguage.CPCL) { + string cpclConfigLabel = "! 0 200 200 406 1\r\n" + "ON-FEED IGNORE\r\n" + "BOX 20 20 380 380 8\r\n" + "T 0 6 137 177 TEST\r\n" + "PRINT\r\n"; + configLabel = Encoding.UTF8.GetBytes(cpclConfigLabel); + } + + tmpFile.Write(configLabel, 0, configLabel.Length); + tmpFile.Flush(); + } + return new FileInfo(tempFilePath).FullName; + } + + private void SendFileButton_Click(object sender, RoutedEventArgs e) { + try { + SetSendFileButtonState(false); + SendFileToPrinter(); + } catch (Exception ex) { + MessageBoxCreator.ShowError(ex.Message, "Send File Error"); + } + } + + private void SetSendFileButtonState(bool state) { + Application.Current.Dispatcher.Invoke(() => { + sendFileButton.IsEnabled = state; + }); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SendFile/SendFileViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SendFile/SendFileViewModel.cs new file mode 100644 index 0000000..475bfda --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SendFile/SendFileViewModel.cs @@ -0,0 +1,23 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +namespace Zebra.Windows.DevDemo.Demos.SendFile { + + class SendFileViewModel : IDemoViewModel { + + public SendFileViewModel() { + Name = "Send File"; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/Setting.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/Setting.cs new file mode 100644 index 0000000..38db9b9 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/Setting.cs @@ -0,0 +1,31 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +namespace Zebra.Windows.DevDemo.Demos.Settings { + + public class Setting { + + public string Key { + get; set; + } + + public string Value { + get; set; + } + + public string Range { + get; set; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/SettingsView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/SettingsView.xaml new file mode 100644 index 0000000..e497721 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/SettingsView.xaml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + Settings + + + + + + + + + + + Printer Settings + + + + + + + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/SettingsView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/SettingsView.xaml.cs new file mode 100644 index 0000000..5a5ca3c --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/SettingsView.xaml.cs @@ -0,0 +1,180 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Printer; +using Zebra.Sdk.Settings; +using Zebra.Windows.DevDemo.Utils; + +namespace Zebra.Windows.DevDemo.Demos.Settings { + + /// + /// Interaction logic for SettingsView.xaml + /// + public partial class SettingsView : UserControl { + + private SettingsViewModel viewModel; + + public SettingsView() { + InitializeComponent(); + + viewModel = DataContext as SettingsViewModel; + } + + private void UpdateSettingsTable() { + Connection connection = null; + try { + connection = connectionSelector.GetConnection(); + connection.Open(); + + ZebraPrinter genericPrinter = ZebraPrinterFactory.GetInstance(connection); + ZebraPrinterLinkOs printer = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter); + + if (printer != null) { + Dictionary settings = printer.GetAllSettings(); + + Application.Current.Dispatcher.Invoke(() => { + if (settings != null) { + foreach (string key in settings.Keys) { + viewModel.Settings.Add(new Setting { Key = key, Value = settings[key].Value, Range = printer.GetSettingRange(key) }); + } + } else { + MessageBoxCreator.ShowError("Error reading settings", "Settings Error"); + } + + printerSettingsGrid.UnselectAll(); + }); + } else { + MessageBoxCreator.ShowError("Connected printer does not support settings", "Connection Error"); + } + } catch (ConnectionException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (ZebraPrinterLanguageUnknownException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (SettingsException e) { + MessageBoxCreator.ShowError(e.Message, "Settings Error"); + } catch (Exception e) { + MessageBoxCreator.ShowError(e.Message, "Save Settings Error"); + } finally { + SetButtonStates(true); + try { + if (connection != null) { + connection.Close(); + } + } catch (ConnectionException) { } + } + } + + private void ClearSettings() { + Application.Current.Dispatcher.Invoke(() => { + viewModel.Settings.Clear(); + }); + } + + private bool SaveModifiedSettingsToPrinter() { + bool result = false; + Connection connection = null; + try { + connection = connectionSelector.GetConnection(); + connection.Open(); + + ZebraPrinter genericPrinter = ZebraPrinterFactory.GetInstance(connection); + ZebraPrinterLinkOs printer = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter); + + if (printer != null) { + foreach (string key in viewModel.ModifiedSettings.Keys) { + if (printer.IsSettingReadOnly(key) == false) { + printer.SetSetting(key, viewModel.ModifiedSettings[key]); + } + } + + viewModel.ModifiedSettings.Clear(); + result = true; + } else { + MessageBoxCreator.ShowError("Connected printer does not support settings", "Connection Error"); + } + } catch (ConnectionException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (ZebraPrinterLanguageUnknownException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (SettingsException e) { + MessageBoxCreator.ShowError(e.Message, "Settings Error"); + } catch (Exception e) { + MessageBoxCreator.ShowError(e.Message, "Save Settings Error"); + } finally { + try { + if (connection != null) { + connection.Close(); + } + } catch (ConnectionException) { } + } + return result; + } + + private void SetButtonStates(bool enabled) { + Application.Current.Dispatcher.Invoke(() => { + saveSettingsButton.IsEnabled = enabled; + getSettingsButton.IsEnabled = enabled; + }); + } + + private async void SaveSettingsButton_Click(object sender, RoutedEventArgs e) { + try { + SetButtonStates(false); + if (await Task.Run(() => SaveModifiedSettingsToPrinter())) { + ClearSettings(); + await Task.Run(() => UpdateSettingsTable()); + } else { + SetButtonStates(true); + } + } catch (Exception ex) { + MessageBoxCreator.ShowError(ex.Message, "Save Settings Error"); + SetButtonStates(true); + } + } + + private async void GetSettingsButton_Click(object sender, RoutedEventArgs e) { + try { + SetButtonStates(false); + ClearSettings(); + await Task.Run(() => UpdateSettingsTable()); + } catch (Exception ex) { + MessageBoxCreator.ShowError(ex.Message, "Get Settings Error"); + SetButtonStates(true); + } + } + + private void PrinterSettingsGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { + if (viewModel.Settings.Count > 0) { + TextBox textBox = e.EditingElement as TextBox; + string newValue = textBox.Text.ToString(); + + Setting setting = e.Row.Item as Setting; + string key = setting.Key; + if (key != null) { + if (viewModel.ModifiedSettings.ContainsKey(key)) { + viewModel.ModifiedSettings[key] = newValue; + } else { + viewModel.ModifiedSettings.Add(key, newValue); + } + } + } + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/SettingsViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/SettingsViewModel.cs new file mode 100644 index 0000000..6050d2e --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/Settings/SettingsViewModel.cs @@ -0,0 +1,37 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace Zebra.Windows.DevDemo.Demos.Settings { + + class SettingsViewModel : IDemoViewModel { + + private ObservableCollection settings = new ObservableCollection(); + private Dictionary modifiedSettings = new Dictionary(); + + public ObservableCollection Settings { + get => settings; + } + + public Dictionary ModifiedSettings { + get => modifiedSettings; + } + + public SettingsViewModel() { + Name = "Settings"; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SmartCard/SmartCardView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SmartCard/SmartCardView.xaml new file mode 100644 index 0000000..1e5346f --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SmartCard/SmartCardView.xaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + Smart Card + + + + + + + + + + + Response Data + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SmartCard/SmartCardView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SmartCard/SmartCardView.xaml.cs new file mode 100644 index 0000000..510070b --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SmartCard/SmartCardView.xaml.cs @@ -0,0 +1,102 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Device; +using Zebra.Sdk.Printer; +using Zebra.Windows.DevDemo.Utils; + +namespace Zebra.Windows.DevDemo.Demos.SmartCard { + + /// + /// Interaction logic for SmartCardView.xaml + /// + public partial class SmartCardView : UserControl { + public SmartCardView() { + InitializeComponent(); + } + + private void RunSmartCardDemo(bool sendData) { + try { + SetButtonStates(false); + ReadSmartCard(sendData); + } catch (Exception e) { + MessageBoxCreator.ShowError(e.Message, "Smart Card Error"); + } + } + + private void ReadSmartCard(bool sendData) { + Connection connection = null; + Task.Run(() => { + try { + UpdateSmartCardOutput(""); + + Application.Current.Dispatcher.Invoke(() => { + connection = connectionSelector.GetConnection(); + }); + + connection.Open(); + + ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection); + SmartcardReader smartcardReader = SmartcardReaderFactory.Create(printer); + if (smartcardReader != null) { + byte[] response = sendData ? smartcardReader.DoCommand("8010000008") : smartcardReader.GetATR(); + + UpdateSmartCardOutput(string.Concat(response.Select(x => x.ToString("x2")))); + smartcardReader.Close(); + } else { + MessageBoxCreator.ShowError("Printer does not have a smart card reader", "Smart Card Error"); + } + } catch (ConnectionException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } catch (ZebraPrinterLanguageUnknownException e) { + MessageBoxCreator.ShowError(e.Message, "Connection Error"); + } finally { + if (connection != null) { + try { + connection.Close(); + } catch (ConnectionException) { } + } + SetButtonStates(true); + } + }); + } + + private void UpdateSmartCardOutput(string newMessage) { + Application.Current.Dispatcher.Invoke(() => { + responseData.Text = newMessage; + }); + } + + private void SetButtonStates(bool enabled) { + Application.Current.Dispatcher.Invoke(() => { + sendDataButton.IsEnabled = enabled; + sendAtrButton.IsEnabled = enabled; + }); + } + + private void SendDataButton_Click(object sender, RoutedEventArgs e) { + RunSmartCardDemo(true); + } + + private void SendAtrButton_Click(object sender, RoutedEventArgs e) { + RunSmartCardDemo(false); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SmartCard/SmartCardViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SmartCard/SmartCardViewModel.cs new file mode 100644 index 0000000..fd47706 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/SmartCard/SmartCardViewModel.cs @@ -0,0 +1,23 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +namespace Zebra.Windows.DevDemo.Demos.SmartCard { + + class SmartCardViewModel : IDemoViewModel { + + public SmartCardViewModel() { + Name = "Smart Card"; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/FormatVariable.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/FormatVariable.cs new file mode 100644 index 0000000..0093de2 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/FormatVariable.cs @@ -0,0 +1,27 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +namespace Zebra.Windows.DevDemo.Demos.StoredFormat { + + public class FormatVariable { + + public string FieldName { + get; set; + } + + public string FieldValue { + get; set; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/StoredFormatView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/StoredFormatView.xaml new file mode 100644 index 0000000..3bf4574 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/StoredFormatView.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + Stored Formats + + + + Retrieved Formats + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/StoredFormatView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/StoredFormatView.xaml.cs new file mode 100644 index 0000000..0610ca4 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/StoredFormatView.xaml.cs @@ -0,0 +1,230 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Device; +using Zebra.Sdk.Printer; +using Zebra.Windows.DevDemo.Dialogs; +using Zebra.Windows.DevDemo.Utils; + +namespace Zebra.Windows.DevDemo.Demos.StoredFormat { + + /// + /// Interaction logic for StoredFormatView.xaml + /// + public partial class StoredFormatView : UserControl { + + private StoredFormatViewModel viewModel; + + private List fieldDescDataVars; + private ObservableCollection formatVariables; + + public StoredFormatView() { + InitializeComponent(); + + viewModel = DataContext as StoredFormatViewModel; + } + + private void CreateFormatTableDialog() { + SetButtonState(retrieveFormatsButton, false); + SetFormatListState(false); + + string formatName = (string)storedFilesList.SelectedValue; + Connection printerConnection = null; + + Task.Run(() => { + try { + printerConnection = connectionSelector.GetConnection(); + printerConnection.Open(); + + ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection); + byte[] formatData = printer.RetrieveFormatFromPrinter(formatName); + + fieldDescDataVars = printer.GetVariableFields(Encoding.UTF8.GetString(formatData)).ToList(); + fieldDescDataVars = FormatFieldDescriptionDataVars(fieldDescDataVars); + + formatVariables = new ObservableCollection(); + for (int i = 0; i < fieldDescDataVars.Count; ++i) { + formatVariables.Add(new FormatVariable { FieldName = fieldDescDataVars[i].FieldName, FieldValue = "" }); + } + + try { + if (printerConnection != null) { + printerConnection.Close(); + } + } catch (ConnectionException) { } + + ShowStoredFormatDialog(formatName); + } catch (Exception e) { + MessageBoxCreator.ShowError(e.Message, "Communication Error"); + SetButtonState(retrieveFormatsButton, true); + SetFormatListState(true); + } finally { + try { + if (printerConnection != null && printerConnection.Connected) { + printerConnection.Close(); + } + } catch (ConnectionException) { } + } + }); + } + + private void PopulateListWithFormats() { + Connection printerConnection = null; + Task.Run(() => { + try { + ClearFormatList(); + printerConnection = connectionSelector.GetConnection(); + + printerConnection.Open(); + ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection); + + string[] formatExtensions = printer.PrinterControlLanguage == PrinterLanguage.ZPL ? new String[] { "ZPL" } : new String[] { "FMT", "LBL" }; + string[] formats = printer.RetrieveFileNames(formatExtensions); + + AddFormatsToList(formats); + } catch (ConnectionException e) { + MessageBoxCreator.ShowError(e.Message, "Communication Error"); + } catch (ZebraPrinterLanguageUnknownException e) { + MessageBoxCreator.ShowError(e.Message, "Communication Error"); + } catch (ZebraIllegalArgumentException e) { + MessageBoxCreator.ShowError(e.Message, "Communication Error"); + } finally { + try { + if (printerConnection != null) { + printerConnection.Close(); + } + } catch (ConnectionException) { + } finally { + SetButtonState(retrieveFormatsButton, true); + SetFormatListState(true); + } + } + }); + } + + private void SetFormatListState(bool state) { + Application.Current.Dispatcher.Invoke(() => { + storedFilesList.IsEnabled = state; + }); + } + + private void AddFormatsToList(string[] formats) { + Application.Current.Dispatcher.Invoke(() => { + foreach (string format in formats) { + viewModel.StoredFormatList.Add(format); + } + }); + } + + private void ClearFormatList() { + SetFormatListState(false); + Application.Current.Dispatcher.Invoke(() => { + viewModel.StoredFormatList.Clear(); + }); + } + + private void PrintFormat(string formatName) { + Connection printerConnection = null; + try { + printerConnection = connectionSelector.GetConnection(); + printerConnection.Open(); + + Dictionary formatVars = GetFormatVariables(); + ZebraPrinterFactory.GetInstance(printerConnection).PrintStoredFormat(formatName, formatVars, "UTF-8"); + } catch (ArgumentException e) { + MessageBoxCreator.ShowError(e.Message, "Communication Error"); + } catch (ConnectionException e) { + MessageBoxCreator.ShowError(e.Message, "Communication Error"); + } catch (ZebraPrinterLanguageUnknownException e) { + MessageBoxCreator.ShowError(e.Message, "Communication Error"); + } finally { + if (printerConnection != null) { + try { + printerConnection.Close(); + } catch (ConnectionException) { } + } + } + } + + private List FormatFieldDescriptionDataVars(List variables) { + foreach (FieldDescriptionData data in variables) { + data.FieldName = data.FieldName ?? "Field " + data.FieldNumber; + } + return variables; + } + + private Dictionary GetFormatVariables() { + Dictionary formatVars = new Dictionary(); + for (int i = 0; i < formatVariables.Count; i++) { + int fieldNum = fieldDescDataVars[i].FieldNumber; + formatVars.Add(fieldNum, formatVariables[i].FieldValue); + } + return formatVars; + } + + private void RetrieveFormatsButton_Click(object sender, RoutedEventArgs e) { + try { + SetButtonState(retrieveFormatsButton, false); + PopulateListWithFormats(); + } catch (Exception ex) { + MessageBoxCreator.ShowError(ex.Message, "Stored Format Error"); + } + } + + private void SetButtonState(Button button, bool state) { + Application.Current.Dispatcher.Invoke(() => { + button.IsEnabled = state; + }); + } + + private void StoredFilesList_MouseDoubleClick(object sender, MouseButtonEventArgs e) { + if (!e.Handled) { + e.Handled = true; + CreateFormatTableDialog(); + } + } + + private void ShowStoredFormatDialog(string formatName) { + Application.Current.Dispatcher.Invoke(() => { + StoredFormatDialog storedFormatDialog = new StoredFormatDialog(new StoredFormatDialogViewModel(formatVariables)); + + Button printFormatButton = storedFormatDialog.PrintFormatButton; + printFormatButton.Click += async (s, e) => { + try { + SetButtonState(printFormatButton, false); + await Task.Run(() => PrintFormat(formatName)); + } catch (Exception ex) { + MessageBoxCreator.ShowError(ex.Message, "Print Format Error"); + } finally { + SetButtonState(printFormatButton, true); + } + }; + + storedFormatDialog.ShowDialog(); + SetButtonState(retrieveFormatsButton, true); + SetFormatListState(true); + }); + } + } +} \ No newline at end of file diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/StoredFormatViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/StoredFormatViewModel.cs new file mode 100644 index 0000000..3cbc180 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Demos/StoredFormat/StoredFormatViewModel.cs @@ -0,0 +1,31 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Collections.ObjectModel; + +namespace Zebra.Windows.DevDemo.Demos.StoredFormat { + + public class StoredFormatViewModel : IDemoViewModel { + + private ObservableCollection storedFormatList = new ObservableCollection(); + + public ObservableCollection StoredFormatList { + get => storedFormatList; + } + + public StoredFormatViewModel() { + Name = "Stored Format"; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/AboutDialog.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/AboutDialog.xaml new file mode 100644 index 0000000..3d7a945 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/AboutDialog.xaml @@ -0,0 +1,17 @@ + + + + + + + Zebra Developer Demos + © 2017 ZIH Corp. + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/AboutDialog.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/AboutDialog.xaml.cs new file mode 100644 index 0000000..c390d78 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/AboutDialog.xaml.cs @@ -0,0 +1,28 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Windows; + +namespace Zebra.Windows.DevDemo.Dialogs { + + /// + /// Interaction logic for AboutDialog.xaml + /// + public partial class AboutDialog : Window { + + public AboutDialog() { + InitializeComponent(); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/StoredFormatDialog.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/StoredFormatDialog.xaml new file mode 100644 index 0000000..ca382c5 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/StoredFormatDialog.xaml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/StoredFormatDialog.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/StoredFormatDialog.xaml.cs new file mode 100644 index 0000000..a9f9ebe --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/StoredFormatDialog.xaml.cs @@ -0,0 +1,35 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Windows; +using System.Windows.Controls; + +namespace Zebra.Windows.DevDemo.Dialogs { + + /// + /// Interaction logic for StoredFormatDialog.xaml + /// + public partial class StoredFormatDialog : Window { + + public Button PrintFormatButton { + get => printFormatButton; + } + + public StoredFormatDialog(StoredFormatDialogViewModel viewModel) { + InitializeComponent(); + + DataContext = viewModel; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/StoredFormatDialogViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/StoredFormatDialogViewModel.cs new file mode 100644 index 0000000..d313e95 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Dialogs/StoredFormatDialogViewModel.cs @@ -0,0 +1,40 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using Zebra.Windows.DevDemo.Demos.StoredFormat; + +namespace Zebra.Windows.DevDemo.Dialogs { + + public class StoredFormatDialogViewModel : INotifyPropertyChanged { + + private ObservableCollection formatVariables = new ObservableCollection(); + + public event PropertyChangedEventHandler PropertyChanged; + + public ObservableCollection FormatVariables { + get => formatVariables; + } + + public StoredFormatDialogViewModel(ObservableCollection formatVariables) { + this.formatVariables = formatVariables; + } + + private void OnPropertyChanged([CallerMemberName] string memberName = null) { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName)); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Enums/ConnectionState.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Enums/ConnectionState.cs new file mode 100644 index 0000000..7e997d0 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Enums/ConnectionState.cs @@ -0,0 +1,23 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +namespace Zebra.Windows.DevDemo.Enums { + + public enum ConnectionState { + Success, + Error, + Progress, + Info + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Enums/ConnectionType.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Enums/ConnectionType.cs new file mode 100644 index 0000000..bb31ff8 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Enums/ConnectionType.cs @@ -0,0 +1,29 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.ComponentModel; + +namespace Zebra.Windows.DevDemo.Enums { + + public enum ConnectionType { + [Description("Network")] + Network, + [Description("USB")] + USB, + [Description("USB Direct")] + UsbDirect, + [Description("Bluetooth")] + Bluetooth + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Enums/DiscoveryMethod.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Enums/DiscoveryMethod.cs new file mode 100644 index 0000000..1f88702 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Enums/DiscoveryMethod.cs @@ -0,0 +1,37 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.ComponentModel; + +namespace Zebra.Windows.DevDemo.Enums { + + public enum DiscoveryMethod { + [Description("Local Broadcast")] + LocalBroadcast, + [Description("Directed Broadcast")] + DirectedBroadcast, + [Description("Multicast Broadcast")] + MulticastBroadcast, + [Description("Subnet Search")] + SubnetSearch, + [Description("Zebra USB Drivers")] + ZebraUsbDrivers, + [Description("USB Direct")] + UsbDirect, + [Description("Find Printers Near Me")] + FindPrintersNearMe, + [Description("Find all Bluetooth Devices")] + Bluetooth + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/MainWindow.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/MainWindow.xaml new file mode 100644 index 0000000..5dbd0a6 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/MainWindow.xaml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + × + + + Available Demos + + + + + + + + + + + + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/MainWindow.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/MainWindow.xaml.cs new file mode 100644 index 0000000..3064458 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/MainWindow.xaml.cs @@ -0,0 +1,66 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using Zebra.Windows.DevDemo.Demos; +using Zebra.Windows.DevDemo.Dialogs; + +namespace Zebra.Windows.DevDemo { + + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window { + + public MainWindow() { + InitializeComponent(); + } + + private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e) + { + if (e.ChangedButton == MouseButton.Left) + { + DragMove(); + } + } + + private void CloseButton_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + QuitApplication(); + } + + private void ListBoxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { + if (sender is ListBoxItem item) { + IDemoViewModel demoViewModel = item.DataContext as IDemoViewModel; + (DataContext as MainWindowViewModel).CurrentDemoViewModel = (DataContext as MainWindowViewModel).DemoViewModels.FirstOrDefault(vm => vm == demoViewModel); + } + } + + private void AboutMenuItem_Click(object sender, RoutedEventArgs e) { + AboutDialog aboutDialog = new AboutDialog(); + aboutDialog.Show(); + } + + private void QuitMenuItem_Click(object sender, RoutedEventArgs e) { + QuitApplication(); + } + + private void QuitApplication() { + Application.Current.Shutdown(); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/MainWindowViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/MainWindowViewModel.cs new file mode 100644 index 0000000..d31efe7 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/MainWindowViewModel.cs @@ -0,0 +1,81 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using Zebra.Windows.DevDemo.Demos; +using Zebra.Windows.DevDemo.Demos.ConnectionBuilder; +using Zebra.Windows.DevDemo.Demos.Connectivity; +using Zebra.Windows.DevDemo.Demos.Discovery; +using Zebra.Windows.DevDemo.Demos.ImagePrint; +using Zebra.Windows.DevDemo.Demos.ListFormats; +using Zebra.Windows.DevDemo.Demos.MagCard; +using Zebra.Windows.DevDemo.Demos.PrinterStatus; +using Zebra.Windows.DevDemo.Demos.Profile; +using Zebra.Windows.DevDemo.Demos.SendFile; +using Zebra.Windows.DevDemo.Demos.Settings; +using Zebra.Windows.DevDemo.Demos.SmartCard; +using Zebra.Windows.DevDemo.Demos.StoredFormat; + +namespace Zebra.Windows.DevDemo { + + class MainWindowViewModel : INotifyPropertyChanged { + + private IDemoViewModel currentDemoViewModel; + private ObservableCollection demoViewModels; + + public event PropertyChangedEventHandler PropertyChanged; + + public IDemoViewModel CurrentDemoViewModel { + get => currentDemoViewModel; + set { + if (currentDemoViewModel != value) { + currentDemoViewModel = value; + OnPropertyChanged(); + } + } + } + + public ObservableCollection DemoViewModels { + get { + if (demoViewModels == null) { + demoViewModels = new ObservableCollection(); + } + return demoViewModels; + } + } + + public MainWindowViewModel() { + DemoViewModels.Add(new ConnectivityViewModel()); + DemoViewModels.Add(new DiscoveryViewModel()); + DemoViewModels.Add(new ImagePrintViewModel()); + DemoViewModels.Add(new ListFormatsViewModel()); + DemoViewModels.Add(new MagCardViewModel()); + DemoViewModels.Add(new PrinterStatusViewModel()); + DemoViewModels.Add(new ProfileViewModel()); + DemoViewModels.Add(new SendFileViewModel()); + DemoViewModels.Add(new SettingsViewModel()); + DemoViewModels.Add(new SmartCardViewModel()); + DemoViewModels.Add(new StoredFormatViewModel()); + DemoViewModels.Add(new ConnectionBuilderViewModel()); + + CurrentDemoViewModel = DemoViewModels[0]; + } + + private void OnPropertyChanged([CallerMemberName] string memberName = null) { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName)); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/ConnectionSelectorView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/ConnectionSelectorView.xaml new file mode 100644 index 0000000..99bea02 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/ConnectionSelectorView.xaml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + Connection Type: + + + + + + + + + USB Printers: + + + Symbolic Name: + + + IP Address: + + + Bluetooth Address: + + + Port: + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/ConnectionSelectorView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/ConnectionSelectorView.xaml.cs new file mode 100644 index 0000000..c3a0eb6 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/ConnectionSelectorView.xaml.cs @@ -0,0 +1,158 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Controls; +using Zebra.Sdk.Comm; +using Zebra.Sdk.Printer.Discovery; +using Zebra.Windows.DevDemo.Enums; + +namespace Zebra.Windows.DevDemo.UserControls { + + /// + /// Interaction logic for ConnectionSelectorView.xaml + /// + public partial class ConnectionSelectorView : UserControl { + + private ConnectionSelectorViewModel viewModel; + + public string IpAddress { + get => viewModel.IpAddress; + } + + public ConnectionType ConnectionType { + get => viewModel.ConnectionType; + } + public DiscoveredPrinterDriver SelectedUsbPrinter { + get => (DiscoveredPrinterDriver) usbPrintersDropdown.SelectedItem; + } + + public ConnectionSelectorView() { + InitializeComponent(); + + viewModel = DataContext as ConnectionSelectorViewModel; + connectionTypesDropdown.SelectedIndex = 0; + } + + private void ConnectionTypesDropdown_SelectionChanged(object sender, SelectionChangedEventArgs e) { + var selectedItem = (sender as ComboBox).SelectedItem; + if (selectedItem != null) { + usbPrintersLabel.Visibility = Visibility.Collapsed; + usbPrintersDropdown.Visibility = Visibility.Collapsed; + usbDirectLabel.Visibility = Visibility.Collapsed; + usbDirectInput.Visibility = Visibility.Collapsed; + ipAddressLabel.Visibility = Visibility.Collapsed; + ipAddressInput.Visibility = Visibility.Collapsed; + portLabel.Visibility = Visibility.Collapsed; + portInput.Visibility = Visibility.Collapsed; + btAddressInput.Visibility = Visibility.Collapsed; + btAddressLabel.Visibility = Visibility.Collapsed; + + switch (selectedItem) { + case ConnectionType.Network: + viewModel.ConnectionType = ConnectionType.Network; + ipAddressLabel.Visibility = Visibility.Visible; + ipAddressInput.Visibility = Visibility.Visible; + portLabel.Visibility = Visibility.Visible; + portInput.Visibility = Visibility.Visible; + break; + + case ConnectionType.USB: + viewModel.ConnectionType = ConnectionType.USB; + usbPrintersLabel.Visibility = Visibility.Visible; + usbPrintersDropdown.Visibility = Visibility.Visible; + break; + + case ConnectionType.UsbDirect: + viewModel.ConnectionType = ConnectionType.UsbDirect; + usbDirectLabel.Visibility = Visibility.Visible; + usbDirectInput.Visibility = Visibility.Visible; + break; + + case ConnectionType.Bluetooth: + viewModel.ConnectionType = ConnectionType.Bluetooth; + btAddressInput.Visibility = Visibility.Visible; + btAddressLabel.Visibility = Visibility.Visible; + break; + } + + if ((ConnectionType)selectedItem == ConnectionType.USB) { + GetUsbPrintersAndAddToList(); + if (usbPrintersDropdown.Items.Count > 0) { + usbPrintersDropdown.SelectedIndex = 0; + } + } + } + } + private void GetUsbPrintersAndAddToList() { + try { + viewModel.UsbDevices.Clear(); + + List discoPrinters = UsbDiscoverer.GetZebraDriverPrinters(); + foreach (DiscoveredPrinterDriver printer in discoPrinters) { + viewModel.UsbDevices.Add(printer); + } + } catch (ConnectionException) { + viewModel.UsbDevices.Clear(); + viewModel.UsbDevices.Add(new DiscoveredPrinterDriver("OS not supported", "", new List())); + usbPrintersDropdown.SelectedIndex = 0; + } + } + + public string getConnectionAddress() { + switch(viewModel.ConnectionType) { + case ConnectionType.Bluetooth: + return viewModel.MacAddress; + case ConnectionType.UsbDirect: + return viewModel.SymbolicName; + case ConnectionType.USB: + return viewModel.UsbPrinterName; + default: + return viewModel.IpAddress; + } + } + + public Connection GetConnection() { + if (viewModel.ConnectionType == ConnectionType.Network) { + try { + int port = string.IsNullOrEmpty(viewModel.Port) ? 9100 : int.Parse(viewModel.Port); + return new TcpConnection(viewModel.IpAddress, port); + } catch (Exception e) { + throw new ConnectionException(e.Message, e); + } + } else if (viewModel.ConnectionType == ConnectionType.UsbDirect) { + try { + return new UsbConnection(viewModel.SymbolicName); + } catch (Exception e) { + throw new ConnectionException(e.Message, e); + } + } else if(viewModel.ConnectionType == ConnectionType.USB) { + DiscoveredPrinterDriver printer = null; + Application.Current.Dispatcher.Invoke(() => { + printer = (DiscoveredPrinterDriver)usbPrintersDropdown.SelectedItem; + }); + viewModel.UsbPrinterName = printer.PrinterName; + return new DriverPrinterConnection(printer.PrinterName); + } else { + try { + return new BluetoothConnection(viewModel.MacAddress); + } catch (Exception e) { + throw new ConnectionException(e.Message, e); + } + } + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/ConnectionSelectorViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/ConnectionSelectorViewModel.cs new file mode 100644 index 0000000..6567694 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/ConnectionSelectorViewModel.cs @@ -0,0 +1,121 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Runtime.CompilerServices; +using Zebra.Sdk.Printer.Discovery; +using Zebra.Windows.DevDemo.Enums; +using Zebra.Windows.DevDemo.Utils; + +namespace Zebra.Windows.DevDemo.UserControls { + + public class ConnectionSelectorViewModel : INotifyPropertyChanged { + + private ConnectionType connectionType; + private string ipAddress; + private string port; + private string macAddress; + private string usbPrinterName; + private string symbolicName; + private ObservableCollection usbDevices = new ObservableCollection(); + + public event PropertyChangedEventHandler PropertyChanged; + + public ConnectionType ConnectionType { + get => connectionType; + set { + if (connectionType != value) { + connectionType = value; + OnPropertyChanged(); + } + } + } + + public string IpAddress { + get => ipAddress; + set { + if (ipAddress != value) { + ipAddress = value; + OnPropertyChanged(); + } + } + } + + public string Port { + get => port; + set { + if (port != value) { + port = value; + OnPropertyChanged(); + } + } + } + + public string MacAddress { + get => macAddress; + set { + if (macAddress != value) { + macAddress = value; + OnPropertyChanged(); + } + } + } + + public string UsbPrinterName { + get => usbPrinterName; + set { + if (usbPrinterName != value) { + usbPrinterName = value; + OnPropertyChanged(); + } + } + } + + public string SymbolicName { + get => symbolicName; + set { + if (symbolicName != value) { + symbolicName = value; + OnPropertyChanged(); + } + } + } + + public ObservableCollection UsbDevices { + get => usbDevices; + } + + public List ConnectionTypes { + get { + List connectionTypes = Enum.GetValues(typeof(ConnectionType)).Cast().ToList(); + if (!BluetoothHelper.IsBluetoothSupported()) { + connectionTypes.Remove(ConnectionType.Bluetooth); + } + return connectionTypes; + } + } + + public ConnectionSelectorViewModel() { + Port = "9100"; + } + + private void OnPropertyChanged([CallerMemberName] string memberName = null) { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName)); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/FileSelectorView.xaml b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/FileSelectorView.xaml new file mode 100644 index 0000000..e0d608e --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/FileSelectorView.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/FileSelectorView.xaml.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/FileSelectorView.xaml.cs new file mode 100644 index 0000000..a7ffef6 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/FileSelectorView.xaml.cs @@ -0,0 +1,45 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using Microsoft.Win32; +using System.Windows; +using System.Windows.Controls; + +namespace Zebra.Windows.DevDemo.UserControls { + + /// + /// Interaction logic for FileSelectorView.xaml + /// + public partial class FileSelectorView : UserControl { + + private FileSelectorViewModel viewModel; + + public string FileName { + get => viewModel.FileName; + } + + public FileSelectorView() { + InitializeComponent(); + + viewModel = DataContext as FileSelectorViewModel; + } + + private void BrowseButton_Click(object sender, RoutedEventArgs e) { + OpenFileDialog openFileDialog = new OpenFileDialog(); + if (openFileDialog.ShowDialog() == true) { + viewModel.FileName = openFileDialog.FileName; + } + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/FileSelectorViewModel.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/FileSelectorViewModel.cs new file mode 100644 index 0000000..1291a39 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/UserControls/FileSelectorViewModel.cs @@ -0,0 +1,40 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace Zebra.Windows.DevDemo.UserControls { + + class FileSelectorViewModel : INotifyPropertyChanged { + + private string fileName; + + public string FileName { + get => fileName; + set { + if (fileName != value) { + fileName = value; + OnPropertyChanged(); + } + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + public void OnPropertyChanged([CallerMemberName] string memberName = null) { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName)); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/BluetoothHelper.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/BluetoothHelper.cs new file mode 100644 index 0000000..d2bcea7 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/BluetoothHelper.cs @@ -0,0 +1,29 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; + +namespace Zebra.Windows.DevDemo.Utils { + + internal class BluetoothHelper { + + public static bool IsBluetoothSupported() { + var osVersion = Environment.OSVersion; + if (osVersion.Version.Major >= 10) { + return true; + } + return false; + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/ConnectionTypeDescriptionValueConverter.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/ConnectionTypeDescriptionValueConverter.cs new file mode 100644 index 0000000..f001592 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/ConnectionTypeDescriptionValueConverter.cs @@ -0,0 +1,35 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.ComponentModel; +using System.Globalization; +using System.Windows.Data; +using Zebra.Windows.DevDemo.Enums; + +namespace Zebra.Windows.DevDemo.Utils { + + public class ConnectionTypeDescriptionValueConverter : IValueConverter { + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + var type = typeof(ConnectionType); + var name = Enum.GetName(type, value); + return ((DescriptionAttribute)Attribute.GetCustomAttribute(type.GetField(name), typeof(DescriptionAttribute))).Description; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { + throw new NotImplementedException(); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/DemoViewModelNameValueConverter.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/DemoViewModelNameValueConverter.cs new file mode 100644 index 0000000..c854df2 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/DemoViewModelNameValueConverter.cs @@ -0,0 +1,32 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.Globalization; +using System.Windows.Data; +using Zebra.Windows.DevDemo.Demos; + +namespace Zebra.Windows.DevDemo.Utils { + + public class DemoViewModelNameValueConverter : IValueConverter { + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + return (value as IDemoViewModel).Name; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { + throw new NotImplementedException(); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/DiscoveryMethodDescriptionValueConverter.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/DiscoveryMethodDescriptionValueConverter.cs new file mode 100644 index 0000000..5be9a6d --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/DiscoveryMethodDescriptionValueConverter.cs @@ -0,0 +1,35 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System; +using System.ComponentModel; +using System.Globalization; +using System.Windows.Data; +using Zebra.Windows.DevDemo.Enums; + +namespace Zebra.Windows.DevDemo.Utils { + + public class DiscoveryMethodDescriptionValueConverter : IValueConverter { + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + var type = typeof(DiscoveryMethod); + var name = Enum.GetName(type, value); + return ((DescriptionAttribute) Attribute.GetCustomAttribute(type.GetField(name), typeof(DescriptionAttribute))).Description; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { + throw new NotImplementedException(); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/MessageBoxCreator.cs b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/MessageBoxCreator.cs new file mode 100644 index 0000000..37c1dd1 --- /dev/null +++ b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/Utils/MessageBoxCreator.cs @@ -0,0 +1,29 @@ +/*********************************************** + * CONFIDENTIAL AND PROPRIETARY + * + * The source code and other information contained herein is the confidential and exclusive property of + * ZIH Corp. and is subject to the terms and conditions in your end user license agreement. + * This source code, and any other information contained herein, shall not be copied, reproduced, published, + * displayed or distributed, in whole or in part, in any medium, by any means, for any purpose except as + * expressly permitted under such license agreement. + * + * Copyright ZIH Corp. 2017 + * + * ALL RIGHTS RESERVED + ***********************************************/ + +using System.Windows; + +namespace Zebra.Windows.DevDemo.Utils { + + public static class MessageBoxCreator { + + public static void ShowError(string message, string caption) { + MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Error); + } + + public static void ShowInformation(string message, string caption) { + MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Information); + } + } +} diff --git a/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/zebralogo.ico b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/zebralogo.ico new file mode 100644 index 0000000..d7034be Binary files /dev/null and b/ZSDK_DevDemos_.NET/Zebra/Windows/DevDemo/zebralogo.ico differ diff --git a/ZSDK_DevDemos_.NET/app.manifest b/ZSDK_DevDemos_.NET/app.manifest new file mode 100644 index 0000000..ff42268 --- /dev/null +++ b/ZSDK_DevDemos_.NET/app.manifest @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +