コード例 #1
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();
            }
        }
コード例 #2
0
        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;
        }
コード例 #3
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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: PowerParser.cs プロジェクト: riQQ/HearthSim.Common
        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;
            }
        }
コード例 #6
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.");
            }
        }