コード例 #1
0
 /// <summary>
 /// Creates a new instance of the FileState class
 /// </summary>
 /// <param name="fileDate">LastModified date of the file.</param>
 /// <param name="fileSize">Size of the file.</param>
 /// <param name="stalker">FileStalker to register the notification to</param>
 public FileState(DateTime fileDate, long fileSize, FileStalker stalker)
 {
     this.FileDate         = fileDate;
     this.FileSize         = fileSize;
     this.LastNotification = DateTime.UtcNow;
     this.FileStalkers     = new FileStalker[] { stalker };
 }
コード例 #2
0
        private static void addFileStalker(FileStalker stalker)
        {
            lock (_StateLock)
            {
                FileState state = null;
                FileInfo  info  = new FileInfo(stalker.FileToWatch);

                if (!_State.TryGetValue(stalker.FileToWatch, out state))
                {
                    if (!info.Exists)
                    {
                        state = new FileState(DateTime.MinValue, -1L, stalker);
                    }
                    else
                    {
                        state = new FileState(info.LastWriteTimeUtc, info.Length, stalker);
                    }
                    _State.Add(stalker.FileToWatch, state);
                    return;
                }

                FileStalker[] newStalkers = new FileStalker[state.FileStalkers.Length + 1];
                Array.Copy(state.FileStalkers, newStalkers, state.FileStalkers.Length);
                newStalkers[newStalkers.Length - 1] = stalker;
                state.FileStalkers = newStalkers;
            }
        }
コード例 #3
0
        private static void removeFileStalker(FileStalker disposedStalker)
        {
            FileState state = null;

            lock (_StateLock)
            {
                if (!_State.TryGetValue(disposedStalker.FileToWatch, out state))
                {
                    return;
                }

                List <FileStalker> stalkers = new List <FileStalker>();

                foreach (FileStalker stalker in state.FileStalkers)
                {
                    if (disposedStalker.ID == stalker.ID)
                    {
                        continue;
                    }
                    stalkers.Add(stalker);
                }
                state.FileStalkers = stalkers.ToArray();
            }
        }
コード例 #4
0
 /// <summary>
 /// Creates a new instance of the FileStalkerCacheDependency.
 /// </summary>
 /// <param name="FilePath">Path to the file to monitor.</param>
 public FileStalkerCacheDependency(string FilePath)
 {
     _Stalker = new FileStalker(FilePath);
     _Stalker.FileModified += new EventHandler <FileModifiedEventArgs>(NotifyDependencyChanged);
     SetUtcLastModified(DateTime.MaxValue);
 }
コード例 #5
0
 internal FileModifiedEventArgs(FileStalker stalker)
 {
     _Stalker = stalker;
 }