public static void LoadProvider(List <IZeroconfProvider> list, string path) { Assembly asm = Assembly.GetExecutingAssembly(); string basePath = asm.Location; string absPath = Path.Combine(Path.GetDirectoryName(basePath), path); Assembly provider_asm = Assembly.LoadFile(absPath); Console.Write("Loading {0} zeroconf provider: ", path); 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(); list.Add(provider); Console.WriteLine("OK"); } catch (Exception e) { Console.WriteLine("FAILED"); } } } }
private static void LoadAsm(List <IZeroconfProvider> providers_list, string this_asm_path, string file) { 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); } } } } }
public RegisterService(IZeroconfProvider provider = null) { ProviderFactory.SelectedProvider = provider; register_service = (IRegisterService)Activator.CreateInstance( ProviderFactory.SelectedProvider.RegisterService); }
public TxtRecord(IZeroconfProvider provider = null) { ProviderFactory.SelectedProvider = provider; record = (ITxtRecord)Activator.CreateInstance(ProviderFactory.SelectedProvider.TxtRecord); }
private static IZeroconfProvider [] GetProviders() { if (providers != null) { return(providers); } var providers_list = new List <IZeroconfProvider>(); var directories = new List <string>(); var asm = Assembly.GetExecutingAssembly(); char path_delimiter = ( Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) ? ':' : ';'; string env_path = Environment.GetEnvironmentVariable("MONO_ZEROCONF_PROVIDERS"); if (!String.IsNullOrEmpty(env_path)) { foreach (string path in env_path.Split(path_delimiter)) { if (Directory.Exists(path)) { directories.Add(path); } } } string this_asm_path = asm.Location; directories.Add(Path.GetDirectoryName(this_asm_path)); if (Assembly.GetExecutingAssembly().GlobalAssemblyCache) { string [] path_parts = directories[0].Split(Path.DirectorySeparatorChar); string new_path = Path.DirectorySeparatorChar.ToString(); string root = Path.GetPathRoot(this_asm_path); if (root.StartsWith(path_parts[0])) { path_parts[0] = root; } for (int i = 0; i < path_parts.Length - 4; i++) { new_path = Path.Combine(new_path, path_parts[i]); } directories.Add(Path.Combine(new_path, "mono-zeroconf")); } 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); } } } } } } if (providers_list.Count == 0) { throw new Exception("No Zeroconf providers could be found or initialized. Necessary daemon may not be running."); } providers = providers_list.ToArray(); return(providers); }
public ServiceBrowser (IZeroconfProvider provider = null) { ProviderFactory.SelectedProvider = provider; browser = (IServiceBrowser)Activator.CreateInstance (ProviderFactory.SelectedProvider.ServiceBrowser); }