public IObservableX <INavigateToItem> Search(string filter)
 {
     return(string.IsNullOrEmpty(filter)
                         ? ObservableX.Empty <INavigateToItem>()
                         : ServiceClient
            .SelectMany(
                (client) => client.ObserveMany(new SourceSymbolSearchRequest {
         Filter = filter
     }),
                (client, symbol) => (INavigateToItem) new SourceSymbolNavigateToItem(symbol, FileNavigationService)));
 }
 public IObservableX <INavigateToItem> Search(string filter)
 {
     return(Providers
            .Select(provider =>
                    provider
                    .Search(filter)
                    .Catch((Exception exception) =>
     {
         Logger.LogError(exception);
         return ObservableX.Empty <INavigateToItem>();
     }))
            .Merge());
 }
Exemple #3
0
 IObservableX <IObservableServiceClient> CreateClientFor(ProcessSettings serviceHostProcessSettings)
 {
     return(ObservableX.CreateWithDisposable <IObservableServiceClient>(observer =>
     {
         try
         {
             var serviceHostUri = ServiceHostUriFor(serviceHostProcessSettings);
             observer.CompleteWith(new ObservableServiceClient(serviceHostUri));
         }
         catch (Exception e)
         {
             Logger.LogError(e);
             observer.OnError(e);
         }
         return Disposable.Empty;
     }));
 }
Exemple #4
0
 IObservableX <TResult> SendAsync <TResponse, TResult>(object request, Action <TResponse, IObserverX <TResult>, MultipleAssignmentDisposable> onSuccess)
 {
     return(ObservableX.CreateWithDisposable <TResult>(observer =>
     {
         var client = NewJsonServiceClient();
         var disposable = MultipleAssignmentDisposableFor(client);
         client.SendAsync <TResponse>(
             request,
             onSuccess: response => onSuccess(response, observer, disposable),
             onError: (response, exception) =>
         {
             disposable.Disposable = null;
             observer.OnError(exception);
         });
         return disposable;
     }));
 }
Exemple #5
0
        public void SupportsManyProviders()
        {
            var providerA         = MockFor <INavigateToItemProvider>();
            var itemFromProviderA = MockFor <INavigateToItem>();

            providerA.Setup(_ => _.Search("")).Returns(ObservableX.Return(itemFromProviderA.Object));

            var providerB         = MockFor <INavigateToItemProvider>();
            var itemFromProviderB = MockFor <INavigateToItem>();

            providerB.Setup(_ => _.Search("")).Returns(ObservableX.Return(itemFromProviderB.Object));

            var aggregator = new NavigateToItemProviderAggregator {
                Providers = new[] { providerA.Object, providerB.Object }
            };
            var aggregatorItems = aggregator.Search("").ToList().FirstOrDefault();

            CollectionAssert.AreEquivalent(new[] { itemFromProviderA.Object, itemFromProviderB.Object }, aggregatorItems);
        }
Exemple #6
0
 public static IObservableX <T> DeserializeMany <T>(this Stream stream)
 {
     return(ObservableX.Using(
                () => new StreamReader(stream),
                reader =>
     {
         var firstLine = reader.ReadLine();
         if (firstLine != "[")
         {
             return ObservableX.Throw <T>(new InvalidOperationException("Expecting '[', got '{0}'".Fmt(firstLine)));
         }
         return ObservableX.Generate(
             reader,
             _ => _ != null,
             _ =>
         {
             var separator = _.Read();
             if (separator == ']')
             {
                 return null;
             }
             if (separator != ',')
             {
                 throw new InvalidOperationException("Expecting ',', got '{0}'".Fmt((char)separator));
             }
             return _;
         },
             _ =>
         {
             var line = _.ReadLine();
             if (line == "]")
             {
                 return null;
             }
             return line;
         })
         .TakeWhile(line => line != null)
         .Select(new JsonSerializer <T>().DeserializeFromString);
     }));
 }
        public void IndexAllFilesAutomaticallyUponStartup()
        {
            var sourceFile             = MockFor <IFile>().Object;
            var sourceFileNotification = MockFor <IFileNotification>();

            sourceFileNotification
            .SetupGet(_ => _.File)
            .Returns(sourceFile);

            var sourceFilesProvider = MockFor <ISourceFilesProvider>();

            sourceFilesProvider
            .SetupGet(_ => _.SourceFiles)
            .Returns(ObservableX.Return(sourceFileNotification.Object));

            var providerSelector = MockFor <ISourceSymbolProviderSelector>();
            var parseWaitEvent   = new AutoResetEvent(false);
            var symbol           = MockFor <ISourceSymbol>();

            providerSelector
            .Setup(_ => _.SourceSymbolsFor(sourceFile))
            .Callback(() => parseWaitEvent.Set())
            .Returns(new[] { symbol.Object });

            var container = new CompositionContainer(typeof(ISourceSymbolIndexProvider).Assembly);

            container.AddExportedValue(sourceFilesProvider.Object);
            container.AddExportedValue(providerSelector.Object);
            container.AddExportedValue <ILogger>(new StandardLogger());

            var subject = container.GetExportedValue <ISourceSymbolIndexProvider>();

            Assert.IsNotNull(subject.Index);

            // TODO: replace by injecting immediate scheduler
            parseWaitEvent.WaitOne(TimeSpan.FromSeconds(1));

            VerifyAllMocks();
        }