BrightstarDB.Models.EventFeed.EventFeedService.RaiseEvent C# (CSharp) Метод

RaiseEvent() публичный Метод

Creates a new event and also connects it to all users that are subscribed to any of the topics it is classified by.
public RaiseEvent ( string description, System.DateTime when, IEnumerable topicIds, object>.Dictionary eventProperties = null ) : void
description string Event description
when System.DateTime Date when the event occured
topicIds IEnumerable A list of the topic ids that classify this event
eventProperties object>.Dictionary A name value collection of all event properties
Результат void
        public void RaiseEvent(string description, DateTime when, IEnumerable<string> topicIds, Dictionary<string, object> eventProperties = null)
        {
            try {
                // create a new event
                var ctx = new EventFeedContext(_connectionString);
                var e = ctx.Events.Create();
                e.Description = description;
                e.Occurred = when;
                var topics = new List<ITopic>();
                foreach (var topicId in topicIds)
                {
                    var topic = ctx.Topics.Where(t => t.Id.Equals(topicId)).ToList().FirstOrDefault();
                    if (topic != null)
                    {
                        topics.Add(topic);

                        // get all the subscribers
                        foreach (var subscriber in topic.Subscribers)
                        {
                            subscriber.Events.Add(e);
                        }
                    }
                }
                e.Topics = topics;

                ctx.SaveChanges();

                if (eventProperties != null)
                {
                    // use a dynamic object to store all the other properties
                    var dynaStore = GetDynaStore();
                    var dynaEvent = dynaStore.GetDataObject(e.Id);

                    foreach (var key in eventProperties.Keys)
                    {
                        dynaEvent[key] = eventProperties[key];
                    }
                    dynaStore.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error in RasieEvent", ex);
            }
        }

Usage Example

Пример #1
0
        public void TestEventData()
        {
            var storeId = Guid.NewGuid().ToString();
            var eventService = new EventFeedService(storeId);

            // create a topic first that can be subscribed to, this topic could have been 'found' by search or be
            // a well known topic.
            eventService.AssertTopic(new Uri("http://www.brightstardb.com/topics/34"), "Topic 34", "A very important topic");
            eventService.AssertSubscriber("domain\\bob", new List<Uri>() { new Uri("http://www.brightstardb.com/topics/34") });
            eventService.RaiseEvent("Bob created document Y",
                                    DateTime.UtcNow,
                                    new List<string> { "http://www.brightstardb.com/topics/34" },
                                    new Dictionary<string, object> { {"Type", "DocumentEvent"},{ "DocumentUrl", "http://sharepoint.brightstardb.com/file1.docx"}});

            var events = eventService.GetTopicTimeline("http://www.brightstardb.com/topics/34", DateTime.MinValue);
            Assert.AreEqual(1, events.Count());

            // get event
            var ev = events.ToList()[0];
            var eventData = eventService.GetEventData(ev);
            Assert.AreEqual("http://sharepoint.brightstardb.com/file1.docx", eventData.DocumentUrl.FirstOrDefault());
        }
All Usage Examples Of BrightstarDB.Models.EventFeed.EventFeedService::RaiseEvent