Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class RegisterService : Service, IRegisterService
private IAvahiEntryGroup entry_group;

public event RegisterServiceEventHandler Response;

private string originalName;
private int retryNameModifier = 2;

public RegisterService ()
{
Expand Down Expand Up @@ -95,12 +98,22 @@ private void OnEntryGroupStateChanged (EntryGroupState state, string error)
switch (state) {
case EntryGroupState.Collision:
if (!OnResponse (ErrorCode.Collision)) {
throw new ApplicationException ();
if (originalName == null)
originalName = Name;

Name = originalName + " (" + retryNameModifier + ")";
retryNameModifier++;

Console.WriteLine("ZeroConf had a name collision, trying: " + Name);

Register();
//throw new ApplicationException ();
}
break;
case EntryGroupState.Failure:
if (!OnResponse (ErrorCode.Failure)) {
throw new ApplicationException ();
Console.WriteLine("Mono.ZeroConf failed to register name with AvahiDBus");
//throw new ApplicationException ();
}
break;
case EntryGroupState.Established:
Expand Down
38 changes: 21 additions & 17 deletions src/Mono.Zeroconf/Mono.Zeroconf.Providers/ProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,27 @@ private static IZeroconfProvider [] GetProviders()
}

foreach(string directory in directories) {
foreach(string file in Directory.GetFiles(directory, "Mono.Zeroconf.Providers.*.dll")) {
if(Path.GetFileName(file) != Path.GetFileName(this_asm_path)) {
Assembly provider_asm = Assembly.LoadFile(file);
foreach(Attribute attr in provider_asm.GetCustomAttributes(false)) {
if(attr is ZeroconfProviderAttribute) {
Type type = (attr as ZeroconfProviderAttribute).ProviderType;
IZeroconfProvider provider = (IZeroconfProvider)Activator.CreateInstance(type);
try {
provider.Initialize();
providers_list.Add(provider);
} catch (Exception e) {
Console.WriteLine (e);
}
}
}
}
}
try
{
foreach(string file in Directory.GetFiles(directory, "Mono.Zeroconf.Providers.*.dll")) {
if(Path.GetFileName(file) != Path.GetFileName(this_asm_path)) {
Assembly provider_asm = Assembly.LoadFile(file);
foreach(Attribute attr in provider_asm.GetCustomAttributes(false)) {
if(attr is ZeroconfProviderAttribute) {
Type type = (attr as ZeroconfProviderAttribute).ProviderType;
IZeroconfProvider provider = (IZeroconfProvider)Activator.CreateInstance(type);
try {
provider.Initialize();
providers_list.Add(provider);
} catch (Exception e) {
Console.WriteLine (e);
}
}
}
}
}
}
catch {}
}

if(providers_list.Count == 0) {
Expand Down