public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var links = new HashSet<Link>((IList<Link>)value, new LinkEqualityComparer());

            writer.WriteStartObject();

            var lookup = links.ToLookup(l => l.Rel);

            foreach (var rel in lookup)
            {
                writer.WritePropertyName(rel.Key);
                if (rel.Count() > 1)
                    writer.WriteStartArray();
                foreach (var link in rel)
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("href");
                    writer.WriteValue(ResolveUri(link.Href));

                    if (link.IsTemplated)
                    {
                        writer.WritePropertyName("templated");
                        writer.WriteValue(true);
                    }

                    writer.WriteEndObject();
                }
                if (rel.Count() > 1)
                    writer.WriteEndArray();
            }
            writer.WriteEndObject();
        }
Example #2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var links = new HashSet<Link>((IList<Link>)value, Link.EqualityComparer);
            var lookup = links.ToLookup(l => l.Rel);
            
            if (lookup.Count == 0) 
                return;

            writer.WriteStartObject();

            foreach (var rel in lookup)
            {
                var count = rel.Count();

                writer.WritePropertyName(rel.Key);
                
                if ((count > 1) || (rel.Key == Link.RelForCuries))
                    writer.WriteStartArray();

                foreach (var link in rel)
                    WriteLink(writer, link);

                if ((count > 1) || (rel.Key == Link.RelForCuries))
                    writer.WriteEndArray();
            }

            writer.WriteEndObject();
        }
		private void Initialize()
		{
			if (null == _consumingMethod)
				throw new InvalidOperationException("Consuming method has not been defined");

			if (!_assemblies.Any())
				throw new InvalidOperationException("There are no assemblies to scan");

			var types = _assemblies
				.SelectMany(a => {
				    try
				    {
				        return a.GetExportedTypes();
				    } catch{}
				    return new Type[0];
				}).Where(x=>x!=null)
				.ToList();

			var messageTypes = types.Where(x => !x.IsInterface && typeof(IMessage).IsAssignableFrom(x)).ToArray();
			var consumerTypes = types.Where(x => typeof(IConsume).IsAssignableFrom(x)).ToArray();

			var consumingDirectly = consumerTypes
				.SelectMany(consumerType =>
					GetConsumedMessages(consumerType)
						.Select(messageType => new MessageMapping(consumerType, messageType, true)))
				.ToArray();

			var result = new HashSet<MessageMapping>();

			foreach (var m in consumingDirectly)
			{
				result.Add(m);
			}
			var allMessages = result.Select(m => m.Message).ToList();
			foreach (var messageType in messageTypes)
			{
				if (!allMessages.Contains(messageType))
				{
					allMessages.Add(messageType);
					result.Add(new MessageMapping(typeof(MessageMapping.BusNull), messageType, true));
				}
			}

			_consumerInfos = result
				.GroupBy(x => x.Consumer)
				.Select(x =>
				{
					var directs = x
						.Where(m => m.Direct)
						.Select(m => m.Message)
						.Distinct();

					var assignables = x
						.Select(m => m.Message)
						.Where(t => directs.Any(d => d.IsAssignableFrom(t)))
						.Distinct();

					return new ConsumerInfo(x.Key, assignables.ToArray());
				}).ToList();


			_messageInfos = result
				.ToLookup(x => x.Message)
				.Select(x =>
				{
					var domainConsumers = x
						.Where(t => t.Consumer != typeof(MessageMapping.BusNull))
						.ToArray();

					return new MessageInfo
					{
						MessageType = x.Key,
						AllConsumers = domainConsumers.Select(m => m.Consumer).Distinct().ToArray(),
						DerivedConsumers = domainConsumers.Where(m => !m.Direct).Select(m => m.Consumer).Distinct().ToArray(),
						DirectConsumers = domainConsumers.Where(m => m.Direct).Select(m => m.Consumer).Distinct().ToArray(),
					};
				}).ToList();

			var includedTypes = _messageInfos
				.Select(m => m.MessageType).ToList();

			// message directory should still include all messages for the serializers
			var orphanedMessages = result
				.Where(m => !includedTypes.Contains(m.Message))
				.Select(m => new MessageInfo
				{
					MessageType = m.Message,
					AllConsumers = Type.EmptyTypes,
					DerivedConsumers = Type.EmptyTypes,
					DirectConsumers = Type.EmptyTypes
				});

			_messageInfos.AddRange(orphanedMessages);


		}
Example #4
0
 public void Remove(bool prompt)
 {
     var selectedViewNames = new HashSet<ViewName>(chooseViewsControl1.SelectedViews);
     if (selectedViewNames.Count == 0)
     {
         return;
     }
     string message;
     if (selectedViewNames.Count == 1)
     {
         message = string.Format(Resources.ManageViewsForm_BtnRemoveOnClick_Are_you_sure_you_want_to_delete_the_view___0___, selectedViewNames.First().Name);
     }
     else
     {
         message = string.Format(Resources.ManageViewsForm_BtnRemoveOnClick_Are_you_sure_you_want_to_delete_these__0__views_, selectedViewNames.Count);
     }
     if (prompt && ViewContext.ShowMessageBox(this, message, MessageBoxButtons.OKCancel) == DialogResult.Cancel)
     {
         return;
     }
     var namesByGroup = selectedViewNames.ToLookup(name => name.GroupId, name => name.Name);
     foreach (var grouping in namesByGroup)
     {
         ViewContext.DeleteViews(grouping.Key, grouping);
     }
     
 }
        public void NamespaceCasingConsistent()
        {
            var nameSpaces = new HashSet<string>();

            foreach (var type in Types)
            {
                nameSpaces.Add(type.Namespace);
                for (int i = 0; i < type.Namespace.Length; i++)
                {
                    if (type.Namespace[i] == '.')
                    {
                        nameSpaces.Add(type.Namespace.Substring(0, i));
                    }
                }

                foreach (var g in nameSpaces.ToLookup(s => s.ToUpperInvariant()))
                {
                    if (g.Count() > 1)
                    {
                        throw new Exception(string.Format("Found many casings {0}: {1}", g.Key, string.Join(",", g)));
                    }
                }
            }
        }