Last active
March 31, 2016 20:34
-
-
Save Mozu-CS/1088b25b8f54a370583c3b3e9ba0a564 to your computer and use it in GitHub Desktop.
A console application for adding a DocumentType, DocumentList, and EntityEditor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<configuration> | |
<startup> | |
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | |
</startup> | |
<appSettings> | |
<add key="TenantId" value="TenantIdValue" /> | |
<add key="SiteId" value="SiteIdValue" /> | |
<add key="ApplicationId" value="AppKeyValue" /> | |
<add key="SharedSecret" value="SharedSecretValue" /> | |
</appSettings> | |
<runtime> | |
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | |
<dependentAssembly> | |
<assemblyIdentity version="4.5.0.0" name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | |
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> | |
</dependentAssembly> | |
<dependentAssembly> | |
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" /> | |
<bindingRedirect oldVersion="0.0.0.0-1.2.15.0" newVersion="1.2.15.0" /> | |
</dependentAssembly> | |
</assemblyBinding> | |
</runtime> | |
</configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Mozu.Api.ToolKit; | |
using System; | |
namespace AMSXBGCONSOLE | |
{ | |
class Bootstrapper : AbstractBootstrapper | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<packages> | |
<package id="Autofac" version="3.4.1" targetFramework="net45" /> | |
<package id="log4net" version="2.0.5" targetFramework="net45" /> | |
<package id="Microsoft.AspNet.WebApi.Client" version="5.1.2" targetFramework="net45" /> | |
<package id="Microsoft.AspNet.WebApi.Core" version="5.1.2" targetFramework="net45" /> | |
<package id="Mozu.Api.SDK" version="1.19.3" targetFramework="net45" /> | |
<package id="Mozu.Api.ToolKit" version="1.2.17" targetFramework="net45" /> | |
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" /> | |
</packages> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using Autofac; | |
using Mozu.Api; | |
using Mozu.Api.ToolKit.Config; | |
using Newtonsoft.Json.Linq; | |
namespace AMSXBGCONSOLE | |
{ | |
class Program | |
{ | |
private static IApiContext _apiContext { get; set; } | |
private static IContainer _container { get; set; } | |
static void Main(string[] args) | |
{ | |
var apiContext = Program.GenerateApicontext(); | |
var documentResource = new Mozu.Api.Resources.Content.Documentlists.DocumentResource(apiContext); | |
var documentListResource = new Mozu.Api.Resources.Content.DocumentListResource(apiContext); | |
var documentTypeResource = new Mozu.Api.Resources.Content.DocumentTypeResource(apiContext); | |
var appSetting = _container.Resolve<IAppSetting>(); | |
var mozuNamespaceFromApplicationKey = appSetting.ApplicationId.Split('.')[0]; | |
var tenantId = int.Parse(appSetting.Settings["TenantId"].ToString()); | |
var entityEditorDocumentTypeFQN = "entityEditor@mozu"; | |
var entityEditorListFQN = "entityEditors@mozu"; | |
var documentType = new Mozu.Api.Contracts.Content.DocumentType() | |
{ | |
Name = "press-release-template", | |
Namespace = mozuNamespaceFromApplicationKey, | |
Metadata = new JObject(new JProperty("isWebPage", true)), | |
Properties = new List<Mozu.Api.Contracts.Content.Property>() | |
{ | |
new Mozu.Api.Contracts.Content.Property() | |
{ | |
IsRequired = true, | |
Name = "title", | |
PropertyType = new Mozu.Api.Contracts.Content.PropertyType() | |
{ | |
PropertyTypeFQN = "string@mozu", | |
DataType = "string" | |
} | |
}, | |
new Mozu.Api.Contracts.Content.Property() | |
{ | |
IsRequired = true, | |
Name = "body", | |
PropertyType = new Mozu.Api.Contracts.Content.PropertyType() | |
{ | |
PropertyTypeFQN = "string@mozu", | |
DataType = "string" | |
} | |
}, | |
new Mozu.Api.Contracts.Content.Property() | |
{ | |
IsRequired = true, | |
Name = "date", | |
PropertyType = new Mozu.Api.Contracts.Content.PropertyType() | |
{ | |
PropertyTypeFQN = "datetime@mozu", | |
DataType = "DateTime" | |
} | |
} | |
} | |
}; | |
var returnedDocumentType = documentTypeResource.CreateDocumentTypeAsync(documentType: documentType).Result; | |
var documentView = new Mozu.Api.Contracts.Content.View() | |
{ | |
Name = "default", | |
IsVisibleInStorefront = true, | |
Fields = new List<Mozu.Api.Contracts.Content.ViewField>() | |
{ | |
new Mozu.Api.Contracts.Content.ViewField() | |
{ | |
Name = "title", | |
Target = "properties.title" | |
}, | |
new Mozu.Api.Contracts.Content.ViewField() | |
{ | |
Name = "body", | |
Target = "properties.body" | |
}, | |
new Mozu.Api.Contracts.Content.ViewField() | |
{ | |
Name = "date", | |
Target = "properties.date" | |
} | |
} | |
}; | |
var documentList = new Mozu.Api.Contracts.Content.DocumentList() | |
{ | |
Name = "press-releases", | |
Namespace = mozuNamespaceFromApplicationKey, | |
DocumentTypes = new List<string>() | |
{ | |
String.Format("{0}@{1}", returnedDocumentType.Name, returnedDocumentType.Namespace) | |
}, | |
SupportsPublishing = true, | |
EnablePublishing = true, | |
SupportsActiveDateRanges = true, | |
EnableActiveDateRanges = true, | |
Views = new List<Mozu.Api.Contracts.Content.View>() | |
{ | |
documentView | |
}, | |
ScopeType = "Tenant", | |
ScopeId = tenantId | |
}; | |
var returnedDocumentList = documentListResource.CreateDocumentListAsync(list: documentList).Result; | |
var entityEditor = new Mozu.Api.Contracts.Content.Document() | |
{ | |
DocumentTypeFQN = entityEditorDocumentTypeFQN, | |
ListFQN = entityEditorListFQN, | |
Name = "press-release-editor", | |
Properties = new JObject(new JProperty("code", | |
@"Ext.create('Ext.form.Panel', { | |
title:""Press Release Editor"", | |
items:[{ | |
xtype:""textfield"", | |
fieldLabel:""Title"", | |
name:""title"" | |
}, | |
{ | |
xtype:""textarea"", | |
fieldLabel:""Body"", | |
name:""body"" | |
}, | |
{ | |
xtype:""datefield"", | |
fieldLabel:""Date"", | |
name:""date"" | |
}], | |
setData: function (data) { | |
this.getForm().setValues(data); | |
this.data = data; | |
}, | |
getData: function () { | |
var data = this.getValues(false, false, false, true); | |
return Ext.applyIf(data, this.data); | |
} | |
});" | |
), | |
new JProperty("priority", 0), | |
new JProperty("documentLists", new List<String>() { returnedDocumentList.ListFQN }), | |
new JProperty("documentTypes", new List<String>() { String.Format("{0}@{1}", returnedDocumentType.Name, returnedDocumentType.Namespace) })) | |
}; | |
var returnedEntityEditor = documentResource.CreateDocumentAsync(document: entityEditor, documentListName: entityEditorListFQN).Result; | |
Console.ReadLine(); | |
} | |
private static IApiContext GenerateApicontext() | |
{ | |
_container = new Bootstrapper().Bootstrap().Container; | |
var appSetting = _container.Resolve<IAppSetting>(); | |
var tenantId = int.Parse(appSetting.Settings["TenantId"].ToString()); | |
var siteId = int.Parse(appSetting.Settings["SiteId"].ToString()); | |
_apiContext = new ApiContext(siteId: siteId, tenantId: tenantId); | |
return _apiContext; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment