Example #1
0
        private static bool SetupPlugin()
        {
            string hostServiceSetting = ConfigurationManager.AppSettings["hostService"];

            if (hostServiceSetting == null)
            {
                hostServiceSetting = "XenClientGuest";
            }

            try
            {
                switch (hostServiceSetting)
                {
                case "Development":
                {
                    hostService = new DevelopmentHostService();
                    break;
                }

                case "XenGuestAgent":
                {
                    hostService = new XenGuestAgentHostService();
                    break;
                }

                case "XenClientGuest":
                {
                    try
                    {
                        hostService = new XenClientGuestHostService();
                    }
                    catch (Exception e)
                    {
                        log.Info(e);
#if DEBUG
                        System.Windows.Forms.MessageBox.Show(string.Format("Using XenGuestAgent, error encountered:\n\n{0}", e.Message));
#endif
                        hostService = new XenGuestAgentHostService();
                    }
                    break;
                }
                }

                monitor.Start();
                hostService.NewAlert += hostService_NewAlert;
                log.Info("Plugin setup!");
                return(true);
            }
            catch (Exception e)
            {
                log.Debug("Failed to initialize", e);
                MessageBox.Show(Resources.ResourceManager.GetString("Failed to initialize"), Resources.ResourceManager.GetString("XenClient Guest Notifications Plug-in"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            return(false);
        }