本文整理汇总了C#中IPropertyBag.TryGetAndRemove方法的典型用法代码示例。如果您正苦于以下问题:C# IPropertyBag.TryGetAndRemove方法的具体用法?C# IPropertyBag.TryGetAndRemove怎么用?C# IPropertyBag.TryGetAndRemove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPropertyBag
的用法示例。
在下文中一共展示了IPropertyBag.TryGetAndRemove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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.");
}
示例2: 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 the input
int pageNumber;
var hasPageNumber = parameters.TryGetAndRemove(context, "pageNumber", out pageNumber);
int pageSize;
var hasPageSize = parameters.TryGetAndRemove(context, "pageSize", out pageSize);
// add the paging query component
if ((hasPageNumber && hasPageSize))
query.Add(new PagingQueryComponent(pageNumber, pageSize));
}
示例3: Get
/// <summary>
/// Gets the dataset.
/// </summary>
/// <param name="context">The request context.</param>
/// <param name="attributes">The attributes of this tag.</param>
/// <returns>Returns the result.</returns>
protected override Dataset Get(IMansionContext context, IPropertyBag attributes)
{
// get the component and method names
string componentName;
if (!attributes.TryGetAndRemove(context, "componentName", out componentName))
throw new AttributeNullException("componentName", this);
string methodName;
if (!attributes.TryGetAndRemove(context, "methodName", out methodName))
throw new AttributeNullException("methodName", this);
// invoke the method
return context.InvokeMethodOnComponent<Dataset>(componentName, methodName, attributes);
}
示例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)
{
// check for search
string where;
if (parameters.TryGetAndRemove(context, "sqlWhere", out where) && !string.IsNullOrEmpty(where))
query.Add(new SqlWhereSpecification(where));
}
示例5: 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 the cache flag
object tmp;
if (parameters.TryGetAndRemove(context, StorageOnlyQueryComponent.PropertyKey, out tmp))
query.Add(new StorageOnlyQueryComponent());
}
示例6: 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 clauseCounter = 0;
// get the depth
var depthValue = new Lazy<int?>(() =>
{
int? depth = 1;
string depthString;
if (parameters.TryGetAndRemove(context, "depth", out depthString))
{
// check for any
if ("any".Equals(depthString, StringComparison.OrdinalIgnoreCase))
depth = null;
else
{
// parse the depth
depth = conversionService.Convert(context, depthString, 1);
}
}
return depth;
});
// check for parentPointer
NodePointer parentPointer;
if (parameters.TryGetAndRemove(context, "childPointer", out parentPointer))
{
query.Add(ParentOfSpecification.Child(parentPointer, depthValue.Value));
clauseCounter++;
}
// check for pointer
Node parentNode;
if (parameters.TryGetAndRemove(context, "childSource", out parentNode))
{
query.Add(ParentOfSpecification.Child(parentNode.Pointer, depthValue.Value));
clauseCounter++;
}
// sort on depth if no explicit sort has been set
if (clauseCounter > 0 && !parameters.Contains("sort"))
query.Add(new SortQueryComponent(DefaultSort));
// check for ambigous parameters
if (clauseCounter > 1)
throw new InvalidOperationException("Detected an ambigious parent of clause. Remove either childPointer or childSource.");
}
示例7: 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)
{
// parse the sorts and add them to the query
string sortString;
if (parameters.TryGetAndRemove(context, "sort", out sortString) && !string.IsNullOrEmpty(sortString))
query.Add(Sort.Parse(sortString));
else
query.Add(Sort.DefaultSort);
}
示例8: 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)
{
int limit;
if (!parameters.TryGetAndRemove(context, "limit", out limit))
return;
// parse the sorts and add them to the query
query.Add(new LimitQueryComponent(limit));
}
示例9: 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)
{
Specification where;
if (!parameters.TryGetAndRemove(context, "where", out where))
return;
// parse the sorts and add them to the query
query.Add(where);
}
示例10: 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 the cache flag
bool isCachable;
if (!parameters.TryGetAndRemove(context, "cache", out isCachable))
isCachable = true;
// add the query component
query.Add(new CacheQueryComponent(isCachable));
}
示例11: 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)
{
// if the authorization is bypassed do not add the security check
// TODO: add validator logic to make sure the type supports authorization
bool bypassAuthorization;
if (parameters.TryGetAndRemove(context, "bypassAuthorization", out bypassAuthorization) && bypassAuthorization)
query.Add(AllowedRolesSpecification.Any());
else
query.Add(AllowedRolesSpecification.UserRoles(context));
}
示例12: Get
/// <summary>
/// Gets the row.
/// </summary>
/// <param name="context">The request context.</param>
/// <param name="attributes">The attributes of this tag.</param>
/// <returns>Returns the result.</returns>
protected override IPropertyBag Get(IMansionContext context, IPropertyBag attributes)
{
// check if query source is specified
IPropertyBag queryProperties;
if (attributes.TryGetAndRemove(context, "querySource", out queryProperties))
attributes = queryProperties.Copy().Merge(attributes);
// invoke template method
return Retrieve(context, attributes, context.Repository, parser);
}
示例13: 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)
{
// loop over all the facet properties
var facetPropertyNames = parameters.Names.Where(candidate => candidate.StartsWith("facet")).ToList();
foreach (var facetPropertyName in facetPropertyNames)
{
// retrieve the facet from the property
FacetDefinition facet;
if (!parameters.TryGetAndRemove(context, facetPropertyName, out facet))
throw new InvalidOperationException(string.Format("Property {0} did not contain a valid facet", facetPropertyName));
// add the query component
query.Add(new FacetQueryComponent(facet));
}
}
示例14: 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)
{
// set all the column values as properties
foreach (var ordinals in dbRecord.GetUnreadOrdinals())
{
// if the column is empty remove the value from the properties, otherwise set the value from the column
if (dbRecord.IsDBNull(ordinals))
{
object obj;
properties.TryGetAndRemove(context, dbRecord.GetName(ordinals), out obj);
}
else
properties.Set(dbRecord.GetName(ordinals), dbRecord.GetValue(ordinals));
}
}
示例15: 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)
{
// get the type name is any
string typeNames;
if (!parameters.TryGetAndRemove(context, "type", out typeNames) && string.IsNullOrEmpty(typeNames))
return;
// parse the type names
var types = typeNames.Split(',').Select(x => typeService.Load(context, x)).ToArray();
if (types.Length == 0)
return;
// add the type hints to the query
query.Add(types);
query.Add(new IsPropertyInSpecification("type", types.Select(type => type.Name)));
}