Ejemplo n.º 1
0
        /// <summary>
        /// Translates the system event to FileChangedEvent.
        /// </summary>
        /// <returns>The event.</returns>
        /// <param name="e">The event args.</param>
        private FileChangedEventArgs TranslateEvent(FileSystemEventArgs e)
        {
            FileChangedEventArgs newEvent = new FileChangedEventArgs();

            newEvent.ChangeType = e.ChangeType;
            newEvent.FullPath   = e.FullPath.Replace("\\", Properties.PathSep).Replace("/", Properties.PathSep);
            newEvent.Name       = e.Name.Replace("\\", Properties.PathSep).Replace("/", Properties.PathSep);

            if (this.LastEvent.Ticks >= DateTime.Now.Ticks)
            {
                newEvent.When = this.LastEvent.AddTicks(1);
            }
            else
            {
                newEvent.When = DateTime.Now;
            }

            this.LastEvent = newEvent.When;

            if (e.ChangeType != WatcherChangeTypes.Deleted)
            {
                FileInfo info = new FileInfo(newEvent.FullPath);
                newEvent.IsDirectory = (info.Attributes & FileAttributes.Directory) == FileAttributes.Directory;
            }

            if (e.ChangeType == WatcherChangeTypes.Renamed)
            {
                newEvent.OldName     = ((RenamedEventArgs)e).OldName.Replace("\\", Properties.PathSep).Replace("/", Properties.PathSep);
                newEvent.OldFullPath = ((RenamedEventArgs)e).OldFullPath.Replace("\\", Properties.PathSep).Replace("/", Properties.PathSep);
            }

            return(newEvent);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle create event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event.</param>
        private void OnCreatedEvent(object sender, FileSystemEventArgs e)
        {
            FileChangedEventArgs newEvent = this.TranslateEvent(e);

            if (this.Created != null)
            {
                this.Created(newEvent);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handle delete event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event.</param>
        private void OnDeletedEvent(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("Deleted: {0}", e.Name);

            FileChangedEventArgs newEvent = this.TranslateEvent(e);

            if (this.Deleted != null)
            {
                this.Deleted(newEvent);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handle the changed event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event.</param>
        private void OnChangedEvent(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("Changed: {0}", e.Name);
            FileChangedEventArgs newEvent = this.TranslateEvent(e);

            if (!newEvent.IsDirectory)
            {
                newEvent.SHA1     = CommonHelper.GetSHA1Hash(e.FullPath);
                newEvent.DataPath = Config.MetaFolderData.File(newEvent.SHA1);
                if (!File.Exists(newEvent.DataPath))
                {
                    File.Copy(newEvent.FullPath, newEvent.DataPath);
                }
            }

            if (this.Changed != null)
            {
                this.Changed(newEvent);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handle rename event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event.</param>
        private void OnRenamedEvent(object sender, RenamedEventArgs e)
        {
            Console.WriteLine("Renamed: {0} -> {1}", e.OldName, e.Name);

            FileChangedEventArgs newEvent = this.TranslateEvent(e);

            if (!newEvent.IsDirectory)
            {
                // TODO remove sha1
                newEvent.SHA1     = CommonHelper.GetSHA1Hash(e.FullPath);
                newEvent.DataPath = Config.MetaFolderData.File(newEvent.SHA1);
                if (!File.Exists(newEvent.DataPath))
                {
                    File.Copy(newEvent.FullPath, newEvent.DataPath);
                }
            }

            if (this.Renamed != null)
            {
                this.Renamed(newEvent);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Translates the system event to FileChangedEvent.
        /// </summary>
        /// <returns>The event.</returns>
        /// <param name="e">The event args.</param>
        private FileChangedEventArgs TranslateEvent(FileSystemEventArgs e)
        {
            FileChangedEventArgs newEvent = new FileChangedEventArgs();
            newEvent.ChangeType = e.ChangeType;
            newEvent.FullPath = e.FullPath.Replace("\\", Properties.PathSep).Replace("/", Properties.PathSep);
            newEvent.Name = e.Name.Replace("\\", Properties.PathSep).Replace("/", Properties.PathSep);

            if (this.LastEvent.Ticks >= DateTime.Now.Ticks)
            {
                newEvent.When = this.LastEvent.AddTicks(1);
            }
            else
            {
                newEvent.When = DateTime.Now;
            }

            this.LastEvent = newEvent.When;

            if (e.ChangeType != WatcherChangeTypes.Deleted)
            {
                FileInfo info = new FileInfo(newEvent.FullPath);
                newEvent.IsDirectory = (info.Attributes & FileAttributes.Directory) == FileAttributes.Directory;
            }

            if (e.ChangeType == WatcherChangeTypes.Renamed)
            {
                newEvent.OldName = ((RenamedEventArgs)e).OldName.Replace("\\", Properties.PathSep).Replace("/", Properties.PathSep);
                newEvent.OldFullPath = ((RenamedEventArgs)e).OldFullPath.Replace("\\", Properties.PathSep).Replace("/", Properties.PathSep);
            }

            return newEvent;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// File renamed.
 /// </summary>
 /// <param name="e">The event.</param>
 public void Renamed(FileChangedEventArgs e)
 {
     Console.WriteLine("Renamed");
     VersionList.Rename(e.Name, e.OldName, e.SHA1, e.When);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// File changed.
 /// </summary>
 /// <param name="e">The event.</param>
 public void Changed(FileChangedEventArgs e)
 {
     Console.WriteLine("Changed");
     VersionList.Change(e.Name, e.IsDirectory, e.SHA1, e.When);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// File created.
 /// </summary>
 /// <param name="e">The event.</param>
 public void Created(FileChangedEventArgs e)
 {
     // TODO comments
     Console.WriteLine("Created");
     VersionList.Create(e.Name, e.IsDirectory, e.When);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// File deleted.
 /// </summary>
 /// <param name="e">The event.</param>
 public void Deleted(FileChangedEventArgs e)
 {
     Console.WriteLine("Deleted");
     VersionList.Delete(e.Name, e.When);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// File renamed.
 /// </summary>
 /// <param name="e">The event.</param>
 public void Renamed(FileChangedEventArgs e)
 {
     Console.WriteLine("Renamed");
     VersionList.Rename(e.Name, e.OldName, e.SHA1, e.When);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// File deleted.
 /// </summary>
 /// <param name="e">The event.</param>
 public void Deleted(FileChangedEventArgs e)
 {
     Console.WriteLine("Deleted");
     VersionList.Delete(e.Name, e.When);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// File created.
 /// </summary>
 /// <param name="e">The event.</param>
 public void Created(FileChangedEventArgs e)
 {
     // TODO comments
     Console.WriteLine("Created");
     VersionList.Create(e.Name, e.IsDirectory, e.When);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// File changed.
 /// </summary>
 /// <param name="e">The event.</param>
 public void Changed(FileChangedEventArgs e)
 {
     Console.WriteLine("Changed");
     VersionList.Change(e.Name, e.IsDirectory, e.SHA1, e.When);
 }