private void connectToPc() { try { LogMessage("Connecting to PC..."); string imsi = m_MbnInterfaceManager.GetInterface(selectedInterfaceId).GetSubscriberInformation().SubscriberID; IMbnConnection connection = ((IMbnConnection[])m_MbnConnectionManager.GetConnections())[0]; string profileXml = String.Format( @"<MBNProfile xmlns='http://www.microsoft.com/networking/WWAN/profile/v1'> <Name>tempProfile</Name> <IsDefault>false</IsDefault> <SubscriberID>{0}</SubscriberID> <Context> <AccessString>ID{1}</AccessString> </Context> </MBNProfile>", imsi, txtAPN.Text); uint requestId; //connection connection.Connect(MBN_CONNECTION_MODE.MBN_CONNECTION_MODE_TMP_PROFILE, profileXml, out requestId); } catch (Exception ex) { LogMessage("Connect failed - " + ex.ToString()); LogMessage("Connect failed - " + ex.ToString()); } }
public void Connect(string subscriberText, string accessStringText, string userNameText, string passwordText) { try { bool connectionState = IsConnected(); string profileXml = ConstructProfileXml(subscriberText, accessStringText, userNameText, passwordText); if (connectionState) { rootPage.NotifyUser("Connection is activated and hence disconnect before connecting again", NotifyType.StatusMessage); } else { uint requestId = 0; m_MbnConnection.Connect( MBN_CONNECTION_MODE.MBN_CONNECTION_MODE_TMP_PROFILE, profileXml, out requestId); rootPage.NotifyUser("Waiting for Connect to complete for requestId: " + requestId.ToString() + " for following XML:\n" + profileXml, NotifyType.StatusMessage); } } catch (Exception e) { rootPage.NotifyUser(ParseExceptionCode(e), NotifyType.ErrorMessage); } }
void ExecuteAction(ActionType action) { IMbnInterfaceManager interfaceManager = null; IMbnInterface inf = null; IMbnSubscriberInformation subscriber = null; try { interfaceManager = (IMbnInterfaceManager) new MbnInterfaceManager(); inf = interfaceManager.GetInterface(InterfaceID); subscriber = inf.GetSubscriberInformation(); XmlDocument xml = new XmlDocument(); xml.LoadXml(mobileProfileTemplate); xml["MBNProfile"]["SubscriberID"].InnerText = subscriber.SubscriberID; xml["MBNProfile"]["SimIccID"].InnerText = subscriber.SimIccID; //Console.WriteLine("Profile: " + xml.OuterXml); IMbnConnection conn = null; try { conn = inf.GetConnection(); //MBN_ACTIVATION_STATE state; //string profile; //conn.GetConnectionState(out state, out profile); uint requestId; if (action == ActionType.Connect) { conn.Connect(MBN_CONNECTION_MODE.MBN_CONNECTION_MODE_TMP_PROFILE, xml.OuterXml, out requestId); } else { conn.Disconnect(out requestId); } } finally { if (conn != null) { Marshal.FinalReleaseComObject(conn); } } } finally { if (subscriber != null) { Marshal.FinalReleaseComObject(subscriber); } if (inf != null) { Marshal.FinalReleaseComObject(inf); } if (interfaceManager != null) { Marshal.FinalReleaseComObject(interfaceManager); } } }