/// <summary> /// Handles the DoWork event of the backgroundWorker control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param> public void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { DataModel.BlockAllOperation = true; try { bool runDeviceConfig = true; NetworkProfile profile = (NetworkProfile)e.Argument; if (profile == null) { // autodetect profile = NetworkProfileHelper.AutoDetectNetworkProfile(DataModel.NetworkProfileList); runDeviceConfig = false; } if (profile != null) { UseCaseProfile.Run(profile, backgroundWorker, runDeviceConfig); } e.Result = profile; } finally { DataModel.BlockAllOperation = false; } }
/// <summary> /// Setups the profiles. /// </summary> /// <returns></returns> public List <NetworkProfile> SetupProfiles() { List <NetworkProfile> list = new List <NetworkProfile>(); string file = Path.GetFullPath(@"..\..\..\ArgonUnitTest\TestProfiles.xml"); Console.WriteLine(file); Assert.IsTrue(File.Exists(file)); list = NetworkProfileHelper.Load(file, ""); return(list); }
/// <summary> /// Saves the specified file name. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="showDialog">if set to <c>true</c> [show dialog].</param> /// <returns></returns> public static bool Save(string fileName = DEFAULT_FILENAME, bool showDialog = false) { if (showDialog) { DialogResult result; result = MessageBox.Show("Do you want to save default config?", "Save config", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (result) { case DialogResult.Cancel: return(false); case DialogResult.No: SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; //dialog.InitialDirectory = initialDirectory; dialog.Title = "Select a config file to save"; result = dialog.ShowDialog(); if (result == DialogResult.OK) { fileName = dialog.FileName; } else { return(false); } break; case DialogResult.Yes: break; } } bool ret = NetworkProfileHelper.Save(DataModel.NetworkProfileList, fileName); UseCaseLogger.ShowInfo("Saved file '" + Path.GetFullPath(fileName) + "'"); return(ret); }
public void TestAutoDetect() { Console.WriteLine("Start"); // load test profiles List <NetworkProfile> networkProfileList = SetupProfiles(); NetworkProfile current = NetworkProfileHelper.AutoDetectNetworkProfile(networkProfileList); if (current != null) { Console.WriteLine("Profile name: {0}, Wifi SSID: {1} ", current.Name, current.AssociatedWifiSSID); } else { Console.WriteLine("No profile found"); } Console.WriteLine("Finished!"); }
/// <summary> /// Loads the specified file name. If operation is ok, DataModel.NetworkProfileList is filled. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="showDialog">if set to <c>true</c> [show dialog].</param> /// <returns></returns> public static void Load(string fileName = DEFAULT_FILENAME, bool showDialog = false) { if (showDialog) { DialogResult result; result = MessageBox.Show("Do you want to load default config?", "Load config", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (result) { case DialogResult.Cancel: return; case DialogResult.No: OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; //dialog.InitialDirectory = initialDirectory; dialog.Title = "Select a config file to load"; result = dialog.ShowDialog(); if (result == DialogResult.OK) { fileName = dialog.FileName; } else { return; } break; case DialogResult.Yes: break; } ; } else { // ASSERT: no dialog to show //To get the location the assembly normally resides on disk or the install directory string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase); //once you have the path you get the directory with: if (!Path.IsPathRooted(fileName)) { // ANS-16 fileName = Path.Combine(path, fileName); Uri uri = new Uri(fileName); fileName = Uri.UnescapeDataString(uri.AbsolutePath); } } // execute config default List <NetworkProfile> list = NetworkProfileHelper.Load(fileName); UseCaseLogger.ShowInfo("Load file '" + Path.GetFullPath(fileName) + "'"); if (!File.Exists(Path.GetFullPath(fileName))) { UseCaseLogger.ShowError("Ehi! No file '" + Path.GetFullPath(fileName) + "' found!"); } else if (list.Count == 0) { UseCaseLogger.ShowError("Ehi! 0 profiles found!"); } else { DataModel.NetworkProfileList = list; UseCaseProfile.Refresh(); } }