Skip to content

Commit

Permalink
feat(ServiceProfile): AddProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jul 9, 2018
1 parent 2a496cd commit f5c666b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Spike/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ static void Main(string[] args)
Console.WriteLine("Multicast DNS spike");

// set logger factory
var properties = new Common.Logging.Configuration.NameValueCollection();
properties["level"] = "TRACE";
properties["showLogName"] = "true";
properties["showDateTime"] = "true";
var properties = new Common.Logging.Configuration.NameValueCollection
{
["level"] = "TRACE",
["showLogName"] = "true",
["showDateTime"] = "true"
};
LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(properties);

var mdns = new MulticastService
Expand Down
20 changes: 20 additions & 0 deletions src/ServiceProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,25 @@ public ServiceProfile(string instanceName, string serviceName, ushort port, IEnu
/// </para>
/// </remarks>
public List<ResourceRecord> Resources { get; set; } = new List<ResourceRecord>();

/// <summary>
/// Add a property of the service to the TXT record.
/// </summary>
/// <param name="key">
/// The name of the property.
/// </param>
/// <param name="value">
/// The value of the property.
/// </param>
public void AddProperty(string key, string value)
{
var txt = Resources.OfType<TXTRecord>().FirstOrDefault();
if (txt == null)
{
txt = new TXTRecord { Name = FullyQualifiedName };
Resources.Add(txt);
}
txt.Strings.Add(key + "=" + value);
}
}
}
15 changes: 15 additions & 0 deletions test/ServiceProfileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,20 @@ public void TXTRecords()
CollectionAssert.Contains(txt.Strings, "a=1");
CollectionAssert.Contains(txt.Strings, "b=2");
}

[TestMethod]
public void AddProperty()
{
var service = new ServiceProfile
{
InstanceName = "x",
ServiceName = "_sdtest._udp"
};
service.AddProperty("a", "1");

var txt = service.Resources.OfType<TXTRecord>().First();
Assert.AreEqual(service.FullyQualifiedName, txt.Name);
CollectionAssert.Contains(txt.Strings, "a=1");
}
}
}

0 comments on commit f5c666b

Please sign in to comment.