private static string GetProviderAPN(string providerName) { if(providerName .Trim ()=="3") { return "ipc.three.com.hk"; } if (providerName.Trim().ToLower () == "cmhk") { return "CMHK"; } if (providerName.Trim().ToLower() == "smartone") { return "smartone"; } return string.Empty; }
private static string GetProfile(string PfName, string SubscriberID, string SimIccID, string HomeProviderName, string AccessString,string DisplayProviderName) { return $@"<?xml version=""1.0""?> <MBNProfile xmlns = ""http://www.microsoft.com/networking/WWAN/profile/v1""> <Name>{PfName}</Name> <IsDefault>true</IsDefault> <ProfileCreationType>UserProvisioned</ProfileCreationType> <SubscriberID>{SubscriberID}</SubscriberID> <SimIccID>{SimIccID}</SimIccID> <HomeProviderName>{HomeProviderName}</HomeProviderName> <ConnectionMode>auto</ConnectionMode> <Context> <AccessString>{AccessString}</AccessString> <Compression>DISABLE</Compression> <AuthProtocol>NONE</AuthProtocol> </Context> <DisplayProviderName xmlns = ""http://www.microsoft.com/networking/WWAN/profile/v2"">{DisplayProviderName}</DisplayProviderName> </MBNProfile> "; }
public static void AddProfile(string profileName) { try { XmlDocument xdoc = new XmlDocument(); string profileString = System.IO.File.ReadAllText(Path.Combine(pfFolder, profileName)); xdoc.LoadXml(profileString); string ProfileInfo = xdoc["MBNProfile"]["HomeProviderName"].InnerText +"/"+ xdoc["MBNProfile"]["Name"].InnerText +"/"+ xdoc["MBNProfile"]["SimIccID"].InnerText ; AddProfileWithXML(xdoc.OuterXml); Global.LogLocalThingsInfo($"AddProfile:{ProfileInfo}"); } catch(Exception ex ) { Global.LogLocalThingsError(ex); } } public static void AddProfileWithXML(string xml) { try { MbnConnectionProfileManager mbnConnProfileMgr = new MbnConnectionProfileManager(); IMbnConnectionProfileManager mbnConnProfileMgrInterface = mbnConnProfileMgr as IMbnConnectionProfileManager; mbnConnProfileMgrInterface.CreateConnectionProfile(xml); } catch (Exception ex) { Global.LogLocalThingsError(ex); } }
Calling:ide
if(!string.IsNullOrEmpty (HomeProviderName)) { uint id; string DisplayProviderName = "3"; string PfName = DisplayProviderName; string v = GetProfile(PfName, SubscriberID, SimIccID, HomeProviderName, AccessString, DisplayProviderName); System.IO.File.WriteAllText(Path.Combine(Network.pfFolder, PfName), v); message += " Pf is empty, Connect with new Profile:" + Environment.NewLine + v + Environment.NewLine; Network.AddProfile(PfName); conn.Connect(MBN_CONNECTION_MODE.MBN_CONNECTION_MODE_PROFILE, PfName, out id); }