public ContentItemViewHolder(
     DisplayContext displayContext,
     ViewGroup container,
     IContentItem contentItem)
 {
     DisplayContext = displayContext;
     Container      = container;
     ContentItem    = contentItem;
 }
Exemple #2
0
        public Task <IHtmlContent> Pager_Gap(IShape shape, DisplayContext displayContext)
        {
            shape.Metadata.Alternates.Clear();
            shape.Metadata.Type = "Pager_Link";
            var parentTag = shape.GetProperty <TagBuilder>("Tag");

            parentTag.AddCssClass("disabled");
            return(displayContext.DisplayHelper.ShapeExecuteAsync(shape));
        }
 static IHtmlString Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context)
 {
     if (shapeBinding == null || shapeBinding.Binding == null)
     {
         // todo: create result from all child shapes
         return(shape.Metadata.ChildContent ?? new HtmlString(""));
     }
     return(CoerceHtmlString(shapeBinding.Binding(context)));
 }
Exemple #4
0
        private static DisplayContextImpl GetImpl(this DisplayContext displayContext)
        {
            var impl = map.Get(displayContext);

            if (impl == null)
            {
                throw new ArgumentOutOfRangeException(string.Format("Argument {0} is not a valid DisplayContext value.", (int)displayContext));
            }
            return(impl);
        }
        private IHtmlString Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit)
        {
            Logger.Information("Rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);

            var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
            var result     = htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);

            Logger.Information("Done rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
            return(result);
        }
Exemple #6
0
        public async Task <IHtmlContent> PagerSearch(
            dynamic Shape,
            dynamic DisplayAsync,
            dynamic New,
            IHtmlHelper Html,
            DisplayContext DisplayContext,
            object PreviousText,
            object NextText,
            string PreviousClass,
            string NextClass)
        {
            Shape.Classes.Add("pager");
            Shape.Metadata.Alternates.Clear();
            Shape.Metadata.Type = "List";

            var previousText = PreviousText ?? T["Previous"];
            var nextText     = NextText ?? T["Next"];

            var routeData           = new RouteValueDictionary(Html.ViewContext.RouteData.Values);
            var httpContextAccessor = DisplayContext.ServiceProvider.GetService <IHttpContextAccessor>();
            var httpContext         = httpContextAccessor.HttpContext;

            if (httpContext != null)
            {
                var queryString = httpContext.Request.Query;
                if (queryString != null)
                {
                    foreach (var key in from string key in queryString.Keys where key != null && !routeData.ContainsKey(key) let value = queryString[key] select key)
                    {
                        routeData[key] = queryString[key];
                    }
                }
            }

            var currentPage    = (int)Shape.CurrentPage;
            var hasMoreResults = (bool)Shape.HasMoreResults;

            if (currentPage != 1)
            {
                var previousRouteData = new RouteValueDictionary(routeData);
                previousRouteData["page"] = (string)(currentPage - 1).ToString();
                Shape.Add(await New.Pager_Previous(Value: previousText, RouteValues: previousRouteData, Pager: Shape));
                Shape.FirstClass = PreviousClass;
            }

            if (hasMoreResults)
            {
                var nextRouteData = new RouteValueDictionary(routeData);
                nextRouteData["page"] = (string)(currentPage + 1).ToString();
                Shape.Add(await New.Pager_Next(Value: nextText, RouteValues: nextRouteData, Pager: Shape));
                Shape.LastClass = NextClass;
            }

            return(await DisplayAsync(Shape));
        }
Exemple #7
0
            internal LastResortLocaleDisplayNames(ULocale locale, DialectHandling dialectHandling)
#pragma warning disable 612, 618
                : base()
#pragma warning restore 612, 618
            {
                this.locale = locale;
                DisplayContext context = (dialectHandling == DialectHandling.DialectNames) ?
                                         DisplayContext.DialectNames : DisplayContext.StandardNames;

                this.contexts = new DisplayContext[] { context };
            }
Exemple #8
0
 public async Task <Stream> Build(IEnumerable <ContentItem> contents, DisplayContext displayContext)
 {
     using (var htmlStream = await _htmlGenerator.GenerateHtml(contents, Descriptor.SupportedFileExtension, displayContext))
         using (var streamReader = new StreamReader(htmlStream))
             using (var wc = new WebClient())
             {
                 var fields = new NameValueCollection();
                 fields.Add("html", streamReader.ReadToEnd());
                 return(new MemoryStream(wc.UploadValues("http://fuckyeahmarkdown.com/go/", fields)));
             }
 }
Exemple #9
0
        private object BindParameter(DisplayContext displayContext, ParameterInfo parameter, TextWriter output)
        {
            if (parameter.Name == "Shape")
            {
                return(displayContext.Value);
            }

            if (parameter.Name == "Display")
            {
                return(displayContext.Display);
            }

            if (parameter.Name == "Output" && parameter.ParameterType == typeof(TextWriter))
            {
                return(output);
            }

            if (parameter.Name == "Output" && parameter.ParameterType == typeof(Action <object>))
            {
                return(new Action <object>(output.Write));
            }

            // meh--
            if (parameter.Name == "Html")
            {
                return(new HtmlHelper(
                           displayContext.ViewContext,
                           displayContext.ViewDataContainer,
                           _routeCollection));
            }

            if (parameter.Name == "Url" && parameter.ParameterType.IsAssignableFrom(typeof(UrlHelper)))
            {
                return(new UrlHelper(displayContext.ViewContext.RequestContext, _routeCollection));
            }

            var getter = _getters.GetOrAdd(parameter.Name, n =>
                                           CallSite <Func <CallSite, object, dynamic> > .Create(
                                               Microsoft.CSharp.RuntimeBinder.Binder.GetMember(
                                                   CSharpBinderFlags.None, n, null, new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) })));

            var result = getter.Target(getter, displayContext.Value);

            if (result == null)
            {
                return(null);
            }

            var converter = _converters.GetOrAdd(parameter.ParameterType, CompileConverter);
            var argument  = converter.Invoke(result);

            return(argument);
        }
