示例#1
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            bool emptyTextbox = false;

            ForeachTextbox(x => emptyTextbox = x.Text == "");

            if (emptyTextbox)
            {
                infoBox.Text = "There are empty fields!";
                return;
            }

            infoBox.Text = "Please wait";

            _settings = new RequestSettings(username.Text, password.Password); //update login info

            PlaylistMaker maker;

            try
            {
                maker = new PlaylistMaker(queryList.Text, playlistName.Text, playlistSummary.Text, _settings);
                maker.CreatePlaylist();
            }
            catch (InvalidLoginInfoException)
            {
                infoBox.Text = "Incorrect username or password";
                return;
            }

            infoBox.Text = "Job done";

            url.Text           = maker.PlaylistUrl;
            urlGrid.Visibility = System.Windows.Visibility.Visible;
        }
示例#2
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);
        }