Esempio n. 1
0
        static void Main(string[] args)
        {
            DisplayBanner();
            if (args.Length < 1)
            {
                DisplayHelp();
                return;
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Started - {0}", DateTime.Now.ToString());
            Console.ResetColor();

            _iocContainer = InitializeIocContainer();
            _control      = new ReadOnlyControlFile(args[0]);
            _verbose      = _control.GetDiagnosticOutput() == DiagnosticOutputLevel.Verbose;

            _driveInfoProvider = _iocContainer.Resolve <IDriveInfoProvider>();

            int numberOfConnections = _control.GetMaximumNumberOfConcurrentDownloads();

            System.Net.ServicePointManager.DefaultConnectionLimit = numberOfConnections;

            ResetCounters();

            // find the episodes to download
            var allEpisodes          = new List <ISyncItem>(20);
            var podcastEpisodeFinder = _iocContainer.Resolve <IEpisodeFinder>();

            podcastEpisodeFinder.StatusUpdate += StatusUpdate;
            foreach (var podcastInfo in _control.GetPodcasts())
            {
                var episodesInThisFeed = podcastEpisodeFinder.FindEpisodesToDownload(_control.GetSourceRoot(), _control.GetRetryWaitInSeconds(), podcastInfo, _control.GetDiagnosticRetainTemporaryFiles());
                allEpisodes.AddRange(episodesInThisFeed);
            }

            _number_of_files_to_download = allEpisodes.Count;
            _number_of_files_downloaded  = 0;
            if (_number_of_files_to_download > 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Downloading {0} episodes", _number_of_files_to_download);
                Console.ResetColor();

                // convert them to tasks
                var converter = _iocContainer.Resolve <ISyncItemToEpisodeDownloaderTaskConverter>();
                IEpisodeDownloader[] downloadTasks = converter.ConvertItemsToTasks(allEpisodes, StatusUpdate, ProgressUpdate);

                // run them in a task pool
                _taskPool = _iocContainer.Resolve <ITaskPool>();
                Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
                _taskPool.RunAllTasks(numberOfConnections, downloadTasks);
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Done - {0}", DateTime.Now.ToString());
            Console.ResetColor();
        }
Esempio n. 2
0
 ///<summary>
 /// construct the copier
 ///</summary>
 ///<param name="driveInfoProvider">abstract access to the file system drive</param>
 ///<param name="fileUtilities">abstract file utilities</param>
 ///<param name="pathUtilities">abstract path utilities</param>
 public Copier(
     IDriveInfoProvider driveInfoProvider,
     IFileUtilities fileUtilities,
     IPathUtilities pathUtilities)
 {
     DriveInfoProvider = driveInfoProvider;
     FileUtilities     = fileUtilities;
     PathUtilities     = pathUtilities;
 }
Esempio n. 3
0
 static DriveInfo()
 {
     #if WIN32
     dip = new Platform.Win32.IO.Win32DriveInfoProvider();
     #elif UNIX
     dip = new Platform.Unix.IO.GioDriveInfoProvider();
     #else
     throw new NotImplementedException();
     #endif
 }
Esempio n. 4
0
        static DriveInfo()
        {
#if WIN32
            dip = new Platform.Win32.IO.Win32DriveInfoProvider();
#elif UNIX
            dip = new Platform.Unix.IO.GioDriveInfoProvider();
#else
            throw new NotImplementedException();
#endif
        }
 public SystemIO_Connector(IDriveInfoProvider provider)
 {
     _provider = provider;
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            AndroidApplication = Application as AndroidApplication;
            AndroidApplication.Logger.Debug(() => "MainActivity:OnCreate");
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            DriveInfoProvider   = AndroidApplication.IocContainer.Resolve <IDriveInfoProvider>();
            FileSystemHelper    = AndroidApplication.IocContainer.Resolve <IFileSystemHelper>();
            PreferencesProvider = AndroidApplication.IocContainer.Resolve <IPreferencesProvider>();
            ControlFileUri      = PreferencesProvider.GetPreferenceString(ApplicationContext.GetString(Resource.String.prefs_control_uri_key), "");
            AndroidApplication.Logger.Debug(() => $"MainActivity:OnCreate Conrol Uri = {ControlFileUri}");

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            // Get our UI controls from the loaded layout
            List <string> envirnment = WindowsEnvironmentInformationProvider.GetEnvironmentRuntimeDisplayInformation();
            StringBuilder builder    = new StringBuilder();

            builder.AppendLine(AndroidApplication.DisplayVersion);
            foreach (string line in envirnment)
            {
                builder.AppendLine(line);
            }
            SetTextViewText(Resource.Id.txtVersions, builder.ToString());

            builder.Clear();

            builder.AppendLine($"Personal Folder = {System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)}");
            builder.AppendLine($"AppData Folder = {System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)}");
            builder.AppendLine($"CommonAppData Folder = {System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData)}");
            Java.IO.File[] files = ApplicationContext.GetExternalFilesDirs(null);
            foreach (Java.IO.File file in files)
            {
                builder.AppendLine($"ExternalFile = {file.AbsolutePath}");
                OverrideRoot = file.AbsolutePath;
            }
            builder.AppendLine($"Podcasts Folder = {Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPodcasts).AbsolutePath}");
            SetTextViewText(Resource.Id.txtAppStorage, builder.ToString());

            ProgressSpinner = FindViewById <ProgressSpinnerView>(Resource.Id.progressBar);

            Button btnLoad = FindViewById <Button>(Resource.Id.btnLoadConfig);

            btnLoad.Click += (sender, e) => LoadConfig();

            Button btnFind = FindViewById <Button>(Resource.Id.btnFindPodcasts);

            // works
            btnFind.Click += (sender, e) => Task.Run(() => FindEpisodesToDownload());
            // crash - java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
            //btnFind.Click += async (sender, e) => await Task.Run(() => FindEpisodesToDownload());
            // blocks UI thread
            //btnFind.Click += async (sender, e) => FindEpisodesToDownload();

            Button btnSetRoot = FindViewById <Button>(Resource.Id.btnSetRoot);

            btnSetRoot.Click += (sender, e) => SetRoot();

            Button btnDownload = FindViewById <Button>(Resource.Id.btnDownload);

            btnDownload.Click += (sender, e) => Task.Run(() => Download());

            bool isReadonly  = Android.OS.Environment.MediaMountedReadOnly.Equals(Android.OS.Environment.ExternalStorageState);
            bool isWriteable = Android.OS.Environment.MediaMounted.Equals(Android.OS.Environment.ExternalStorageState);

            if (!string.IsNullOrEmpty(ControlFileUri))
            {
                try
                {
                    // TODO - we need to ask permission if the file has been edited by another app
                    Android.Net.Uri uri = Android.Net.Uri.Parse(ControlFileUri);
                    AndroidApplication.ControlFile = OpenControlFile(uri);
                }
                catch (Exception ex)
                {
                    AndroidApplication.Logger.LogException(() => $"MainActivity: OnCreate", ex);
                    SetTextViewText(Resource.Id.txtConfigFilePath, $"Error {ex.Message}");
                }
            }
        }