本文整理汇总了C#中IMansionContext类的典型用法代码示例。如果您正苦于以下问题:C# IMansionContext类的具体用法?C# IMansionContext怎么用?C# IMansionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMansionContext类属于命名空间,在下文中一共展示了IMansionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoExecute
/// <summary>
/// </summary>
/// <param name="context"></param>
protected override void DoExecute(IMansionContext context)
{
// get the properties
var sectionProperties = GetAttributes(context);
// get the section name
string sectionName;
if (!sectionProperties.TryGetAndRemove(context, "name", out sectionName))
throw new InvalidOperationException("The attribute section name is required");
// get the target field
string targetField;
sectionProperties.TryGetAndRemove(context, "targetField", out targetField);
// push the section properties to the stack
using (context.Stack.Push("Section", sectionProperties))
{
// render the section
if (string.IsNullOrWhiteSpace(targetField))
{
using (templateService.Render(context, sectionName))
ExecuteChildTags(context);
}
else
{
using (templateService.Render(context, sectionName, targetField))
ExecuteChildTags(context);
}
}
}
示例2: RecordSet
/// <summary>
/// Creates a filled nodeset.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="properties"></param>
/// <param name="records"></param>
public RecordSet(IMansionContext context, IPropertyBag properties, IEnumerable<Record> records) : base(properties)
{
// validate arguments
if (records == null)
throw new ArgumentNullException("records");
if (properties == null)
throw new ArgumentNullException("properties");
// set values
foreach (var node in records)
RowCollection.Add(node);
Set("count", RowCollection.Count);
// check for paging
var totalRowCount = properties.Get(context, "totalCount", -1);
var pageNumber = properties.Get(context, "pageNumber", -1);
var rowsPerPage = properties.Get(context, "pageSize", -1);
if (totalRowCount != -1 && pageNumber != -1 && rowsPerPage != -1)
SetPaging(totalRowCount, pageNumber, rowsPerPage);
// check for sort
string sortString;
if (properties.TryGet(context, "sort", out sortString))
{
foreach (var sort in Collections.Sort.Parse(sortString))
AddSort(sort);
}
}
示例3: DoExecute
/// <summary>
/// Executes this tag.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
protected override void DoExecute(IMansionContext context)
{
// get the web context
var webContext = context.Cast<IMansionWebContext>();
// get the column
Column column;
if (!webContext.TryPeekControl(out column))
throw new InvalidOperationException(string.Format("'{0}' must be added to a '{1}'", GetType(), typeof (Column)));
// get the property names on which to sort
var propertyName = GetRequiredAttribute<string>(context, "on");
// create the filter
var sort = new ColumnSort
{
PropertyName = propertyName
};
// allow facets
using (webContext.ControlStack.Push(sort))
ExecuteChildTags(webContext);
// set the sort to the column
column.Sort = sort;
}
示例4: DoProcess
/// <summary>
/// Processes the <paramref name="parameters"/> and turn them into <paramref name="query"/>.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="parameters">The parameters which to process.</param>
/// <param name="query">The <see cref="Query"/> in which to set the parameters.</param>
protected override void DoProcess(IMansionContext context, IPropertyBag parameters, Query query)
{
var counter = 0;
// check for id, guid or pointer
int id;
if (parameters.TryGetAndRemove(context, "id", out id))
{
query.Add(new IsPropertyEqualSpecification("id", id));
counter++;
}
string guids;
if (parameters.TryGetAndRemove(context, "guid", out guids) && !string.IsNullOrEmpty(guids))
{
// split the value
var values = guids.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
query.Add(new IsPropertyInSpecification("guid", values));
counter++;
}
NodePointer pointer;
if (parameters.TryGetAndRemove(context, "pointer", out pointer))
{
query.Add(new IsPropertyEqualSpecification("id", pointer.Id));
counter++;
}
// check for ambigous parameters
if (counter > 1)
throw new InvalidOperationException("Detected an ambigious id parmeters. Remove either id, guid or pointer.");
}
示例5: DoAfterUpdate
/// <summary>
/// This method is called just after a node is updated by the repository.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="record"> </param>
/// <param name="properties">The properties which were set to the updated <paramref name="record"/>.</param>
protected override void DoAfterUpdate(IMansionContext context, Record record, IPropertyBag properties)
{
// get the propagate property names
var propagatePropertyNames = properties.Names.Where(x => x.StartsWith(PropagatePrefix, StringComparison.OrdinalIgnoreCase));
// get the property names who's value is true
var propagatedNowProperties = propagatePropertyNames.Where(x => properties.Get(context, x, false));
// loop over all the updated properties and propagated properties
foreach (var propagatePropertyName in propagatedNowProperties)
{
// get the name of the property being propagated
var propagatedPropertyName = propagatePropertyName.Substring(PropagatePrefix.Length);
// get the propagated property value
var propagatedPropertyValue = properties.Get<object>(context, propagatedPropertyName);
// retrieve all the children nodes and update them all
foreach (var childNode in context.Repository.RetrieveNodeset(context, new PropertyBag
{
{"parentSource", record},
{"depth", "any"}
}).Nodes)
{
context.Repository.UpdateNode(context, childNode, new PropertyBag
{
{propagatedPropertyName, propagatedPropertyValue}
});
}
}
}
示例6: DoMap
/// <summary>
/// Maps the given <paramref name="dbRecord"/> to <paramref name="properties"/>.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="dbRecord">The <see cref="DbRecord"/> which to map.</param>
/// <param name="properties">The <see cref="IPropertyBag"/> in which to store the mapped result.</param>
protected override void DoMap(IMansionContext context, DbRecord dbRecord, IPropertyBag properties)
{
// field indices
var idIndex = dbRecord.GetOrdinal("id");
var parentPointerIndex = dbRecord.GetOrdinal("parentPointer");
var nameIndex = dbRecord.GetOrdinal("name");
var parentPathIndex = dbRecord.GetOrdinal("parentPath");
var typeIndex = dbRecord.GetOrdinal("type");
var parentStructureIndex = dbRecord.GetOrdinal("parentStructure");
// assemble the node pointer
var pointer = (dbRecord.IsDBNull(parentPointerIndex) ? string.Empty : dbRecord.GetString(parentPointerIndex) + NodePointer.PointerSeparator) + dbRecord.GetInt32(idIndex);
var structure = (dbRecord.IsDBNull(parentStructureIndex) ? string.Empty : dbRecord.GetString(parentStructureIndex) + NodePointer.StructureSeparator) + dbRecord.GetString(typeIndex);
var path = (dbRecord.IsDBNull(parentPathIndex) ? string.Empty : dbRecord.GetString(parentPathIndex) + NodePointer.PathSeparator) + dbRecord.GetString(nameIndex);
var nodePointer = NodePointer.Parse(pointer, structure, path);
// set the pointer
properties.Set("pointer", nodePointer);
properties.Set("path", nodePointer.PathString);
properties.Set("structure", nodePointer.StructureString);
properties.Set("depth", nodePointer.Depth);
properties.Set("name", nodePointer.Name);
properties.Set("type", nodePointer.Type);
if (nodePointer.HasParent)
{
properties.Set("parentPointer", nodePointer.Parent);
properties.Set("parentId", nodePointer.Parent.Id);
}
}
示例7: DoBeforeUpdate
/// <summary>
/// This method is called just before a node is updated by the repository.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="node">The node which will be modified.</param>
/// <param name="modifiedProperties">The updated properties of the node.</param>
protected override void DoBeforeUpdate(IMansionContext context, Node node, IPropertyBag modifiedProperties)
{
// if the name has not changed we are not interested
string newName;
if (!modifiedProperties.TryGet(context, "name", out newName))
return;
// if the name has not changed after normalization we are not interested
newName = TagUtilities.Normalize(newName);
if (node.Pointer.Name.Equals(newName))
{
modifiedProperties.Remove("name");
return;
}
modifiedProperties.Set("name", newName);
// if the tag is renamed to another already existing tag, move all content to that existing tag and delete this one
Node existingTag;
var tagIndexNode = TagUtilities.RetrieveTagIndexNode(context);
if (TagUtilities.TryRetrieveTagNode(context, tagIndexNode, newName, out existingTag))
{
// TODO: move all content to the existing tag
// TODO: delete this tag
}
}
示例8: Section
/// <summary>
/// Constructs an section.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="properties">The descriptor of this section.</param>
/// <param name="expression">The expressio of this section.</param>
public Section(IMansionContext context, IPropertyBag properties, IExpressionScript expression)
{
// validate arguments
if (context == null)
throw new ArgumentNullException("context");
if (properties == null)
throw new ArgumentNullException("properties");
if (expression == null)
throw new ArgumentNullException("expression");
// set values
Properties = properties;
Expression = expression;
Id = Guid.NewGuid().ToString();
Name = Properties.Get<string>(context, "name");
ShouldBeRenderedOnce = !Properties.Get(context, "repeatable", true);
TargetField = Properties.Get(context, "field", Name);
// check if there is a requires property
string requiresExpressionString;
if (Properties.TryGet(context, "requires", out requiresExpressionString))
{
// assemble the expression
var expressionService = context.Nucleus.ResolveSingle<IExpressionScriptService>();
var requiresExpression = expressionService.Parse(context, new LiteralResource(requiresExpressionString));
// execute the expression
areRequirementsSatisfied = requiresExpression.Execute<bool>;
}
else
areRequirementsSatisfied = mansionContext => true;
}
示例9: DoExecute
/// <summary>
/// </summary>
/// <param name="context"></param>
protected override void DoExecute(IMansionContext context)
{
// validate arguments
if (context == null)
throw new ArgumentNullException("context");
// get the attributes
var attributes = GetAttributes(context);
string extension;
if (!attributes.TryGet(context, "extension", out extension))
attributes.Set("extension", TemplateServiceConstants.DefaultTemplateExtension);
// get the resource paths
var resourcePath = applicationResourceService.ParsePath(context, attributes);
// get the resources
IEnumerable<IResource> resources;
if (GetAttribute(context, "checkExists", true))
resources = applicationResourceService.Get(context, resourcePath);
else
applicationResourceService.TryGet(context, resourcePath, out resources);
// open the templates and executes child tags);
using (templateService.Open(context, resources))
ExecuteChildTags(context);
}
示例10: Create
/// <summary>
/// Creates an instance of <see cref="ChildType"/> from <paramref name="descriptor"/>.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="descriptor">The <see cref="ChildTypeDescriptor"/>.</param>
/// <param name="behavior">The <see cref="CmsBehavior"/>.</param>
public static void Create(IMansionContext context, ChildTypeDescriptor descriptor, CmsBehavior behavior)
{
// validate arguments
if (context == null)
throw new ArgumentNullException("context");
if (descriptor == null)
throw new ArgumentNullException("descriptor");
if (behavior == null)
throw new ArgumentNullException("behavior");
// get the type
var type = descriptor.Properties.Get<ITypeDefinition>(context, "type", null);
var baseType = descriptor.Properties.Get<ITypeDefinition>(context, "baseType", null);
if (type == null && baseType == null)
throw new InvalidOperationException(string.Format("Invalid child type descriptor on type '{0}'. Specify either an type or a baseType.", descriptor.TypeDefinition.Name));
if (type != null && baseType != null)
throw new InvalidOperationException(string.Format("Invalid child type descriptor on type '{0}'. Ambigious type detected. Specify either an type or a baseType.", descriptor.TypeDefinition.Name));
if (type != null)
CreateChildType(context, descriptor, behavior, type);
else
{
CreateChildType(context, descriptor, behavior, baseType);
foreach (var inheritingType in baseType.GetInheritingTypes(context))
CreateChildType(context, descriptor, behavior, inheritingType);
}
}
示例11: DoExecute
/// <summary>
/// </summary>
/// <param name="context">The application context.</param>
protected override void DoExecute(IMansionContext context)
{
// get all attributes
var attributes = GetAttributes(context);
// get the target attribute
string target;
if (!attributes.TryGetAndRemove(context, "target", out target) || string.IsNullOrEmpty(target))
throw new InvalidOperationException("The target attribute is manditory");
bool global;
if (!attributes.TryGetAndRemove(context, "global", out global))
global = false;
// get the result
var results = Get(context, attributes);
// push the node to the stack in the target dataspace
using (context.Stack.Push(target, results, global))
{
// check if the node was found
if (results != null && results.RowCount > 0)
ExecuteChildTags(context);
else
{
// execute not found tag
NotFoundTag notFoundTag;
if (TryGetAlternativeChildTag(out notFoundTag))
notFoundTag.Execute(context);
}
}
}
示例12: Prepare
/// <summary>
/// Prepares an insert query.
/// </summary>
/// <param name="context"></param>
/// <param name="connection">The connection.</param>
/// <param name="transaction">The transaction.</param>
/// <param name="sourceNode"></param>
/// <param name="targetParentNode"></param>
/// <returns></returns>
public void Prepare(IMansionContext context, SqlConnection connection, SqlTransaction transaction, Node sourceNode, Node targetParentNode)
{
// validate arguments
if (connection == null)
throw new ArgumentNullException("connection");
if (transaction == null)
throw new ArgumentNullException("transaction");
if (sourceNode == null)
throw new ArgumentNullException("sourceNode");
if (targetParentNode == null)
throw new ArgumentNullException("targetParentNode");
// get the properties of the new node
var newProperties = new PropertyBag(sourceNode);
// if the target pointer is the same as the parent of the source node, generate a new name to distinguish between the two.
if (sourceNode.Pointer.Parent == targetParentNode.Pointer)
{
// get the name of the node
var name = sourceNode.Get<string>(context, "name");
// change the name to indicate the copied node
newProperties.Set("name", name + CopyPostfix);
}
// create an insert query
command = context.Nucleus.CreateInstance<InsertNodeCommand>();
command.Prepare(context, connection, transaction, targetParentNode.Pointer, newProperties);
}
示例13: DoExecute
/// <summary>
/// </summary>
/// <param name="context"></param>
protected override void DoExecute(IMansionContext context)
{
// get the attributes
var attributes = GetAttributes(context);
// get the XML output pipe
var outputPipe = context.OutputPipe as JsonOutputPipe;
if (outputPipe == null)
throw new InvalidOperationException("No JSON output pipe found on thet stack. Open an JSON output pipe first.");
// start the element
outputPipe.JsonWriter.WriteStartObject();
// render the attributes
foreach (var attribute in attributes)
{
outputPipe.JsonWriter.WritePropertyName(attribute.Key);
outputPipe.JsonWriter.WriteValue(attribute.Value);
}
// render the children
ExecuteChildTags(context);
// finish the element
outputPipe.JsonWriter.WriteEndObject();
}
示例14: DoProcess
/// <summary>
/// Processes the <paramref name="parameters"/> and turn them into <paramref name="query"/>.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="parameters">The parameters which to process.</param>
/// <param name="query">The <see cref="Query"/> in which to set the parameters.</param>
protected override void DoProcess(IMansionContext context, IPropertyBag parameters, Query query)
{
// check for search
string where;
if (parameters.TryGetAndRemove(context, "sqlWhere", out where) && !string.IsNullOrEmpty(where))
query.Add(new SqlWhereSpecification(where));
}
示例15: Search
/// <summary>
/// Performs a search using the specified <paramref name="query"/>.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="query">The <see cref="Query"/> on which to search.</param>
/// <returns>Returns the resulting <see cref="RecordSet"/>.</returns>
/// <exception cref="ArgumentNullException">Thrown if one of the parameters is null.</exception>
/// <exception cref="ConnectionException">Thrown if a error occurred while executing the search query.</exception>
public RecordSet Search(IMansionContext context, Query query)
{
// validate arguments
if (context == null)
throw new ArgumentNullException("context");
if (query == null)
throw new ArgumentNullException("query");
// find the root type for this query
var rootType = query.TypeHints.FindCommonAncestor(context);
// resolve the index definitions of this record
var indexDefinitions = indexDefinitionResolver.Resolve(context, rootType);
// determine the index which to use to perform the search
var indexDefinitionTypeMappingPair = SelectBestIndexForQuery(rootType, query, indexDefinitions);
// create a search descriptor
var search = new SearchQuery(indexDefinitionTypeMappingPair.Item1, indexDefinitionTypeMappingPair.Item2);
// map all the query components to the search descriptor
foreach (var component in query.Components)
converters.Elect(context, component).Map(context, query, component, search);
// execute the query
return Search(context, search);
}