Skip to content

Instantly share code, notes, and snippets.

View sshibani's full-sized avatar

Siawash Shibani sshibani

View GitHub Profile
@sshibani
sshibani / Tridion Extension
Last active August 29, 2015 14:07
Tridion extension methods for Tridion TOM.Net API. available as Nuget Package: https://www.nuget.org/packages/Tridion-Extensions-ContentManager/ Source: https://bitbucket.org/sshibani/tridion.extensions
Component comp = Engine.GetObject("tcm:6-4267") as Component;
// retrieve the itemfields
var fields = comp.Fields();
// retrieve the meta itemsfields
var metaFields = comp.MetaFields();
// to retrieve a component that is added to "comp" as a component link:
Component comp = fields.Component("LinkedComponent");
@sshibani
sshibani / Tridion Extension CoreService
Last active August 29, 2015 14:07
Tridion extension methods for Tridion TOM.Net API. available as Nuget Package: https://www.nuget.org/packages/tridion-extensions-coreservice/ Source: https://bitbucket.org/sshibani/tridion.extensions
var client = Wrapper.GetCoreServiceWsHttpInstance(cmsurl, username, password, domain, CoreServiceInstance.Tridion2011);
Console.WriteLine(client.GetApiVersion());
// retrieve a component linked from a component
ComponentData comp = "tcm:5-18".ToTcmUri().GetItem<ComponentData>().GetFieldAsComponent("linkedComponent");
//retrieve a xml representation list of the items within the forlder and its childern
XElement el = "tcm:5-55-2".ToTcmUri().GetListXml(true);
// retrieve field as string from the content
@sshibani
sshibani / MyCustomController
Last active October 9, 2015 13:51
DD4T RestService WebApi
using DD4T.ContentModel.Contracts.Logging;
using System;
using System.Collections.Generic;
using System.Web.Http;
namespace MyDD4T.RestService
{
[RoutePrefix("mycustom")]
public class MyCustomController : ApiController
{
@sshibani
sshibani / Startup.cs
Last active October 9, 2015 13:51
Sample Startup.cs for DD4T.RestService.WebApi
using Microsoft.Owin;
using Owin;
using DD4T.RestService.WebApi;
using Autofac;
using Autofac.Integration.WebApi;
[assembly: OwinStartup(typeof(MyDD4T.RestService.Startup))]
namespace MyDD4T.RestService
{
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using DD4T.RestService.WebApi;
using Autofac;
using Autofac.Integration.WebApi;
using DD4T.ContentModel.Contracts.Logging;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security;
@sshibani
sshibani / Authentication headers
Last active October 30, 2015 09:11
Add Basic authentication header to DD4T Rest Provider
public class HttpClientAuthentication : DD4T.Providers.Rest.IHttpMessageHandlerFactory
{
public HttpMessageHandler CreatePipeline(HttpMessageHandler innerHandler)
{
return HttpClientFactory.CreatePipeline(innerHandler, new[] {
new BasicAuthenticationHandler()
});
}
}
@sshibani
sshibani / global.asax
Last active October 30, 2015 13:28
Globals.asax snippet
ILifetimeScope BuildContainer()
{
var builder = new ContainerBuilder();
builder.RegisterType<HttpClientAuthentication>()
.As<DD4T.Providers.Rest.IHttpMessageHandlerFactory>();
builder.UseDD4T();
}
@sshibani
sshibani / gist:cd32b9ffe4a147c68a01
Created December 29, 2015 12:11
mvc route for dd4t
routes.MapRoute(
name: "TridionPage",
url: "{*PageUrl}",
defaults: new { controller = "Page", action = "Page" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
public class MvcApplication : System.Web.HttpApplication
{
ILifetimeScope BuildContainer()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.UseDD4T();
return builder.Build();
}
protected void Application_Start()
public class PageController : TridionControllerBase
{
public PageController(IPageFactory pageFactor,
IComponentPresentationFactory componentPresentationFactory,
ILogger logger,
IDD4TConfiguration configuration) :
base(pageFactor, componentPresentationFactory, logger, configuration)
{
public override ActionResult Page(string url)