Пример #1
0
        /// <summary>
        /// Deletes a file.
        /// </summary>
        /// <param name="containerName">Used to match the ISaveDevice interface; ignored by the implementation.</param>
        /// <param name="fileName">The file to delete.</param>
        public void Delete(String containerName, String fileName, FileLocationContainer container)
        {
            if (container.HasFlag(FileLocationContainer.SavedGames) || container.HasFlag(FileLocationContainer.Title))
            {
                throw new InvalidOperationException("Can not search in other containers than IsolatedStorage");
            }

            using (IsolatedStorageFile storage = GetIsolatedStorage(container))
            {
                #if SILVERLIGHT
                while (!this.IsReady || this.IsBusy)
                {
                    Thread.SpinWait(1000);
                }
                Thread.MemoryBarrier();
#else
                SpinWait.SpinUntil(() => { System.Threading.Thread.MemoryBarrier(); return(this.IsReady && !this.IsBusy); });
#endif

                if (FileExists(containerName, fileName, container))
                {
                    storage.DeleteFile(String.Join("/", containerName, fileName));
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Gets IStorageDevice
        /// </summary>
        /// <param name="container"></param>
        /// <returns></returns>
        public IStorageDevice GetStorageDevice(FileLocationContainer container)
        {
            switch (container)
            {
            case FileLocationContainer.Isolated:
            case FileLocationContainer.IsolatedMachine:
            case FileLocationContainer.IsolatedUser:
                return(_isolatedDevice);

            case FileLocationContainer.Shared:
#if SILVERLIGHT
                throw new NotSupportedException();
#else
                return(_sharedDevice);
#endif
            case FileLocationContainer.Player:
#if SILVERLIGHT
                throw new NotSupportedException();
#else
                return(_playerDevice);
#endif
            case FileLocationContainer.Title:
                return(_titleDevice);
            }

            throw new InvalidOperationException("No such container");
        }
Пример #3
0
 public void Reset()
 {
     Container = null;
     File      = null;
     Pattern   = null;
     Action    = null;
     UserState = null;
     Location  = 0;
 }
Пример #4
0
        /// <summary>
        /// Gets an array of all files available in a container.
        /// </summary>
        /// <param name="containerName">Used to match the ISaveDevice interface; ignored by the implementation.</param>
        /// <param name="pattern">A search pattern to use to find files.</param>
        /// <returns>An array of file names of the files in the container.</returns>
        public String[] GetFiles(String containerName, String pattern, FileLocationContainer container)
        {
            if (container.HasFlag(FileLocationContainer.SavedGames) || container.HasFlag(FileLocationContainer.Title))
            {
                throw new InvalidOperationException("Can not search in other containers than IsolatedStorage");
            }

            using (IsolatedStorageFile storage = GetIsolatedStorage(container))
            {
                return(storage.GetFileNames(pattern));
            }
        }
Пример #5
0
        /// <summary>
        /// Determines if a given file exists.
        /// </summary>
        /// <param name="containerName">Used to match the ISaveDevice interface; ignored by the implementation.</param>
        /// <param name="fileName">The name of the file.</param>
        /// <returns>True if the file exists, false otherwise.</returns>
        public bool FileExists(String containerName, String fileName, FileLocationContainer container)
        {
            if (container.HasFlag(FileLocationContainer.SavedGames) || container.HasFlag(FileLocationContainer.Title))
            {
                throw new InvalidOperationException("Can not search in other containers than IsolatedStorage");
            }

            using (IsolatedStorageFile storage = GetIsolatedStorage(container))
            {
                return(storage.FileExists(String.Join("/", containerName, fileName)));
            }
        }
Пример #6
0
        /// <summary>
        /// Gets IAsyncStorageDevice
        /// </summary>
        /// <param name="container"></param>
        /// <returns></returns>
        public IAsyncStorageDevice GetAsyncStorageDevice(FileLocationContainer container)
        {
            switch (container)
            {
            case FileLocationContainer.IsolatedMachine:
            case FileLocationContainer.IsolatedUser:
                return(_isolatedDevice);

            case FileLocationContainer.Shared:
                return(_sharedDevice);

            case FileLocationContainer.Player:
                return(_playerDevice);
            }

            throw new InvalidOperationException("No such container");
        }
Пример #7
0
        /// <summary>
        /// Helper method that gets isolated storage. On Windows we use GetUserStoreForDomain, but on the other
        /// platforms we use GetUserStoreForApplication.
        /// </summary>
        /// <returns>The opened IsolatedStorageFile.</returns>
        private IsolatedStorageFile GetIsolatedStorage(FileLocationContainer container)
        {
#if WINDOWS
            switch (container)
            {
            case FileLocationContainer.Public:
            case FileLocationContainer.IsolatedMachine:
                return(IsolatedStorageFile.GetMachineStoreForDomain());

            case FileLocationContainer.Private:
            case FileLocationContainer.IsolatedUser:
                return(IsolatedStorageFile.GetUserStoreForDomain());

            default:
                return(GetIsolatedStorage(FileLocationContainer.IsolatedMachine));
            }
#else
            return(IsolatedStorageFile.GetUserStoreForApplication());
#endif
        }
		/// <summary>
		/// Helper method that gets isolated storage. On Windows we use GetUserStoreForDomain, but on the other
		/// platforms we use GetUserStoreForApplication.
		/// </summary>
		/// <returns>The opened IsolatedStorageFile.</returns>
		private IsolatedStorageFile GetIsolatedStorage(FileLocationContainer container)
		{
#if WINDOWS
			switch (container)
			{
				case FileLocationContainer.Public:
				case FileLocationContainer.IsolatedMachine:
					return IsolatedStorageFile.GetMachineStoreForDomain();

				case FileLocationContainer.Private:
				case FileLocationContainer.IsolatedUser:
					return IsolatedStorageFile.GetUserStoreForDomain();

				default :
					return GetIsolatedStorage(FileLocationContainer.IsolatedMachine);
			}
#else
			return IsolatedStorageFile.GetUserStoreForApplication();
#endif
		}
		/// <summary>
		/// Saves a file asynchronously.
		/// </summary>
		/// <param name="containerName">The name of the container in which to save the file.</param>
		/// <param name="fileName">The file to save.</param>
		/// <param name="saveAction">The save action to perform.</param>
		public void SaveAsync(String containerName, String fileName, FileAction saveAction, FileLocationContainer container)
		{
			SaveAsync(containerName, fileName, saveAction, null, container);
		}
Пример #10
0
 /// <summary>
 /// Deletes a file asynchronously.
 /// </summary>
 /// <param name="containerName">The name of the container from which to delete the file.</param>
 /// <param name="fileName">The file to delete.</param>
 public void DeleteAsync(String containerName, String fileName, FileLocationContainer container)
 {
     DeleteAsync(containerName, fileName, null, container);
 }
Пример #11
0
		/// <summary>
		/// Gets IStorageDevice
		/// </summary>
		/// <param name="container"></param>
		/// <returns></returns>
		public IStorageDevice GetStorageDevice(FileLocationContainer container)
		{
			switch (container)
			{
                case FileLocationContainer.Isolated:
				case FileLocationContainer.IsolatedMachine:
				case FileLocationContainer.IsolatedUser:
					return _isolatedDevice;
				case FileLocationContainer.Shared:
#if SILVERLIGHT
                    throw new NotSupportedException();
#else
					return _sharedDevice;
#endif
				case FileLocationContainer.Player:
#if SILVERLIGHT
                    throw new NotSupportedException();
#else
					return _playerDevice;
#endif
                case FileLocationContainer.Title:
					return _titleDevice;
			}

			throw new InvalidOperationException("No such container");
		}
			public void Reset()
			{
				Container = null;
				File = null;
				Pattern = null;
				Action = null;
				UserState = null;
				Location = 0;
			}
		/// <summary>
		/// Gets an array of all files available in a container that match the given pattern asynchronously.
		/// </summary>
		/// <param name="containerName">The name of the container in which to search for files.</param>
		/// <param name="pattern">A search pattern to use to find files.</param>
		/// <param name="userState">A state Object used to identify the async operation.</param>
		public void GetFilesAsync(String containerName, String pattern, Object userState, FileLocationContainer container)
		{
			// increment our pending operations count
			PendingOperationsIncrement();

			// get a FileOperationState and fill it in
			FileOperationState state = GetFileOperationState();
			state.Container = containerName;
			state.Pattern = pattern;
			state.UserState = userState;
			state.Location = container;

			// queue up the work item
			ThreadPool.QueueUserWorkItem(DoGetFilesAsync, state);
		}
		/// <summary>
		/// Gets an array of all files available in a container asynchronously.
		/// </summary>
		/// <param name="containerName">The name of the container in which to search for files.</param>
		/// <param name="userState">A state Object used to identify the async operation.</param>
		public void GetFilesAsync(String containerName, Object userState, FileLocationContainer container)
		{
			GetFilesAsync(containerName, "*", userState, container);
		}
		/// <summary>
		/// Determines if a given file exists asynchronously.
		/// </summary>
		/// <param name="containerName">The name of the container in which to check for the file.</param>
		/// <param name="fileName">The name of the file.</param>
		public void FileExistsAsync(String containerName, String fileName, FileLocationContainer container)
		{
			FileExistsAsync(containerName, fileName, null, container);
		}
Пример #16
0
        /// <summary>
        /// Gets an array of all files available in a container that match the given pattern asynchronously.
        /// </summary>
        /// <param name="containerName">The name of the container in which to search for files.</param>
        /// <param name="pattern">A search pattern to use to find files.</param>
        /// <param name="userState">A state Object used to identify the async operation.</param>
        public void GetFilesAsync(String containerName, String pattern, Object userState, FileLocationContainer container)
        {
            // increment our pending operations count
            PendingOperationsIncrement();

            // get a FileOperationState and fill it in
            FileOperationState state = GetFileOperationState();

            state.Container = containerName;
            state.Pattern   = pattern;
            state.UserState = userState;
            state.Location  = container;

            // queue up the work item
            ThreadPool.QueueUserWorkItem(DoGetFilesAsync, state);
        }
Пример #17
0
 /// <summary>
 /// Gets an array of all files available in a container that match the given pattern asynchronously.
 /// </summary>
 /// <param name="containerName">The name of the container in which to search for files.</param>
 /// <param name="pattern">A search pattern to use to find files.</param>
 public void GetFilesAsync(String containerName, String pattern, FileLocationContainer container)
 {
     GetFilesAsync(containerName, pattern, null, container);
 }
Пример #18
0
 /// <summary>
 /// Gets an array of all files available in a container asynchronously.
 /// </summary>
 /// <param name="containerName">The name of the container in which to search for files.</param>
 /// <param name="userState">A state Object used to identify the async operation.</param>
 public void GetFilesAsync(String containerName, Object userState, FileLocationContainer container)
 {
     GetFilesAsync(containerName, "*", userState, container);
 }
Пример #19
0
        /// <summary>
        /// Determines if a given file exists asynchronously.
        /// </summary>
        /// <param name="containerName">The name of the container in which to check for the file.</param>
        /// <param name="fileName">The name of the file.</param>
        /// <param name="userState">A state Object used to identify the async operation.</param>
        public void FileExistsAsync(String containerName, String fileName, Object userState, FileLocationContainer container)
        {
            // increment our pending operations count
            PendingOperationsIncrement();

            // get a FileOperationState and fill it in
            FileOperationState state = GetFileOperationState();

            state.Container = containerName;
            state.File      = String.Join("/", containerName, fileName);
            state.UserState = userState;
            state.Location  = container;

            // queue up the work item
            ThreadPool.QueueUserWorkItem(DoFileExistsAsync, state);
        }
Пример #20
0
 /// <summary>
 /// Determines if a given file exists asynchronously.
 /// </summary>
 /// <param name="containerName">The name of the container in which to check for the file.</param>
 /// <param name="fileName">The name of the file.</param>
 public void FileExistsAsync(String containerName, String fileName, FileLocationContainer container)
 {
     FileExistsAsync(containerName, fileName, null, container);
 }
		/// <summary>
		/// Loads a file asynchronously.
		/// </summary>
		/// <param name="containerName">The name of the container from which to load the file.</param>
		/// <param name="fileName">The file to load.</param>
		/// <param name="loadAction">The load action to perform.</param>
		public void LoadAsync(String containerName, String fileName, FileAction loadAction, FileLocationContainer container)
		{
			LoadAsync(containerName, fileName, loadAction, null, container);
		}
		/// <summary>
		/// Deletes a file asynchronously.
		/// </summary>
		/// <param name="containerName">The name of the container from which to delete the file.</param>
		/// <param name="fileName">The file to delete.</param>
		public void DeleteAsync(String containerName, String fileName, FileLocationContainer container)
		{
			DeleteAsync(containerName, fileName, null, container);
		}
Пример #23
0
 /// <summary>
 /// Saves a file asynchronously.
 /// </summary>
 /// <param name="containerName">The name of the container in which to save the file.</param>
 /// <param name="fileName">The file to save.</param>
 /// <param name="saveAction">The save action to perform.</param>
 public void SaveAsync(String containerName, String fileName, FileAction saveAction, FileLocationContainer container)
 {
     SaveAsync(containerName, fileName, saveAction, null, container);
 }
		/// <summary>
		/// Determines if a given file exists asynchronously.
		/// </summary>
		/// <param name="containerName">The name of the container in which to check for the file.</param>
		/// <param name="fileName">The name of the file.</param>
		/// <param name="userState">A state Object used to identify the async operation.</param>
		public void FileExistsAsync(String containerName, String fileName, Object userState, FileLocationContainer container)
		{
			// increment our pending operations count
			PendingOperationsIncrement();

			// get a FileOperationState and fill it in
			FileOperationState state = GetFileOperationState();
			state.Container = containerName;
			state.File = String.Join("/", containerName, fileName);
			state.UserState = userState;
			state.Location = container;

			// queue up the work item
			ThreadPool.QueueUserWorkItem(DoFileExistsAsync, state);
		}
		/// <summary>
		/// Loads a file.
		/// </summary>
		/// <param name="containerName">Used to match the ISaveDevice interface; ignored by the implementation.</param>
		/// <param name="fileName">The file to load.</param>
		/// <param name="loadAction">The load action to perform.</param>
		public void Load(String containerName, String fileName, FileAction loadAction, FileLocationContainer container)
		{
			if (container.HasFlag(FileLocationContainer.SavedGames) || container.HasFlag(FileLocationContainer.Title))
				throw new InvalidOperationException("Can not search in other containers than IsolatedStorage");

			using (IsolatedStorageFile storage = GetIsolatedStorage(container))
			{

				SpinWait.SpinUntil(() => { System.Threading.Thread.MemoryBarrier(); return this.IsReady && !this.IsBusy; });   

				using (var stream = storage.OpenFile(String.Join("/", containerName, fileName), FileMode.Open))
				{
					loadAction(stream);
				}
			}
		}
		/// <summary>
		/// Gets an array of all files available in a container that match the given pattern asynchronously.
		/// </summary>
		/// <param name="containerName">The name of the container in which to search for files.</param>
		/// <param name="pattern">A search pattern to use to find files.</param>
		public void GetFilesAsync(String containerName, String pattern, FileLocationContainer container)
		{
			GetFilesAsync(containerName, pattern, null, container);
		}
Пример #27
0
        /// <summary>
        /// Loads a file.
        /// </summary>
        /// <param name="containerName">Used to match the ISaveDevice interface; ignored by the implementation.</param>
        /// <param name="fileName">The file to load.</param>
        /// <param name="loadAction">The load action to perform.</param>
        public void Load(String containerName, String fileName, FileAction loadAction, FileLocationContainer container)
        {
            if (container.HasFlag(FileLocationContainer.SavedGames) || container.HasFlag(FileLocationContainer.Title))
            {
                throw new InvalidOperationException("Can not search in other containers than IsolatedStorage");
            }

            using (IsolatedStorageFile storage = GetIsolatedStorage(container))
            {
                SpinWait.SpinUntil(() => { System.Threading.Thread.MemoryBarrier(); return(this.IsReady && !this.IsBusy); });

                using (var stream = storage.OpenFile(String.Join("/", containerName, fileName), FileMode.Open))
                {
                    loadAction(stream);
                }
            }
        }
		/// <summary>
		/// Deletes a file.
		/// </summary>
		/// <param name="containerName">Used to match the ISaveDevice interface; ignored by the implementation.</param>
		/// <param name="fileName">The file to delete.</param>
		public void Delete(String containerName, String fileName, FileLocationContainer container)
		{
			if (container.HasFlag(FileLocationContainer.SavedGames) || container.HasFlag(FileLocationContainer.Title))
				throw new InvalidOperationException("Can not search in other containers than IsolatedStorage");

			using (IsolatedStorageFile storage = GetIsolatedStorage(container))
			{
                #if SILVERLIGHT
                while (!this.IsReady || this.IsBusy)
                    Thread.SpinWait(1000); Thread.MemoryBarrier();
#else
				SpinWait.SpinUntil(() => { System.Threading.Thread.MemoryBarrier(); return this.IsReady && !this.IsBusy; });   
#endif

				if (FileExists(containerName, fileName, container))
				{
					storage.DeleteFile(String.Join("/", containerName, fileName));
				}
			}
		}
		/// <summary>
		/// Determines if a given file exists.
		/// </summary>
		/// <param name="containerName">Used to match the ISaveDevice interface; ignored by the implementation.</param>
		/// <param name="fileName">The name of the file.</param>
		/// <returns>True if the file exists, false otherwise.</returns>
		public bool FileExists(String containerName, String fileName, FileLocationContainer container)
		{
			if (container.HasFlag(FileLocationContainer.SavedGames) || container.HasFlag(FileLocationContainer.Title))
				throw new InvalidOperationException("Can not search in other containers than IsolatedStorage");
		
			using (IsolatedStorageFile storage = GetIsolatedStorage(container))
			{
				return storage.FileExists(String.Join("/", containerName, fileName));
			}
		}
Пример #30
0
		/// <summary>
		/// Gets IStorageDevice
		/// </summary>
		/// <param name="container"></param>
		/// <returns></returns>
		public IStorageDevice GetStorageDevice(FileLocationContainer container)
		{
			switch (container)
			{
				case FileLocationContainer.IsolatedMachine:
				case FileLocationContainer.IsolatedUser:
					return _isolatedDevice;
				case FileLocationContainer.Shared:
					return _sharedDevice;
				case FileLocationContainer.Player:
					return _playerDevice;
				case FileLocationContainer.Title:
					return _titleDevice;
			}

			throw new InvalidOperationException("No such container");
		}
		/// <summary>
		/// Gets an array of all files available in a container.
		/// </summary>
		/// <param name="containerName">Used to match the ISaveDevice interface; ignored by the implementation.</param>
		/// <param name="pattern">A search pattern to use to find files.</param>
		/// <returns>An array of file names of the files in the container.</returns>
		public String[] GetFiles(String containerName, String pattern, FileLocationContainer container)
		{
			if (container.HasFlag(FileLocationContainer.SavedGames) || container.HasFlag(FileLocationContainer.Title))
				throw new InvalidOperationException("Can not search in other containers than IsolatedStorage");
		
			using (IsolatedStorageFile storage = GetIsolatedStorage(container))
			{
				return storage.GetFileNames(pattern);
			}
		}
Пример #32
0
		/// <summary>
		/// Gets IAsyncStorageDevice
		/// </summary>
		/// <param name="container"></param>
		/// <returns></returns>
		public IAsyncStorageDevice GetAsyncStorageDevice(FileLocationContainer container)
		{
			switch (container)
			{
				case FileLocationContainer.IsolatedMachine:
				case FileLocationContainer.IsolatedUser:
					return _isolatedDevice;

#if !SILVERLIGHT
				case FileLocationContainer.Shared:
					return _sharedDevice;
				case FileLocationContainer.Player:
					return _playerDevice;
#endif
			}

			throw new InvalidOperationException("No such container");
		}
Пример #33
0
 /// <summary>
 /// Loads a file asynchronously.
 /// </summary>
 /// <param name="containerName">The name of the container from which to load the file.</param>
 /// <param name="fileName">The file to load.</param>
 /// <param name="loadAction">The load action to perform.</param>
 public void LoadAsync(String containerName, String fileName, FileAction loadAction, FileLocationContainer container)
 {
     LoadAsync(containerName, fileName, loadAction, null, container);
 }