Created
April 8, 2017 22:50
-
-
Save jakkaj/b42bb530d4152544a33bb4735a98f03f to your computer and use it in GitHub Desktop.
Azure Search Bot Session Entity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Arlo.SDK.Entities; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Arlo.SDK.Entities.Product; | |
using Microsoft.Azure.Search; | |
using Microsoft.Azure.Search.Models; | |
using System.ComponentModel.DataAnnotations; | |
using System.Globalization; | |
namespace SearchIndexer.SupportLibrary | |
{ | |
/// <summary> | |
/// Used to provide a strongly-typed object for the Search Service to index. | |
/// Azure Search requires a self-contained, serializable class with appropriate search attributes. | |
/// </summary> | |
[SerializePropertyNamesAsCamelCase] | |
class SessionFacade | |
{ | |
private static readonly DateTime? DEFAULT_START = new DateTime(2017, 2, 15); | |
private static readonly DateTime? DEFAULT_END = new DateTime(2017, 2, 17); | |
private static readonly IFormatProvider CULTURE_INFO = new CultureInfo("en-AU"); | |
//private static readonly TimeZoneInfo TIMEZONE = TimeZoneInfo.FindSystemTimeZoneById("E. Australia Standard Time"); | |
// UTC+10: Note no daylight saving! | |
//private static readonly TimeSpan TIME_ZONE = new TimeSpan(10, 0, 0); | |
public SessionFacade(ArloSession arloSession) | |
{ | |
this.SessionId = arloSession.SessionID; | |
this.Name = arloSession.Name; | |
this.StartDateTime = ConvertToDateTimeOffset(arloSession.StartDateTime, DEFAULT_START); | |
this.FinishDateTime = ConvertToDateTimeOffset(arloSession.FinishDateTime, DEFAULT_END); | |
this.SessionType = arloSession.SessionType; | |
this.Description = arloSession.Description; | |
this.Status = arloSession.Status; | |
this.Presenters = GetPresenters(arloSession.Presenters); | |
this.Room = arloSession.Room; | |
this.Code = arloSession.Code; | |
this.AdditionalInfo = ""; | |
// Need to ensure we're on Qld time, not TZ of Azure data centre | |
//this.LastIndexed = new DateTimeOffset(DateTime.Now, TIME_ZONE); | |
this.LastIndexed = new DateTimeOffset(DateTime.Now); | |
} | |
private DateTimeOffset? ConvertToDateTimeOffset(string input, DateTime? defaultDateTime) | |
{ | |
DateTime dateTime; | |
bool isParsed = false; | |
//isParsed = DateTime.TryParse(input, CULTURE_INFO, DateTimeStyles.AdjustToUniversal, out dateTime); | |
isParsed = DateTime.TryParse(input, CULTURE_INFO, DateTimeStyles.None, out dateTime); | |
if (!isParsed) | |
{ | |
this.StartDateTime = defaultDateTime; | |
} | |
//var dto = new DateTimeOffset(dateTime, TIME_ZONE); | |
return new DateTimeOffset(dateTime); | |
} | |
private IEnumerable<string> GetPresenters(List<ArloContact> presenters) | |
{ | |
return presenters.Select(presenter => | |
presenter == null ? string.Empty : presenter.FirstName + " " + presenter.LastName | |
).ToList(); | |
} | |
[Key] | |
[IsFilterable] | |
public string SessionId { get; set; } | |
[IsFilterable] | |
public DateTimeOffset? LastIndexed { get; set; } | |
[IsFilterable, IsSortable] | |
public string Name { get; set; } | |
[IsFilterable, IsFacetable, IsSortable] | |
public DateTimeOffset? StartDateTime { get; set; } | |
[IsFilterable, IsFacetable, IsSortable] | |
public DateTimeOffset? FinishDateTime { get; set; } | |
[IsFacetable, IsFilterable, IsSearchable] | |
public string SessionType { get; set; } | |
[IsSearchable] | |
[Analyzer(AnalyzerName.AsString.EnLucene)] | |
public string Description { get; set; } | |
public string Status { get; set; } | |
[IsSearchable, IsFacetable, IsFilterable] | |
[Analyzer(AnalyzerName.AsString.EnLucene)] | |
public IEnumerable<string> Presenters { get; set; } | |
[IsSearchable, IsFacetable] | |
public string Room { get; set; } | |
[IsSearchable, IsFilterable] | |
public string Code { get; set; } | |
[IsSearchable] | |
public string AdditionalInfo { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment