Exemplo n.º 1
0
 public CharacteristicBLE(GattCharacteristic pInput, SetupComplete pReady, ChangeEvent pEvent)
 {
     Ready           = pReady;
     ValueChanged    = pEvent;
     mCharacteristic = pInput;
     Build();
 }
 public PairedDeviceBLE(IDevice pDevice, SetupComplete ready)
 {
     mServices = new List <IServiceBLE>();
     mDevice   = pDevice;
     Ready    += ready;
     Build();
 }
Exemplo n.º 3
0
        public ServiceBLE(IService pInput, SetupComplete ready, ChangeEvent pEvent)
        {
            mCharacteristics = new List <ICharacteristicBLE>();
            Ready           += ready;
            mService         = pInput;
            mEvent           = pEvent;

            Build();
        }
        public ServiceBLE(IService pInput, SetupComplete ready)
        {
            mCharacteristics = new List <ICharacteristicBLE>();
            if (ready != null)
            {
                Ready += ready;
            }

            mService = pInput;
            Build();
        }
Exemplo n.º 5
0
        public CharacteristicBLE(ICharacteristic pInput, SetupComplete ready, ChangeEvent pEvent)
        {
            Ready          += ready;
            ValueChanged   += pEvent;
            mCharacteristic = pInput;
            mCharacteristic.ValueUpdated += CharacteristicEvent_ValueChanged;


            if (mCharacteristic.CanUpdate)
            {
                mCharacteristic.StartUpdatesAsync().ContinueWith((obj) => { Ready?.Invoke(); });
            }
            else
            {
                Ready?.Invoke();
            }
        }
        public CharacteristicBLE(ICharacteristic pInput, SetupComplete ready)
        {
            Ready += ready;

            Debug.WriteLine("Setting up characteristic");

            mCharacteristic = pInput;
            mCharacteristic.ValueUpdated += CharacteristicEvent_ValueChanged;

            if (mCharacteristic.CanUpdate)
            {
                mCharacteristic.StartUpdatesAsync().ContinueWith(UpdateStarted);
            }
            else
            {
                Ready?.Invoke();
            }

            _ValueChanged = null;
        }
Exemplo n.º 7
0
        public static string InstallOrUpdate()
        {
            if (!Directory.Exists("Synthea"))
            {
                Directory.CreateDirectory("Synthea");
            }

            CheckJavaInstallation();

            VersionCheck?.Invoke("SyntheaInstaller", EventArgs.Empty);
            var client = new RestClient("https://github.com/synthetichealth/synthea");

            var response       = client.Execute(new RestRequest("/releases/latest", Method.GET));
            var tag            = (string)((dynamic)JsonConvert.DeserializeObject(response.Content)).tag_name;
            var currentVersion = tag.Substring(1);

            if (Directory.Exists($"Synthea/synthea-{currentVersion}"))
            {
                SetupComplete?.Invoke("SyntheaInstaller", EventArgs.Empty);
                return(currentVersion);
            }

            DownloadLatest?.Invoke("SyntheaInstaller", EventArgs.Empty);
            client.DownloadData(new RestRequest($"/archive/{tag}.zip")).SaveAs("synthea.temp");
            ZipFile.ExtractToDirectory("synthea.temp", "Synthea");
            if (File.Exists("synthea.temp"))
            {
                File.Delete("synthea.temp");
            }

            InstallLatest?.Invoke("SyntheaInstaller", EventArgs.Empty);
            var synthea = SyntheaRunner.StartSynthea("-p 1", currentVersion);

            synthea.WaitForExit();
            synthea.Close();

            Directory.Delete($"Synthea/synthea-{currentVersion}/output", true);

            SetupComplete?.Invoke("SyntheaInstaller", EventArgs.Empty);
            return(currentVersion);
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.Camera1Fragment, container, false);

            bool opened = safeCameraOpenInView(view);


            controls = new Camera1Controls(mCamera);
            ChildFragmentManager.BeginTransaction().Replace(Resource.Id.camera_controls, controls).Commit();

            if (!opened)
            {
                Console.WriteLine("Camera failed to open");
                return(view);
            }

            SetupComplete?.Invoke();

            //view.Post(() => view.RequestLayout());

            return(view);
        }
        private void NextButtonClick(object element)
        {
            try
            {
                logger.Debug("Started account request and creating rsaKeys");
                if (String.IsNullOrEmpty(email) || String.IsNullOrEmpty(masterPassword))
                {
                    // To - Do Change style of Dialog
                    MessageBox.Show("Error retreiving account information");
                    return;
                }

                if (this.masterPassword != UserPassword)
                {
                    // To - Do Change style of Dialog
                    MessageBox.Show("Master password not matching");
                    return;
                }
                UserPassword = string.Empty;
                //Generate a public/private key pair

                /*RSA rsaBase = new RSA();
                 * rsaBase.GenerateKeys(1024, 65537, null, null);
                 * string privateKeyPem = rsaBase.PrivateKeyAsPEM;
                 * string publicKeyPem = rsaBase.PublicKeyAsPEM;
                 *
                 * logger.Debug("Call webAPI.RequestAccount");
                 * string publicKeyPem = rsaBase.PublicKeyAsPEM;*/
                byte[]             publicKeyPem  = null;
                ProtectedDataBlock privateKeyPem = null;
                using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048))
                {
                    privateKeyPem = new ProtectedDataBlock(Encoding.UTF8.GetBytes(RSAKeyManagement.ExportPrivateKeyToPEM(rsa)));
                    publicKeyPem  = Encoding.UTF8.GetBytes(RSAKeyManagement.ExportPublicKeyToPEM(rsa));
                }

                IPBWebAPI webAPI          = resolver.GetInstanceOf <IPBWebAPI>();
                dynamic   accountResponse = webAPI.RequestAccount(new WEBApiJSON.AccountRequest()
                {
                    email = email, language = "English", installation = pbData.InstallationUUID, public_key = Convert.ToBase64String(publicKeyPem)
                });
                if (accountResponse == null)
                {
                    // To - Do Change style of Dialog
                    MessageBox.Show("Error in account registration");
                    return;
                }
                else
                {
                    if (accountResponse.error != null)
                    {
                        //MessageBox.Show(accountResponse.error.details[0].ToString());
                        if (accountResponse.error.code == "400")
                        {
                            //try to register device
                            dynamic deviceRegistrationResponse = webAPI.RegisterDevice(new WEBApiJSON.DeviceRegistrationRequest()
                            {
                                installation     = pbData.InstallationUUID,
                                nickname         = Environment.MachineName,
                                software_version = Assembly.GetExecutingAssembly().GetName().Version.ToString()
                            }, email);
                            if (deviceRegistrationResponse == null)
                            {
                                // To - Do Change style of Dialog
                                MessageBox.Show("Error in device registration");
                                return;
                            }
                            else
                            {
                                if (deviceRegistrationResponse.error != null)
                                {
                                    //MessageBox.Show(deviceRegistrationResponse.error.message.ToString());
                                    if (deviceRegistrationResponse.error.code.ToString() == "403")
                                    {
                                        //send verification code for new device
                                        dynamic verificationRequestResponse = webAPI.RequestVerificationCode(email);
                                        Application.Current.Dispatcher.Invoke((Action) delegate
                                        {
                                            var verificationScreen = new VerificationRequired(resolver, email, masterPassword);// resolver.GetInstanceOf<VerificationRequired>();

                                            Navigator.NavigationService.Navigate(verificationScreen);
                                        });
                                    }

                                    return;
                                }
                                Application.Current.Dispatcher.Invoke((Action) delegate
                                {
                                    Login login             = resolver.GetInstanceOf <Login>();
                                    login.EmailTextBox.Text = email;
                                    Navigator.NavigationService.Navigate(login);
                                });
                            }
                        }
                    }
                }
                logger.Debug("Creating profile");
                if (!pbData.CreateProfile(email, masterPassword))
                {
                    // To - Do Change style of Dialog
                    MessageBox.Show("Error while creating secure database");
                }
                pbData.AddUserInfo(new DTO.UserInfo()
                {
                    Email = email, RSAPrivateKey = privateKeyPem, PublicKey = publicKeyPem
                });
                logger.Debug("Performing initial sync");
                PerformInitialSync();
                SetDefaultSettings(pbData);

                inAppAnalyitics.Get <Events.AccountCreationFlow, AccountCreationFlowItem>().Log(new AccountCreationFlowItem(3, AccountCreationFlowSteps.ConfirmMP, string.Empty, MarketingActionType.Continue));

                // Added dispatcher because background worker can't create new UI elements
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    var nextScreen = new SetupComplete(resolver);// resolver.GetInstanceOf<SetupComplete>();

                    Navigator.NavigationService.Navigate(nextScreen);
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        private void SetPinButtonClick(object obj)
        {
            SetupComplete setumComplete = resolver.GetInstanceOf <SetupComplete>();

            Navigator.NavigationService.Navigate(setumComplete);
        }
Exemplo n.º 11
0
 public ServiceBLE(GattDeviceService pInput, SetupComplete ready, ChangeEvent pEvent)
 {
     Ready    = ready;
     mService = pInput;
     Build(pEvent);
 }
Exemplo n.º 12
0
        private void HandlePowerTaskList(Line line)
        {
            var match = _gameEntityRegex.Match(line.Text);

            if (match.Success)
            {
                var id = int.Parse(match.Groups["id"].Value);
                _currentEntity = id;
                GameStateChange?.Invoke(new FullEntity(new GameEntityData(id), null));
                return;
            }

            match = _playerEntityRegex.Match(line.Text);
            if (match.Success)
            {
                var entityId = int.Parse(match.Groups["id"].Value);
                var playerId = int.Parse(match.Groups["playerId"].Value);
                _currentEntity = entityId;
                GameStateChange?.Invoke(new FullEntity(new PlayerEntityData(entityId, playerId), null));
                return;
            }

            match = _fullEntityRegex.Match(line.Text);
            if (match.Success)
            {
                var id = int.Parse(match.Groups["id"].Value);
                _currentEntity = id;
                var cardId = match.Groups["cardId"].Value;
                var zone   = GameTagParser.ParseEnum <Zone>(match.Groups["zone"].Value);
                if (string.IsNullOrEmpty(cardId) && zone != Zone.SETASIDE)
                {
                    cardId = _currentBlock?.Data.NextPredictedCard() ?? cardId;
                }
                GameStateChange?.Invoke(new FullEntity(new EntityData(id, null, cardId, zone), _currentBlock?.Data));
                return;
            }

            match = _tagChangeRegex.Match(line.Text);
            if (match.Success)
            {
                var entity = ParseEntity(match.Groups["entity"].Value);
                Enum.TryParse(match.Groups["tag"].Value, out GameTag tag);
                var value    = GameTagParser.ParseTag(tag, match.Groups["value"].Value);
                var entityId = entity.Id == -1 ? null : (int?)entity.Id;
                GameStateChange?.Invoke(new TagChange(new TagChangeData(tag, value, false, entityId, entity.Name)));
                return;
            }

            match = _updatingEntityRegex.Match(line.Text);
            if (match.Success)
            {
                var cardId = match.Groups["cardId"].Value;
                var entity = ParseEntity(match.Groups["entity"].Value);
                _currentEntity = entity.Id;
                var type = match.Groups["type"].Value;
                if (type == "CHANGE_ENTITY")
                {
                    GameStateChange?.Invoke(new ChangeEntity(new EntityData(entity.Id, entity.Name, cardId, null)));
                }
                else
                {
                    GameStateChange?.Invoke(new ShowEntity(new EntityData(entity.Id, entity.Name, cardId, null), _currentBlock?.Data));
                }
                return;
            }

            match = _creationTagRegex.Match(line.Text);
            if (match.Success && !line.Text.Contains("HIDE_ENTITY"))
            {
                var tag   = GameTagParser.ParseEnum <GameTag>(match.Groups["tag"].Value);
                var value = GameTagParser.ParseTag(tag, match.Groups["value"].Value);
                GameStateChange?.Invoke(new TagChange(new TagChangeData(tag, value, true, _currentEntity, null)));
                return;
            }

            match = _hideEntityRegex.Match(line.Text);
            if (match.Success)
            {
                var id = int.Parse(match.Groups["id"].Value);
                _currentEntity = id;
                GameStateChange?.Invoke(new HideEntity(new EntityData(id, "", null, null)));
            }

            match = _blockStartRegex.Match(line.Text);
            if (match.Success)
            {
                var type              = match.Groups["type"].Value;
                var entity            = ParseEntity(match.Groups["entity"].Value.Trim());
                var target            = ParseEntity(match.Groups["target"].Value.Trim());
                var effectCardId      = match.Groups["effectCardId"].Value;
                var effectIndex       = int.Parse(match.Groups["effectIndex"].Value);
                var rawTriggerKeyword = match.Groups["triggerKeyword"].Value;
                var triggerKeyword    = string.IsNullOrEmpty(rawTriggerKeyword) || rawTriggerKeyword == "0" ? null
                                        : (GameTag?)GameTagParser.ParseEnum <GameTag>(rawTriggerKeyword);
                var blockData = new BlockData(type, entity.Id, entity.CardId, effectCardId, effectIndex, triggerKeyword, target);
                _currentBlock = _currentBlock?.CreateChild(blockData) ?? new Block(null, blockData);
                foreach (var card in _blockHelper.GetCreatedCards(blockData))
                {
                    blockData.PredictedCards.Add(card);
                }
                BlockStart?.Invoke(blockData);
                return;
            }

            match = _debugDumpRegex.Match(line.Text);
            if (match.Success)
            {
                if (int.Parse(match.Groups["id"].Value) == 2)
                {
                    SetupComplete?.Invoke();
                }
            }

            if (line.Text.Contains("BLOCK_END"))
            {
                BlockEnd?.Invoke(_currentBlock?.Data);
                _currentBlock = _currentBlock?.Parent;
            }
        }
