Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        public static Boolean Save()
        {
            if (_fileManager == null)
            {
                throw new InvalidOperationException("Progress class not initialized");
            }

            // Get the storage device for the player
            try
            {
                IStorageDevice storage = _fileManager.GetStorageDevice(FileLocationContainer.Player);

                // Wait until storage container is ready and save the file
                if (SpinWait.SpinUntil(() => { Thread.MemoryBarrier(); return(storage.IsReady); }, Progress.FileOperationTimeout))
                {
                    storage.Save(".", String.Format(DefaultFileName, _current.SerialNumber), Save);
                    return(true);
                }
            }
            catch (Exception)
            {
            }

            return(false);
        }
        /// <summary>
        ///
        /// </summary>
        public static Boolean Save()
        {
            if (_fileManager == null)
            {
                throw new InvalidOperationException("Progress class not initialized");
            }

#if SILVERLIGHT
            // Get the storage device for the player
            IStorageDevice storage = _fileManager.GetStorageDevice(FileLocationContainer.Isolated);

            Boolean timeout = false;
            Timer   timer   = new Timer((a) => timeout = true, null, PlayerProgress.FileOperationTimeout, System.Threading.Timeout.Infinite);

            while (!storage.IsReady && !timeout)
            {
                Thread.SpinWait(1000); Thread.MemoryBarrier();
            }

            if (timeout)
            {
                return(false);
            }

            storage.Save(".", String.Format(DefaultFileName, _current.SerialNumber), Save);
            return(true);
#else
            try
            {
                // Get the storage device for the player
                IStorageDevice storage = _fileManager.GetStorageDevice(FileLocationContainer.Player);

                // Wait until storage container is ready and save the file
                if (SpinWait.SpinUntil(() => { Thread.MemoryBarrier(); return(storage.IsReady); }, PlayerProgress.FileOperationTimeout))
                {
                    storage.Save(".", String.Format(DefaultFileName, _current.SerialNumber), Save);
                    return(true);
                }
            }
            catch (Exception)
            {
            }

            return(false);
#endif
        }
        /// <summary>
        ///
        /// </summary>
        public static Boolean Save()
        {
            if (_fileManager == null)
            {
                throw new InvalidOperationException("Settings class not initialized");
            }

            // Get the storage device for the player
            IStorageDevice storage = _fileManager.GetStorageDevice(FileLocationContainer.Player);

            // Wait until storage container is ready and save the file
            if (SpinWait.SpinUntil(() => { Thread.MemoryBarrier(); return(storage.IsReady); }, Settings.FileOperationTimeout))
            {
                storage.Save(".", Settings.DefaultFileName, Save);
                return(true);
            }

            return(false);
        }
 /// <summary>
 /// Save a serializable object in the user's local storage
 /// </summary>
 /// <typeparam name="T">Object type</typeparam>
 /// <param name="containerName">Folder in the user's storage. If the folder doesn't exist, it's created</param>
 /// <param name="fileName">The file's name</param>
 /// <param name="obj">Serializable object</param>
 public virtual void Save <T>(string containerName, string fileName, T obj)
 {
     _storageDevice.Save <T>(containerName, fileName, obj);
 }