惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 司徒正美
宝玉的分享
宝玉的分享
美团技术团队
量子位
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
IT之家
IT之家
爱范儿
爱范儿
J
Java Code Geeks
博客园 - Franky
Last Week in AI
Last Week in AI
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
GbyAI
GbyAI
Recent Announcements
Recent Announcements
小众软件
小众软件
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog

博客园 - czh

基于MDB_ICP协议的纸币识别器与自动售货机通讯的研究 How could you login to ms sql server if you lost system admin password to setup windows auto-login Compile DLLs referenced into exe/dll 族谱软件系统的使用介绍 javascript在vs2003中调试随笔和javascript使用小总结[转载] 世界互联网正处于剧变前夜! 系统分析师 考试 DVD playable asp.net 页面事件:顺序与回传 创业还是读研? C#判断文件名是否合法 Window消息大全 关于STRONG NAME 好东西 一名25岁的董事长给大学生的18条忠告(不想虚度年华的进来) ZT SQL*PLUS命令的使用大全 如何做一个增加系统DSN的过程 ASP连接11种数据库语法总结
Mobile Network auto-Connection
czh · 2018-07-25 · via 博客园 - czh
        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:

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