public void CustomInitialize(frmChummerMain mainControl) { MainForm = mainControl; //Not necessary anymore - see GetSINnerByAuthorization //Task.Factory.StartNew(async () => //{ // try // { // using (new CursorWait(true, MainForm)) // { // await Task.Delay(1000 * 10); // var client = await StaticUtils.GetClient(); // if (client != null) // { // var res = await client.GetRolesWithHttpMessagesAsync(); // if (res != null) // { // StaticUtils.UserRoles = res.Body.ToList(); // } // else // StaticUtils.UserRoles = new List<string>() {"none "}; // } // } // } // catch (Exception e) // { // System.Diagnostics.Trace.TraceError(e.ToString()); // } //}); }
public void Test00_BasicStartup() { Debug.WriteLine("Unit test initialized for: Test00_BasicStartup()"); frmChummerMain frmOldMainForm = Program.MainForm; frmChummerMain frmTestForm = null; // Try-finally pattern necessary in order prevent weird exceptions from disposal of MdiChildren try { frmTestForm = new frmChummerMain(true) { WindowState = FormWindowState.Minimized, ShowInTaskbar = false // This lets the form be "shown" in unit tests (to actually have it show, ShowDialog() needs to be used, but that forces the test to be interactve) }; Program.MainForm = frmTestForm; // Set program Main form to Unit test version frmTestForm.Show(); // Show the main form so that we know the UI can load in properly while ( !frmTestForm .IsFinishedLoading) // Hacky, but necessary to get xUnit to play nice because it can't deal well with the dreaded WinForms + async combo { Thread.Sleep(100); Application.DoEvents(); } frmTestForm.Close(); } finally { frmTestForm?.Dispose(); } Program.MainForm = frmOldMainForm; }
public void CustomInitialize(frmChummerMain mainControl) { MainForm = mainControl; if (String.IsNullOrEmpty(ChummerHub.Client.Properties.Settings.Default.TempDownloadPath)) { ChummerHub.Client.Properties.Settings.Default.TempDownloadPath = Path.GetTempPath(); } }
public void Test04_LoadCharacterForms() { Debug.WriteLine("Unit test initialized for: Test04_LoadCharacterForms()"); frmChummerMain frmOldMainForm = Program.MainForm; frmChummerMain frmTestForm = null; // Try-finally pattern necessary in order prevent weird exceptions from disposal of MdiChildren try { frmTestForm = new frmChummerMain(true) { WindowState = FormWindowState.Minimized, ShowInTaskbar = false // This lets the form be "shown" in unit tests (to actually have it show, ShowDialog() needs to be used, but that forces the test to be interactve) }; Program.MainForm = frmTestForm; // Set program Main form to Unit test version frmTestForm.Show(); // We don't actually want to display the main form, so Show() is used (ShowDialog() would actually display it). while (!frmTestForm.IsFinishedLoading) // Hacky, but necessary to get xUnit to play nice because it can't deal well with the dreaded WinForms + async combo { Thread.Sleep(Utils.DefaultSleepDuration); Application.DoEvents(); } foreach (FileInfo objFileInfo in TestFiles) { using (Character objCharacter = LoadCharacter(objFileInfo)) { try { using (CharacterShared frmCharacterForm = objCharacter.Created ? (CharacterShared) new frmCareer(objCharacter) : new frmCreate(objCharacter)) { frmCharacterForm.MdiParent = frmTestForm; frmCharacterForm.ShowInTaskbar = false; frmCharacterForm.WindowState = FormWindowState.Minimized; frmCharacterForm.Show(); } } catch (Exception e) { string strErrorMessage = "Exception while loading form for " + objFileInfo.FullName + ":"; strErrorMessage += Environment.NewLine + e; Debug.WriteLine(strErrorMessage); Console.WriteLine(strErrorMessage); Assert.Fail(strErrorMessage); } } } frmTestForm.Close(); } finally { frmTestForm?.Dispose(); } Program.MainForm = frmOldMainForm; }
public void CustomInitialize(frmChummerMain mainControl) { try { //this function is only for "you" //feel free to initialize yourself and set/change anything in the ChummerMain-Form you want. myWork = new NeonJungleWork(); } catch (Exception e) { Log.Error(e); } }
public void CustomInitialize(frmChummerMain mainControl) { try { //this function is only for "you" //feel free to initialize yourself and set/change anything in the ChummerMain-Form you want. //as an example, lets change the MAIN TITLE! mainControl.Text = "SamplePlugin changed the title!"; } catch (Exception e) { Log.Error(e); } }
public void CustomInitialize(frmChummerMain mainControl) { try { // This function is only for "you" // Feel free to initialize yourself and set/change anything in the ChummerMain-Form you want. // If you uncomment the following line as an example, the main title of the entire program gets changed! //mainControl.Text = "SamplePlugin changed the title!"; } catch(Exception e) { Log.Error(e); } }
public void BasicStartup() { Debug.WriteLine("Unit test initialized for: BasicStartup()"); frmChummerMain frmOldMainForm = Program.MainForm; // This lets the form be "shown" in unit tests (to actually have it show, ShowDialog() needs to be used) using (frmChummerMain frmTestForm = new frmChummerMain(true) { ShowInTaskbar = false }) { Program.MainForm = frmTestForm; // Set program Main form to Unit test version frmTestForm.Show(); // Show the main form so that we know the UI can load in properly } Program.MainForm = frmOldMainForm; }
public async Task BasicStartup() { Debug.WriteLine("Unit test initialized for: BasicStartup()"); frmChummerMain frmOldMainForm = Program.MainForm; // ShowInTaskbar = false lets the form be "shown" in unit tests (to actually have it show, ShowDialog() needs to be used) using (frmChummerMain frmTestForm = new frmChummerMain(true) { ShowInTaskbar = false }) { Program.MainForm = frmTestForm; // Set program Main form to Unit test version frmTestForm.Show(); // Show the main form so that we know the UI can load in properly await Task.Delay(20); // Need this here to prevent the Main Form display method from being optimized away by the Close() triggered on disposal } Program.MainForm = frmOldMainForm; }
public async Task Load4CharacterForms() { Debug.WriteLine("Unit test initialized for: Load4CharacterForms()"); frmChummerMain frmOldMainForm = Program.MainForm; using (frmChummerMain frmTestForm = new frmChummerMain(true) { WindowState = FormWindowState.Minimized, ShowInTaskbar = false // This lets the form be "shown" in unit tests (to actually have it show, ShowDialog() needs to be used) }) { Program.MainForm = frmTestForm; // Set program Main form to Unit test version frmTestForm.Show(); // We don't actually want to display the main form, so Show() is used (ShowDialog() would actually display it). foreach (FileInfo objFileInfo in TestFiles) { using (Character objCharacter = await LoadCharacter(objFileInfo)) { try { using (CharacterShared frmCharacterForm = objCharacter.Created ? (CharacterShared) new frmCareer(objCharacter) : new frmCreate(objCharacter)) { frmCharacterForm.MdiParent = frmTestForm; frmCharacterForm.WindowState = FormWindowState.Minimized; frmCharacterForm.Show(); } } catch (Exception e) { string strErrorMessage = "Exception while loading form for " + objFileInfo.FullName + ":"; strErrorMessage += Environment.NewLine + e; Debug.WriteLine(strErrorMessage); Console.WriteLine(strErrorMessage); Assert.Fail(strErrorMessage); } } } } Program.MainForm = frmOldMainForm; }
public void CustomInitialize(frmChummerMain mainControl) { MainForm = mainControl; Task.Factory.StartNew(async() => { try { await Task.Delay(1000 * 2); var client = await StaticUtils.GetClient(); var res = await client?.GetRolesWithHttpMessagesAsync(); if (res != null) { StaticUtils.UserRoles = res.Body.ToList(); } } catch (Exception e) { System.Diagnostics.Trace.TraceError(e.ToString()); } }); }
public void CustomInitialize(frmChummerMain mainControl) { Log.Info("CustomInitialize for Plugin ChummerHub.Client entered."); MainForm = mainControl; if (String.IsNullOrEmpty(ChummerHub.Client.Properties.Settings.Default.TempDownloadPath)) { ChummerHub.Client.Properties.Settings.Default.TempDownloadPath = Path.GetTempPath(); } //check global mutex BlnHasDuplicate = false; try { BlnHasDuplicate = !Program.GlobalChummerMutex.WaitOne(0, false); } catch (AbandonedMutexException ex) { Log.Error(ex); Utils.BreakIfDebug(); BlnHasDuplicate = true; } if (PipeManager == null) { PipeManager = new NamedPipeManager("Chummer"); Log.Info("blnHasDuplicate = " + BlnHasDuplicate.ToString()); // If there is more than 1 instance running, do not let the application start a receiving server. if (BlnHasDuplicate) { Log.Info("More than one instance, not starting NamedPipe-Server..."); throw new ApplicationException("More than one instance is running."); } else { Log.Info("Only one instance, starting NamedPipe-Server..."); PipeManager.StartServer(); PipeManager.ReceiveString += HandleNamedPipe_OpenRequest; } } }
public void Load3CharacterForms() { Debug.WriteLine("Unit test initialized for: Load3CharacterForms()"); frmChummerMain frmOldMainForm = Program.MainForm; Program.MainForm = MainForm; // Set program Main form to Unit test version MainForm.Show(); // We don't actually want to display the main form, so Show() is used (ShowDialog() would actually display it). string strPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "TestFiles"); DirectoryInfo objPathInfo = new DirectoryInfo(strPath); //Assuming Test is your Folder FileInfo[] aobjFiles = objPathInfo.GetFiles("*.chum5"); //Getting Text files foreach (FileInfo objFileInfo in aobjFiles) { using (Character objCharacter = LoadCharacter(objFileInfo)) { try { using (CharacterShared frmCharacterForm = objCharacter.Created ? (CharacterShared) new frmCareer(objCharacter) : new frmCreate(objCharacter)) { frmCharacterForm.MdiParent = MainForm; frmCharacterForm.WindowState = FormWindowState.Minimized; frmCharacterForm.Show(); frmCharacterForm.Close(); } } catch (Exception e) { string strErrorMessage = "Exception while loading form for " + objFileInfo.FullName + ":"; strErrorMessage += Environment.NewLine + e; Debug.WriteLine(strErrorMessage); Console.WriteLine(strErrorMessage); Assert.Fail(strErrorMessage); } } } MainForm.Close(); Program.MainForm = frmOldMainForm; }
public async Task LoadCharacter() { Properties.Settings.Default.SINnerUrl = "https://sinners.azurewebsites.net/"; Debug.WriteLine("Unit test initialized for: LoadCharacter()"); string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; if (MainForm == null) { MainForm = new frmChummerMain(true); } path = System.IO.Path.Combine(path, "data"); DirectoryInfo d = new DirectoryInfo(path); //Assuming Test is your Folder FileInfo[] Files = d.GetFiles("*.chum5"); //Getting Text files foreach (FileInfo file in Files) { try { Debug.WriteLine("Loading: " + file.Name); Character c = await MainForm.LoadCharacter(file.FullName); if (c == null) { continue; } Debug.WriteLine("Character loaded: " + c.Name); if (c.Created) { using (frmCareer career = new frmCareer(c)) { career.Show(); ucSINnersUserControl sINnersUsercontrol = new ucSINnersUserControl(); var ce = await sINnersUsercontrol.SetCharacterFrom(career); await ChummerHub.Client.Backend.Utils.PostSINnerAsync(ce); await ChummerHub.Client.Backend.Utils.UploadChummerFileAsync(ce); career.Hide(); career.Dispose(); } } else { using (frmCreate create = new frmCreate(c)) { create.Show(); ucSINnersUserControl sINnersUsercontrol = new ucSINnersUserControl(); var ce = await sINnersUsercontrol.SetCharacterFrom(create); await ChummerHub.Client.Backend.Utils.PostSINnerAsync(ce); await ChummerHub.Client.Backend.Utils.UploadChummerFileAsync(ce); create.Hide(); create.Dispose(); } } } catch (Exception e) { string msg = "Exception while loading " + file.FullName + ":"; msg += Environment.NewLine + e.ToString(); Debug.Write(msg); throw; } } }
public void CustomInitialize(frmChummerMain mainControl) { MainForm = mainControl; }