Esempio n. 1
0
        /// <summary>
        /// Initializes the camera.
        /// </summary>
        /// <returns>The camera.</returns>
        public async Task InitializeCamera()
        {
            try
            {
                var lfLiveSessionDelegate = new CustomLFLiveSessionDelegate(LiveSessionChanged);

                _session.Delegate = lfLiveSessionDelegate;
                _session.PreView  = _mainView;

                await RequestAccessForVideo();
            }
            catch (Exception error)
            {
                _log.WriteLineTime(_tag + "\n" +
                                   "InitializeCamera() Camera failed to initialise \n " +
                                   "ErrorMessage: \n" +
                                   error.Message + "\n" +
                                   "Stacktrace: \n " +
                                   error.StackTrace);
            }

            Available?.Invoke(this, _cameraAvailable);

            _log.WriteLineTime(_tag + "\n" + "RetrieveCameraDevice() Camera initalised \n ");
        }
Esempio n. 2
0
        internal void HandleGuildCreate(GatewayGuild data)
        {
            if (!_guilds.TryGetValue(data.Id.RawValue, out var guild))
            {
                guild = new CachedGuild {
                    Id = data.Id
                };
                guild.Update(data);
                _guilds[data.Id.RawValue] = guild;
                Created?.Invoke(guild);

                guild.Unavailable = data.Unavailable;
                if (guild.Unavailable != true)
                {
                    Available?.Invoke(guild);
                }
            }
            else
            {
                if (data.Unavailable == false && guild.Unavailable != false)
                {
                    guild.Unavailable = false;
                    Available?.Invoke(guild);
                }
                else if (data.Unavailable == true && guild.Unavailable != true)
                {
                    guild.Unavailable = true;
                    Unavailable?.Invoke(guild);
                }
                guild.Update(data);
            }
        }
        /// <summary>
        /// Opens the camera.
        /// </summary>
        public void OpenCamera()
        {
            if (_context == null || OpeningCamera)
            {
                return;
            }

            OpeningCamera = true;

            _manager = (CameraManager)_context.GetSystemService(Context.CameraService);

            try
            {
                string cameraId = _manager.GetCameraIdList()[0];

                // To get a list of available sizes of camera preview, we retrieve an instance of
                // StreamConfigurationMap from CameraCharacteristics
                CameraCharacteristics  characteristics = _manager.GetCameraCharacteristics(cameraId);
                StreamConfigurationMap map             = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
                _previewSize = map.GetOutputSizes(Java.Lang.Class.FromType(typeof(SurfaceTexture)))[0];
                Android.Content.Res.Orientation orientation = Resources.Configuration.Orientation;
                if (orientation == Android.Content.Res.Orientation.Landscape)
                {
                    _cameraTexture.SetAspectRatio(_previewSize.Width, _previewSize.Height);
                }
                else
                {
                    _cameraTexture.SetAspectRatio(_previewSize.Height, _previewSize.Width);
                }

                HandlerThread thread = new HandlerThread("CameraPreview");
                thread.Start();
                Handler backgroundHandler = new Handler(thread.Looper);

                // We are opening the camera with a listener. When it is ready, OnOpened of mStateListener is called.
                _manager.OpenCamera(cameraId, _stateListener, null);
            }
            catch (Java.Lang.Exception error)
            {
                _log.WriteLineTime(_tag + "\n" +
                                   "OpenCamera() Failed to open camera  \n " +
                                   "ErrorMessage: \n" +
                                   error.Message + "\n" +
                                   "Stacktrace: \n " +
                                   error.StackTrace);

                Available?.Invoke(this, false);
            }
            catch (System.Exception error)
            {
                _log.WriteLineTime(_tag + "\n" +
                                   "OpenCamera() Failed to open camera  \n " +
                                   "ErrorMessage: \n" +
                                   error.Message + "\n" +
                                   "Stacktrace: \n " +
                                   error.StackTrace);

                Available?.Invoke(this, false);
            }
        }
Esempio n. 4
0
 public void Publish(int count)
 {
     for (int i = 1; i <= count; ++i)
     {
         double value = Fetch(i);
         var    e     = new QuoteEventArgs(value);
         Available?.Invoke(this, e);
     }
 }
Esempio n. 5
0
        private void NatUtilityOnDeviceFound(object sender, DeviceEventArgs deviceEventArgs)
        {
            Devices.Add(deviceEventArgs.Device);

            if (Devices.Count == 1)
            {
                Available?.Invoke(this, EventArgs.Empty);
            }
        }
    public void Publish(int count)
    {
        for (int i = 1; i <= count; ++i)
        {
            double value = Generate(i);
            var    e     = new QuoteEventArgs(value);

            Available?.Invoke(this, e);             //if(Available != null) Available.Invoke(this, e)
        }
    }
Esempio n. 7
0
 public void Publish(int count)
 {
     for (int i = 1; i <= count; ++i)
     {
         for (int t = Environment.TickCount + 1000 * i; t > Environment.TickCount;)
         {
             ;
         }
         double val = 0.01 * generator.Next(1000, 10000);
         Available?.Invoke(this, new QuoteEventArgs(val));             //raising the event
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Initializes the camera.
        /// </summary>
        /// <returns>The camera.</returns>
        public void InitializeCamera()
        {
            try
            {
                NSError error;
                NSError err;

                _device.LockForConfiguration(out err);
                _device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
                _device.UnlockForConfiguration();

                _input = new AVCaptureDeviceInput(_device, out error);
                _captureSession.AddInput(_input);

                _output = new AVCaptureStillImageOutput();

                var dict = new NSMutableDictionary();
                dict[AVVideo.CodecKey] = new NSNumber((int)AVVideoCodec.JPEG);
                _captureSession.AddOutput(_output);

                InvokeOnMainThread(delegate
                {
                    // capture connection used for rotating camera
                    _captureConnection = _previewLayer.Connection;
                    SetStartOrientation();
                    // set orientation before loading camera
                    _captureSession.StartRunning();
                });
            }
            catch (Exception error)
            {
                _log.WriteLineTime(_tag + "\n" +
                                   "InitializeCamera() Camera failed to initialise \n " +
                                   "ErrorMessage: \n" +
                                   error.Message + "\n" +
                                   "Stacktrace: \n " +
                                   error.StackTrace);
            }

            Available?.Invoke(this, _cameraAvailable);

            _log.WriteLineTime(_tag + "\n" + "RetrieveCameraDevice() Camera initalised \n ");
        }
Esempio n. 9
0
 /// <summary>
 /// Notifies the available.
 /// </summary>
 /// <param name="isAvailable">If set to <c>true</c> is available.</param>
 public void NotifyAvailable(bool isAvailable)
 {
     Available?.Invoke(this, isAvailable);
 }
Esempio n. 10
0
 public PacketItem(Getter <T> getter, Setter <T> settter = null, Available <T> available = null) : this()
 {
     Get          = getter;
     Set          = settter;
     GetAvailable = (packet) => available?.Invoke(packet) ?? true;
 }