Exemplo n.º 1
0
        public IDisposable Start(TraceSource trace)
        {
            var service = Qactive.TcpQbservableServer.CreateService <TimeSpan, long>(
                endPoint,
                new QbservableServiceOptions()
            {
                AllowExpressionsUnrestricted = true
            },
                (IObservable <TimeSpan> 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);
            },
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Timer service fatal error: " + ex.Message),
                       () => Console.WriteLine("This will never be printed because a service host never completes.")));
        }
Exemplo n.º 2
0
        public IDisposable Start(TraceSource trace)
        {
            var service = Qactive.TcpQbservableServer.CreateService <IList <FeedServiceArgument>, FeedItem>(
                endPoint,
                new QbservableServiceOptions()
            {
                SendServerErrorsToClients = true, AllowExpressionsUnrestricted = true
            },
                (IObservable <IList <FeedServiceArgument> > request) =>
                (from arguments in request.Do((IList <FeedServiceArgument> 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);
            },
                       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.")));
        }
Exemplo n.º 3
0
        public IDisposable Start(TraceSource trace)
        {
            IObservable <long> source = Observable.Interval(TimeSpan.FromSeconds(1))
                                        .Do(value => ConsoleTrace.WriteLine(ConsoleColor.Green, "Basic service generated value: {0}", value));

            var service = source.ServeQbservableTcp(
                endPoint,
                new QbservableServiceOptions()
            {
                SendServerErrorsToClients = true, EnableDuplex = true, AllowExpressionsUnrestricted = true
            });

            return(service.Subscribe(
                       terminatedClient =>
            {
                foreach (var ex in terminatedClient.Exceptions)
                {
                    ConsoleTrace.WriteLine(ConsoleColor.Magenta, "Basic service error: {0}", ex.SourceException.Message);
                }

                ConsoleTrace.WriteLine(ConsoleColor.Yellow, "Basic client shutdown: " + terminatedClient.Reason);
            },
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Basic fatal service error: {0}", ex.Message),
                       () => Console.WriteLine("This will never be printed because a service host never completes.")));
        }
Exemplo n.º 4
0
        public static void ReplaceTracer(this Server server)
        {
            ConsoleTrace ct = new ConsoleTrace();
            TisLogger    tl = new TisLogger(ct);

            Reflector.SetInstanceFieldByName(server, "m_tisTracer",
                                             tl, ReflectionWays.SystemReflection);
        }
Exemplo n.º 5
0
        public IActionResult Index(DifficultyEnum difficulty)
        {
            var game = CreateGame(difficulty);

            CacheGame(game);
            ConsoleTrace.LogSuccess("Playground generated.");

            return(View(game));
        }
Exemplo n.º 6
0
        static IEnumerable <int> LocalIterator()
        {
            ConsoleTrace.PrintCurrentMethod();

            var rnd = new Random();

            for (int i = 0; i < 3; i++)
            {
                yield return(rnd.Next(1, 101));
            }
        }
Exemplo n.º 7
0
        public void ConsoleTest()
        {
            #region arrange
            string message = "Hello World";
            #endregion

            #region act
            IDiagnostic trace = new ConsoleTrace();
            trace.trace(message);
            #endregion

            #region assert
            Assert.IsTrue(true);
            #endregion
        }
Exemplo n.º 8
0
        static void Main()
        {
            ConsoleTrace.PrintCurrentMethod();

            Console.WriteLine();
            Console.WriteLine("Press any key to connect to the server.  Make sure that it's running first!");

            Console.ReadKey(intercept: true);

            new BasicClient().Run();
            new TimerClient().Run();
            new BasicFeedAggregationClient().Run();
            new AdvancedClient().Run();
            new DuplexClient().Run();
            new ChatClient().Run();
            new MaliciousClient().Run();
        }
Exemplo n.º 9
0
        private HashSet <Tuple <int, int> > GenerateMinesCoordinates(int boardBoundary, int mines)
        {
            var next   = _randomNumberGenerator.Next(0, boardBoundary);
            var result = new HashSet <Tuple <int, int> >();

            while (mines > 0)
            {
                try
                {
                    var temp = next;
                    next = _randomNumberGenerator.Next(0, boardBoundary);

                    while (temp == next)
                    {
                        next = _randomNumberGenerator.Next(0, boardBoundary);
                    }

                    var coordinates         = new Tuple <int, int>(temp, next);
                    var existingCoordinates = result.Any(c => c.Item1 == coordinates.Item1 && c.Item2 == coordinates.Item2);

                    try
                    {
                        if (existingCoordinates)
                        {
                            throw new ArgumentException("existing coordinates");
                        }
                    }
                    catch (ArgumentException ae)
                    {
                        ConsoleTrace.LogWarning(ae.Message);

                        continue;
                    }

                    result.Add(coordinates);

                    mines--;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            return(result);
        }
Exemplo n.º 10
0
        public void ActivateRules()
        {
            var activeQueueRules = ruleConfigurator.ConfigureQueueTriggeredRules();

            foreach (var rule in activeQueueRules)
            {
                try
                {
                    rule.ActivateListener();
                }
                catch (Exception ex)
                {
                    ConsoleTrace.Log(ex.Message + ex.StackTrace);
                    continue;
                }
            }
        }
Exemplo n.º 11
0
        public IDisposable Start(TraceSource trace)
        {
            var appBase = Path.GetDirectoryName(new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath);

            // Excluded this logic because 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 = TcpQbservableServer.CreateService <object, int, TransportInitializer>(
                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}");
            }),
                       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.")));
        }
Exemplo n.º 12
0
        public void Run()
        {
            Console.WriteLine();
            Console.WriteLine("Feed aggregation client starting...");

            var feedAggregatorServiceArgs = new List <FeedServiceArgument>()
            {
                new FeedServiceArgument()
                {
                    IsAtom = false, Url = new Uri("http://rss.cnn.com/rss/cnn_topstories.rss")
                },
                new FeedServiceArgument()
                {
                    IsAtom = false, Url = new Uri("http://blogs.msdn.com/b/rxteam/rss.aspx")
                },
                new FeedServiceArgument()
                {
                    IsAtom = true, Url = new Uri("http://social.msdn.microsoft.com/Forums/en-US/rx/threads?outputAs=atom")
                }
            };

            var client = new QbservableTcpClient <FeedItem>(Program.AdvancedServiceEndPoint, typeof(FeedItem));

            IQbservable <FeedItem> query =
                (from item in client.Query(feedAggregatorServiceArgs)
                 where item.PublishDate >= DateTimeOffset.UtcNow.AddHours(-DateTimeOffset.UtcNow.TimeOfDay.TotalHours)
                 select item)
                .Do(value => Console.WriteLine("{0} pushing value: {1}", Assembly.GetEntryAssembly().EntryPoint.DeclaringType.Namespace, value.Title));

            using (query.Subscribe(
                       value => ConsoleTrace.WriteLine(ConsoleColor.Green, "Feed client observed: ({0}) {1}", value.FeedUrl.Host, value.Title),
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Feed client error: {0}", ex.Message),
                       () => ConsoleTrace.WriteLine(ConsoleColor.DarkCyan, "Feed client completed")))
            {
                Console.WriteLine();
                Console.WriteLine("Feed client started.  Waiting for advanced service notifications...");
                Console.WriteLine();
                Console.WriteLine("(Press any key to stop)");
                Console.WriteLine();

                Console.ReadKey(intercept: true);
            }
        }
Exemplo n.º 13
0
        public void Run()
        {
            Console.WriteLine();
            Console.WriteLine("Advanced client starting...");
            Console.WriteLine();

            var suffix               = ")";
            var localObj             = new LocalObject();
            var localTransferableObj = new SharedLibrary.TransferableObject(100);

            var client = new TcpQbservableClient <long>(Program.BasicServiceEndPoint, typeof(SharedLibrary.TransferableObject));

            IQbservable <string> query =
                (from value in client.Query()
                 let r = new TransferableObject(42)
                         let numberBase = new { Remote = r.Value, Local = localTransferableObj.Value }
                 from n in Observable.Range(1, 5)
                 let number = (value + 1) * n
                              where number % 2 == 0
                              let result = numberBase.Remote + numberBase.Local + number
                                           let prefix = LocalStaticMethod(localObj.LocalInstanceMethod()) + localObj.LocalInstanceProperty
                                                        let list = (from i in LocalIterator()
                                                                    select i * 2)
                                                                   .Aggregate("", (acc, cur) => acc + cur + ",", acc => acc.Substring(0, acc.Length - 1))
                                                                   select prefix + result + ", [" + list + "]" + suffix)
                .Take(16)
                .Do(value => Console.WriteLine("{0} pushing value: {1}", Assembly.GetEntryAssembly().EntryPoint.DeclaringType.Namespace, value));

            using (query.Subscribe(
                       value => ConsoleTrace.WriteLine(ConsoleColor.Green, "Advanced client observed: {0}", value),
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Advanced client error: {0}", ex.Message),
                       () => ConsoleTrace.WriteLine(ConsoleColor.DarkCyan, "Advanced client completed")))
            {
                Console.WriteLine();
                Console.WriteLine("Advanced client started.  Waiting for basic service notifications...");
                Console.WriteLine();
                Console.WriteLine("(Press any key to continue)");
                Console.WriteLine();

                Console.ReadKey(intercept: true);
            }
        }
Exemplo n.º 14
0
        public void Run()
        {
            Console.WriteLine();
            Console.WriteLine("Duplex client starting...");

            var trace = new TraceSource("Custom", SourceLevels.All);

            trace.Listeners.Add(new AbbreviatedConsoleTraceListener());

            var suffix          = ")";
            var localObj        = new LocalObject();
            var localObservable = Observable
                                  .Interval(TimeSpan.FromSeconds(2))
                                  .Take(2)
                                  .Do(value => trace.TraceInformation("localObservable: {0}", value));

            var client = new QbservableTcpClient <long>(Program.BasicServiceEndPoint, new DuplexLocalEvaluator());

            IQbservable <string> query =
                (from serviceValue in client.Query()
                 let prefix = LocalStaticMethod(localObj.LocalInstanceMethod()) + localObj.LocalInstanceProperty
                              from clientValue in localObservable
                              .Do(value => Console.WriteLine("{0} received value: {1}", Assembly.GetEntryAssembly().EntryPoint.DeclaringType.Namespace, value))
                              from random in LocalIterator()
                              select prefix + clientValue + "/" + serviceValue + ", R=" + random + suffix)
                .Take(21)
                .Do(value => Console.WriteLine("{0} pushing value: {1}", Assembly.GetEntryAssembly().EntryPoint.DeclaringType.Namespace, value));

            using (query.Subscribe(
                       value => ConsoleTrace.WriteLine(ConsoleColor.Green, "Duplex client observed: {0}", value),
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Duplex client error: {0}", ex.Message),
                       () => ConsoleTrace.WriteLine(ConsoleColor.DarkCyan, "Duplex client completed")))
            {
                Console.WriteLine();
                Console.WriteLine("Duplex client started.  Waiting for basic service notifications...");
                Console.WriteLine();
                Console.WriteLine("(Press any key to stop)");
                Console.WriteLine();

                Console.ReadKey(intercept: true);
            }
        }
Exemplo n.º 15
0
        public void Run()
        {
            var client = new QbservableTcpClient <ChatServiceHooks>(Program.ChatServiceEndPoint);

            Console.WriteLine();
            Console.Write("Enter your user name> ");

            string userName = Console.ReadLine();

            Console.Write("Enter names to ignore separated by commas> ");

            var userNamesToIgnore = Console.ReadLine().Split(',').Select(name => name.Trim() + ' ');

            var myMessages = new Subject <string>();

            IObservable <string> outgoingMessages = myMessages;

            IQbservable <string> query =
                (from hooks in client.Query(userName)
                 .Do(hooks => outgoingMessages.Subscribe(hooks.IncomingMessages))
                 from message in hooks.OutgoingMessages
                 where !userNamesToIgnore.Any(message.StartsWith)
                 select message);

            using (query.Subscribe(
                       message => ConsoleTrace.WriteLine(ConsoleColor.Green, message),
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Chat client error: " + ex.Message),
                       () => ConsoleTrace.WriteLine(ConsoleColor.DarkCyan, "Chat client completed")))
            {
                Console.WriteLine();
                Console.WriteLine("Chat client started.  You may begin entering messages...");
                Console.WriteLine();
                Console.WriteLine("(Enter a blank line to stop)");
                Console.WriteLine();

                string message;
                while ((message = Console.ReadLine()).Length > 0)
                {
                    myMessages.OnNext(message);
                }
            }
        }
Exemplo n.º 16
0
        public IDisposable Start(TraceSource trace)
        {
            IObservable <int> source = Observable.Range(1, 3, ThreadPoolScheduler.Instance)
                                       .Do(value => ConsoleTrace.WriteLine(ConsoleColor.Green, "Limited service generated value: {0}", value));

            var service = source.ServeQbservableTcp(endPoint);

            return(service.Subscribe(
                       terminatedClient =>
            {
                foreach (var ex in terminatedClient.Exceptions)
                {
                    ConsoleTrace.WriteLine(ConsoleColor.Magenta, "Limited service error: " + ex.SourceException.Message);
                }

                ConsoleTrace.WriteLine(ConsoleColor.Yellow, "Malicious client shutdown: " + terminatedClient.Reason);
            },
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Limited service fatal error: " + ex.Message),
                       () => Console.WriteLine("This will never be printed because a service host never completes.")));
        }
Exemplo n.º 17
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            ConsoleTrace.Log("RuleEngine Started");

            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    _ruleActivator.ActivateRules();
                }
                catch (Exception ex)
                {
                    ConsoleTrace.LogError(ex.Message);

                    continue;
                }

                ConsoleTrace.Log("Rules Activated");
                Thread.Sleep(Timeout.Infinite);
            }
        }