Exemple #10
0
        public Task <IHtmlContent> Pager_Next(Shape shape, DisplayContext displayContext)
        {
            shape.Metadata.Alternates.Clear();
            shape.Metadata.Type = "Pager_Link";

            if (!shape.Attributes.ContainsKey("rel"))
            {
                shape.Attributes["rel"] = "next";
            }

            return(displayContext.DisplayHelper.ShapeExecuteAsync(shape));
        }
        private object BindParameter(DisplayContext displayContext, ParameterInfo parameter, TextWriter output)
        {
            if (String.Equals(parameter.Name, "Shape", StringComparison.OrdinalIgnoreCase))
            {
                return(displayContext.Value);
            }

            if (String.Equals(parameter.Name, "Display", StringComparison.OrdinalIgnoreCase))
            {
                return(displayContext.Display);
            }

            if (String.Equals(parameter.Name, "Output", StringComparison.OrdinalIgnoreCase) &&
                parameter.ParameterType == typeof(TextWriter))
            {
                return(output);
            }

            if (String.Equals(parameter.Name, "Output", StringComparison.OrdinalIgnoreCase) &&
                parameter.ParameterType == typeof(Action <object>))
            {
                return(new Action <object>(output.Write));
            }

            if (String.Equals(parameter.Name, "Html", StringComparison.OrdinalIgnoreCase))
            {
                return(MakeHtmlHelper(displayContext.ViewContext, displayContext.ViewContext.ViewData));
            }

            if (String.Equals(parameter.Name, "Url", StringComparison.OrdinalIgnoreCase) &&
                parameter.ParameterType.IsAssignableFrom(typeof(UrlHelper)))
            {
                return(_componentContext.GetService <IUrlHelper>());
            }

            var getter = _getters.GetOrAdd(parameter.Name.ToLowerInvariant(), n =>
                                           CallSite <Func <CallSite, object, dynamic> > .Create(
                                               Binder.GetMember(
                                                   CSharpBinderFlags.None, n, null, new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) })));

            var result = getter.Target(getter, displayContext.Value);

            if (result == null)
            {
                return(null);
            }

            //var converter = _converters.GetOrAdd(parameter.ParameterType, CompileConverter);
            //var argument = converter.Invoke(result);
            //return argument;

            return(Convert.ChangeType(result, parameter.ParameterType));
        }
        public override string Process(string template, string name, DisplayContext context = null, dynamic model = null)
        {
            if (String.IsNullOrEmpty(template))
            {
                return(string.Empty);
            }

            var compiledTemplate = _compiler.CompileRazor(template, name, new Dictionary <string, object>());
            var result           = ActivateAndRenderTemplate(compiledTemplate, context, null, model);

            return(result);
        }
