Example #1
0
 private void ResignCurrent()
 {
     if (Interlocked.CompareExchange(ref _current, null, this) == this)
     {
         CurrentChanged?.Invoke(this, new CurrentActivityChangedEventArgs(null));
     }
 }
Example #2
0
        private void TimeKeeperMainThread()
        {
            var cancel = _cancelSource.Token;

            while (true)
            {
                var relTime  = TimeUtil.GetRelativeTime(TimeProvider.Now);
                var previous = _profile.Previous(TimeProvider.Now);
                var next     = _profile.Next(TimeProvider.Now);

                var brightness  = (int)LinearNodeInterpolation.Interpolate(relTime, previous, next, NodeProperty.Brightness);
                var temperature = (int)LinearNodeInterpolation.Interpolate(relTime, previous, next, NodeProperty.ColorTemperature);
                temperature -= temperature % 10;

                _allMonitors.SetBrightness(brightness);
                _allMonitors.SetTemperature(temperature);

                CurrentChanged?.Invoke(this, EventArgs.Empty);
                NodeElapsed?.Invoke(this, EventArgs.Empty);

                var result = WaitHandle.WaitAny(new[] { cancel.WaitHandle, _runNow }, TimeSpan.FromSeconds(1));

                if (result == 0)
                {
                    break;              // Stop
                }
            }
        }
Example #3
0
        public static async Task SetCurrentAsync(IDocumentReference?doc)
        {
            if (doc?.Id != Current?.Doc.Id || doc is null)
            {
                listener?.Remove();

                if (doc is null)
                {
                    if (DonorUser.Current is null)
                    {
                        Current     = null;
                        previousUID = null;
                        CurrentUpdated?.Invoke(null);
                        CurrentChanged?.Invoke(null);
                        return;
                    }
                    else
                    {
                        var            bundleCollection = DonorUser.Current.Doc.Collection("DonationBundles");
                        DonationBundle bundle           = new DonationBundle
                        {
                            StripeStatus  = StripeStatus.Pending,
                            GiftAidState  = DonorUser.Current.GiftAidEnabled ? GiftAidState.Unclaimed : GiftAidState.Ineligible,
                            Amount        = 0,
                            UserConfirmed = false
                        };
                        doc = await bundleCollection.AddAsync(bundle);

                        await DonorUser.Current.Doc.UpdateAsync(new { CurrentDonationBundle = doc });
                    }
                }
                listener = doc.AddSnapshotListener((snapshot, ex) => OnCurrentSnapshot(snapshot));
            }
        }
Example #4
0
            public bool MoveCurrentTo(object item)
            {
                if (item != null)
                {
                    int newCurrentPosition = m_source.IndexOf(item);
                    if (newCurrentPosition != -1)
                    {
                        CurrentPosition = newCurrentPosition;
                        CurrentChanged?.Invoke(this, null);
                        return(true);
                    }
                }

                // The item is not in the collection
                // We're going to schedule a call back later so we
                // restore the selection to the way we wanted it to begin with
                if (CurrentPosition >= 0 && CurrentPosition < m_source.Count)
                {
                    Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() =>
                    {
                        CurrentChanged?.Invoke(this, null);
                    })).AsTask().Wait();
                }
                return(false);
            }
Example #5
0
        private void SetDelegateView(ICollectionView collectionView)
        {
            if (delegateView == collectionView)
            {
                return;
            }

            IEnumerable <object> oldItems;

            if (delegateView != null)
            {
                delegateView.CollectionChanged -= OnDelegateViewCollectionChanged;
                delegateView.CurrentChanged    -= OnDelegateViewCurrentChanged;
                oldItems = delegateView.Cast <object>();
            }
            else
            {
                oldItems = new object[0];
            }

            delegateView = collectionView ?? CollectionView.Empty;

            delegateView.CollectionChanged += OnDelegateViewCollectionChanged;
            delegateView.CurrentChanged    += OnDelegateViewCurrentChanged;

            CollectionChanged.Raise(this, NotifyCollectionChangedEventArgs.Reset(oldItems, delegateView.Cast <object>()));
            CurrentChanged.Raise(this);
        }
