/// <summary> /// Load the settings from a file with no UI. /// </summary> /// <param name="fileName">filename to use</param> /// <param name="loadedSettings">settings that were loaded</param> /// <returns>true if settings were loaded, false otherwise</returns> public static bool TryLoadSettingsNoUi(string fileName, out OATeSettings loadedSettings) { loadedSettings = null; if (!File.Exists(fileName)) { return(false); } using (var streamReader = new StreamReader(fileName)) { try { var loadedObjects = XamlServices.Load(streamReader.BaseStream); loadedSettings = loadedObjects as OATeSettings; if (loadedSettings == null) { return(false); } } catch (XmlException) { return(false); } catch (XamlParseException) { return(false); } catch (XamlObjectWriterException) { return(false); } } return(true); }
/// <summary> /// Use the common dialog to load settings from a file. /// </summary> /// <param name="fileName">File to start with.</param> /// <param name="loadedSettings">The settings that were loaded</param> /// <returns>true if we were able to load the settings, false otherwise</returns> public static bool TryLoadSettingsWithOpenFileDialog(string fileName, out OATeSettings loadedSettings) { loadedSettings = null; var openFileDialog = new OpenFileDialog { FileName = Path.GetFileName(fileName), InitialDirectory = Path.GetDirectoryName(fileName), DefaultExt = "xml", Filter = Properties.Resources.FileDialogFilter }; if (openFileDialog.ShowDialog() == false) { // User canceled the dialog. Quietly return. return(false); } fileName = openFileDialog.FileName; if (!TryLoadSettingsNoUi(fileName, out loadedSettings)) { // Couldn't load the file. Show an error message. var errorMessageText = string.Format(CultureInfo.CurrentCulture, Properties.Resources.OpenErrorMessage, fileName); MessageBox.Show( errorMessageText, Properties.Resources.ErrorMessageCaption, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } return(true); }
/// <summary> /// Use the common dialog to save the settings to a file. /// </summary> /// <param name="fileName">settings file name to start with</param> /// <param name="settings">the settings to save</param> public static void SaveSettings(string fileName, OATeSettings settings) { var saveFileDialog = new SaveFileDialog { FileName = Path.GetFileName(fileName), InitialDirectory = Path.GetDirectoryName(fileName), DefaultExt = "xml", Filter = Properties.Resources.FileDialogFilter }; if (saveFileDialog.ShowDialog() == false) { // User canceled the dialog. Quietly return. return; } fileName = saveFileDialog.FileName; var settingsXmlString = XamlServices.Save(settings); try { using (var streamWriter = new StreamWriter(fileName)) { streamWriter.Write(settingsXmlString); } } catch (Exception e) { if (e is IOException || e is UnauthorizedAccessException) { // Couldn't save for a reason we expect. Show an error message. var errorMessageText = string.Format(CultureInfo.CurrentCulture, Properties.Resources.SaveErrorMessage, fileName); MessageBox.Show( errorMessageText, Properties.Resources.ErrorMessageCaption, MessageBoxButton.OK, MessageBoxImage.Error); } else { throw; } } }
private void CreateOATeSettings() { _Console = new Console(); _Console.Show(); _ListOATeSettings = new List <OATeSettings>(); foreach (var item in Directory.EnumerateDirectories(Directory.GetCurrentDirectory())) { foreach (var settings in Directory.GetFiles(item, "OATeSettings.xml")) { OATeSettings newsett = new OATeSettings(); if (OATeSettings.TryLoadSettingsNoUi(settings, out newsett)) { _ListOATeSettings.Add(newsett); } } } if (!OATeSettings.TryLoadSettingsNoUi("OATeSettings.xml", out _OATeSettings)) { this._OATeSettings = new OATeSettings(); _OATeSettings.Barra = "Sole/spettro.png"; _OATeSettings.Puntatore = "Sole/Puntatore.png"; this._OATeSettings.MediaFiles = new System.Collections.Generic.List <OATeMedia>(); OATeMedia media1 = new OATeMedia(); media1.FromValue = 0; media1.ToValue = 0.1; media1.MediaUri = "Sole/Video/Ic_flat_2d.mpg"; _OATeSettings.MediaFiles.Add(media1); media1 = new OATeMedia(); media1.FromValue = 0.1; media1.ToValue = 0.2; media1.MediaUri = "Sole/Video/latest_1024_0094.mp4"; _OATeSettings.MediaFiles.Add(media1); media1 = new OATeMedia(); media1.FromValue = 0.2; media1.ToValue = 0.3; media1.MediaUri = "Sole/Video/latest_1024_0131.mp4"; _OATeSettings.MediaFiles.Add(media1); media1 = new OATeMedia(); media1.FromValue = 0.3; media1.ToValue = 0.4; media1.MediaUri = "Sole/Video/latest_1024_0193.mp4"; _OATeSettings.MediaFiles.Add(media1); media1 = new OATeMedia(); media1.FromValue = 0.4; media1.ToValue = 0.5; media1.MediaUri = "Sole/Video/latest_1024_0211.mp4"; _OATeSettings.MediaFiles.Add(media1); media1 = new OATeMedia(); media1.FromValue = 0.5; media1.ToValue = 0.6; media1.MediaUri = "Sole/Video/latest_1024_0304.mp4"; _OATeSettings.MediaFiles.Add(media1); media1 = new OATeMedia(); media1.FromValue = 0.6; media1.ToValue = 0.7; media1.MediaUri = "Sole/Video/latest_1024_0335.mp4"; _OATeSettings.MediaFiles.Add(media1); media1 = new OATeMedia(); media1.FromValue = 0.8; media1.ToValue = 0.9; media1.MediaUri = "Sole/Video/latest_1024_1600.mp4"; _OATeSettings.MediaFiles.Add(media1); media1 = new OATeMedia(); media1.FromValue = 0.9; media1.ToValue = 1; media1.MediaUri = "Sole/Video/latest_1024_1700.mp4"; _OATeSettings.MediaFiles.Add(media1); OATeSettings.SaveSettings("OATeSettings.xml", _OATeSettings); } _ListOATeSettings.Add(_OATeSettings); CameraViewer = new TwoCamerasTest.MainForm(); CameraViewer.Show(); CameraViewer.Hide(); _MediaViewer = new MediaViewer(_OATeSettings); _MediaViewer.Width = SystemParameters.PrimaryScreenWidth; _MediaViewer.Height = SystemParameters.PrimaryScreenHeight - this.Height; _MediaViewer.Left = 0; _MediaViewer.Top = 0; _MediaViewer.Show(); ImageSource source = new BitmapImage(new Uri(_OATeSettings.Barra, UriKind.RelativeOrAbsolute)); border_barra.Background = new ImageBrush(source); foreach (var item in _OATeSettings.MediaFiles) { _MediaViewer.AddElement(item); } UserStateVisualizer._OATeSettings = this._OATeSettings; UserStateVisualizer.ValueReached += UserStateVisualizer_ValueReached; UserStateVisualizer.ValueReached += _MediaViewer.UserStateVisualizer_ValueReached; }
private void Window_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.C) { CameraViewer.TopMost = true; CameraViewer.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; CameraViewer.WindowState = System.Windows.Forms.FormWindowState.Maximized; CameraViewer.Show(); } if (e.Key == Key.F) { int index = ListOATeSettings.IndexOf(_OATeSettings); if ((index + 1) < ListOATeSettings.Count) { _OATeSettings = ListOATeSettings[index + 1]; } else { _OATeSettings = ListOATeSettings[0]; } //ImageSource source = new BitmapImage(new Uri(_OATeSettings.Barra, UriKind.RelativeOrAbsolute)); //border_barra.Background = new ImageBrush(source); _MediaViewer._OATeSettings = _OATeSettings; foreach (var item in _OATeSettings.MediaFiles) { _MediaViewer.AddElement(item); } UserStateVisualizer._OATeSettings = this._OATeSettings; UserStateVisualizer.StartPoint(); } //if ((e.KeyboardDevice.IsKeyDown(Key.LeftAlt) || e.KeyboardDevice.IsKeyDown(Key.RightAlt)) && e.SystemKey == Key.Escape) // Application.Current.Shutdown(0); if ((e.KeyboardDevice.IsKeyDown(Key.LeftAlt) || e.KeyboardDevice.IsKeyDown(Key.RightAlt)) && e.SystemKey == Key.L) { OATeSettings oATeSettings; if (OATeSettings.TryLoadSettingsWithOpenFileDialog("OATeSettings.xml", out oATeSettings)) { UserStateVisualizer.ValueReached -= _MediaViewer.UserStateVisualizer_ValueReached; _OATeSettings = oATeSettings; _MediaViewer.Close(); _MediaViewer = new MediaViewer(_OATeSettings); _MediaViewer.Width = SystemParameters.PrimaryScreenWidth; _MediaViewer.Height = SystemParameters.PrimaryScreenHeight - this.Height; _MediaViewer.Left = 0; _MediaViewer.Top = 0; _MediaViewer.Show(); UserStateVisualizer.ValueReached += _MediaViewer.UserStateVisualizer_ValueReached; ImageSource source = new BitmapImage(new Uri(_OATeSettings.Barra, UriKind.RelativeOrAbsolute)); border_barra.Background = new ImageBrush(source); UserStateVisualizer._OATeSettings = _OATeSettings; foreach (var item in _OATeSettings.MediaFiles) { _MediaViewer.AddElement(item); } } } }
public MediaViewer(OATeSettings oATeSettings) { InitializeComponent(); _OATeSettings = oATeSettings; }