public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string plainText = String.Empty; try { if (value != null) { string text = value.ToString(); if (text.Length > 0) { plainText = HtmlUtil.CleanHtml(text); if (parameter != null) { int maxLength = 0; Int32.TryParse(parameter.ToString(), out maxLength); if (maxLength > 0) { plainText = HtmlUtil.Truncate(plainText, maxLength, "..."); } } } } } catch (Exception ex) { AppLogs.WriteError("TextPlainConverter.Convert", ex); } return(plainText); }
/// <summary> /// Executes the Share service. /// </summary> /// <param name="title">The title shared.</param> /// <param name="message">The message shared.</param> /// <param name="link">The link shared.</param> /// <param name="image">The image shared.</param> public void Share(string title, string message, string link, string image) { title = HtmlUtil.CleanHtml(title); message = HtmlUtil.CleanHtml(message); var availableShareTypes = GetAvailableShareTypes(title, message, link, image); OpenShareTypeSelector(availableShareTypes, title, message, link, image); }
/// <summary> /// Sanitize a string. /// </summary> /// <param name="value">The binded string.</param> /// <param name="targetType">The type of the binding target property.</param> /// <param name="parameter">The converter parameter.</param> /// <param name="culture">The culture to be used in the conversion.</param> /// <returns>A regular string.</returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var valueLabel = string.Empty; if (value != null) { valueLabel = HtmlUtil.CleanHtml(value.ToString()); } return(valueLabel); }
/// <summary> /// Converts a regular expression into a binded property and sanitize it. /// </summary> /// <param name="value">The binded object from a repository.</param> /// <param name="targetType">The type of the conversion.</param> /// <param name="parameter">The binding expression.</param> /// <param name="culture">The culture to be used in the conversion.</param> /// <returns>String with resolved bindings.</returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var parameterLabel = parameter as string; if (!string.IsNullOrEmpty(parameterLabel) && value != null) { parameterLabel = BindingExpressionUtil.ResolveBindingExpression(value, parameterLabel); parameterLabel = HtmlUtil.CleanHtml(parameterLabel); } return(parameterLabel); }
static private StandardTileData CreateTileData(TileInfo tileInfo) { return(new StandardTileData { Title = HtmlUtil.CleanHtml(tileInfo.Title), Count = tileInfo.Count, BackTitle = HtmlUtil.CleanHtml(tileInfo.BackTitle), BackContent = HtmlUtil.CleanHtml(tileInfo.BackContent), BackgroundImage = String.IsNullOrEmpty(tileInfo.BackgroundImagePath) ? null : new Uri(tileInfo.BackgroundImagePath, UriKind.RelativeOrAbsolute), BackBackgroundImage = String.IsNullOrEmpty(tileInfo.BackBackgroundImagePath) ? null : new Uri(tileInfo.BackBackgroundImagePath, UriKind.RelativeOrAbsolute) }); }
/// <summary> /// Executes the Share Link service. /// </summary> /// <param name="title">The title shared.</param> /// <param name="message">The message shared.</param> /// <param name="link">The link shared.</param> private static void ShareLink(string title, string message, string link = "") { title = string.IsNullOrEmpty(title) ? string.Empty : HtmlUtil.CleanHtml(title); message = string.IsNullOrEmpty(message) ? string.Empty : HtmlUtil.CleanHtml(message); var linkUri = string.IsNullOrEmpty(link) ? new System.Uri(AppResources.HomeUrl) : new System.Uri(link, System.UriKind.Absolute); var shareLinkTask = new ShareLinkTask { Title = title, Message = message, LinkUri = linkUri }; shareLinkTask.Show(); }
/// <summary> /// Converts a text into a speech and pronounces it. /// </summary> /// <param name="text">The text to be pronounced.</param> static public async void SpeakText(string text) { try { if (!string.IsNullOrEmpty(text)) { await Speech.SpeakTextAsync(HtmlUtil.CleanHtml(text)); } } catch (Exception ex) { AppLogs.WriteError("SpeechServices", ex); } }
/// <summary> /// Resolve an expression with bindings /// </summary> /// <param name="value">Binding data source</param> /// <param name="parameterLabel">Expression with bindings</param> /// <returns></returns> public static string ResolveBindingExpression(object value, string parameterLabel) { var matches = Regex.Matches(parameterLabel, Regexp); foreach (Match match in matches) { var bindingMatch = match.Groups["binding"]; var prop = value.GetType().GetProperty(bindingMatch.Value); string replaceValue = string.Empty; if (prop != null) { replaceValue = prop.GetValue(value).ToString(); } parameterLabel = parameterLabel.Replace("{" + bindingMatch.Value + "}", replaceValue); parameterLabel = HtmlUtil.CleanHtml(parameterLabel); parameterLabel = parameterLabel.Trim(); } return(parameterLabel); }
private static StandardTileData GetStandardTileData(TileInfo tileInfo) { var tileData = new StandardTileData { Title = HtmlUtil.CleanHtml(tileInfo.Title) ?? string.Empty, Count = tileInfo.Count, BackTitle = HtmlUtil.CleanHtml(tileInfo.BackTitle) ?? string.Empty, BackContent = HtmlUtil.CleanHtml(tileInfo.BackContent) ?? string.Empty }; if (!string.IsNullOrEmpty(tileInfo.BackgroundImagePath)) { tileData.BackgroundImage = new Uri(tileInfo.BackgroundImagePath, UriKind.RelativeOrAbsolute); } if (!string.IsNullOrEmpty(tileInfo.BackgroundImagePath)) { tileData.BackBackgroundImage = new Uri(tileInfo.BackBackgroundImagePath, UriKind.RelativeOrAbsolute); } return(tileData); }
/// <summary> /// Converts a text into a speech and pronounces it. /// </summary> /// <param name="text">The text to be pronounced.</param> public async void TextToSpeech(string text) { try { if (!string.IsNullOrEmpty(text)) { var synth = new SpeechSynthesizer(); var language = CultureInfo.CurrentCulture.ToString(); var voices = InstalledVoices.All.Where(v => v.Language == language).OrderByDescending(v => v.Gender); const VoiceGender gender = VoiceGender.Female; synth.SetVoice(voices.FirstOrDefault(v => v.Gender == gender)); await synth.SpeakTextAsync(HtmlUtil.CleanHtml(text)); } } catch (Exception ex) { Debug.WriteLine("{0}{1}. {2}{3}", AppResources.SpeechError, text, AppResources.Error, ex.ToString()); } }