public Patron PrintCard(Cardstock cardstock)
        {
            var serializer = new XmlSerializer(typeof(Cardstock));

            var memoryStream = new MemoryStream();
            var streamWriter = new StreamWriter(memoryStream, System.Text.Encoding.UTF8);

            serializer.Serialize(streamWriter, cardstock);

            byte[] utf8EncodedXml = memoryStream.ToArray();
            string serializedValue = Encoding.UTF8.GetString(utf8EncodedXml);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Concat(URI.RESTurl(), "PrintCard"));
            request.Method = "POST";
            request.ContentType = "application/xml";
            request.ContentLength = utf8EncodedXml.Length;
            this.authenticationProvider.AuthenticatePostRequest(request, serializedValue);
            request.Accept = "application/xml";

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(utf8EncodedXml, 0, utf8EncodedXml.Length);
            dataStream.Close();

            HttpWebResponse response = null;

            Patron patron = null;
            try
            {
                using (response = (HttpWebResponse)request.GetResponse())
                {
                    Stream ReceiveStream = response.GetResponseStream();
                    StreamReader readStream = new StreamReader(ReceiveStream);
                    string xml = readStream.ReadToEnd();

                    if (xml.Contains("sql_exception") || xml.Contains("__exception__"))
                        throw new WebException(xml);

                    if (xml.Contains("IdCardError"))
                    {
                        IdCardError error = (IdCardError)errorSerializer.Deserialize(new StringReader(xml));
                        MessageBox.Show(error.Errors[0].Error.ToString());
                        return null;
                    }

                    patron = (Patron)patronSerializer.Deserialize(new StringReader(xml));
                }
            }

            catch (WebException webEx)
            {
                MessageBox.Show("The ID Card will not be printed!\n\n" + webEx.ToString(), "Patron Web Service ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return null;
            }
            return patron;
        }
        private void ReadCard_Button(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;

            string defaultPrinterName = "";
            short defaultCopyCount = 1;
            using (StreamReader reader = new StreamReader(File.Open(IDWorksProductionManager.APP_SPECIAL_FOLDER + "\\" + IDWorksProductionManager.PRINTER_CONFIG_FILE, FileMode.Open)))
            {
                defaultPrinterName = reader.ReadLine();
                short.TryParse(reader.ReadLine(), out defaultCopyCount);
            }

            String proxId = ApplicationPresenter.Manager.ReadSmartCard(defaultPrinterName);
            Mouse.OverrideCursor = Cursors.Arrow;
            //            MessageBox.Show(proxId,"PROX ID",MessageBoxButton.OK,MessageBoxImage.Information);
            //            if (proxId != "Error")
            {
                if (MessageBox.Show("Update ProxID?", proxId, MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    Session session = SecurityContextHolder.Credential as Session;
                    Cardstock cardstock = new Cardstock();
                    cardstock.personID = _patron.Identifiers.PersonId;
                    cardstock.updated_by_id = session.PersonId;
                    cardstock.ProxId = proxId;
                    cardstock.newCard = "N";

                    cardstock.definition = "BYU";
                    var def = TemplateCombo.SelectedItem as EligibleCard;
                    cardstock.definition = def.CardType;
                    cardstock.PrintLocation = session.Authorized.Location;

                    Patron patron = ApplicationPresenter.Manager.PrintCard(cardstock);
                    UpdatePrintedValues(patron);
                }
            }
            Keyboard.Focus(_presenter.View.searchBar.lastName);
        }
 public void ReprintCard(string personId, Cardstock cardstock)
 {
     callCounts[(int)IdCardClientOperation.REPRINT_CARD]++;
 }