LiveConnectClient missing eventhandlers Live SDK 5.3 WP8 - c#

hi there :) il get right to it.
Problem :
when i try to instanciate LiveConnectClient and then try to access the event : GetCompleted
which supose to be in the LiveConnectClient is not showing and on all the examples i been looking at even those on here are using it. this is not the only class this is happening on it is also happening on LiveAuthClient as well no events even the post on the net says there should be.
i tried to reinstall Vs2012 and sdk wp8 and live sdk from scratch but have not solved it
for refrence i using this example to see if i can it to work :
//event triggered when Skydrive sign in status is changed
private void btnSignIn_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
{
//if the user is signed in
if (e.Status == LiveConnectSessionStatus.Connected)
{
session = e.Session;
client = new LiveConnectClient(e.Session);
infoTextBlock.Text = "Accessing SkyDrive...";
//get the folders in their skydrive
client.GetCompleted +=
new EventHandler<LiveOperationCompletedEventArgs>(btnSignin_GetCompleted);
client.GetAsync("me/skydrive/files?filter=folders,albums");
}
//otherwise the user isn't signed in
else
{
infoTextBlock.Text = "Not signed in.";
client = null;
}
}
i got no luck solving it and running out of ideas. So im hoping one of u boys out there can shed some light on it or lend a hand with dew wise words :)
thanks in advance. and i do apologies if this is to long a post.
regards jens

Indeed, it seems like those events have been removed in the latest versions of the SDK. You don't need them though, thanks to the async/await keywords. First, mark your method as async, then call the GetAsync method with the await keyword. And place afterward the code you would normally put in the GetCompleted event:
private async void btnSignIn_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
{
//if the user is signed in
if (e.Status == LiveConnectSessionStatus.Connected)
{
session = e.Session;
client = new LiveConnectClient(e.Session);
infoTextBlock.Text = "Accessing SkyDrive...";
//get the folders in their skydrive
var result = await client.GetAsync("me/skydrive/files?filter=folders,albums");
// Do here what you would normally do in btnSignin_GetCompleted
}
//otherwise the user isn't signed in
else
{
infoTextBlock.Text = "Not signed in.";
client = null;
}
}

Related

How to use Bluetooth in C#/.net?

I'm trying to do an UI with C# on Visual Studio (on PC[windows10]) and connect some bluetooth devices.
I'm using Windows.Devices.Radios & Windows.Devices.Bluetooth, but I have some troubles with that. After few steps I try to use the bluetooth when I press a button.
This is the code
private async void btnStart_ClickAsync(object sender, EventArgs e)
{
Repl test = new Repl();
var radio = await Radio.RequestAccessAsync();
if (access != RadioAccessStatus.Allowed)
{
return;
}
BluetoothAdapter adapter = await BluetoothAdapter.GetDefaultAsync();
if (null != adapter)
{
var btRadio = await adapter.GetRadioAsync();
if (bluetoothState)
{
await btRadio.SetStateAsync(RadioState.On);
}
else
{
await btRadio.SetStateAsync(RadioState.Off);
}
}
string connect = $"connect {macRight}\r\n";
//string start = "start\r\n";
await BaseCommands.repl.ParseLine(connect);
}
after the 1st request I'm always in the "return;"
I saw some people saying use x32 or x64 and x86. I already try that but I don't know why it doesn't work for me ...
I also saw some post saying change something in the Manifest, but I don't know where to find it :/
I'm a beginner with C#/.NET so if someone can help me to fix that i will appreciate =)
PS : I have another project which use bluetooth and it work perfectly so I have no ideas to fix my own project ...

How to programmatically pair a bluetooth device

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 });

Skype bot (translation from VB) not working

