/// <summary> /// Compares the value associated with the current request to the value /// provided using the operator provided. If the operation fails false /// is returned. /// </summary> /// <remarks> /// Method assumes that if device detection is enabled the capabilities /// provider being used for requests is configured to provider results for /// the property name. /// </remarks> /// <param name="propertyName">Name of the property to be tested</param> /// <param name="value">Value to be compared against</param> /// <param name="conditionOperator">Test to be applied between the two values</param> /// <returns> /// True if the condition operator for the values is satisfied, otherwise false. /// </returns> internal static bool GetDoubleProperty(string propertyName, double value, ConditionOperator conditionOperator) { try { var requestValue = MainUtil.GetFloat(HttpContext.Current.Request.Browser[propertyName], 0); switch (conditionOperator) { case ConditionOperator.Equal: return(requestValue == value); case ConditionOperator.GreaterThanOrEqual: return(requestValue >= value); case ConditionOperator.GreaterThan: return(requestValue > value); case ConditionOperator.LessThanOrEqual: return(requestValue <= value); case ConditionOperator.LessThan: return(requestValue < value); case ConditionOperator.NotEqual: return(requestValue != value); default: return(false); } } catch (Exception) { return(false); } }
protected virtual void ParseNode(SafeDictionary <string> attributes) { Assert.ArgumentNotNull(attributes, "attributes"); var str = Extract(attributes, "outputMethod"); xhtml = str == "xhtml" || Settings.Rendering.ImagesAsXhtml && str != "html"; source = Extract(attributes, "src"); alt = Extract(attributes, "alt"); border = Extract(attributes, "border"); hspace = Extract(attributes, "hspace"); vspace = Extract(attributes, "vspace"); className = Extract(attributes, "class"); if (string.IsNullOrEmpty(border) && !xhtml) { border = "0"; } allowStretch = MainUtil.GetBool(Extract(attributes, ref asSet, "allowStretch", "as"), false); ignoreAspectRatio = MainUtil.GetBool(Extract(attributes, "ignoreAspectRatio", "iar"), false); width = MainUtil.GetInt(Extract(attributes, ref widthSet, "width", "w"), 0); height = MainUtil.GetInt(Extract(attributes, ref heightSet, "height", "h"), 0); scale = MainUtil.GetFloat(Extract(attributes, ref scaleSet, "scale", "sc"), 0.0f); maxWidth = MainUtil.GetInt(Extract(attributes, ref maxWidthSet, "maxWidth", "mw"), 0); maxHeight = MainUtil.GetInt(Extract(attributes, ref maxHeightSet, "maxHeight", "mh"), 0); thumbnail = MainUtil.GetBool(Extract(attributes, ref thumbnailSet, "thumbnail", "thn"), false); backgroundColor = Extract(attributes, "backgroundColor", "bc") ?? string.Empty; database = Extract(attributes, "database", "db"); language = Extract(attributes, "language", "la"); version = Extract(attributes, "version", "vs"); disableMediaCache = MainUtil.GetBool(Extract(attributes, ref disableMediaCacheSet, "disableMediaCache"), false); }
/// <summary> /// When overridden in a derived class, this method contains the code to determine whether the value in the input control is valid. /// </summary> /// <returns>The result of the evaluation.</returns> protected override ValidatorResult Evaluate() { int minWidth = MainUtil.GetInt(Parameters["MinWidth"], 0); int minHeight = MainUtil.GetInt(Parameters["MinHeight"], 0); int maxWidth = MainUtil.GetInt(Parameters["MaxWidth"], int.MaxValue); int maxHeight = MainUtil.GetInt(Parameters["MaxHeight"], int.MaxValue); float aspectRatio = MainUtil.GetFloat(Parameters["AspectRatio"], 0.00f); if (ItemUri != null) { if (MediaItem == null) { return(ValidatorResult.Valid); } int width = MainUtil.GetInt(MediaItem.InnerItem["Width"], 0); int height = MainUtil.GetInt(MediaItem.InnerItem["Height"], 0); if (minWidth == maxWidth && minHeight == maxHeight && (width != minWidth || height != minHeight)) { return(GetResult("The image referenced in the Image field \"{0}\" does not match the size requirements. Image needs to be exactly {1}x{2} but is {3}x{4}", GetField().DisplayName, minWidth.ToString(), minHeight.ToString(), width.ToString(), height.ToString())); } if (aspectRatio != 0.00f && height != 0 && (Math.Round((double)width / height, 2) != Math.Round(aspectRatio, 2))) { return(GetResult("The image referenced in the Image field \"{0}\" has an invalid aspect ratio. The aspect ratio needs to be {1} but is {2}.", GetField().DisplayName, Math.Round(aspectRatio, 2).ToString(), (Math.Round((double)width / height, 2).ToString()))); } if (width < minWidth) { return(GetResult("The image referenced in the Image field \"{0}\" is too small. The width needs to be at least {1} pixels but is {2}.", GetField().DisplayName, minWidth.ToString(), width.ToString())); } if (height < minHeight) { return(GetResult("The image referenced in the Image field \"{0}\" is too small. The height needs to be at least {1} pixels but is {2}.", GetField().DisplayName, minHeight.ToString(), height.ToString())); } if (width > maxWidth) { return(GetResult("The image referenced in the Image field \"{0}\" is too big. The width needs to at most {1} pixels but is {2}.", GetField().DisplayName, maxWidth.ToString(), width.ToString())); } if (height > maxHeight) { return(GetResult("The image referenced in the Image field \"{0}\" is too big. The height needs to be at most {1} pixels but is {2}.", GetField().DisplayName, maxHeight.ToString(), height.ToString())); } } return(ValidatorResult.Valid); }
/// <summary> /// If the value associated with the current request is between the lower /// and upper parameters returns true. /// </summary> /// <remarks> /// Method assumes that if device detection is enabled the capabilities /// provider being used for requests is configured to provider results for /// the property name. /// </remarks> /// <param name="propertyName">Name of the property to be tested</param> /// <param name="lower">Lower limit for the comparison</param> /// <param name="upper">Upper limit for the comparison</param> /// <returns>True if the current requests value is between the limits, otherwise false</returns> internal static bool GetCompareProperty(string propertyName, double lower, double upper) { try { var requestValue = MainUtil.GetFloat(HttpContext.Current.Request.Browser[propertyName], 0); return(requestValue >= lower && requestValue <= upper); } catch (Exception) { return(false); } }
/// <summary> /// Handles the DataBinding event of the literalControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void literalControl_DataBinding(object sender, EventArgs e) { var target = (Literal)sender; Control container = target.NamingContainer; var dataItem = DataBinder.GetDataItem(container) as BaseItem; if (dataItem != null) { float fieldValue = MainUtil.GetFloat(dataItem[this.FieldName], 0); target.Text = fieldValue.ToString("P"); } }
/// <summary> /// Handles the DataBinding event of the dataLabel control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void dataLabel_DataBinding(object sender, EventArgs e) { var target = (Control)sender; Control container = target.NamingContainer; var dataItem = DataBinder.GetDataItem(container) as BaseItem; if (dataItem != null) { object fieldValue; switch (this.Field.Type) { case "Currency": fieldValue = String.IsNullOrEmpty(dataItem[this.fieldName]) ? (object)dataItem[this.fieldName] : MainUtil.GetFloat(dataItem[this.fieldName], 0); break; default: fieldValue = dataItem[this.fieldName]; break; } string serverUrl = StringUtil.EnsurePostfix('/', Sitecore.Web.WebUtil.GetServerUrl(dataItem.WebUrl, false)); switch (this.fieldName) { case "ows_LinkFilename": case "ows_LinkTitle": var linkButtonControl = (LinkButton)sender; linkButtonControl.Text = (string)fieldValue; Control parentCell = linkButtonControl.Parent; while (!(parentCell is TableCell) && parentCell.Parent != null) { parentCell = parentCell.Parent; } if (parentCell is TableCell) { (parentCell as TableCell).CssClass = "NameCell"; } if (!IsFolderItem(dataItem)) { ClientAction defaultAction = dataItem.GetActions().GetDefault() as ClientAction ?? dataItem.GetActions()["open"] as ClientAction; if (defaultAction != null) { linkButtonControl.OnClientClick = defaultAction.Script; } } else { linkButtonControl.OnClientClick = string.Format("goToFolder('{0}','{1}');return true;", dataItem.Title, folderPath); } break; case "ows_DocIcon": var linkButton = (LinkButton)sender; string imageUrl = string.Empty; var img = new Image(); img.Style.Add(HtmlTextWriterStyle.Margin, "1px"); linkButton.Controls.Add(img); if (!IsFolderItem(dataItem)) { if (dataItem is DocumentItem) { imageUrl = ((DocumentItem)dataItem).Thumbnail; if (((DocumentItem)dataItem).IsCheckedOut) { linkButton.Controls.Add(new Image() { CssClass = "overlayForIcon", ImageUrl = "/~/icon/Applications/16x16/nav_up_left_green.png.aspx", Width = Unit.Pixel(8), Height = Unit.Pixel(8) }); } } ClientAction defaultAction = dataItem.GetActions().GetDefault() as ClientAction ?? dataItem.GetActions()["open"] as ClientAction; if (defaultAction != null) { linkButton.OnClientClick = defaultAction.Script; } } else { linkButton.OnClientClick = string.Format("goToFolder('{0}','{1}');return true;", dataItem.Title, folderPath); imageUrl = ((FolderItem)dataItem).Thumbnail; } if (string.IsNullOrEmpty(imageUrl)) { imageUrl = Images.GetThemedImageSource("Applications/16x16/document_plain.png"); } img.ImageUrl = imageUrl; break; default: var labelControl = (Label)sender; if (!string.IsNullOrEmpty(Field.DisplayImage)) { bool boolFieldValue = MainUtil.GetBool(fieldValue, false); if (boolFieldValue) { labelControl.Controls.Add( new Image { ImageUrl = string.Format( "{0}/_layouts/images/{1}", serverUrl.Trim(new char[] { '/' }), Field.DisplayImage), }); } else { labelControl.Text = " "; } } else { labelControl.Text = (fieldValue is string && String.IsNullOrEmpty((string)fieldValue)) ? " " : string.Format(this.cultureInfo, this.format, fieldValue); } break; } } else { target.Parent.Controls.Add(new Literal() { Text = " " }); } }