Ejemplo n.º 1
0
        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            ExchangeStatus status = (ExchangeStatus)e.Result;

            if (status.LowDiskSpace)
            {
                MessageBox.Show(Resources.LowDiskSpaceText, Resources.LowDiskSpaceHeader);
            }

            if (status.LowAssetSpace)
            {
                MessageBox.Show(Resources.LowAssetSpaceText, Resources.LowAssetSpaceHeader);
            }

            DateTime currentRun = DateTime.Now;

            txtLastRunDate.Text = currentRun.ToString();

            if (status.ContentDownloaded)
            {
                txtContentLastDownloaded.Text = currentRun.ToString();
            }
            ;

            txtLastRunStatus.Text = status.ExitWithError ? "Failed" : "Succeeded";

            if (_bCancelled)
            {
                lblCurrentOperation.Text = "Cancelled by user.";
            }
            else
            {
                lblCurrentOperation.Text = "Finished!";
            }

            _bFinished = true;
            this.Close();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // make sure no other content exchanger is running
            Process process     = Process.GetCurrentProcess();
            string  processName = process.ProcessName;

            Process[] contentExchangerProcesses = Process.GetProcessesByName(processName);

            if (contentExchangerProcesses.Length > 1)
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            SSLValidator.OverrideValidation();

            System.Globalization.CultureInfo systemCultureInfo = System.Globalization.CultureInfo.CurrentCulture;
            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-GB");
            System.Threading.Thread.CurrentThread.CurrentCulture   = ci;
            System.Threading.Thread.CurrentThread.CurrentUICulture = ci;

            if (args.Length > 0)
            {
                if (args[0] == "/v")
                {
                    Application.Run(new VerboseRunForm(systemCultureInfo));
                    return;
                }

                if (args[0] == "/s")
                {
                    Application.Run(new SafeModeForm());
                    return;
                }
            }
            else
            {
                Exchanger exchanger = new Exchanger();

                ExchangeStatus status = exchanger.Execute();

                CELog log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
                log.SaveLog();

                if (status.LowDiskSpace)
                {
                    MessageBox.Show(Resources.LowDiskSpaceText, Resources.LowDiskSpaceHeader);

                    return;
                }

                if (status.LowAssetSpace)
                {
                    MessageBox.Show(Resources.LowAssetSpaceText, Resources.LowAssetSpaceHeader);

                    return;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates application data and asset files from the relay server, generates the user's playlist
        /// and cleans up any old files
        /// </summary>
        internal ExchangeStatus Execute()
        {
            CELog          log                = null;
            ExchangeStatus status             = new ExchangeStatus();
            bool           bContentDownloaded = false;

            if (!_bGlobalsSet)
            {
                _logger.WriteTimestampedMessage("Error Setting Globals. Exiting Content Exchanger");
                status.ExitWithError     = true;
                status.ContentDownloaded = false;

                log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
                log.SaveLog();

                return(status);
            }

            status.LowDiskSpace = IsDiskSpaceLow();

            if (status.LowDiskSpace)
            {
                _logger.WriteTimestampedMessage("Low Disk Space. Exiting Content Exchanger");
                status.ExitWithError     = true;
                status.ContentDownloaded = false;

                log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
                log.SaveLog();

                return(status);
            }

            if (!DirStructureOK())
            {
                _logger.WriteTimestampedMessage("Error checking disk structure. Exiting Content Exchanger");
                status.ExitWithError     = true;
                status.ContentDownloaded = false;

                log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
                log.SaveLog();

                return(status);
            }

            if (!FileAccessRights())
            {
                _logger.WriteTimestampedMessage("Insufficient file access rights. Exiting Content Exchanger");
                status.ExitWithError     = true;
                status.ContentDownloaded = false;

                log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
                log.SaveLog();

                return(status);
            }

            try
            {
                FailedInternetConnectionAttemptFileAccessor failedAttemptAccessor = new FailedInternetConnectionAttemptFileAccessor();

                try
                {
                    SendHeartbeat(_machineGUID);
                    failedAttemptAccessor.ResetFailedAttempts();
                }
                catch (WebException)
                {
                    failedAttemptAccessor.RecordFailedAttempt();

                    if (RunsInTheBackground)
                    {
                        if (failedAttemptAccessor.GetFailedAttempts() >= MAX_NO_FAILED_INTERNET_CONNECTION_ATTEMPTS)
                        {
                            MessageBox.Show("Oxigen is having trouble communicating via the Internet. Please see the FAQs to ensure your PC is correctly configured.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                            failedAttemptAccessor.ResetFailedAttempts();
                            status.ExitWithError     = true;
                            status.ContentDownloaded = false;
                            return(status);
                        }
                    }

                    throw;
                }

                // update config files
                bool bCancelled = false;

                using (WebClient client = new WebClient())
                {
                    if (client.Proxy != null)
                    {
                        client.Proxy.Credentials = CredentialCache.DefaultCredentials;
                    }

                    UpdateConfigFiles(client, ref bCancelled);

                    if (bCancelled)
                    {
                        status.ExitWithError = false;

                        log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
                        log.SaveLog();

                        return(status);
                    }

                    // raed the downloaded channel subscriptions
                    ChannelSubscriptions channelSubscriptions = GetChannelSubscriptions();

                    if (channelSubscriptions == null)
                    {
                        _logger.WriteTimestampedMessage("No channel subscripitions found. Exiting Content Exchanger");

                        ReportProgress(100, 100);
                        status.ExitWithError     = false;
                        status.ContentDownloaded = false;

                        log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
                        log.SaveLog();

                        return(status);
                    }

                    channelSubscriptions = FilterChannelSubscriptionsByLock(channelSubscriptions);

                    // get the channel data files
                    GetChannelDataFiles(channelSubscriptions, ref bCancelled, client);

                    if (bCancelled)
                    {
                        status.ExitWithError = false;

                        log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
                        log.SaveLog();

                        return(status);
                    }

                    // Generate Playlist
                    Playlist playlist = null;

                    ReportProgress(0, 20, "Creating the local playlist");

                    try
                    {
                        playlist = PlaylistMaker.CreatePlaylist(_channelDataPath,
                                                                _advertDataPath,
                                                                _demographicDataPath,
                                                                _playlistPath,
                                                                _password,
                                                                _defaultDisplayDuration,
                                                                channelSubscriptions,
                                                                _logger);
                    }
                    catch (Exception ex)
                    {
                        _logger.WriteError(ex);
                        _logger.WriteTimestampedMessage("Exiting Content Exchanger");
                        ReportProgress(100, 100);
                        status.ExitWithError     = true;
                        status.ContentDownloaded = false;

                        log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
                        log.SaveLog();

                        return(status);
                    }

                    ReportProgress(100, 30);

                    // clean up unused files
                    CleanUpUnusedFiles(channelSubscriptions, playlist);

                    if (_worker != null && _worker.CancellationPending)
                    {
                        status.ExitWithError = false;

                        log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
                        log.SaveLog();

                        return(status);
                    }

                    bool bLowAssetSpace = false;

                    // Get content and advert files
                    bool bAssetFilesSuccessful = GetAssetFiles(playlist, ref bLowAssetSpace, ref bContentDownloaded,
                                                               ref bCancelled, client);

                    if (bCancelled)
                    {
                        status.ContentDownloaded = bContentDownloaded;
                        status.ExitWithError     = false;

                        log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
                        log.SaveLog();

                        return(status);
                    }

                    status.ContentDownloaded = bContentDownloaded;
                    status.ExitWithError     = !bAssetFilesSuccessful;
                    status.LowAssetSpace     = bLowAssetSpace;
                }
            }
            catch (Exception ex)
            {
                _logger.WriteError(ex);
                status.ExitWithError = true;
            }

            _logger.WriteTimestampedMessage("Exiting Content Exchanger");

            ReportProgress(100, 100);

            log = new CELog(DateTime.Now, status.ContentDownloaded, status.ExitWithError);
            log.SaveLog();

            return(status);
        }