コード例 #1
0
        void IFileChangeNotificationSystem.StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out Object state, out DateTimeOffset lastWrite, out long fileSize)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }
            if (onChangedCallback == null)
            {
                throw new ArgumentNullException("onChangedCallback");
            }
            FileChangeEventTarget target = new FileChangeEventTarget(onChangedCallback);
            FileAttributesData    fad;

            HttpRuntime.FileChangesMonitor.StartMonitoringPath(filePath, target.Handler, out fad);
            if (fad == null)
            {
                fad = FileAttributesData.NonExistantAttributesData;
            }
            state = target;
#if DBG
            Debug.Assert(fad.UtcLastWriteTime.Kind == DateTimeKind.Utc, "fad.UtcLastWriteTime.Kind == DateTimeKind.Utc");
#endif
            lastWrite = fad.UtcLastWriteTime;
            fileSize  = fad.FileSize;
        }
コード例 #2
0
 internal FileChangeEventTarget(string fileName, OnChangedCallback onChangedCallback) {
     _fileName = fileName;
     _onChangedCallback = onChangedCallback;
     _changedHandler = new FileSystemEventHandler(this.OnChanged);
     _errorHandler = new ErrorEventHandler(this.OnError);
     _renamedHandler = new RenamedEventHandler(this.OnRenamed);
 }
コード例 #3
0
 private void VerticalOffsetField_eventTextSubmitted(UIComponent component, string value)
 {
     if (!float.TryParse(value, out VerticalOffset))
     {
         return;
     }
     OnChangedCallback?.Invoke();
 }
 internal FileChangeEventTarget(string fileName, OnChangedCallback onChangedCallback)
 {
     _fileName          = fileName;
     _onChangedCallback = onChangedCallback;
     _changedHandler    = new FileSystemEventHandler(this.OnChanged);
     _errorHandler      = new ErrorEventHandler(this.OnError);
     _renamedHandler    = new RenamedEventHandler(this.OnRenamed);
 }
コード例 #5
0
        public void StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            callback = onChangedCallback;

            string parentDir;

            if (File.Exists(filePath))
            {
                var fi = new FileInfo(filePath);
                lastWriteTime = DateTimeOffset.FromFileTime(fi.LastWriteTimeUtc.Ticks);
                fileSize      = fi.Length;
                parentDir     = Path.GetDirectoryName(filePath);
            }
            else if (Directory.Exists(filePath))
            {
                var di = new DirectoryInfo(filePath);
                lastWriteTime = DateTimeOffset.FromFileTime(di.LastWriteTimeUtc.Ticks);
                fileSize      = -1L;
                parentDir     = filePath;
            }
            else
            {
                lastWriteTime = DateTimeOffset.MaxValue;
                fileSize      = -1L;

                if (filePath.LastIndexOf(Path.DirectorySeparatorChar) != -1)
                {
                    parentDir = Path.GetDirectoryName(filePath);
                }
                else
                {
                    parentDir = filePath;
                }
            }

            FileChangeNotificationSystemEntry entry;

            lock (watchers_lock)
            {
                Dictionary <string, FileChangeNotificationSystemEntry> watchers = Watchers;

                if (!watchers.TryGetValue(parentDir, out entry))
                {
                    entry = new FileChangeNotificationSystemEntry(parentDir, this);
                    watchers.Add(parentDir, entry);
                }

                entry.Add(filePath);
                entry.Start();
            }

            state = entry;
        }
コード例 #6
0
        private void OnChangedHelper(object state)
        {
            this._flags[2] = true;
            Interlocked.CompareExchange(ref this._onChangedState, state, NOT_SET);
            OnChangedCallback callback = this._onChangedCallback;

            if ((callback != null) && this._flags.ChangeValue(4, true))
            {
                callback(this._onChangedState);
            }
        }