Exemplo n.º 13
0
        //Tries to open a CameraDevice
        public void openCamera(int width, int height, Bundle savedInstanceState)
        {
            if (null == Activity || Activity.IsFinishing)
            {
                return;
            }

            manager = (CameraManager)Activity.GetSystemService(Context.CameraService);
            try
            {
                if (!cameraOpenCloseLock.TryAcquire(2500, TimeUnit.Milliseconds))
                {
                    throw new RuntimeException("Time out waiting to lock camera opening.");
                }

                string cameraId = GetCam(manager, CURRENTCAMERA);
                CameraCharacteristics characteristics = manager.GetCameraCharacteristics(cameraId);

                StreamConfigurationMap map = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);

                videoSize = ChooseVideoSize(map.GetOutputSizes(Class.FromType(typeof(MediaRecorder))));

                previewSize = ChooseOptimalSize(map.GetOutputSizes(Class.FromType(typeof(MediaRecorder))), width, height, videoSize);

                int orientation = (int)Resources.Configuration.Orientation;
                if (orientation == (int)Android.Content.Res.Orientation.Landscape)
                {
                    textureView.SetAspectRatio(previewSize.Width, previewSize.Height);
                }
                else
                {
                    textureView.SetAspectRatio(previewSize.Height, previewSize.Width);
                }
                configureTransform(width, height);
                mediaRecorder = new MediaRecorder();
                if (stateListener == null)
                {
                    stateListener = new MyCameraStateCallback(this);
                }

                manager.OpenCamera(cameraId, stateListener, null);
                SetupComplete?.Invoke();
                max  = (Rect)characteristics.Get(CameraCharacteristics.SensorInfoActiveArraySize);
                size = (Size)characteristics.Get(CameraCharacteristics.SensorInfoPixelArraySize);

                controls          = new Camera2Controls(cameraDevice, size, max);
                controls.OnFocus += DoFocus;
                try
                {
                    ChildFragmentManager.BeginTransaction().Replace(Resource.Id.camera_controls, controls).Commit();
                }
                catch (System.Exception)
                {
                }
            }
            catch (CameraAccessException)
            {
                Toast.MakeText(Activity, "Cannot access the camera.", ToastLength.Short).Show();
                Activity.Finish();
            }
            catch (NullPointerException)
            {
                //var dialog = new ErrorDialog();
                //dialog.Show(ChildFragmentManager, "dialog");
            }
            catch (InterruptedException)
            {
                throw new RuntimeException("Interrupted while trying to lock camera opening.");
            }
        }