예제 #1
0
        public async static Task Run()
        {
            // =========================================================
            // Iron.io Cache
            // =========================================================

            IronCacheRestClient ironCacheClient = Client.New();

            // Get a Cache object
            CacheClient cache = ironCacheClient.Cache("my_cache");

            // Put value to cache by key
            await cache.Put("number_item", 42);

            CacheItem item = await cache.Get("number_item");

            // Get value from cache by key
            Console.WriteLine(item.Value);

            // Get value from cache by key
            Console.WriteLine(await cache.Get <int>("number_item"));

            // Numbers can be incremented
            await cache.Increment("number_item", 10);

            // Immediately delete an item
            await cache.Delete("number_item");

            await cache.Put("complex_item", new { greeting = "Hello", target = "world" });

            CacheItem complexItem = await cache.Get("complex_item");

            // Get value from cache by key
            Console.WriteLine(complexItem.Value);

            await cache.Delete("complex_item");

            await cache.Put("sample_class", new SampleClass { Name = "Sample Class CacheItem" });

            SampleClass sampleClassItem = await cache.Get <SampleClass>("sample_class");

            Console.WriteLine(sampleClassItem.Inspect());

            await cache.Delete("sample_class");
        }
예제 #2
0
파일: Program.cs 프로젝트: drdk/iron_dotnet
        private static void Main(string[] args)
        {
            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter();

            // =========================================================
            // Iron.io MQ
            // =========================================================

            //IronMqRestClient ironMq = IronSharp.IronMQ.Client.New();

            // For beta testing
            IronMqRestClient ironMq = IronSharp.IronMQ.Client.New(new IronClientConfig {
                ProjectId = "53a3b3bd5e8edd1245000005", Token = "O7KrMTwmw997iq0KzL7v", Host = "192.168.1.155", ApiVersion = 3, Port = 8080, Scheme = Uri.UriSchemeHttp
            });

            // Simple actions

            // Post message to a queue
            TestPosting(ironMq);

            // Post message to a queue and reserve it
            TestReservation(ironMq);

            // Post message, reserve it and delete
            TestDeletingReservedMessage(ironMq);

            // Actions on queue

            // Update queue info
            TestUpdatingTheQueue(ironMq);

            // Clear all messages of queue
            TestClearingQueue(ironMq);

            // Delete queue and its messages
            TestDeletingQueue(ironMq);

            // Get list of all queus inside project
            TestGettingListQueue(ironMq);

            // Actions on messages

            //TestPosting(ironMq);
            //TestReservation(ironMq);
            //TestDeletingReservedMessage(ironMq);

            // Get message by id without reservation
            TestGettingMessageById(ironMq);

            // Get message without reserving it
            TestPeekingMessage(ironMq);

            // Delete unreserved message
            TestDeletingMessage(ironMq);

            // Touch message to prolongate reservation
            TestTouching(ironMq);

            // Touch message to prolongate reservation
            TestTouchingTwice(ironMq);

            // Release reserved message
            TestReleasing(ironMq);

            // Delete a bunch of messages
            TestDeletingMessages(ironMq);

            // Get subscriber's URL
            TestGettingSubscribersInfo(ironMq);

            // =========================================================
            // Iron.io Worker
            // =========================================================

            Console.WriteLine("Be sure to create a 'Test' worker before running this sample");
            Console.WriteLine("Press ANY key to continue");
            Console.Read();

            IronWorkerRestClient workerClient = IronSharp.IronWorker.Client.New();

            string taskId = workerClient.Tasks.Create("Test", new { Key = "Value" });

            Console.WriteLine("TaskID: {0}", taskId);

            TaskInfoCollection taskInfoCollection = workerClient.Tasks.List("Test");

            foreach (TaskInfo task in taskInfoCollection.Tasks)
            {
                Console.WriteLine(task.Inspect());
            }

            ScheduleOptions options = ScheduleBuilder.Build().
                                      Delay(TimeSpan.FromMinutes(1)).
                                      WithFrequency(TimeSpan.FromHours(1)).
                                      RunFor(TimeSpan.FromHours(3)).
                                      WithPriority(TaskPriority.Default);

            var payload = new
            {
                a = "b",
                c = new[] { 1, 2, 3 }
            };

            ScheduleIdCollection schedule = workerClient.Schedules.Create("Test", payload, options);

            Console.WriteLine(schedule.Inspect());

            workerClient.Schedules.Cancel(schedule.Schedules.First().Id);

            // =========================================================
            // Iron.io Cache
            // =========================================================

            IronCacheRestClient ironCacheClient = IronSharp.IronCache.Client.New();

            // Get a Cache object
            CacheClient cache = ironCacheClient.Cache("my_cache");

            // Put value to cache by key
            cache.Put("number_item", 42);

            // Get value from cache by key
            Console.WriteLine(cache.Get("number_item").Value);

            // Get value from cache by key
            Console.WriteLine(cache.Get <int>("number_item"));

            // Numbers can be incremented
            cache.Increment("number_item", 10);

            // Immediately delete an item
            cache.Delete("number_item");

            cache.Put("complex_item", new { greeting = "Hello", target = "world" });

            // Get value from cache by key
            Console.WriteLine(cache.Get("complex_item").Value);

            cache.Delete("complex_item");

            Console.WriteLine("============= Done ==============");
            Console.Read();
        }
