Example #1
0
        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();
            }
        }
Example #2
0
        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);
        }
Example #3
0
        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));
            }
        }
Example #4
0
        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);
        }
Example #5
0
        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");
        }
Example #6
0
        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);
        }
Example #7
0
        private void checkBoxAutoUpdate_Unchecked(object sender, RoutedEventArgs e)
        {
            if (this.initializing)
            {
                return;
            }

            StaticHelper.SetApplicationSetting("AutoUpdate", this.checkBoxAutoUpdate.IsChecked.ToString());
        }
Example #8
0
        private void checkBoxCallMailto_Checked(object sender, RoutedEventArgs e)
        {
            if (this.initializing)
            {
                return;
            }

            StaticHelper.SetApplicationSetting("CallMailtoProtocol", this.checkBoxCallMailto.IsChecked.ToString());
        }
Example #9
0
        private void checkBoxCopySubject_Checked(object sender, RoutedEventArgs e)
        {
            if (this.initializing)
            {
                return;
            }

            StaticHelper.SetApplicationSetting("CopySubjectToClipboard", this.checkBoxCopySubject.IsChecked.ToString());
        }
Example #10
0
 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();
        }
Example #12
0
        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();
        }
Example #13
0
        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();
        }
Example #16
0
        /// <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);
                }
            }
        }
Example #17
0
        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;
            }
        }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the Manager class
 /// </summary>
 public Manager()
 {
     InitializeComponent();
     this.checkBoxAutoUpdate.IsChecked = Convert.ToBoolean(StaticHelper.GetApplicationSetting("AutoUpdate"));
 }
Example #19
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     StaticHelper.SetApplicationSetting("MasterEmailAccount", this.textBoxMasterEmailAccount.Text);
 }
Example #20
0
        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);
        }