示例#1
0
        public void testUncompressWithSubdomainsAndTrailingSlash()
        {
            String testURL = "http://www.forums.google.com/";

            byte[] testBytes = { 0x00, (byte)'f', (byte)'o', (byte)'r', (byte)'u', (byte)'m', (byte)'s', (byte)'.', (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', 0x00 };
            Assert.AreEqual(testURL, UrlBeaconUrlCompressor.Uncompress(testBytes));
        }
示例#2
0
        public void testUncompressHttpsURLWithTrailingSlash()
        {
            String testURL = "https://www.radiusnetworks.com/";

            byte[] testBytes = { 0x01, (byte)'r', (byte)'a', (byte)'d', (byte)'i', (byte)'u', (byte)'s', (byte)'n', (byte)'e', (byte)'t', (byte)'w', (byte)'o', (byte)'r', (byte)'k', (byte)'s', 0x00 };
            Assert.AreEqual(testURL, UrlBeaconUrlCompressor.Uncompress(testBytes));
        }
示例#3
0
        public void testUncompressWithoutTLD()
        {
            String testURL = "http://xxx";

            byte[] testBytes = { 0x02, (byte)'x', (byte)'x', (byte)'x' };
            Assert.AreEqual(testURL, UrlBeaconUrlCompressor.Uncompress(testBytes));
        }
示例#4
0
        public void testUncompressWithDotInfoTLD()
        {
            String testURL = "http://google.info";

            byte[] testBytes = { 0x02, (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', 0x0b };
            Assert.AreEqual(testURL, UrlBeaconUrlCompressor.Uncompress(testBytes));
        }
示例#5
0
        public void testDecompressWithPath()
        {
            String testURL = "http://google.com/123";

            byte[] testBytes = { 0x02, (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', 0x00, (byte)'1', (byte)'2', (byte)'3' };
            Assert.AreEqual(testURL, UrlBeaconUrlCompressor.Uncompress(testBytes));
        }
示例#6
0
        public void testCompressWithDotCaTLDWithSlash()
        {
            String testURL = "http://google.ca/";

            byte[] expectedBytes = { 0x02, (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', (byte)'.', (byte)'c', (byte)'a', (byte)'/' };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
示例#7
0
        public void testCompressHttpsAndWWWInCaps()
        {
            String testURL = "HTTPS://WWW.radiusnetworks.com";

            byte[] expectedBytes = { 0x01, (byte)'r', (byte)'a', (byte)'d', (byte)'i', (byte)'u', (byte)'s', (byte)'n', (byte)'e', (byte)'t', (byte)'w', (byte)'o', (byte)'r', (byte)'k', (byte)'s', 0x07 };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
示例#8
0
        public void testCompressWithSubdomainsAndSlashesInPath()
        {
            String testURL = "http://www.forums.google.com/123/456";

            byte[] expectedBytes = { 0x00, (byte)'f', (byte)'o', (byte)'r', (byte)'u', (byte)'m', (byte)'s', (byte)'.', (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', 0x00, (byte)'1', (byte)'2', (byte)'3', (byte)'/', (byte)'4', (byte)'5', (byte)'6' };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
示例#9
0
        public void testCompressWithDotInfoTLD()
        {
            String testURL = "http://google.info";

            byte[] expectedBytes = { 0x02, (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', 0x0b };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
示例#10
0
        public void testCompressWithMoreSubdomains()
        {
            String testURL = "http://www.forums.developer.google.com/123";

            byte[] expectedBytes = { 0x00,
                                     Convert.ToByte('f'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('r'),
                                     Convert.ToByte('u'),
                                     Convert.ToByte('m'),
                                     Convert.ToByte('s'),
                                     Convert.ToByte('.'),
                                     Convert.ToByte('d'),
                                     Convert.ToByte('e'),
                                     Convert.ToByte('v'),
                                     Convert.ToByte('e'),
                                     Convert.ToByte('l'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('p'),
                                     Convert.ToByte('e'),
                                     Convert.ToByte('r'),
                                     Convert.ToByte('.'),
                                     Convert.ToByte('g'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('g'),
                                     Convert.ToByte('l'),
                                     Convert.ToByte('e'),
                                     0x00,
                                     Convert.ToByte('1'),
                                     Convert.ToByte('2'),
                                     Convert.ToByte('3') };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
示例#11
0
        protected virtual async void RangingBeaconsInRegion(object sender, ICollection <AltBeaconOrg.BoundBeacon.Beacon> beacons)
        {
            MvxTrace.TaggedTrace(TAG, "RangingBeaconsInRegion");

            if (beacons != null && beacons.Count > 0)
            {
                var foundBeacons = beacons.ToList();
                foreach (var beacon in foundBeacons)
                {
                    if (beacon.BeaconTypeCode == 0x10) //Eddystone URL
                    {
                        var url = UrlBeaconUrlCompressor.Uncompress(beacon.Id1.ToByteArray());
                        await BeaconsService.Instance.ActivateEddystoneUrl(url);
                    }
                    else if (beacon.BeaconTypeCode == 0x00) //Eddystone UID
                    {
                        var uid = beacon.Id1.ToString().Replace("0x", "") + beacon.Id2.ToString().Replace("0x", "");
                        await BeaconsService.Instance.ActivateEddystoneUrl(uid);
                    }
                    else if (beacon.BeaconTypeCode == 533) //iBeacon
                    {
                        await BeaconsService.Instance.ActivateiBeacon(
                            beacon.Id1.ToString().Replace("-", ""),
                            Int32.Parse(beacon.Id2.ToString()),
                            Int32.Parse(beacon.Id3.ToString())
                            );
                    }
                }
            }
        }
示例#12
0
        public void testUncompressWithSubdomainsAndSlashesInPath()
        {
            String testURL = "http://www.forums.google.com/123/456";

            byte[] testBytes = { 0x00, (byte)'f', (byte)'o', (byte)'r', (byte)'u', (byte)'m', (byte)'s', (byte)'.', (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', 0x00, (byte)'1', (byte)'2', (byte)'3', (byte)'/', (byte)'4', (byte)'5', (byte)'6' };
            Assert.AreEqual(testURL, UrlBeaconUrlCompressor.Uncompress(testBytes));
        }
示例#13
0
        public void testCompressEntireURLInCapsWithPath()
        {
            String testURL = "HTTPS://WWW.RADIUSNETWORKS.COM/C2HC48";

            byte[] expectedBytes = { 0x01, (byte)'r', (byte)'a', (byte)'d', (byte)'i', (byte)'u', (byte)'s', (byte)'n', (byte)'e', (byte)'t', (byte)'w', (byte)'o', (byte)'r', (byte)'k', (byte)'s', 0x00, (byte)'C', (byte)'2', (byte)'H', (byte)'C', (byte)'4', (byte)'8' };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
示例#14
0
        public void testCompressWithDomainInCaps()
        {
            String testURL = "http://GOO.GL/C2HC48";

            byte[] expectedBytes = { 0x02, (byte)'g', (byte)'o', (byte)'o', (byte)'.', (byte)'g', (byte)'l', (byte)'/', (byte)'C', (byte)'2', (byte)'H', (byte)'C', (byte)'4', (byte)'8' };
            String hexBytes      = bytesToHex(UrlBeaconUrlCompressor.Compress(testURL));

            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
示例#15
0
        public void testCompressWithDotCoTLD()
        {
            String testURL = "http://google.co";

            byte[] expectedBytes = { 0x02, (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', (byte)'.', (byte)'c', (byte)'o' };
            String hexBytes      = bytesToHex(UrlBeaconUrlCompressor.Compress(testURL));

            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
示例#16
0
        public void testCompressWithoutTLD()
        {
            String testURL = "http://xxx";

            byte[] expectedBytes = { 0x02,
                                     Convert.ToByte('x'),
                                     Convert.ToByte('x'),
                                     Convert.ToByte('x') };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
        public void TestDetectsUriBeacon()
        {
            //"https://goo.gl/hqBXE1"
            byte[]       bytes  = { 2, 1, 4, 3, 3, (byte)216, (byte)254, 19, 22, (byte)216, (byte)254, 0, (byte)242, 3, 103, 111, 111, 46, 103, 108, 47, 104, 113, 66, 88, 69, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            BeaconParser parser = new BeaconParser().SetBeaconLayout("s:0-1=fed8,m:2-2=00,p:3-3:-41,i:4-21v");

            Beacon uriBeacon = parser.FromScanData(bytes, -55, null, DateTime.UtcNow.Ticks);

            AssertEx.NotNull("UriBeacon should be not null if parsed successfully", uriBeacon);
            AssertEx.AreEqual("UriBeacon identifier length should be correct",
                              14,
                              uriBeacon.Id1.ToByteArray().Length);
            String urlString = UrlBeaconUrlCompressor.Uncompress(uriBeacon.Id1.ToByteArray());

            AssertEx.AreEqual("URL should be decompressed successfully", "https://goo.gl/hqBXE1", urlString);
        }
示例#18
0
        public void testCompressWithTrailingSlash()
        {
            String testURL = "http://google.com/123";

            byte[] expectedBytes = { 0x02,
                                     Convert.ToByte('g'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('g'),
                                     Convert.ToByte('l'),
                                     Convert.ToByte('e'),
                                     0x00,
                                     Convert.ToByte('1'),
                                     Convert.ToByte('2'),
                                     Convert.ToByte('3') };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
示例#19
0
        public void testCompressWithSubdomainsWithTrailingSlash()
        {
            String testURL = "http://www.forums.google.com/";

            byte[] expectedBytes = { 0x00,
                                     Convert.ToByte('f'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('r'),
                                     Convert.ToByte('u'),
                                     Convert.ToByte('m'),
                                     Convert.ToByte('s'),
                                     Convert.ToByte('.'),
                                     Convert.ToByte('g'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('g'),
                                     Convert.ToByte('l'),
                                     Convert.ToByte('e'),
                                     0x00 };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
示例#20
0
        public void testCompressHttpsURL()
        {
            String testURL = "https://www.radiusnetworks.com";

            byte[] expectedBytes = { 0x01,
                                     Convert.ToByte('r'),
                                     Convert.ToByte('a'),
                                     Convert.ToByte('d'),
                                     Convert.ToByte('i'),
                                     Convert.ToByte('u'),
                                     Convert.ToByte('s'),
                                     Convert.ToByte('n'),
                                     Convert.ToByte('e'),
                                     Convert.ToByte('t'),
                                     Convert.ToByte('w'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('r'),
                                     Convert.ToByte('k'),
                                     Convert.ToByte('s'),
                                     0x07 };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
示例#21
0
        public async void DidRangeBeaconsInRegion(ICollection <Beacon> beacons, Region region)
        {
            foreach (var beacon in beacons)
            {
                if (beacon.ServiceUuid == 0xfeaa && beacon.BeaconTypeCode == 0x10)
                {
                    // This is a Eddystone-URL frame
                    Uri url = new Uri(UrlBeaconUrlCompressor.Uncompress(beacon.Id1.ToByteArray()));
                    //lookup beacons:

                    if (url.Host == WhiteLabelConfig.BEACONHOST && url.PathAndQuery.StartsWith("/b/"))
                    {
                        //Console.WriteLine(url);
                        var shortcode = url.Segments.Last();

                        if (!_shortcodes.Contains(shortcode))
                        {
                            try
                            {
                                var shootid = await Bootlegger.BootleggerClient.GetEventFromShortcode(shortcode);

                                var shoot = await Bootlegger.BootleggerClient.GetEventInfo(shootid, new CancellationTokenSource().Token);

                                _shortcodes.Add(shortcode);
                                NearbyShoots.Add(shoot);
                                OnEventsFound?.Invoke();
                            }
                            catch
                            {
                                Console.WriteLine("Cant find shoot from shortcode");
                            }
                        }
                    }
                }
            }
        }
示例#22
0
        public async Task <bool> StartBroadcastingBle(Context context, Shoot ev)
        {
            //ask to turn on bluetooth:
            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.DefaultAdapter;

            var allprefs = context.GetSharedPreferences(WhiteLabelConfig.BUILD_VARIANT.ToLower(), FileCreationMode.Private);
            //var prefs = allprefs.Edit();
            var useble = allprefs.GetBoolean("ble-" + ev.id, true);

            //prefs.PutInt("ble_enable", currentversion);
            //prefs.Apply();
            if (!useble)
            {
                return(false);
            }

            if (mBluetoothAdapter.State == State.Off)
            {
                //ask to turn on:
                TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();
                var dialog = new Android.Support.V7.App.AlertDialog.Builder(context);
                dialog.SetTitle(Resource.String.enableble);
                dialog.SetMessage(Resource.String.blemessage);
                dialog.SetPositiveButton(Android.Resource.String.Yes, (o, e) =>
                {
                    tcs.SetResult(true);
                });

                dialog.SetNegativeButton(Android.Resource.String.No, (o, e) =>
                {
                    tcs.SetResult(false);
                });

                dialog.Show();

                var result = await tcs.Task;
                if (result)
                {
                    allprefs.Edit().PutBoolean("ble-" + ev.id, true).Apply();

                    //turn on ble
                    mBluetoothAdapter.Enable();
                    //need to wait for ble event saying its started here:
                    await Task.WhenAny(Task.Delay(3000), Task.Factory.StartNew(() =>
                    {
                        while (mBluetoothAdapter.State != State.On)
                        {
                            Task.Yield();
                        }
                    }));
                }
                else
                {
                    allprefs.Edit().PutBoolean("ble-" + ev.id, false).Apply();
                    return(false);
                }
            }

            var compat = BeaconTransmitter.CheckTransmissionSupported(context);

            if (compat == BeaconTransmitter.Supported)
            {
                try
                {
                    byte[] urlBytes = UrlBeaconUrlCompressor.Compress("https://" + WhiteLabelConfig.BEACONHOST + "/b/");// 91071");//+ev.offlinecode);
                    //HACK: remove line!
                    //ev.offlinecode = "91071";
                    List <byte> bytes = new List <byte>(urlBytes);
                    bytes.AddRange(Encoding.ASCII.GetBytes(ev.offlinecode));

                    urlBytes = bytes.ToArray();

                    Identifier        encodedUrlIdentifier = Identifier.FromBytes(urlBytes, 0, urlBytes.Length, false);
                    List <Identifier> identifiers          = new List <Identifier>();
                    identifiers.Add(encodedUrlIdentifier);
                    beacon = new Beacon.Builder()
                             .SetIdentifiers(identifiers)
                             .SetServiceUuid(0xfeaa)
                             .SetManufacturer(0x0118)
                             .SetBeaconTypeCode(0x10)
                             .SetTxPower(-59)
                             .Build();
                    BeaconParser beaconParser = new BeaconParser().SetBeaconLayout(BeaconParser.EddystoneUrlLayout);

                    beaconTransmitter = new BeaconTransmitter(context, beaconParser);

                    beaconTransmitter.StartAdvertising(beacon, this);
                }
                catch (MalformedURLException)
                {
                    Log.Debug("BOOTLEGGER", "That URL cannot be parsed");
                }
                return(true);
            }
            else
            {
                //not supported
                return(false);
            }
        }