Example #1
0
        public IList <Session> FindSessions(LuisResult result)
        {
            IList <Session> sessions = new List <Session>();
            SessionQuery    query    = new SessionQuery();
            IList <string>  topics   = new List <string>();

            foreach (EntityRecommendation entity in result.Entities)
            {
                if (entity.Type.Equals("Topic"))
                {
                    topics.Add(entity.Entity);
                }
                else if (entity.Type.Equals("Speaker"))
                {
                    query.Speaker = entity.Entity;
                }
                else if (entity.Type.Equals("Room"))
                {
                    query.Room = entity.Entity;
                }
                else if (entity.Type.Equals("Time"))
                {
                    var      localTimeZone    = TimeZoneInfo.Local.BaseUtcOffset;
                    var      mountainTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time").BaseUtcOffset;
                    var      timeZoneDiff     = localTimeZone.Subtract(mountainTimeZone);
                    DateTime eventDay         = new DateTime(2016, 06, 24, 0, 0, 0, DateTimeKind.Local);
                    int      tzDiff           = timeZoneDiff.Hours;
                    eventDay.AddHours(tzDiff);


                    DateTime timeResult = new DateTime();
                    //specific time
                    var validTime = DateTime.TryParse(entity.Entity, out timeResult);
                    if (validTime)
                    {
                        //Convert to Mountain time
                        timeResult = timeResult.AddHours(tzDiff);

                        //Convert to the Event Date
                        if (timeResult.Date.CompareTo(eventDay) != 0)
                        {
                            TimeSpan ts = eventDay - timeResult.Date;
                            // Difference in days
                            int differenceInDays = ts.Days;
                            timeResult = timeResult.AddDays(differenceInDays);
                        }

                        DateTimeOffset offset = new DateTimeOffset(timeResult.ToUniversalTime());
                        query.StartTime = offset.AddHours(-1);
                        query.EndTime   = offset.AddHours(1);
                    }
                }
            }
            query.Topics = topics;

            var svc = new AzureSearchService();

            sessions = svc.FindSessions(query);

            return(sessions);
        }