Commit 7da533f6 刘韬

接入zebra printer sdk

1 个父辈 8c307787
正在显示 116 个修改的文件 包含 4474 行增加58 行删除
......@@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrintLabel", "PrintLabel\Pr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrintLabel_Test", "PrintLabel_Test\PrintLabel_Test.csproj", "{857ACBBF-F326-4AD0-AD6F-B7F7479AFE2C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZebraPrinterHelper", "ZebraPrinterHelper\ZebraPrinterHelper.csproj", "{E4F7AFC7-2F6D-4685-8350-3C05697428EA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeveloperDemo_Windows", "ZebraDemoSource\DeveloperDemo_Windows.csproj", "{8B42A994-831D-4EAF-B40F-436166CD5B6A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -21,6 +25,14 @@ Global
{857ACBBF-F326-4AD0-AD6F-B7F7479AFE2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{857ACBBF-F326-4AD0-AD6F-B7F7479AFE2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{857ACBBF-F326-4AD0-AD6F-B7F7479AFE2C}.Release|Any CPU.Build.0 = Release|Any CPU
{E4F7AFC7-2F6D-4685-8350-3C05697428EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4F7AFC7-2F6D-4685-8350-3C05697428EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4F7AFC7-2F6D-4685-8350-3C05697428EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4F7AFC7-2F6D-4685-8350-3C05697428EA}.Release|Any CPU.Build.0 = Release|Any CPU
{8B42A994-831D-4EAF-B40F-436166CD5B6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B42A994-831D-4EAF-B40F-436166CD5B6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B42A994-831D-4EAF-B40F-436166CD5B6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B42A994-831D-4EAF-B40F-436166CD5B6A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -14,7 +14,7 @@ namespace PrintLabel
/// <summary>
/// 像素毫米转换的倍数
/// </summary>
internal const float MULTIPLE = 100f;
internal static float MULTIPLE = 203f;
/// <summary>
/// 添加标签时初始的大小,mm
/// </summary>
......
......@@ -63,6 +63,12 @@ namespace Asa
Common.LabelPrint.PrinterName = name;
Common.LabelPrint.PrintLandscape = landscape;
}
public void SetResolution(int printerDPI)
{
Common.MULTIPLE = printerDPI;
}
public bool Rotate180 { set => Common.LabelPrint.Rotate180 = value; get => Common.LabelPrint.Rotate180; }
/// <summary>
......@@ -79,7 +85,7 @@ namespace Asa
}
public Bitmap PrintPreview(Dictionary<string, string> key)
{
Common.LabelPrint.labelIdx = 1;
//Common.LabelPrint.labelIdx = 1;
Bitmap bmp = Common.LabelPrint.PrintPreview(key, out string[] code);
return bmp;
}
......
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/>
</startup>
</configuration>
\ No newline at end of file
</configuration>
......@@ -48,6 +48,7 @@ namespace PrintLabel_Test
text.Add("aa", "123");
text.Add("bb", "yumtrj");
print.Print(text);
}
private void button4_Click(object sender, EventArgs e)
......

namespace PrintLabel_Test
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button3 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button3
//
this.button3.Location = new System.Drawing.Point(483, 142);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(123, 49);
this.button3.TabIndex = 5;
this.button3.Text = "打印";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(27, 20);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(123, 49);
this.button1.TabIndex = 4;
this.button1.Text = "编辑标签";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(253, 157);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(153, 20);
this.comboBox1.TabIndex = 6;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(253, 17);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(153, 21);
this.textBox1.TabIndex = 7;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(224, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(23, 12);
this.label1.TabIndex = 8;
this.label1.Text = "IP:";
//
// button2
//
this.button2.Location = new System.Drawing.Point(483, 12);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(123, 49);
this.button2.TabIndex = 5;
this.button2.Text = "连接";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(251, 142);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(59, 12);
this.label2.TabIndex = 8;
this.label2.Text = "选择标签:";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(253, 246);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(41, 12);
this.label3.TabIndex = 9;
this.label3.Text = "label3";
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button3);
this.Controls.Add(this.button1);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label3;
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PrintLabel_Test
{
public partial class Form2 : Form
{
private Asa.PrintLabel print;
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
print = new Asa.PrintLabel(Application.StartupPath + "\\Label");
reloadlabel();
ConfigHelper.Config.PropertyBind("IP", textBox1, "Text", "TextChanged");
ConfigHelper.Config.PropertyBind<int>("labelindex", comboBox1, "SelectedIndex", "SelectedIndexChanged");
}
private void button1_Click(object sender, EventArgs e)
{
print.EditLabel();
reloadlabel();
}
void reloadlabel() {
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.Items.Clear();
comboBox1.Items.AddRange(print.GetLabelName());
comboBox1.SelectedIndex = 0;
}
private void button3_Click(object sender, EventArgs e)
{
print.LoadLabel(comboBox1.Text);
Dictionary<string, string> text = new Dictionary<string, string>();
text.Add("aa", "123");
text.Add("bb", "yumtrj");
text.Add("cc", DateTime.Now.ToString());
var bmp = print.PrintPreview(text);
if (!zebraManger.PrintImage(bmp, out string msg)) {
MessageBox.Show(msg);
}
bmp.Dispose();
}
ZebraPrinterHelper.ZebraManger zebraManger;
private void button2_Click(object sender, EventArgs e)
{
zebraManger = new ZebraPrinterHelper.ZebraManger(textBox1.Text, ZebraPrinterHelper.ConnectionType.Network);
if (!zebraManger.Connection(out string msg)) {
MessageBox.Show(msg);
}else
MessageBox.Show("连接成功");
}
private void timer1_Tick(object sender, EventArgs e)
{
if (zebraManger == null)
return;
Task.Run(() =>
{
if (zebraManger.IsLabelOnPeeler)
this.Invoke((EventHandler)delegate
{
label3.Text = "剥纸器上检测到有标签";
});
else
this.Invoke((EventHandler)delegate
{
label3.Text = "剥纸器上没有检测到标签";
});
});
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
\ No newline at end of file
......@@ -8,10 +8,11 @@
<OutputType>WinExe</OutputType>
<RootNamespace>PrintLabel_Test</RootNamespace>
<AssemblyName>PrintLabel_Test</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
......@@ -33,6 +34,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ConfigHelper">
<HintPath>..\..\ConfigHelper\ConfigHelper\bin\Debug\ConfigHelper.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.Core" />
......@@ -53,11 +57,20 @@
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Form2.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form2.Designer.cs">
<DependentUpon>Form2.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form2.resx">
<DependentUpon>Form2.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
......@@ -66,6 +79,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
......@@ -85,6 +99,10 @@
<Project>{b8f25ece-dee6-41d6-8ef0-8afbf2577c17}</Project>
<Name>PrintLabel</Name>
</ProjectReference>
<ProjectReference Include="..\ZebraPrinterHelper\ZebraPrinterHelper.csproj">
<Project>{e4f7afc7-2f6d-4685-8350-3c05697428ea}</Project>
<Name>ZebraPrinterHelper</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
......@@ -16,7 +16,7 @@ namespace PrintLabel_Test
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new Form2());
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace PrintLabel_Test.Properties
{
namespace PrintLabel_Test.Properties {
using System;
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
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()
{
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PrintLabel_Test.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 覆盖当前线程的 CurrentUICulture 属性
/// 使用此强类型的资源类的资源查找
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set
{
set {
resourceCulture = value;
}
}
......
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace PrintLabel_Test.Properties
{
namespace PrintLabel_Test.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.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
{
public static Settings Default {
get {
return defaultInstance;
}
}
......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
</configuration>
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 © 2018")]
[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
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> 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")]
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Zebra.Windows.DevDemo.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// 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", "15.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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Zebra.Windows.DevDemo.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.6.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;
}
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
\ No newline at end of file
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件的差异太大,无法显示。
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<Application x:Class="DeveloperDemo_Windows.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style x:Key="ZebraHeader" TargetType="TextBlock">
<Setter Property="Foreground" Value="#007CB0" />
<Setter Property="FontSize" Value="16" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
<Style x:Key="ZebraTextInput" TargetType="TextBox">
<Setter Property="FontSize" Value="12" />
<Setter Property="Height" Value="24" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
<Style TargetType="ComboBox">
<Setter Property="Height" Value="30" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
<Style x:Key="DashedLineFocusVisualStyle">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="2"
StrokeThickness="1"
Stroke="Black"
StrokeDashArray="2 2"
SnapsToDevicePixels="true"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="Button">
<Setter Property="Background" Value="#007CB0" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Padding" Value="10,0" />
<Setter Property="Height" Value="24" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="FocusVisualStyle" Value="{StaticResource DashedLineFocusVisualStyle}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#3396C0" />
<Setter Property="Opacity" Value="1" />
</Trigger>
</Style.Triggers>
</Style>
</Application.Resources>
</Application>
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
using System.Windows;
namespace Zebra.Windows.DevDemo {
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application {
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.ConnectionBuilder.ConnectionBuilderView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos.ConnectionBuilder"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:ConnectionBuilderViewModel />
</UserControl.DataContext>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Style="{StaticResource ZebraHeader}" Grid.ColumnSpan="2" Margin="0,0,0,10">Connection Builder</TextBlock>
<TextBlock Grid.Row="1" Name="AddressTextBlock" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,10">Address:</TextBlock>
<TextBox x:Name="usbDriverIpAddress" Style="{StaticResource ZebraTextInput}" Grid.Row="1" Grid.Column="1" Margin="0,0,0,10" VerticalAlignment="Center" KeyUp="UsbDriverIpAddress_KeyUp" />
<TextBlock Grid.Row="2" Margin="0,0,10,10" VerticalAlignment="Center">Connection Prefix:</TextBlock>
<ComboBox x:Name="connectionPrefixDropdown" ItemsSource="{Binding ConnectionPrefixes}" Width="180" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,0,0,10" SelectionChanged="ConnectionPrefixDropdown_SelectionChanged" />
<TextBlock Grid.Row="3" Margin="0,0,10,15" VerticalAlignment="Center">Connection String:</TextBlock>
<TextBlock x:Name="connectionString" Grid.Row="3" Grid.Column="1" Margin="0,0,0,15" VerticalAlignment="Center" />
<Button x:Name="testConnectionStringButton" Grid.Row="4" Grid.ColumnSpan="2" Click="TestConnectionStringButton_Click">Test Connection String</Button>
<Separator Grid.Row="5" Grid.ColumnSpan="2" Margin="0,15,0,15" />
<TextBlock Style="{StaticResource ZebraHeader}" Grid.Row="6" Grid.ColumnSpan="2" Margin="0,0,0,10">Log</TextBlock>
<TextBox x:Name="logData" Text="{Binding LogData}" Grid.Row="7" Grid.ColumnSpan="2" AcceptsReturn="True" TextWrapping="NoWrap" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"></TextBox>
</Grid>
</UserControl>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for ConnectionBuilderView.xaml
/// </summary>
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();
}
}
}
/***********************************************
* 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. 2018
*
* 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<string> connectionPrefixes = new ObservableCollection<string>() {
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<string> ConnectionPrefixes {
get => connectionPrefixes;
}
public ConnectionBuilderViewModel() {
Name = "Connection Builder";
logData = "Log:\n\n";
if(BluetoothHelper.IsBluetoothSupported()) {
connectionPrefixes.Add(ConnectionPrefix.Bluetooth);
connectionPrefixes.Add(ConnectionPrefix.BluetoothMulti);
}
}
}
}
/***********************************************
* 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. 2018
*
* 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";
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.Connectivity.ConnectivityView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos"
xmlns:usercontrols="clr-namespace:Zebra.Windows.DevDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">Connectivity</TextBlock>
<usercontrols:ConnectionSelectorView x:Name="connectionSelector" Margin="0,0,0,15" />
<Button x:Name="testButton" Click="TestButton_Click">Test</Button>
<Separator Margin="0,15,0,15" />
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">Connection Status</TextBlock>
<TextBlock><Bold><Run x:Name="connectionStatus" Foreground="Red" Text="Not Connected"></Run></Bold></TextBlock>
</StackPanel>
</UserControl>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for Connectivity.xaml
/// </summary>
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;
}
}
}
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
namespace Zebra.Windows.DevDemo.Demos.Connectivity {
public class ConnectivityViewModel : IDemoViewModel {
public ConnectivityViewModel() {
Name = "Connectivity";
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.Discovery.DiscoveryView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos.Discovery"
xmlns:utils="clr-namespace:Zebra.Windows.DevDemo.Utils"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:DiscoveryViewModel />
</UserControl.DataContext>
<UserControl.Resources>
<utils:DiscoveryMethodDescriptionValueConverter x:Key="converter" />
</UserControl.Resources>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">Discovery</TextBlock>
<Grid Grid.Row="1" Margin="0,0,0,15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Margin="0,0,10,0" VerticalAlignment="Center">Discovery Method:</TextBlock>
<ComboBox x:Name="discoveryMethodsDropdown" ItemsSource="{Binding DiscoveryMethods}" Grid.Column="1" Width="160" HorizontalAlignment="Left" VerticalAlignment="Center" SelectionChanged="DiscoveryMethodsDropdown_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Converter={StaticResource converter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock x:Name="ipAddressLabel" Grid.Row="1" Margin="0,10,10,0" VerticalAlignment="Center">IP Address:</TextBlock>
<TextBox x:Name="ipAddressInput" Style="{StaticResource ZebraTextInput}" Text="{Binding IpAddress}" Grid.Row="1" Grid.Column="1" Margin="0,10,0,0" Width="120" HorizontalAlignment="Left" VerticalAlignment="Center" />
<TextBlock x:Name="numberOfHopsLabel" Grid.Row="2" Margin="0,10,10,0" VerticalAlignment="Center">Number of Hops:</TextBlock>
<TextBox x:Name="numberOfHopsInput" Style="{StaticResource ZebraTextInput}" Text="{Binding NumberOfHops}" Grid.Row="2" Grid.Column="1" Margin="0,10,0,0" Width="120" HorizontalAlignment="Left" VerticalAlignment="Center" PreviewTextInput="NumberOfHopsInput_PreviewTextInput" />
<TextBlock x:Name="subnetRangeLabel" Grid.Row="3" Margin="0,10,10,0" VerticalAlignment="Center">Subnet Range:</TextBlock>
<TextBox x:Name="subnetRangeInput" Style="{StaticResource ZebraTextInput}" Text="{Binding SubnetRange}" Grid.Row="3" Grid.Column="1" Margin="0,10,0,0" Width="120" HorizontalAlignment="Left" VerticalAlignment="Center" />
</Grid>
<Button Grid.Row="2" x:Name="discoverPrintersButton" Click="DiscoverPrintersButton_Click">Discover Printers</Button>
<Separator Grid.Row="3" Margin="0,15,0,15" />
<Grid Grid.Row="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource ZebraHeader}" Grid.ColumnSpan="2" Margin="0,0,0,10">Discovered Printers</TextBlock>
<ListBox x:Name="discoveredPrintersList" ItemsSource="{Binding DiscoveredPrinters}" Grid.Row="1" Margin="0,0,5,0" SelectionChanged="DiscoveredPrintersList_SelectionChanged">
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy" Click="DiscoveredPrintersList_Click"/>
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>
<TextBox x:Name="discoveredPrinterInfo" Text="{Binding DiscoveredPrinterInfo}" Grid.Row="1" Grid.Column="1" Margin="5,0,0,0" AcceptsReturn="True" TextWrapping="NoWrap" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"></TextBox>
</Grid>
</Grid>
</UserControl>
/***********************************************
* 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. 2018
*
* 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.Printer.Discovery;
using Zebra.Windows.DevDemo.Enums;
using Zebra.Windows.DevDemo.Utils;
namespace Zebra.Windows.DevDemo.Demos.Discovery {
/// <summary>
/// Interaction logic for Discovery.xaml
/// </summary>
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<string, string> 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);
}
/// <exception cref="ConnectionException"></exception>
/// <exception cref="DiscoveryException"></exception>
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(new ZebraPrinterFilter())) {
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);
});
}
}
}
}
/***********************************************
* 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. 2018
*
* 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<DiscoveredPrinter> discoveredPrinters = new ObservableCollection<DiscoveredPrinter>();
private string discoveredPrinterInfo;
private string ipAddress;
private string numberOfHops;
private string subnetRange;
public List<DiscoveryMethod> DiscoveryMethods {
get {
List<DiscoveryMethod> discoveryMethods = Enum.GetValues(typeof(DiscoveryMethod)).Cast<DiscoveryMethod>().ToList();
if(!BluetoothHelper.IsBluetoothSupported()) {
discoveryMethods.Remove(DiscoveryMethod.Bluetooth);
}
return discoveryMethods;
}
}
public ObservableCollection<DiscoveredPrinter> 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";
}
}
}
/***********************************************
* 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. 2018
*
* 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));
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.ImagePrint.ImagePrintView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos.ImagePrint"
xmlns:usercontrols="clr-namespace:Zebra.Windows.DevDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:ImagePrintViewModel />
</UserControl.DataContext>
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">Image Print</TextBlock>
<usercontrols:ConnectionSelectorView x:Name="connectionSelector" Margin="0,0,0,10" />
<Grid Margin="0,0,0,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" Margin="0,0,10,10">Image File:</TextBlock>
<usercontrols:FileSelectorView x:Name="fileSelector" Grid.Column="1" Margin="0,0,0,10" />
<TextBlock VerticalAlignment="Center" Grid.Row="1" Margin="0,0,10,10"><Run Text="Store on Printer:" /></TextBlock>
<CheckBox IsChecked="{Binding ShouldStoreImage}" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,0,10" />
<TextBlock VerticalAlignment="Center" Grid.Row="2" Margin="0,0,10,15"><Run Text="Stored File Name:" /></TextBlock>
<TextBox Text="{Binding StoredFileName}" Style="{StaticResource ZebraTextInput}" VerticalAlignment="Center" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,0,15" />
<Button x:Name="printButton" Grid.Row="3" Grid.ColumnSpan="3" Content="Print" Click="PrintButton_Click" />
</Grid>
</StackPanel>
</UserControl>
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
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.Graphics;
using Zebra.Sdk.Printer;
using Zebra.Windows.DevDemo.Utils;
namespace Zebra.Windows.DevDemo.Demos.ImagePrint {
/// <summary>
/// Interaction logic for ImagePrintView.xaml
/// </summary>
public partial class ImagePrintView : UserControl {
private ImagePrintViewModel viewModel;
public ImagePrintView() {
InitializeComponent();
viewModel = DataContext as ImagePrintViewModel;
}
private void PrintButton_Click(object sender, RoutedEventArgs evt) {
SetPrintButtonState(false);
Connection printerConnection = null;
Task.Run(() => {
try {
printerConnection = connectionSelector.GetConnection();
printerConnection.Open();
ZebraImageI image = ZebraImageFactory.GetImage(fileSelector.FileName);
if (viewModel.ShouldStoreImage) {
ZebraPrinterFactory.GetInstance(printerConnection).StoreImage(viewModel.StoredFileName, image, 540, 412);
}
ZebraPrinterFactory.GetInstance(printerConnection).PrintImage(image, 0, 0, 550, 412, false);
} 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, "Image Error");
} catch (ZebraIllegalArgumentException e) {
MessageBoxCreator.ShowError(e.Message, "Illegal Arguments");
} catch (ArgumentException e) {
MessageBoxCreator.ShowError(e.Message, "Invalid File Path");
} finally {
try {
if (printerConnection != null) {
printerConnection.Close();
}
} catch (ConnectionException) {
} finally {
SetPrintButtonState(true);
}
}
});
}
private void SetPrintButtonState(bool state) {
Application.Current.Dispatcher.Invoke(() => {
printButton.IsEnabled = state;
});
}
}
}
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
namespace Zebra.Windows.DevDemo.Demos.ImagePrint {
class ImagePrintViewModel : IDemoViewModel {
private bool shouldStoreImage;
private string storedFileName;
public bool ShouldStoreImage {
get => shouldStoreImage;
set {
if (shouldStoreImage != value) {
shouldStoreImage = value;
OnPropertyChanged();
}
}
}
public string StoredFileName {
get => storedFileName;
set {
if (storedFileName != value) {
storedFileName = value;
OnPropertyChanged();
}
}
}
public ImagePrintViewModel() {
Name = "Image Print";
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.ListFormats.ListFormatsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos.ListFormats"
xmlns:usercontrols="clr-namespace:Zebra.Windows.DevDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:ListFormatsViewModel />
</UserControl.DataContext>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">List Formats</TextBlock>
<usercontrols:ConnectionSelectorView x:Name="connectionSelector" Grid.Row="1" Margin="0,0,0,15" />
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="retrieveFilesButton" Margin="0,0,5,0" Click="RetrieveFilesButton_Click">Retrieve Files</Button>
<Button x:Name="retrieveFormatsButton" Grid.Column="1" Margin="5,0,0,0" Click="RetrieveFormatsButton_Click">Retrieve Formats</Button>
</Grid>
<Separator Grid.Row="3" Margin="0,15,0,15" />
<TextBlock Style="{StaticResource ZebraHeader}" Grid.Row="4" Margin="0,0,0,10">Retrieved Files / Formats</TextBlock>
<ListBox ItemsSource="{Binding FormatsList}" Grid.Row="5" x:Name="storedFilesList"></ListBox>
</Grid>
</UserControl>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for ListFormatsView.xaml
/// </summary>
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);
}
}
}
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
using System.Collections.ObjectModel;
namespace Zebra.Windows.DevDemo.Demos.ListFormats {
class ListFormatsViewModel : IDemoViewModel {
private ObservableCollection<string> formatsList = new ObservableCollection<string>();
public ObservableCollection<string> FormatsList {
get => formatsList;
}
public ListFormatsViewModel() {
Name = "List Formats";
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.MagCard.MagCardView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos.MagCard"
xmlns:usercontrols="clr-namespace:Zebra.Windows.DevDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:MagCardViewModel />
</UserControl.DataContext>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">Mag Card</TextBlock>
<usercontrols:ConnectionSelectorView x:Name="connectionSelector" Grid.Row="1" Margin="0,0,0,15" />
<Button x:Name="readMagCardButton" Grid.Row="2" Click="ReadMagCardButton_Click">Read Mag Card</Button>
<Separator Grid.Row="3" Margin="0,15,0,15" />
<TextBlock Style="{StaticResource ZebraHeader}" Grid.Row="4" Margin="0,0,0,10">Mag Card Data</TextBlock>
<TextBox x:Name="magCardData" Text="{Binding MagCardData}" Grid.Row="5" AcceptsReturn="True" TextWrapping="NoWrap" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"></TextBox>
</Grid>
</UserControl>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for MagCardView.xaml
/// </summary>
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");
}
}
}
}
/***********************************************
* 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. 2018
*
* 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";
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.PrinterStatus.PrinterStatusView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos.PrinterStatus"
xmlns:usercontrols="clr-namespace:Zebra.Windows.DevDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">Printer Status</TextBlock>
<usercontrols:ConnectionSelectorView x:Name="connectionSelector" Grid.Row="1" Margin="0,0,0,15" />
<Button x:Name="getPrinterStatusButton" Grid.Row="2" Click="GetPrinterStatusButton_Click">Get Printer Status</Button>
<Separator Grid.Row="3" Margin="0,15,0,15" />
<TextBlock Style="{StaticResource ZebraHeader}" Grid.Row="4" Margin="0,0,0,10">Printer Status</TextBlock>
<TextBox x:Name="printerStatus" Grid.Row="5" AcceptsReturn="True" TextWrapping="NoWrap" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" />
</Grid>
</UserControl>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for PrinterStatusView.xaml
/// </summary>
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<string> 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<string> 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<string> { 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;
});
}
}
}
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
namespace Zebra.Windows.DevDemo.Demos.PrinterStatus {
public class PrinterStatusViewModel : IDemoViewModel {
public PrinterStatusViewModel() {
Name = "Printer Status";
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.Profile.ProfileView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos.Profile"
xmlns:usercontrols="clr-namespace:Zebra.Windows.DevDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">Profile</TextBlock>
<usercontrols:ConnectionSelectorView x:Name="connectionSelector" Margin="0,0,0,10" />
<!--<Grid Margin="0,0,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" VerticalAlignment="Center" Margin="0,0,10,10">Profile File:</TextBlock>
<TextBox Grid.Column="1" VerticalAlignment="Center" Margin="0,0,10,10"/>
<Button Grid.Column="2" VerticalAlignment="Center" Margin="0,0,0,10" Click="BrowseButton_Click" Content="Browse"/>
</Grid>-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="createProfileButton" Margin="0,5,5,0" Click="CreateProfileButton_Click">Create Profile</Button>
<Button x:Name="uploadProfileButton" Grid.Column="1" Margin="5,5,0,0" Click="UploadProfileButton_Click">Upload Profile</Button>
</Grid>
</StackPanel>
</UserControl>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for ProfileView.xaml
/// </summary>
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);
}
}
}
}
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
namespace Zebra.Windows.DevDemo.Demos.Profile {
class ProfileViewModel : IDemoViewModel {
public ProfileViewModel() {
Name = "Profile";
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.SendFile.SendFileView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos.SendFile"
xmlns:usercontrols="clr-namespace:Zebra.Windows.DevDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">Send File</TextBlock>
<usercontrols:ConnectionSelectorView x:Name="connectionSelector" Grid.Row="1" Margin="0,0,0,15" />
<Button x:Name="sendFileButton" Grid.Row="2" Click="SendFileButton_Click">Send File</Button>
</Grid>
</UserControl>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for SendFileView.xaml
/// </summary>
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;
});
}
}
}
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
namespace Zebra.Windows.DevDemo.Demos.SendFile {
class SendFileViewModel : IDemoViewModel {
public SendFileViewModel() {
Name = "Send File";
}
}
}
/***********************************************
* 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. 2018
*
* 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;
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.Settings.SettingsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos.Settings"
xmlns:usercontrols="clr-namespace:Zebra.Windows.DevDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:SettingsViewModel />
</UserControl.DataContext>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">Settings</TextBlock>
<usercontrols:ConnectionSelectorView x:Name="connectionSelector" Grid.Row="1" Margin="0,0,0,15" />
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="saveSettingsButton" Margin="0,0,5,0" Click="SaveSettingsButton_Click">Save Settings and Refresh</Button>
<Button x:Name="getSettingsButton" Grid.Column="1" Margin="5,0,0,0" Click="GetSettingsButton_Click">Get Settings</Button>
</Grid>
<Separator Grid.Row="3" Margin="0,15,0,15" />
<TextBlock Style="{StaticResource ZebraHeader}" Grid.Row="4" Margin="0,0,0,10">Printer Settings</TextBlock>
<DataGrid x:Name="printerSettingsGrid" ItemsSource="{Binding Settings}" Grid.Row="5" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CellEditEnding="PrinterSettingsGrid_CellEditEnding">
<DataGrid.Columns>
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True" Width="140" />
<DataGridTextColumn Header="Value" Binding="{Binding Value}" Width="*" />
<DataGridTextColumn Header="Range" Binding="{Binding Range}" IsReadOnly="True" Width="140" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</UserControl>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for SettingsView.xaml
/// </summary>
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<string, Sdk.Settings.Setting> 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);
}
}
}
}
}
}
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Zebra.Windows.DevDemo.Demos.Settings {
class SettingsViewModel : IDemoViewModel {
private ObservableCollection<Setting> settings = new ObservableCollection<Setting>();
private Dictionary<string, string> modifiedSettings = new Dictionary<string, string>();
public ObservableCollection<Setting> Settings {
get => settings;
}
public Dictionary<string, string> ModifiedSettings {
get => modifiedSettings;
}
public SettingsViewModel() {
Name = "Settings";
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.SmartCard.SmartCardView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos.SmartCard"
xmlns:usercontrols="clr-namespace:Zebra.Windows.DevDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">Smart Card</TextBlock>
<usercontrols:ConnectionSelectorView x:Name="connectionSelector" Grid.Row="1" Margin="0,0,0,15" />
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="sendDataButton" Margin="0,0,5,0" Click="SendDataButton_Click">Send Data</Button>
<Button x:Name="sendAtrButton" Grid.Column="1" Margin="5,0,0,0" Click="SendAtrButton_Click">Send ATR</Button>
</Grid>
<Separator Grid.Row="3" Margin="0,15,0,15" />
<TextBlock Style="{StaticResource ZebraHeader}" Grid.Row="4" Margin="0,0,0,10">Response Data</TextBlock>
<TextBox x:Name="responseData" Grid.Row="5" AcceptsReturn="True" TextWrapping="NoWrap" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"></TextBox>
</Grid>
</UserControl>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for SmartCardView.xaml
/// </summary>
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);
}
}
}
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
namespace Zebra.Windows.DevDemo.Demos.SmartCard {
class SmartCardViewModel : IDemoViewModel {
public SmartCardViewModel() {
Name = "Smart Card";
}
}
}
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
namespace Zebra.Windows.DevDemo.Demos.StoredFormat {
public class FormatVariable {
public string FieldName {
get; set;
}
public string FieldValue {
get; set;
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.Demos.StoredFormat.StoredFormatView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Demos.StoredFormat"
xmlns:usercontrols="clr-namespace:Zebra.Windows.DevDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:StoredFormatViewModel />
</UserControl.DataContext>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource ZebraHeader}" Margin="0,0,0,10">Stored Formats</TextBlock>
<usercontrols:ConnectionSelectorView x:Name="connectionSelector" Grid.Row="1" Margin="0,0,0,15" />
<Button x:Name="retrieveFormatsButton" Grid.Row="2" Margin="5,0,0,0" Click="RetrieveFormatsButton_Click">Retrieve Formats</Button>
<Separator Grid.Row="3" Margin="0,15,0,15" />
<TextBlock Style="{StaticResource ZebraHeader}" Grid.Row="4" Margin="0,0,0,10">Retrieved Formats</TextBlock>
<ListBox ItemsSource="{Binding StoredFormatList}" Grid.Row="5" x:Name="storedFilesList" MouseDoubleClick="StoredFilesList_MouseDoubleClick"></ListBox>
</Grid>
</UserControl>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for StoredFormatView.xaml
/// </summary>
public partial class StoredFormatView : UserControl {
private StoredFormatViewModel viewModel;
private List<FieldDescriptionData> fieldDescDataVars;
private ObservableCollection<FormatVariable> 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<FormatVariable>();
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<int, string> 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<FieldDescriptionData> FormatFieldDescriptionDataVars(List<FieldDescriptionData> variables) {
foreach (FieldDescriptionData data in variables) {
data.FieldName = data.FieldName ?? "Field " + data.FieldNumber;
}
return variables;
}
private Dictionary<int, string> GetFormatVariables() {
Dictionary<int, string> formatVars = new Dictionary<int, string>();
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
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
using System.Collections.ObjectModel;
namespace Zebra.Windows.DevDemo.Demos.StoredFormat {
public class StoredFormatViewModel : IDemoViewModel {
private ObservableCollection<string> storedFormatList = new ObservableCollection<string>();
public ObservableCollection<string> StoredFormatList {
get => storedFormatList;
}
public StoredFormatViewModel() {
Name = "Stored Format";
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<Window x:Class="Zebra.Windows.DevDemo.Dialogs.StoredFormatDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.Dialogs"
mc:Ignorable="d"
Title="Format Variables" Height="300" Width="300">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid x:Name="formatVariables" ItemsSource="{Binding FormatVariables}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Variable" Binding="{Binding FieldName}" IsReadOnly="True" Width="140" />
<DataGridTextColumn Header="Value" Binding="{Binding FieldValue}" Width="*" />
</DataGrid.Columns>
</DataGrid>
<Button x:Name="printFormatButton" Grid.Row="1" Margin="0,10,0,0">Print Format</Button>
</Grid>
</Window>
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
using System.Windows;
using System.Windows.Controls;
namespace Zebra.Windows.DevDemo.Dialogs {
/// <summary>
/// Interaction logic for StoredFormatDialog.xaml
/// </summary>
public partial class StoredFormatDialog : Window {
public Button PrintFormatButton {
get => printFormatButton;
}
public StoredFormatDialog(StoredFormatDialogViewModel viewModel) {
InitializeComponent();
DataContext = viewModel;
}
}
}
/***********************************************
* 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. 2018
*
* 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<FormatVariable> formatVariables = new ObservableCollection<FormatVariable>();
public event PropertyChangedEventHandler PropertyChanged;
public ObservableCollection<FormatVariable> FormatVariables {
get => formatVariables;
}
public StoredFormatDialogViewModel(ObservableCollection<FormatVariable> formatVariables) {
this.formatVariables = formatVariables;
}
private void OnPropertyChanged([CallerMemberName] string memberName = null) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName));
}
}
}
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
namespace Zebra.Windows.DevDemo.Enums {
public enum ConnectionState {
Success,
Error,
Progress,
Info
}
}
/***********************************************
* 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. 2018
*
* 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
}
}
/***********************************************
* 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. 2018
*
* 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
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<Window x:Class="Zebra.Windows.DevDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo"
xmlns:utils="clr-namespace:Zebra.Windows.DevDemo.Utils"
xmlns:connectivity="clr-namespace:Zebra.Windows.DevDemo.Demos.Connectivity"
xmlns:discovery="clr-namespace:Zebra.Windows.DevDemo.Demos.Discovery"
xmlns:imageprint="clr-namespace:Zebra.Windows.DevDemo.Demos.ImagePrint"
xmlns:listformats="clr-namespace:Zebra.Windows.DevDemo.Demos.ListFormats"
xmlns:magcard="clr-namespace:Zebra.Windows.DevDemo.Demos.MagCard"
xmlns:printerstatus="clr-namespace:Zebra.Windows.DevDemo.Demos.PrinterStatus"
xmlns:profile="clr-namespace:Zebra.Windows.DevDemo.Demos.Profile"
xmlns:sendfile="clr-namespace:Zebra.Windows.DevDemo.Demos.SendFile"
xmlns:settings="clr-namespace:Zebra.Windows.DevDemo.Demos.Settings"
xmlns:smartcard="clr-namespace:Zebra.Windows.DevDemo.Demos.SmartCard"
xmlns:storedformat="clr-namespace:Zebra.Windows.DevDemo.Demos.StoredFormat"
xmlns:connectionbuilder="clr-namespace:Zebra.Windows.DevDemo.Demos.ConnectionBuilder"
mc:Ignorable="d"
WindowStyle="None" ResizeMode="CanResizeWithGrip" AllowsTransparency="True"
Title="Zebra Developer Demos" MinWidth="640" Width="640" MinHeight="480" Height="480">
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
<Window.Resources>
<utils:DemoViewModelNameValueConverter x:Key="converter" />
<DataTemplate DataType="{x:Type connectivity:ConnectivityViewModel}">
<connectivity:ConnectivityView />
</DataTemplate>
<DataTemplate DataType="{x:Type discovery:DiscoveryViewModel}">
<discovery:DiscoveryView />
</DataTemplate>
<DataTemplate DataType="{x:Type imageprint:ImagePrintViewModel}">
<imageprint:ImagePrintView />
</DataTemplate>
<DataTemplate DataType="{x:Type listformats:ListFormatsViewModel}">
<listformats:ListFormatsView />
</DataTemplate>
<DataTemplate DataType="{x:Type magcard:MagCardViewModel}">
<magcard:MagCardView />
</DataTemplate>
<DataTemplate DataType="{x:Type printerstatus:PrinterStatusViewModel}">
<printerstatus:PrinterStatusView />
</DataTemplate>
<DataTemplate DataType="{x:Type profile:ProfileViewModel}">
<profile:ProfileView />
</DataTemplate>
<DataTemplate DataType="{x:Type sendfile:SendFileViewModel}">
<sendfile:SendFileView />
</DataTemplate>
<DataTemplate DataType="{x:Type settings:SettingsViewModel}">
<settings:SettingsView />
</DataTemplate>
<DataTemplate DataType="{x:Type smartcard:SmartCardViewModel}">
<smartcard:SmartCardView />
</DataTemplate>
<DataTemplate DataType="{x:Type storedformat:StoredFormatViewModel}">
<storedformat:StoredFormatView />
</DataTemplate>
<DataTemplate DataType="{x:Type connectionbuilder:ConnectionBuilderViewModel}">
<connectionbuilder:ConnectionBuilderView />
</DataTemplate>
<BitmapImage x:Key="ZebraLogoImageSource" UriSource="../../../Resources/Images/Zebra_Logo_W.png" />
</Window.Resources>
<DockPanel>
<Grid x:Name="titleBar" DockPanel.Dock="Top" Background="#007CB0" MouseDown="TitleBar_MouseDown">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="{StaticResource ZebraLogoImageSource}" Width="120" Height="40" Margin="15" />
<TextBlock x:Name="closeButton" Grid.Column="1" Foreground="White" FontWeight="Bold" FontSize="24" Padding="10,0" VerticalAlignment="Top" HorizontalAlignment="Right" PreviewMouseLeftButtonDown="CloseButton_PreviewMouseLeftButtonDown">×</TextBlock>
</Grid>
<DockPanel DockPanel.Dock="Left" Margin="10" Width="150">
<TextBlock Style="{StaticResource ZebraHeader}" DockPanel.Dock="Top" Margin="0,0,0,10">Available Demos</TextBlock>
<ListBox ItemsSource="{Binding DemoViewModels}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListBoxItem_PreviewMouseLeftButtonDown" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Converter={StaticResource converter}}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
<ContentControl Content="{Binding CurrentDemoViewModel}" />
</DockPanel>
</Window>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
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) {
Application.Current.Shutdown();
}
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);
}
}
}
}
/***********************************************
* 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. 2018
*
* 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<IDemoViewModel> demoViewModels;
public event PropertyChangedEventHandler PropertyChanged;
public IDemoViewModel CurrentDemoViewModel {
get => currentDemoViewModel;
set {
if (currentDemoViewModel != value) {
currentDemoViewModel = value;
OnPropertyChanged();
}
}
}
public ObservableCollection<IDemoViewModel> DemoViewModels {
get {
if (demoViewModels == null) {
demoViewModels = new ObservableCollection<IDemoViewModel>();
}
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));
}
}
}
<!--
/***********************************************
* 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. 2018
*
* ALL RIGHTS RESERVED
***********************************************/
-->
<UserControl x:Class="Zebra.Windows.DevDemo.UserControls.ConnectionSelectorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zebra.Windows.DevDemo.UserControls"
xmlns:utils="clr-namespace:Zebra.Windows.DevDemo.Utils"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:ConnectionSelectorViewModel />
</UserControl.DataContext>
<UserControl.Resources>
<utils:ConnectionTypeDescriptionValueConverter x:Key="converter" />
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Margin="0,0,10,10" VerticalAlignment="Center">Connection Type:</TextBlock>
<ComboBox x:Name="connectionTypesDropdown" ItemsSource="{Binding ConnectionTypes}" Width="100" Grid.Column="1" Margin="0,0,0,10" HorizontalAlignment="Left" VerticalAlignment="Center" SelectionChanged="ConnectionTypesDropdown_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Converter={StaticResource converter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock x:Name="usbPrintersLabel" Grid.Row="1" Margin="0,0,10,0" VerticalAlignment="Center">USB Printers:</TextBlock>
<ComboBox x:Name="usbPrintersDropdown" ItemsSource="{Binding UsbDevices}" Width="180" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" />
<TextBlock x:Name="usbDirectLabel" Grid.Row="1" Margin="0,0,10,0" VerticalAlignment="Center">Symbolic Name:</TextBlock>
<TextBox x:Name="usbDirectInput" Width="180" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding SymbolicName}" />
<TextBlock x:Name="ipAddressLabel" Grid.Row="1" Margin="0,0,10,10" VerticalAlignment="Center">IP Address:</TextBlock>
<TextBox x:Name="ipAddressInput" Style="{StaticResource ZebraTextInput}" Width="180" Grid.Row="1" Grid.Column="1" Margin="0,0,0,10" HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding IpAddress}" />
<TextBlock x:Name="btAddressLabel" Grid.Row="1" Margin="0,0,10,10" VerticalAlignment="Center">Bluetooth Address:</TextBlock>
<TextBox x:Name="btAddressInput" Style="{StaticResource ZebraTextInput}" Width="180" Grid.Row="1" Grid.Column="1" Margin="0,0,0,10" HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding MacAddress}" />
<TextBlock x:Name="portLabel" Grid.Row="2" Margin="0,0,10,0" VerticalAlignment="Center">Port:</TextBlock>
<TextBox x:Name="portInput" Style="{StaticResource ZebraTextInput}" Width="60" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding Port}" />
</Grid>
</UserControl>
/***********************************************
* 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. 2018
*
* 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 {
/// <summary>
/// Interaction logic for ConnectionSelectorView.xaml
/// </summary>
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<DiscoveredPrinterDriver> 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<string>()));
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);
}
}
}
}
}
/***********************************************
* 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. 2018
*
* 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<DiscoveredPrinter> usbDevices = new ObservableCollection<DiscoveredPrinter>();
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<DiscoveredPrinter> UsbDevices {
get => usbDevices;
}
public List<ConnectionType> ConnectionTypes {
get {
List<ConnectionType> connectionTypes = Enum.GetValues(typeof(ConnectionType)).Cast<ConnectionType>().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));
}
}
}
此文件太大,无法显示。
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!