コード例 #7
0
		public void StartMonitoring (string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
		{
			if (UseNullState)
				state = null;
			else
				state = filePath;
			lastWriteTime = DateTimeOffset.FromFileTime (DateTime.Now.Ticks);
			callback = onChangedCallback;
			fileSize = 10;
			StartMonitoringCalled = true;
			StartMonitoringCallCount++;
		}
コード例 #8
0
        void IFileChangeNotificationSystem.StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
        {
            if (filePath is null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }
            if (onChangedCallback is null)
            {
                throw new ArgumentNullException(nameof(onChangedCallback));
            }

            FileInfo         fileInfo = new FileInfo(filePath);
            string           dir      = Path.GetDirectoryName(filePath);
            DirectoryMonitor dirMon   = _dirMonitors[dir] as DirectoryMonitor;

            if (dirMon == null)
            {
                lock (_lock)
                {
                    dirMon = _dirMonitors[dir] as DirectoryMonitor;
                    if (dirMon == null)
                    {
                        dirMon     = new DirectoryMonitor();
                        dirMon.Fsw = new FileSystemWatcher(dir);
                        dirMon.Fsw.NotifyFilter = NotifyFilters.FileName
                                                  | NotifyFilters.DirectoryName
                                                  | NotifyFilters.CreationTime
                                                  | NotifyFilters.Size
                                                  | NotifyFilters.LastWrite
                                                  | NotifyFilters.Security;
                        dirMon.Fsw.EnableRaisingEvents = true;
                    }
                    _dirMonitors[dir] = dirMon;
                }
            }

            FileChangeEventTarget target = new FileChangeEventTarget(fileInfo.Name, onChangedCallback);

            lock (dirMon)
            {
                dirMon.Fsw.Changed += target.ChangedHandler;
                dirMon.Fsw.Created += target.ChangedHandler;
                dirMon.Fsw.Deleted += target.ChangedHandler;
                dirMon.Fsw.Error   += target.ErrorHandler;
                dirMon.Fsw.Renamed += target.RenamedHandler;
            }

            state         = target;
            lastWriteTime = File.GetLastWriteTime(filePath);
            fileSize      = (fileInfo.Exists) ? fileInfo.Length : -1;
        }
コード例 #9
0
        void InvokeOnChangedCallback(object state)
        {
            if (onChangedCallback == null)
            {
                return;
            }

            try {
                onChangedCallback(state);
            } finally {
                onChangedCallback = null;
                onChangedState    = null;
            }
        }
コード例 #10
0
 public void NotifyOnChanged(OnChangedCallback onChangedCallback)
 {
     if (onChangedCallback == null)
     {
         throw new ArgumentNullException("onChangedCallback");
     }
     if (Interlocked.CompareExchange <OnChangedCallback>(ref this._onChangedCallback, onChangedCallback, null) != null)
     {
         throw new InvalidOperationException(R.Method_already_invoked);
     }
     if (this._flags[2])
     {
         this.OnChanged(null);
     }
 }
コード例 #11
0
 public void NotifyOnChanged(OnChangedCallback onChangedCallback)
 {
     if (onChangedCallback == null)
     {
         throw new ArgumentNullException("onChangedCallback");
     }
     if (Interlocked.CompareExchange<OnChangedCallback>(ref this._onChangedCallback, onChangedCallback, null) != null)
     {
         throw new InvalidOperationException(R.Method_already_invoked);
     }
     if (this._flags[2])
     {
         this.OnChanged(null);
     }
 }
コード例 #12
0
 public void StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
 {
     if (UseNullState)
     {
         state = null;
     }
     else
     {
         state = filePath;
     }
     lastWriteTime         = DateTimeOffset.FromFileTime(DateTime.Now.Ticks);
     _callback             = onChangedCallback;
     fileSize              = 10;
     StartMonitoringCalled = true;
     StartMonitoringCallCount++;
 }
コード例 #13
0
ファイル: ChangeMonitor.cs プロジェクト: pedrobsaila/runtime
        // Cache implementers must call this to be notified of any dependency changes.
        // NotifyOnChanged can only be invoked once, and will throw InvalidOperationException
        // on subsequent calls.  The OnChangedCallback is guaranteed to be called exactly once.
        // It will be called when the dependency changes, or if it has already changed, it will
        // be called immediately (on the same thread??).
        public void NotifyOnChanged(OnChangedCallback onChangedCallback)
        {
            if (onChangedCallback is null)
            {
                throw new ArgumentNullException(nameof(onChangedCallback));
            }

            if (Interlocked.CompareExchange(ref _onChangedCallback, onChangedCallback, null) != null)
            {
                throw new InvalidOperationException(SR.Method_already_invoked);
            }

            // if it already changed, raise the event now.
            if (_flags[CHANGED])
            {
                OnChanged(null);
            }
        }
コード例 #14
0
        void IFileChangeNotificationSystem.StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }
            if (onChangedCallback == null)
            {
                throw new ArgumentNullException("onChangedCallback");
            }
            FileInfo         info          = new FileInfo(filePath);
            string           directoryName = Path.GetDirectoryName(filePath);
            DirectoryMonitor monitor       = this._dirMonitors[directoryName] as DirectoryMonitor;

            if (monitor == null)
            {
                lock (this._lock)
                {
                    monitor = this._dirMonitors[directoryName] as DirectoryMonitor;
                    if (monitor == null)
                    {
                        monitor = new DirectoryMonitor {
                            Fsw = new FileSystemWatcher(directoryName)
                        };
                        monitor.Fsw.NotifyFilter        = NotifyFilters.Security | NotifyFilters.CreationTime | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.DirectoryName | NotifyFilters.FileName;
                        monitor.Fsw.EnableRaisingEvents = true;
                    }
                    this._dirMonitors[directoryName] = monitor;
                }
            }
            FileChangeEventTarget target = new FileChangeEventTarget(info.Name, onChangedCallback);

            lock (monitor)
            {
                monitor.Fsw.Changed += target.ChangedHandler;
                monitor.Fsw.Created += target.ChangedHandler;
                monitor.Fsw.Deleted += target.ChangedHandler;
                monitor.Fsw.Error   += target.ErrorHandler;
                monitor.Fsw.Renamed += target.RenamedHandler;
            }
            state         = target;
            lastWriteTime = File.GetLastWriteTime(filePath);
            fileSize      = info.Exists ? info.Length : -1L;
        }