예제 #3
0
        private static void Main(string[] args)
        {
            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter();
            IronMqRestClient ironMq = IronSharp.IronMQ.Client.New(new IronClientConfig {
                ProjectId = "5bf768af967e0f000910fed3", Token = "y7TU7c3D3IUXtwrcJJFH", Host = "mq-aws-eu-west-1-1.iron.io", ApiVersion = 3, Scheme = Uri.UriSchemeHttp
            });

            QueueClient queueHabitacion  = ironMq.Queue("Habitacion");
            var         codigoHabitacion = "HBT0000007";
            string      messageId1       = queueHabitacion.Post(codigoHabitacion);

            Console.WriteLine("Mensaje enviado: {0}", codigoHabitacion);

            QueueClient queueHotel  = ironMq.Queue("Hotel");
            var         codigoHotel = "HT00000002";
            string      messageId2  = queueHotel.Post(codigoHotel);

            Console.WriteLine("Mensaje enviado: {0}", codigoHabitacion);

            //QueueMessage messageHabitacion = queueHabitacion.Reserve();
            //Console.WriteLine("Respuesta: " + messageHabitacion.Body);

            //QueueMessage messageHotel = queueHotel.Reserve();
            //Console.WriteLine("Respuesta: " + messageHotel.Body);
            //Console.WriteLine(message.ReservationId);


            //bool finished = false;
            //var hotelIds = new List<string>();
            //while (!finished)
            //{
            //    messageHotel = queueHotel.Reserve();
            //    if (messageHotel != null)
            //        hotelIds.Add(messageHotel.Body);
            //    else
            //        finished = true;
            //}



            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter();

            // =========================================================
            // Iron.io MQ
            // =========================================================

            //IronMqRestClient ironMq = IronSharp.IronMQ.Client.New();

            // For beta testing
            //IronMqRestClient ironMq = IronSharp.IronMQ.Client.New(new IronClientConfig { ProjectId = "53a3b3bd5e8edd1245000005", Token = "O7KrMTwmw997iq0KzL7v", Host = "192.168.1.155", ApiVersion = 3, Port = 8080, Scheme = Uri.UriSchemeHttp });

            // Simple actions

            // Post message to a queue
            TestPosting(ironMq);

            // Post message to a queue and reserve it
            TestReservation(ironMq);

            // Post message, reserve it and delete
            TestDeletingReservedMessage(ironMq);

            // Actions on queue

            // Update queue info
            TestUpdatingTheQueue(ironMq);

            // Clear all messages of queue
            TestClearingQueue(ironMq);

            // Delete queue and its messages
            TestDeletingQueue(ironMq);

            // Get list of all queus inside project
            TestGettingListQueue(ironMq);

            // Actions on messages

            //TestPosting(ironMq);
            //TestReservation(ironMq);
            //TestDeletingReservedMessage(ironMq);

            // Get message by id without reservation
            TestGettingMessageById(ironMq);

            // Get message without reserving it
            TestPeekingMessage(ironMq);

            // Delete unreserved message
            TestDeletingMessage(ironMq);

            // Touch message to prolongate reservation
            TestTouching(ironMq);

            // Touch message to prolongate reservation
            TestTouchingTwice(ironMq);

            // Release reserved message
            TestReleasing(ironMq);

            // Delete a bunch of messages
            TestDeletingMessages(ironMq);

            // Get subscriber's URL
            TestGettingSubscribersInfo(ironMq);

            // =========================================================
            // Iron.io Worker
            // =========================================================

            Console.WriteLine("Be sure to create a 'Test' worker before running this sample");
            Console.WriteLine("Press ANY key to continue");
            Console.Read();

            IronWorkerRestClient workerClient = IronSharp.IronWorker.Client.New();

            string taskId = workerClient.Tasks.Create("Test", new { Key = "Value" });

            Console.WriteLine("TaskID: {0}", taskId);

            TaskInfoCollection taskInfoCollection = workerClient.Tasks.List("Test");

            foreach (TaskInfo task in taskInfoCollection.Tasks)
            {
                Console.WriteLine(task.Inspect());
            }

            ScheduleOptions options = ScheduleBuilder.Build().
                                      Delay(TimeSpan.FromMinutes(1)).
                                      WithFrequency(TimeSpan.FromHours(1)).
                                      RunFor(TimeSpan.FromHours(3)).
                                      WithPriority(TaskPriority.Default);

            var payload = new
            {
                a = "b",
                c = new[] { 1, 2, 3 }
            };

            ScheduleIdCollection schedule = workerClient.Schedules.Create("Test", payload, options);

            Console.WriteLine(schedule.Inspect());

            workerClient.Schedules.Cancel(schedule.Schedules.First().Id);

            // =========================================================
            // Iron.io Cache
            // =========================================================

            IronCacheRestClient ironCacheClient = IronSharp.IronCache.Client.New();

            // Get a Cache object
            CacheClient cache = ironCacheClient.Cache("my_cache");

            // Put value to cache by key
            cache.Put("number_item", 42);

            // Get value from cache by key
            Console.WriteLine(cache.Get("number_item").Value);

            // Get value from cache by key
            Console.WriteLine(cache.Get <int>("number_item"));

            // Numbers can be incremented
            cache.Increment("number_item", 10);

            // Immediately delete an item
            cache.Delete("number_item");

            cache.Put("complex_item", new { greeting = "Hello", target = "world" });

            // Get value from cache by key
            Console.WriteLine(cache.Get("complex_item").Value);

            cache.Delete("complex_item");

            Console.WriteLine("============= Done ==============");
            Console.Read();
        }