public void OpenWAV() { OutputLogs logs = OutputLogs.Instance(); OpenFileDialogService.Filter = "Wav Files (.wav)|*.wav|All Files (*.*)|*.*"; OpenFileDialogService.FilterIndex = 1; OpenFileDialogService.Title = "Open target audio"; if (OpenFileDialogService.ShowDialog()) { IFileInfo file = OpenFileDialogService.Files.First(); WavReader reader = null; try { reader = new WavReader(File.Open(file.GetFullName(), FileMode.Open, FileAccess.Read, FileShare.None)); Audio = reader.ReadAudio(); AudioFileName = file.Name; string msg = string.Concat("Succesfully loaded file - ", file.GetFullName()); logs.AddLog(new Message(MessageType.Info, msg, "WavReader")); } catch (ApplicationException ex) { logs.AddLog(new Message(MessageType.Error, ex.Message, ex.Source)); } finally { if (reader != null) { reader.Dispose(); } } } }
public void Code() { OutputLogs logs = OutputLogs.Instance(); switch (action) { case NavigationCodes.Extract: OutputLogs.Instance().AddLog(new Message(MessageType.Info, "Extracting started...", method.ToString())); try { var bytes = method.Extract(cover); if (bytes == null) { throw new ApplicationException("No embedded message found."); } Message = Encoding.ASCII.GetString(bytes); string goodMsg = "Embedded message successfuly extracted."; logs.AddLog(new Message(MessageType.Info, goodMsg, method.ToString())); } catch (ApplicationException ex) { logs.AddLog(new Message(MessageType.Error, ex.Message, method.ToString())); } break; case NavigationCodes.Embed: logs.AddLog(new Message(MessageType.Info, "Embedding started...", method.ToString())); try { int[] signal = null; if (GetStatistics) { signal = (int[])cover.GetSignal().Clone(); } var data = Encoding.ASCII.GetBytes(Message); method.Embed(cover, data); logs.AddLog(new Message(MessageType.Info, "Message successfuly embeded.", method.ToString())); SaveFileDialogService.DefaultExt = "wav"; SaveFileDialogService.DefaultFileName = "StegoAudio"; if (SaveFileDialogService.ShowDialog()) { using (var stream = new WavWriter(SaveFileDialogService.OpenFile())) stream.WriteWavDefault(cover); logs.AddLog(new Message(MessageType.Info, "File was succesfuly saved.", "WavWriter")); } if (GetStatistics) { var stegosignal = cover.GetSignal(); var service = DocumentManagerService; var doc = service.CreateDocument("Statistics", new StatisticsViewModel(signal, stegosignal)); doc.Show(); } } catch (ApplicationException ex) { logs.AddLog(new Message(MessageType.Error, ex.Message, method.ToString())); } break; default: logs.AddLog(new Message(MessageType.Error, "Internal error", method.ToString())); break; } }