Ejemplo n.º 1
0
 // And this for Autofac or real IoC
 public ConversationManager(
     ISignallingService signaller,
     IPeerManager peerManager,
     IMediaManager mediaManager,
     IDispatcherProvider dispatcherProvider)
 {
     this.signaller   = signaller;
     this.peerManager = peerManager;
     this.peerManager.OnIceCandidate += this.OnLocalIceCandidateDeterminedAsync;
     this.mediaManager       = mediaManager;
     this.dispatcherProvider = dispatcherProvider;
 }
Ejemplo n.º 2
0
        public MainViewModel(
            [Dependency(Dispatchers.Current)] IDispatcherProvider dispatcher,
            IFactory <IManagementViewModel> managementViewModelFactory,
            IFactory <IConfigurationViewModel> configurationViewModelFactory,
            IMessageBoxService messageBoxService,
            IThreadsController threadsController,
            IFile file)
        {
#if DEBUG
            var configurationModel = new ConfigurationModel()
            {
                BufferSize          = "10000",
                DestinationFileName = "Test.data",
                DestinationFolder   = @"C:\Users\nero0\Desktop\Новая папка (2)",
                SourceFilePath      = @"C:\Users\nero0\Downloads\Brainstorm - Years And Seconds.mp3"
            };
#else
            var configurationModel = new ConfigurationModel();
#endif
            ManagementViewModel    = managementViewModelFactory.ConstructWith(threadsController).And(configurationModel).Create();
            ConfigurationViewModel = configurationViewModelFactory.ConstructWith <IConfigurationModel>(configurationModel).Create();

            Cancel = threadsController.WriterState.Amb(threadsController.ReaderState)
                     .Select(state => state != WorkerState.Unstarted && state != WorkerState.Stopped)
                     .ToReactiveCommand(dispatcher.Scheduler, false);
            Cancel.Subscribe(threadsController.Cancel);

            StartCopying = threadsController.WriterState.Amb(threadsController.ReaderState)
                           .Select(state => state == WorkerState.Unstarted || state == WorkerState.Stopped)
                           .CombineLatest(ConfigurationViewModel.HasNotErrors, (state, err) => state && err)
                           .ToReactiveCommand(dispatcher.Scheduler);

            StartCopying.Subscribe(() =>
            {
                var destPath   = Path.Combine(configurationModel.DestinationFolder, configurationModel.DestinationFileName);
                var bufferSize = int.Parse(configurationModel.BufferSize);
                if (file.Exists(destPath))
                {
                    if (
                        messageBoxService.ShowYesNowQuestion(
                            $"File {destPath} already exists. Would you like to replace it?", "Information") ==
                        MessageBoxResult.Yes)
                    {
                        threadsController.StartReadAndWrite(configurationModel.SourceFilePath, destPath, bufferSize);
                    }
                }
                else
                {
                    threadsController.StartReadAndWrite(configurationModel.SourceFilePath, destPath, bufferSize);
                }
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        public MainPageViewModel(IApplicationOptionsProvider optionsProvider, IDispatcherProvider dp, ISimulation simulation)
        {
            this.optionsProvider = optionsProvider;
            this.dp         = dp;
            this.simulation = simulation;

            confirmRequest      = new InteractionRequest <Confirmation>();
            notificationRequest = new InteractionRequest <Notification>();
            Confirm             = new RelayCommand(DoConfirm);
            RunSimulation       = new AsyncRelayCommand(RunSimulationAsync);
            Beehives            = new ObservableCollection <BeehiveViewModel>();

            optionsProvider.OptionsChanged += OnOptionsChanged;
        }
Ejemplo n.º 4
0
        public ManagementViewModel([Dependency(Dispatchers.Current)] IDispatcherProvider dispatcher,
                                   IMessageBoxService messageBoxService,
                                   IThreadsController threadsController)
        {
            threadsController.Result.Subscribe(r =>
            {
                if (r.Result == Result.Error)
                {
                    messageBoxService.ShowErrorMessage(r.Exception.ToString(), "Error");
                }
                else
                {
                    messageBoxService.ShowInformation(r.Result.ToString(), "Information");
                }
            });

            Progress =
                threadsController.Progress
                .Sample(TimeSpan.FromMilliseconds(50))
                .ToReactiveProperty(dispatcher.Scheduler);

            BufferSize =
                threadsController.CurrentBufferSize
                .Sample(TimeSpan.FromMilliseconds(50))
                .ToReactiveProperty(dispatcher.Scheduler);

            ReaderState = threadsController.ReaderState.ToReactiveProperty(dispatcher.Scheduler);
            WriterState = threadsController.WriterState.ToReactiveProperty(dispatcher.Scheduler);

            PauseReading = threadsController.ReaderState.Select(x => x == WorkerState.Running)
                           .ToReactiveCommand(dispatcher.Scheduler);
            PauseReading.Subscribe(threadsController.PauseReading);

            ResumeReading = threadsController.ReaderState.Select(x => x == WorkerState.Suspended)
                            .ToReactiveCommand(dispatcher.Scheduler);
            ResumeReading.Subscribe(threadsController.ResumeReading);


            PauseWriting = threadsController.WriterState.Select(x => x == WorkerState.Running)
                           .ToReactiveCommand(dispatcher.Scheduler);
            PauseWriting.Subscribe(threadsController.PauseWriting);

            ResumeWriting = threadsController.WriterState.Select(x => x == WorkerState.Suspended)
                            .ToReactiveCommand(dispatcher.Scheduler);
            ResumeWriting.Subscribe(threadsController.ResumeWriting);
        }
Ejemplo n.º 5
0
        public static IDispatcher GetDispatcher(this BindableObject bindableObject)
        {
            if (s_default != null)
            {
                // If we're already using the fallback dispatcher, keep using it
                return(s_default);
            }

            // See if the current platform has a DispatcherProvider for us
            s_current = s_current ?? DependencyService.Get <IDispatcherProvider>();

            if (s_current == null)
            {
                // No DispatcherProvider available, use the fallback dispatcher
                s_default = new FallbackDispatcher();
                return(s_default);
            }

            // Use the DispatcherProvider to retrieve an appropriate dispatcher for this BindableObject
            return(s_current.GetDispatcher(bindableObject));
        }
Ejemplo n.º 6
0
 public virtual Task StartActivityAsync(params object[] args)
 {
     ActivityArgs       = new ActivityArgs(args);
     DispatcherProvider = new DispatcherProvider();
     return(StartActivityAsync());
 }
Ejemplo n.º 7
0
 public static void BeginInvoke(this IDispatcherProvider p, Action action, DispatcherPriority priority = DispatcherPriority.Normal)
 {
     p.Dispatcher.BeginInvoke(action, priority);
 }
Ejemplo n.º 8
0
 public static void CheckedInvoke(this IDispatcherProvider p, Action action)
 {
     p.Dispatcher.CheckedInvoke(action);
 }
Ejemplo n.º 9
0
 public GoogleDriveTreeViewModel()
 {
     _dispatcher           = new DispatcherProvider();
     FrequentFileContainer = new MultipleSelectionContainer <string>();
     EmptyFolderContainer  = new MultipleSelectionContainer <string>();
 }