Example #1
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 #2
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);
        }