Пример #1
0
        private void PollMethod()
        {
            while (true)
            {
                lock (dataLock)
                {
                    if (NotifyFilter.HasFlag(GwNotifyFilter.EventState))
                    {
                        CheckEventChanges();
                    }

                    // any WvW
                    if ((notifyFilter & GwNotifyFilter.WvW) != 0)
                    {
                        CheckWvWMatchChanges();
                        CheckWvWDetailChanges();
                    }
                }

                if (DataReady != null)
                {
                    DataReady(this);
                }

                Thread.Sleep(PollFrequency);
            }
        }
Пример #2
0
 public ScenarioNotificationData(ScenarioData scenarioData, NotifyFilter filter)
 {
     Assert.IsNotNull(scenarioData, "scenarioData");
     Assert.IsNotNull(filter, "filter");
     this.ScenarioData = scenarioData;
     this.Filter       = filter;
 }
Пример #3
0
        /// <inheritdoc />
        /// <remarks>
        /// You can add the same routine again and we will call you once for each registered callback. Caller should handle that logic
        /// </remarks>
        public async Task RegisterCallbackAsync(NotifyFilter filter, Func <ScenarioData, Task> callbackRoutine, CancellationToken token)
        {
            Assert.IsNotNull(filter, "filter");
            Assert.IsNotNull(callbackRoutine, "callbackRoutine");

            this.Logger.LogMessage("RegisterCallbackAsync:: Registering callback with Filter '{0}'", filter);

            if (!this.GetCallbackSupportedScenario().Contains(filter.TargetScenario))
            {
                throw new NotSupportedException(
                          string.Format(CultureInfo.InvariantCulture, "Scenario : '{0}' not supported for callback", filter.TargetScenario));
            }

            await this.singleAccessLock.WaitAsync(token).ConfigureAwait(false);

            try
            {
                if (!this.callbackMap.ContainsKey(filter))
                {
                    this.callbackMap[filter] = new List <Func <ScenarioData, Task> > {
                        callbackRoutine
                    };
                }
                else
                {
                    this.callbackMap[filter].Add(callbackRoutine);
                }

                if (this.newEventSearcherTask == null)
                {
                    this.Logger.LogMessage("RegisterCallbackAsync:: Kicking off Searcher Task");

                    // kick off tasks that continuously monitors for new signals.
                    this.newEventSearcherTask = this.taskRunner.Run(() => this.SearchForNewSignalsInClusterAsync(token), this.InternalTokenSource.Token);
                }

                if (this.eventDispatcherTask == null)
                {
                    this.Logger.LogMessage("RegisterCallbackAsync:: Kicking off Dispatcher Task");

                    // kick off a task that continuously looks for new signals seen and invoke callbacks associated with them.
                    this.eventDispatcherTask = this.taskRunner.Run(() => this.DispatchSignalsAsync(token), this.InternalTokenSource.Token);
                }
            }
            finally
            {
                this.singleAccessLock.Release();
            }
        }
Пример #4
0
        /// <inheritdoc />
        public async Task UnRegisterCallbackAsync(NotifyFilter filter, Func <ScenarioData, Task> callbackRoutine, CancellationToken token)
        {
            Assert.IsNotNull(filter, "filter");
            Assert.IsNotNull(callbackRoutine, "callbackRoutine");
            this.Logger.LogMessage("UnRegisterCallbackAsync:: UnRegistering callback with Filter '{0}'", filter);

            if (!this.GetCallbackSupportedScenario().Contains(filter.TargetScenario))
            {
                throw new NotSupportedException(
                          string.Format(CultureInfo.InvariantCulture, "Scenario : '{0}' not supported for callback", filter.TargetScenario));
            }

            await this.singleAccessLock.WaitAsync(token).ConfigureAwait(false);

            this.Logger.LogMessage("Remove : Got Lock");

            try
            {
                if (!this.callbackMap.ContainsKey(filter))
                {
                    throw new CallbackNotRegisteredException(string.Format(CultureInfo.InvariantCulture, "Callback for Filter: {0} not registered", filter));
                }

                if (!this.callbackMap[filter].Contains(callbackRoutine))
                {
                    throw new CallbackNotRegisteredException(string.Format(CultureInfo.InvariantCulture, "Callback for Filter: {0} with Delegage: {1} not registered", filter, callbackRoutine));
                }

                this.Logger.LogMessage("Remove : Removing Now");
                this.callbackMap[filter].Remove(callbackRoutine);

                // if there are no callbacks for this filter, remove the entry from map.
                if (!this.callbackMap[filter].Any())
                {
                    this.callbackMap[filter] = null;
                    this.callbackMap.Remove(filter);

                    this.Logger.LogMessage("Remove : Emptying Nulling");
                }
            }
            finally
            {
                this.Logger.LogMessage("Remove : Releasing Lock");
                this.singleAccessLock.Release();
            }
        }
