public void RecognizeBarcode(Bitmap bitmap)
        {
            if (state != InnerState.BORROWING && state != InnerState.RETURNING) { throw new InvalidOperationException("The user is in an invalid state!"); }

            if (bitmap == null)
            {
                //invalid request, show in the welcome page
                View.ShowWelcomePage();
                return;
            }

            try
            {
                short port = 0;
                //show a loading message
                View.ShowLoading();
                //call the web service to send the picture
                using (IServiceClientProxy proxy = new IServiceClientProxy(binding, new ProtocolVersion11()))
                {
                    SendBarcodeImage sendImageRequest = new SendBarcodeImage();
                    SendBarcodeImageResponse response = proxy.SendBarcodeImage(sendImageRequest);
                    port = response.SendBarcodeImageResult;

                    //send the image
                    string code = SendImage(port, GHI.Utilities.Bitmaps.ConvertToFile(bitmap));
                    if (code == null)
                    {
                        //the bar code was not recognized
                        //show the camera page
                        View.ShowMessageWithButton(CODE_NOT_RECOGNIZED_MSG, () => { View.ShowCamera(); });
                        return;
                    }

                    //get book info
                    GetBookInformationsResponse bookInfoResponse = proxy.GetBookInformations(new GetBookInformations() { barcode = code });
                    if (bookInfoResponse.GetBookInformationsResult.ISBN == null)
                    {
                        //the book is not in the WS database
                        View.ShowMessageWithButton(INVALID_BARCODE_MSG, () => { View.ShowCamera(); });
                        return;
                    }

                    LibraryModelSingleton.Instance.Book = bookInfoResponse.GetBookInformationsResult;
                    if (state == InnerState.BORROWING)
                    {
                        //show the book information
                        View.ShowBooKForLoan();
                    }
                    else if (state == InnerState.RETURNING)
                    {
                        //call the ws in order to get the loan information
                        GetLoanState loanStateRequest = new GetLoanState();
                        loanStateRequest.bookID = bookInfoResponse.GetBookInformationsResult.ID;
                        loanStateRequest.userID = LibraryModelSingleton.Instance.User.ID;
                        loanStateRequest.returned = false;
                        GetLoanStateResponse loanStateResponse = proxy.GetLoanState(loanStateRequest);
                        if (loanStateResponse.GetLoanStateResult.LoanStateCompositeType.Length == 0)
                        {
                            //the book was not borrowed by the user
                            View.ShowMessageWithButton(INVALID_BARCODE_MSG, () => { View.ShowWelcomePage(); });
                        }
                        else
                        {
                            //show the book information
                            LibraryModelSingleton.Instance.StartDate = loanStateResponse.GetLoanStateResult.LoanStateCompositeType[0].LoanStartDate;
                            LibraryModelSingleton.Instance.DueDate = loanStateResponse.GetLoanStateResult.LoanStateCompositeType[0].LoanExpirationDate;
                            View.ShowBooKForReturning();
                        }
                    }
                }
            }
            catch (Exception)
            { //show a message and then returns in the login page
                state = InnerState.INITIAL;
                View.ShowMessageWithButton(ERROR_MSG, () => { this.Logout(); });
            }
        }
Example #2
0
 public override object ReadObject(XmlReader reader)
 {
     SendBarcodeImage SendBarcodeImageField = null;
     if (IsParentStartElement(reader, false, true))
     {
         SendBarcodeImageField = new SendBarcodeImage();
         reader.Read();
         reader.ReadEndElement();
     }
     return SendBarcodeImageField;
 }
        public virtual SendBarcodeImageResponse SendBarcodeImage(SendBarcodeImage req)
        {
            // Create request header
            String action;
            action = "http://tempuri.org/IService/SendBarcodeImage";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, EndpointAddress, m_version.AnonymousUri, null, null);
            WsMessage request = new WsMessage(header, req, WsPrefix.None);

            // Create request serializer
            SendBarcodeImageDataContractSerializer reqDcs;
            reqDcs = new SendBarcodeImageDataContractSerializer("SendBarcodeImage", "http://tempuri.org/");
            request.Serializer = reqDcs;
            request.Method = "SendBarcodeImage";

            // Send service request
            m_requestChannel.Open();
            WsMessage response = m_requestChannel.Request(request);
            m_requestChannel.Close();

            // Process response
            SendBarcodeImageResponseDataContractSerializer respDcs;
            respDcs = new SendBarcodeImageResponseDataContractSerializer("SendBarcodeImageResponse", "http://tempuri.org/");
            SendBarcodeImageResponse resp;
            resp = ((SendBarcodeImageResponse)(respDcs.ReadObject(response.Reader)));
            response.Reader.Dispose();
            response.Reader = null;
            return resp;
        }