Exemplo n.º 18
0
        public IDisposable Start(TraceSource trace)
        {
            var messageDispatch = new Subject <string>();

            messageDispatch.Subscribe(message => ConsoleTrace.WriteLine(ConsoleColor.DarkGray, message));

            var service = Qactive.TcpQbservableServer.CreateService <string, ChatServiceHooks>(
                endPoint,
                new QbservableServiceOptions()
            {
                EnableDuplex = true, AllowExpressionsUnrestricted = true
            },
                (IObservable <string> request) =>
                (from userName in request
                 from hooks in Observable.Create <ChatServiceHooks>(
                     (IObserver <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);
            },
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Chat service fatal error: " + ex.Message),
                       () => Console.WriteLine("This will never be printed because a service host never completes.")));
        }
        public void ActivateListener()
        {
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                try
                {
                    var kafkaReceiver = scope.ServiceProvider.GetService <IMessageQueueReceiver>();

                    kafkaReceiver.GroupId         = TopicName;
                    kafkaReceiver.TopicPartitions = new List <(string, int)>()
                    {
                        (TopicName, Partition)
                    };
                    kafkaReceiver.OnMessageReceived += ExecutePackager;
                    kafkaReceiver.ReceiveInNewThread();
                }
                catch (Exception ex)
                {
                    ConsoleTrace.LogError(ex.Message);
                }
            }
        }
