237 lines
8.0 KiB
C#
237 lines
8.0 KiB
C#
//-----------------------------------------------------------------------
|
|
// <copyright file="SpsModel.cs" company="BTU/IIT">
|
|
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
|
|
// </copyright>
|
|
// <author>Stubbfel</author>
|
|
// <date>15.10.2013</date>
|
|
// <summary>Implements the sps model class</summary>
|
|
//-----------------------------------------------------------------------
|
|
namespace CampusAppWPortalLib8.Model.GeoDb
|
|
{
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Xml.Serialization;
|
|
|
|
/// <summary> Model for a xml-response of the SPSService. </summary>
|
|
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
|
/// <typeparam name="T"> Generic type parameter. </typeparam>
|
|
[XmlRoot("root")]
|
|
public class SpsModel
|
|
{
|
|
#region Constructor
|
|
|
|
/// <summary> Initializes a new instance of the SpsModel class. </summary>
|
|
/// <remarks> Stubbfel, 20.08.2013. </remarks>
|
|
public SpsModel()
|
|
{
|
|
this.HasChanged = false;
|
|
this.Places = new ObservableCollection<PlaceModel>();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Property
|
|
|
|
/// <summary> Gets or sets a list of places. </summary>
|
|
/// <value> The places. </value>
|
|
[XmlElement("place")]
|
|
public ObservableCollection<PlaceModel> Places { get; set; }
|
|
|
|
/// <summary> Gets or sets a value indicating whether this object has changed. </summary>
|
|
/// <value> true if this object has changed, false if not. </value>
|
|
public bool HasChanged { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
#region public
|
|
|
|
/// <summary> Gets places by information. </summary>
|
|
/// <remarks> Stubbfel, 19.08.2013. </remarks>
|
|
/// <param name="query"> The query. </param>
|
|
/// <param name="ignoreCases"> (Optional) the ignore cases. </param>
|
|
/// <param name="informationNames"> (Optional) name of the information. </param>
|
|
/// <returns> The places by information. </returns>
|
|
public List<PlaceModel> GetPlacesByInformation(string query, bool ignoreCases = true, List<string> informationNames = null)
|
|
{
|
|
string querryStr = string.Empty;
|
|
List<PlaceModel> resultplaces = new List<PlaceModel>();
|
|
|
|
foreach (PlaceModel place in this.Places)
|
|
{
|
|
if (this.IsPlaceQueryMatched(place, query, ignoreCases, informationNames))
|
|
{
|
|
resultplaces.Add(place);
|
|
}
|
|
}
|
|
|
|
return resultplaces;
|
|
}
|
|
|
|
/// <summary> Adds the places. </summary>
|
|
/// <remarks> Stubbfel, 09.09.2013. </remarks>
|
|
/// <param name="places"> A list of places. </param>
|
|
public void AddPlaces(List<PlaceModel> places)
|
|
{
|
|
foreach (PlaceModel place in places)
|
|
{
|
|
if (this.Places.Contains(place))
|
|
{
|
|
int index = this.Places.IndexOf(place);
|
|
this.Places[index].AddPlaceInformations(place.Informations.ToList());
|
|
this.Places[index].AddPlaceServices(place.Services.ToList());
|
|
}
|
|
else
|
|
{
|
|
this.Places.Add(place);
|
|
}
|
|
}
|
|
|
|
this.HasChanged = true;
|
|
}
|
|
|
|
/// <summary> Creates PID list. </summary>
|
|
/// <remarks> Stubbfel, 09.09.2013. </remarks>
|
|
/// <returns> The new PID list. </returns>
|
|
public List<string> CreatePidList()
|
|
{
|
|
List<string> pidList = new List<string>();
|
|
foreach (PlaceModel place in this.Places)
|
|
{
|
|
pidList.Add(place.PlaceId);
|
|
}
|
|
|
|
return pidList;
|
|
}
|
|
|
|
/// <summary> Gets place by identifier. </summary>
|
|
/// <remarks> Stubbfel, 09.09.2013. </remarks>
|
|
/// <param name="id"> The identifier. </param>
|
|
/// <returns> The place by identifier. </returns>
|
|
public PlaceModel GetPlaceById(string id)
|
|
{
|
|
foreach (PlaceModel place in this.Places)
|
|
{
|
|
if (place.PlaceId.Equals(id))
|
|
{
|
|
return place;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary> Query if 'pidList' contains information names. </summary>
|
|
/// <remarks> Stubbfel, 09.09.2013. </remarks>
|
|
/// <param name="pidList"> List of pids. </param>
|
|
/// <param name="names"> The names. </param>
|
|
/// <returns> true if it succeeds, false if it fails. </returns>
|
|
public bool ContainsInformationNames(List<string> pidList, List<string> names)
|
|
{
|
|
foreach (string pid in pidList)
|
|
{
|
|
PlaceModel place = this.GetPlaceById(pid);
|
|
if (!place.ContainsInformationNames(names))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary> Query if 'pidList' contains service names. </summary>
|
|
/// <remarks> Stubbfel, 09.09.2013. </remarks>
|
|
/// <param name="pidList"> List of pids. </param>
|
|
/// <param name="names"> The names. </param>
|
|
/// <returns> true if it succeeds, false if it fails. </returns>
|
|
public bool ContainsServiceNames(List<string> pidList, List<string> names)
|
|
{
|
|
foreach (string pid in pidList)
|
|
{
|
|
PlaceModel place = this.GetPlaceById(pid);
|
|
if (!place.ContainsServiceNames(names))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary> Filter by PID. </summary>
|
|
/// <remarks> Stubbfel, 11.09.2013. </remarks>
|
|
/// <param name="pidList"> List of pids. </param>
|
|
/// <returns> filtered list of places. </returns>
|
|
public List<PlaceModel> FilterByPid(List<string> pidList)
|
|
{
|
|
List<PlaceModel> fitlerList = new List<PlaceModel>();
|
|
|
|
if (pidList == null || pidList.Count < 1)
|
|
{
|
|
return fitlerList;
|
|
}
|
|
|
|
foreach (PlaceModel place in this.Places)
|
|
{
|
|
if (pidList.Contains(place.PlaceId))
|
|
{
|
|
fitlerList.Add(place);
|
|
}
|
|
}
|
|
|
|
return fitlerList;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region private
|
|
|
|
/// <summary> Method check if a certain place matched by query string. </summary>
|
|
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
|
/// <param name="place"> the Place. </param>
|
|
/// <param name="query"> the Query. </param>
|
|
/// <param name="ignoreCases"> (Optional) the ignore cases. </param>
|
|
/// <param name="informationNames"> (Optional) name of the information. </param>
|
|
/// <returns> true if it match otherwise false. </returns>
|
|
private bool IsPlaceQueryMatched(PlaceModel place, string query, bool ignoreCases = true, List<string> informationNames = null)
|
|
{
|
|
string queryString = query;
|
|
if (ignoreCases)
|
|
{
|
|
queryString = query.ToLower();
|
|
}
|
|
|
|
bool allInfos = true;
|
|
if (informationNames != null && informationNames.Count > 0)
|
|
{
|
|
allInfos = false;
|
|
}
|
|
|
|
foreach (PlaceInformation info in place.Informations)
|
|
{
|
|
if (allInfos || informationNames.Contains(info.InformationName))
|
|
{
|
|
string infoVal = info.InformationValue;
|
|
if (ignoreCases)
|
|
{
|
|
infoVal = infoVal.ToLower();
|
|
}
|
|
|
|
if (infoVal.Contains(queryString))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
#endregion
|
|
#endregion
|
|
}
|
|
}
|