Exemplo n.º 1
0
        public void PublishUpdate_SerializerCalled()
        {
            publisher.NotifyUpdate("A", "B");

            A.CallTo(() => _serializer.Serialize(
                         A <CacheUpdateNotificationArgs> .That.Matches(args => args.Key == "A" && args.Type == "B" && args.ClientName == "C")))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
Exemplo n.º 2
0
 public void Add <T>(string key, T item)
 {
     _database.StringSet(
         key,
         _itemSerializer.Serialize(item),
         _defaultTtl,
         When.Always,
         CommandFlags.FireAndForget);
 }
Exemplo n.º 3
0
        public void NotifyUpdate(string key, string type)
        {
            var data = _itemSerializer.Serialize(new CacheUpdateNotificationArgs {
                Key = key, Type = type, ClientName = _connection.ClientName
            });

            _connection.GetSubscriber().Publish(
                "cacheUpdate",
                data,
                CommandFlags.FireAndForget);
        }
Exemplo n.º 4
0
        public PublisherTests()
        {
            _connection = A.Fake <IConnectionMultiplexer>();
            _serializer = A.Fake <IItemSerializer>();
            _subscriber = A.Fake <ISubscriber>();

            A.CallTo(() => _connection.GetSubscriber(null)).Returns(_subscriber);
            A.CallTo(() => _connection.ClientName).Returns("C");
            A.CallTo(() => _serializer.Serialize(A <CacheUpdateNotificationArgs> .Ignored)).Returns(new byte[] { 1 });

            publisher = new RedisPublisher(_connection, _serializer);
        }
        public ActionResult Get(int take = -1, int skip = -1, float lat = 0, float lng = 0, string profiles = "", bool personalize = true)
        {
            try
            {
                // fetching profile names from the action parameter
                var profileNames = string.IsNullOrWhiteSpace(profiles) ? new string[0] : profiles.Split('|');
                // or loading from the tracker if not specified
                if (personalize && !profileNames.Any())
                {
                    profileNames = Tracker.Current.GetPopulatedProfilesFromTracker();
                }

                var allItems = dataService.GetAll(Context.Database, profileNames, take, skip, lat, lng, out int totalSearchResults);

                if (personalize)
                {
                    var scoredItems = itemScoringService.ScoreItems(allItems, Context.Database);
                    // return scored items only if anything was returned
                    if (scoredItems.Any())
                    {
                        allItems = scoredItems;
                    }
                }

                var events  = new JArray(allItems.Select(i => JObject.Parse(itemSerializer.Serialize(i))));
                var results = new JObject
                {
                    { "events", events },
                    { "total", totalSearchResults }
                };

                return(Content(results.ToString(), "application/json"));
            }
            catch (Exception ex)
            {
                Log.Error("Unable to retrieve events", ex, this);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemplo n.º 6
0
        public override void Serialize(Field field, JsonTextWriter writer)
        {
            Assert.ArgumentNotNull(field, nameof(field));
            Assert.ArgumentNotNull(writer, nameof(writer));

            using (RecursionLimit recursionLimit = new RecursionLimit(string.Format("{0}|{1}|{2}", GetType().FullName, field.Item.ID, field.ID), 1))
            {
                if (recursionLimit.Exceeded)
                {
                    return;
                }

                Item[] items = ((MultilistField)field).GetItems();
                if (items == null || items.Length == 0)
                {
                    writer.WritePropertyName(field.Name);
                    writer.WriteStartArray();
                    writer.WriteEndArray();
                }
                else
                {
                    writer.WritePropertyName(field.Name);
                    writer.WriteStartArray();
                    foreach (Item obj in items)
                    {
                        if (obj.IsDerived(productTemplateId))
                        {
                            continue;
                        }

                        writer.WriteStartObject();
                        writer.WritePropertyName("id");
                        writer.WriteValue(obj.ID.Guid.ToString());
                        writer.WritePropertyName("fields");
                        writer.WriteRawValue(ItemSerializer.Serialize(obj));
                        writer.WriteEndObject();
                    }
                    writer.WriteEndArray();
                }
            }
        }
Exemplo n.º 7
0
        public void RoundtripSerializeGeneric <T>(T input)
        {
            var result = serializer.Deserialize <T>(serializer.Serialize(input));

            result.ShouldBe(input);
        }
 public ActionResult Get(int take = 4)
 {
     try
     {
         var allItems     = dataService.GetAll(Context.Database);
         var scroredItems = itemScoringService.ScoreItems(allItems, Context.Database);
         var items        = new JArray(scroredItems.Take(take).Select(i => JObject.Parse(itemSerializer.Serialize(i))));
         return(Content(items.ToString(), "application/json"));
     }
     catch (Exception ex)
     {
         Log.Error("Unable to retrieve events", ex, this);
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
     }
 }