Exemplo n.º 20
0
        public void Run()
        {
            var client = new QbservableTcpClient <long>(Program.BasicServiceEndPoint);

            var query =
                (from value in client.Query()
                 where value % 2 == 0
                 select value)
                .Do(value => Console.WriteLine("{0} pushing value: {1}", Assembly.GetEntryAssembly().EntryPoint.DeclaringType.Namespace, value));

            using (query.Subscribe(
                       value => ConsoleTrace.WriteLine(ConsoleColor.Green, "Basic client observed: {0}", value),
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Basic client error: {0}", ex.Message),
                       () => ConsoleTrace.WriteLine(ConsoleColor.DarkCyan, "Basic client completed")))
            {
                Console.WriteLine();
                Console.WriteLine("Basic client started.  Waiting for basic service notifications...");
                Console.WriteLine();
                Console.WriteLine("(Press any key to stop)");
                Console.WriteLine();

                Console.ReadKey(intercept: true);
            }
        }
Exemplo n.º 21
0
        public void Run()
        {
            var client = new TcpQbservableClient <long>(Program.TimerServiceEndPoint);

            IQbservable <int> query =
                (from value in client.Query(TimeSpan.FromSeconds(1))
                 from page in new WebClient().DownloadStringTaskAsync(new Uri("http://blogs.msdn.com/b/rxteam"))
                 select page.Length)
                .Do(result => Console.WriteLine("Where am I?  Result = " + result));

            using (query.Subscribe(
                       value => ConsoleTrace.WriteLine(ConsoleColor.Green, "Timer client observed: " + value),
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Timer client error: " + ex.Message),
                       () => ConsoleTrace.WriteLine(ConsoleColor.DarkCyan, "Timer client completed")))
            {
                Console.WriteLine();
                Console.WriteLine("Timer client started.  Waiting for timer service notification...");
                Console.WriteLine();
                Console.WriteLine("(Press any key to continue)");
                Console.WriteLine();

                Console.ReadKey(intercept: true);
            }
        }
