コード例 #1
0
        public ScreenShotViewModel(LanguageManager loc,
                                   Settings settings,
                                   DiskWriter diskWriter,
                                   ClipboardWriter clipboardWriter,
                                   ImageUploadWriter imgurWriter,
                                   ScreenShotModel screenShotModel,
                                   VideoSourcesViewModel videoSourcesViewModel,
                                   IPlatformServices platformServices) : base(settings, loc)
        {
            DiskWriter      = diskWriter;
            ClipboardWriter = clipboardWriter;
            ImgurWriter     = imgurWriter;

            ScreenShotCommand = videoSourcesViewModel
                                .ObserveProperty(sourcesViewModel => sourcesViewModel.SelectedVideoSourceKind)
                                .Select(videoSourceProvider => !(videoSourceProvider is NoVideoSourceProvider))
                                .ToReactiveCommand()
                                .WithSubscribe(() => screenShotModel.CaptureScreenShot());

            async Task ScreenShotWindow(IWindow window)
            {
                var img = screenShotModel.ScreenShotWindow(window);

                await screenShotModel.SaveScreenShot(img);
            }

            ScreenShotActiveCommand  = new DelegateCommand(async() => await ScreenShotWindow(platformServices.ForegroundWindow));
            ScreenShotDesktopCommand = new DelegateCommand(async() => await ScreenShotWindow(platformServices.DesktopWindow));
            ScreenshotRegionCommand  = new DelegateCommand(async() => await screenShotModel.ScreenshotRegion());
            ScreenshotWindowCommand  = new DelegateCommand(async() => await screenShotModel.ScreenshotWindow());
            ScreenshotScreenCommand  = new DelegateCommand(async() => await screenShotModel.ScreenshotScreen());
        }
コード例 #2
0
        public ScreenShotViewModel(VideoViewModel VideoViewModel,
                                   RecentViewModel RecentViewModel,
                                   ISystemTray SystemTray,
                                   LanguageManager Loc,
                                   Settings Settings,
                                   IRegionProvider RegionProvider,
                                   IMainWindow MainWindow,
                                   DiskWriter DiskWriter,
                                   ClipboardWriter ClipboardWriter,
                                   ImgurWriter ImgurWriter,
                                   IVideoSourcePicker SourcePicker) : base(Settings, Loc)
        {
            _videoViewModel      = VideoViewModel;
            _recentViewModel     = RecentViewModel;
            _systemTray          = SystemTray;
            _regionProvider      = RegionProvider;
            _mainWindow          = MainWindow;
            _sourcePicker        = SourcePicker;
            this.DiskWriter      = DiskWriter;
            this.ClipboardWriter = ClipboardWriter;
            this.ImgurWriter     = ImgurWriter;

            ScreenShotCommand = new DelegateCommand(() => CaptureScreenShot());

            ScreenShotActiveCommand = new DelegateCommand(async() => await SaveScreenShot(ScreenShotWindow(Window.ForegroundWindow)));

            ScreenShotDesktopCommand = new DelegateCommand(async() => await SaveScreenShot(ScreenShotWindow(Window.DesktopWindow)));

            ScreenshotRegionCommand = new DelegateCommand(async() => await ScreenshotRegion());

            ScreenshotWindowCommand = new DelegateCommand(async() => await ScreenshotWindow());

            ScreenshotScreenCommand = new DelegateCommand(async() => await ScreenshotScreen());
        }
