public static AddressEntry[] ParseEntries(string addresses) { if (addresses == null) { throw new ArgumentNullException(nameof(addresses)); } List <AddressEntry> entries = new List <AddressEntry>(); foreach (string entryStr in addresses.Split(';')) { entries.Add(AddressEntry.Parse(entryStr)); } return(entries.ToArray()); }
public static AddressEntry Parse(string s) { AddressEntry entry = new AddressEntry(); string[] parts = s.Split(new[] { ':' }, 2); if (parts.Length < 2) { throw new FormatException("No colon found"); } entry.Method = parts[0]; if (parts[1].Length > 0) { foreach (string propStr in parts[1].Split(',')) { parts = propStr.Split('='); if (parts.Length < 2) { throw new FormatException("No equals sign found"); } if (parts.Length > 2) { throw new FormatException("Too many equals signs found"); } if (parts[0] == "guid") { try { entry.Guid = Guid.ParseExact(parts[1], "N"); } catch { throw new FormatException("Invalid guid specified"); } continue; } entry.Properties[parts[0]] = Unescape(parts[1]); } } return(entry); }
public static async Task <DBusConnection> ConnectAsync(ClientSetupResult connectionContext, Action <Exception> onDisconnect, CancellationToken cancellationToken, IEnumerable <IClientObjectProvider> clientProviders) { var _entries = AddressEntry.ParseEntries(connectionContext.ConnectionAddress); if (_entries.Length == 0) { throw new ArgumentException("No addresses were found", nameof(connectionContext.ConnectionAddress)); } Guid _serverId = Guid.Empty; IMessageStream stream = null; var index = 0; while (index < _entries.Length) { AddressEntry entry = _entries[index++]; _serverId = entry.Guid; try { stream = await Transport.ConnectAsync(entry, connectionContext, cancellationToken) .TimeoutAfter(connectionContext.InitialTimeout) .ConfigureAwait(false); } catch { if (index < _entries.Length) { continue; } throw; } break; } return(await CreateAndConnectAsync(stream, onDisconnect, clientProviders, true, connectionContext.InitialTimeout)); }