コード例 #15
0
ファイル: ChangeMonitor.cs プロジェクト: pedrobsaila/runtime
        // The helper routines (OnChangedHelper and DisposeHelper) are used to prevent
        // an infinite loop, where Dispose calls OnChanged and OnChanged calls Dispose.
        private void OnChangedHelper(object state)
        {
            _flags[CHANGED] = true;

            // the callback is only invoked once, after NotifyOnChanged is called, so
            // remember "state" on the first call and use it when invoking the callback
            Interlocked.CompareExchange(ref _onChangedState, state, s_NOT_SET);

            OnChangedCallback onChangedCallback = _onChangedCallback;

            if (onChangedCallback != null)
            {
                // only invoke the callback once
                if (_flags.ChangeValue(INVOKED, true))
                {
                    onChangedCallback(_onChangedState);
                }
            }
        }
コード例 #16
0
		public void StartMonitoring (string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
		{
			if (String.IsNullOrEmpty (filePath))
				throw new ArgumentNullException ("filePath");
			
			callback = onChangedCallback;

			string parentDir;
			if (File.Exists (filePath)) {
				var fi = new FileInfo (filePath);
				lastWriteTime = DateTimeOffset.FromFileTime (fi.LastWriteTimeUtc.Ticks);
				fileSize = fi.Length;
				parentDir = Path.GetDirectoryName (filePath);
			} else if (Directory.Exists (filePath)) {
				var di = new DirectoryInfo (filePath);
				lastWriteTime = DateTimeOffset.FromFileTime (di.LastWriteTimeUtc.Ticks);
				fileSize = -1L;
				parentDir = filePath;
			} else {
				lastWriteTime = DateTimeOffset.MaxValue;
				fileSize = -1L;

				if (filePath.LastIndexOf (Path.DirectorySeparatorChar) != -1)
					parentDir = Path.GetDirectoryName (filePath);
				else
					parentDir = filePath;
			}

			FileChangeNotificationSystemEntry entry;
			lock (watchers_lock) {
				Dictionary <string, FileChangeNotificationSystemEntry> watchers = Watchers;

				if (!watchers.TryGetValue (parentDir, out entry)) {
					entry = new FileChangeNotificationSystemEntry (parentDir, this);
					watchers.Add (parentDir, entry);
				}

				entry.Add (filePath);
				entry.Start ();
			}

			state = entry;
		}
コード例 #17
0
        void IFileChangeNotificationSystem.StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out Object state, out DateTimeOffset lastWriteTime, out long fileSize) {
            if (filePath == null) {
                throw new ArgumentNullException("filePath");
            }
            if (onChangedCallback == null) {
                throw new ArgumentNullException("onChangedCallback");
            }
            FileInfo fileInfo = new FileInfo(filePath);
            string dir = Path.GetDirectoryName(filePath);
            DirectoryMonitor dirMon = _dirMonitors[dir] as DirectoryMonitor;
            if (dirMon == null) {
                lock (_lock) {
                    dirMon = _dirMonitors[dir] as DirectoryMonitor;
                    if (dirMon == null) {
                        dirMon = new DirectoryMonitor();
                        dirMon.Fsw = new FileSystemWatcher(dir);
                        dirMon.Fsw.NotifyFilter = NotifyFilters.FileName 
                                                  | NotifyFilters.DirectoryName 
                                                  | NotifyFilters.CreationTime 
                                                  | NotifyFilters.Size 
                                                  | NotifyFilters.LastWrite 
                                                  | NotifyFilters.Security;
                        dirMon.Fsw.EnableRaisingEvents = true;
                    }
                    _dirMonitors[dir] = dirMon;
                }
            }
            
            FileChangeEventTarget target = new FileChangeEventTarget(fileInfo.Name, onChangedCallback);

            lock (dirMon) {
                dirMon.Fsw.Changed += target.ChangedHandler;
                dirMon.Fsw.Created += target.ChangedHandler;
                dirMon.Fsw.Deleted += target.ChangedHandler;
                dirMon.Fsw.Error += target.ErrorHandler;
                dirMon.Fsw.Renamed += target.RenamedHandler;
            }

            state = target;
            lastWriteTime = File.GetLastWriteTime(filePath);
            fileSize = (fileInfo.Exists) ? fileInfo.Length : -1;
        }
 void IFileChangeNotificationSystem.StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
 {
     if (filePath == null)
     {
         throw new ArgumentNullException("filePath");
     }
     if (onChangedCallback == null)
     {
         throw new ArgumentNullException("onChangedCallback");
     }
     FileInfo info = new FileInfo(filePath);
     string directoryName = Path.GetDirectoryName(filePath);
     DirectoryMonitor monitor = this._dirMonitors[directoryName] as DirectoryMonitor;
     if (monitor == null)
     {
         lock (this._lock)
         {
             monitor = this._dirMonitors[directoryName] as DirectoryMonitor;
             if (monitor == null)
             {
                 monitor = new DirectoryMonitor {
                     Fsw = new FileSystemWatcher(directoryName)
                 };
                 monitor.Fsw.NotifyFilter = NotifyFilters.Security | NotifyFilters.CreationTime | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.DirectoryName | NotifyFilters.FileName;
                 monitor.Fsw.EnableRaisingEvents = true;
             }
             this._dirMonitors[directoryName] = monitor;
         }
     }
     FileChangeEventTarget target = new FileChangeEventTarget(info.Name, onChangedCallback);
     lock (monitor)
     {
         monitor.Fsw.Changed += target.ChangedHandler;
         monitor.Fsw.Created += target.ChangedHandler;
         monitor.Fsw.Deleted += target.ChangedHandler;
         monitor.Fsw.Error += target.ErrorHandler;
         monitor.Fsw.Renamed += target.RenamedHandler;
     }
     state = target;
     lastWriteTime = File.GetLastWriteTime(filePath);
     fileSize = info.Exists ? info.Length : -1L;
 }
