Beispiel #1
0
        public ConfAttendee CheckBarcode(ConfScan scan)
        {
            var attendee = Find<ConfAttendee> (a => a.Barcode == scan.Barcode);
            //var attendees = Query<ConfAttendee> ("SELECT * FROM ConfAttendee WHERE Barcode = ?", scan.Barcode);

            if (attendee != null)
                scan.AttendeeName = attendee.Name;
            return attendee; // could be null
        }
Beispiel #2
0
        public override void LoadView()
        {
            base.LoadView();

            if (!SetupCaptureSession())
            {
                throw new NotSupportedException("Unable to setup camera for QR scan");
            }

            previewLayer.Frame = new System.Drawing.RectangleF(0, 40, 320, 320);              //HACK: UIScreen.MainScreen.Bounds;
            View.Layer.AddSublayer(previewLayer);

            qrResult = new UILabel(new RectangleF(0, 380, 320, 30));
            View.AddSubview(qrResult);

            QrScan += (result) => {
                Console.WriteLine("Scan : " + result.BarcodeFormat + " " + result.Text);
                InvokeOnMainThread(() => {
                    //new UIAlertView ("Scan", result.Text, null, "OK").Show ()
                    qrResult.Text += result.Text + "\n";

                    var scan = new ConfScan()
                    {
                        Barcode = result.Text, ScannedAt = DateTime.Now
                    };
                    AppDelegate.UserData.AddScan(scan);

                    scanTable.InsertAsync(scan)
                    .ContinueWith(t => {
                        Console.WriteLine(t.Status);
                        Console.WriteLine("Updated scan in cloud " + t);
                    }, scheduler);

                    session.StopRunning();
                });
            };

            startButton       = UIButton.FromType(UIButtonType.RoundedRect);
            startButton.Frame = new RectangleF(0, 0, 50, 30);
            startButton.SetTitle("Scan", UIControlState.Normal);
            startButton.TouchUpInside += (sender, e) => {
                session.StartRunning();
            };
            View.AddSubview(startButton);
        }
        public override void LoadView()
        {
            base.LoadView ();

            if (!SetupCaptureSession ())
                throw new NotSupportedException ("Unable to setup camera for QR scan");

            previewLayer.Frame = new System.Drawing.RectangleF (0, 40, 320, 320); //HACK: UIScreen.MainScreen.Bounds;
            View.Layer.AddSublayer (previewLayer);

            qrResult = new UILabel(new RectangleF (0, 380, 320, 30));
            View.AddSubview (qrResult);

            QrScan += (result) => {
                Console.WriteLine ("Scan : " + result.BarcodeFormat + " " + result.Text );
                InvokeOnMainThread (() => {
                    //new UIAlertView ("Scan", result.Text, null, "OK").Show ()
                    qrResult.Text += result.Text + "\n";

                    var scan = new ConfScan () {Barcode=result.Text, ScannedAt=DateTime.Now};
                    AppDelegate.UserData.AddScan (scan);

                    scanTable.InsertAsync (scan)
                        .ContinueWith (t => {
                            Console.WriteLine (t.Status);
                            Console.WriteLine ("Updated scan in cloud " + t);

                        }, scheduler);

                    session.StopRunning ();
                });
            };

            startButton = UIButton.FromType (UIButtonType.RoundedRect);
            startButton.Frame = new RectangleF(0,0,50,30);
            startButton.SetTitle ("Scan", UIControlState.Normal);
            startButton.TouchUpInside += (sender, e) => {
                session.StartRunning ();
            };
            View.AddSubview(startButton);
        }
 public void AddScan(ConfScan scan)
 {
     Insert(scan);
 }
        public override void LoadView()
        {
            base.LoadView ();

            if (!SetupCaptureSession ()) {
                Console.WriteLine ("Scan function requires a camera - doesn't work in the iOS Simulator");
                throw new NotSupportedException ("Unable to setup camera for QR scan");
            }
            scanButton = UIButton.FromType (UIButtonType.System);
            scanButton.BackgroundColor = UIColor.White;
            scanButton.Frame = new RectangleF(50,60,220,80);
            scanButton.SetTitle ("Scan Again", UIControlState.Normal);
            scanButton.TouchUpInside += (sender, e) => {
                View.BackgroundColor = UIColor.Black;
                session.StartRunning ();
                qrResult1.Text = "";
                qrResult2.Text = "";
                scanButton.RemoveFromSuperview ();
            };

            qrResult1 = new UILabel(new RectangleF (10, 300, 300, 40));
            qrResult1.TextColor = UIColor.White;
            qrResult1.BackgroundColor = UIColor.Clear;
            qrResult1.Font = UIFont.BoldSystemFontOfSize (32f);
            qrResult1.AdjustsFontSizeToFitWidth = true;

            qrResult2 = new UILabel(new RectangleF (10, 350, 300, 30));
            qrResult2.TextColor = UIColor.White;
            qrResult2.BackgroundColor = UIColor.Clear;
            qrResult2.Font = UIFont.BoldSystemFontOfSize (18f);

            QrScan += (result) => {
                //Console.WriteLine ("Scan : " + result.BarcodeFormat + " " + result.Text );
                InvokeOnMainThread (async () => {

                    session.StopRunning();

                    qrResult2.Text = result; //.Text;

                    var scan = new ConfScan () { Barcode=result, ScannedAt=DateTime.Now };

                    bool valid = false, reentry = false;

                    // LOCAL DATA OPERATIONS
                    // check for attendee
                    var validAttendee = AppDelegate.UserData.CheckBarcode (scan);

                    if (validAttendee != null) {
                        valid = true;
                        scan.IsValid = true;
                        qrResult1.Text = validAttendee.Name;
                        if (validAttendee.ScanCount > 0) {
                            reentry = true;
                            validAttendee.ScanCount += 1;
                            qrResult2.Text += " (re-entry)";
                            AppDelegate.UserData.Update (validAttendee);
                        } else {
                            // first entry
                            validAttendee.ScanCount = 1;
                            AppDelegate.UserData.Update (validAttendee);
                        }
                    } else {
                        qrResult1.Text = "BARCODE NOT FOUND";
                        scan.AttendeeName = "NOT FOUND";
                        scan.IsValid = false;
                    }
                    // Adds to local database
                    AppDelegate.UserData.AddScan (scan);

                    //HACK: commented out Azure for now ~ no account
                    // and still need to test the new async-style calls
            //					try {
            //						// REMOTE DATA OPERATIONS
            //						// Massive hack here, need to revisit how we deal with these Azure updates
            //						await AzureManager.scanTable.InsertAsync (scan);
            //						Console.WriteLine ("Updated scan in cloud, Id:" + scan.Id);
            //
            //						// we need to find out of the Attendee.Barcode is already in Azure...
            //						if (validAttendee != null) {
            //							if (validAttendee.Id > 0) {
            //								await AzureManager.attendeeTable.UpdateAsync (validAttendee);
            //								Console.WriteLine ("Updated attendee in cloud, Id:" + validAttendee.Id);
            //							} else {
            //								await AzureManager.attendeeTable.InsertAsync (validAttendee);
            //								Console.WriteLine ("Inserted attendee in cloud, Id:" + validAttendee.Id);
            //								AppDelegate.UserData.Update (validAttendee); // with Azure~Id
            //								Console.WriteLine ("Inserted attendee in local, Id:" + validAttendee.Id);
            //							}
            //						}
            //					} catch (AggregateException ae) {
            //						Console.WriteLine ("AZURE error " + ae);
            //					} catch (Exception e) {
            //						Console.WriteLine ("AZURE error " + e);
            //					}

                    if (valid && !reentry) {
                        View.BackgroundColor = UIColor.Green;
                        Speak ("Please enter");
                    } else if (valid && reentry) {
                        View.BackgroundColor = UIColor.Orange;
                        Speak ("Welcome back");
                    } else {
                        View.BackgroundColor = UIColor.Red;
                        Speak ("Denied!");
                    }
                    View.AddSubview (scanButton);
                });
            };

            //View.AddSubview (scanButton); // gets added/removed dynamically
            View.AddSubview (qrResult1);
            View.AddSubview (qrResult2);
        }
        public override void LoadView()
        {
            base.LoadView();

            if (!SetupCaptureSession())
            {
                Console.WriteLine("Scan function requires a camera - doesn't work in the iOS Simulator");
                throw new NotSupportedException("Unable to setup camera for QR scan");
            }
            scanButton = UIButton.FromType(UIButtonType.System);
            scanButton.BackgroundColor = UIColor.White;
            scanButton.Frame           = new RectangleF(50, 60, 220, 80);
            scanButton.SetTitle("Scan Again", UIControlState.Normal);
            scanButton.TouchUpInside += (sender, e) => {
                View.BackgroundColor = UIColor.Black;
                session.StartRunning();
                qrResult1.Text = "";
                qrResult2.Text = "";
                scanButton.RemoveFromSuperview();
            };

            qrResult1                           = new UILabel(new RectangleF(10, 300, 300, 40));
            qrResult1.TextColor                 = UIColor.White;
            qrResult1.BackgroundColor           = UIColor.Clear;
            qrResult1.Font                      = UIFont.BoldSystemFontOfSize(32f);
            qrResult1.AdjustsFontSizeToFitWidth = true;

            qrResult2                 = new UILabel(new RectangleF(10, 350, 300, 30));
            qrResult2.TextColor       = UIColor.White;
            qrResult2.BackgroundColor = UIColor.Clear;
            qrResult2.Font            = UIFont.BoldSystemFontOfSize(18f);

            QrScan += (result) => {
                //Console.WriteLine ("Scan : " + result.BarcodeFormat + " " + result.Text );
                InvokeOnMainThread(async() => {
                    session.StopRunning();

                    qrResult2.Text = result;                     //.Text;

                    var scan = new ConfScan()
                    {
                        Barcode = result, ScannedAt = DateTime.Now
                    };

                    bool valid = false, reentry = false;

                    // LOCAL DATA OPERATIONS
                    // check for attendee
                    var validAttendee = AppDelegate.UserData.CheckBarcode(scan);

                    if (validAttendee != null)
                    {
                        valid          = true;
                        scan.IsValid   = true;
                        qrResult1.Text = validAttendee.Name;
                        if (validAttendee.ScanCount > 0)
                        {
                            reentry = true;
                            validAttendee.ScanCount += 1;
                            qrResult2.Text          += " (re-entry)";
                            AppDelegate.UserData.Update(validAttendee);
                        }
                        else
                        {
                            // first entry
                            validAttendee.ScanCount = 1;
                            AppDelegate.UserData.Update(validAttendee);
                        }
                    }
                    else
                    {
                        qrResult1.Text    = "BARCODE NOT FOUND";
                        scan.AttendeeName = "NOT FOUND";
                        scan.IsValid      = false;
                    }
                    // Adds to local database
                    AppDelegate.UserData.AddScan(scan);


                    //HACK: commented out Azure for now ~ no account
                    // and still need to test the new async-style calls
//					try {
//						// REMOTE DATA OPERATIONS
//						// Massive hack here, need to revisit how we deal with these Azure updates
//						await AzureManager.scanTable.InsertAsync (scan);
//						Console.WriteLine ("Updated scan in cloud, Id:" + scan.Id);
//
//						// we need to find out of the Attendee.Barcode is already in Azure...
//						if (validAttendee != null) {
//							if (validAttendee.Id > 0) {
//								await AzureManager.attendeeTable.UpdateAsync (validAttendee);
//								Console.WriteLine ("Updated attendee in cloud, Id:" + validAttendee.Id);
//							} else {
//								await AzureManager.attendeeTable.InsertAsync (validAttendee);
//								Console.WriteLine ("Inserted attendee in cloud, Id:" + validAttendee.Id);
//								AppDelegate.UserData.Update (validAttendee); // with Azure~Id
//								Console.WriteLine ("Inserted attendee in local, Id:" + validAttendee.Id);
//							}
//						}
//					} catch (AggregateException ae) {
//						Console.WriteLine ("AZURE error " + ae);
//					} catch (Exception e) {
//						Console.WriteLine ("AZURE error " + e);
//					}

                    if (valid && !reentry)
                    {
                        View.BackgroundColor = UIColor.Green;
                        Speak("Please enter");
                    }
                    else if (valid && reentry)
                    {
                        View.BackgroundColor = UIColor.Orange;
                        Speak("Welcome back");
                    }
                    else
                    {
                        View.BackgroundColor = UIColor.Red;
                        Speak("Denied!");
                    }
                    View.AddSubview(scanButton);
                });
            };

            //View.AddSubview (scanButton); // gets added/removed dynamically
            View.AddSubview(qrResult1);
            View.AddSubview(qrResult2);
        }
