コード例 #1
0
ファイル: AddressEntry.cs プロジェクト: rcaelers/dbus-sharp
        public static AddressEntry Parse(string s)
        {
            AddressEntry entry = new AddressEntry ();

            string[] parts = s.Split (':');

            if (parts.Length < 2)
                throw new InvalidAddressException ("No colon found");
            if (parts.Length > 2)
                throw new InvalidAddressException ("Too many colons found");

            entry.Method = parts[0];

            foreach (string propStr in parts[1].Split (',')) {
                parts = propStr.Split ('=');

                if (parts.Length < 2)
                    throw new InvalidAddressException ("No equals sign found");
                if (parts.Length > 2)
                    throw new InvalidAddressException ("Too many equals signs found");

                if (parts[0] == "guid") {
                    try {
                        entry.GUID = UUID.Parse (parts[1]);
                    } catch {
                        throw new InvalidAddressException ("Invalid guid specified");
                    }
                    continue;
                }

                entry.Properties[parts[0]] = Unescape (parts[1]);
            }

            return entry;
        }
コード例 #2
0
        void OpenPrivate(string address)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            AddressEntry[] entries = Address.Parse(address);
            if (entries.Length == 0)
            {
                throw new Exception("No addresses were found");
            }

            int index = 0;

            while (index < entries.Length)
            {
                AddressEntry entry = entries[index++];

                Id = entry.GUID;
                try {
                    Transport = Transport.Create(entry);
                } catch {
                    if (index < entries.Length)
                    {
                        continue;
                    }
                    throw;
                }

                break;
            }

            isConnected = true;
        }
コード例 #3
0
        public TcpServer(string address)
        {
            AddressEntry[] entries = DBus.Address.Parse(address);
            AddressEntry   entry   = entries[0];

            if (entry.Method != "tcp")
            {
                throw new Exception();
            }

            string val;

            if (entry.Properties.TryGetValue("port", out val))
            {
                port = UInt32.Parse(val);
            }

            if (entry.GUID == UUID.Zero)
            {
                entry.GUID = UUID.Generate();
            }
            Id = entry.GUID;

            /*
             * Id = entry.GUID;
             * if (Id == UUID.Zero)
             *      Id = UUID.Generate ();
             */

            this.address = entry.ToString();
            //Console.WriteLine ("Server address: " + Address);
        }
コード例 #4
0
        public static AddressEntry Parse(string s)
        {
            AddressEntry entry = new AddressEntry();

            string[] parts = s.Split(':');

            if (parts.Length < 2)
            {
                throw new InvalidAddressException("No colon found");
            }
            if (parts.Length > 2)
            {
                throw new InvalidAddressException("Too many colons 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 InvalidAddressException("No equals sign found");
                    }
                    if (parts.Length > 2)
                    {
                        throw new InvalidAddressException("Too many equals signs found");
                    }

                    if (parts[0] == "guid")
                    {
                        try {
                            entry.GUID = UUID.Parse(parts[1]);
                        } catch {
                            throw new InvalidAddressException("Invalid guid specified");
                        }
                        continue;
                    }

                    entry.Properties[parts[0]] = Unescape(parts[1]);
                }
            }

            return(entry);
        }
コード例 #5
0
ファイル: Address.cs プロジェクト: AaltoNEPPI/dbus-sharp
        // (unix:(path|abstract)=.*,guid=.*|tcp:host=.*(,port=.*)?);? ...
        // or
        // autolaunch:
        public static AddressEntry[] Parse(string addresses)
        {
            if (addresses == null)
            {
                throw new ArgumentNullException(addresses);
            }

            List <AddressEntry> entries = new List <AddressEntry> ();

            foreach (string entryStr in addresses.Split(';'))
            {
                entries.Add(AddressEntry.Parse(entryStr));
            }

            return(entries.ToArray());
        }
コード例 #6
0
        public UnixServer(string address)
        {
            AddressEntry[] entries = DBus.Address.Parse(address);
            AddressEntry   entry   = entries[0];

            if (entry.Method != "unix")
            {
                throw new Exception();
            }

            string val;

            if (entry.Properties.TryGetValue("path", out val))
            {
                unixPath   = val;
                isAbstract = false;
            }
            else if (entry.Properties.TryGetValue("abstract", out val))
            {
                unixPath   = val;
                isAbstract = true;
            }

            if (String.IsNullOrEmpty(unixPath))
            {
                throw new Exception("Address path is invalid");
            }

            if (entry.GUID == UUID.Zero)
            {
                entry.GUID = UUID.Generate();
            }
            Id = entry.GUID;

            /*
             * Id = entry.GUID;
             * if (Id == UUID.Zero)
             *      Id = UUID.Generate ();
             */

            this.address = entry.ToString();
            //Console.WriteLine ("Server address: " + Address);
        }
コード例 #7
0
        internal void OpenPrivate(string address)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            AddressEntry[] entries = Address.Parse(address);
            if (entries.Length == 0)
            {
                throw new Exception("No addresses were found");
            }

            //TODO: try alternative addresses if needed
            AddressEntry entry = entries[0];

            Id          = entry.GUID;
            Transport   = Transport.Create(entry);
            isConnected = true;
        }
コード例 #8
0
        public WinServer(string address)
        {
            AddressEntry[] entries = DBus.Address.Parse(address);
            AddressEntry   entry   = entries[0];

            if (entry.Method != "win")
            {
                throw new Exception();
            }

            string val;

            if (entry.Properties.TryGetValue("path", out val))
            {
                pipePath = val;
            }

            if (String.IsNullOrEmpty(pipePath))
            {
                throw new Exception("Address path is invalid");
            }

            if (entry.GUID == UUID.Zero)
            {
                entry.GUID = UUID.Generate();
            }
            Id = entry.GUID;

            /*
             * Id = entry.GUID;
             * if (Id == UUID.Zero)
             *      Id = UUID.Generate ();
             */

            this.address = entry.ToString();
            Console.WriteLine("Server address: " + Address);
        }
コード例 #9
0
ファイル: Connection.cs プロジェクト: AaltoNEPPI/dbus-sharp
 public override void Open(AddressEntry entry)
 {
 }