Ejemplo n.º 1
0
        /// <summary>
        /// Gets an array of cards pending to be printed.
        /// </summary>
        /// <param name="printerId"></param>
        /// <returns></returns>
        public MabelResponse GetPendingPrints(int printerId)
        {
            MabelResponse response = MakeRequest(new MabelRequest(this, "cardHandler.getPendingPrints", new
                                                                  MabelGetPendingPrints(printerId)));

            return(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the token on the last card that a printer requested.
        /// </summary>
        /// <param name="token"></param>
        /// <param name="printerId"></param>
        /// <returns></returns>
        public MabelResponse SetToken(String token, int printerId)
        {
            MabelResponse response = MakeRequest(new MabelRequest(this, "cardHandler.capturedRFID",
                                                                  new MabelSetTokenParams(token, printerId)));

            return(response);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the next card enqueued to be printed
        /// </summary>
        /// <param name="printerId">The ID of the printer who is requesting the card</param>
        /// <returns></returns>
        public MabelCard GetNextJob(int printerId)
        {
            MabelRequest  request  = new MabelRequest(this, "cardHandler.getNextPrintJob", new MabelGetNextJobParams(printerId));
            MabelResponse response = MakeRequest(request);

            if (response.code == 200)
            {
                if (response.results == null)
                {
                    // The API is OK, there's just no cards to print :)
                    return(null);
                }
            }
            else
            {
                //Something has gone wrong, best ignore and hope for the best, but exit out this time around
                // throw an exception probably?
                throw new Exception("Problem with request to API: " + response.message);
            }
            // otherwise...
            MabelCard card = new MabelCard();

            card.card_id   = (int)response.results.SelectToken("cardId");
            card.member_id = response.results.SelectToken("memberId").ToString();

            card.card_front_image_encoded = (string)response.results.SelectToken("imageFront");
            card.card_back_image_encoded  = (string)response.results.SelectToken("imageBack");
            return(card);
        }
Ejemplo n.º 4
0
        private void UpdateMabelStatus()
        {
            MabelAPI      mabel_api = new MabelAPI();
            MabelResponse resp      = mabel_api.MabelSays();

            if (manager == null)
            {
                return;
            }
            if (!resp.isError)
            {
                tbMabelStatus.Text      = resp.message;
                tbMabelStatus.BackColor = Color.LightGreen;
                // get the number of pending prints
                MabelResponse pendingResp = mabel_api.GetPendingPrints(manager.GetPrinterId());
                if (!pendingResp.isError)
                {
                    tbQueueSize.Text = pendingResp.count.ToString();
                }
            }
            else
            {
                tbMabelStatus.Text      = resp.message;
                tbMabelStatus.BackColor = Color.LightPink;
            }
        }
Ejemplo n.º 5
0
        private void btnTestMabelConn_Click(object sender, EventArgs e)
        {
            MabelAPI mabel_api = new MabelAPI();

            mabel_api.setBaseUrl(tbMabelUrl.Text);
            try
            {
                MabelResponse resp = mabel_api.MabelSays();
                tbTestResponse.Text = "MABEL Response: " + resp.message;
                if (!resp.isError)
                {
                    testWorks = true;
                    tbTestResponse.BackColor = Color.LightGreen;
                    settingsErrorProvider.SetError(tbTestResponse, "");
                }
                else
                {
                    if (resp.results != null)
                    {
                        tbTestResponse.Text += resp.results;
                    }
                    testWorks = false;
                    tbTestResponse.BackColor = Color.LightPink;
                    settingsErrorProvider.SetError(tbTestResponse, "Error connecting to MABEL");
                }
            } catch (Exception ex)
            {
                testWorks                = false;
                tbTestResponse.Text      = ex.Message;
                tbTestResponse.BackColor = Color.LightPink;
                settingsErrorProvider.SetError(tbTestResponse, "Error connecting to MABEL");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Sets a card's status to printed via the API.
        /// </summary>
        /// <param name="printerId"></param>
        /// <param name="card"></param>
        /// <returns></returns>
        public MabelResponse SetCardPrinted(int printerId, MabelCard card)
        {
            MabelResponse response = MakeRequest(new MabelRequest(this, "cardHandler.setPrinted",
                                                                  new MabelSetCardPrinterParams(card.card_id)
                                                                  ));

            return(response);
        }
Ejemplo n.º 7
0
        public MabelResponse MabelSays()
        {
            MabelResponse response = MakeRequest(
                new MabelRequest(
                    this,
                    "mabelSays",
                    null));

            return(response);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Sets a card's RFID via the API (deprecated)
        /// </summary>
        /// <param name="printerId"></param>
        /// <param name="card"></param>
        /// <param name="rfid"></param>
        /// <returns></returns>
        public MabelResponse SetCardRfid(int printerId, MabelCard card, String rfid)
        {
            MabelResponse response = MakeRequest(
                new MabelRequest(
                    this,
                    "cardPrinter.setStatus",
                    new MabelSetCardRfidParams(printerId, card.card_id, rfid)
                    )
                );

            return(response);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets the status of a card via the API
        /// </summary>
        /// <param name="printerId"></param>
        /// <param name="card"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public MabelResponse SetCardStatus(int printerId, MabelCard card, string status)
        {
            MabelResponse response = MakeRequest(
                new MabelRequest(
                    this,
                    "cardHandler.setStatus",
                    new MabelSetCardStatusParams(card.card_id, status)
                    )
                );

            return(response);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Checks the version of the API (not implemented)
        /// </summary>
        /// <returns></returns>
        public MabelResponse CheckVersion()
        {
            MabelResponse response =
                MakeRequest(
                    new MabelRequest(
                        this,
                        "cardPrinter.checkVersion",
                        null)
                    );

            return(response);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Unregisters a printer
        /// </summary>
        /// <param name="printerId">The printer's ID</param>
        /// <returns></returns>
        public MabelResponse UnregisterPrinter(int printerId)
        {
            MabelResponse response = MakeRequest(
                new MabelRequest(
                    this,
                    "cardPrinter.unregister",
                    new MabelPrinterUnregisterParams(printerId)
                    )
                );

            return(response);
        }
Ejemplo n.º 12
0
        // API Functions  //

        /// <summary>
        /// Registers the printer
        /// </summary>
        /// <param name="printerId">The printer ID to register</param>
        /// <param name="printerName">The "name" of the printer (as in windows)</param>
        /// <param name="printerLocation">The location of the printer</param>
        /// <param name="printerModel">The model of the printer</param>
        /// <returns></returns>
        public MabelResponse RegisterPrinter(int printerId, string printerName, string printerLocation, PrinterInfo info)
        {
            MabelResponse response = MakeRequest(
                new MabelRequest(
                    this,
                    "cardPrinter.register",
                    new MabelPrinterRegisterParams(printerId, printerName, printerLocation, new MabelPrinterInfo(info))
                    )
                );

            return(response);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Sets the status of a printer.
        /// </summary>
        /// <param name="printerId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public MabelResponse SetPrinterStatus(int printerId, string status)
        {
            MabelResponse response =
                MakeRequest(new MabelRequest(
                                this,
                                "cardPrinter.printerSetStatus",
                                new MabelPrinterSetStatus(printerId, status)
                                )
                            );

            return(response);
        }
        public bool Unregister()
        {
            MabelResponse resp = mabel_api.UnregisterPrinter(printer_id);

            _registered = false;
            if (resp.isError)
            {
                OnUnregisterError(new PrinterEventArgs(null, "Unregister failed " + resp.message, _printerInfo));
                return(false);
            }
            else
            {
                OnUnregistered(new PrinterEventArgs(null, "Unregistered Successfully", _printerInfo));
                _state = PrinterState.UNREGISTERED;
                return(true);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Makess a request to the Mabel API, using the specified request object
        /// </summary>
        /// <param name="mabelRequest">A build MabelRequest object with the desired params for the function call.</param>
        /// <returns></returns>
        private MabelResponse MakeRequest( MabelRequest mabelRequest)
        {
            ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;
            String url = mabelRequest.buildURL();
            WebRequest request = WebRequest.Create(url);
            request.Timeout = 3000;
            //request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested;
            //request.Credentials = new NetworkCredential(Properties.Settings.Default.Username, Properties.Settings.Default.Password, Properties.Settings.Default.Domain);
            //request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
            // Get the response.
            lastRequest = mabelRequest;
            MabelResponse mabelResponse = new MabelResponse();
            HttpWebResponse response = null;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
                lastResponse = mabelResponse;
            }
            catch (Exception ex)
            {
                mabelResponse.isError = true;
                mabelResponse.message = "HTTP EXCEPTION:" + ex.Message;
                // this may be overridden later... ?
            }
            if (response != null)
            {
                Stream dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                string responseFromServer = reader.ReadToEnd();
                // Display the content.
                // Clean up the streams and the response.
                reader.Close();
                response.Close();
                mabelResponse._raw = responseFromServer;
            } else
            {
                // if there's no content, then the HTTP exception is as good as we're going to get
                OnDebug(new MabelEventArgs(url, mabelRequest, mabelResponse));
                return mabelResponse;
            }

            // Get the stream containing content returned by the server.
            JObject o;
            try {
                o = JObject.Parse(mabelResponse._raw);
            } catch (Exception ex)
            {
                mabelResponse.isError = true;
                mabelResponse.message = "JSON Exception: " + ex.Message;
                OnDebug(new MabelEventArgs(url, mabelRequest, mabelResponse));
                return mabelResponse;
            }

            try {
                mabelResponse.code = (int)o["meta"]["status"];
                mabelResponse.message = (string)o["meta"]["msg"];
                mabelResponse.count = (int)o["meta"]["count"];
            } catch (Exception ex2)
            {
                mabelResponse.isError = true;
                mabelResponse.message = "JSON Exception: meta fields: " + ex2.Message;
                OnDebug(new MabelEventArgs(url, mabelRequest, mabelResponse));
                return mabelResponse;
            }
            if (mabelResponse.code != 200)
            {
                // it's an error, return it now, don't bother looking for results
                mabelResponse.isError = true;
            }
            else
            {
                mabelResponse.isError = false;
            }
            // otherwise, hand back the results :)

            if (o["result"].Type != JTokenType.Null)
            {
                mabelResponse.results = o["result"];
            }
            else
            {
                mabelResponse.results = null;
            }

            OnDebug(new MabelEventArgs(url, mabelRequest, mabelResponse));

            return mabelResponse;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Makess a request to the Mabel API, using the specified request object
        /// </summary>
        /// <param name="mabelRequest">A build MabelRequest object with the desired params for the function call.</param>
        /// <returns></returns>
        private MabelResponse MakeRequest(MabelRequest mabelRequest)
        {
            ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;
            String     url     = mabelRequest.buildURL();
            WebRequest request = WebRequest.Create(url);

            request.Timeout = 3000;
            //request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested;
            //request.Credentials = new NetworkCredential(Properties.Settings.Default.Username, Properties.Settings.Default.Password, Properties.Settings.Default.Domain);
            //request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
            // Get the response.
            lastRequest = mabelRequest;
            MabelResponse   mabelResponse = new MabelResponse();
            HttpWebResponse response      = null;

            try
            {
                response     = (HttpWebResponse)request.GetResponse();
                lastResponse = mabelResponse;
            }
            catch (Exception ex)
            {
                mabelResponse.isError = true;
                mabelResponse.message = "HTTP EXCEPTION:" + ex.Message;
                // this may be overridden later... ?
            }
            if (response != null)
            {
                Stream dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                string responseFromServer = reader.ReadToEnd();
                // Display the content.
                // Clean up the streams and the response.
                reader.Close();
                response.Close();
                mabelResponse._raw = responseFromServer;
            }
            else
            {
                // if there's no content, then the HTTP exception is as good as we're going to get
                OnDebug(new MabelEventArgs(url, mabelRequest, mabelResponse));
                return(mabelResponse);
            }

            // Get the stream containing content returned by the server.
            JObject o;

            try {
                o = JObject.Parse(mabelResponse._raw);
            } catch (Exception ex)
            {
                mabelResponse.isError = true;
                mabelResponse.message = "JSON Exception: " + ex.Message;
                OnDebug(new MabelEventArgs(url, mabelRequest, mabelResponse));
                return(mabelResponse);
            }

            try {
                mabelResponse.code    = (int)o["meta"]["status"];
                mabelResponse.message = (string)o["meta"]["msg"];
                mabelResponse.count   = (int)o["meta"]["count"];
            } catch (Exception ex2)
            {
                mabelResponse.isError = true;
                mabelResponse.message = "JSON Exception: meta fields: " + ex2.Message;
                OnDebug(new MabelEventArgs(url, mabelRequest, mabelResponse));
                return(mabelResponse);
            }
            if (mabelResponse.code != 200)
            {
                // it's an error, return it now, don't bother looking for results
                mabelResponse.isError = true;
                OnError(new MabelEventArgs(url, mabelRequest, mabelResponse));
            }
            else
            {
                mabelResponse.isError = false;
            }
            // otherwise, hand back the results :)

            if (o["result"].Type != JTokenType.Null)
            {
                mabelResponse.results = o["result"];
            }
            else
            {
                mabelResponse.results = null;
            }

            OnDebug(new MabelEventArgs(url, mabelRequest, mabelResponse));

            return(mabelResponse);
        }
Ejemplo n.º 17
0
 public MabelEventArgs(String URL, MabelRequest request, MabelResponse response)
 {
     this.URL      = URL;
     this.request  = request;
     this.response = response;
 }
Ejemplo n.º 18
0
 public MabelEventArgs(String URL, MabelRequest request, MabelResponse response)
 {
     this.URL = URL;
     this.request = request;
     this.response = response;
 }