Beispiel #7
0
 public ScanElement(ConfScan sc) : base(sc.Barcode)
 {
     scan = sc;
 }
        public override void LoadView()
        {
            base.LoadView ();

            if (!SetupCaptureSession ())
                throw new NotSupportedException ("Unable to setup camera for QR scan");

            scanButton = UIButton.FromType (UIButtonType.RoundedRect);
            scanButton.Frame = new RectangleF(50,60,220,80);
            scanButton.SetTitle ("Scan Again", UIControlState.Normal);
            scanButton.TouchUpInside += (sender, e) => {
                View.BackgroundColor = UIColor.Black;
                session.StartRunning ();
                qrResult1.Text = "";
                qrResult2.Text = "";
                scanButton.RemoveFromSuperview ();
            };

            qrResult1 = new UILabel(new RectangleF (10, 300, 300, 40));
            qrResult1.TextColor = UIColor.White;
            qrResult1.BackgroundColor = UIColor.Clear;
            qrResult1.Font = UIFont.BoldSystemFontOfSize (32f);
            qrResult1.AdjustsFontSizeToFitWidth = true;

            qrResult2 = new UILabel(new RectangleF (10, 350, 300, 30));
            qrResult2.TextColor = UIColor.White;
            qrResult2.BackgroundColor = UIColor.Clear;
            qrResult2.Font = UIFont.BoldSystemFontOfSize (18f);

            previewLayer.Frame = new System.Drawing.RectangleF (0, 0, 320, 290);
            View.Layer.AddSublayer (previewLayer);

            QrScan += (result) => {
                Console.WriteLine ("Scan : " + result.BarcodeFormat + " " + result.Text );
                InvokeOnMainThread (() => {
                    qrResult2.Text = result.Text;

                    var scan = new ConfScan () { Barcode=result.Text, ScannedAt=DateTime.Now };

                    bool valid = false, reentry = false;

                    // LOCAL DATA OPERATIONS
                    // check for attendee
                    var validAttendee = AppDelegate.UserData.CheckBarcode (scan);

                    if (validAttendee != null) {
                        valid = true;
                        scan.IsValid = true;
                        qrResult1.Text = validAttendee.Name;
                        if (validAttendee.ScanCount > 0) {
                            reentry = true;
                            validAttendee.ScanCount += 1;
                            qrResult2.Text += " (re-entry)";
                            AppDelegate.UserData.Update (validAttendee);
                        } else {
                            // first entry
                            validAttendee.ScanCount = 1;
                            AppDelegate.UserData.Update (validAttendee);
                        }
                    } else {
                        qrResult1.Text = "BARCODE NOT FOUND";
                        scan.AttendeeName = "NOT FOUND";
                        scan.IsValid = false;
                    }
                    AppDelegate.UserData.AddScan (scan);

                    // REMOTE DATA OPERATIONS
                    // Massive hack here, need to revisit how we deal with PKs in Azure
                    AzureManager.scanTable.InsertAsync (scan)
                        .ContinueWith (t => {
                            Console.WriteLine ("Updated scan in cloud " + t.Status + " " + t.Id);
                        }, scheduler);
                    // we need to find out of the Attendee.Barcode is already in Azure...
                    if (validAttendee != null) {
                        if (validAttendee.Id > 0)
                            AzureManager.attendeeTable.UpdateAsync (validAttendee)
                                .ContinueWith (u => {
                                    Console.WriteLine ("Updated attendee in cloud " + u.Status + " update " + u.Id);
                                }, scheduler);
                        else {
                            AzureManager.attendeeTable.InsertAsync (validAttendee)
                                .ContinueWith (v => {
                                    Console.WriteLine ("Inserted attendee in cloud " + v.Status + " " + v.Id + " ~ " + validAttendee.Id);
                                    AppDelegate.UserData.Update (validAttendee); // with Azure~Id
                                }, scheduler);
                        }
                    }

                    if (valid && !reentry)
                        View.BackgroundColor = UIColor.Green;
                    else if (valid && reentry)
                        View.BackgroundColor = UIColor.Orange;
                    else
                        View.BackgroundColor = UIColor.Red;

                    session.StopRunning ();
                    View.AddSubview (scanButton);
                });
            };

            //View.AddSubview (scanButton); // gets added/removed dynamically
            View.AddSubview (qrResult1);
            View.AddSubview (qrResult2);
        }