本文整理汇总了C#中System.Item.IsNull方法的典型用法代码示例。如果您正苦于以下问题:C# Item.IsNull方法的具体用法?C# Item.IsNull怎么用?C# Item.IsNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Item
的用法示例。
在下文中一共展示了Item.IsNull方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAchievedGoals
/// <summary>
/// Returns a grouping of achieved goals against visits per variation
/// </summary>
/// <param name="goalItem"></param>
/// <param name="testItem"></param>
/// <param name="startDate"></param>
/// <param name="endDate"></param>
/// <returns></returns>
public List<VisitVariation> GetAchievedGoals(Item goalItem, Item testItem, DateTime startDate, DateTime endDate)
{
if (goalItem.IsNull() || testItem.IsNull())
{
return new List<VisitVariation>();
}
try
{
using (AnalyticsDataContext AnalyticsDataContext = new AnalyticsDataContext(ConfigurationManager.ConnectionStrings["analytics"].ConnectionString))
{
//how many people saw the test
string visitQuery = "select count(*) as VisitCount, dbo.fn_abc_hexadecimal(p.testValues) AS TestValues from pages p " +
"where p.testSetId = {0} and p.[datetime] >= {1} and p.[datetime] <= {2} " +
"group by testValues";
//how many people performed action (EV) against the test?
string evQuery = "select count(*) as AchievedGoalCount, dbo.fn_abc_hexadecimal(testValues) as TestValues from " +
"(" +
"select p.itemId, p.[DateTime], (select distinct(testValues) from pages where testSetId = {0} and visitId = p.visitId) as testValues " +
"from pages p " +
"inner join pageEvents pe on pe.pageId = p.pageId " +
"where pe.pageEventDefinitionId = {1} and p.[datetime] >= {2} and p.[datetime] <= {3} " +
") t " +
"where testValues is not null " +
"group by testValues";
//get page hits
var visitResults = AnalyticsDataContext.ExecuteQuery<VisitVariation>(visitQuery, testItem.ID.RemoveBrackets(), startDate, endDate).ToList();
if (visitResults.Count == 0)
{
return new List<VisitVariation>();
}
//get hits that hit goal
var engagementResults = AnalyticsDataContext.ExecuteQuery<VisitVariation>(evQuery, testItem.ID.RemoveBrackets(), goalItem.ID.RemoveBrackets(), startDate, endDate).ToList();
List<VisitVariation> variations = new List<VisitVariation>();
foreach (VisitVariation variationResult in visitResults)
{
VisitVariation result = variationResult;
Int32 achievedCount = engagementResults.Where(x => x.TestValues == result.TestValues).Select(x => x.AchievedGoalCount).FirstOrDefault();
result.AchievedGoalCount = achievedCount;
variations.Add(result);
}
return variations;
}
}
catch (Exception e)
{
Logger.Error("Page Statistics Context - Could not retrieve the achieved goals");
Logger.Error(e.Message);
Logger.Error(e.InnerException);
}
return new List<VisitVariation>();
}
示例2: Write
public bool Write(Item value)
{
return value is Object && this.Write(value as Object) ||
value is Array && this.Write(value as Array) ||
(value is Null || value.IsNull()) && this.Write(value as Null) ||
value is Boolean && this.Write(value as Boolean) ||
value is Number && this.Write(value as Number) ||
value is String && this.Write(value as String);
}
示例3: GetFieldSuiteImage
/// <summary>
/// Returns the Interface for this item
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static IFieldSuiteImage GetFieldSuiteImage(Item item)
{
if (item.IsNull())
{
return null;
}
XmlNode node = Factory.GetConfigNode("fieldSuite/fields/imagesField");
if (node == null)
{
return null;
}
List<IFieldSuiteImage> mappings = GetFieldSuiteImageMappings(node, item);
if (mappings == null || mappings.Count == 0)
{
return null;
}
return mappings.FirstOrDefault();
}
示例4: Search
/// <summary>
/// An extension of Item that allows you to launch a Search from an item
/// </summary>
/// <returns>List of Results of Type IEnumerable List of SitecoreItem (which implements IItem)</returns>
/// <param name="startLocationItem">The start location of the search</param>
/// <param name="refinements">A collection of refinements to the query</param>
/// <param name="hitCount">This will output the hitCount of the search</param>
/// <param name="relatedIds">Pipe delimited string of Id to query by Links to and from items</param>
/// <param name="indexName">Force query to run on a particular index</param>
/// <param name="text">The raw text query</param>
/// <param name="templates">Pipe delimited string of Id of Templates</param>
/// <param name="location">Override the location of the search with an Id</param>
/// <param name="language">Query by the two letter ISO country code</param>
/// <param name="id">Query by ID</param>
/// <param name="sortField">Sort query by field (must be in index)</param>
/// <param name="sortDirection">Sort in either "asc" or "desc"</param>
/// <param name="itemName">Query by item name</param>
/// <param name="startDate">mm/dd/yyyy format of start date</param>
/// <param name="endDate">mm/dd/yyyy format of end date</param>
/// <param name="numberOfItemsToReturn">0-XXXXXX (The bigger this number is the less performant it will be)</param>
/// <example>BucketManager.Search(Sitecore.Context.Item, text: "Tim", templates: "TemplateGUID")</example>
/// <example>BucketManager.Search(Sitecore.Context.Item, text: "Tim", relatedIds: "ItemGUID", sortField: "_name")</example>
public static IEnumerable<SitecoreItem> Search(Item startLocationItem, SafeDictionary<string> refinements, out int hitCount, IEnumerable<Guid> relatedIds = null, string indexName = "itembuckets_buckets", string text = "", IEnumerable<Guid> templates = null, string location = "", string language = "en", string id = "", string sortField = "", string sortDirection = "", string itemName = "", string startDate = "", string endDate = "", int numberOfItemsToReturn = 20)
{
using (var searcher = new IndexSearcher(indexName))
{
var culture = CultureInfo.CreateSpecificCulture("en-US");
var startDateOut = DateTime.Now;
var endDateOut = DateTime.Now.AddDays(1);
var startFlag = true;
var endFlag = true;
if (!DateTime.TryParse(startDate, culture, DateTimeStyles.None, out startDateOut))
{
startDateOut = DateTime.Now;
startFlag = false;
}
if (!DateTime.TryParse(endDate, culture, DateTimeStyles.None, out endDateOut))
{
endDateOut = DateTime.Now.AddDays(1);
endFlag = false;
}
if (startLocationItem.IsNull())
{
Log.Warn("You are trying to run an Search on an item that has a start location of null", null);
hitCount = 0;
return new List<SitecoreItem>();
}
var dateSearchParam = new DateRangeSearchParam
{
ItemName = itemName,
FullTextQuery = text,
RelatedIds = relatedIds,
TemplateIds = templates,
LocationIds = startLocationItem.ID.ToGuid().ToEnumerable(),
Language = language,
SortDirection = sortDirection,
Refinements = refinements,
ID = id,
SortByField = sortField,
PageSize = numberOfItemsToReturn
};
if (startFlag || endFlag)
{
dateSearchParam.Ranges = new List<DateRangeSearchParam.DateRangeField>
{
new DateRangeSearchParam.DateRangeField(
SearchFieldIDs.CreatedDate,
startDateOut,
endDateOut)
{
InclusiveStart = true, InclusiveEnd = true
}
};
}
var keyValuePair = searcher.GetItems(dateSearchParam);
hitCount = keyValuePair.Key;
return keyValuePair.Value;
}
}
示例5: GetFieldGutterHtml
protected virtual string GetFieldGutterHtml(Item item, string fieldId)
{
if (item.IsNull())
{
return string.Format("<div id=\"{1}_fieldGutterDiv\" class=\"droplinkFieldGutterDiv\">{0}</div>", string.Empty, fieldId);
}
IFieldGutterProcessor fieldGutterProcessor = FieldGutterProcessorFactory.GetProcessor();
if (fieldGutterProcessor == null)
{
return string.Format("<div id=\"{1}_fieldGutterDiv\" class=\"droplinkFieldGutterDiv\">{0}</div>", string.Empty, fieldId);
}
string fieldGutterHtml = fieldGutterProcessor.Process(new FieldGutterArgs(item, fieldId));
if (string.IsNullOrEmpty(fieldGutterHtml))
{
return string.Format("<div id=\"{1}_fieldGutterDiv\" class=\"droplinkFieldGutterDiv\">{0}</div>", string.Empty, fieldId);
}
return string.Format("<div id=\"{1}_fieldGutterDiv\" class=\"droplinkFieldGutterDiv\">{0}</div>", fieldGutterHtml, fieldId);
}
示例6: Render
/// <summary>
/// Renders the list item as Html
/// </summary>
/// <param name="item"></param>
/// <param name="itemId"></param>
/// <param name="fieldId"></param>
/// <param name="useFieldGutter"></param>
/// <returns></returns>
public override string Render(Item item, string itemId, string fieldId, bool useFieldGutter)
{
//defaults
string icon = "/sitecore modules/shell/field suite/document_error.png";
//check item
if (item.IsNull())
{
return RenderItemNotFound(itemId, fieldId);
}
//disable items if the form is read only)
if (ReadOnly)
{
ItemClick = string.Empty;
ButtonClick = string.Empty;
}
string templateName = string.Empty;
//set to items properties
if (item.IsNotNull())
{
icon = item.Appearance.Icon;
TemplateItem template = item.Template;
if (!string.IsNullOrEmpty(template.Name))
{
templateName = template.Name;
}
}
//check and retrieve parameters
string imgElement = string.Empty;
if (Parameters != null && Parameters.Count > 0)
{
imgElement = Parameters[0] as string;
}
string fieldGutterHtml = string.Empty;
IFieldGutterProcessor fieldGutterProcessor = FieldGutterProcessorFactory.GetProcessor();
if (fieldGutterProcessor != null)
{
string html = fieldGutterProcessor.Process(new FieldGutterArgs(item, fieldId));
if (!string.IsNullOrEmpty(html))
{
fieldGutterHtml = html;
}
}
return string.Format(HtmlTemplate,
item.ID,
fieldGutterHtml,
imgElement,
templateName,
Images.GetImage(icon, 0x10, 0x10, "absmiddle", "0px 4px 0px 0px", templateName),
Text,
HoverText,
ItemClick,
SelectedClass);
}
示例7: GetTestVariations_ForCurrentItem
/// <summary>
/// Returns test variations for a specific test and item
/// </summary>
/// <param name="currentItem"></param>
/// <param name="testItem"></param>
/// <param name="startDate"></param>
/// <param name="endDate"></param>
/// <returns></returns>
public List<TestVariationGrouping> GetTestVariations_ForCurrentItem(Item currentItem, Item testItem, DateTime startDate, DateTime endDate)
{
if (currentItem.IsNull())
{
return new List<TestVariationGrouping>();
}
try
{
using (AnalyticsDataContext AnalyticsDataContext = new AnalyticsDataContext(ConfigurationManager.ConnectionStrings["analytics"].ConnectionString))
{
var results = AnalyticsDataContext.Pages
.Where(x =>
x.TestSetId == testItem.Parent.ID.Guid
&& x.ItemId == currentItem.ID.Guid
&& x.DateTime >= startDate
&& x.DateTime <= endDate)
.Select(x => new
{
TestSetID = x.TestSetId,
TestValueString = AnalyticsDataContext.fn_abc_hexadecimal(x.TestValues),
SomeValue = x.Visit.Value
});
var results1 = results.GroupBy(x => x.TestValueString).Select(g => new { TestSet = g.First().TestValueString, Count = g.Count(), ValueSum = g.Sum(x => x.SomeValue) }).ToList();
List<TestVariationGrouping> groupings = new List<TestVariationGrouping>();
foreach (var obj in results1)
{
var binary = obj.TestSet;
var totalVisits = results.Where(x => x.TestValueString == binary).ToList();
var inActiveVisits = results.Where(x => x.SomeValue == 0 && x.TestValueString == binary).ToList();
Int32 activeVisits = 0;
if (totalVisits.Count > 0)
{
activeVisits = totalVisits.Count - inActiveVisits.Count;
}
TestVariationGrouping grouping = new TestVariationGrouping(obj.TestSet, obj.ValueSum, obj.Count);
grouping.TotalVisits = totalVisits.Count;
grouping.ActiveVisits = activeVisits;
grouping.InActiveVisits = inActiveVisits.Count;
groupings.Add(grouping);
}
return groupings;
}
}
catch (Exception e)
{
Logger.Error("Page Statistics Context - Could not retrieve the test variations");
Logger.Error(e.Message);
Logger.Error(e.InnerException);
}
return new List<TestVariationGrouping>();
}
示例8: RenderItem
/// <summary>
/// Renders an item
/// </summary>
/// <param name="item"></param>
/// <param name="selectedItem"></param>
/// <returns></returns>
public virtual string RenderItem(Item item, bool selectedItem)
{
FieldSuiteListItem listItem = new FieldSuiteListItem();
if (item.IsNull())
{
//return not found list item template
listItem.ShowAddRemoveButton = true;
return listItem.RenderItemNotFound(item.ID.ToString(), this.ID);
}
listItem.ShowAddRemoveButton = true;
listItem.ButtonClick = string.Format("FieldSuite.Fields.ToggleItem('{0}', this);", this.ID);
listItem.ItemClick = "FieldSuite.Fields.SelectItem(this);";
listItem.SelectedClass = "velirFieldSelected";
listItem.ReadOnly = this.ReadOnly;
listItem.Text = item.DisplayName;
listItem.HoverText = item.Paths.FullPath;
Int32 renderCount = RenderItemCount;
if (selectedItem)
{
renderCount = RenderSelectedItemCount;
}
//for performance reason limit field gutter
bool useFieldGutter = false;
IFieldGutterProcessor fieldGutterProcessor = FieldGutterProcessorFactory.GetProcessor();
if (fieldGutterProcessor != null)
{
Int32 maxCount = fieldGutterProcessor.MaxCount;
if (maxCount != 0 && renderCount <= maxCount)
{
useFieldGutter = true;
}
}
//return list item as html
if (selectedItem)
{
RenderSelectedItemCount++;
}
else
{
RenderItemCount++;
}
return listItem.Render(item, item.ID.ToString(), this.ID, useFieldGutter);
}
示例9: GetFullParameters
/// <summary>
/// Gets the full parameters.
/// </summary>
/// <param name="startLocationItem">The start location item.</param>
/// <param name="refinements">The refinements.</param>
/// <param name="relatedIds">The related ids.</param>
/// <param name="p">The p.</param>
/// <param name="text">The text.</param>
/// <param name="templates">The templates.</param>
/// <param name="location">The location.</param>
/// <param name="language">The language.</param>
/// <param name="id">The id.</param>
/// <param name="sortField">The sort field.</param>
/// <param name="sortDirection">The sort direction.</param>
/// <param name="itemName">Name of the item.</param>
/// <param name="startDate">The start date.</param>
/// <param name="endDate">The end date.</param>
/// <param name="numberOfItemsToReturn">The number of items to return.</param>
/// <param name="pageNumber">The page number.</param>
/// <param name="customParametersOccurance">The custom parameters occurrence.</param>
/// <returns>The date range search parameters.</returns>
private static DateRangeSearchParam GetFullParameters(
Item startLocationItem,
SafeDictionary<string> refinements,
string relatedIds,
string p,
string text,
string templates,
string location,
string language,
string id,
string sortField,
string sortDirection,
string itemName,
string startDate,
string endDate,
int numberOfItemsToReturn,
int pageNumber,
QueryOccurance customParametersOccurance)
{
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
DateTime startDateOut;
bool startFlag = true;
if (!DateTime.TryParse(startDate, culture, DateTimeStyles.None, out startDateOut))
{
startDateOut = DateTime.Now;
startFlag = false;
}
DateTime endDateOut;
bool endFlag = true;
if (!DateTime.TryParse(endDate, culture, DateTimeStyles.None, out endDateOut))
{
endDateOut = DateTime.Now.AddDays(1);
endFlag = false;
}
if (startLocationItem.IsNull())
{
Log.Warn("You are trying to run an Search on an item that has a start location of null", null);
return null;
}
var dateSearchParam = new DateRangeSearchParam
{
ItemName = itemName,
FullTextQuery = text,
RelatedIds = relatedIds,
TemplateIds = templates,
LocationIds = startLocationItem.ID.ToString(),
Language = language,
ID = id,
SortDirection = sortDirection,
SortByField = sortField,
PageSize = numberOfItemsToReturn,
PageNumber = pageNumber,
Refinements = refinements,
Occurance = customParametersOccurance
};
if (startFlag || endFlag)
{
dateSearchParam.Ranges = new List<DateRangeSearchParam.DateRangeField>
{
new DateRangeSearchParam.DateRangeField(
SearchFieldIDs.CreatedDate,
startDateOut,
endDateOut)
{
InclusiveStart = true,
InclusiveEnd = true
}
};
}
return dateSearchParam;
}