Exemplo n.º 1
0
 public void DidDetectTags(NFCNdefReaderSession session, INFCNdefTag[] tags)
 {
     try
     {
         string user_id_tag = AppDelegate.user_id_tag;
         if (user_id_tag == "?")
         {
             Task task = App.DisplayAlertAsync("¡Primero escanea este Tag para escribirlo!");
             session.InvalidateSession();
             session.Dispose();
             AppDelegate.user_id_tag = "?";
         }
         else
         {
             if ((Convert.ToInt32(user_id_tag) == Convert.ToInt32(MainViewModel.GetInstance().User.UserId.ToString())) || (0 == Convert.ToInt32(user_id_tag)))
             {
                 var nFCNdefTag = tags[0];
                 session.ConnectToTag(nFCNdefTag, CompletionHandler);
                 string         dominio        = "http://boxweb.azurewebsites.net/";
                 string         user           = MainViewModel.GetInstance().User.UserId.ToString();
                 string         tag_id         = "";
                 string         url            = dominio + "index3.aspx?user_id=" + user + "&tag_id=" + tag_id;
                 NFCNdefPayload payload        = NFCNdefPayload.CreateWellKnownTypePayload(url);
                 NFCNdefMessage nFCNdefMessage = new NFCNdefMessage(new NFCNdefPayload[] { payload });
                 nFCNdefTag.WriteNdef(nFCNdefMessage, delegate
                 {
                     Console.WriteLine("ok");
                 });
                 //Task task = App.DisplayAlertAsync(user_id_tag);
             }
             else
             {
                 Task task2 = App.DisplayAlertAsync("¡Este Tag esta vinculado con otro usuario!");
                 session.Dispose();
                 session.InvalidateSession();
                 AppDelegate.user_id_tag = "?";
             }
             AppDelegate.user_id_tag = "?";
             PopupNavigation.Instance.PopAsync();
             session.InvalidateSession();
             _tagSession.InvalidateSession();
             Thread.Sleep(4000);
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex);
         modo_escritura = false;
     }
 }
Exemplo n.º 2
0
        public override void DidDetectTags(NFCNdefReaderSession session, INFCNdefTag[] tags)
        {
            try
            {
                var nFCNdefTag = tags[0];
                session.ConnectToTag(nFCNdefTag, CompletionHandler);
                string         dominio        = "http://boxweb.azurewebsites.net/";
                string         user           = MainViewModel.GetInstance().User.UserId.ToString();
                string         tag_id         = "";
                string         url            = dominio + "index3.aspx?user_id=" + user + "&tag_id=" + tag_id;
                NFCNdefPayload payload        = NFCNdefPayload.CreateWellKnownTypePayload(url);
                NFCNdefMessage nFCNdefMessage = new NFCNdefMessage(new NFCNdefPayload[] { payload });
                nFCNdefTag.WriteNdef(nFCNdefMessage, delegate
                {
                    session.InvalidateSession();
                });
                //Task task = App.DisplayAlertAsync(user_id_tag);

                //AppDelegate.user_id_tag = "?";
                //PopupNavigation.Instance.PopAsync();


                //session.InvalidateSession();
                //session.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                session.Dispose();
                session.InvalidateSession();
            }

            MainViewModel.GetInstance().Home = new HomeViewModel();
            Xamarin.Forms.Application.Current.MainPage = new MasterPage();
        }
