在我之前的一篇文章里曾经介绍过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的数据传输对象使用。
  1. namespace ChatRoom.Services.DTO
  2. {
  3.     /// <summary>
  4.     /// 用户信息(数据传输对象)
  5.     /// </summary>
  6.     [FluorineFx.TransferObject]
  7.     public class UserInfo
  8.     {
  9.         /// <summary>
  10.         /// 构造方法
  11.         /// </summary>
  12.         public UserInfo() { }

  13.         public int ID { get; set; }

  14.         public string UserName { get; set; }

  15.         public string NickName { get; set; }

  16.         public string Password { get; set; }

  17.         public string HeadImage { get; set; }
  18.     }
  19. }
复制代码
远程服务接口(DataService)提供了用户注册,登陆等最基本的通信接口方法,在了解通信接口之前首先学习一个工具类,该类的提供了一个将DataTable类型数据转话为IList<Object>类型返回,详细代码如下:
  1. namespace ChatRoom.Services.Utils
  2. {
  3.     public static class ConvertUtils
  4.     {
  5.         /// <summary>
  6.         /// 提供将DataTable类型对象转换为List集合
  7.         /// </summary>
  8.         /// <param name="table"></param>
  9.         /// <returns></returns>
  10.         public static List<T> ConvertToList<T>(DataTable table) where T : new()
  11.         {
  12.             //置为垃圾对象
  13.             List<T> list = null;

  14.             if (table != null)
  15.             {
  16.                 DataColumnCollection columns = table.Columns;
  17.                 int columnCount = columns.Count;
  18.                 T type = new T();
  19.                 Type columnType = type.GetType();
  20.                 PropertyInfo[] properties = columnType.GetProperties();

  21.                 if (properties.Length == columnCount)
  22.                 {
  23.                     list = new List<T>();
  24.                     foreach (DataRow currentRow in table.Rows)
  25.                     {
  26.                         for (int i = 0; i < columnCount; i++)
  27.                         {
  28.                             for (int j = 0; j < properties.Length; j++)
  29.                             {
  30.                                 if (columns.ColumnName == properties[j].Name)
  31.                                 {
  32.                                     properties[j].SetValue(type, currentRow, null);
  33.                                 }
  34.                             }
  35.                         }
  36.                         list.Add(type);
  37.                         type = new T();
  38.                     }
  39.                 }
  40.                 else
  41.                 {
  42.                     list = null;
  43.                 }
  44.             }
  45.             else
  46.             {
  47.                 throw new ArgumentNullException("参数不能为空");
  48.             }
  49.             return list;
  50.         }
  51.     }
  52. }
复制代码
TOP