I am trying to made windows phone application with offline routing. I have found that It is possible by using Bing API.
I have registered and got the key, but I can't find, how can I use the key.
I am using following code:
private async void Button_Click(object sender, RoutedEventArgs e)
{
RouteQuery query = new RouteQuery();
List<GeoCoordinate> wayPoints = new List<GeoCoordinate>();
wayPoints.Add(new GeoCoordinate(47.23449, -121.172447));
wayPoints.Add(new GeoCoordinate(47.062638, -120.691795));
query.Waypoints = wayPoints;
query.QueryCompleted += geoQ_QueryCompleted;
query.QueryAsync();
}
private void geoQ_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
try
{
Route myRoute = e.Result;
MessageBox.Show("Completed");
}
catch (TargetInvocationException)
{
/// Unauthorized access exception 0x8004231C
Thread.Sleep(1000); // waiting for completing the query
geoQ_QueryCompleted(sender, e);
}
}
But I am getting Unauthorized access exception 0x8004231C.
I would like to ask you, how can I fix it?
You don't need the key to show offline map. If you have map downloaded on your device, then offline routing should work. You can see the sample to get more details.
Following is the quote from msdn sample,
However, mapping services also work without Internet connectivity when maps are downloaded for offline use.
Related
I have been working on a Softphone project in c# and have been using Ozeki VoIP SDK.
So far I have got the softphone successfully registering and making outbound calls. However, I can not hear the called party but they can hear me. (Me being the softphone and called party being a Cisco SPA504G Phone)
2-Way audio is fine when using other applications (Such as X-Lite)
The SIP Trace shows I am sending but not receiving any RTP packages, is this something I have done wrong in my code (See below) or an issue on the PBX side. (Thirdlane PBX)
void CreateCall()
{
string numberToDial = txtNum.Text;
logOutput("Call " + numberToDial);
txtLog.ScrollToCaret();
call = softphone.CreateCallObject(phoneLine, numberToDial);
call.CallStateChanged += call_CallStateChanged;
call.Start();
}
private void SetupDevices()
{
connector.Connect(microphone, mediaSender);
connector.Connect(mediaReceiver, speaker);
mediaSender.AttachToCall(call);
mediaReceiver.AttachToCall(call);
microphone.Start();
speaker.Start();
}
void call_CallStateChanged(object sender, CallStateChangedArgs e)
{
if (e.State == CallState.Answered)
{
WireUpCallEvents();
}
if (e.State == CallState.Completed)
{
WireDownCallEvents();
}
logOutput("Call state: " + e.State);
}
private void WireUpCallEvents()
{
call.CallStateChanged += (call_CallStateChanged);
SetupDevices();
}
private void WireDownCallEvents()
{
call.CallStateChanged -= (call_CallStateChanged);
}
After trying another extension on another PBX I found that the issue was caused by the additional setting "nat" not being set. Once I set this with the value "yes" I was able to get 2-way audio on both parties.
This was a Thridlane PBX so the setting was in "Selected Tenants PBX" => "Extensions and Contacts" => "User Extensions" => (The extension number I was using) => Phone.
I'm using PCSC library for SmartCard Readers events detection and trying to use it in Windows service.
Readers search function:
private void CheckPresentReaders()
{
using (var context = new SCardContext())
{
context.Establish(SCardScope.System);
PresentCardReaders = context.GetReaders();
}
}
SmartCard removed function:
private void SCardRemoved(object sender, CardStatusEventArgs e)
{
WriteToLog("Locking machine. SmartCard was removed.");
// LockWorkStation();
}
Monitor creation:
CheckPresentReaders();
if (PresentCardReaders.Length != 0)
{
SCardMonitor monitor = new SCardMonitor(ContextFactory.Instance, SCardScope.System);
monitor.CardRemoved += new CardRemovedEvent(SCardRemoved);
foreach (string reader in PresentCardReaders)
monitor.Start(reader);
}
WriteToLog function is a simple Log Entry creation function.
When it is compiled - service starting and then stopping immediately.
I have two suspects - not delegated WriteToLog and/or SCardRemoved, which requires two parameters -
(object sender, CardStatusEventArgs e)
Those are required by library.
Can this be a problem? Any other suggestions?
Thanks.
I've implemented it properly into Topshelf Service and it does work.
https://github.com/35359595/SmartCardMonitorService
I recently bought a Lilypad Simblee BLE Board and I'd like to pair it programmatically to my computer (using the 32feet.NET library in C#).
I'm aware the "How to programmatically pair a bluetooth device" has already been asked on StackOverflow (here for example), however for some reason, all my attempts to pair the device programmatically have failed. Indeed, I successfully paired the device with the "Manage Bluetooth devices" window in Windows 10 Settings panel (Settings > Devices > Bluetooth).
Firstly, I don't know the pairing method (either legacy or SSP) to use with my device. Windows never asked me for a PIN or something, so I guess it's SSP, but I'm unsure.
I searched on Google how to do a SSP pairing request with 32feet.NET: I found this.
However, once it discovered my device (the device discovery works properly), the pairing request instantly fails.
My code:
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Sockets;
using System;
using System.Collections.Generic;
namespace HLK_Client
{
class HLKBoard
{
public event HLKBoardEventHandler HLKBoardConnectionComplete;
public delegate void HLKBoardEventHandler(object sender, HLKBoardEventArgs e);
private BluetoothClient _bluetoothClient;
private BluetoothComponent _bluetoothComponent;
private List<BluetoothDeviceInfo> _inRangeBluetoothDevices;
private BluetoothDeviceInfo _hlkBoardDevice;
private EventHandler<BluetoothWin32AuthenticationEventArgs> _bluetoothAuthenticatorHandler;
private BluetoothWin32Authentication _bluetoothAuthenticator;
public HLKBoard()
{
_bluetoothClient = new BluetoothClient();
_bluetoothComponent = new BluetoothComponent(_bluetoothClient);
_inRangeBluetoothDevices = new List<BluetoothDeviceInfo>();
_bluetoothAuthenticatorHandler = new EventHandler<BluetoothWin32AuthenticationEventArgs>(_bluetoothAutenticator_handlePairingRequest);
_bluetoothAuthenticator = new BluetoothWin32Authentication(_bluetoothAuthenticatorHandler);
_bluetoothComponent.DiscoverDevicesProgress += _bluetoothComponent_DiscoverDevicesProgress;
_bluetoothComponent.DiscoverDevicesComplete += _bluetoothComponent_DiscoverDevicesComplete;
}
public void ConnectAsync()
{
_inRangeBluetoothDevices.Clear();
_hlkBoardDevice = null;
_bluetoothComponent.DiscoverDevicesAsync(255, true, true, true, false, null);
}
private void PairWithBoard()
{
Console.WriteLine("Pairing...");
bool pairResult = BluetoothSecurity.PairRequest(_hlkBoardDevice.DeviceAddress, null);
if (pairResult)
{
Console.WriteLine("Success");
}
else
{
Console.WriteLine("Fail"); // Instantly fails
}
}
private void _bluetoothComponent_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
{
_inRangeBluetoothDevices.AddRange(e.Devices);
}
private void _bluetoothComponent_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e)
{
for (int i = 0; i < _inRangeBluetoothDevices.Count; ++i)
{
if (_inRangeBluetoothDevices[i].DeviceName == "HLK")
{
_hlkBoardDevice = _inRangeBluetoothDevices[i];
PairWithBoard();
return;
}
}
HLKBoardConnectionComplete(this, new HLKBoardEventArgs(false, "Didn't found any \"HLK\" discoverable device"));
}
private void _bluetoothAutenticator_handlePairingRequest(object sender, BluetoothWin32AuthenticationEventArgs e)
{
e.Confirm = true; // Never reach this line
}
}
}
Why does the pairing request fail?
The answer to the question you linked has a plausible suggestion... did you read it?
Also you should look at this question as well.
32feet library is built around legacy pairing, so that you either need to know the pin of the device you are connecting to, or you supply it with a null to get a popup window to enter a pin.
It also says that the windows function used by 32feet is deprecated in newer versions of windows. If that's true, the reason it's failing instantly is because you've passed a null pin in your pairing request and for it to proceed windows needs to show a dialog which no longer exists.
What happens if you try to connect with the pin "0000" or "1234" ?
I'm looking at the source code of WindowsBluetoothSecurity.cs in 32feet.net and I see if a pairing request fails, it logs the error code to Debug.WriteLine, any chance you could post that error code here?
One good work around to this problem might be to import BluetoothAuthenticateDeviceEx and use that manually to complete the pairing request. If you don't want to do this manually, it looks like in the latest version of the 32feet source, there is actually a SSP pairing method that utilises this method but it's not public and it's not used anywhere so you'll need to access it via reflection:
typeof(BluetoothSecurity)
.GetMethod("PairRequest", BindingFlags.Static | BindingFlags.NonPublic)
.Invoke(null, new object[] { _hlkBoardDevice.DeviceAddress, BluetoothAuthenticationRequirements.MITMProtectionNotRequired });
I'm trying to show a route from point-to-point on the bing-maps (testing on real device). I've entered 2 waypoints (GeoCoordinate) and I'm trying to get the route via the Windows PhoneToolKit using the await query.GetRouteAsync(). Unfortunately, I'm getting an unknown error:
The result of the async call:
'e.Result' threw an exception of type 'System.Reflection.TargetInvocationException'
The inner exception:
Exception from HRESULT: 0x8004231C
I've checked the MSDN website and noticed that this errorcode is not listed in the errorlist...
The related code is below. I've used the exact same code as in the sample set of the Windows Phone Toolkit, but removed the things which has nothing to do with getting the route:
private async void BtnShowRoute_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
try
{
RouteQuery query = new RouteQuery();
List<GeoCoordinate> wayPoints = new List<GeoCoordinate>();
wayPoints.Add(new GeoCoordinate(47.23449, -121.172447));
wayPoints.Add(new GeoCoordinate(47.062638, -120.691795));
query.Waypoints = wayPoints;
Route route = await query.GetRouteAsync();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
}
I have no idea what is going wrong here. Does anyone else experienced this issue? If so, did you resolve it? And how?
Note: I'm running Windows Phone 8.1. Dev Preview
This happens when the underlying service call times out before completing the query. Hopefully this will be fixed in next version , but for now you can use following code:
private async void BtnShowRoute_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
RouteQuery query = new RouteQuery();
List<GeoCoordinate> wayPoints = new List<GeoCoordinate>();
wayPoints.Add(new GeoCoordinate(47.23449, -121.172447));
wayPoints.Add(new GeoCoordinate(47.062638, -120.691795));
query.Waypoints = wayPoints;
query .QueryCompleted += geoQ_QueryCompleted;
query.GetRouteAsync();
}
private void geoQ_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
try
{
Route myRoute = e.Result;
}
catch (TargetInvocationException)
{
Thread.Sleep(1000); // waiting for completing the query
geoQ_QueryCompleted(sender, e);
}
}
I'm trying to get a raw push notification to work from Azure Mobile Services to Windows Phone 8.
I've only signed up with Windows Azure for the free mobile services which comes with the free 20mb database and free mobile services.
The site to manage Windows Azure services has a link to an example of how to send a push notification to an app to update a flip tile which can be found here.
On insert into a table a script runs which sends the notification.
There's another example on MSDN which provides an example of how to create an ASP page that sends a raw notification to a WP8 app. That example is here.
I've gotten both examples to work but I need the first example to send a raw notification instead so the code in the second example works.
This is the code I have:
In my Windows Phone 8 app I have this to receive notifications, in App.xaml.cs:
private void AcquirePushChannel()
{
/// Holds the push channel that is created or found.
HttpNotificationChannel pushChannel;
// The name of our push channel.
string channelName = "RawSampleChannel";
// Try to find the push channel.
pushChannel = HttpNotificationChannel.Find(channelName);
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
// Register for all the events before attempting to open the channel.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
pushChannel.Open();
}
else
{
// The channel was already open, so just register for all the events.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
// Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
//MessageBox.Show(String.Format("Channel Uri is {0}",
// pushChannel.ChannelUri.ToString()));
}
}
void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
// Display the new URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
MessageBox.Show(String.Format("Channel Uri is {0}",
e.ChannelUri.ToString()));
});
}
void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
{
// Error handling logic for your particular application would be here.
Deployment.Current.Dispatcher.BeginInvoke(() =>
MessageBox.Show(String.Format("A push notification {0} error occurred. {1} ({2}) {3}",
e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData))
);
}
/// <summary>
/// Event handler for when a raw notification arrives. For this sample, the raw
/// data is simply displayed in a MessageBox.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void PushChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
{
string message;
using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body))
{
message = reader.ReadToEnd();
}
Deployment.Current.Dispatcher.BeginInvoke(() =>
MessageBox.Show(String.Format("Received Notification {0}:\n{1}",
DateTime.Now.ToShortTimeString(), message))
);
}
In Application Launching it calls AcquirePushChannel:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
AcquirePushChannel();
}
My issue is in my Windows Azure Mobile Services database, where I have the following code on insert to a table to send the raw push notification, which doesn't work:
function insert(item, user, request) {
request.execute({
success: function () {
// Write to the response and then send the notification in the background
request.respond();
// for testing I'm manually putting in the channel ID where it says <channelID> below
push.mpns.sendRaw(<channelID>,
'test', {
success: function (pushResponse) {
console.log("Sent push:", pushResponse);
}
});
}
});
}
There is doc on this here, so I'm sure it's correct, but it just doesn't work.
And there's an example here.
One other question is, how can I view console.log via Windows Azure?
I was able to find out from the logs that my code wasn't sending the notification and worked out that it was my method of testing which was causing it and so I've fixed it. I've found out that the insert script only fires when I use the code:
private MobileServiceCollection<TodoItem, TodoItem> items;
private IMobileServiceTable<TodoItem> todoTable = App.MobileService.GetTable<TodoItem>();
private async void InsertTodoItem(TodoItem todoItem)
{
// This code inserts a new TodoItem into the database. When the operation completes
// and Mobile Services has assigned an Id, the item is added to the CollectionView
await todoTable.InsertAsync(todoItem);
items.Add(todoItem);
}
The insert script for example doesn't run if you use Management Studio and insert a row manually.