Esempio n. 1
0
        public static Stream GetFileStream(string file)
        {
            Stream stream = null;

            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!isf.FileExists(file))
                {
                    using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream(file, FileMode.Open, isf))
                    {
                        fs.CopyTo(stream, (int)fs.Length);
                    }
                }
            }

            return stream;
        }
        /// <summary>
        /// Resaves video clip from temporary directory to persistent 
        /// </summary>
        private VideoResult SaveVideoClip()
        {
            try
            {
                using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (string.IsNullOrEmpty(filePath) || (!isoFile.FileExists(filePath)))
                    {
                        return new VideoResult(TaskResult.Cancel);
                    }

                    string fileName = String.Format(FileNameFormat, Guid.NewGuid().ToString());
                    string newPath = Path.Combine("/" + LocalFolderName + "/", fileName);
                    isoFile.CopyFile(filePath, newPath);
                    isoFile.DeleteFile(filePath);

                    memoryStream = new MemoryStream();
                    using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(newPath, FileMode.Open, isoFile))
                    {
                        fileStream.CopyTo(memoryStream);
                    }

                    VideoResult result = new VideoResult(TaskResult.OK);
                    result.VideoFileName = newPath;
                    result.VideoFile = this.memoryStream;
                    result.VideoFile.Seek(0, SeekOrigin.Begin);
                    return result;
                }

            }
            catch (Exception)
            {
                return new VideoResult(TaskResult.None);
            }
        }
Esempio n. 3
0
		private static Stream GetReport() {
			var stream = new MemoryStream();
			try {
				var writer = new StreamWriter(stream, Encoding.UTF8);
				writer.WriteLine(reportOriginIdentity.ToString("B"));
				writer.WriteLine(Util.LibraryVersion);
				writer.WriteLine(".NET Framework {0}", Environment.Version);

				foreach (var observation in observations) {
					observation.Flush();
					writer.WriteLine("====================================");
					writer.WriteLine(observation.FileName);
					try {
						using (var fileStream = new IsolatedStorageFileStream(observation.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, file)) {
							writer.Flush();
							fileStream.CopyTo(writer.BaseStream);
						}
					} catch (FileNotFoundException) {
						writer.WriteLine("(missing)");
					}
				}

				// Not all event counters may have even loaded in this app instance.
				// We flush the ones in memory, and then read all of them off disk.
				foreach (var counter in events.Values) {
					counter.Flush();
				}

				foreach (string eventFile in file.GetFileNames("event-*.txt")) {
					writer.WriteLine("====================================");
					writer.WriteLine(eventFile);
					using (var fileStream = new IsolatedStorageFileStream(eventFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, file)) {
						writer.Flush();
						fileStream.CopyTo(writer.BaseStream);
					}
				}

				// Make sure the stream is positioned at the beginning.
				writer.Flush();
				stream.Position = 0;
				return stream;
			} catch {
				stream.Dispose();
				throw;
			}
		}
        } // StartVideoRecording()

        private void StopVideoRecording()
        {
            try
            {
                // Stop recording.
                if (captureSource.VideoCaptureDevice != null
                && captureSource.State == CaptureState.Started)
                {
                    captureSource.Stop();

                    // Disconnect fileSink.
                    fileSink.CaptureSource = null;
                    fileSink.IsolatedStorageFileName = null;
                    
                    // Set the button states and the message.
                    UpdateUI(ButtonState.Stopped, "Recording stopped...");

                    viewfinderRectangle.Fill = null;

                    // Create the file stream 
                    isoVideoFile = new IsolatedStorageFileStream(fileName,
                                            FileMode.Open, FileAccess.Read,
                                            IsolatedStorageFile.GetUserStoreForApplication());

                    MemoryStream videoStream = new MemoryStream();
                    using (isoVideoFile)
                    {
                        isoVideoFile.CopyTo(videoStream);
                    }

                    PurposeColor.screens.AddEventsSituationsOrThoughts.ReceiveVideoFromWindows(videoStream, isoVideoFile.Name);
                    
                    isoVideoFile.Flush();
                    isoVideoFile.Dispose();
                    isoVideoFile = null;
                    //videoStream = null;

                    DisposeVideoRecorder();

                }
            }
            // If stop fails, display an error.
            catch (Exception e)
            {
                this.Dispatcher.BeginInvoke(delegate()
                {
                    txtDebug.Text = "ERROR: " + e.Message.ToString();
                });
            }
        }//StopVideoRecording()
        /// <summary>
        /// Loads the State from Isolated Storage (in user store for domain)
        /// </summary>
        /// <remarks>
        /// Sets <see cref="IsLoaded" /> after it's finished to prevent a race condition with saving the state to the MemoryStream.
        /// </remarks>
        public virtual void Load()
        {
            // Don't save or load state in design mode
            if (DesignerProperties.GetIsInDesignMode(this.ribbon))
            {
                Debug.WriteLine("State not loaded from isolated storage. Because we are in design mode.");
                this.IsLoaded = true;
                return;
            }

            if (this.ribbon.AutomaticStateManagement == false)
            {
                this.IsLoaded = true;
                Debug.WriteLine("State not loaded from isolated storage. Because automatic state management is disabled.");
                return;
            }

            try
            {
                var storage = GetIsolatedStorageFile();
                if (IsolatedStorageFileExists(storage, this.IsolatedStorageFileName))
                {
                    using (var stream = new IsolatedStorageFileStream(this.IsolatedStorageFileName, FileMode.Open, FileAccess.Read, storage))
                    {
                        this.Load(stream);

                        // Copy loaded state to MemoryStream for temporary storage.
                        // Temporary storage is used for style changes etc. so we can apply the current state again.
                        stream.Position = 0;
                        this.memoryStream.Position = 0;
                        stream.CopyTo(this.memoryStream);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Error while trying to load Ribbon state. Error: {ex}");
            }

            this.IsLoaded = true;
        }
Esempio n. 6
0
        /// <summary>
        /// Loads an audio buffer from isolated storage.
        /// </summary>
        public void LoadAudioBuffer(String fileName)
        {
            // Set the stream back to zero in case there is already something in it
            stream.SetLength(0);

            // Retrieve the named audio file from the storage.
            IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();

            try
            {
                using (var isoFileStream = new IsolatedStorageFileStream(
                    fileName,
                    FileMode.Open,
                    myStore))
                {
                    isoFileStream.CopyTo(stream);
                    stream.Flush();
                }
            }
            catch
            {
                MessageBox.Show("Error while trying to load audio buffer.");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Read Isolated Storage file to memory
        /// </summary>
        /// <param name="fileName">filename</param>
        /// <returns>MemoryStream</returns>
        private static MemoryStream ReadFromIsolatedStorage(string fileName)
        {
            MemoryStream stream = new MemoryStream();

            IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();

            if (isoStore.FileExists(fileName))
            {
                Console.WriteLine(fileName + " file read success.");
                using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(fileName, FileMode.Open, isoStore))
                {
                    isoStream.CopyTo(stream);
                }
            }
            else
            {
                throw new Exception("Could not read from file");
            }

            return stream;
        }