/// <summary>
        /// Saves results to Google Drive file.
        /// </summary>
        /// <param name="results">Results to save.</param>
        /// <param name="storageName">Storage name to write on Google Drive.</param>
        /// <returns>True if saving was successful, false otherwise.</returns>
        /// <remarks>
        /// This method creates and deletes temporary file to store appraised content.
        /// </remarks>
        public bool SaveResults(IReadOnlyList <IReadOnlyList <RatingDataContainer> > results,
                                string storageName)
        {
            if (string.IsNullOrEmpty(storageName))
            {
                return(false);
            }

            string tempStorageName = "temp_" + storageName;

            while (LocalFileWriter.DoesExistFile(tempStorageName))
            {
                tempStorageName = "temp_" + tempStorageName;
            }

            // Save results to local file and upload it.
            if (!_localFileWriter.SaveResults(results, tempStorageName))
            {
                return(false);
            }

            try
            {
                return(ReadFileAndUploadOrUpdate(tempStorageName, storageName));
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, $"An error occured during uploading \"{storageName}\".");
                GlobalMessageHandler.OutputMessage("An error occured during uploading " +
                                                   $"\"{storageName}\" : {ex}");
                return(false);
            }
            finally
            {
                DeleteFileSafe(tempStorageName);
                _logger.Debug($"Deleted temporary created file \"{tempStorageName}\".");
            }
        }
Esempio n. 2
0
        private void StartStopButton_Click(object sender, EventArgs e)
        {
            LockApp(true);

            if (_operationLauncher != null && _operationLauncher.IsWorking)
            {
                ReviewsBackgroundWorker.CancelAsync();
                ReviewsWorkerInfos.Text = Resources.StopInProgress;
                StartStopButton.Enabled = false;

            }
            else
            {
                if (!CheckForm())
                    return;
                //IMIRecordsProvider provider;
                //CSVFileProvider.TryBuildProvider(SourceFileTB.Text, out provider);

                var filters = new List<Func<Product, bool>>();

                if (FilterOnReviewsIdsCB.Checked)
                {
                    filters.Add(ProductFiltersBuilder.NewFilterOnIds(IdsToFilterTB.Text));
                }
                else
                {
                    var reviewers = ConfigurationManager.AppSettings["Reviewers"];
                    filters.Add(ProductFiltersBuilder.NewFilterOnReviewers(reviewers));
                    if (FilterOnReviewersCB.Checked)
                    {
                        filters.Add(ProductFiltersBuilder.NewFilterOnReviewers(NewReviewersTB.Text));
                    }
                }

                //Output
                IWriter writer;
                if (DestFileRB.Checked)
                    writer = new LocalFileWriter(DestFileTB.Text);
                else if (DestFtpRB.Checked)
                    writer = new FTPFileWriter(DestFTPDirTB.Text, DestFTPUserTB.Text, DestFTPPasswordTB.Text);
                else
                    throw new InvalidOperationException("Impossible de créer le Writer de sortie. vous n'êtes pas supposés passer dans ce code");

                //_operationsManagerDeprecated = new OperationsManager_Deprecated(provider, writer, LastUpdateDateDTP.Value, OperationsListBox.CheckedItems.Cast<Operation>().ToList());
                var reviewProcessorBuilder = new ReviewProcessorBuilder();
                var operations = OperationsListBox.CheckedItems.Cast<Operation>().ToList();
                _operationLauncher = reviewProcessorBuilder.BuildFor<Album>(SourceFileTB.Text, writer, filters, operations, LastUpdateDateDTP.Value, DoReviewCleaning.Checked);
                //_operationLauncher = new AlbumOperationManager(reviewProcessor, OperationsListBox.CheckedItems.Cast<Operation>().ToList(), writer, );

                ReviewsBackgroundWorker.RunWorkerAsync();
                StartStopButton.Text = Resources.CancelLabel;
                StartStopButton.Enabled = true;
            }
        }
Esempio n. 3
0
        private void StartStopButton_Click(object sender, EventArgs e)
        {
            LockApp(true);

            if (_operationLauncher != null && _operationLauncher.IsWorking)
            {
                ReviewsBackgroundWorker.CancelAsync();
                ReviewsWorkerInfos.Text = Resources.StopInProgress;
                StartStopButton.Enabled = false;
            }
            else
            {
                if (!CheckForm())
                {
                    return;
                }
                //IMIRecordsProvider provider;
                //CSVFileProvider.TryBuildProvider(SourceFileTB.Text, out provider);

                var filters = new List <Func <Product, bool> >();

                if (FilterOnReviewsIdsCB.Checked)
                {
                    filters.Add(ProductFiltersBuilder.NewFilterOnIds(IdsToFilterTB.Text));
                }
                else
                {
                    var reviewers = ConfigurationManager.AppSettings["Reviewers"];
                    filters.Add(ProductFiltersBuilder.NewFilterOnReviewers(reviewers));
                    if (FilterOnReviewersCB.Checked)
                    {
                        filters.Add(ProductFiltersBuilder.NewFilterOnReviewers(NewReviewersTB.Text));
                    }
                }

                //Output
                IWriter writer;
                if (DestFileRB.Checked)
                {
                    writer = new LocalFileWriter(DestFileTB.Text);
                }
                else if (DestFtpRB.Checked)
                {
                    writer = new FTPFileWriter(DestFTPDirTB.Text, DestFTPUserTB.Text, DestFTPPasswordTB.Text);
                }
                else
                {
                    throw new InvalidOperationException("Impossible de créer le Writer de sortie. vous n'êtes pas supposés passer dans ce code");
                }

                //_operationsManagerDeprecated = new OperationsManager_Deprecated(provider, writer, LastUpdateDateDTP.Value, OperationsListBox.CheckedItems.Cast<Operation>().ToList());
                var reviewProcessorBuilder = new ReviewProcessorBuilder();
                var operations             = OperationsListBox.CheckedItems.Cast <Operation>().ToList();
                _operationLauncher = reviewProcessorBuilder.BuildFor <Album>(SourceFileTB.Text, writer, filters, operations, LastUpdateDateDTP.Value, DoReviewCleaning.Checked);
                //_operationLauncher = new AlbumOperationManager(reviewProcessor, OperationsListBox.CheckedItems.Cast<Operation>().ToList(), writer, );

                ReviewsBackgroundWorker.RunWorkerAsync();
                StartStopButton.Text    = Resources.CancelLabel;
                StartStopButton.Enabled = true;
            }
        }