Exemplo n.º 1
0
        public void TestMethod1()
        {
            var s = SlackResponseFactory.CreateWhereIsResponse("Robson", "Vancouver Office", new Uri("https://slack-whereis.s3.ca-central-1.amazonaws.com/maps/saturna.png"), "Meeting Room", UseStatus.Available, "Available until 5:00 PM", floor: "16th Floor");

            var j = JsonConvert.SerializeObject(s);

            ExchangeProvider p = new ExchangeProvider(new ExchangeConfig()
            {
                Server = "https://exchange.absolute.com/ews/exchange.asmx", Domain = "absolute.com", Username = "******", Password = "******"
            });
            bool isAvailable = p.GetAvailability("*****@*****.**", out string details);
        }
Exemplo n.º 2
0
        private Func <CancellationToken, Task> GetTaskForSearch(string searchText, Uri callbackEndpoint, IServiceScopeFactory scopeFactory)
        {
            Func <CancellationToken, Task> myFunc = (cancellationToken) => {
                using (var scope = scopeFactory.CreateScope())
                {
                    var locationRepository = scope.ServiceProvider.GetService <ILocationRepository>();
                    var httpClientFactory  = scope.ServiceProvider.GetService <IHttpClientFactory>();

                    Console.WriteLine($"Starting search task for {searchText}");
                    var locations = locationRepository.GetLocationByName(searchText);
                    if (!locations.Any())
                    {
                        locations = locationRepository.GetLocationByTag(searchText);
                        if (!locations.Any())
                        {
                            SlackCallbackHelper.PostCallback(callbackEndpoint, httpClientFactory, $"I couldn't find {searchText}");
                            return(new Task(() => { }));
                        }
                    }

                    SimpleSlackBlockResponse r = new SimpleSlackBlockResponse();
                    r.AddBlock(new SectionBlock()
                    {
                        Text = new PlainSectionBlockText("I found the following:", true)
                    });
                    foreach (var location in locations)
                    {
                        bool   available           = false;
                        string availabilityDetails = " ";
                        if (location != null)
                        {
                            string locationType = "Other";
                            switch (location)
                            {
                            case MeetingRoom meetingRoom:
                                locationType = "Meeting Room";

                                if (meetingRoom.EmailAddress != null)
                                {
                                    try
                                    {
                                        available = _exchangeProvider.GetAvailability(meetingRoom.EmailAddress, out availabilityDetails);
                                    }
                                    catch (Exception ex)
                                    {
                                        _logger.LogError(ex, "Unable to obtain data from Exchange provider!");
                                    }
                                }
                                break;

                            case Employee employee:
                                locationType = "Employee";

                                if (employee.EmailAddress != null)
                                {
                                    try
                                    {
                                        available = _exchangeProvider.GetAvailability(employee.EmailAddress, out availabilityDetails);
                                    }
                                    catch (Exception ex)
                                    {
                                        _logger.LogError(ex, "Unable to obtain data from Exchange provider!");
                                    }
                                }
                                break;

                            case Department department:
                                locationType = "Department";
                                break;

                            default:
                                locationType = location.GetType().ToString();
                                break;
                            }

                            var s = SlackResponseFactory.CreateWhereIsResponse(location.Name, location.Office, location.MapImageUrl == null ? null : new Uri(location.MapImageUrl), locationType, availabilityDetails == " " ? UseStatus.None : (available ? UseStatus.Available : UseStatus.InUse), availabilityDetails, floor: location.Floor, thumbUrl: string.IsNullOrEmpty(location.LocationImageUrl) ? null : new Uri(location.LocationImageUrl));
                            //var s = SlackResponseFactory.CreateWhereIsResponse(location);
                            r.Append(s);
                        }
                    }
                    r.AddBlock(new DividerBlock()).AddBlock(new ContextBlock().AddElement(new MarkdownContextElement("For any questions or issues, contact <@Henry>")));
                    SlackCallbackHelper.PostCallback(callbackEndpoint, httpClientFactory, r);
                    return(new Task(() => { }));
                }
            };

            return(myFunc);
        }