Blacksmith.Sample.Program.Main C# (CSharp) Method

Main() static private method

static private Main ( string args ) : void
args string
return void
        static void Main(string[] args)
        {
            var configCheck = new ConfigurationWrapper();
            string yourProjectId = ""; // enter your projectid here or use app.config
            string yourtoken = ""; // enter your token or use app.config

            if (String.IsNullOrEmpty(yourProjectId))
            {
                yourProjectId = configCheck.BlacksmithProjectId;
            }

            if (String.IsNullOrEmpty(yourtoken))
            {
                yourtoken = configCheck.BlacksmithToken;
            }

            var client = new Client(yourProjectId, yourtoken);

            var pusher = new Timer { AutoReset = true, Interval = 1000, Enabled = true };
            var one = new Timer { AutoReset = true, Interval = 2500, Enabled = true };
            var bunch = new Timer { AutoReset = true, Interval = 5000, Enabled = true };

            // let's start pushing messages into the queue
            // the queue name is based on the class name
            pusher.Elapsed += (sender, eventArgs) =>
                client
                    .Queue<MyMessage>()
                    .Push(new MyMessage { Text = string.Format("Hello, World from {0}!", ++_count) });

            // I will handle try catches for you for
            // when it comes to deserializing and executing your processing code
            // also, I will delete the message from the queue on success!
            one.Elapsed +=
                (sender, eventArgs) =>
                client.Queue<MyMessage>()
                    .Next()
                    .OnError(Console.WriteLine)
                    .Consume((m, ctx) =>
                    {
                        Console.WriteLine("consuming one: {0}", m.Target.Text);
                    });

            // Can't wait, get a bunch of messages back and consume each one
            bunch.Elapsed +=
                (sender, eventArgs) =>
                    client.Queue<MyMessage>()
                        .Get(5)
                        .ForEach(r => r.Consume((m, ctx) =>
                        {
                            Console.WriteLine("{0} : {1}", m.Id, m.Target.Text);
                        }));

            Console.ReadLine();

            // clear the queue
            pusher.Stop();
            bunch.Stop();

            client.Queue<MyMessage>().Clear();
        }
Program