コード例 #19
0
        void IFileChangeNotificationSystem.StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out Object state, out DateTimeOffset lastWrite, out long fileSize) {
            if (filePath == null) {
                throw new ArgumentNullException("filePath");
            }
            if (onChangedCallback == null) {
                throw new ArgumentNullException("onChangedCallback");
            }
            FileChangeEventTarget target = new FileChangeEventTarget(onChangedCallback);
            FileAttributesData fad;
            HttpRuntime.FileChangesMonitor.StartMonitoringPath(filePath, target.Handler, out fad);
            if (fad == null) {
                fad = FileAttributesData.NonExistantAttributesData;
            }
            state = target;
#if DBG            
            Debug.Assert(fad.UtcLastWriteTime.Kind == DateTimeKind.Utc, "fad.UtcLastWriteTime.Kind == DateTimeKind.Utc");
#endif
            lastWrite = fad.UtcLastWriteTime;
            fileSize = fad.FileSize;
        }
コード例 #20
0
        public void NotifyOnChanged(OnChangedCallback onChangedCallback)
        {
            if (onChangedCallback == null)
            {
                throw new ArgumentNullException("onChangedCallback");
            }

            if (notifyOnChangedCalled)
            {
                throw new InvalidOperationException("The callback method has already been invoked.");
            }

            notifyOnChangedCalled  = true;
            this.onChangedCallback = onChangedCallback;
            if (HasChanged)
            {
                InvokeOnChangedCallback(onChangedState);
                return;
            }
        }