Пример #5
0
        void Register()
        {
            if (_key == null)
            {
                return;
            }

            var watchSubTree = NotifyFilter.Has(RegistryNotifyFilter.WatchSubTree);
            var notifyFilter = NotifyFilter & ~RegistryNotifyFilter.WatchSubTree;

            var result = NativeMethods.AdvApi32.RegNotifyChangeKeyValue(_key.Handle, watchSubTree, notifyFilter, _waitEvent.SafeWaitHandle, true);

            if (NativeUtils.Failed(result))
            {
                throw new Win32Exception(result);
            }

            _registeredWaitHandle = ThreadPool.RegisterWaitForSingleObject(_waitEvent, _callback, null, -1, true);
        }
Пример #6
0
 void INotifySource2.SetNotifyFilter(NotifyFilter in_NotifyFilter, UserThread in_pUserThreadFilter)
 {
     notifyFilter = in_NotifyFilter;
     userThread   = in_pUserThreadFilter;
 }
Пример #7
0
 void INotifySource2.SetNotifyFilter(NotifyFilter in_NotifyFilter, UserThread in_pUserThreadFilter) {
     notifyFilter = in_NotifyFilter;
     userThread = in_pUserThreadFilter;
 }
Пример #8
0
        private async Task <IList <Func <ScenarioData, Task> > > GetCallbacksForFilterAsync(NotifyFilter filter, CancellationToken token)
        {
            await this.singleAccessLock.WaitAsync(token).ConfigureAwait(false);

            try
            {
                return(this.callbackMap[filter]);
            }
            catch (KeyNotFoundException)
            {
                this.Logger.LogWarning("GetCallbacksForFilterAsync:: Key {0} not found", filter);
                throw;
            }
            finally
            {
                this.singleAccessLock.Release();
            }
        }
Пример #9
0
        /// <summary>
        /// Get new signals from store that matches the given filter
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private async Task <IEnumerable <ScenarioData> > GetNewSignalsMatchingGivenFilterAsync(NotifyFilter filter, CancellationToken token)
        {
            var allSignalsSeen = await this.GetSignalsForScenarioAsync(
                filter.TargetScenario,
                await this.GetDurationToLookForNewSignalsForScenarioAsync(filter.TargetScenario, token).ConfigureAwait(false),
                token).ConfigureAwait(false);

            var newSignalsMatchingFilter = new List <ScenarioData>();

            foreach (var oneSignal in allSignalsSeen.OrderBy(signal => signal.OriginTime))
            {
                // Encapsulate the new information into a shareable abstraction. We mark the event seen time as current time
                // which may not be completely accurate but it's close enough for all purposes.
                var scenarioData = new ScenarioData(filter.TargetScenario, oneSignal, DateTime.UtcNow);

                if (DateTime.UtcNow - oneSignal.OriginTime > filter.SignalAvailableForAtLeastDuration)
                {
                    if (!filter.NotifyOnlyForUnique || !await this.IsSignalAlreadyReportedAsync(scenarioData, token).ConfigureAwait(false))
                    {
                        newSignalsMatchingFilter.Add(scenarioData);
                    }
                }
            }

            return(newSignalsMatchingFilter);
        }
Пример #10
0
        private IService GetService(ParameterValue[] parameterValues, bool watchForCreate, bool watchForChanges, bool watchForRename, bool watchForDelete, NotifyFilter notifyFilter = null)
        {
            var designer = tester.CreateDesigner();

            designer.Properties[DirectoryWatchShared.WatchForChangesPropertyName].Value   = watchForChanges;
            designer.Properties[DirectoryWatchShared.WatchForCreationPropertyName].Value  = watchForCreate;
            designer.Properties[DirectoryWatchShared.WatchForDeletionsPropertyName].Value = watchForDelete;
            designer.Properties[DirectoryWatchShared.WatchForRenamingPropertyName].Value  = watchForRename;
            if (notifyFilter != null)
            {
                designer.Properties[DirectoryWatchShared.NotifyFilterPropertyName].Value = notifyFilter;
            }

            return(tester.Compile(designer).Execute(parameterValues));
        }
Пример #11
0
 private IService GetService(string path, bool watchForCreate, bool watchForChanges, bool watchForRename, bool watchForDelete, NotifyFilter notifyFilter = null, string filter = null, bool includeSubdirectories = false)
 {
     return(GetService(GetParameterValues(path, filter, includeSubdirectories), watchForCreate, watchForChanges, watchForRename, watchForDelete, notifyFilter));
 }
Пример #12
0
 public static extern bool ReadDirectoryChangesW(IntPtr hDirectory, IntPtr lpBuffer, int nBufferLength, [MarshalAs(UnmanagedType.Bool)] bool bWatchSubtree, NotifyFilter dwNotifyFilter, ref int lpBytesReturned, IntPtr lpOverlapped, IntPtr lpCompletionRoutine);
Пример #13
0
 public static extern IntPtr FindFirstChangeNotification(string lpPathName, bool bWatchSubtree, NotifyFilter dwNotifyFilter);