Example #1
0
        public static PublishedResource CreatePublishedResource(string name, string clientId, PublishedEvent eventData)
        {
            if (string.IsNullOrEmpty(name))
                return null;
            
            var eventType = GetPublishedEventType(name);
            var assembly = typeof(PublishedResource).Assembly;
            var resourceType = assembly.GetTypes()
                .Where(t => t.IsSubclassOf(typeof(PublishedResource)) && 
                    t.GetCustomAttributes(typeof(PublishedEventAttribute), false)
                    .Any(c => ((PublishedEventAttribute)c).Name == name))
                .FirstOrDefault();

            var resource = (PublishedResource)resourceType.GetConstructor(new Type[] {eventType}).Invoke(new object[] {eventData});
            if (resource == null)
                return null;

            resource.Id = Guid.NewGuid().ToString();
            resource.ClientId = clientId;
            resource.EventName = name;

            return resource;
        }
Example #2
0
        public static PublishedResource CreatePublishedResource(string name, string clientId, PublishedEvent eventData)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            var eventType    = GetPublishedEventType(name);
            var assembly     = typeof(PublishedResource).Assembly;
            var resourceType = assembly.GetTypes()
                               .Where(t => t.IsSubclassOf(typeof(PublishedResource)) &&
                                      t.GetCustomAttributes(typeof(PublishedEventAttribute), false)
                                      .Any(c => ((PublishedEventAttribute)c).Name == name))
                               .FirstOrDefault();

            var resource = (PublishedResource)resourceType.GetConstructor(new Type[] { eventType }).Invoke(new object[] { eventData });

            if (resource == null)
            {
                return(null);
            }

            resource.Id        = Guid.NewGuid().ToString();
            resource.ClientId  = clientId;
            resource.EventName = name;

            return(resource);
        }