コード例 #3
0
        public ScreenShotViewModel(LanguageManager Loc,
                                   Settings Settings,
                                   DiskWriter DiskWriter,
                                   ClipboardWriter ClipboardWriter,
                                   ImageUploadWriter ImgurWriter,
                                   ScreenShotModel ScreenShotModel,
                                   VideoSourcesViewModel VideoSourcesViewModel,
                                   IPlatformServices PlatformServices) : base(Settings, Loc)
        {
            this.DiskWriter      = DiskWriter;
            this.ClipboardWriter = ClipboardWriter;
            this.ImgurWriter     = ImgurWriter;

            ScreenShotCommand = VideoSourcesViewModel
                                .ObserveProperty(M => M.SelectedVideoSourceKind)
                                .Select(M => !(M is NoVideoSourceProvider))
                                .ToReactiveCommand()
                                .WithSubscribe(() => ScreenShotModel.CaptureScreenShot());

            async Task ScreenShotWindow(IWindow Window)
            {
                var img = ScreenShotModel.ScreenShotWindow(Window);

                await ScreenShotModel.SaveScreenShot(img);
            }

            ScreenShotActiveCommand  = new DelegateCommand(async() => await ScreenShotWindow(PlatformServices.ForegroundWindow));
            ScreenShotDesktopCommand = new DelegateCommand(async() => await ScreenShotWindow(PlatformServices.DesktopWindow));
            ScreenshotRegionCommand  = new DelegateCommand(async() => await ScreenShotModel.ScreenshotRegion());
            ScreenshotWindowCommand  = new DelegateCommand(async() => await ScreenShotModel.ScreenshotWindow());
            ScreenshotScreenCommand  = new DelegateCommand(async() => await ScreenShotModel.ScreenshotScreen());
        }
コード例 #4
0
        public ScreenShotViewModel(LanguageManager Loc,
                                   Settings Settings,
                                   DiskWriter DiskWriter,
                                   ClipboardWriter ClipboardWriter,
                                   ImageUploadWriter ImgurWriter,
                                   ScreenShotModel ScreenShotModel,
                                   VideoSourcesViewModel VideoSourcesViewModel) : base(Settings, Loc)
        {
            this.DiskWriter      = DiskWriter;
            this.ClipboardWriter = ClipboardWriter;
            this.ImgurWriter     = ImgurWriter;

            ScreenShotCommand = VideoSourcesViewModel
                                .ObserveProperty(M => M.SelectedVideoSourceKind)
                                .Select(M => !(M is NoVideoSourceProvider))
                                .ToReactiveCommand()
                                .WithSubscribe(() => ScreenShotModel.CaptureScreenShot());

            ScreenShotActiveCommand  = new DelegateCommand(async() => await ScreenShotModel.SaveScreenShot(ScreenShotModel.ScreenShotWindow(Window.ForegroundWindow)));
            ScreenShotDesktopCommand = new DelegateCommand(async() => await ScreenShotModel.SaveScreenShot(ScreenShotModel.ScreenShotWindow(Window.DesktopWindow)));
            ScreenshotRegionCommand  = new DelegateCommand(async() => await ScreenShotModel.ScreenshotRegion());
            ScreenshotWindowCommand  = new DelegateCommand(async() => await ScreenShotModel.ScreenshotWindow());
            ScreenshotScreenCommand  = new DelegateCommand(async() => await ScreenShotModel.ScreenshotScreen());

            ScreenShotImageFormats = ScreenShotModel.ScreenShotImageFormats;

            SelectedScreenShotImageFormat = ScreenShotModel
                                            .ToReactivePropertyAsSynchronized(M => M.SelectedScreenShotImageFormat);
        }
コード例 #5
0
ファイル: ClipboardService.cs プロジェクト: metaseed/Metakey
        /// <summary>
        /// Write a specified clipboard data from an encrypted file.
        /// </summary>
        /// <param name="clipboardWriter">The <see cref="ClipboardWriter"/> used to write the data.</param>
        /// <param name="identifier">The data identifier.</param>
        /// <param name="clipboardDataPath">The full path to the clipboard data folder.</param>
        private void ReadFileToClipboardData(ClipboardWriter clipboardWriter, DataIdentifier identifier, string
                                             clipboardDataPath)
        {
            Requires.NotNull(clipboardWriter, nameof(clipboardWriter));
            Requires.NotNull(identifier, nameof(identifier));
            Requires.NotNullOrWhiteSpace(clipboardDataPath, nameof(clipboardDataPath));
            var dataFilePath = Path.Combine(clipboardDataPath, $"{identifier.Identifier}.dat");

            if (!File.Exists(dataFilePath))
            {
                return;
            }

            var dataPassword =
                SecurityHelper.ToSecureString(SecurityHelper.EncryptString(SecurityHelper.ToSecureString(
                                                                               identifier.Identifier.ToString(
                                                                                   ))));

            Requires.NotNull(dataPassword, nameof(dataPassword));
            var fileStream = File.OpenRead(dataFilePath);
            var aesStream  = new AesStream(fileStream, dataPassword,
                                           SecurityHelper.GetSaltKeys(dataPassword).GetBytes(16));

            clipboardWriter.AddData(identifier.FormatName, aesStream, fileStream);
        }