Exemple #13
0
        private string ActivateAndRenderTemplate(IRazorTemplateBase obj, DisplayContext displayContext, string templateVirtualPath, object model)
        {
            var buffer = new StringBuilder(1024);

            using (var writer = new StringWriter(buffer)) {
                using (var htmlWriter = new HtmlTextWriter(writer)) {
                    if (displayContext != null && displayContext.ViewContext.Controller != null)
                    {
                        var shapeViewContext = new ViewContext(
                            displayContext.ViewContext.Controller.ControllerContext,
                            displayContext.ViewContext.View,
                            displayContext.ViewContext.ViewData,
                            displayContext.ViewContext.TempData,
                            htmlWriter
                            );

                        obj.WebPageContext = new WebPageContext(displayContext.ViewContext.HttpContext, obj as WebPageRenderingBase, model);
                        obj.ViewContext    = shapeViewContext;

                        obj.ViewData = new ViewDataDictionary(displayContext.ViewDataContainer.ViewData)
                        {
                            Model = model
                        };
                        obj.InitHelpers();
                    }
                    else
                    {
                        // Setup a fake view context in order to support razor syntax inside of HTML attributes,
                        // for instance: <a href="@WorkContext.CurrentSite.BaseUrl">Homepage</a>.
                        var viewData    = new ViewDataDictionary(model);
                        var httpContext = _wca.GetContext().HttpContext;
                        obj.ViewContext = new ViewContext(
                            new ControllerContext(
                                httpContext.Request.RequestContext,
                                new StubController()),
                            new StubView(),
                            viewData,
                            new TempDataDictionary(),
                            htmlWriter);

                        obj.ViewData       = viewData;
                        obj.WebPageContext = new WebPageContext(httpContext, obj as WebPageRenderingBase, model);
                        obj.WorkContext    = _wca.GetContext();
                    }

                    obj.VirtualPath = templateVirtualPath ?? "~/Themes/Orchard.Templates";
                    obj.Render(htmlWriter);
                }
            }

            return(buffer.ToString());
        }
Exemple #14
0
        private IHtmlString RenderRazorViewToString(string path, DisplayContext context)
        {
            using (var sw = new StringWriter()) {
                var controllerContext = CreateControllerContext();
                var viewResult        = _viewEngine.Value.FindPartialView(controllerContext, path, false);

                context.ViewContext.ViewData = new ViewDataDictionary(context.Value);
                context.ViewContext.TempData = new TempDataDictionary();
                viewResult.View.Render(context.ViewContext, sw);
                viewResult.ViewEngine.ReleaseView(controllerContext, viewResult.View);
                return(new HtmlString(sw.GetStringBuilder().ToString()));
            }
        }
        private IHtmlString PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, object serviceInstance)
        {
            var output    = new HtmlStringWriter();
            var arguments = methodInfo.GetParameters()
                            .Select(parameter => BindParameter(displayContext, parameter, output));

            var returnValue = methodInfo.Invoke(serviceInstance, arguments.ToArray());

            if (methodInfo.ReturnType != typeof(void))
            {
                output.Write(CoerceHtmlString(returnValue));
            }
            return(output);
        }
Exemple #16
0
            public override DisplayContext GetContext(DisplayContextType type)
            {
                DisplayContext result = DisplayContext.StandardNames;  // final fallback

                foreach (DisplayContext context in contexts)
                {
                    if (context.Type() == type)
                    {
                        result = context;
                        break;
                    }
                }
                return(result);
            }
