forked from Sitecore/TDS-T4-Model-Generation
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0fd41da
Showing
54 changed files
with
3,351 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Sitecore.Data.Items; | ||
using Herskind.Model.Helper.FieldTypes; | ||
|
||
namespace Herskind.Model.Helper | ||
{ | ||
public class BaseFieldClusterWrapper : IFieldClusterWrapper | ||
{ | ||
protected Item _item; | ||
protected Dictionary<string, IFieldWrapper> _fields = new Dictionary<string,IFieldWrapper>(); | ||
|
||
protected IFieldWrapper GetField(string key) | ||
{ | ||
key = key.ToLower(); | ||
if (!_fields.Keys.Contains(key)) | ||
{ | ||
try | ||
{ | ||
var scField = _item.Fields[key]; | ||
switch (scField.Type.ToLower()) | ||
{ | ||
case "checkbox": | ||
_fields[key] = new BooleanFieldWrapper(scField); | ||
break; | ||
case "image": | ||
_fields[key] = null; | ||
// TODO: image | ||
//return null; | ||
break; | ||
case "date": | ||
case "datetime": | ||
_fields[key] = new DateFieldWrapper(scField); | ||
break; | ||
case "checklist": | ||
case "treelist": | ||
case "treelistex": | ||
case "multilist": | ||
_fields[key] = new ListFieldWrapper(scField); | ||
break; | ||
case "droplink": | ||
case "droptree": | ||
case "general link": | ||
_fields[key] = new LinkFieldWrapper(scField); | ||
break; | ||
case "single-line text": | ||
case "multi-line text": | ||
case "rich text": | ||
_fields[key] = new TextFieldWrapper(scField); | ||
break; | ||
default: | ||
_fields[key] = null; | ||
break; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
// Todo: Log error | ||
} | ||
} | ||
return _fields[key]; | ||
} | ||
|
||
public BaseFieldClusterWrapper(Item item) | ||
{ | ||
_item = item; | ||
} | ||
|
||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Sitecore.Web.UI.WebControls; | ||
using Herskind.Model.Helper.FieldTypes; | ||
|
||
namespace Herskind.Model.Helper | ||
{ | ||
public class BaseFieldWrapper : IFieldWrapper | ||
{ | ||
protected bool _modified = false; | ||
protected Sitecore.Data.Fields.Field _field; | ||
|
||
|
||
public BaseFieldWrapper(Sitecore.Data.Fields.Field field) | ||
{ | ||
Sitecore.Diagnostics.Assert.ArgumentNotNull(field, "field"); | ||
_field = field; | ||
} | ||
|
||
public string RawValue | ||
{ | ||
get | ||
{ | ||
return _field.Value; | ||
} | ||
set | ||
{ | ||
_modified = true; | ||
_field.Value = value; | ||
} | ||
} | ||
|
||
public bool IsModified | ||
{ | ||
get { return _modified; } | ||
} | ||
|
||
public string Render() | ||
{ | ||
return FieldRenderer.Render(_field.Item, _field.Key); | ||
} | ||
|
||
public string Render(string parameters) | ||
{ | ||
return FieldRenderer.Render(_field.Item, _field.Key, parameters); | ||
} | ||
|
||
public object Original | ||
{ | ||
get { return _field; } | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Sitecore.Data.Items; | ||
using Herskind.Model.Helper.FieldTypes; | ||
|
||
namespace Herskind.Model.Helper | ||
{ | ||
public class BaseItemWrapper : IItemWrapper | ||
{ | ||
protected Item _item; | ||
protected Dictionary<string, IFieldWrapper> _fields = new Dictionary<string,IFieldWrapper>(); | ||
|
||
protected IFieldWrapper GetField(string key) | ||
{ | ||
key = key.ToLower(); | ||
if (!_fields.Keys.Contains(key)) | ||
{ | ||
try | ||
{ | ||
var scField = _item.Fields[key]; | ||
switch (scField.Type.ToLower()) | ||
{ | ||
case "checkbox": | ||
_fields[key] = new BooleanFieldWrapper(scField); | ||
break; | ||
case "image": | ||
_fields[key] = null; | ||
// TODO: image | ||
//return null; | ||
break; | ||
case "date": | ||
case "datetime": | ||
_fields[key] = new DateFieldWrapper(scField); | ||
break; | ||
case "checklist": | ||
case "treelist": | ||
case "treelistex": | ||
case "multilist": | ||
_fields[key] = new ListFieldWrapper(scField); | ||
break; | ||
case "droplink": | ||
case "droptree": | ||
case "general link": | ||
_fields[key] = new LinkFieldWrapper(scField); | ||
break; | ||
case "single-line text": | ||
case "multi-line text": | ||
case "rich text": | ||
_fields[key] = new TextFieldWrapper(scField); | ||
break; | ||
default: | ||
_fields[key] = null; | ||
break; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
// Todo: Log error | ||
} | ||
} | ||
return _fields[key]; | ||
} | ||
|
||
public BaseItemWrapper(Item item) | ||
{ | ||
_item = item; | ||
} | ||
|
||
public string DatabaseName | ||
{ | ||
get { return _item.Database.Name; } | ||
} | ||
|
||
public string ItemName | ||
{ | ||
get { return _item.Name; } | ||
} | ||
|
||
public string LanguageName | ||
{ | ||
get { return _item.Language.Name; } | ||
} | ||
|
||
public string ItemLocation | ||
{ | ||
get { return _item.Paths.FullPath; } | ||
} | ||
|
||
public void SaveChanges() | ||
{ | ||
if (_item.Editing.IsEditing) | ||
{ | ||
_item.Editing.EndEdit(); | ||
} | ||
} | ||
|
||
public object Original | ||
{ | ||
get { return _item; } | ||
} | ||
|
||
public string GenerateUrl() | ||
{ | ||
return Sitecore.Links.LinkManager.GetItemUrl(_item); | ||
} | ||
|
||
public string GenerateUrl(bool includeHostname) | ||
{ | ||
var options = Sitecore.Links.LinkManager.GetDefaultUrlOptions(); | ||
options.AlwaysIncludeServerUrl = true; | ||
return Sitecore.Links.LinkManager.GetItemUrl(_item, options); | ||
} | ||
|
||
public IEnumerable<T> SelectChildren<T>() where T : IItemWrapper | ||
{ | ||
IItemFactory factory = ItemFactory.Instance; | ||
return factory.SelectChildrenOfPath<T>(this._item.ID.ToString()); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
code/Herskind.Model.Helper/FieldTypes/BooleanFieldWrapper.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Sitecore.Data.Fields; | ||
|
||
namespace Herskind.Model.Helper.FieldTypes | ||
{ | ||
public class BooleanFieldWrapper : BaseFieldWrapper, IBooleanFieldWrapper | ||
{ | ||
public BooleanFieldWrapper(Field field) | ||
: base(field) | ||
{ | ||
} | ||
|
||
public bool Boolean | ||
{ | ||
get | ||
{ | ||
return RawValue == "1"; | ||
} | ||
set | ||
{ | ||
RawValue = value ? "1" : ""; | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Herskind.Model; | ||
using Sitecore.Data.Fields; | ||
using Sitecore.Data.Items; | ||
|
||
namespace Herskind.Model.Helper.FieldTypes | ||
{ | ||
public class DateFieldWrapper : BaseFieldWrapper, IDateFieldWrapper | ||
{ | ||
public DateFieldWrapper(Field field) | ||
: base(field) | ||
{ | ||
} | ||
|
||
public string Render(string dateFormat) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public DateTime Date | ||
{ | ||
get | ||
{ | ||
return new DateField(_field).DateTime; | ||
} | ||
set | ||
{ | ||
RawValue = Sitecore.DateUtil.ToIsoDate(value, true); | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
code/Herskind.Model.Helper/FieldTypes/IBooleanFieldWrapper.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Herskind.Model.Helper.FieldTypes | ||
{ | ||
public interface IBooleanFieldWrapper : IFieldWrapper | ||
{ | ||
bool Boolean { get; set; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
code/Herskind.Model.Helper/FieldTypes/IDateFieldWrapper.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Herskind.Model.Helper.FieldTypes | ||
{ | ||
public interface IDateFieldWrapper : IFieldWrapper | ||
{ | ||
DateTime Date { get; set; } | ||
string Render(string dateFormat); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
code/Herskind.Model.Helper/FieldTypes/IImageFieldWrapper.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Herskind.Model.Helper.FieldTypes | ||
{ | ||
public interface IImageFieldWrapper : IFieldWrapper | ||
{ | ||
string Render(int width, int height); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
code/Herskind.Model.Helper/FieldTypes/ILinkFieldWrapper.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Herskind.Model.Helper.FieldTypes | ||
{ | ||
public interface ILinkFieldWrapper : IFieldWrapper | ||
{ | ||
string RenderAroundHtml(string innerHTML); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
code/Herskind.Model.Helper/FieldTypes/IListFieldWrapper.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Collections; | ||
|
||
namespace Herskind.Model.Helper.FieldTypes | ||
{ | ||
public interface IListFieldWrapper : IFieldWrapper | ||
{ | ||
IEnumerable<IItemWrapper> Items { get; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
code/Herskind.Model.Helper/FieldTypes/ITextFieldWrapper.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Herskind.Model.Helper.FieldTypes | ||
{ | ||
public interface ITextFieldWrapper : IFieldWrapper | ||
{ | ||
string Render(int lenght, string elipsis); | ||
} | ||
} |
Oops, something went wrong.