Example #6
0
        private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
        {
            Current = snapshot?.ToObject <DonorUser>();
            CurrentUpdated?.Invoke(Current);
            if (previousUID != Current?.UID)
            {
                previousUID = Current?.UID;
                CurrentChanged?.Invoke(Current);
                CrossFirebasePushNotification.Current.UnsubscribeAll();
                if (!(Current is null))
                {
                    CrossFirebasePushNotification.Current.Subscribe("Urgent_Project");
                }
            }
            _ = DonationBundle.SetCurrentAsync(Current?.CurrentDonationBundle);
            if (!(Current is null) && ThemeEngine.SetTheme(Current.DesiredTheme))
            {
                SecureStorage.SetAsync("ThemePreference", Current.DesiredTheme.ToString());
            }
            var newTopics = Current?.DonatedProjectUIDs.Select(x => "Project_" + x)
                            .Where(x => !CrossFirebasePushNotification.Current.SubscribedTopics.Contains(x));

            if (newTopics?.Any() ?? false)
            {
                CrossFirebasePushNotification.Current.Subscribe(newTopics.ToArray());
            }
            System.Diagnostics.Debug.WriteLine(string.Join(", ", CrossFirebasePushNotification.Current.SubscribedTopics));
        }
 internal RestBackend(HttpMessageHandler handler)
 {
     httpClient             = handler == null ? new HttpClient() : new HttpClient(handler);
     httpClient.BaseAddress = new Uri("http://localhost:8080");
     poller = new CurrentEntryPoller(this);
     poller.CurrentChanged += (sender, args) => CurrentChanged?.Invoke(this, args);
 }
        private static void SetCurrent(Activity?activity)
        {
            Activity?previous = s_current.Value;

            s_current.Value = activity;
            CurrentChanged?.Invoke(null, new ActivityChangedEventArgs(previous, activity));
        }
Example #9
0
 /// <summary>
 /// Raises the <see cref="CurrentChanged"/> event.
 /// </summary>
 protected virtual void OnCurrentChanged(object e)
 {
     if (_updating <= 0)
     {
         CurrentChanged?.Invoke(this, e);
         OnPropertyChanged("CurrentItem");
     }
 }
Example #10
0
        private static void currentChanged()
        {
            if (Current != null)
            {
                Current.Visibility = Visibility.Visible;
            }

            CurrentChanged?.Invoke(Current, EventArgs.Empty);
        }
            void IVirtualDesktopNotification.CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew)
            {
                var args = new VirtualDesktopChangedEventArgs(FromComObject(pDesktopOld), FromComObject(pDesktopNew));

                if (CurrentChanged != null)
                {
                    CurrentChanged.Invoke(this, args);
                }
            }
Example #12
0
 private void SetAsCurrent()
 {
     ContextHelper.Current = this;
     if (Interlocked.Exchange(ref _current, this) != this)
     {
         _current = this;
         CurrentChanged?.Invoke(this, new CurrentActivityChangedEventArgs(this));
     }
 }
Example #13
0
        static IDisposable RegisterMinimalListener()
        {
            var window = new TransparentWindow();

            window.Show();
            Guid?        desktopId  = null;
            var          timeLimit  = TimeSpan.FromSeconds(30);
            var          limitTimer = Stopwatch.StartNew();
            COMException exception  = null;
            int          attempts   = 10;

            while (limitTimer.Elapsed < timeLimit || attempts > 0)
            {
                attempts = Math.Max(0, attempts - 1);
                try {
                    desktopId = VirtualDesktop.IdFromHwnd(window.Handle);
                    exception = null;
                } catch (COMException ex) when(ex.Match(HResult.INVALID_STATE))
                {
                    Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new Action(() => {}));
                    if (limitTimer.Elapsed >= timeLimit && attempts <= 0)
                    {
                        throw;
                    }
                    exception = ex;
                }
            }

            if (desktopId == null && exception != null && limitTimer.Elapsed >= timeLimit)
            {
                throw exception;
            }

            var timer = new DispatcherTimer(DispatcherPriority.Normal)
            {
                Interval  = TimeSpan.FromMilliseconds(250),
                IsEnabled = true,
            };

            timer.Tick += delegate {
                var newId = VirtualDesktop.IdFromHwnd(window.Handle);
                if (newId == null || newId == desktopId)
                {
                    return;
                }
                var newDesktop  = VirtualDesktop.FromId(newId.Value);
                var oldDesktop  = desktopId == null ? null : VirtualDesktop.FromId(desktopId.Value);
                var changedArgs = new VirtualDesktopChangedEventArgs(oldDesktop, newDesktop);
                CurrentChanged?.Invoke(typeof(VirtualDesktop), changedArgs);
                desktopId = newId;
            };

            return(Disposable.Create(() => {
                timer.Stop();
                window.Close();
            }));
        }
