Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            using (var setCache = new SetCache())
                using (var messageQueueReader = new MessageQueueReader <Visit>(new PushCampaignConfiguration(), item => DateTime.Now.ToString("u")))
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Title           = CONSOLE_TITLE;
                    Console.WriteLine($" [--- {CONSOLE_TITLE} ---]");
                    if (VERBOSE)
                    {
                        Console.WriteLine(" [*] Waiting for messages.");
                    }

                    var pushNotificationProviderFactory = new PushNotificationProviderFactory(Console.Out);
                    _campaignPusher = new CampaignPusher(setCache, pushNotificationProviderFactory);

                    var commandResult = await messageQueueReader.StartReadingAsync(HandleData);

                    if (commandResult.IsInvalid)
                    {
                        Console.WriteLine(" Error opening connection to read queue.");
                        Console.ReadLine();
                        return;
                    }

                    if (VERBOSE)
                    {
                        Console.WriteLine(" Press [enter] any time to exit.");
                    }
                    Console.ReadLine();
                }
        }
        public static void SetValue(T obj, String name, Object value)
        {
            Action <T, Object> d;

            if (SetCache.TryGetValue(name, out d))
            {
                d(obj, value);
            }
            var getDelg = CreateSetPropertyValueAction(name);

            SetCache[name] = getDelg;
            getDelg(obj, value);
        }
Ejemplo n.º 3
0
        public async Task CachedServiceClient_does_return_cached_ETag_Requests_Async()
        {
            var client = GetCachedServiceClient();

            var request = new SetCache { ETag = "etag", CacheControl = CacheControl.MustRevalidate };

            var response = await client.GetAsync(request);
            Assert.That(client.CacheHits, Is.EqualTo(0));
            Assert.That(response, Is.EqualTo(request));

            response = await client.GetAsync(request);
            Assert.That(client.CacheHits, Is.EqualTo(1));
            Assert.That(response, Is.EqualTo(request));
        }
Ejemplo n.º 4
0
        public static TProxy Set <TProxy, TValue>(this TProxy proxy, Expression <Func <TProxy, TValue> > property, TValue value)
        {
            // get property to assign
            var propExpression = property.Body.Unwrap() as MemberExpression;

            if (propExpression == null || !(propExpression.Member is PropertyInfo))
            {
                throw new ArgumentException("Expecting a property");
            }
            var prop = propExpression.Member as PropertyInfo;

            // check that given proxy is really a proxy
            var p = proxy as IProxy;

            if (p == null)
            {
                throw new NullReferenceException("Cannot set property " + prop.Name + ". Given object is not a proxy.");
            }

            // set the property
            SetCache <TProxy, TValue> .Setter(prop)(proxy, value);

            return(proxy);
        }
Ejemplo n.º 5
0
        public void CachedServiceClient_does_return_cached_LastModified_Requests()
        {
            var client = GetCachedServiceClient();

            var request = new SetCache { LastModified = new DateTime(2016, 1, 1, 0, 0, 0) };

            var response = client.Get(request);
            Assert.That(client.CacheHits, Is.EqualTo(0));
            Assert.That(response, Is.EqualTo(request));

            response = client.Get(request);
            Assert.That(client.CacheHits, Is.EqualTo(1));
            Assert.That(response, Is.EqualTo(request));
        }