Ejemplo n.º 1
0
 private async void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (e.AddedItems.Count > 0 && e.AddedItems[0] is ViewModels.FileItemViewModel vm1)
     {
         if (vm1.IsFolder)
         {
             await SetFolder(vm1);
         }
         else
         {
             FileOpenedEventHandler?.Invoke(this, vm1);
             (sender as Microsoft.Toolkit.Uwp.UI.Controls.DataGrid).SelectedItem = null;
         }
     }
 }
Ejemplo n.º 2
0
        protected void OnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            string remoteAddress = args.RemoteAddress.CanonicalName;

            // Reject messages from this computer
            if (remoteAddress == information.LocalAddress)
            {
                return;
            }

            DataReader reader = args.GetDataReader();

            byte[] data = new byte[reader.UnconsumedBufferLength];
            reader.ReadBytes(data);

            EndpointInformation message = EndpointInformation.Deserialize(data);

            if (message != null)
            {
                // Did message originate from a server?
                if (message.Type == EndpointType.Server)
                {
                    ServerDiscovered?.Invoke(this, message);
                }
            }
        }
Ejemplo n.º 3
0
 private void OnReadingChanged(GyrometerReading reading)
 {
     if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
     {
         this.Log().DebugFormat($"Gyrometer reading received " +
                                $"X:{reading.AngularVelocityX}, Y:{reading.AngularVelocityY}, Z:{reading.AngularVelocityZ}");
     }
     _readingChanged?.Invoke(this, new GyrometerReadingChangedEventArgs(reading));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Closes the device, stops the device watcher, stops listening for app events, and resets object state to before a device
        /// was ever connected.
        ///
        /// When the UsbDevice is closing, it will cancel all IO operations that are still pending (not complete).
        /// The close will not wait for any IO completion callbacks to be called, so the close call may complete before any of
        /// the IO completion callbacks are called.
        /// The pending IO operations will still call their respective completion callbacks with either a task
        /// canceled error or the operation completed.
        /// </summary>
        private void CloseCurrentlyConnectedDevice()
        {
            if (device != null)
            {
                // Notify callback that we're about to close the device
                deviceCloseCallback?.Invoke(this, deviceInformation);

                NanoDevicesEventSource.Log.CloseDevice(deviceInformation.Id);
            }
        }
Ejemplo n.º 5
0
            private void T_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
            {
                sender.DataRequested -= T_DataRequested;
                var d = args.Request.Data;

                d.Properties.Title             = Package.Current.DisplayName;
                d.Properties.ApplicationName   = Package.Current.DisplayName;
                d.Properties.PackageFamilyName = Package.Current.Id.FamilyName;
                handler?.Invoke(sender, args);
            }
Ejemplo n.º 6
0
        /// <summary>
        /// Closes the device, stops the device watcher, stops listening for app events, and resets object state to before a device
        /// was ever connected.
        ///
        /// When the UsbDevice is closing, it will cancel all IO operations that are still pending (not complete).
        /// The close will not wait for any IO completion callbacks to be called, so the close call may complete before any of
        /// the IO completion callbacks are called.
        /// The pending IO operations will still call their respective completion callbacks with either a task
        /// canceled error or the operation completed.
        /// </summary>
        private void CloseCurrentlyConnectedDevice()
        {
            if (device != null)
            {
                // Notify callback that we're about to close the device
                deviceCloseCallback?.Invoke(this, deviceInformation);

                Debug.WriteLine($"Closing device {deviceInformation.Id}");
            }
        }
Ejemplo n.º 7
0
 public NotifyOnLoadedCalendarDatePicker()
 {
     DefaultStyleKey = typeof(NotifyOnLoadedCalendarDatePicker);
     DateChanged    += (sender, args) =>
     {
         if (IsLoaded)
         {
             _dateChangedWhenLoaded?.Invoke(sender, args);
         }
     };
 }
Ejemplo n.º 8
0
        private void OnMessageReceived(byte[] message, int startingOffset, int length, TimeSpan timestamp)
        {
            if (message.Length == 0)
            {
                // ignore empty message
                return;
            }

            try
            {
                // parse message
                var parsedMessages = _parser.Parse(message, startingOffset, length, timestamp);
                foreach (var parsedMessage in parsedMessages)
                {
                    var eventArgs = new MidiMessageReceivedEventArgs(parsedMessage);
                    _messageReceived?.Invoke(this, eventArgs);
                }
            }
            catch (Exception ex)
            {
                this.Log().LogError("MIDI Message could not be parsed", ex);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Closes the device, stops the device watcher, stops listening for app events, and resets object state to before a device
        /// was ever connected.
        ///
        /// When the SerialDevice is closing, it will cancel all IO operations that are still pending (not complete).
        /// The close will not wait for any IO completion callbacks to be called, so the close call may complete before any of
        /// the IO completion callbacks are called.
        /// The pending IO operations will still call their respective completion callbacks with either a task
        /// cancelled error or the operation completed.
        /// </summary>
        private void CloseCurrentlyConnectedDevice()
        {
            if (_device != null)
            {
                // Notify callback that we're about to close the device
                _deviceCloseCallback?.Invoke(this, _deviceInformation);

                // dispose on a Task to give it a timeout to perform the Dispose()
                // this is required to be able to actually close devices that get stuck with pending tasks on the in/output streams
                var closeTask = Task.Factory.StartNew(() =>
                {
                    // This closes the handle to the device
                    _device.Dispose();
                    _device = null;
                });

                //need to wrap this in try-catch to catch possible AggregateExceptions
                try
                {
                    Task.WaitAll(new Task[] { closeTask }, TimeSpan.FromMilliseconds(1000));
                }
                catch { }
            }
        }
Ejemplo n.º 10
0
 internal static void NotifyLayoutChanged(RadioButtons sender)
 {
     LayoutChanged?.Invoke(sender, null);
 }
Ejemplo n.º 11
0
 public void Dispatch <TSender, TArgs>(TypedEventHandler <TSender, TArgs> eventHandler, TSender sender, TArgs args, string eventName = null)
 {
     eventHandler?.Invoke(sender, args);
 }
Ejemplo n.º 12
0
 private void OnNativeReadingChanged(object sender, NativeHingeAngleReading e) =>
 _readingChanged?.Invoke(this, new HingeAngleSensorReadingChangedEventArgs(new HingeAngleReading(e.AngleInDegrees, e.Timestamp)));
Ejemplo n.º 13
0
 void RaiseAfterRestoreSavedNavigation() => afterRestoreSavedNavigation?.Invoke(this, CurrentPageType);
Ejemplo n.º 14
0
 private void OnReadingChanged(MagnetometerReading reading)
 {
     _readingChanged?.Invoke(this, new MagnetometerReadingChangedEventArgs(reading));
 }
        /// <summary>
        /// This method opens the device using the WinRT Serial API. After the device is opened, save the device
        /// so that it can be used across scenarios.
        ///
        /// It is important that the FromIdAsync call is made on the UI thread because the consent prompt can only be displayed
        /// on the UI thread.
        ///
        /// This method is used to reopen the device after the device reconnects to the computer and when the app resumes.
        /// </summary>
        /// <param name="deviceInfo">Device information of the device to be opened</param>
        /// <param name="deviceSelector">The AQS used to find this device</param>
        /// <returns>True if the device was successfully opened, false if the device could not be opened for well known reasons.
        /// An exception may be thrown if the device could not be opened for extraordinary reasons.</returns>
        public async Task <bool> OpenDeviceAsync(DeviceInformation deviceInfo, string deviceSelector)
        {
            await Task.Delay(250);

            device = await SerialDevice.FromIdAsync(deviceInfo.Id);

            bool successfullyOpenedDevice = false;

            try
            {
                // Device could have been blocked by user or the device has already been opened by another app.
                if (device != null)
                {
                    successfullyOpenedDevice = true;

                    deviceInformation   = deviceInfo;
                    this.deviceSelector = deviceSelector;

                    Debug.WriteLine($"Device {deviceInformation.Id} opened");

                    // adjust settings for serial port
                    device.BaudRate = 115200;

                    /////////////////////////////////////////////////////////////
                    // need to FORCE the parity setting to _NONE_ because
                    // the default on the current ST Link is different causing
                    // the communication to fail
                    /////////////////////////////////////////////////////////////
                    device.Parity = SerialParity.None;

                    device.WriteTimeout   = TimeSpan.FromMilliseconds(1000);
                    device.ReadTimeout    = TimeSpan.FromMilliseconds(1000);
                    device.ErrorReceived += Device_ErrorReceived;

                    // Notify registered callback handle that the device has been opened
                    deviceConnectedCallback?.Invoke(this, deviceInformation);

                    // Background tasks are not part of the app, so app events will not have an affect on the device
                    if (!isBackgroundTask && (appSuspendEventHandler == null || appResumeEventHandler == null))
                    {
                        RegisterForAppEvents();
                    }

                    // User can block the device after it has been opened in the Settings charm. We can detect this by registering for the
                    // DeviceAccessInformation.AccessChanged event
                    if (deviceAccessEventHandler == null)
                    {
                        RegisterForDeviceAccessStatusChange();
                    }

                    // Create and register device watcher events for the device to be opened unless we're reopening the device
                    if (deviceWatcher == null)
                    {
                        deviceWatcher = DeviceInformation.CreateWatcher(deviceSelector);

                        RegisterForDeviceWatcherEvents();
                    }

                    if (!watcherStarted)
                    {
                        // Start the device watcher after we made sure that the device is opened.
                        StartDeviceWatcher();
                    }
                }
                else
                {
                    successfullyOpenedDevice = false;

                    //notificationStatus = NotifyType.ErrorMessage;

                    var deviceAccessStatus = DeviceAccessInformation.CreateFromId(deviceInfo.Id).CurrentStatus;

                    switch (deviceAccessStatus)
                    {
                    case DeviceAccessStatus.DeniedByUser:
                        Debug.WriteLine($"Access to the device was blocked by the user : {deviceInfo.Id}");
                        break;

                    case DeviceAccessStatus.DeniedBySystem:
                        // This status is most likely caused by app permissions (did not declare the device in the app's package.appxmanifest)
                        // This status does not cover the case where the device is already opened by another app.
                        Debug.WriteLine($"Access to the device was blocked by the system : {deviceInfo.Id}");
                        break;

                    default:
                        // Most likely the device is opened by another app, but cannot be sure
                        Debug.WriteLine($"Unknown error, possibly opened by another app : {deviceInfo.Id}");
                        break;
                    }
                }
            }
            // catch all because the device open might fail for a number of reasons
            catch (Exception ex)
            {
            }

            return(successfullyOpenedDevice);
        }
Ejemplo n.º 16
0
 public void RaiseResponseReceived()
 {
     ResponseReceived?.Invoke(this, new TcpClientResponseReceivedArgs(Response));
 }