Exemplo n.º 3
0
        public override void DidDetect(NFCNdefReaderSession session, NFCNdefMessage[] messages)
        {
            int user_id = 0;

            try
            {
                if (messages != null && messages.Length > 0)
                {
                    var      first         = messages[0];
                    string   messa         = GetRecords(first.Records);
                    string[] variables     = messa.Split('=');
                    string[] depura_userid = variables[1].Split('&');
                    string   tag_id        = variables[2];
                    user_id = Convert.ToInt32(depura_userid[0]);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            AppDelegate.user_id_tag = user_id.ToString();
            session.InvalidateSession();
            session.Dispose();
            Thread.Sleep(4000);
            write_tag myobject = new write_tag();

            myobject.ScanWriteAsync();
        }
Exemplo n.º 4
0
 private void ListenYubiKey(bool listen)
 {
     if (_deviceActionService.SupportsNfc())
     {
         _nfcSession?.InvalidateSession();
         _nfcSession?.Dispose();
         _nfcSession = null;
         if (listen)
         {
             _nfcSession = new NFCNdefReaderSession(_nfcDelegate, null, true)
             {
                 AlertMessage = AppResources.HoldYubikeyNearTop
             };
             _nfcSession.BeginSession();
         }
     }
 }
Exemplo n.º 5
0
 public static void ListenYubiKey(bool listen, IDeviceActionService deviceActionService,
                                  NFCNdefReaderSession nfcSession, NFCReaderDelegate nfcDelegate)
 {
     if (deviceActionService.SupportsNfc())
     {
         nfcSession?.InvalidateSession();
         nfcSession?.Dispose();
         nfcSession = null;
         if (listen)
         {
             nfcSession = new NFCNdefReaderSession(nfcDelegate, null, true)
             {
                 AlertMessage = AppResources.HoldYubikeyNearTop
             };
             nfcSession.BeginSession();
         }
     }
 }
Exemplo n.º 6
0
        public override void DidInvalidate(NFCNdefReaderSession session, NSError error)
        {
            var readerError = (NFCReaderError)(long)error.Code;

            if (readerError != NFCReaderError.ReaderSessionInvalidationErrorFirstNDEFTagRead &&
                readerError != NFCReaderError.ReaderSessionInvalidationErrorUserCanceled)
            {
                InvokeOnMainThread(() =>
                {
                    var alertController = UIAlertController.Create("Session Invalidated", error.LocalizedDescription, UIAlertControllerStyle.Alert);
                    alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                    //DispatchQueue.MainQueue.DispatchAsync(() =>
                    //{
                    //    this.PresentViewController(alertController, true, null);
                    //});
                });
            }
            session.InvalidateSession();
            session.Dispose();
        }
Exemplo n.º 7
0
        public void DidDetect(NFCNdefReaderSession session, NFCNdefMessage[] messages)
        {
            int user_id = 0;

            try
            {
                if (messages != null && messages.Length > 0)
                {
                    var      first         = messages[0];
                    string   messa         = GetRecords(first.Records);
                    string[] variables     = messa.Split('=');
                    string[] depura_userid = variables[1].Split('&');
                    string   tag_id        = variables[2];
                    user_id = Convert.ToInt32(depura_userid[0]);
                    var A = MainViewModel.GetInstance().Imprime_box;
                    A = new Imprime_box();
                    if (write_tag.modo_escritura == false)
                    {
                        A.Consulta_user(user_id.ToString(), tag_id);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                user_id = 0;
            }

            user_id_tag = user_id.ToString();
            if (write_tag.modo_escritura == true)
            {
                session.InvalidateSession();
                session.Dispose();
                Thread.Sleep(7000);
                write_tag.modo_escritura = false;
                write_tag myobject = new write_tag();
                myobject.ScanWriteAsync();
            }
            session.InvalidateSession();
            Session.InvalidateSession();
        }
Exemplo n.º 8
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Forms.Init();

            if (!Resolver.IsSet)
            {
                SetIoc();
            }

            _lockService       = Resolver.Resolve <ILockService>();
            _deviceInfoService = Resolver.Resolve <IDeviceInfoService>();
            _pushHandler       = new iOSPushNotificationHandler(Resolver.Resolve <IPushNotificationListener>());
            _nfcDelegate       = new NFCReaderDelegate((success, message) => ProcessYubikey(success, message));
            var appIdService = Resolver.Resolve <IAppIdService>();

            var crashManagerDelegate = new HockeyAppCrashManagerDelegate(
                appIdService, Resolver.Resolve <IAuthService>());
            var manager = BITHockeyManager.SharedHockeyManager;

            manager.Configure("51f96ae568ba45f699a18ad9f63046c3", crashManagerDelegate);
            manager.CrashManager.CrashManagerStatus = BITCrashManagerStatus.AutoSend;
            manager.UserId = appIdService.AppId;
            manager.StartManager();
            manager.Authenticator.AuthenticateInstallation();
            manager.DisableMetricsManager = manager.DisableFeedbackManager = manager.DisableUpdateManager = true;

            LoadApplication(new App.App(
                                null,
                                Resolver.Resolve <IAuthService>(),
                                Resolver.Resolve <IConnectivity>(),
                                Resolver.Resolve <IDatabaseService>(),
                                Resolver.Resolve <ISyncService>(),
                                Resolver.Resolve <ISettings>(),
                                _lockService,
                                Resolver.Resolve <ILocalizeService>(),
                                Resolver.Resolve <IAppInfoService>(),
                                Resolver.Resolve <IAppSettingsService>(),
                                Resolver.Resolve <IDeviceActionService>()));

            // Appearance stuff

            var primaryColor = new UIColor(red: 0.24f, green: 0.55f, blue: 0.74f, alpha: 1.0f);
            var grayLight    = new UIColor(red: 0.47f, green: 0.47f, blue: 0.47f, alpha: 1.0f);

            UINavigationBar.Appearance.ShadowImage = new UIImage();
            UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
            UIBarButtonItem.AppearanceWhenContainedIn(new Type[] { typeof(UISearchBar) }).TintColor = primaryColor;
            UIButton.AppearanceWhenContainedIn(new Type[] { typeof(UISearchBar) }).SetTitleColor(primaryColor,
                                                                                                 UIControlState.Normal);
            UIButton.AppearanceWhenContainedIn(new Type[] { typeof(UISearchBar) }).TintColor = primaryColor;
            UIStepper.Appearance.TintColor = grayLight;
            UISlider.Appearance.TintColor  = primaryColor;

            MessagingCenter.Subscribe <Xamarin.Forms.Application, ToolsExtensionPage>(
                Xamarin.Forms.Application.Current, "ShowAppExtension", (sender, page) =>
            {
                var itemProvider           = new NSItemProvider(new NSDictionary(), Core.Constants.UTTypeAppExtensionSetup);
                var extensionItem          = new NSExtensionItem();
                extensionItem.Attachments  = new NSItemProvider[] { itemProvider };
                var activityViewController = new UIActivityViewController(new NSExtensionItem[] { extensionItem }, null);
                activityViewController.CompletionHandler = (activityType, completed) =>
                {
                    page.EnabledExtension(completed && activityType == "com.8bit.bitwarden.find-login-action-extension");
                };

                var modal = UIApplication.SharedApplication.KeyWindow.RootViewController.ModalViewController;
                if (activityViewController.PopoverPresentationController != null)
                {
                    activityViewController.PopoverPresentationController.SourceView = modal.View;
                    var frame     = UIScreen.MainScreen.Bounds;
                    frame.Height /= 2;
                    activityViewController.PopoverPresentationController.SourceRect = frame;
                }

                modal.PresentViewController(activityViewController, true, null);
            });

            MessagingCenter.Subscribe <Xamarin.Forms.Application, bool>(Xamarin.Forms.Application.Current,
                                                                        "ListenYubiKeyOTP", (sender, listen) =>
            {
                if (_deviceInfoService.NfcEnabled)
                {
                    _nfcSession?.InvalidateSession();
                    _nfcSession?.Dispose();
                    _nfcSession = null;
                    if (listen)
                    {
                        _nfcSession = new NFCNdefReaderSession(_nfcDelegate, null, true);
                        _nfcSession.AlertMessage = AppResources.HoldYubikeyNearTop;
                        _nfcSession.BeginSession();
                    }
                }
            });

            UIApplication.SharedApplication.StatusBarHidden = false;
            UIApplication.SharedApplication.StatusBarStyle  = UIStatusBarStyle.LightContent;

            MessagingCenter.Subscribe <Xamarin.Forms.Application, bool>(Xamarin.Forms.Application.Current,
                                                                        "ShowStatusBar", (sender, show) =>
            {
                UIApplication.SharedApplication.SetStatusBarHidden(!show, false);
            });

            ZXing.Net.Mobile.Forms.iOS.Platform.Init();
            return(base.FinishedLaunching(app, options));
        }
Exemplo n.º 9
0
 public override void DidInvalidate(NFCNdefReaderSession session, NSError error)
 {
     //add code here
     session.InvalidateSession();
     session.Dispose();
 }
Exemplo n.º 10
0
 public override void DidInvalidate(NFCNdefReaderSession session, NSError error)
 {
     session.InvalidateSession();
     session.Dispose();
     _tagSession.InvalidateSession();
 }