Exemplo n.º 22
0
        public static void mainConsole()
        {
            IDiagnostic trace = new ConsoleTrace();

            trace.trace("Hello World");
        }
Exemplo n.º 23
0
        public int LocalInstanceMethod()
        {
            ConsoleTrace.PrintCurrentMethod();

            return(100);
        }
Exemplo n.º 24
0
        private void Run(IPEndPoint serviceEndPoint)
        {
            var client = new QbservableTcpClient <int>(serviceEndPoint, typeof(MessageBox));

            /* The sandboxed service does not prevent Console.WriteLine because that API doesn't demand any permissions.
             * This shows why setting AllowExpressionsUnrestricted to true is a bad idea, unless you trust all clients.
             */
            IQbservable <string> query1 = client.Query()
                                          .Take(1)
                                          .Do(_ => Console.WriteLine("Hello from malicious client!"))
                                          .Select(_ => "Malicious message sent successfully.");

            /* The default expression limiter does not prevent Environment.CurrentDirectory from being read because it's a property.
             * This shows why hosting services in a sandboxed AppDomain is a good idea, unless you trust all clients.
             */
            IQbservable <string> query2 = client.Query()
                                          .Take(1)
                                          .Select(_ => Environment.CurrentDirectory);

            // This query is prevented in both service scenarios
            IQbservable <string> query3 = client.Query()
                                          .Select(_ => MessageBox.Show("Hello from malicious client!").ToString());

            // This query is prevented in both service scenarios
            IQbservable <string> query4 = client.Query()
                                          .Select(_ => Environment.GetEnvironmentVariable("Temp", EnvironmentVariableTarget.Machine));

            // This query is prevented in both service scenarios
            IQbservable <string> query5 = client.Query()
                                          .Select(_ => System.IO.File.Create("c:\\malicious.exe").Length.ToString());

            // This query is prevented in both service scenarios
            IQbservable <string> query6 = client.Query()
                                          .Select(_ => AppDomain.CreateDomain(
                                                      "Malicious Domain",
                                                      null,
                                                      new AppDomainSetup()
            {
                ApplicationBase = "C:\\Windows\\Temp\\"
            },
                                                      new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted))
                                                  .FriendlyName);

            // This query is prevented in both service scenarios
            IQbservable <string> query7 = client.Query()
                                          .Select(_ => System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

            // This query is prevented in both service scenarios
            IQbservable <string> query8 = client.Query()
                                          .Do(_ => new PermissionSet(PermissionState.Unrestricted).Assert())
                                          .Select(_ => string.Empty);

            Func <int, IObserver <string> > createObserver = queryNumber => Observer.Create <string>(
                value => ConsoleTrace.WriteLine(ConsoleColor.Green, "Malicious query #{0} observed: {1}", queryNumber, value),
                ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Malicious query #{0} error: {1}", queryNumber, ex.Message),
                () => ConsoleTrace.WriteLine(ConsoleColor.DarkCyan, "Malicious query #{0} completed", queryNumber));

            using (query1.Subscribe(createObserver(1)))
                using (query2.Subscribe(createObserver(2)))
                    using (query3.Subscribe(createObserver(3)))
                        using (query4.Subscribe(createObserver(4)))
                            using (query5.Subscribe(createObserver(5)))
                                using (query6.Subscribe(createObserver(6)))
                                    using (query7.Subscribe(createObserver(7)))
                                        using (query8.Subscribe(createObserver(8)))
                                        {
                                            Console.WriteLine();
                                            Console.WriteLine("Malicious client started.  Waiting for service errors...");
                                            Console.WriteLine();
                                            Console.WriteLine("(Press any key to continue)");
                                            Console.WriteLine();

                                            Console.ReadKey(intercept: true);
                                        }

            IQbservable <int> safeQuery =
                from value in client.Query()
                where value > 0
                select value * 10;

            using (safeQuery.Subscribe(
                       value => ConsoleTrace.WriteLine(ConsoleColor.Green, "Safe query observed: " + value),
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Safe query error: " + ex.Message),
                       () => ConsoleTrace.WriteLine(ConsoleColor.DarkCyan, "Safe query completed")))
            {
                Console.WriteLine();
                Console.WriteLine("Waiting for service notifications...");
                Console.WriteLine();
                Console.WriteLine("(Press any key to continue)");
                Console.WriteLine();

                Console.ReadKey(intercept: true);
            }
        }
Exemplo n.º 25
0
        static string LocalStaticMethod(int ignoredParameter)
        {
            ConsoleTrace.PrintCurrentMethod();

            return("(N");
        }
Exemplo n.º 26
0
 public void AddedToEntity(Entity entity)
 {
     _entity = entity;
     _trace  = new ConsoleTrace();
 }
Exemplo n.º 27
0
 public void Log(string message, ConsoleMessageType type = ConsoleMessageType.Unspecified)
 {
     ConsoleTrace.WriteLine(message, type);
 }