Example #14
0
    /// <summary>
    /// Called when the current health amount changed.
    /// </summary>
    /// <param name="prevHealth">The previous health amount.</param>
    /// <param name="currentHealth">The current health amount.</param>
    private void OnCurrentChanged(int prevHealth, int currentHealth)
    {
        CurrentChanged?.Invoke(prevHealth, currentHealth);
        CurrentChangedAsPercentage?.Invoke((float)currentHealth / (float)max);

        if (prevHealth > currentHealth)
        {
            FMODUtil.PlayOnTransform(hitSound, transform);
        }
    }
Example #15
0
 /// <summary>
 /// Currently selected item changed event
 /// </summary>
 /// <param name="e">event args</param>
 protected virtual void OnCurrentChanged(object e)
 {
     if (_deferCounter > 0)
     {
         return;
     }
     CurrentChanged?.Invoke(this, e);
     // ReSharper disable once ExplicitCallerInfoArgument
     OnPropertyChanged(nameof(CurrentItem));
 }
Example #16
0
 private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
 {
     Current = snapshot?.ToObject <Team>();
     CurrentUpdated?.Invoke(Current);
     if (previousUID != Current?.UID)
     {
         previousUID = Current?.UID;
         CurrentChanged?.Invoke(Current);
     }
 }
        private async Task OnIntervalAsync(IBackendAsync backend)
        {
            var current = await backend.GetCurrentAsync().ConfigureAwait(false);

            if (lastCurrent != current?.Name)
            {
                CurrentChanged?.Invoke(this, EventArgs.Empty);
                lastCurrent = current?.Name;
            }
        }
Example #18
0
            public bool MoveCurrentToPosition(int index)
            {
                if (index < 0 || index >= m_source.Count)
                {
                    return(false);
                }

                CurrentPosition = index;
                CurrentChanged?.Invoke(this, null);
                return(true);
            }
Example #19
0
        public bool MoveNext()
        {
            if (_position == _randomIndexes.Length - 1)
            {
                return(false);
            }

            _position++;
            CurrentChanged?.Invoke();
            return(true);
        }
Example #20
0
 protected virtual bool OnCurrentChanged(int old, int current)
 {
     if (CurrentChanged == null)
     {
         return(false);
     }
     else
     {
         return(CurrentChanged.Invoke(old, current));
     }
 }
        private void SetCurrent(object item, int itemIndex)
        {
            if (this.currentItem == item && this.currentItemIndex == itemIndex)
            {
                return;
            }

            this.currentItem      = item;
            this.currentItemIndex = itemIndex;

            CurrentChanged.Raise(this);
        }
Example #22
0
        public async Task SetCurrentAsync(string name)
        {
            var previousEntry = (await GetCurrentAsync().ConfigureAwait(false))?.Name;
            await proxyController.SetCurrentEntryAsync(name).ConfigureAwait(false);

            if (previousEntry != null && previousEntry != (await GetCurrentAsync().ConfigureAwait(false))?.Name)
            {
                CurrentChanged?.Invoke(this, EventArgs.Empty);
            }

            await Task.Factory.StartNew(() => UpdateSlaveAsync(name)).ConfigureAwait(true);
        }
Example #23
0
        private void bindingSource_CurrentChanged(object sender, EventArgs e)
        {
            if (_isProgrammFocus)
            {
                return;
            }
            var processObject = bindingSource.Current as ProcessObject;

            if (processObject != null)
            {
                CurrentChanged.Raise(this, processObject);
            }
            //OnCurrentChanged(new EventArgs<ProcessObject>(processObject));
        }
