Click or drag to resize

ProfileUtil Interface

Defines functions used for creating and applying profiles to a Zebra printer.

Namespace:  Zebra.Sdk.Printer
Assembly:  SdkApi.Core (in SdkApi.Core.dll) Version: 2.15.2634
Syntax
public interface ProfileUtil

The ProfileUtil type exposes the following members.

Methods
  NameDescription
Public methodCreateBackup
Save a backup of your printer's settings, alerts, and files for later restoration.
Public methodCreateProfile(Stream)
Create a profile of your printer's settings, alerts, and files for cloning to other printers.
Public methodCreateProfile(String)
Create a profile of your printer's settings, alerts, and files for cloning to other printers.
Public methodLoadBackup(String)
Takes settings, alerts, and files from a backup, and applies them to a printer.
Public methodLoadBackup(String, Boolean)
Takes settings, alerts, and files from a backup, and applies them to a printer.
Public methodLoadProfile(String)
Takes settings, alerts, and files from a profile, and applies them to a printer.
Public methodLoadProfile(String, FileDeletionOption, Boolean)
Takes settings, alerts, and files from a profile, and applies them to a printer.
Top
Examples
Desktop
using System;
using System.IO;
using Zebra.Sdk.Comm;
using Zebra.Sdk.Device;
using Zebra.Sdk.Printer;

public class ProfileUtilExample {

    private enum ProfileOperations {
        CREATE_PROFILE, RESTORE_BACKUP, CLONE_A_PRINTER
    };

    public static void Main(string[] args) {
        string pathToProfile = "C:\\MyNewProfile.zprofile";
        ProfileOperations whatToDo = ProfileOperations.CREATE_PROFILE; // Change this to load the profile.
        TcpConnection connection = new TcpConnection("192.168.1.32", TcpConnection.DEFAULT_ZPL_TCP_PORT);
        try {
            connection.Open();

            ZebraPrinter genericPrinter = ZebraPrinterFactory.GetInstance(connection);
            ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter);

            if (linkOsPrinter != null) {
                Console.WriteLine("Start profile operation");
                switch (whatToDo) {
                    case ProfileOperations.CREATE_PROFILE:
                        linkOsPrinter.CreateProfile(pathToProfile);
                        break;

                    case ProfileOperations.RESTORE_BACKUP:
                        linkOsPrinter.LoadBackup(pathToProfile);
                        break;

                    case ProfileOperations.CLONE_A_PRINTER:
                        linkOsPrinter.LoadProfile(pathToProfile);
                        break;
                }
            }
        } catch (ConnectionException e) {
            Console.WriteLine("Could not use connection");
            Console.WriteLine(e.ToString());
        } catch (ZebraPrinterLanguageUnknownException e) {
            Console.WriteLine("Could not recognize Zebra printer");
            Console.WriteLine(e.ToString());
        } catch (ZebraIllegalArgumentException e) {
            Console.WriteLine("Unexpected response from Zebra printer");
            Console.WriteLine(e.ToString());
        } catch (IOException e) {
            Console.WriteLine("Could not write to " + pathToProfile);
            Console.WriteLine(e.ToString());
        } finally {
            connection.Close();
        }
    }
}
Examples
Android™
using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using System;
using System.IO;
using System.Threading.Tasks;
using Zebra.Sdk.Comm;
using Zebra.Sdk.Device;
using Zebra.Sdk.Printer;

public class ProfileUtilExample : Activity {

    public enum ProfileOperations {
        CREATE_PROFILE, RESTORE_BACKUP, CLONE_A_PRINTER
    };

