Files
win8phoneApp/CampusAppWP8/CampusAppWPortalLib8/Model/GeoDb/PlaceModel.cs
2013-10-22 14:01:48 +02:00

233 lines
8.1 KiB
C#

//-----------------------------------------------------------------------
// <copyright file="PlaceModel.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 place model class</summary>
//-----------------------------------------------------------------------
namespace CampusAppWPortalLib8.Model.GeoDb
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using CampusAppWPortalLib8.Model.Utility;
using CampusAppWPortalLib8.Resources;
using CampusAppWPortalLib8.Utility;
/// <summary> Model for a place of the SPSService. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
/// <seealso cref="T:System.IEquatable{CampusAppWP8.Model.GeoDb.PlaceModel}"/>
public class PlaceModel : IEquatable<PlaceModel>
{
#region Property
/// <summary> Gets or sets the placeId. </summary>
/// <value> The identifier of the place. </value>
[XmlAttribute("id")]
public string PlaceId { get; set; }
/// <summary> Gets or sets the id of the "parent" of a place. </summary>
/// <value> The identifier of the parent. </value>
[XmlAttribute("parentId")]
public string ParentId { get; set; }
/// <summary> Gets or sets the ReferencePoint of a place. </summary>
/// <value> The reference point. </value>
[XmlAttribute("refpoint")]
public string RefPoint { get; set; }
/// <summary> Gets or sets the information. </summary>
/// <value> The information. </value>
[XmlElement("placeInformation")]
public ObservableCollection<PlaceInformation> Informations { get; set; }
/// <summary> Gets or sets the services. </summary>
/// <value> The services. </value>
[XmlElement("placeService")]
public ObservableCollection<PlaceService> Services { get; set; }
/// <summary>
/// Gets or sets a string, which is the caption of the place (e.g. for contents of UIElements)
/// </summary>
/// <value> The caption. </value>
public string Caption { get; set; }
/// <summary> Gets the geo reference point. </summary>
/// <value> The geo reference point. </value>
public GeoMapPoint GeoRefPoint
{
get
{
string refstring = this.RefPoint;
Regex rx = new Regex(Constants.Regex_Coordinate);
MatchCollection matches = rx.Matches(refstring);
if (matches.Count != 1)
{
return null;
}
string[] values = matches[0].ToString().Split(' ');
if (values.Length != 2)
{
return null;
}
// create the GeoCoordirate
try
{
return new GeoMapPoint(double.Parse(values[1], CultureInfo.InvariantCulture), double.Parse(values[0], CultureInfo.InvariantCulture), 0);
}
catch (Exception ex)
{
Logger.LogException(ex);
return null;
}
}
}
#endregion
#region Method
/// <summary> Converts this object to a nfc string. </summary>
/// <remarks> Stubbfel, 21.08.2013. </remarks>
/// <returns> This object as a string. </returns>
public string ToNfcString()
{
string nfcStr = "{\n\"url\":\"http://www.tu-cottbus.de/campusapp\",\n\"pid\":\"" + this.PlaceId + "\",\n\"parent\":\"" + this.ParentId + "\"\n}";
return nfcStr;
}
/// <summary> Tests if this PlaceModel is considered equal to another. </summary>
/// <remarks> Stubbfel, 09.09.2013. </remarks>
/// <param name="other"> The place model to compare to this object. </param>
/// <returns> true if the objects are considered equal, false if they are not. </returns>
public bool Equals(PlaceModel other)
{
if (other.PlaceId.Equals(this.PlaceId))
{
return true;
}
return false;
}
/// <summary> Adds a place information. </summary>
/// <remarks> Stubbfel, 09.09.2013. </remarks>
/// <param name="placeInformations"> The place information. </param>
public void AddPlaceInformations(List<PlaceInformation> placeInformations)
{
foreach (PlaceInformation info in placeInformations)
{
if (this.Informations.Contains(info))
{
int index = this.Informations.IndexOf(info);
this.Informations[index].InformationValue = info.InformationValue;
}
else
{
this.Informations.Add(info);
}
}
}
/// <summary> Adds a place services. </summary>
/// <remarks> Stubbfel, 09.09.2013. </remarks>
/// <param name="placeServices"> The place services. </param>
public void AddPlaceServices(List<PlaceService> placeServices)
{
foreach (PlaceService service in placeServices)
{
if (this.Services.Contains(service))
{
int index = this.Services.IndexOf(service);
this.Services[index].Request = service.Request;
this.Services[index].SAP = service.SAP;
}
else
{
this.Services.Add(service);
}
}
}
/// <summary> Query if 'names' contains information names. </summary>
/// <remarks> Stubbfel, 09.09.2013. </remarks>
/// <param name="names"> The names. </param>
/// <returns> true if it succeeds, false if it fails. </returns>
public bool ContainsInformationNames(List<string> names)
{
foreach (string name in names)
{
bool tmpResult = false;
foreach (PlaceInformation info in this.Informations)
{
if (name.Equals(info.InformationName))
{
tmpResult = true;
break;
}
}
if (!tmpResult)
{
return tmpResult;
}
}
return true;
}
/// <summary> Query if 'services' contains service names. </summary>
/// <remarks> Stubbfel, 09.09.2013. </remarks>
/// <param name="services"> The services. </param>
/// <returns> true if it succeeds, false if it fails. </returns>
public bool ContainsServiceNames(List<string> services)
{
foreach (string name in services)
{
bool tmpResult = false;
foreach (PlaceService service in this.Services)
{
if (name.Equals(service.ServiceName))
{
tmpResult = true;
break;
}
}
if (!tmpResult)
{
return tmpResult;
}
}
return true;
}
/// <summary> Method gets the InformationValue of a certain InformationName. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
/// <param name="key"> string for InformationName. </param>
/// <returns> value of the information. </returns>
public string GetInformationsValue(string key)
{
foreach (PlaceInformation info in this.Informations)
{
if (info.InformationName.Equals(key))
{
return info.InformationValue;
}
}
return null;
}
#endregion
}
}