I was following a tutorial on youtube on how to create a simple Skype bot. It was written in VB and with my limited knowledge I did my best to recreate it in C#
I stumbled upon "handles" which I can only assume is related to the eventhandler in C#
This is the code I've got so far but when I message myself from another skype account it doesn't respond. I've made sure to accept the little popup on skype that allows 3rd party software.
public partial class Form1 : Form
{
Skype oSkype = new Skype();
string trigger = "!";
public Form1()
{
InitializeComponent();
oSkype.Attach(7, false);
oSkype.MessageStatus += new _ISkypeEvents_MessageStatusEventHandler(oSkype_MessageStatus);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void oSkype_MessageStatus(ChatMessage pMessage, TChatMessageStatus Status)
{
if (Status == TChatMessageStatus.cmsReceived || Status == TChatMessageStatus.cmsSent)
{
string msg = pMessage.Body;
Chat c = pMessage.Chat;
if (msg.StartsWith(trigger))
{
listBox1.Items.Add(DateTime.Now.ToLongTimeString() + ": " + pMessage.Sender.Handle + " sent you a message");
msg = msg.Remove(0, 1).ToLower();
if (msg == "test")
{
c.SendMessage("Test");
}
else
{
c.SendMessage("Unrecognizable command.");
}
}
}
}
}
The code from the tutorial that I was following had this instead:
oSkype_MessageStatus(pMessage as ChatMessage, Status as TChatMessageStatus) Handles oSkype.MessageStatus
The closest to what I could come to implement this in c# was to add the void to the eventhandler in public Form1() which you can see in my code.
Thanks in advance!
Skype4Com's chat functions are not supported in the newer Skype versions. They were deprecated somewhere in-between 2013-2014.
From Skype's blog post Feature evolution and support for the Skype Desktop API:
Iā€™m happy to share that we will be extending support for two of the most widely used features ā€“ call recording and compatibility with hardware devices ā€“ until we determine alternative options or retire the current solution. Although chat via third party applications, will cease to work as previously communicated.
It has been a while since I have worked with COM Skype bots, but your code seems to be fine.
Nevertheless, I would suggest you to move to a modern approach on bots. Please check out the new Microsoft Bot Framework

Trying to check if disconnected using System.Net.WebRequest

I'm developing a website in asp.net and c# which needs to catch if the user isn't connected when they press a button. So basically, if the user is connected, it will load up the GetList function, and if not a message will appear.
Code so far is...
protected void btnAlphabetical_Click(object sender, EventArgs e)
{
Session["Online"] = 0;
CheckConnect();
if ((int)Session["Online"] == 1) { GetList(); }
if ((int)Session["Online"] == 0) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "alertMessage", "alert('You are currently offline')", true); }
}
protected void CheckConnect()
{
System.Uri Url = new System.Uri("http://www.mywebsite.com/apicture.jpg?" + DateTime.Now);
System.Net.WebRequest WebReq;
System.Net.WebResponse Resp;
WebReq = System.Net.WebRequest.Create(Url);
try
{
Resp = WebReq.GetResponse();
Resp.Close();
WebReq = null;
Session["Online"] = 1;
}
catch
{
WebReq = null;
Session["Online"] = 0;
}
}
Basically, we set our Online session value to 0 and call the CheckConnect function. This gets a jpg that's already on the website and, if it can be loaded, sets our Online variable to 1. If it can't find it, it sets it to 0. When control returns to the main function (a button), we progress depending on what Online is - 1 or 0.
Trouble is, and I'm unsure whether this is more to do with my system settings than anything:
when we're online and getting something that DOES exist it works fine and GetList is fired
when we're online and getting something that DOESN'T exist (an invalid URL) it works fine and our message appears (GetList isn't fired)
HOWEVER, when we're offline and fire it, my browser (IE8) just goes to the regular "diagnose connection settings" screen
Is this my code, or part of IE8 in general? I can't use another browser as it's the one my company uses.
Thanks.
EDIT - the general purpose of this is to be used on mobile devices. The user will load up the page and make changes, then use the button. If connection is lost between the page being loaded and the user pressing the button, I don't want the user to lose their changes.

Mute microphone on Windows 7

I have an problem with muting the mic on an windows 7 machine. But all the code i have found dosen't run ore it's not doing anything the runned. Have is it done for an Windows 7 machine using C# code. I just need an on/off solution.
The DDL file works also with Win x64bit. But i thing that i creates an error another place.
mixers.Recording.Lines.GetMixerFirstLineByComponentType(
MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE).Volume = 0;
if (!mediaElement1.CheckAccess()) mediaElement1.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate { mediaElement1.Play(); });
if (MessageBox.Show("Incoming Call from: " + string.Format(e.RemoteParticipant), "Video Chat Call", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
mixers.Recording.Lines.GetMixerFirstLineByComponentType(
MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE).Volume = 1;
if (!mediaElement1.CheckAccess()) mediaElement1.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate { mediaElement1.Stop(); });
_currentConversation.StartVideo();
}'
If error occurs at if (MessageBox.Show("Incoming Call from: " + string.Format(e.RemoteParticipant), "Video Chat Call", MessageBoxButton.YesNo) == MessageBoxResult.Yes) and says {"Arithmetic operation resulted in an overflow."}
http://www.computercabal.com/2010/11/mute-microphone-from-c-on-windows.html -- this gentleman appears to have had a similar problem, and he's provided the source code for a solution.
You can use Audio Switcher Api
https://www.nuget.org/packages/AudioSwitcher.AudioApi.CoreAudio/4.0.0-alpha5
Code is quite simple:
private async void btnMute_ButtonClick(object sender, EventArgs e)
{
var audioController = new CoreAudioController();
var devices = await audioController.GetDevicesAsync(DeviceType.Capture, DeviceState.Active);
var device = devices.FirstOrDefault(x => x.IsDefaultDevice);
if(device != null) {
await device.SetMuteAsync(!device.IsMuted);
}
}
this might help: Windows Mixer Control in C#
Good luck :).
EDIT: It can also mute certain devices if I'm right.

Categories