public async Task <bool> DownloadPodcastAsync(
            IPodcastEpisode episode, string directoryOut, AsyncCompletedEventHandler completedDownloadEvent = null,
            DownloadProgressChangedEventHandler downloadProgressChangedEvent = null, bool downloadInsertions = false)
        {
            try
            {
                if (string.IsNullOrEmpty(directoryOut))
                {
                    return(false);
                }

                if (!_fileHelper.DirectoryExists(directoryOut))
                {
                    _fileHelper.CreateDirectory(directoryOut);
                }

                if (episode is Episode naoOuvoEpisode && _fileHelper.DirectoryExists(directoryOut))
                {
                    var archiveName = naoOuvoEpisode.Url.Substring(naoOuvoEpisode.Url.LastIndexOf("/") + 1);

                    if (currentFilesDownloading.Any(name => name.Equals(archiveName, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        return(false);
                    }

                    var httpclient = new HttpClient()
                    {
                        Timeout = (new TimeSpan(5, 0, 0))
                    };

                    var client = new WebApiClient(httpclient, _fileHelper);

                    currentFilesDownloading.Add(archiveName);
                    directoryOut = directoryOut.EndsWith("\\") ? directoryOut : directoryOut + "\\";

                    if (downloadInsertions)
                    {
                        await DownloadNaoOuvoInsertions(naoOuvoEpisode, directoryOut, archiveName);
                    }

                    var filePath = string.Concat(directoryOut, archiveName);

                    await client.GetAsync(naoOuvoEpisode.Url, filePath);

                    currentFilesDownloading.Remove(archiveName);
                    completedDownloadEvent?.Invoke(null, null);

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Error on NaoOuvo download.\n\nDetails{ex.Message}");
                return(false);
            }

            return(false);
        }
Ejemplo n.º 2
0
 private void CheckIfDbExist()
 {
     if (_fileHelper.CheckIfFileExist(_dbName))
     {
         _fileHelper.CreateDirectory(_dbName);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Log the telemetry to file.
        /// For Testing purposes.
        /// </summary>
        /// <param name="eventName">
        /// The event Name.
        /// </param>
        /// <param name="metrics">
        /// Metrics
        /// </param>
        /// <param name="fileHelper">
        /// The file Helper.
        /// </param>
        internal void LogToFile(string eventName, IDictionary <string, object> metrics, IFileHelper fileHelper)
        {
            string resultDirectory = Path.GetTempPath() + "TelemetryLogs";
            string resultFileName  = Guid.NewGuid().ToString();
            string path            = Path.Combine(resultDirectory, resultFileName);

            if (!fileHelper.DirectoryExists(resultDirectory))
            {
                fileHelper.CreateDirectory(resultDirectory);
            }

            var telemetryData = string.Join(";", metrics.Select(x => x.Key + "=" + x.Value));
            var finalData     = string.Concat(eventName, ";", telemetryData);

            if (EqtTrace.IsInfoEnabled)
            {
                EqtTrace.Info("TextFileTelemetryPublisher.LogToFile : Logging telemetry data points to file {0}", path);
            }

            fileHelper.WriteAllTextToFile(path, finalData);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Bereitet das ImageRepo für den gebrauch vor
        /// </summary>
        void PrepareImageRepository()
        {
            BaseImagePath = System.IO.Path.Combine(Environment.CurrentDirectory, "Images");

            _fileHelper.CreateDirectory(BaseImagePath);
        }