コード例 #6
0
        public ScreenShotViewModel(LanguageManager Loc,
                                   Settings Settings,
                                   DiskWriter DiskWriter,
                                   ClipboardWriter ClipboardWriter,
                                   ImageUploadWriter ImgurWriter,
                                   ScreenShotModel ScreenShotModel,
                                   VideoSourcesViewModel VideoSourcesViewModel,
                                   WebcamModel WebcamModel,
                                   IPlatformServices PlatformServices) : base(Settings, Loc)
        {
            this.DiskWriter      = DiskWriter;
            this.ClipboardWriter = ClipboardWriter;
            this.ImgurWriter     = ImgurWriter;

            ScreenShotCommand = new[]
            {
                VideoSourcesViewModel
                .ObserveProperty(M => M.SelectedVideoSourceKind)
                .Select(M => M is NoVideoSourceProvider),
                VideoSourcesViewModel
                .ObserveProperty(M => M.SelectedVideoSourceKind)
                .Select(M => M is WebcamSourceProvider),
                WebcamModel
                .ObserveProperty(M => M.SelectedCam)
                .Select(M => M is NoWebcamItem)
            }
            .CombineLatest(M =>
            {
                var noVideo    = M[0];
                var webcamMode = M[1];
                var noWebcam   = M[2];

                if (webcamMode)
                {
                    return(!noWebcam);
                }

                return(!noVideo);
            })
            .ToReactiveCommand()
            .WithSubscribe(M => ScreenShotModel.CaptureScreenShot());

            async Task ScreenShotWindow(IWindow Window)
            {
                var img = ScreenShotModel.ScreenShotWindow(Window);

                await ScreenShotModel.SaveScreenShot(img);
            }

            ScreenShotActiveCommand  = new DelegateCommand(async() => await ScreenShotWindow(PlatformServices.ForegroundWindow));
            ScreenShotDesktopCommand = new DelegateCommand(async() => await ScreenShotWindow(PlatformServices.DesktopWindow));
            ScreenshotRegionCommand  = new DelegateCommand(async() => await ScreenShotModel.ScreenshotRegion());
            ScreenshotWindowCommand  = new DelegateCommand(async() => await ScreenShotModel.ScreenshotWindow());
            ScreenshotScreenCommand  = new DelegateCommand(async() => await ScreenShotModel.ScreenshotScreen());
        }
コード例 #7
0
ファイル: ClipboardService.cs プロジェクト: metaseed/Metakey
        /// <summary>
        /// Set the clipboard content from a list of identifiers.
        /// </summary>
        /// <param name="identifiers">The list of <see cref="DataIdentifier"/> that specify which data must be added to the clipboard.</param>
        internal void SetClipboard(IEnumerable <DataIdentifier> identifiers)
        {
            Requires.NotNull(identifiers, nameof(identifiers));
            Pause();
            var dataService = ServiceLocator.GetService <DataService>();

            using (var clipboardWriter = new ClipboardWriter())
            {
                foreach (var dataIdentifier in identifiers)
                {
                    ReadFileToClipboardData(clipboardWriter, dataIdentifier, dataService.ClipboardDataPath);
                }

                clipboardWriter.Flush();
            }
        }
