Ejemplo n.º 1
0
		/// <summary>
		/// Event handler that gets called when a file has been renamed
		/// </summary>
		/// <param name="sender">The sender of the event</param>
		/// <param name="e">The event data</param>
		private static void Janitor_FileRenamed(object sender, RenamedEventArgs e)
		{
			bool isDir = Directory.Exists(e.FullPath);

			if (!isDir && !MediaManager.IsSupported(e.FullPath))
				return;

			JanitorTask task = new JanitorTask() { Data = e.OldFullPath + "\n" + e.FullPath, Job = isDir ? JanitorJob.RenameFolder : JanitorJob.RenameFile };

			foreach (JanitorTask jt in janitorTasks)
			{
				// on delete this event will fire afterwards, but we should skip it
				if (jt.Job == JanitorJob.DeleteFile && jt.Data == e.FullPath)
					return;

				// check if this job is already in the queue
				if (jt.Job == task.Job && jt.Data == task.Data)
					return;
			}
			//janitorLazyness.Stop();
			if (janitorLazyness != null)
				janitorLazyness.Dispose();
			janitorTasks.Add(task);
			janitorLazyness = new Timer(Janitor_Clean, null, 400, 3600);
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Event handler that gets called when a file has been modified
		/// </summary>
		/// <param name="sender">The sender of the event</param>
		/// <param name="e">The event data</param>
		private static void Janitor_FileChanged(object sender, FileSystemEventArgs e)
		{
			bool isDir = Directory.Exists(e.FullPath);

			if (!PathIsAdded(e.FullPath) || !MediaManager.IsSupported(e.FullPath))
				return;

			JanitorTask task = new JanitorTask() { Data = e.FullPath };
			if (e.ChangeType == WatcherChangeTypes.Deleted)
			{
				if (MediaManager.IsSupported(e.FullPath))
					task.Job = JanitorJob.DeleteFile;
				else if (Directory.Exists(e.FullPath))
					task.Job = JanitorJob.DeleteFolder;
				else
					return;
			}
			else if (e.ChangeType == WatcherChangeTypes.Created)
				task.Job = isDir ? JanitorJob.CreateFolder : JanitorJob.CreateFile;

			else if (e.ChangeType == WatcherChangeTypes.Changed)
			{
				if (isDir) return;
				task.Job = JanitorJob.UpdateFile;
			}
			else
				return;

			foreach (JanitorTask jt in janitorTasks)
			{
				// on create folder this event will fire afterwards, but we should skip it
				if (!isDir && jt.Job == JanitorJob.CreateFolder && e.ChangeType == WatcherChangeTypes.Changed && jt.Data == e.FullPath)
					return;

				// on rename and create this event will fire afterwards, but we should skip it
				if (e.ChangeType == WatcherChangeTypes.Changed &&
					((jt.Job == JanitorJob.RenameFile && jt.Data.EndsWith("\n" + e.FullPath)) ||
					(jt.Job == JanitorJob.CreateFile && jt.Data == e.FullPath)))
					return;

				// check if this job is already in the queue
				if (jt.Job == task.Job && jt.Data == task.Data)
					return;
			}

			if (janitorLazyness != null)
				janitorLazyness.Dispose();
			janitorTasks.Add(task);
			janitorLazyness = new Timer(Janitor_Clean, null, 400, 3600);
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Event handler that gets called when a Library has been modified
		/// </summary>
		/// <param name="sender">The sender of the event</param>
		/// <param name="e">The event data</param>
		private static void Janitor_LibraryChanged(object sender, FileSystemEventArgs e)
		{
			JanitorTask task = new JanitorTask() { Data = System.IO.Path.GetFileNameWithoutExtension(e.Name) };
			if (e.ChangeType == WatcherChangeTypes.Deleted)
				task.Job = JanitorJob.DeleteLibrary;
			else if (e.ChangeType == WatcherChangeTypes.Created)
				task.Job = JanitorJob.CreateLibrary;
			else if (e.ChangeType == WatcherChangeTypes.Changed)
				task.Job = JanitorJob.UpdateLibrary;
			else
				return;

			foreach (JanitorTask jt in janitorTasks)
			{
				// on rename and create this event will fire afterwards, but we should skip it
				if (e.ChangeType == WatcherChangeTypes.Changed &&
					((jt.Job == JanitorJob.RenameLibrary && jt.Data.EndsWith("\n" + System.IO.Path.GetFileNameWithoutExtension(e.Name))) ||
					(jt.Job == JanitorJob.CreateLibrary && jt.Data == System.IO.Path.GetFileNameWithoutExtension(e.Name))))
				{
					return;
				}

				// check if this job is already in the queue
				if (jt.Job == task.Job && jt.Data == task.Data)
				{
					return;
				}

				// an update may be preceded by a delete, so we change the delete task into an update task
				if (task.Job == JanitorJob.UpdateLibrary && jt.Job == JanitorJob.DeleteLibrary && task.Data == jt.Data)
				{
					jt.Job = JanitorJob.UpdateLibrary;
					return;
				}

				// an update may be followed by a delete, so we skip the delete
				if (task.Job == JanitorJob.DeleteLibrary && jt.Job == JanitorJob.UpdateLibrary && task.Data == jt.Data)
				{
					return;
				}
			}

			if (janitorLazyness != null)
				janitorLazyness.Dispose();
			janitorTasks.Add(task);
			janitorLazyness = new Timer(Janitor_Clean, null, 400, 3600);
		}