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;
        }
 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);
 }
 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);
 }
Ejemplo n.º 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;
        }
        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);
            }
        }
Ejemplo n.º 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++;
		}
Ejemplo n.º 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;
        }
Ejemplo n.º 9
0
        void InvokeOnChangedCallback(object state)
        {
            if (onChangedCallback == null)
            {
                return;
            }

            try {
                onChangedCallback(state);
            } finally {
                onChangedCallback = null;
                onChangedState    = null;
            }
        }
 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);
     }
 }
 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);
     }
 }
 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++;
 }
Ejemplo n.º 13
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 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);
            }
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 15
0
        // 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);
                }
            }
        }
Ejemplo n.º 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;
		}
        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;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
            }
        }
 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;
 }
        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;
        }
Ejemplo n.º 23
0
 internal FileChangeEventTarget(OnChangedCallback onChangedCallback) {
     _onChangedCallback = onChangedCallback;
     _handler = new FileChangeEventHandler(this.OnChanged);
 }
Ejemplo n.º 24
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 (Interlocked.CompareExchange(ref _onChangedCallback, onChangedCallback, null) != null)
Ejemplo n.º 25
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;
			}
			
		}
Ejemplo n.º 26
0
		void InvokeOnChangedCallback (object state)
		{
			if (onChangedCallback == null)
				return;

			try {
				onChangedCallback (state);
			} finally {
				onChangedCallback = null;
				onChangedState = null;
			}
		}
 internal FileChangeEventTarget(OnChangedCallback onChangedCallback)
 {
     this._onChangedCallback = onChangedCallback;
     this._handler           = new FileChangeEventHandler(this.OnChanged);
 }
 public void NotifyOnChanged(OnChangedCallback onChangedCallback)
 {
     Contract.Requires(onChangedCallback != null);
 }
Ejemplo n.º 29
0
 public void SetGridChangeListener(OnChangedCallback action)
 {
     myChangeCallback = action;
 }
 private void ReverseCheckboxOnEventCheckChanged(UIComponent component, bool value)
 {
     OnChangedCallback?.Invoke();
 }
Ejemplo n.º 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);
            }
        }
 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);
 }
Ejemplo n.º 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);
		}
 private void DropDown_eventSelectedIndexChanged(UIComponent component, int index)
 {
     DebugUtils.Log("UINetTypeItem.DropDown_eventChanged");
     OnChangedCallback?.Invoke();
 }
 public void NotifyOnChanged(OnChangedCallback onChangedCallback)
 {
     Contract.Requires(onChangedCallback != null);
 }