Exemple #17
0
        private object BindParameter(DisplayContext displayContext, ParameterInfo parameter)
        {
            if (String.Equals(parameter.Name, "Shape", StringComparison.OrdinalIgnoreCase))
            {
                return(displayContext.Value);
            }

            if (String.Equals(parameter.Name, "Display", StringComparison.OrdinalIgnoreCase))
            {
                return(displayContext.Display);
            }

            if (String.Equals(parameter.Name, "Html", StringComparison.OrdinalIgnoreCase))
            {
                return(MakeHtmlHelper(displayContext.ViewContext, displayContext.ViewContext.ViewData));
            }

            if (String.Equals(parameter.Name, "Url", StringComparison.OrdinalIgnoreCase) &&
                parameter.ParameterType.IsAssignableFrom(typeof(UrlHelper)))
            {
                return(_componentContext.GetService <IUrlHelper>());
            }

            if (String.Equals(parameter.Name, "Output", StringComparison.OrdinalIgnoreCase) &&
                parameter.ParameterType == typeof(TextWriter))
            {
                throw new InvalidOperationException("Output is no more a valid Shape method parameter");
            }

            if (String.Equals(parameter.Name, "Output", StringComparison.OrdinalIgnoreCase) &&
                parameter.ParameterType == typeof(Action <object>))
            {
                throw new InvalidOperationException("Output is no more a valid Shape method parameter");
            }


            var getter = _getters.GetOrAdd(parameter.Name, n =>
                                           CallSite <Func <CallSite, object, dynamic> > .Create(
                                               Binder.GetMember(
                                                   CSharpBinderFlags.None, n, null, new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) })));

            var result = getter.Target(getter, displayContext.Value);

            if (result == null)
            {
                return(null);
            }

            return(Convert.ChangeType(result, parameter.ParameterType));
        }
Exemple #18
0
 public LocaleDisplayNames Get(ULocale locale, DialectHandling dialectHandling)
 {
     if (!(dialectHandling == this.dialectHandling && DisplayContext.CapitalizationNone == this.capitalization &&
           DisplayContext.LengthFull == this.nameLength && DisplayContext.Substitute == this.substituteHandling &&
           locale.Equals(this.locale)))
     {
         this.locale             = locale;
         this.dialectHandling    = dialectHandling;
         this.capitalization     = DisplayContext.CapitalizationNone;
         this.nameLength         = DisplayContext.LengthFull;
         this.substituteHandling = DisplayContext.Substitute;
         this.cache = new LocaleDisplayNamesImpl(locale, dialectHandling);
     }
     return(cache);
 }
Exemple #19
0
        private UiListItem NewRow(ULocale modified, DisplayContext capContext)
        {
            ULocale minimized           = ULocale.MinimizeSubtags(modified, ULocale.Minimize.FAVOR_SCRIPT);
            string  tempName            = modified.GetDisplayName(locale);
            bool    titlecase           = capContext == DisplayContext.CapitalizationForUIListOrMenu;
            string  nameInDisplayLocale =
                titlecase ? ToTitleWholeStringNoLowercase(locale, tempName) : tempName;

            tempName = modified.GetDisplayName(modified);
            string nameInSelf = capContext ==
                                DisplayContext.CapitalizationForUIListOrMenu ?
                                ToTitleWholeStringNoLowercase(modified, tempName) : tempName;

            return(new UiListItem(minimized, modified, nameInDisplayLocale, nameInSelf));
        }
Exemple #20
0
        public void BindingProvidedByStrategyInvokesMethod()
        {
            var initializers = GetAlterationBuilders(_container.Resolve <IShapeTableProvider>());

            var shapeDescriptor = initializers.Where(i => i.ShapeType == "Simple")
                                  .Aggregate(new ShapeDescriptor {
                ShapeType = "Simple"
            }, (d, i) => { i.Alter(d); return(d); });

            var displayContext = new DisplayContext();
            var result         = shapeDescriptor.Binding(displayContext);
            var result2        = shapeDescriptor.Binding.Invoke(displayContext);

            Assert.That(result.ToString(), Is.EqualTo("Simple"));
            Assert.That(result2.ToString(), Is.EqualTo("Simple"));
        }
        private Task <IHtmlContent> PerformInvokeAsync(DisplayContext displayContext, MethodInfo methodInfo, object serviceInstance)
        {
            var parameters = _parameters.GetOrAdd(methodInfo, m => m.GetParameters());
            var arguments  = parameters.Select(parameter => BindParameter(displayContext, parameter));

            // Resolve the service the method is declared on
            var returnValue = methodInfo.Invoke(serviceInstance, arguments.ToArray());

            // If the shape returns a value, write it to the stream
            if (methodInfo.ReturnType != typeof(void))
            {
                return(Task.FromResult(CoerceHtmlContent(returnValue)));
            }

            return(Task.FromResult <IHtmlContent>(null));
        }
