Esempio n. 1
0
        /// <summary>
        /// Initialize the instance.
        /// </summary>
        /// <param name="service">Service instance.</param>
        /// <param name="logger">Graph logger.</param>
        internal void Initialize(Service service, IGraphLogger logger)
        {
            Validator.IsNull(this.Logger, "Multiple initializations are not allowed.");

            this.Logger   = logger;
            this.Observer = new SampleObserver(logger);

            var builder      = new CommunicationsClientBuilder("AudioVideoPlaybackBot", service.Configuration.AadAppId, this.Logger);
            var authProvider = new AuthenticationProvider(
                service.Configuration.AadAppId,
                service.Configuration.AadAppSecret,
                this.Logger);

            builder.SetAuthenticationProvider(authProvider);
            builder.SetNotificationUrl(service.Configuration.CallControlBaseUrl);
            builder.SetMediaPlatformSettings(service.Configuration.MediaPlatformSettings);
            builder.SetServiceBaseUrl(service.Configuration.PlaceCallEndpointUrl);

            this.Client = builder.Build();
            this.Client.Calls().OnIncoming += this.CallsOnIncoming;
            this.Client.Calls().OnUpdated  += this.CallsOnUpdated;

            this.OnlineMeetings = new OnlineMeetingHelper(authProvider, service.Configuration.PlaceCallEndpointUrl);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Bot" /> class.
        /// </summary>
        /// <param name="options">The bot options.</param>
        /// <param name="graphLogger">The graph logger.</param>
        public Bot(BotOptions options, IGraphLogger graphLogger)
        {
            BotInstanceUri = CallAffinityMiddleware.GetWebInstanceCallbackUri(options.BotBaseUrl);

            var instanceNotificationUri = CallAffinityMiddleware.GetWebInstanceCallbackUri(
                new Uri(options.BotBaseUrl, HttpRouteConstants.OnIncomingRequestRoute));

            this.graphLogger = graphLogger;
            var name    = GetType().Assembly.GetName().Name;
            var builder = new CommunicationsClientBuilder(
                name,
                options.AppId,
                this.graphLogger);

            var authProvider = new AuthenticationProvider(
                name,
                options.AppId,
                options.AppSecret,
                this.graphLogger);

            builder.SetAuthenticationProvider(authProvider);
            builder.SetNotificationUrl(instanceNotificationUri);
            builder.SetServiceBaseUrl(options.PlaceCallEndpointUrl);

            Client = builder.Build();
            Client.Calls().OnIncoming += CallsOnIncoming;
            Client.Calls().OnUpdated  += CallsOnUpdated;

            IncidentStatusManager = new IncidentStatusManager();

            var audioBaseUri = options.BotBaseUrl;

            MediaMap[TransferringPromptName] = new MediaPrompt
            {
                MediaInfo = new MediaInfo
                {
                    Uri        = new Uri(audioBaseUri, "audio/responder-transfering.wav").ToString(),
                    ResourceId = Guid.NewGuid().ToString(),
                },
            };

            MediaMap[NotificationPromptName] = new MediaPrompt
            {
                MediaInfo = new MediaInfo
                {
                    Uri        = new Uri(audioBaseUri, "audio/responder-notification.wav").ToString(),
                    ResourceId = Guid.NewGuid().ToString(),
                },
            };

            MediaMap[BotIncomingPromptName] = new MediaPrompt
            {
                MediaInfo = new MediaInfo
                {
                    Uri        = new Uri(audioBaseUri, "audio/bot-incoming.wav").ToString(),
                    ResourceId = Guid.NewGuid().ToString(),
                },
            };

            MediaMap[BotEndpointIncomingPromptName] = new MediaPrompt
            {
                MediaInfo = new MediaInfo
                {
                    Uri        = new Uri(audioBaseUri, "audio/bot-endpoint-incoming.wav").ToString(),
                    ResourceId = Guid.NewGuid().ToString(),
                },
            };

            OnlineMeetings = new OnlineMeetingHelper(authProvider, options.PlaceCallEndpointUrl);
        }
Esempio n. 3
0
        public static UcwaUserConfiguration GetUcwaUserConfiguration(string sipUri, CallContext callContext)
        {
            callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.IsTaskCompleted, bool.FalseString);
            callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.IsUcwaSupported, bool.FalseString);
            UcwaUserConfiguration ucwaUserConfiguration = new UcwaUserConfiguration();

            ucwaUserConfiguration.SipUri = sipUri;
            if (string.IsNullOrEmpty(sipUri))
            {
                callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.IsTaskCompleted, bool.TrueString);
                throw new OwaInvalidRequestException("No sipUri specified");
            }
            UserContext userContext = UserContextManager.GetUserContext(callContext.HttpContext, callContext.EffectiveCaller, true);

            if (string.Compare(userContext.SipUri, sipUri, StringComparison.OrdinalIgnoreCase) != 0)
            {
                callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.ManagerSipUri, ExtensibleLogger.FormatPIIValue(sipUri));
            }
            if (userContext.ExchangePrincipal.MailboxInfo.OrganizationId != null && userContext.ExchangePrincipal.MailboxInfo.OrganizationId.OrganizationalUnit != null)
            {
                callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.Organization, userContext.ExchangePrincipal.MailboxInfo.OrganizationId.OrganizationalUnit.Name);
            }
            OAuthCredentials oauthCredential;

            try
            {
                oauthCredential = UcwaConfigurationUtilities.GetOAuthCredential(sipUri);
                oauthCredential.ClientRequestId = new Guid?(Guid.NewGuid());
                callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.OAuthCorrelationId, oauthCredential.ClientRequestId.Value.ToString());
            }
            catch (OwaException ex)
            {
                string text = UcwaConfigurationUtilities.BuildFailureLogString(ex);
                callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.Exceptions, text);
                ExTraceGlobals.OnlineMeetingTracer.TraceError <string>(0L, "[UcwaConfigurationUtilities.GetUcwaUserConfiguration] An error occurred while obtaining OAuth credential; Exception: {0}", text);
                ucwaUserConfiguration.DiagnosticInfo = text;
                return(ucwaUserConfiguration);
            }
            AutodiscoverResult ucwaDiscoveryUrl = AutodiscoverWorker.GetUcwaDiscoveryUrl(sipUri, oauthCredential);

            callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.AuthenticatedLyncAutodiscoverServer, ucwaDiscoveryUrl.AuthenticatedLyncAutodiscoverServer);
            callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.IsAuthdServerFromCache, ucwaDiscoveryUrl.IsAuthdServerFromCache ? bool.TrueString : bool.FalseString);
            callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.IsUcwaUrlFromCache, ucwaDiscoveryUrl.IsUcwaUrlFromCache ? bool.TrueString : bool.FalseString);
            callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.UnauthenticatedRedirectHops, string.Join(";", ucwaDiscoveryUrl.UnauthenticatedRedirects));
            callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.AuthenticatedRedirectHops, string.Join(";", ucwaDiscoveryUrl.AuthenticatedRedirects));
            callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.WorkerExceptions, ucwaDiscoveryUrl.BuildFailureString());
            if (!ucwaDiscoveryUrl.IsOnlineMeetingEnabled)
            {
                ExTraceGlobals.OnlineMeetingTracer.TraceInformation(0, 0L, "[UcwaConfigurationUtilities.GetUcwaUserConfiguration] Online meetings are not enabled in this topology");
                ucwaUserConfiguration.DiagnosticInfo = "Online meetings not enabled on the server";
                return(ucwaUserConfiguration);
            }
            if (ucwaDiscoveryUrl.HasError)
            {
                Exception     exception     = ucwaDiscoveryUrl.Error.Exception;
                StringBuilder stringBuilder = new StringBuilder(ucwaDiscoveryUrl.Error.FailureStep.ToString() + "_");
                stringBuilder.Append(UcwaConfigurationUtilities.BuildFailureLogString(exception));
                stringBuilder.Append(ucwaDiscoveryUrl.Error.ResponseFailureReason ?? string.Empty);
                string text2 = stringBuilder.ToString();
                callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.Exceptions, text2);
                callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.RequestHeaders, ucwaDiscoveryUrl.Error.RequestHeaders);
                callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.ResponseHeaders, ucwaDiscoveryUrl.Error.ResponseHeaders);
                callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.ResponseBody, ucwaDiscoveryUrl.Error.ResponseBody);
                if (ucwaDiscoveryUrl.IsAuthdServerFromCache)
                {
                    AutodiscoverCache.InvalidateDomain(OnlineMeetingHelper.GetSipDomain(sipUri));
                    callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.CacheOperation, AutodiscoverCacheOperation.InvalidateDomain.ToString());
                }
                ExTraceGlobals.OnlineMeetingTracer.TraceError <string>(0L, "[UcwaConfigurationUtilities.GetUcwaUserConfiguration] An error occured while fetching UCWA configuration; Exception: {0}", text2);
                ucwaUserConfiguration.DiagnosticInfo = text2;
                return(ucwaUserConfiguration);
            }
            callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.ResponseBody, ucwaDiscoveryUrl.ResponseBody);
            ucwaUserConfiguration.IsUcwaSupported = ucwaDiscoveryUrl.IsUcwaSupported;
            ucwaUserConfiguration.UcwaUrl         = ucwaDiscoveryUrl.UcwaDiscoveryUrl;
            callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.IsTaskCompleted, bool.TrueString);
            if (ucwaUserConfiguration.IsUcwaSupported)
            {
                callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.IsUcwaSupported, bool.TrueString);
                callContext.ProtocolLog.Set(GetUcwaUserConfigurationMetaData.UcwaUrl, ucwaUserConfiguration.UcwaUrl);
            }
            return(ucwaUserConfiguration);
        }