Example #1
0
        public void Initialize()
        {
            //Thread.CurrentThread.Name = "UI Thread";

            // Check the directories exist
            if (!Directory.Exists(ApplicationSettings.Default.LibraryPath + @"\backgrounds\"))
            {
                // Will handle the create of everything here
                Directory.CreateDirectory(ApplicationSettings.Default.LibraryPath + @"\backgrounds");
            }

            // Default the XmdsConnection
            ApplicationSettings.Default.XmdsLastConnection = DateTime.MinValue;

            // Show in taskbar
            ShowInTaskbar = ApplicationSettings.Default.ShowInTaskbar;

            // Setup the proxy information
            OptionForm.SetGlobalProxy();

            _statLog = new StatLog();

            // Create the info form
            _clientInfoForm = new ClientInfo();
            _clientInfoForm.Hide();

            // Define the hotkey
            Keys key;

            try
            {
                key = (Keys)Enum.Parse(typeof(Keys), ApplicationSettings.Default.ClientInformationKeyCode.ToUpper());
            }
            catch
            {
                // Default back to I
                key = Keys.I;
            }

            KeyStore.Instance.AddKeyDefinition("ClientInfo", key, ((ApplicationSettings.Default.ClientInfomationCtrlKey) ? Keys.Control : Keys.None));

            // Register a handler for the key event
            KeyStore.Instance.KeyPress += Instance_KeyPress;

            // Trace listener for Client Info
            ClientInfoTraceListener clientInfoTraceListener = new ClientInfoTraceListener(_clientInfoForm);

            clientInfoTraceListener.Name = "ClientInfo TraceListener";
            Trace.Listeners.Add(clientInfoTraceListener);

            // Log to disk?
            if (!string.IsNullOrEmpty(ApplicationSettings.Default.LogToDiskLocation))
            {
                TextWriterTraceListener listener = new TextWriterTraceListener(ApplicationSettings.Default.LogToDiskLocation);
                Trace.Listeners.Add(listener);
            }

#if !DEBUG
            // Initialise the watchdog
            if (!_screenSaver)
            {
                try
                {
                    // Update/write the status.json file
                    File.WriteAllText(System.IO.Path.Combine(ApplicationSettings.Default.LibraryPath, "status.json"), "{\"lastActivity\":\"" + DateTime.Now.ToString() + "\"}");

                    // Start watchdog
                    WatchDogManager.Start();
                }
                catch (Exception e)
                {
                    Trace.WriteLine(new LogMessage("MainForm - InitializeXibo", "Cannot start watchdog. E = " + e.Message), LogType.Error.ToString());
                }
            }
#endif
            // An empty set of overlay regions
            //_overlays = new Collection<Region>();


            Trace.WriteLine(new LogMessage("MainForm", "Client Initialised"), LogType.Info.ToString());
        }
Example #2
0
        public ClientManager()
        {
            Instance = this;

            InitializeComponent();

            // Check the directories exist
            if (!Directory.Exists(Settings.Default.LibraryPath) || !Directory.Exists(Settings.Default.LibraryPath + @"\backgrounds\"))
            {
                // Will handle the create of everything here
                Directory.CreateDirectory(Settings.Default.LibraryPath + @"\backgrounds");
                Directory.CreateDirectory(Settings.Default.LibraryPath + @"\Layouts");
                Directory.CreateDirectory(Settings.Default.LibraryPath + @"\Uploads\Media");
            }

            // Create a cachemanager
            SetCacheManager();

            ShowSplashScreen();

            // Change the default Proxy class
            OptionForm.SetGlobalProxy();

            Closed += delegate
            {
                Closing();
                Environment.Exit(0);
            };

            MyCommand.InputGestures.Add(new KeyGesture(Key.Q, ModifierKeys.Control));

            CommandBindings.Add(new CommandBinding(MyCommand, MyCommandExecuted));

            InitializeComponent();

            Switcher.ClientManager = this;


            Switcher.Switch(AdvertPlayer.Instance);

            var customerPage = CustomerPage.Instance;

            // Setup the proxy information
            OptionForm.SetGlobalProxy();

            _statLog = new StatLog();

            this.StartKeepAliveThread();

            this.StartMessageReceiveThread();

            try
            {
                // Create the Schedule
                _schedule = new Schedule(App.UserAppDataPath + "\\" + Settings.Default.ScheduleFile, ClientManager.Instance.CacheManager);

                // Bind to the schedule change event - notifys of changes to the schedule
                _schedule.ScheduleChangeEvent += ScheduleScheduleChangeEvent;

                // Initialize the other schedule components
                _schedule.InitializeComponents();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message, LogType.Error.ToString());
                MessageBox.Show("Fatal Error initialising AdvertPlayer", "Fatal Error");

                Environment.Exit(0);
            }
        }