public List <GroupInfo> GetGroups() { using (IDataQuery dataQuery = OpenQuery()) { List <GroupInfo> groups = dataQuery.Open <DAO.GroupInfo>().List().Select(dao => dao.ToObj()).ToList(); List <GroupChannelMap> map = dataQuery.Open <DAO.GroupChannelMap>().List().Select(dao => dao.ToObj()).ToList(); foreach (GroupInfo group in groups) { group.Channels = map.Where(x => x.GroupLINK == group.LINK).Where(x => x.ChannelLINK != null).Select(x => x.ChannelLINK.Value).ToArray(); } return(groups); } }
public List <ChannelInfo> GetChannels() { using (IDataQuery dataQuery = OpenQuery()) { return(dataQuery.Open <DAO.ChannelInfo>().List().Select(dao => dao.ToObj()).ToList()); } }
/// <summary> /// /// </summary> /// <returns></returns> public List <DAO.ServiceInfo> GetServiceInstances() { using (IDataQuery dataQuery = OpenQuery()) { return(dataQuery.Open <DAO.ServiceInfo>().List().ToList()); } }
public List <GroupChannelMap> GetGroupMap() { using (IDataQuery dataQuery = OpenQuery()) { return(dataQuery.Open <DAO.GroupChannelMap>().List().Select(dao => dao.ToObj()).ToList()); } }
/// <summary> /// /// </summary> /// <returns></returns> public List <Contact> GetContacts() { using (IDataQuery dataQuery = OpenQuery()) { return(dataQuery.Open <DAO.Contact>().List().Select(dao => dao.ToObj()).ToList()); } }
/// <summary> /// Выборка сообщений. /// </summary> /// <param name="dataQuery"></param> /// <returns></returns> public virtual IQueryOver <DAO.Message, DAO.Message> QueryMessages(IDataQuery dataQuery) { #region Validate parameters if (dataQuery == null) { throw new ArgumentNullException("dataQuery"); } #endregion return(dataQuery.Open <DAO.Message>()); }
/// <summary> /// /// </summary> /// <param name="channel"></param> /// <param name="status"></param> /// <param name="skip"></param> /// <param name="take"></param> /// <param name="totalCount"></param> /// <returns></returns> public virtual List <Message> GetLastMessages(string status, int?skip, int?take, out int totalCount) { using (IDataQuery dataQuery = OpenQuery()) { var query = dataQuery.Open <DAO.Message>(); //if (String.IsNullOrEmpty(channel)) // query.Where(msg => msg.Channel == null || msg.Channel == ""); //else if (channel != "*") // query.Where(msg => msg.Channel == channel); if (status == MessageStatus.DRAFT) { query.AndRestrictionOn(msg => msg.Status.Value).IsNull(); } else if (!String.IsNullOrWhiteSpace(status)) { string[] statuses = status.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); query.AndRestrictionOn(msg => msg.Status.Value).IsIn(statuses); } totalCount = query.RowCount(); //query = dataQuery.Open<DAO.Message>(); //if ( status == MessageStatus.DRAFT ) //{ // query.AndRestrictionOn(msg => msg.Status.Value).IsNull(); //} //else if ( !String.IsNullOrWhiteSpace(status) ) //{ // string[] statuses = status.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); // query.AndRestrictionOn(msg => msg.Status.Value).IsIn(statuses); //} if (skip != null && skip > 0) { query.Skip(skip.Value); } if (take != null) { query.Take(take.Value); } //if ( String.IsNullOrEmpty(channel) ) // query.Where(msg => msg.Channel == null || msg.Channel == ""); //else if ( channel != "*" ) // query.Where(msg => msg.Channel == channel); query.OrderBy(msg => msg.LINK).Desc(); return(query.List().Select(msg => msg.ToObj()).ToList()); } }
/// <summary> /// Сообщение по GUID и направлению. /// </summary> /// <param name="channel"></param> /// <param name="msgGuid"></param> /// <param name="direction"></param> /// <returns></returns> public virtual Message FindMessage(string msgGuid, string direction) { using (IDataQuery dataQuery = OpenQuery()) { var query = dataQuery.Open <DAO.Message>(); //if ( String.IsNullOrEmpty(channel) ) // query.Where(msg => msg.Channel == null || msg.Channel == ""); //else if ( channel != "*" ) // query.Where(msg => (msg.Channel == channel)); query.Where(msg => (msg.GUID == msgGuid && msg.Direction == direction)); return(query.SingleOrDefault().ToObj()); } }
/// <summary> /// /// </summary> /// <param name="begin"></param> /// <param name="end"></param> /// <returns></returns> public virtual List <DAO.DateStatMessage> GetMessagesByDate(DateTime?begin, DateTime?end) { using (IDataQuery dataQuery = OpenQuery()) { var query = dataQuery.Open <DAO.DateStatMessage>(); if (end != null) { query.Where(msg => msg.Date <= end); } if (begin != null) { query.Where(msg => msg.Date >= begin); } return(query.List().ToList()); } }
/// <summary> /// Выборка сообщений. /// </summary> /// <param name="queryParams">Параметры.</param> /// <returns></returns> public virtual List <Message> SelectMessages(QueryParams queryParams) { #region Validate parameters if (queryParams == null) { throw new ArgumentNullException("queryParams"); } if (String.IsNullOrEmpty(queryParams.Query)) { throw new ArgumentException("Отсутствует текст запроса.", "queryParams"); } #endregion using (IDataQuery dataQuery = OpenQuery()) { IQuery query; if (queryParams.Params is IDictionary <string, object> ) { query = dataQuery.Open(queryParams.Query); foreach (KeyValuePair <string, object> pair in (IDictionary <string, object>)queryParams.Params) { query.SetParameter(pair.Key, pair.Value); } } else if (queryParams.Params is IEnumerable <object> ) { query = dataQuery.Open(queryParams.Query); for (int i = 0; i < ((IEnumerable <object>)queryParams.Params).Count(); i++) { object value = ((IEnumerable <object>)queryParams.Params).ToArray()[i]; query.SetParameter(i, value); } } else if (queryParams.Params == null) { query = dataQuery.Open(queryParams.Query); } else { query = dataQuery.Open(queryParams.Query); query.SetProperties(queryParams.Params); } if (queryParams.Skip != null && queryParams.Skip > 0) { query.SetFirstResult(queryParams.Skip.Value); } if (queryParams.Take != null) { query.SetMaxResults(queryParams.Take.Value); } IList list = query.List(); if (list.Count == 0) { return(new List <Message>()); } else { if (list[0] is DAO.Message) { return(list.OfType <DAO.Message>().Select(msg => msg.ToObj()).ToList()); } else if (list[0] is Array) { return(list.OfType <object[]>().Select(arr => ((DAO.Message)arr[0]).ToObj()).ToList()); } else { return(new List <Message>()); } } } }