在我之前的一篇文章里曾经介绍过FluorineFx的ApplicationAdapter的基本步骤,以及使用FluorineFx的ApplicationAdapter来开发及时通信应用的相关知识点。ApplicationAdapter应用最终需要部署到支持FluorineFx服务的Web应用(ASP.NET网站)上,如下图则表示了FluorineFx应用的目录结构。
附件:
FxAppRoom.jpg 对于使用过FluorineFx开发应用的朋友来说,这个图在熟悉不过了。要使用FluorineFx开发及时通信应用,项目结构就必须这样搭建,首先看看本篇案例的解决方案截图:
附件:
FxVideoChatProject.jpg 从上面的解决方案截图可以看到,整个项目由两部分构成,一个是FluorineFx的类库,封装了远程服务(RemotingService)接口和及时通信应用程序(ApplicationAdapter)。另一个则是FluorineFx网站(和ASP.NET网站没多大的区别,不同的是其中加入了FluorineFx的一些相关配置)。
为了方便演示案例本篇就直接使用的 Access做为数据库,根据数据库的字段结构建立了一个数据传输对象(DTO),同时为该DTO对象标记[FluorineFx.TransferObject],以使其可以作为FluorineFx的数据传输对象使用。
- namespace ChatRoom.Services.DTO
- {
- /// <summary>
- /// 用户信息(数据传输对象)
- /// </summary>
- [FluorineFx.TransferObject]
- public class UserInfo
- {
- /// <summary>
- /// 构造方法
- /// </summary>
- public UserInfo() { }
- public int ID { get; set; }
- public string UserName { get; set; }
- public string NickName { get; set; }
- public string Password { get; set; }
- public string HeadImage { get; set; }
- }
- }
复制代码远程服务接口(DataService)提供了用户注册,登陆等最基本的通信接口方法,在了解通信接口之前首先学习一个工具类,该类的提供了一个将DataTable类型数据转话为IList<Object>类型返回,详细代码如下:
- namespace ChatRoom.Services.Utils
- {
- public static class ConvertUtils
- {
- /// <summary>
- /// 提供将DataTable类型对象转换为List集合
- /// </summary>
- /// <param name="table"></param>
- /// <returns></returns>
- public static List<T> ConvertToList<T>(DataTable table) where T : new()
- {
- //置为垃圾对象
- List<T> list = null;
- if (table != null)
- {
- DataColumnCollection columns = table.Columns;
- int columnCount = columns.Count;
- T type = new T();
- Type columnType = type.GetType();
- PropertyInfo[] properties = columnType.GetProperties();
- if (properties.Length == columnCount)
- {
- list = new List<T>();
- foreach (DataRow currentRow in table.Rows)
- {
- for (int i = 0; i < columnCount; i++)
- {
- for (int j = 0; j < properties.Length; j++)
- {
- if (columns.ColumnName == properties[j].Name)
- {
- properties[j].SetValue(type, currentRow, null);
- }
- }
- }
- list.Add(type);
- type = new T();
- }
- }
- else
- {
- list = null;
- }
- }
- else
- {
- throw new ArgumentNullException("参数不能为空");
- }
- return list;
- }
- }
- }
复制代码