Esempio n. 1
0
        private async Task <string> GetEmailBodyAsync(EmailRequest request)
        {
            var templatePath = pathFinder.GetTemplatePath(request.TemplateKey);
            var template     = await resourceLoader.LoadAsync(templatePath);

            var emailBody = templateProcessor.Process(template, request.Payload);

            return(emailBody);
        }
Esempio n. 2
0
        /// <summary>
        /// Performs a fetch from the given URI by using an asynchronous
        /// request.
        /// </summary>
        /// <param name="loader">The resource loader to use.</param>
        /// <param name="request">The request to issue.</param>
        /// <param name="cancel">
        /// The token which can be used to cancel the request.
        /// </param>
        /// <returns>
        /// The task which will eventually return the stream.
        /// </returns>
        public static Task <IResponse> FetchAsync(this IResourceLoader loader, ResourceRequest request, CancellationToken cancel)
        {
            if (loader == null)
            {
                return(DefaultResponse);
            }

            return(loader.LoadAsync(request, cancel));
        }
Esempio n. 3
0
        /// <summary>
        /// Attempts to load a resource with the provided path and holds it in case it's loaded successfully.
        /// </summary>
        public static async UniTask <Resource <TResource> > LoadAndHoldAsync <TResource> (this IResourceLoader <TResource> loader, string path, object holder)
            where TResource : UnityEngine.Object
        {
            var resource = await loader.LoadAsync(path);

            if (loader.IsLoaded(path))
            {
                loader.Hold(path, holder);
            }
            return(resource);
        }
Esempio n. 4
0
        private async Task <Result <string> > GetEmailBodyAsync(MercuryRequest <ExpandoObject> request, CancellationToken token)
        {
            var templatePath = pathFinder.GetTemplatePath(request.TemplateKey);

            var templateResult = await resourceLoader.LoadAsync(templatePath, token).ConfigureAwait(false);

            if (templateResult.IsFailed)
            {
                return(templateResult);
            }

            token.ThrowIfCancellationRequested();

            var templateProcessingResult = templateProcessor.Process(templateResult.Value, request.Payload);

            if (templateProcessingResult.IsFailed)
            {
                return(templateProcessingResult);
            }

            return(Result.Ok(templateProcessingResult.Value));
        }
Esempio n. 5
0
 /// <summary>
 /// Performs a fetch from the given URI by using an asynchronous
 /// request.
 /// </summary>
 /// <param name="loader">The resource loader to use.</param>
 /// <param name="request">The request to issue.</param>
 /// <param name="cancel">
 /// The token which can be used to cancel the request.
 /// </param>
 /// <returns>
 /// The task which will eventually return the stream.
 /// </returns>
 public static Task <IResponse> FetchAsync(this IResourceLoader loader, ResourceRequest request, CancellationToken cancel)
 {
     return(loader != null?loader.LoadAsync(request, cancel) : TaskEx.FromResult(default(IResponse)));
 }
Esempio n. 6
0
        /// <summary>
        /// Performs a potentially CORS-enabled fetch from the given URI by
        /// using an asynchronous GET request. For more information see:
        /// http://www.w3.org/TR/html5/infrastructure.html#potentially-cors-enabled-fetch
        /// </summary>
        /// <param name="loader">The resource loader to use.</param>
        /// <param name="request">The request to issue.</param>
        /// <param name="setting">The cross origin settings to use.</param>
        /// <param name="behavior">
        /// The default behavior in case it is undefined.
        /// </param>
        /// <param name="cancel">
        /// The token which can be used to cancel the request.
        /// </param>
        /// <returns>
        /// The task which will eventually return the stream.
        /// </returns>
        public static async Task <IResponse> FetchWithCorsAsync(this IResourceLoader loader, ResourceRequest request, CorsSetting setting, OriginBehavior behavior, CancellationToken cancel)
        {
            if (loader == null)
            {
                return(null);
            }

            var url = request.Target;

            if (request.Origin == url.Origin || url.Scheme == KnownProtocols.Data || url.Href == "about:blank")
            {
                while (true)
                {
                    var data = new ResourceRequest(request.Source, url)
                    {
                        Origin = request.Origin,
                        IsManualRedirectDesired = true
                    };

                    var result = await loader.LoadAsync(data, cancel).ConfigureAwait(false);

                    if (result.StatusCode == HttpStatusCode.Redirect ||
                        result.StatusCode == HttpStatusCode.RedirectKeepVerb ||
                        result.StatusCode == HttpStatusCode.RedirectMethod ||
                        result.StatusCode == HttpStatusCode.TemporaryRedirect ||
                        result.StatusCode == HttpStatusCode.MovedPermanently ||
                        result.StatusCode == HttpStatusCode.MultipleChoices)
                    {
                        url = new Url(result.Headers.GetOrDefault(HeaderNames.Location, url.Href));

                        if (request.Origin == url.Origin)
                        {
                            request = new ResourceRequest(request.Source, url)
                            {
                                IsCookieBlocked    = request.IsCookieBlocked,
                                IsSameOriginForced = request.IsSameOriginForced,
                                Origin             = request.Origin
                            };
                            return(await loader.FetchWithCorsAsync(request, setting, behavior, cancel).ConfigureAwait(false));
                        }
                    }
                    else
                    {
                        return(result);
                    }
                }
            }
            else if (setting == CorsSetting.None)
            {
                if (behavior == OriginBehavior.Fail)
                {
                    throw new DomException(DomError.Network);
                }

                return(await loader.LoadAsync(request, cancel).ConfigureAwait(false));
            }
            else if (setting == CorsSetting.Anonymous || setting == CorsSetting.UseCredentials)
            {
                request.IsCredentialOmitted = setting == CorsSetting.Anonymous;
                var result = await loader.FetchAsync(request, cancel).ConfigureAwait(false);

                if (result != null && result.StatusCode == HttpStatusCode.OK)
                {
                    return(result);
                }
                else if (result != null)
                {
                    result.Dispose();
                }
            }

            throw new DomException(DomError.Network);
        }
Esempio n. 7
0
 public static void LoadAsync <T>(string filePath, Action <T> onComplete, Action onFail)
     where T : Object
 {
     _loader.LoadAsync(filePath, onComplete, onFail);
 }