Exemple #22
0
        //https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/shortcodes.php
        public string ProcessContent(string text, string flavor)
        {
            //dynamic foo = factory.Create("Foo", ArgsUtility.Named(new { one = 1, two = "dos" }));

            var args = new RouteValueDictionary(new Dictionary <string, object> {
            });

            var shape = _shapeFactory.Create("ShortCodeName", Arguments.FromT(args.Values, args.Keys));


            var context = new DisplayContext {
                Value       = shape,
                ViewContext = new ViewContext()
            };

            var shortCodeText = _displayManager.Execute(context);
        }
Exemple #23
0
        public Task <IHtmlContent> RenderAsync(string relativePath, DisplayContext displayContext)
        {
            var viewName = "/" + relativePath;

            if (displayContext.ViewContext.View != null)
            {
                var htmlHelper = MakeHtmlHelper(displayContext.ViewContext, displayContext.ViewContext.ViewData);
                return(Task.FromResult(htmlHelper.Partial(viewName, displayContext.Value)));
            }
            else
            {
                // If the View is null, it means that the shape is being executed from a non-view origin / where no ViewContext was established by the view engine, but manually.
                // Manually creating a ViewContext works when working with Shape methods, but not when the shape is implemented as a Razor view template.
                // Horrible, but it will have to do for now.
                return(RenderRazorViewAsync(viewName, displayContext));
            }
        }
Exemple #24
0
            public LocaleDisplayNames Get(ULocale locale, params DisplayContext[] contexts)
            {
                DialectHandling dialectHandlingIn  = DialectHandling.STANDARD_NAMES;
                DisplayContext  capitalizationIn   = DisplayContext.CapitalizationNone;
                DisplayContext  nameLengthIn       = DisplayContext.LengthFull;
                DisplayContext  substituteHandling = DisplayContext.Substitute;

                foreach (DisplayContext contextItem in contexts)
                {
                    switch (contextItem.Type())
                    {
                    case DisplayContextType.DialectHandling:
                        dialectHandlingIn = (contextItem.Value() == DisplayContext.StandardNames.Value()) ?
                                            DialectHandling.STANDARD_NAMES : DialectHandling.DIALECT_NAMES;
                        break;

                    case DisplayContextType.Capitalization:
                        capitalizationIn = contextItem;
                        break;

                    case DisplayContextType.DisplayLength:
                        nameLengthIn = contextItem;
                        break;

                    case DisplayContextType.SubstituteHandling:
                        substituteHandling = contextItem;
                        break;

                    default:
                        break;
                    }
                }
                if (!(dialectHandlingIn == this.dialectHandling && capitalizationIn == this.capitalization &&
                      nameLengthIn == this.nameLength && substituteHandling == this.substituteHandling &&
                      locale.Equals(this.locale)))
                {
                    this.locale             = locale;
                    this.dialectHandling    = dialectHandlingIn;
                    this.capitalization     = capitalizationIn;
                    this.nameLength         = nameLengthIn;
                    this.substituteHandling = substituteHandling;
                    this.cache = new LocaleDisplayNamesImpl(locale, contexts);
                }
                return(cache);
            }
Exemple #25
0
        private async Task <IHtmlContent> RenderRazorViewAsync(string viewName, DisplayContext displayContext)
        {
            var viewEngines = _options.Value.ViewEngines;

            if (viewEngines.Count == 0)
            {
                throw new InvalidOperationException(string.Format("'{0}.{1}' must not be empty. At least one '{2}' is required to locate a view for rendering.",
                                                                  typeof(MvcViewOptions).FullName,
                                                                  nameof(MvcViewOptions.ViewEngines),
                                                                  typeof(IViewEngine).FullName));
            }

            var viewEngine = viewEngines[0];

            var result = await RenderViewToStringAsync(viewName, displayContext.Value, viewEngine);

            return(new HtmlString(result));
        }
        private IHtmlContent PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, object serviceInstance)
        {
            using (var output = new StringCollectionTextWriter(System.Text.Encoding.UTF8))
            {
                var arguments = methodInfo
                                .GetParameters()
                                .Select(parameter => BindParameter(displayContext, parameter, output));

                // Resolve the service the method is declared on
                var returnValue = methodInfo.Invoke(serviceInstance, arguments.ToArray());

                // If the shape returns a value, write it to the stream
                if (methodInfo.ReturnType != typeof(void))
                {
                    output.Write(CoerceHtmlString(returnValue));
                }

                return(output.Content);
            }
        }
