[Roam-commit] SF.net SVN: roam: [109] Trunk/Source
Status: Alpha
Brought to you by:
jonfroehlich
|
From: <jon...@us...> - 2007-12-07 06:40:08
|
Revision: 109
http://roam.svn.sourceforge.net/roam/?rev=109&view=rev
Author: jonfroehlich
Date: 2007-12-06 22:40:03 -0800 (Thu, 06 Dec 2007)
Log Message:
-----------
renamed CameraMediaSniffer.cs to CameraMediaCapturedSniffer.cs
Modified Paths:
--------------
Trunk/Source/Roam.Test/UI/Controls/CameraMediaSnifferTest.cs
Trunk/Source/Roam.suo
Added Paths:
-----------
Trunk/Source/Roam/Media/CameraMediaCapturedSniffer.cs
Removed Paths:
-------------
Trunk/Source/Roam/Media/CameraMediaSniffer.cs
Added: Trunk/Source/Roam/Media/CameraMediaCapturedSniffer.cs
===================================================================
--- Trunk/Source/Roam/Media/CameraMediaCapturedSniffer.cs (rev 0)
+++ Trunk/Source/Roam/Media/CameraMediaCapturedSniffer.cs 2007-12-07 06:40:03 UTC (rev 109)
@@ -0,0 +1,250 @@
+#region Copyright & License
+//
+// Copyright (c) 2005 - 2007 The Regents of the University of Washington, Intel
+// Research Seattle, and the Roam project. All rights reserved.
+//
+// This software is open-source under the BSD license. You may obtain a copy
+// of this license at
+//
+// http://roam.sourceforge.net/license.txt
+//
+// Alternatively, please see "license.txt" which should be included in
+// this source code distribution.
+//
+#endregion Copyright & License
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenNETCF.IO;
+using System.IO;
+using System.Threading;
+using Microsoft.WindowsMobile.Status;
+using System.Diagnostics;
+
+namespace Roam.Media
+{
+ /// <summary>
+ /// jeffixme : need to update this to work dynamically when a storage card is
+ /// removed/added
+ /// </summary>
+ /// <summary>
+ ///
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ public class CameraMediaCapturedSniffer : IDisposable
+ {
+ public event EventHandler<MediaCapturedEventArgs> MediaCaptured;
+
+ private List<FileSystemWatcher> _listFileSystemWatchers = new List<FileSystemWatcher>();
+
+ /// <summary>
+ /// So, unfortunately, we cannot combine file extensions in our filter string.
+ /// This is a limitation of the FileSystemWatcher. So, for example, a filter
+ /// string of "*.mp4, *.avi" to watch for two different video file formats would
+ /// not work. Therefore, our filter is set to *.* -- we can always filter
+ /// after we receive a FileCreatedEvent
+ /// </summary>
+ private string _filter = "*.*";
+
+ public CameraMediaCapturedSniffer()
+ {
+ string[] paths = GetMediaPathsToMonitor();
+
+ for (int i = 0; i < paths.Length; i++)
+ {
+ //jeffixme : we should never create the Storage Card directory
+ //so we should check to see if they have a Storage Card
+ //i suppose we should also dynamically check if they place/remove a storage card
+ if (!Directory.Exists(paths[i])) { Directory.CreateDirectory(paths[i]); }
+
+ FileSystemWatcher fsw = new FileSystemWatcher(paths[i], _filter);
+ fsw.Created += new FileSystemEventHandler(OnFileCreated);
+ fsw.EnableRaisingEvents = true;
+ fsw.NotifyFilter = NotifyFilters.FileName;
+
+ FileSystemWatcher fsw2 = new FileSystemWatcher(paths[i], _filter);
+ fsw2.Changed += new FileSystemEventHandler(OnFileChanged);
+ fsw2.EnableRaisingEvents = true;
+ fsw2.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
+
+ _listFileSystemWatchers.Add(fsw);
+ }
+ }
+
+ public virtual void OnFileChanged(object sender, FileSystemEventArgs e)
+ {
+ Debug.WriteLine("OnFileChanged: " + e.FullPath);
+ }
+
+ public virtual void Dispose()
+ {
+ foreach (FileSystemWatcher fsw in _listFileSystemWatchers)
+ {
+ fsw.Dispose();
+ }
+ _listFileSystemWatchers.Clear();
+ }
+
+ protected virtual string[] GetMediaPathsToMonitor()
+ {
+ //jeffixme the location of the date dir needs to change
+ //when the day rollovers;
+ //we can either update them each time the date changes or
+ //only when the camera application is being used (check system state)
+ string dateDir = DateTime.Now.ToString("MM-dd-yyyy") + " 00001";
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ //a previous version of this class received these paths
+ //from the Registry--should I go back to that?
+ string localPicturePath = @"My Documents\My Pictures\";
+ string storagePicturePath = @"\Storage Card\My Documents\My Pictures\";
+ string localVideoPath = @"My Documents\My Videos\";
+ string storageVideoPath = @"\Storage Card\My Documents\My Videos\";
+
+ string[] paths = new string[] {
+ localPicturePath, storagePicturePath, localVideoPath, storageVideoPath,
+ Path.Combine(localPicturePath, dateDir), Path.Combine(storagePicturePath, dateDir),
+ Path.Combine(localVideoPath, dateDir), Path.Combine(storageVideoPath, dateDir)
+ };
+ return paths;
+ }
+
+ private void OnFileCreated(object sender, FileSystemEventArgs e)
+ {
+ Debug.WriteLine("OnFileCreated: " + e.FullPath);
+ string activeApp = SystemState.ActiveApplication;
+
+ //use file exists to make sure its a file and not a dir that
+ //passed through the filter
+ if (File.Exists(e.FullPath))
+ {
+ ThreadPool.QueueUserWorkItem(MediaCapturedCallback,
+ new MediaCapturedEventArgs(Path.GetDirectoryName(e.FullPath),
+ e.Name, activeApp));
+ }
+ }
+
+ private void MediaCapturedCallback(object state)
+ {
+ MediaCapturedEventArgs mediaCapturedEventArgs = (MediaCapturedEventArgs)state;
+
+ int maxRetries = 200;
+ int retryCount = 0;
+ int delayMS = 50;
+ int maxSingleDelayMS = 5000;
+ bool successfullyOpened = false;
+ while (!successfullyOpened && retryCount < maxRetries)
+ {
+ try
+ {
+ if (File.Exists(mediaCapturedEventArgs.FullPath))
+ {
+ //see if we can open the file (OnFileCreated is called before the file is fully written)
+ Stream s = File.Open(mediaCapturedEventArgs.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
+ s.Close();
+ successfullyOpened = true;
+ }
+ else
+ {
+ throw new FileNotFoundException(mediaCapturedEventArgs.FullPath);
+ }
+ }
+ catch (IOException ioe)
+ {
+ Debug.WriteLine(ioe.Message);
+ int delay = Math.Min(delayMS * (retryCount + 1), maxSingleDelayMS);
+ Thread.Sleep(delay);
+ retryCount++;
+ }
+ }
+
+ Debug.WriteLine(string.Format("SuccessFullyOpened: {2} RetryCount: {1} MaxRetries: {0}",
+ maxRetries, retryCount, successfullyOpened));
+
+ if (successfullyOpened)
+ {
+ OnMediaCapturedEvent(this, mediaCapturedEventArgs);
+ }
+ }
+
+ protected virtual void OnMediaCapturedEvent(object sender, MediaCapturedEventArgs mcea)
+ {
+ if (MediaCaptured != null)
+ {
+ MediaCaptured(sender, mcea);
+ }
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ public class MediaCapturedEventArgs : EventArgs
+ {
+ private string _directory;
+ private string _filename;
+ private string _activeApp;
+ private MediaType _mediaType;
+
+ public MediaCapturedEventArgs(string directory, string filename, string activeAppAtTimeOfCapture)
+ {
+ _directory = directory;
+ _filename = filename;
+ _activeApp = activeAppAtTimeOfCapture;
+ _mediaType = GetMediaType(filename);
+ }
+
+ public string ActiveApplication { get { return _activeApp; } }
+ public string FullPath { get { return Path.Combine(_directory, _filename); } }
+ public string Directory { get { return _directory; } }
+ public string Filename { get { return _filename; } }
+ public MediaType MediaType { get { return _mediaType; } }
+
+ protected virtual MediaType GetMediaType(string filename)
+ {
+ string ext = Path.GetExtension(filename);
+ switch (ext)
+ {
+ case ".jpg":
+ case ".png":
+ case ".gif":
+ return MediaType.Photo;
+ case ".3gp":
+ case ".mp4":
+ case ".qt":
+ case ".mpg":
+ case ".avi":
+ return MediaType.Video;
+ default:
+ return MediaType.Unknown;
+ }
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ public enum MediaType
+ {
+ Photo,
+ Video,
+ Unknown
+ }
+}
Deleted: Trunk/Source/Roam/Media/CameraMediaSniffer.cs
===================================================================
--- Trunk/Source/Roam/Media/CameraMediaSniffer.cs 2007-12-07 06:31:14 UTC (rev 108)
+++ Trunk/Source/Roam/Media/CameraMediaSniffer.cs 2007-12-07 06:40:03 UTC (rev 109)
@@ -1,250 +0,0 @@
-#region Copyright & License
-//
-// Copyright (c) 2005 - 2007 The Regents of the University of Washington, Intel
-// Research Seattle, and the Roam project. All rights reserved.
-//
-// This software is open-source under the BSD license. You may obtain a copy
-// of this license at
-//
-// http://roam.sourceforge.net/license.txt
-//
-// Alternatively, please see "license.txt" which should be included in
-// this source code distribution.
-//
-#endregion Copyright & License
-using System;
-using System.Collections.Generic;
-using System.Text;
-using OpenNETCF.IO;
-using System.IO;
-using System.Threading;
-using Microsoft.WindowsMobile.Status;
-using System.Diagnostics;
-
-namespace Roam.Media
-{
- /// <summary>
- /// jeffixme : need to update this to work dynamically when a storage card is
- /// removed/added
- /// </summary>
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public class CameraMediaSniffer : IDisposable
- {
- public event EventHandler<MediaCapturedEventArgs> MediaCaptured;
-
- private List<FileSystemWatcher> _listFileSystemWatchers = new List<FileSystemWatcher>();
-
- /// <summary>
- /// So, unfortunately, we cannot combine file extensions in our filter string.
- /// This is a limitation of the FileSystemWatcher. So, for example, a filter
- /// string of "*.mp4, *.avi" to watch for two different video file formats would
- /// not work. Therefore, our filter is set to *.* -- we can always filter
- /// after we receive a FileCreatedEvent
- /// </summary>
- private string _filter = "*.*";
-
- public CameraMediaSniffer()
- {
- string[] paths = GetMediaPathsToMonitor();
-
- for (int i = 0; i < paths.Length; i++)
- {
- //jeffixme : we should never create the Storage Card directory
- //so we should check to see if they have a Storage Card
- //i suppose we should also dynamically check if they place/remove a storage card
- if (!Directory.Exists(paths[i])) { Directory.CreateDirectory(paths[i]); }
-
- FileSystemWatcher fsw = new FileSystemWatcher(paths[i], _filter);
- fsw.Created += new FileSystemEventHandler(OnFileCreated);
- fsw.EnableRaisingEvents = true;
- fsw.NotifyFilter = NotifyFilters.FileName;
-
- FileSystemWatcher fsw2 = new FileSystemWatcher(paths[i], _filter);
- fsw2.Changed += new FileSystemEventHandler(OnFileChanged);
- fsw2.EnableRaisingEvents = true;
- fsw2.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
-
- _listFileSystemWatchers.Add(fsw);
- }
- }
-
- public virtual void OnFileChanged(object sender, FileSystemEventArgs e)
- {
- Debug.WriteLine("OnFileChanged: " + e.FullPath);
- }
-
- public virtual void Dispose()
- {
- foreach (FileSystemWatcher fsw in _listFileSystemWatchers)
- {
- fsw.Dispose();
- }
- _listFileSystemWatchers.Clear();
- }
-
- protected virtual string[] GetMediaPathsToMonitor()
- {
- //jeffixme the location of the date dir needs to change
- //when the day rollovers;
- //we can either update them each time the date changes or
- //only when the camera application is being used (check system state)
- string dateDir = DateTime.Now.ToString("MM-dd-yyyy") + " 00001";
-
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- //a previous version of this class received these paths
- //from the Registry--should I go back to that?
- string localPicturePath = @"My Documents\My Pictures\";
- string storagePicturePath = @"\Storage Card\My Documents\My Pictures\";
- string localVideoPath = @"My Documents\My Videos\";
- string storageVideoPath = @"\Storage Card\My Documents\My Videos\";
-
- string[] paths = new string[] {
- localPicturePath, storagePicturePath, localVideoPath, storageVideoPath,
- Path.Combine(localPicturePath, dateDir), Path.Combine(storagePicturePath, dateDir),
- Path.Combine(localVideoPath, dateDir), Path.Combine(storageVideoPath, dateDir)
- };
- return paths;
- }
-
- private void OnFileCreated(object sender, FileSystemEventArgs e)
- {
- Debug.WriteLine("OnFileCreated: " + e.FullPath);
- string activeApp = SystemState.ActiveApplication;
-
- //use file exists to make sure its a file and not a dir that
- //passed through the filter
- if (File.Exists(e.FullPath))
- {
- ThreadPool.QueueUserWorkItem(MediaCapturedCallback,
- new MediaCapturedEventArgs(Path.GetDirectoryName(e.FullPath),
- e.Name, activeApp));
- }
- }
-
- private void MediaCapturedCallback(object state)
- {
- MediaCapturedEventArgs mediaCapturedEventArgs = (MediaCapturedEventArgs)state;
-
- int maxRetries = 200;
- int retryCount = 0;
- int delayMS = 50;
- int maxSingleDelayMS = 5000;
- bool successfullyOpened = false;
- while (!successfullyOpened && retryCount < maxRetries)
- {
- try
- {
- if (File.Exists(mediaCapturedEventArgs.FullPath))
- {
- //see if we can open the file (OnFileCreated is called before the file is fully written)
- Stream s = File.Open(mediaCapturedEventArgs.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
- s.Close();
- successfullyOpened = true;
- }
- else
- {
- throw new FileNotFoundException(mediaCapturedEventArgs.FullPath);
- }
- }
- catch (IOException ioe)
- {
- Debug.WriteLine(ioe.Message);
- int delay = Math.Min(delayMS * (retryCount + 1), maxSingleDelayMS);
- Thread.Sleep(delay);
- retryCount++;
- }
- }
-
- Debug.WriteLine(string.Format("SuccessFullyOpened: {2} RetryCount: {1} MaxRetries: {0}",
- maxRetries, retryCount, successfullyOpened));
-
- if (successfullyOpened)
- {
- OnMediaCapturedEvent(this, mediaCapturedEventArgs);
- }
- }
-
- protected virtual void OnMediaCapturedEvent(object sender, MediaCapturedEventArgs mcea)
- {
- if (MediaCaptured != null)
- {
- MediaCaptured(sender, mcea);
- }
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public class MediaCapturedEventArgs : EventArgs
- {
- private string _directory;
- private string _filename;
- private string _activeApp;
- private MediaType _mediaType;
-
- public MediaCapturedEventArgs(string directory, string filename, string activeAppAtTimeOfCapture)
- {
- _directory = directory;
- _filename = filename;
- _activeApp = activeAppAtTimeOfCapture;
- _mediaType = GetMediaType(filename);
- }
-
- public string ActiveApplication { get { return _activeApp; } }
- public string FullPath { get { return Path.Combine(_directory, _filename); } }
- public string Directory { get { return _directory; } }
- public string Filename { get { return _filename; } }
- public MediaType MediaType { get { return _mediaType; } }
-
- protected virtual MediaType GetMediaType(string filename)
- {
- string ext = Path.GetExtension(filename);
- switch (ext)
- {
- case ".jpg":
- case ".png":
- case ".gif":
- return MediaType.Photo;
- case ".3gp":
- case ".mp4":
- case ".qt":
- case ".mpg":
- case ".avi":
- return MediaType.Video;
- default:
- return MediaType.Unknown;
- }
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public enum MediaType
- {
- Photo,
- Video,
- Unknown
- }
-}
Modified: Trunk/Source/Roam.Test/UI/Controls/CameraMediaSnifferTest.cs
===================================================================
--- Trunk/Source/Roam.Test/UI/Controls/CameraMediaSnifferTest.cs 2007-12-07 06:31:14 UTC (rev 108)
+++ Trunk/Source/Roam.Test/UI/Controls/CameraMediaSnifferTest.cs 2007-12-07 06:40:03 UTC (rev 109)
@@ -38,7 +38,7 @@
/// <author>Jon Froehlich</author>
public partial class CameraMediaSnifferTest : Form
{
- private CameraMediaSniffer _cameraMediaSniffer = new CameraMediaSniffer();
+ private CameraMediaCapturedSniffer _cameraMediaSniffer = new CameraMediaCapturedSniffer();
public CameraMediaSnifferTest()
{
InitializeComponent();
Modified: Trunk/Source/Roam.suo
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|