コード例 #21
0
 void IFileChangeNotificationSystem.StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWrite, out long fileSize)
 {
     FileAttributesData nonExistantAttributesData;
     if (filePath == null)
     {
         throw new ArgumentNullException("filePath");
     }
     if (onChangedCallback == null)
     {
         throw new ArgumentNullException("onChangedCallback");
     }
     FileChangeEventTarget target = new FileChangeEventTarget(onChangedCallback);
     HttpRuntime.FileChangesMonitor.StartMonitoringPath(filePath, target.Handler, out nonExistantAttributesData);
     if (nonExistantAttributesData == null)
     {
         nonExistantAttributesData = FileAttributesData.NonExistantAttributesData;
     }
     state = target;
     lastWrite = nonExistantAttributesData.UtcLastWriteTime;
     fileSize = nonExistantAttributesData.FileSize;
 }
コード例 #22
0
        void IFileChangeNotificationSystem.StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWrite, out long fileSize)
        {
            FileAttributesData nonExistantAttributesData;

            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }
            if (onChangedCallback == null)
            {
                throw new ArgumentNullException("onChangedCallback");
            }
            FileChangeEventTarget target = new FileChangeEventTarget(onChangedCallback);

            HttpRuntime.FileChangesMonitor.StartMonitoringPath(filePath, target.Handler, out nonExistantAttributesData);
            if (nonExistantAttributesData == null)
            {
                nonExistantAttributesData = FileAttributesData.NonExistantAttributesData;
            }
            state     = target;
            lastWrite = nonExistantAttributesData.UtcLastWriteTime;
            fileSize  = nonExistantAttributesData.FileSize;
        }
コード例 #23
0
 internal FileChangeEventTarget(OnChangedCallback onChangedCallback) {
     _onChangedCallback = onChangedCallback;
     _handler = new FileChangeEventHandler(this.OnChanged);
 }
