public Form1() { OOFSponderInsights.TrackInfo(OOFSponderInsights.CurrentMethod()); InitializeComponent(); #region SetBuildInfo foreach (Assembly a in Thread.GetDomain().GetAssemblies()) { if (a.GetName().Name == "OOFScheduling") { OOFData.version = lblBuild.Text = a.GetName().Version.ToString(); break; } } #endregion OOFSponderInsights.ConfigureApplicationInsights(); OOFSponderInsights.Track("OOFSponderStart"); //Set icon in code this.Icon = Properties.Resources.OOFSponderIcon; #region Add to Startup // The path to the key where Windows looks for startup applications RegistryKey rkApp = Registry.CurrentUser.OpenSubKey( @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); //Path to launch shortcut string startPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs) + @"\Microsoft\OOFSponder.appref-ms"; rkApp.SetValue("OOFSponder", startPath); #endregion #region Tray Menu Initialize // Create a simple tray menu with only one item. trayMenu = new ContextMenu(); trayMenu.MenuItems.Add("Exit", OnExit); // Add menu to tray icon and show it. notifyIcon1.ContextMenu = trayMenu; notifyIcon1.Icon = Properties.Resources.OOFSponderIcon; #endregion #region Read the list of teams to populate with templates //Read in the list of teams and build the dictionary list of team name //and template location //for each team, add an entry to the the Team Settings menu item (teamSettingsToolStripMenuItem) //If Use Team Settings is checked and a team is selected //then pull the remote files in as the text and then set the //controls to ReadOnly //Use a naming convention of "ExternalOOF.html" and "InternalOOF.html"? //Will also need to add some #Start/#End/#TimeZone logic //could even get fancy and have that be some sort of pop-up //so that each team could have its own //this is definitely future work :) #endregion //prep for async work System.Threading.Tasks.Task AuthTask = null; AuthTask = System.Threading.Tasks.Task.Run((Action)(() => { O365.MSALWork(O365.AADAction.SignIn); })); #if DEBUGFLOW MessageBox.Show("Attach now", "OOFSponder", MessageBoxButtons.OK); #endif if (OOFData.Instance.IsPermaOOFOn) { SetUIforSecondary(); } else { SetUIforPrimary(); } if (OOFData.Instance.WorkingHours != "") { string[] workingHours = OOFData.Instance.WorkingHours.Split('|'); //Zero means you are off that day (not working) therefore the box is checked string[] dayHours = workingHours[0].Split('~'); if (dayHours[2] == "0") { sundayOffWorkCB.Checked = true; } else { sundayOffWorkCB.Checked = false; } sundayStartTimepicker.Value = DateTime.Parse(dayHours[0]); sundayEndTimepicker.Value = DateTime.Parse(dayHours[1]); dayHours = workingHours[1].Split('~'); if (dayHours[2] == "0") { mondayOffWorkCB.Checked = true; } else { mondayOffWorkCB.Checked = false; } mondayStartTimepicker.Value = DateTime.Parse(dayHours[0]); mondayEndTimepicker.Value = DateTime.Parse(dayHours[1]); dayHours = workingHours[2].Split('~'); if (dayHours[2] == "0") { tuesdayOffWorkCB.Checked = true; } else { tuesdayOffWorkCB.Checked = false; } tuesdayStartTimepicker.Value = DateTime.Parse(dayHours[0]); tuesdayEndTimepicker.Value = DateTime.Parse(dayHours[1]); dayHours = workingHours[3].Split('~'); if (dayHours[2] == "0") { wednesdayOffWorkCB.Checked = true; } else { wednesdayOffWorkCB.Checked = false; } wednesdayStartTimepicker.Value = DateTime.Parse(dayHours[0]); wednesdayEndTimepicker.Value = DateTime.Parse(dayHours[1]); dayHours = workingHours[4].Split('~'); if (dayHours[2] == "0") { thursdayOffWorkCB.Checked = true; } else { thursdayOffWorkCB.Checked = false; } thursdayStartTimepicker.Value = DateTime.Parse(dayHours[0]); thursdayEndTimepicker.Value = DateTime.Parse(dayHours[1]); dayHours = workingHours[5].Split('~'); if (dayHours[2] == "0") { fridayOffWorkCB.Checked = true; } else { fridayOffWorkCB.Checked = false; } fridayStartTimepicker.Value = DateTime.Parse(dayHours[0]); fridayEndTimepicker.Value = DateTime.Parse(dayHours[1]); dayHours = workingHours[6].Split('~'); if (dayHours[2] == "0") { saturdayOffWorkCB.Checked = true; } else { saturdayOffWorkCB.Checked = false; } saturdayStartTimepicker.Value = DateTime.Parse(dayHours[0]); saturdayEndTimepicker.Value = DateTime.Parse(dayHours[1]); } bool haveNecessaryData = false; //we need the OOF messages and working hours if (OOFData.Instance.PrimaryOOFExternalMessage != "" && OOFData.Instance.PrimaryOOFInternalMessage != "" && OOFData.Instance.WorkingHours != "") { haveNecessaryData = true; } if (haveNecessaryData) { toolStripStatusLabel1.Text = "Ready"; OOFSponderInsights.TrackInfo("HaveNecessaryData"); } else { toolStripStatusLabel1.Text = "Please setup OOFsponder"; OOFSponderInsights.TrackInfo("MissingData"); } toolStripStatusLabel2.Text = ""; Loopy(); //set up handlers to persist OOF messages htmlEditorControl1.Validated += htmlEditorValidated; htmlEditorControl2.Validated += htmlEditorValidated; //wait on async auth stuff if not null if (AuthTask != null) { AuthTask.Wait(); } //trigger a check on current status System.Threading.Tasks.Task.Run(() => RunSetOofO365()); radPrimary.CheckedChanged += new System.EventHandler(radPrimary_CheckedChanged); fileToolStripMenuItem.DropDownOpening += fileToolStripMenuItem_DropDownOpening; }