private void Window_Loaded(object sender, RoutedEventArgs e) { // check for updates if (Convert.ToBoolean(StaticHelper.GetApplicationSetting("AutoUpdate"))) { if (string.IsNullOrEmpty(StaticHelper.GetApplicationSetting("LastUpdateCheckDate"))) { StaticHelper.CheckForMenuXmlUpdates(); } else { DateTime lastcheck = Convert.ToDateTime(StaticHelper.GetApplicationSetting("LastUpdateCheckDate")); TimeSpan t = DateTime.Now - lastcheck; if (t.Days >= Convert.ToInt32(StaticHelper.GetApplicationSetting("UpdateCheckFrequency"))) { StaticHelper.CheckForMenuXmlUpdates(); } } } // get the buttons StaticHelper.LogMessage(MessageType.Info, "Getting buttons"); menu[] buttons = StaticHelper.GetControlledVocabularyMenus(); // build the buttons StaticHelper.LogMessage(MessageType.Info, "Building menu"); this.BuildMenu(buttons); if (this.menu1.Items.Count == 0) { this.ShowManager(); } }
public static bool DeployZippedButton(string sourceUrl, string buttonName) { try { using (var client = GetPreconfiguredWebClient()) { client.DownloadFile(sourceUrl, StaticHelper.GetCachePath().FullName + @"\" + buttonName + ".zip"); } } catch (Exception ex) { LogMessage(MessageType.Error, "DeployZippedButton failed." + ex.Message); return(false); } RemoveContent(new DirectoryInfo(Path.Combine(StaticHelper.GetButtonsPath().FullName, buttonName))); using (ZipFile zip = ZipFile.Read(StaticHelper.GetCachePath().FullName + @"\" + buttonName + ".zip")) { foreach (ZipEntry e in zip) { e.Extract(StaticHelper.GetButtonsPath().FullName, ExtractExistingFileAction.OverwriteSilently); } } RemoveContent(StaticHelper.GetCachePath()); return(true); }
public static void LogMessage(MessageType messageType, string error) { if (messageType == MessageType.Error) { using (EventLog eventLog = new EventLog()) { eventLog.Source = "ControlledVocabulary"; eventLog.Log = "Application"; eventLog.WriteEntry(error); } return; } // Get the installation path DirectoryInfo installationPath = StaticHelper.GetInstallationPath(); if (!File.Exists(installationPath + @"\enablelogging.txt")) { return; } DirectoryInfo logDirectory = new DirectoryInfo(@"C:\ControlledVocabularyLog"); if (!logDirectory.Exists) { logDirectory.Create(); } using (TextWriter tw = new StreamWriter(logDirectory.FullName + @"\Log.txt", true, Encoding.UTF8)) { tw.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} - {1}: {2}", DateTime.Now, messageType, error)); } }
public static menu[] GetControlledVocabularyMenus() { // Get the installation path DirectoryInfo installationPath = StaticHelper.GetInstallationPath(); // Iterate over Add-ins found DirectoryInfo buttonRoot = new DirectoryInfo(Path.Combine(installationPath.FullName, "Buttons")); DirectoryInfo[] buttons = buttonRoot.GetDirectories(); menu[] menus = new menu[buttons.Length]; int i = 0; foreach (FileInfo file in buttons.Select(button => new FileInfo(Path.Combine(button.FullName, "button.xml")))) { XmlSerializer deserializer = new XmlSerializer(typeof(menu)); using (FileStream buttonStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read)) { try { menus[i] = (menu)deserializer.Deserialize(buttonStream); } catch (Exception ex) { LogMessage(MessageType.Error, ex.ToString()); } } i++; } return(menus); }
private void Window_Loaded(object sender, RoutedEventArgs e) { this.initializing = false; // get the buttons install location this.labelAppData.Tag = string.Format(CultureInfo.InvariantCulture, @"{0}\Controlled Vocabulary", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); this.GetButtons(); try { Process[] processes = Process.GetProcessesByName("OUTLOOK"); if (processes.Length > 0) { this.labelOutlookRunning.Visibility = System.Windows.Visibility.Visible; } } catch { // Do Nothing } this.checkBoxCallMailto.IsChecked = Convert.ToBoolean(StaticHelper.GetApplicationSetting("CallMailtoProtocol")); this.checkBoxCopySubject.IsChecked = Convert.ToBoolean(StaticHelper.GetApplicationSetting("CopySubjectToClipboard")); this.textBoxMasterEmailAccount.Text = StaticHelper.GetApplicationSetting("MasterEmailAccount"); }
private static void Guidance(object sender, RoutedEventArgs e) { MenuItem m = (MenuItem)sender; string[] idParts = m.Uid.Split(new[] { StaticHelper.SplitSequence }, StringSplitOptions.RemoveEmptyEntries); string guidanceUrl = StaticHelper.GetGuidanceUrl(idParts[0]); System.Diagnostics.Process.Start(guidanceUrl); }
private void checkBoxAutoUpdate_Unchecked(object sender, RoutedEventArgs e) { if (this.initializing) { return; } StaticHelper.SetApplicationSetting("AutoUpdate", this.checkBoxAutoUpdate.IsChecked.ToString()); }
private void checkBoxCallMailto_Checked(object sender, RoutedEventArgs e) { if (this.initializing) { return; } StaticHelper.SetApplicationSetting("CallMailtoProtocol", this.checkBoxCallMailto.IsChecked.ToString()); }
private void checkBoxCopySubject_Checked(object sender, RoutedEventArgs e) { if (this.initializing) { return; } StaticHelper.SetApplicationSetting("CopySubjectToClipboard", this.checkBoxCopySubject.IsChecked.ToString()); }
private void buttonCheckForUpdates_Click(object sender, RoutedEventArgs e) { if (StaticHelper.CheckForMenuXmlUpdates()) { MessageBox.Show("Update is complete", "Finished", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Update failed. Check your Event Log", "Finished", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void buttonAddDiscovered_Click_1(object sender, RoutedEventArgs e) { foreach (CheckedListBoxItem item in this.checkedListItems) { if (item.IsChecked) { StaticHelper.DeployZippedButton(item.SourcePath, item.Name); } } this.GetButtons(); }
private void buttonAddDiscovered_Click_1(object sender, RoutedEventArgs e) { foreach (CheckedListBoxItem item in this.checkedListItems) { if (item.IsChecked) { if (!StaticHelper.DeployZippedButton(item.SourcePath, item.Name)) { MessageBox.Show("Deploy Failed. Check your Event Log", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } this.GetButtons(); }
private void ShowManager() { Manager managerWindow = new Manager(); managerWindow.ShowDialog(); StaticHelper.LogMessage(MessageType.Info, "Building menu"); // get the buttons StaticHelper.LogMessage(MessageType.Info, "Getting buttons"); menu[] buttons = StaticHelper.GetControlledVocabularyMenus(); // build the buttons StaticHelper.LogMessage(MessageType.Info, "Building menu"); this.BuildMenu(buttons); }
public static void DeployZippedButton(string sourceUrl, string buttonName) { using (var client = GetPreconfiguredWebClient()) { client.DownloadFile(sourceUrl, StaticHelper.GetCachePath().FullName + @"\" + buttonName + ".zip"); } RemoveContent(new DirectoryInfo(Path.Combine(StaticHelper.GetButtonsPath().FullName, buttonName))); using (ZipFile zip = ZipFile.Read(StaticHelper.GetCachePath().FullName + @"\" + buttonName + ".zip")) { foreach (ZipEntry e in zip) { e.Extract(StaticHelper.GetButtonsPath().FullName, ExtractExistingFileAction.OverwriteSilently); } } RemoveContent(StaticHelper.GetCachePath()); }
private void label2_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { string mailto = "mailto:" + StaticHelper.GetApplicationSetting("ErrorEmail"); mailto += "?subject=" + this.exception.Message; string inner = string.Empty; if (this.exception.InnerException != null) { inner = " --- " + this.exception.InnerException; } mailto += "&body=" + this.exception.Message + " ---- " + this.exception.StackTrace + inner; if (Convert.ToBoolean(StaticHelper.GetApplicationSetting("CallMailtoProtocol"))) { Process.Start(mailto); } this.Close(); }
/// <summary> /// Initializes a new instance of the MainWindow class /// </summary> public MainWindow() { try { this.InitializeComponent(); this.Width = Convert.ToInt32(Settings.Default.WindowWidth); this.Height = Convert.ToInt32(Settings.Default.WindowHeight); FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location); this.Title += " - " + new Version(versionInfo.FileMajorPart, versionInfo.FileMinorPart, versionInfo.FileBuildPart, versionInfo.FilePrivatePart); } catch (Exception ex) { StaticHelper.LogMessage(MessageType.Error, "in error"); StaticHelper.LogMessage(MessageType.Error, ex.ToString()); if (ex.InnerException != null) { StaticHelper.LogMessage(MessageType.Error, ex.InnerException.Message); } } }
private static void Send(object sender, RoutedEventArgs e) { MenuItem m = (MenuItem)sender; try { string[] idParts = m.Uid.Split(new[] { StaticHelper.SplitSequence }, StringSplitOptions.RemoveEmptyEntries); // Get the recipients string[] recipients = StaticHelper.GetRecipients(idParts[0], m.Uid); string mailto = "mailto:" + recipients[0]; mailto += "?subject=" + m.Tag; if (!string.IsNullOrEmpty(recipients[1])) { mailto += "&cc=" + recipients[1]; } if (!string.IsNullOrEmpty(recipients[2])) { mailto += "&bcc=" + recipients[2]; } if (Convert.ToBoolean(StaticHelper.GetApplicationSetting("CopySubjectToClipboard"))) { Clipboard.SetText(m.Tag.ToString()); } if (Convert.ToBoolean(StaticHelper.GetApplicationSetting("CallMailtoProtocol"))) { Process.Start(mailto); } } catch (System.Exception ex) { StaticHelper.LogMessage(MessageType.Error, ex.ToString()); throw; } }
/// <summary> /// Initializes a new instance of the Manager class /// </summary> public Manager() { InitializeComponent(); this.checkBoxAutoUpdate.IsChecked = Convert.ToBoolean(StaticHelper.GetApplicationSetting("AutoUpdate")); }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { StaticHelper.SetApplicationSetting("MasterEmailAccount", this.textBoxMasterEmailAccount.Text); }
public static bool CheckForMenuXmlUpdates() { LogMessage(MessageType.Info, "Checking for Menu content updates"); try { DirectoryInfo installationPath = GetInstallationPath(); XmlSerializer deserializer = new XmlSerializer(typeof(ButtonConfiguration)); // Iterate over Add-ins found DirectoryInfo buttonRoot = new DirectoryInfo(Path.Combine(installationPath.FullName, "Buttons")); DirectoryInfo[] buttons = buttonRoot.GetDirectories(); foreach (FileInfo file in buttons.Select(button => new FileInfo(Path.Combine(button.FullName, "config.xml")))) { // open the configuration file for the button ButtonConfiguration buttonConfig; using (FileStream buttonStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read)) { buttonConfig = (ButtonConfiguration)deserializer.Deserialize(buttonStream); } // if an onlineUrl is present, then we look for an update if (!string.IsNullOrEmpty(buttonConfig.onlineUrl)) { string currentMenu; using (TextReader tr = new StreamReader(Path.Combine(file.DirectoryName, @"button.xml"))) { currentMenu = tr.ReadToEnd(); } using (var client = GetPreconfiguredWebClient()) { // check if we need to update the whole button or just look for structure updates. if (!UpgradeButton(buttonConfig, file)) { Stream myStream = client.OpenRead(buttonConfig.onlineUrl); if (myStream != null) { using (StreamReader sr = new StreamReader(myStream)) { string latestMenu = sr.ReadToEnd(); if (latestMenu != currentMenu) { FileInfo f = new FileInfo(Path.Combine(file.DirectoryName, @"button.xml")); // First make sure the file is writable. FileAttributes fileAttributes = File.GetAttributes(f.FullName); // If readonly attribute is set, reset it. if ((fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(f.FullName, fileAttributes ^ FileAttributes.ReadOnly); } using (TextWriter tw = new StreamWriter(f.FullName)) { LogMessage(MessageType.Info, "Updating menu with online updates"); tw.Write(latestMenu); } } } } } } } } StaticHelper.SetApplicationSetting("LastUpdateCheckDate", DateTime.Now.ToString()); } catch (Exception ex) { LogMessage(MessageType.Error, "Update check failed." + ex.Message); return(false); } return(true); }