Exemple #27
0
        private IHtmlString PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, object serviceInstance)
        {
            var output    = new HtmlStringWriter();
            var arguments = methodInfo.GetParameters()
                            .Select(parameter => BindParameter(displayContext, parameter, output));

            try {
                var returnValue = methodInfo.Invoke(serviceInstance, arguments.ToArray());
                if (methodInfo.ReturnType != typeof(void))
                {
                    output.Write(CoerceHtmlString(returnValue));
                }
                return(output);
            }
            catch (TargetInvocationException e) {
                // Throwing a TIE here will probably kill the web process
                // in Azure. For unknown reasons.
                throw new Exception(string.Concat("TargetInvocationException ", methodInfo.Name), e.InnerException);
            }
        }
        public override string Process(string template, string name, DisplayContext context = null, dynamic model = null)
        {
            if (string.IsNullOrEmpty(template))
            {
                return(string.Empty);
            }

            var compiledTemplate = _compiler.CompileRazor(template, name, new Dictionary <string, object>());

            if (model != null)
            {
                model.OrchardUrl      = (_httpContextBase.Request.Url == null ? string.Empty: _httpContextBase.Request.Url.PathAndQuery);
                model.OrchardUser     = (_orchardServices.WorkContext.CurrentUser == null ? string.Empty: _orchardServices.WorkContext.CurrentUser.UserName);
                model.OrchardEmail    = (_orchardServices.WorkContext.CurrentUser == null ? string.Empty: _orchardServices.WorkContext.CurrentUser.Email);
                model.OrchardTimeZone = (_orchardServices.WorkContext.CurrentSite == null ? string.Empty : _orchardServices.WorkContext.CurrentSite.SiteTimeZone);
            }
            var result = ActivateAndRenderTemplate(compiledTemplate, model);

            return(result);
        }
Exemple #29
0
        protected async Task <bool> SendEmailAsync(string email, string subject, IShape model)
        {
            var options = ControllerContext.HttpContext.RequestServices.GetRequiredService <IOptions <MvcViewOptions> >();

            // Just use the current context to get a view and then create a view context.
            var view = options.Value.ViewEngines
                       .Select(x => x.FindView(
                                   ControllerContext,
                                   ControllerContext.ActionDescriptor.ActionName,
                                   false)).FirstOrDefault()?.View;

            var displayContext = new DisplayContext()
            {
                ServiceProvider = ControllerContext.HttpContext.RequestServices,
                Value           = model,
                ViewContext     = new ViewContext(ControllerContext, view, ViewData, TempData, new StringWriter(), new HtmlHelperOptions())
            };

            var body = string.Empty;

            using (var sw = new StringWriter())
            {
                var htmlContent = await _displayManager.ExecuteAsync(displayContext);

                htmlContent.WriteTo(sw, HtmlEncoder.Default);
                body = sw.ToString();
            }

            var message = new MailMessage()
            {
                Body       = body,
                IsBodyHtml = true,
                Subject    = subject
            };

            message.To.Add(email);

            var result = await _smtpService.SendAsync(message);

            return(result.Succeeded);
        }
        private IHtmlString Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit)
        {
            Logger.Information("Rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
            IHtmlString result;

            if (displayContext.ViewContext.View != null)
            {
                var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
                result = htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
            }
            else
            {
                // If the View is null, it means that the shape is being executed from a non-view origin / where no ViewContext was established by the view engine, but manually.
                // Manually creating a ViewContext works when working with Shape methods, but not when the shape is implemented as a Razor view template.
                // Horrible, but it will have to do for now.
                result = RenderRazorViewToString(harvestShapeInfo.TemplateVirtualPath, displayContext);
            }

            Logger.Information("Done rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
            return(result);
        }