Example #1
0
        /// <summary>
        /// Initialize the Application.
        /// </summary>
        /// <param name="loggingContext">The logging context.</param>
        /// <returns>The task.</returns>
        public async Task InitializeApplicationAsync(LoggingContext loggingContext = null)
        {
            if (Application == null)
            {
                if (!(ClientPlatform as ClientPlatform).IsSandBoxEnv)
                {
                    Uri discoverUri = ClientPlatform.DiscoverUri;
                    Uri baseUri     = UriHelper.GetBaseUriFromAbsoluteUri(discoverUri.ToString());

                    var discover = new Discover(m_restfulClient, baseUri, discoverUri, this);
                    await discover.RefreshAndInitializeAsync(ApplicationEndpointId.ToString(), loggingContext).ConfigureAwait(false);

                    Application = discover.Application;
                }
                else
                {
                    Uri applicationsUri = Constants.PlatformApplicationsUri_SandBox;
                    Uri baseUri         = UriHelper.GetBaseUriFromAbsoluteUri(applicationsUri.ToString());
                    if (this.ApplicationEndpointId != null)
                    {
                        applicationsUri = UriHelper.AppendQueryParameterOnUrl(applicationsUri.ToString(), Constants.EndpointId, ApplicationEndpointId.ToString(), false);
                    }

                    var applications = new Applications(m_restfulClient, null, baseUri, applicationsUri, this);
                    await applications.RefreshAndInitializeAsync(loggingContext).ConfigureAwait(false);

                    Application = applications.Application;
                }

                await Application.RefreshAndInitializeAsync(loggingContext).ConfigureAwait(false);
            }
        }
Example #2
0
        /// <summary>
        /// Call Get on application and initialize communication resource
        /// </summary>
        /// <param name="endpointId">The application endpoint's sip id</param>
        /// <param name="loggingContext"><see cref="LoggingContext"/> to be used for logging all related events.</param>
        public async Task RefreshAndInitializeAsync(string endpointId, LoggingContext loggingContext = null)
        {
            await this.RefreshAsync(loggingContext).ConfigureAwait(false);

            if (this.PlatformResource.Applications != null)
            {
                Uri baseUri         = UriHelper.GetBaseUriFromAbsoluteUri(this.PlatformResource.Applications.Href);
                Uri applicationsUri = new Uri(this.PlatformResource.Applications.Href);
                if (!string.IsNullOrEmpty(endpointId))
                {
                    applicationsUri = UriHelper.AppendQueryParameterOnUrl(applicationsUri.ToString(), Constants.EndpointId, endpointId, false);
                }

                #pragma warning disable CS0618 // Type or member is obsolete
                Applications = new Applications(RestfulClient, null, baseUri, applicationsUri, this);
                await Applications.RefreshAndInitializeAsync(loggingContext).ConfigureAwait(false);

                #pragma warning restore CS0618 // Type or member is obsolete
            }
            else
            {
                throw new RemotePlatformServiceException("Retrieved DiscoverResource doesn't have link to ApplicationsResource.");
            }
        }