예제 #1
0
        /// <summary>
        /// Register providers from user settings, where they were previously saved.
        /// </summary>
        public async Task RestoreProviders()
        {
            // Load available IProvider types into memory
            if (ProviderService.Available.Count == 0)
            {
                ProviderService.LoadProviders();
            }

            var tasks = new Dictionary <string, Task <bool> >();

            // ToList() is needed because the original Dictionary is changing while we iterating
            SettingsService.Current.SafeProviders
            .ToList()
            .ForEach(p => tasks[p.Key] = ProviderService.RegisterProvider(
                         ProviderService.GetProviderById(p.Value.Id), p.Key, p.Value.State, false));

            // Wait for tasks to finish and remove unloaded providers
            foreach (var task in tasks)
            {
                if (!ProviderService.Loaded.ContainsKey(task.Key) && !await task.Value)
                {
                    ToastService.Create(string.Format(Resources.ProviderRegistrationFailed, task.Key));
                    ProviderService.ClearProvider(task.Key);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Capture a lot of bitmaps and convert them to video.
        /// </summary>
        /// <param name="region"></param>
        /// <param name="offset"></param>
        public async void CaptureVideo(Rectangle region, Point offset)
        {
            MemoryStream stream;
            var          toast = -1;

            // Create a new toast which closing event gonna stop the recording
            toast = ToastService.Create(Resources.StopRecording, Color.OrangeRed, 0, () =>
            {
                toast = ToastService.Create(Resources.Encoding, 0);
                CaptureService.StopRecording();
            });

            // Use Mpeg if enabled
            if (ConfigService.Current.EnableMpeg)
            {
                stream = await CaptureService.RecordMpeg(region, offset);
            }
            else
            {
                stream = await CaptureService.RecordGif(region, offset);
            }

            ToastService.Remove(toast);

            // Generate filename and start the upload(s)
            var url = await UploadAll(stream, ConfigService.Current.EnableMpeg? "mp4" : "gif");

            stream.Dispose();

            CopyUrl(url);
            Complete(url != null); // Exits the application
        }
예제 #3
0
        /// <summary>
        /// Upload the given stream with all loaded providers.
        /// </summary>
        /// <param name="ext"></param>
        /// <param name="stream"></param>
        /// <returns></returns>
        private async Task <string> UploadAll(MemoryStream stream, string ext)
        {
            var name  = $"{DateTime.Now:yyyy_MM_dd_HH_mm_ss}.{ext}";
            var toast = ToastService.Create(string.Format(Resources.Uploading, $"{(double)stream.Length / (1024 * 1024):0.00} MB"), 0);

            // Try to load the saved providers (if load on startup is disabled)
            if (!ConfigService.Current.StartupRegister)
            {
                await RestoreProviders();
            }

            // Save file locally if no providers were registered
            if (ProviderService.RegisteredProviders.Count == 0)
            {
                File.WriteAllBytes(name, stream.ToArray());
                ToastService.Remove(toast);
                return(null);
            }

            var uploads = new Dictionary <string, Task <string> >();

            string result = null;
            string last   = null;

            // Run the uploads async
            foreach (var p in ProviderService.RegisteredProviders)
            {
                if (p.Value != null)
                {
                    uploads[p.Key] = p.Value.Upload(name, stream);
                }
            }

            // Wait for the uploads to finish and get the chosen URL
            foreach (var p in uploads)
            {
                var url = await p.Value;

                if (string.IsNullOrEmpty(url))
                {
                    ToastService.Remove(toast);
                    ToastService.Create(string.Format(Resources.ProviderUploadFailed, p.Key));
                }
                else
                {
                    last = url;

                    if (p.Key == ConfigService.Current.CopyProvider)
                    {
                        result = url;
                    }
                }
            }

            ToastService.Remove(toast);

            // If the chosen URL was not found (or null), use the URL of the last successful one
            return(string.IsNullOrEmpty(result) ? last : result);
        }
예제 #4
0
 /// <summary>
 /// Show the end notifcation.
 /// </summary>
 /// <param name="success">If success is false, the text gonna tell the user, that the upload has failed.</param>
 private void Complete(bool success)
 {
     ToastService.Create(success ? Resources.UploadCompleted : Resources.UploadFailed, 3000, () =>
     {
         // We only exit on Windows, because other platforms shows us the CopyForm
         if (VersionService.GetPlatform() == PlatformType.Windows)
         {
             Application.Exit();
         }
     });
 }
예제 #5
0
        /// <summary>
        /// Capture a lot of bitmaps and convert them to video.
        /// </summary>
        /// <param name="region"></param>
        public async void CaptureVideo(Rectangle region)
        {
            MemoryStream stream;
            var          toast = -1;

            // Create a new toast which closing event gonna stop the recording
            toast = ToastService.Create(Resources.StopRecording, Color.OrangeRed, 0, () =>
            {
                toast = ToastService.Create(Resources.Encoding, 0);
                CaptureService.StopRecording();
            });

            stream = await CaptureService.RecordVideo(region, Config.VideoExt, SettingsService.Current.SafeVideoFps);

            ToastService.Remove(toast);

            // Generate filename and start the upload(s)
            var url = await UploadAll(stream, Config.VideoExt);

            stream.Dispose();

            CopyUrl(url);
            Complete(url != null); // Exits the application
        }