コード例 #8
0
        public void ClipboardWriterAndReader()
        {
            using (var clipboardWriter = new ClipboardWriter())
            {
                var value = new MemoryStream(new byte[] { 72, 101, 108, 108, 111 }); // "Hello" in binary

                clipboardWriter.AddData("ASCIITextTest", value);

                clipboardWriter.Flush();
            }

            var dataFromClipboard = (MemoryStream)System.Windows.Clipboard.GetData("ASCIITextTest");

            Assert.IsTrue(dataFromClipboard.ToArray().SequenceEqual(new byte[] { 72, 101, 108, 108, 111 }));

            var dataFromClipboard2 = new MemoryStream();
            var dataObject         = (System.Windows.DataObject)System.Windows.Clipboard.GetDataObject();

            using (var clipboardReader = new ClipboardReader(dataObject))
            {
                Assert.IsFalse(clipboardReader.IsReadable);
                Assert.IsFalse(clipboardReader.CanReadNextBlock());

                foreach (var format in dataObject.GetFormats())
                {
                    clipboardReader.BeginRead(format);
                    Assert.IsTrue(clipboardReader.IsReadable);
                    Assert.IsTrue(clipboardReader.CanReadNextBlock());

                    while (clipboardReader.CanReadNextBlock())
                    {
                        var buffer = clipboardReader.ReadNextBlock();
                        dataFromClipboard2.Write(buffer, 0, buffer.Length);
                    }

                    clipboardReader.EndRead();
                }
            }

            Assert.IsTrue(dataFromClipboard2.ToArray().SequenceEqual(new byte[] { 72, 101, 108, 108, 111 }));
        }
コード例 #9
0
        public ScreenShotViewModel(VideoSourcesViewModel VideoSourcesViewModel,
                                   ISystemTray SystemTray,
                                   LanguageManager Loc,
                                   Settings Settings,
                                   IRegionProvider RegionProvider,
                                   IMainWindow MainWindow,
                                   DiskWriter DiskWriter,
                                   ClipboardWriter ClipboardWriter,
                                   ImageUploadWriter ImgurWriter,
                                   IVideoSourcePicker SourcePicker,
                                   IAudioPlayer AudioPlayer,
                                   IEnumerable <IImageWriterItem> ImageWriters) : base(Settings, Loc)
        {
            _videoSourcesViewModel = VideoSourcesViewModel;
            _systemTray            = SystemTray;
            _regionProvider        = RegionProvider;
            _mainWindow            = MainWindow;
            _sourcePicker          = SourcePicker;
            _audioPlayer           = AudioPlayer;
            this.DiskWriter        = DiskWriter;
            this.ClipboardWriter   = ClipboardWriter;
            this.ImgurWriter       = ImgurWriter;

            AvailableImageWriters = ImageWriters.ToList();

            if (!AvailableImageWriters.Any(M => M.Active))
            {
                AvailableImageWriters[0].Active = true;
            }

            ScreenShotCommand        = new DelegateCommand(() => CaptureScreenShot());
            ScreenShotActiveCommand  = new DelegateCommand(async() => await SaveScreenShot(ScreenShotWindow(Window.ForegroundWindow)));
            ScreenShotDesktopCommand = new DelegateCommand(async() => await SaveScreenShot(ScreenShotWindow(Window.DesktopWindow)));
            ScreenshotRegionCommand  = new DelegateCommand(async() => await ScreenshotRegion());
            ScreenshotWindowCommand  = new DelegateCommand(async() => await ScreenshotWindow());
            ScreenshotScreenCommand  = new DelegateCommand(async() => await ScreenshotScreen());
        }
コード例 #10
0
 public BlockAndSemicolon(ClipboardWriter writer)
 {
     _writer = writer;
     _writer.OpenBlockCore();
 }
コード例 #11
0
 private static void Before()
 {
     Builder = new StringBuilder();
     Writer  = ClipboardWriter.CreateForStringBuilder(Builder);
 }
コード例 #12
0
 public CodeWriter()
 {
     _builder = new StringBuilder();
     _writer  = ClipboardWriter.CreateForStringBuilder(_builder);
 }
コード例 #13
0
 public Block(ClipboardWriter writer)
 {
     _writer = writer;
     _writer.OpenBlockCore();
 }