    protected override void OnCreate(Bundle savedInstanceState) {
        base.OnCreate(savedInstanceState);

        LinearLayout layout = (LinearLayout)View.Inflate(this, Android.Resource.Layout.ActivityListItem, null);
        layout.Orientation = Orientation.Vertical;

        Button testButton = new Button(this) {
            Text = "Run Profile Util Example",
            LayoutParameters = new ViewGroup.LayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent))
        };
        layout.AddView(testButton);

        SetContentView(layout);

        testButton.Click += async (sender, e) => {
            await Task.Run(() => {
                string ipAddress = "1.2.3.4";
                string pathToProfile = "/path/to/MyNewProfile.zprofile";

                ProfileOperations profileOperation = ProfileOperations.CREATE_PROFILE; // Change this to load the profile.
                ProfileUtil(ipAddress, pathToProfile, profileOperation);
            });
        };
    }

    public void ProfileUtil(string ipAddress, string pathToProfile, ProfileOperations profileOperation) {
        TcpConnection connection = new TcpConnection(ipAddress, TcpConnection.DEFAULT_ZPL_TCP_PORT);
        try {
            connection.Open();

            ZebraPrinter genericPrinter = ZebraPrinterFactory.GetInstance(connection);
            ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter);

            if (linkOsPrinter != null) {
                Console.WriteLine("Start profile operation");
                switch (profileOperation) {
                    case ProfileOperations.CREATE_PROFILE:
                        linkOsPrinter.CreateProfile(pathToProfile);
                        break;

                    case ProfileOperations.RESTORE_BACKUP:
                        linkOsPrinter.LoadBackup(pathToProfile);
                        break;

                    case ProfileOperations.CLONE_A_PRINTER:
                        linkOsPrinter.LoadProfile(pathToProfile);
                        break;
                }
            }
        } catch (ConnectionException e) {
            Console.WriteLine("Could not use connection");
            Console.WriteLine(e.ToString());
        } catch (ZebraPrinterLanguageUnknownException e) {
            Console.WriteLine("Could not recognize Zebra printer");
            Console.WriteLine(e.ToString());
        } catch (ZebraIllegalArgumentException e) {
            Console.WriteLine("Unexpected response from Zebra printer");
            Console.WriteLine(e.ToString());
        } catch (IOException e) {
            Console.WriteLine("Could not write to " + pathToProfile);
            Console.WriteLine(e.ToString());
        } finally {
            connection.Close();
        }
    }
}
Examples
iOS
using CoreGraphics;
using System;
using System.IO;
using System.Threading.Tasks;
using UIKit;
using Zebra.Sdk.Comm;
using Zebra.Sdk.Device;
using Zebra.Sdk.Printer;

public class ProfileUtilExample : UIViewController {

    public enum ProfileOperations {
        CREATE_PROFILE, RESTORE_BACKUP, CLONE_A_PRINTER
    };

    public ProfileUtilExample(IntPtr handle) : base(handle) {
        UIButton testButton = new UIButton(UIButtonType.System) {
            Frame = new CGRect(25, 25, 300, 150)
        };

        testButton.SetTitle("Run Profile Util Example", UIControlState.Normal);

        testButton.TouchUpInside += async (sender, e) => {
            await Task.Run(() => {
                string ipAddress = "1.2.3.4";
                string pathToProfile = "/path/to/MyNewProfile.zprofile";

                ProfileOperations profileOperation = ProfileOperations.CREATE_PROFILE; // Change this to load the profile.
                ProfileUtil(ipAddress, pathToProfile, profileOperation);
            });
        };

        View.AddSubview(testButton);
    }

    public void ProfileUtil(string ipAddress, string pathToProfile, ProfileOperations profileOperation) {
        TcpConnection connection = new TcpConnection(ipAddress, TcpConnection.DEFAULT_ZPL_TCP_PORT);
        try {
            connection.Open();

            ZebraPrinter genericPrinter = ZebraPrinterFactory.GetInstance(connection);
            ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter);

            if (linkOsPrinter != null) {
                Console.WriteLine("Start profile operation");
                switch (profileOperation) {
                    case ProfileOperations.CREATE_PROFILE:
                        linkOsPrinter.CreateProfile(pathToProfile);
                        break;

                    case ProfileOperations.RESTORE_BACKUP:
                        linkOsPrinter.LoadBackup(pathToProfile);
                        break;

                    case ProfileOperations.CLONE_A_PRINTER:
                        linkOsPrinter.LoadProfile(pathToProfile);
                        break;
                }
            }
        } catch (ConnectionException e) {
            Console.WriteLine("Could not use connection");
            Console.WriteLine(e.ToString());
        } catch (ZebraPrinterLanguageUnknownException e) {
            Console.WriteLine("Could not recognize Zebra printer");
            Console.WriteLine(e.ToString());
        } catch (ZebraIllegalArgumentException e) {
            Console.WriteLine("Unexpected response from Zebra printer");
            Console.WriteLine(e.ToString());
        } catch (IOException e) {
            Console.WriteLine("Could not write to " + pathToProfile);
            Console.WriteLine(e.ToString());
        } finally {
            connection.Close();
        }
    }
}
See Also