WP7应用开发笔记(7) 配置和存储

配置

既然选择了TCP协议,那么从WP7手机连接到TCP服务器,必须要知道服务器的IP和端口。为了方便服务器端口使用固定的8012端口。

那么WP7至少需要在手机上存储IP地址字符串。

 

Windows Phone 本地数据存储

Windows Phone 应用程序可以使用独立存储将数据储存到手机本地。应用程序可以通过三种方式储存数据:

  1. 设置:使用 IsolatedStorageSettings 类将数据存储为键/值对。
  2. 文件和文件夹:使用 IsolatedStorageFile 类存储文件和文件夹。
  3. 本地数据库:7.1新增,只能支持LINQ TO SQL ,不能写SQL语句。

 

本地存储IP数据

因为我只需要存储一个IP地址,不用考虑,IsolatedStorageSettings是最佳选择。下面是一个包装封装类,看看IsolatedStorageSettings是如何使用的吧。

 public static class IPEndPointStorage

  {

        private const string Key = "ipaddress";

        public const int Port = 8012;



        public static string IPAddress

        {

            get

            {

                string ipAddress;

                return IsolatedStorageSettings.ApplicationSettings.TryGetValue(Key, out ipAddress) ? ipAddress : null;

            }

            set { IsolatedStorageSettings.ApplicationSettings[Key] = value; }

        }

}

你可能感兴趣的:(wp7)