public IDisposable Start(TraceSource trace) { var service = QbservableTcpServer.CreateService <IList <FeedServiceArgument>, FeedItem>( endPoint, new QbservableServiceOptions() { SendServerErrorsToClients = true, AllowExpressionsUnrestricted = true }, request => (from arguments in request.Do(args => ConsoleTrace.WriteLine(ConsoleColor.DarkCyan, "Advanced service received {0} arguments.", args.Count)) from feed in arguments from _ in Observable.Timer(TimeSpan.Zero, TimeSpan.FromMinutes(1)) from item in Observable.Using(() => new HttpClient(), client => client.GetStreamAsync(feed.Url).ToObservable().Select(feed => SyndicationFeed.Load(XmlReader.Create(feed)))) select new FeedItem() { FeedUrl = feed.Url, Title = item.Title.Text, PublishDate = item.LastUpdatedTime }) .Do(item => ConsoleTrace.WriteLine(ConsoleColor.Green, "Advanced service generated item: {0}", item.Title))); return(service.Subscribe( terminatedClient => { foreach (var ex in terminatedClient.Exceptions) { ConsoleTrace.WriteLine(ConsoleColor.Magenta, "Advanced service error: {0}", ex.SourceException.Message); } ConsoleTrace.WriteLine(ConsoleColor.Yellow, "Advanced client shutdown: " + terminatedClient.Reason); }, ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Advanced fatal service error: {0}", ex.Message), () => Console.WriteLine("This will never be printed because a service host never completes."))); }
public IDisposable Start(TraceSource trace) { var service = QbservableTcpServer.CreateService <TimeSpan, long>( endPoint, new QbservableServiceOptions() { AllowExpressionsUnrestricted = true }, request => (from duration in request.Do(arg => Console.WriteLine("Timer client sent arg: " + arg)) from value in Observable.Timer(duration) select value)); return(service.Subscribe( terminatedClient => { foreach (var ex in terminatedClient.Exceptions) { ConsoleTrace.WriteLine(ConsoleColor.Magenta, "Timer service error: " + ex.SourceException.Message); } ConsoleTrace.WriteLine(ConsoleColor.Yellow, "Timer client shutdown: " + terminatedClient.Reason); }, ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Timer service fatal error: " + ex.Message), () => Console.WriteLine("This will never be printed because a service host never completes."))); }
public IDisposable Start(TraceSource trace) { var appBase = Path.GetDirectoryName(new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath); // Excluded this logic because the unless the exe is configured to load all assemblies from bin, you end up loading // two different copies of the same assembly into the AppDomains and the types are incompatible. //#if DEBUG // var newAppBase = appBase; //#else // /* Released example apps have all of their dependencies in a bin\ folder. // * It's more secure setting the bin folder as the app domain's base path // * instead of it being the same as the host app with a probing path. // */ // var newAppBase = Path.Combine(appBase, "bin"); //#endif var service = QbservableTcpServer.CreateService <object, int>( new AppDomainSetup() { ApplicationBase = appBase }, endPoint, new QbservableServiceOptions() { AllowExpressionsUnrestricted = true }, new Func <IObservable <object>, IObservable <int> >(CreateService)); return(service.Subscribe( terminatedClient => DoUnrestricted(() => { foreach (var ex in terminatedClient.Exceptions) { var security = ex.SourceException as SecurityException; ConsoleTrace.WriteLine(ConsoleColor.Magenta, "Sandboxed service error: " + security?.Demanded ?? ex.SourceException.Message); } ConsoleTrace.WriteLine(ConsoleColor.Yellow, "Malicious client shutdown: " + terminatedClient.Reason); }), ex => DoUnrestricted(() => ConsoleTrace.WriteLine(ConsoleColor.Red, "Sandboxed service fatal error: " + ex.Message)), () => Console.WriteLine("This will never be printed because a service host never completes."))); }
public IDisposable Start(TraceSource trace) { var messageDispatch = new Subject <string>(); messageDispatch.Subscribe(message => ConsoleTrace.WriteLine(ConsoleColor.DarkGray, message)); var service = QbservableTcpServer.CreateService <string, ChatServiceHooks>( endPoint, new QbservableServiceOptions() { EnableDuplex = true, AllowExpressionsUnrestricted = true }, request => (from userName in request from hooks in Observable.Create <ChatServiceHooks>( observer => { messageDispatch.OnNext(userName + " is online."); var hooks = new ChatServiceHooks(userName, messageDispatch); Scheduler.CurrentThread.Schedule(() => observer.OnNext(hooks)); return(() => messageDispatch.OnNext(userName + " is offline.")); }) select hooks)); return(service.Subscribe( terminatedClient => { foreach (var ex in terminatedClient.Exceptions) { ConsoleTrace.WriteLine(ConsoleColor.Magenta, "Chat service error: " + ex.SourceException.Message); } ConsoleTrace.WriteLine(ConsoleColor.Yellow, "Chat client shutdown: " + terminatedClient.Reason); }, ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Chat service fatal error: " + ex.Message), () => Console.WriteLine("This will never be printed because a service host never completes."))); }