Beispiel #1
0
        private void FileReferenceChangeContext_FileChanged(object sender, string fullFilePath)
        {
            lock (_gate)
            {
                if (_metadataReferenceRefreshCancellationTokenSources.TryGetValue(fullFilePath, out var cancellationTokenSource))
                {
                    cancellationTokenSource.Cancel();
                    _metadataReferenceRefreshCancellationTokenSources.Remove(fullFilePath);
                }

                cancellationTokenSource = new CancellationTokenSource();
                _metadataReferenceRefreshCancellationTokenSources.Add(fullFilePath, cancellationTokenSource);

                Task.Delay(TimeSpan.FromSeconds(5), cancellationTokenSource.Token).ContinueWith(_ =>
                {
                    var needsNotification = false;

                    lock (_gate)
                    {
                        // We need to re-check the cancellation token source under the lock, since it might have been cancelled and restarted
                        // due to another event
                        cancellationTokenSource.Token.ThrowIfCancellationRequested();
                        needsNotification = true;

                        _metadataReferenceRefreshCancellationTokenSources.Remove(fullFilePath);
                    }

                    if (needsNotification)
                    {
                        ReferenceChanged?.Invoke(this, fullFilePath);
                    }
                }, cancellationTokenSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default);
            }
        }
Beispiel #2
0
        internal void OnReferenceChanged(DBItem item)
        {
            if (!item.Attached)
            {
                return;
            }

            //if (item is DocumentWork work)
            //{
            //    if (work.Completed || work.UpdateState == DBUpdateState.Default)
            //        RefreshCache();
            //}
            //else if (item is DocumentReference reference)
            //{
            //    RefChanged?.Invoke(this, ListChangedType.Reset);
            //}
            if (item.UpdateState != DBUpdateState.Default && (item.UpdateState & DBUpdateState.Commit) != DBUpdateState.Commit && item.Attached)
            {
                changes++;
            }
            else if (changes > 0 && (item.UpdateState == DBUpdateState.Default || !item.Attached))
            {
                changes--;
            }
            ReferenceChanged?.Invoke(this, new DBItemEventArgs(item));
        }
 protected virtual void OnReferenceChanged(ReferenceChangedEventArgs <T> e)
 {
     ReferenceChanged?.Invoke(this, e);
 }
Beispiel #4
0
 public void OnReferenceChanged(object source, CHEventArgs args)
 {
     ReferenceChanged?.Invoke(source, args);
 }