Ejemplo n.º 1
0
 private void ResignCurrent()
 {
     if (Interlocked.CompareExchange(ref _current, null, this) == this)
     {
         CurrentChanged?.Invoke(this, new CurrentActivityChangedEventArgs(null));
     }
 }
Ejemplo n.º 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
                }
            }
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 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);
            }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
        private static void SetCurrent(Activity?activity)
        {
            Activity?previous = s_current.Value;

            s_current.Value = activity;
            CurrentChanged?.Invoke(null, new ActivityChangedEventArgs(previous, activity));
        }
Ejemplo n.º 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");
     }
 }
Ejemplo n.º 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);
                }
            }
Ejemplo n.º 12
0
 private void SetAsCurrent()
 {
     ContextHelper.Current = this;
     if (Interlocked.Exchange(ref _current, this) != this)
     {
         _current = this;
         CurrentChanged?.Invoke(this, new CurrentActivityChangedEventArgs(this));
     }
 }
Ejemplo n.º 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();
            }));
        }
Ejemplo n.º 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);
        }
    }
Ejemplo n.º 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));
 }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 18
0
            public bool MoveCurrentToPosition(int index)
            {
                if (index < 0 || index >= m_source.Count)
                {
                    return(false);
                }

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

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

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

            CurrentChanged.Raise(this);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 27
0
        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);
            }
        }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 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());
     }
 }
Ejemplo n.º 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
                }
            }
        }