// In bigger applications, there might be the need to pass data to a Muffin. // In this sample, the command line arguments are passed to Muffin1 using // HostPlatform as a way of communication. // // The executable will be executed with the following commandline arguments: // "SOME USELESS COMMANDLINE ARGUMENTS" static void Main(string[] args) { _args = args; _client = new MuffinClient(); _client.PlatformLoader.EnableComplete += PlatformLoader_EnableComplete; _client.Start(); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); _client.Dispose(); }
// Not every Muffin/Service/Protocol has basic tasks to do, some of them might // need to be split in smaller separate parts that work together. // This sample contains three examples for how to use Parts to have multiple // classes work together. static void Main() { var client = new MuffinClient(); client.Start(); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); // Calling Dispose here will also dispose all loaded MuffinParts // automatically. There is no need to dispose them manually. client.Dispose(); }
// This sample shows how a Muffin can consume a Platform / Service // // ConsolePlatform is used to write to the console and Muffins should use it // instead of directly calling the Console class. Now if we want to log all // console output, it can be accomplished very easily. // // ConsoleOutputService adds a Timestamp to each message to make the console // output easier to read. // // Muffin1 does some tasks and reports its state to the console. // LogMuffin has the responsbility to log all the console output. static void Main() { var client = new MuffinClient(); client.Start(); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); // Disposing the client also calls Dispose() in every loaded Muffin, Service // and Platform so they can clean up their resources. To avoid memory leaks, // always call MuffinClient.Dispose to make sure all resources are cleaned up. client.Dispose(); }
// Sometimes, it might be necessary for Muffins to communicate with eachother. // This sample demonstrates how this can be done. // // Muffin1 wants to change the text that Muffin2 is writing to the console every // 500 miliseconds, but Muffin1 is loaded before Muffin2, so it can't change // the Text in its Enable() method. static void Main() { var client = new MuffinClient(); client.Start(); Thread.Sleep(4000); // Calling Dispose here will abort the separate Thread in Muffin2. By // leaving out this line, you can prevent the program from exiting as there // is yet another thread running. See how important it is to call Dispose? client.Dispose(); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); }
// This sample demonstrates how you can load classes that are not located in the // main assembly of your program. This requires you to refrence // System.ComponentModel.Composition. // Muffin1 is stored in SampleApplication6.Muffins.dll assembly and should be // loaded from SampleApplication6.exe. static void Main() { var client = new MuffinClient(); // Get the MuffinsAssembly and add it to the clients catalog Assembly muffinsAssembly = typeof(Muffin1).Assembly; client.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(muffinsAssembly)); client.Start(); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); client.Dispose(); }
// This sample demonstrates how easy it is to get started with MuffinFramework. // Each layer contains a simple hello world class. Note that these classes are // not refrenced anywhere in this code and will be loaded dynamically. // // The classes will be loaded in the following order: // Platform1 -> Service1 -> Muffin1 static void Main() { var watch = new Stopwatch(); do { watch.Restart(); var client = new MuffinClient(); client.Start(); watch.Stop(); Console.WriteLine(Environment.NewLine + string.Format("Startup time: {0:#.00}ms", watch.Elapsed.TotalMilliseconds) + Environment.NewLine + "Press any key to repeat the test! Press the spacebar to exit!" + Environment.NewLine + new string('_', Console.BufferWidth)); client.Dispose(); } while (Console.ReadKey(true).Key != ConsoleKey.Spacebar); }