Files
win8phoneApp/CampusAppWP8/CampusAppWPortalLib8/Model/GeoDb/CampusBuildingModel.cs
2013-10-21 15:04:24 +02:00

134 lines
4.2 KiB
C#

//-----------------------------------------------------------------------
// <copyright file="CampusBuildingModel.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 campus building model class</summary>
//-----------------------------------------------------------------------
namespace CampusAppWPortalLib8.Model.GeoDb
{
using System.Collections.Generic;
using CampusAppWPortalLib8.Resources;
/// <summary> Class is model for buildings of a campus. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
public class CampusBuildingModel<T, V>
where V : PlaceModel
where T : CampusBuildingLayerModel<V>, new()
{
#region constructor
public CampusBuildingModel()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="CampusBuildingModel" /> class.
/// </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
/// <param name="buildingId"> id of the building. </param>
/// <param name="places"> list of place which can be room of the buildings. </param>
public CampusBuildingModel(string buildingId, List<V> places)
{
this.BuildingId = buildingId;
this.AddLayers(places);
}
#endregion
#region Property
/// <summary> Gets the Layer of the building. </summary>
/// <value> The layers. </value>
public Dictionary<string, T> Layers { get; private set; }
/// <summary> Gets or sets the Building V. </summary>
/// <value> The building. </value>
public V Building { get; set; }
public string BuildingId { get; set; }
#endregion
#region method
public void AddLayers(List<V> places)
{
if (this.Layers == null)
{
this.Layers = new Dictionary<string, T>();
}
foreach (V place in places)
{
if (place.ParentId.Equals(this.BuildingId))
{
string placeLayerId = place.GetInformationsValue(Constants.PisInformationName_Layer);
if (placeLayerId == null)
{
continue;
}
if (this.Layers.ContainsKey(placeLayerId))
{
this.Layers[placeLayerId].Rooms.Places.Add(place);
}
else
{
T layer = new T() { LayerId = placeLayerId };
layer.AddsRooms(new List<V> { place });
this.Layers.Add(placeLayerId, layer);
}
}
else if (place.PlaceId.Equals(this.BuildingId))
{
this.Building = place;
}
}
}
/// <summary> Method gets a place by their placeID. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
/// <param name="placeID"> the placeId of the place. </param>
/// <returns> The place by identifier. </returns>
public V GetPlaceById(string placeID)
{
V result = null;
foreach (T layer in this.Layers.Values)
{
result = layer.Rooms.GetPlaceById(placeID);
if (result != null)
{
break;
}
}
return result;
}
/// <summary> Gets layer key. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
/// <param name="placeId"> Identifier for the place. </param>
/// <returns> The layer key. </returns>
public string GetLayerKey(string placeId)
{
V tmpPlace = null;
foreach (T layer in this.Layers.Values)
{
tmpPlace = layer.Rooms.GetPlaceById(placeId);
if (tmpPlace != null)
{
return layer.LayerId;
}
}
return null;
}
#endregion
}
}