Esempio n. 1
0
        public async Task <String> calcPosition(String tagAddress, GeoCoordinate presentCoordinate, Boolean isConnected)
        {
            String addressName = tagAddress;
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            try
            {
                if (!isConnected)
                {
                    dBFacade.createLocalStorageNFCs(presentCoordinate.Latitude, presentCoordinate.Longitude, tagAddress);
                    return(tagAddress);
                }
                cancellationTokenSource.CancelAfter(10000);

                if (!cancellationTokenSource.IsCancellationRequested)
                {
                    Address address = await dBFacade.getAddress(tagAddress);

                    Debug.WriteLine("Address: " + address);
                    if (address == null)
                    {
                        return(null);
                    }
                    addressName = address.AddressName;
                    GeoCoordinate targetCoordinate = new GeoCoordinate(address.Latitude, address.Longtitude);
                    await getDistance(presentCoordinate, targetCoordinate, addressName);
                }
                else
                {
                    await getDistance(presentCoordinate, presentCoordinate, tagAddress);
                }
            }
            catch (OperationCanceledException ex)
            {
                Debug.WriteLine("cancellation token");
                Debug.WriteLine(ex.StackTrace);
            }
            return(addressName);
        }