Ejemplo n.º 1
0
        //TODO move to base class.  Maybe also make 'virtual' AddSimpleServiceRecord method.
        static ServiceRecord CreateSimpleServiceRecord(Guid serviceClass, string serviceName)
        {
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();

            bldr.AddServiceClass(serviceClass);
            bldr.ServiceName = serviceName;
            var simpleSR = bldr.ServiceRecord;

            return(simpleSR);
        }
Ejemplo n.º 2
0
        public static ServiceRecordBuilder FromJsr82ServerUri(String url)
        {
            // srvString = protocol colon slashes srvHost 0*5(srvParams)
            // srvParams = name / master / encrypt / authorize / authenticate
            // text = 1*( ALPHA / DIGIT / SP / "-" / "_" )
            //
            ServiceRecordBuilder bldr = new ServiceRecordBuilder();
            const String         pattern
                = @"^([a-z0-9]+)"       //scheme
                  + "://localhost:"
                  + "([0-9a-fA-F]{32})" //uuid
                  //param(s)
                  + "(?:;([a-zA-Z]+)=([a-zA-Z0-9"
                  + " "    // space
                  + "_"    //underscore
                  + "\x2D" //hyphen
                  + "]+))*$"
                ;
            Match match = Regex.Match(url, pattern);

            if (!match.Success)
            {
                throw new ArgumentException("Invalid URI format.");
            }
            System.Diagnostics.Debug.Assert(match.Groups.Count >= 3,
                                            "Expect 2 non-optional groups, plus input pseudo group");
            String scheme  = match.Groups[1].Value;
            String classId = match.Groups[2].Value;

            //
            switch (scheme)
            {
            case "btl2cap":
                bldr.ProtocolType = BluetoothProtocolDescriptorType.L2Cap;
                break;

            case "btspp":
                bldr.ProtocolType = BluetoothProtocolDescriptorType.Rfcomm;
                break;

            case "btgoep":
                bldr.ProtocolType = BluetoothProtocolDescriptorType.GeneralObex;
                break;

            default:
                throw new ArgumentException("Unknown JSR82 URI scheme part.");
            }
            //
            Guid guid = new Guid(classId);

            bldr.AddServiceClass(guid);
            //
            for (int i = 3; i < match.Groups.Count; i += 2)
            {
                if ("NAME".Equals(match.Groups[i].Value.ToUpper(CultureInfo.InvariantCulture)))
                {
                    bldr.ServiceName = match.Groups[i + 1].Value;
                }
            }
            return(bldr);
        }