コード例 #24
0
ファイル: ChangeMonitor.cs プロジェクト: vitek-karas/runtime
 // Cache implementers must call this to be notified of any dependency changes.
 // NotifyOnChanged can only be invoked once, and will throw InvalidOperationException
 // on subsequent calls.  The OnChangedCallback is guaranteed to be called exactly once.
 // It will be called when the dependency changes, or if it has already changed, it will
 // be called immediately (on the same thread??).
 public void NotifyOnChanged(OnChangedCallback onChangedCallback !!)
 {
     if (Interlocked.CompareExchange(ref _onChangedCallback, onChangedCallback, null) != null)
コード例 #25
0
ファイル: ChangeMonitor.cs プロジェクト: nzdunic/ravendb
		public void NotifyOnChanged (OnChangedCallback onChangedCallback)
		{
			if (onChangedCallback == null)
				throw new ArgumentNullException ("onChangedCallback");

			if (notifyOnChangedCalled)
				throw new InvalidOperationException ("The callback method has already been invoked.");

			notifyOnChangedCalled = true;
			this.onChangedCallback = onChangedCallback;
			if (HasChanged) {
				InvokeOnChangedCallback (onChangedState);
				return;
			}
			
		}
コード例 #26
0
ファイル: ChangeMonitor.cs プロジェクト: nzdunic/ravendb
		void InvokeOnChangedCallback (object state)
		{
			if (onChangedCallback == null)
				return;

			try {
				onChangedCallback (state);
			} finally {
				onChangedCallback = null;
				onChangedState = null;
			}
		}
コード例 #27
0
 internal FileChangeEventTarget(OnChangedCallback onChangedCallback)
 {
     this._onChangedCallback = onChangedCallback;
     this._handler           = new FileChangeEventHandler(this.OnChanged);
 }
 public void NotifyOnChanged(OnChangedCallback onChangedCallback)
 {
     Contract.Requires(onChangedCallback != null);
 }
コード例 #29
0
 public void SetGridChangeListener(OnChangedCallback action)
 {
     myChangeCallback = action;
 }
コード例 #30
0
 private void ReverseCheckboxOnEventCheckChanged(UIComponent component, bool value)
 {
     OnChangedCallback?.Invoke();
 }
コード例 #31
0
        // Cache implementers must call this to be notified of any dependency changes.
        // NotifyOnChanged can only be invoked once, and will throw InvalidOperationException
        // on subsequent calls.  The OnChangedCallback is guaranteed to be called exactly once.
        // It will be called when the dependency changes, or if it has already changed, it will
        // be called immediately (on the same thread??).
        public void NotifyOnChanged(OnChangedCallback onChangedCallback) {
            if (onChangedCallback == null) {
                throw new ArgumentNullException("onChangedCallback");
            }

            if (Interlocked.CompareExchange(ref _onChangedCallback, onChangedCallback, null) != null) {
                throw new InvalidOperationException(R.Method_already_invoked);                
            }

            // if it already changed, raise the event now.
            if (_flags[CHANGED]) {
                OnChanged(null);
            }
        }
コード例 #32
0
 void IFileChangeNotificationSystem.StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
 {
     StartMonitoring(filePath, onChangedCallback, out state, out lastWriteTime, out fileSize);
 }
コード例 #33
0
		void IFileChangeNotificationSystem.StartMonitoring (string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
		{
			StartMonitoring (filePath, onChangedCallback, out state, out lastWriteTime, out fileSize);
		}
コード例 #34
0
 private void DropDown_eventSelectedIndexChanged(UIComponent component, int index)
 {
     DebugUtils.Log("UINetTypeItem.DropDown_eventChanged");
     OnChangedCallback?.Invoke();
 }
 public void NotifyOnChanged(OnChangedCallback onChangedCallback)
 {
     Contract.Requires(onChangedCallback != null);
 }