Example #24
0
 private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
 {
     Current = snapshot?.ToObject <DonationBundle>();
     CurrentUpdated?.Invoke(Current);
     if (previousUID != Current?.UID)
     {
         previousUID = Current?.UID;
         CurrentChanged?.Invoke(Current);
     }
     if (Current?.StripeStatus is StripeStatus.Succeeded || Current?.StripeStatus is StripeStatus.Failed)
     {
         _ = SetCurrentAsync(null);
         CurrentProcessed?.Invoke(Current?.StripeStatus is StripeStatus.Succeeded);
     }
 }
        public void ApplyChanges(Project newProject)
        {
            if (newProject == null)
            {
                throw new ArgumentNullException(nameof(newProject));
            }

            var oldProject = Current;

            Current = newProject;

            var changes = newProject.GetChanges(oldProject);
            var args    = new ProjectChangedEventArgs(oldProject, newProject, changes);

            CurrentChanged?.Invoke(this, args);
        }
Example #26
0
        /// <summary>
        /// Changes current mark from cross to nought or from nought to cross.
        /// </summary>
        public void ChangeCurrentMark()
        {
            lock (this)
            {
                if (Current == Mark.Cross)
                {
                    current = Mark.Nought;
                }
                else
                {
                    current = Mark.Cross;
                }
            }

            CurrentChanged?.Invoke(this, EventArgs.Empty);
        }
        public async Task SetCurrentAsync(string name)
        {
            var previousEntry = (await GetCurrentAsync().ConfigureAwait(false))?.Name;
            var response      = await httpClient.PutAsJsonAsync("api/entry", new NameEntry(name)).ConfigureAwait(false);

            var newEntry = string.Empty;

            if (response.IsSuccessStatusCode)
            {
                newEntry = (await response.Content.ReadAsAsync <CommandEntry>().ConfigureAwait(false))?.Name;
            }

            if (previousEntry != null && previousEntry != newEntry)
            {
                CurrentChanged?.Invoke(this, EventArgs.Empty);
            }
        }
Example #28
0
 public static void SetCurrent(string?uid)
 {
     if (uid != Current?.UID)
     {
         listener?.Remove();
         if (string.IsNullOrEmpty(uid))
         {
             Current     = null;
             previousUID = null;
             CurrentUpdated?.Invoke(null);
             CurrentChanged?.Invoke(null);
             return;
         }
         var doc = Firestore.Collection("Users").Document(uid !);
         listener = doc.AddSnapshotListener((snapshot, ex) => OnCurrentSnapshot(snapshot));
     }
 }
Example #29
0
 private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
 {
     Current = snapshot?.ToObject <PartnerUser>();
     CurrentUpdated?.Invoke(Current);
     if (Current?.UID != previousUID)
     {
         previousUID = Current?.UID;
         CurrentChanged?.Invoke(Current);
     }
     if (Current?.TeamConfirmed ?? false)
     {
         Team.SetCurrent(Current.TeamUID);
     }
     if (!(Current is null) && ThemeEngine.SetTheme(Current.DesiredTheme))
     {
         SecureStorage.SetAsync("ThemePreference", Current.DesiredTheme.ToString());
     }
 }
Example #30
0
        private void LerpedValuesMonitorMainThread()
        {
            var cancel = _cancelSource.Token;

            while (true)
            {
                var changed = false;

                if (_destinationBrightness != -1)
                {
                    var currentBrightness = _monitor.GetBrightness();
                    var newBrightness     = Lerp(currentBrightness, _destinationBrightness, MaxBrightnessDeltaPerSecond);
                    if (currentBrightness != newBrightness)
                    {
                        _monitor.SetBrightness(newBrightness);
                        changed = true;
                    }
                }

                if (_destinationTemperature != -1)
                {
                    var currentTemperature = _monitor.GetTemperature();
                    var newTemperature     = Lerp(currentTemperature, _destinationTemperature, MaxTemperatureDeltaPerSecond);
                    if (currentTemperature != newTemperature)
                    {
                        _monitor.SetTemperature(newTemperature);
                        changed = true;
                    }
                }

                if (changed)
                {
                    CurrentChanged?.Invoke(this, EventArgs.Empty);
                }

                var result = WaitHandle.WaitAny(new[] { cancel.WaitHandle }, TimeSpan.FromSeconds(0.1));

                if (result == 0)
                {
                    break;              // Stop
                }
            }
        }