本文整理汇总了C#中ViewEngineCollection类的典型用法代码示例。如果您正苦于以下问题:C# ViewEngineCollection类的具体用法?C# ViewEngineCollection怎么用?C# ViewEngineCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ViewEngineCollection类属于命名空间,在下文中一共展示了ViewEngineCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AsksEachViewEngineInTheOrderItWasCalled
public void AsksEachViewEngineInTheOrderItWasCalled()
{
var redEngine = new Mock<IViewEngine>();
var redResult = new ViewEngineResult(false, new[] { "Whatever"});
redEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(redResult);
var orangeEngine = new Mock<IViewEngine>();
orangeEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns((ViewEngineResult)null);
var blueEngine = new Mock<IViewEngine>();
var blueResult = new ViewEngineResult(true, new string[0]);
blueEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(blueResult);
var greenEngine = new Mock<IViewEngine>();
var greenResult = new ViewEngineResult(true, new string[0]);
greenEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(greenResult);
var collection = new ViewEngineCollection();
collection.Add(redEngine.Object);
collection.Add(orangeEngine.Object);
collection.Add(blueEngine.Object);
collection.Add(greenEngine.Object);
var result = collection.FindView(RequestBuilder.CreateRequest().BuildControllerContext(), new ViewResultOptions(), "Foo");
Assert.AreEqual(blueResult, result);
}
示例2: NoMvcViewEngineCollectionExtensions
public NoMvcViewEngineCollectionExtensions(ViewEngineCollection viewEngineCollection)
{
if (viewEngineCollection == null)
throw new ArgumentNullException("viewEngineCollection");
_viewEngineCollection = viewEngineCollection;
}
开发者ID:stevenlauwers22,项目名称:AspNet.NoMvcAndTinyControllers,代码行数:7,代码来源:NoMvcViewEngineCollectionExtensions.cs
示例3: NotifyNewComment
public static void NotifyNewComment(int commentId)
{
var currentCultureName = Thread.CurrentThread.CurrentCulture.Name;
if (currentCultureName != "es-ES")
{
throw new InvalidOperationException(String.Format("Current culture is {0}", currentCultureName));
}
// Prepare Postal classes to work outside of ASP.NET request
var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
var engines = new ViewEngineCollection();
engines.Add(new FileSystemRazorViewEngine(viewsPath));
var emailService = new EmailService(engines);
// Get comment and send a notification.
using (var db = new MailerDbContext())
{
var comment = db.Comments.Find(commentId);
var email = new NewCommentEmail
{
To = "[email protected]",
UserName = comment.UserName,
Comment = comment.Text
};
emailService.Send(email);
}
}
示例4: RegisterViewEngines
public void RegisterViewEngines(ViewEngineCollection engines)
{
var sparkViewFactory = new SubFolderSupportedSparkViewFactory();
sparkViewFactory.AddSubDirectoryViewLocation("PartialViews");
engines.Add(sparkViewFactory);
}
示例5: RegisterViewEngines
public static void RegisterViewEngines(ViewEngineCollection viewEngines)
{
// 清除所有 View Engine
viewEngines.Clear();
// 重新註冊 RazorViewEngine,如果你使用的是 WebForm ViewEngine 則是加入 WebFormViewEngine
viewEngines.Add(new RazorViewEngine());
}
示例6: Main
private static void Main()
{
// create the email template
var template = new EmailTemplate("Test");
dynamic dtemplate = template;
dtemplate.To = "[email protected]";
dtemplate.Message = "Hello, non-asp.net world! ";
dtemplate.Test = "test property";
dtemplate.SubjectSuffix = DateTime.Now.ToShortTimeString();
dtemplate.Values = new[] {"one", "two", "three"};
template.Attach(@"c:\tmp\test2.log");
template.Attach(@"c:\tmp\cat.jpg", "CatImageId"); // TODO: put in progam folder
// serialize and deserialize the email template
var serializerSettings = new JsonSerializerSettings
{
Converters = new List<JsonConverter>
{
new AttachmentReadConverter(true)
}
};
var serializedTemplate = JsonConvert.SerializeObject(template, Formatting.Indented, serializerSettings);
Console.WriteLine(serializedTemplate);
Console.WriteLine("serialized size: {0}", serializedTemplate.Length);
var deserializedTemplate = JsonConvert.DeserializeObject<EmailTemplate>(serializedTemplate, serializerSettings);
// send the email template
var engines = new ViewEngineCollection
{
new ResourceRazorViewEngine(typeof (Program).Assembly, @"ResourceSample.Resources.Views")
};
var service = new SmtpMessagingService(engines);
service.Send(deserializedTemplate);
}
示例7: RegisterViewEngines
public static void RegisterViewEngines(ViewEngineCollection viewEngines)
{
viewEngines.Clear();
var lightweightRazorViewEngine = new LightweightRazorViewEngine();
viewEngines.Add(lightweightRazorViewEngine);
}
示例8: Send
public void Send(string content)
{
_smtpClient = new SmtpClient(Address, Port);
_smtpClient.Credentials = new NetworkCredential(Account, Password);
_smtpClient.EnableSsl = false;
MailMessage mailMessage = new MailMessage();
mailMessage.BodyEncoding = Encoding.UTF8;
mailMessage.From = new MailAddress(From, SenderName, Encoding.UTF8);
mailMessage.To.Add(To);
mailMessage.Body = content;
mailMessage.Subject = Subject;
_smtpClient.Send(mailMessage);
dynamic email = new Email("Example");
email.To = "[email protected]";
email.Send();
var viewsPath = Path.GetFullPath(@"..\..\Views");
var engines = new ViewEngineCollection();
engines.Add(new FileSystemRazorViewEngine(viewsPath));
var service = new EmailService(engines);
dynamic email = new Email("Test");
// Will look for Test.cshtml or Test.vbhtml in Views directory.
email.Message = "Hello, non-asp.net world!";
service.Send(email);
// RESTORE DATABASE is terminating abnormally.
}
示例9: TemplateViewRenderer
/// <summary>
/// Creates a new <see cref="TemplateViewRenderer"/> that uses the given view engines.
/// </summary>
/// <param name="viewEngines">The view engines to use when rendering Template views.</param>
public TemplateViewRenderer(ViewEngineCollection viewEngines)
{
if (viewEngines == null) throw new ArgumentNullException(nameof(viewEngines));
_viewEngines = viewEngines;
ViewDirectoryName = "Templates";
}
示例10: RegisterViewEngines
public static void RegisterViewEngines(ViewEngineCollection viewEngines)
{
// Theeming works in combination with IThemeable on the start page to lookup
// views and resources below /themes/name/ before falling back to root
// viewEngines.RegisterThemeViewEngine<RazorViewEngine>("~/Themes/");
}
示例11: CreateEngine
public static PrecompileEngine CreateEngine(ViewEngineCollection engines)
{
var en = new PrecompileEngine();
engines.Insert(0, en);
VirtualPathFactoryManager.RegisterVirtualPathFactory(en);
return en;
}
示例12: FindPartialViewAggregatesAllSearchedLocationsIfAllEnginesFail
public void FindPartialViewAggregatesAllSearchedLocationsIfAllEnginesFail()
{
// Arrange
ControllerContext context = new Mock<ControllerContext>().Object;
ViewEngineCollection viewEngineCollection = new ViewEngineCollection();
Mock<IViewEngine> engine1 = new Mock<IViewEngine>();
ViewEngineResult engine1Result = new ViewEngineResult(new[] { "location1", "location2" });
engine1.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine1Result);
Mock<IViewEngine> engine2 = new Mock<IViewEngine>();
ViewEngineResult engine2Result = new ViewEngineResult(new[] { "location3", "location4" });
engine2.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine2Result);
viewEngineCollection.Add(engine1.Object);
viewEngineCollection.Add(engine2.Object);
// Act
ViewEngineResult result = viewEngineCollection.FindPartialView(context, "partial");
// Assert
Assert.Null(result.View);
Assert.Equal(4, result.SearchedLocations.Count());
Assert.True(result.SearchedLocations.Contains("location1"));
Assert.True(result.SearchedLocations.Contains("location2"));
Assert.True(result.SearchedLocations.Contains("location3"));
Assert.True(result.SearchedLocations.Contains("location4"));
}
示例13: Register
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets)
{
container.Configure(x =>
{
x.For<IAtomPubService>().Singleton().Add<AtomPubService>();
//this is default controller for all, no name given
x.For<IController>().Add<AtomPubController>();
});
RegisterController<AtomPubController>(container);
RegisterRoutes<AtomPubRouteRegistrar>(container, routes);
//register main site master page
RegisterPage(container, new Page("Site")
{
Areas = new[] { "head", "nav", "content", "sidetop", "sidemid", "sidebot", "foot", "tail" },
SupportedScopes = SupportedScopes.EntireSite | SupportedScopes.Workspace | SupportedScopes.Collection | SupportedScopes.Entry
});
//register other pages
RegisterPage(container, new Page("AtomPubIndex", "Site")
{
SupportedScopes = SupportedScopes.EntireSite | SupportedScopes.Collection | SupportedScopes.Workspace
});
RegisterPage(container, new Page("AtomPubResource", "Site")
{
SupportedScopes = SupportedScopes.Entry
});
}
示例14: DefaultConstructor
public void DefaultConstructor() {
// Act
ViewEngineCollection collection = new ViewEngineCollection();
// Assert
Assert.AreEqual(0, collection.Count);
}
示例15: RegisterViewEngine
public static void RegisterViewEngine(ViewEngineCollection engines)
{
var sparkSettings = new SparkSettings();
sparkSettings
.AddNamespace("System")
.AddNamespace("System.Collections.Generic")
.AddNamespace("System.Linq")
.AddNamespace("System.Web.Mvc")
.AddNamespace("System.Web.Mvc.Html");
sparkSettings
.AddAssembly("Spark.Web.Mvc")
.AddAssembly("System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35")
.AddAssembly("System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
var builder = new DefaultDescriptorBuilder();
builder.Filters.Add(new AreaDescriptorFilter());
var container = SparkEngineStarter.CreateContainer(sparkSettings);
container.SetServiceBuilder<Spark.Web.Mvc.IDescriptorBuilder>(c => builder);
SparkEngineStarter.RegisterViewEngine(container);
engines.Add(new SparkViewFactory(sparkSettings));
}