コード例 #1
0
ファイル: Program.cs プロジェクト: bmegias/RabbitMQSample
        static void Main(string[] args)
        {
            var names = new[]
            {
                "Brau", "Raul", "Oriol", "Xavi", "Rocio", "Juanjo"
            };

            Console.WriteLine("***** RPC Client *****");
            var tot = 0;
            var serviceName = typeof(Program).Namespace.ToLowerInvariant();

            var cfg = new[] { new HandlerConfig<HelloResponse>(null) };
            var sub = new RabbitSubscriber(RabbitCfg.XCHG, serviceName, RabbitCfg.HOST, cfg);
            var pub = new RabbitPublisher(RabbitCfg.XCHG, RabbitCfg.HOST, sub);

            sub.StartAsyncMessageLoop();

            names
                .AsParallel()
                .ForAll(name =>
            {
                var corId = Guid.NewGuid().ToString();

                pub.PublishRequest<HelloRequest, HelloResponse>(
                    corId
                    , new HelloRequest() { Name = name }
                    , response =>
                    {
                        Console.WriteLine("Received CorrelationId: {0} Message: {1}"
                                               , corId
                                               , MessageBase.ToJson(response));
                    });
            });
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var books = new[] {new Book{Publisher="Lucerne Press",
                    First="David",
                    Last="Hamilton",
                    Title="David Hamilton Book",
                    ISBN="ISBN Number" },
                new Book{Publisher="Lucerne Press",
                    First="Stefan",
                    Last="Hesse",
                    Title="Stefan Hesse Book",
                    ISBN="ISBN Number"},
                new Book{Publisher="Lucerne Press",
                    First="Mike",
                    Last="Ray",
                    Title="Mike Ray Book",
                    ISBN="ISBN Number"},
                new Book{Publisher="Lucerne Press",
                    First="Bento",
                    Last="Nuno",
                    Title="Bento Nuno Book",
                    ISBN="ISBN Number"}};

            var titles=from book in books.AsParallel() where book.Publisher=="Lucerne Press"
                        orderby book.Title select book;

            foreach(Book book in titles)
            {
                Console.WriteLine("{0} {1}: {2}", book.First, book.Last, book.Title);
            }

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
コード例 #3
0
        public IEnumerable<Card> Get(string subtype)
        {
            var innistradBlockSets = new[]
            {
                "Innistrad",
                "Dark Ascension",
                "Avacyn Restored",
            };

            var hunter = new HunterService();

            return innistradBlockSets
                .AsParallel()
                .SelectMany(setName => hunter.GetCardsForSet(setName))
                .Where(c => c.compactType != null)
                .Where(c => ((string)c.compactType).ToLower().Contains((subtype ?? String.Empty).ToLower()))
                .Select(c => new Card((string)c.checklistName, (string)c.checklistColor));
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            var producer = new Subject<IMedium>();
            producer.Subscribe(x => Console.WriteLine($"received value {x.Title}"));
            producer.Subscribe(x => Console.WriteLine($"received value {x.CurrentValue}"));

            var imediums = new IMedium[]
            {
                new Videogame("Stick of Truth", "PS3",40,"South Park PRG","Viedeogame"),
                new Videogame("Golden Sun", "GameBoy", 20, "Fantasy RPG","Viedeogame"),
                new MusikCD("Heroes","Sabaton",40,"Limited Edition Earbook","Musik CD", "Heavy Metal"),
                new MusikCD("Bigger, Better, Faster, More!","4 non Blondes", 15, "Album 1992", "Musik CD", "Alternative-Rock"),
            };
            var videogames = new []
            {
                new Videogame("Super Mario Galaxy", "Nintendo Wii", 40, "Jump and Run Game", "Viedeogame"),
                new Videogame("Lemmings", "Super Nintendo", 35, "Help the Lemmings find their way!", "Viedeogame"),
                new Videogame("Worms","PC",20, "Worms against other Worms, Strategy Game", "Viedeogame"),
                new Videogame("Pokemon","GameBoy", 25, "Catch em all!", "Viedeogame"),
                new Videogame("Halo","Xbox",30, "First person shooter", "Viedeogame"),
            };

            var musicCDs = new[]
            {
                new MusikCD("Live Licks","The Rolling Stones", 20, "Live Album 2004", "Musik CD", "Classic Rock"),
                new MusikCD("Drunken Lullabies","Flogging Molly",15, "Studio Album 2002", "Musik CD", "Irish Folk"),
                new MusikCD("Live After Death","Iron Maiden",17,"Live Album 1985", "Musik CD","Heavy Metal"),
                new MusikCD("Back in Black","AC/DC",15,"Studio Album 1980","Musik CD","Hard Rock"),
            };

            Console.WriteLine();
            foreach (var b in imediums)
            {
                Console.WriteLine("{0,-20}{1,-40}{2,8:0.00} EUR", b.MediumType, b.Title, b.CurrentValue);
            }

            Console.WriteLine();
            Console.WriteLine ("Games in Library: " + Videogame.GameCount);
            Console.WriteLine();

            foreach (var b in videogames)
            {
                Console.WriteLine("{0,-40} {1,-40} {2,8:0.00} EUR", b.Title, b.Platform, b.CurrentValue);

            }

            Console.WriteLine();

            foreach (var b in musicCDs)
            {
                Console.WriteLine("{0,-20} {1,-20} {2, -20} {3,-20} {4,8:0.00} EUR", b.Title, b.Interpret, b.Description, b.Genre, b.CurrentValue);
            }

            foreach (var b in videogames) {
                if (b.Platform == "PC") {
                    b.CurrentValue = b.CurrentValue + 5;
                }
            }

            Console.WriteLine ();

            foreach (var b in videogames)
            {
                Console.WriteLine("{0,-40} {1,-40} {2,8:0.00} EUR {3,8:0.00}", b.Title, b.Platform, b.CurrentValue,b.getValueFactor());

            }

            var json = serializer(videogames);
            using (var sw = new StreamWriter(new FileStream("test.json", FileMode.Create)))
            {
                sw.Write(json);
            }

            // using (var sr = new StreamReader(new FileStream("test.json", FileMode.Open)))
            var fs = new FileStream("test.json", FileMode.Open);
            var sr = new StreamReader(fs);

                string filetext = sr.ReadToEnd();

            var objectarray = deserializer(filetext);

            sr.Close();
            fs.Close();

            Console.WriteLine(filetext);
            Console.WriteLine();

            foreach (var i in videogames)
            {
                producer.OnNext(i); // push value i to subscribers
            }

            var ValuableMedia = imediums
                .AsParallel()
                .Where(x => x.CurrentValue > 20)
                .Select(x => "Wertvolles Medium: " + x.Title)
                ;

            Console.WriteLine();
            foreach (var x in ValuableMedia)
            {
                Console.WriteLine("{0}", x);
            }

            var FirstCDs = musicCDs
                .AsParallel()
                .Take(3)
                ;
            Console.WriteLine();

            foreach (var x in FirstCDs)
            {
                Console.WriteLine("Titel: {0}", x.Title);
            }

            TasksExample.Run(videogames);
        }
コード例 #5
0
 public void PlinqSum()
 {
     var numbers = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
     var sumOfSquares = numbers.AsParallel().Select(i => Functions.Square(i)).Sum();
     Console.WriteLine(sumOfSquares);
 }
コード例 #6
0
 public void ParallelCustomAggregator()
 {
     var numbers = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
     var sumOfSquares = numbers.AsParallel().Select(i => Functions.Square(i)).Aggregate(0, (sum, value) => sum + value);
     Console.WriteLine(sumOfSquares);
 }
コード例 #7
0
		private void WeatherPlinqClick(object sender, RoutedEventArgs routedEventArgs)
		{
			ResetTimer();
			Task.Factory.StartNew(() =>
			{
				var cities = new[] {KansasCity, Seattle, NewYork};
				var weathers = (from city in cities.AsParallel().WithDegreeOfParallelism(2)
					select GetWeather(city)).ToArray();
				Dispatcher.InvokeAsync(() => ShowWeather(weathers));
			});
		}
コード例 #8
0
ファイル: SearchEngine.cs プロジェクト: moberg/coloursearch
        public void RebuildDatabase(string fileLocation)
        {
            string[] images = new[]
                                  {
                                      Directory.GetFiles(fileLocation, "*.jpg"),
                                      Directory.GetFiles(fileLocation, "*.png")
                                  }.SelectMany(x => x).ToArray();

            int i = 0;
            int total = images.Length;

            var entities = images
                    .AsParallel()
                    .Select(f =>
                                {

                                    var s = new SearchEntity(f, new Bitmap(f).GetHistograms());

                                    var current = Interlocked.Increment(ref i);
                                    Console.Write("\rRebuilding database: {0}%   ", (i / (double)total * 100).ToString("N1"));

                                    return s;
                                })
                    .ToArray();

            _db = new SearchDatabase {Images = entities, BasePath = fileLocation};

            Console.WriteLine("");
        }
コード例 #9
0
ファイル: Class1.cs プロジェクト: gogo71/BlogCodeSamples
 static void PLinqTest()
 {
     var numbers = new[] { 1, 2, 3, 4 };
     numbers.AsParallel().WithCancellation(cancellationToken)
                         .Select(SomeLongComputation).ToList();
 }