/// <summary> /// Create a nice looking header /// </summary> /// <param name="values"></param> /// <param name="targetType"></param> /// <param name="parameter"></param> /// <param name="culture"></param> /// <returns></returns> public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { // Get values string filter = values[0] as string; string headerText = values[1] as string; // Generate header text string text = "{0}{3}" + headerText + " {4}"; if (!String.IsNullOrEmpty(filter)) { text += "(Filter: {2}" + values[0] + "{4})"; } text += "{1}"; // Escape special XML characters like <>&' text = new System.Xml.Linq.XText(text).ToString(); // Format the text text = String.Format(text, @"<TextBlock xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>", "</TextBlock>", "<Run FontWeight='bold' Text='", "<Run Text='", @"'/>"); // Convert to stream MemoryStream stream = new MemoryStream(ASCIIEncoding.UTF8.GetBytes(text)); // Convert to object TextBlock block = (TextBlock)System.Windows.Markup.XamlReader.Load(stream); return(block); }
/// <summary> /// Create a nice looking header /// </summary> /// <param name="values"></param> /// <param name="targetType"></param> /// <param name="parameter"></param> /// <param name="culture"></param> /// <returns></returns> public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { // Get values string filter = values[0] as string; string headerText = values[1] as string; // Generate header text string text = "{0}{3}" + headerText + " {4}"; if (!String.IsNullOrEmpty(filter)) text += "(Filter: {2}" + values[0] + "{4})"; text += "{1}"; // Escape special XML characters like <>&' text = new System.Xml.Linq.XText(text).ToString(); // Format the text text = String.Format(text, @"<TextBlock xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>", "</TextBlock>", "<Run FontWeight='bold' Text='", "<Run Text='", @"'/>"); // Convert to stream MemoryStream stream = new MemoryStream(ASCIIEncoding.UTF8.GetBytes(text)); // Convert to object TextBlock block = (TextBlock)System.Windows.Markup.XamlReader.Load(stream); return block; }
private void AddScript(ClientContext cc, ListItem item) { var wpm = item.File.GetLimitedWebPartManager(PersonalizationScope.Shared); // context.Load(wpm.WebParts, Function(wps) wps.Include(Function(wp) wp.WebPart.Properties, Function(wp) wp.Id)) cc.Load(wpm.WebParts, wps => wps.Include(wp => wp.WebPart.Properties, wp => wp.Id, wp => wp.WebPart.ExportMode, wp => wp.ZoneId)); cc.Load(item.File.ListItemAllFields); cc.ExecuteQuery(); var content = IO.File.ReadAllText(Script); var escaped = new System.Xml.Linq.XText(content).ToString(); var scriptWebPart = wpm.WebParts.FirstOrDefault(w => w.WebPart.Properties["Title"].ToString().ToLowerInvariant().Contains("script")); if (scriptWebPart != null) { WriteVerbose("Web part found. replacing script content."); scriptWebPart.WebPart.Properties["Content"] = content; scriptWebPart.SaveWebPartChanges(); cc.ExecuteQuery(); } else { WriteVerbose("Web part does not exist. creating new web part"); var newWp = wpm.ImportWebPart(String.Format(Resources.ScriptWebPartXml, escaped)); var webPartToAdd = wpm.AddWebPart(newWp.WebPart, "Left", 0); cc.Load(webPartToAdd); cc.ExecuteQuery(); } }
/// <summary> /// Sends a File Object to the Person /// </summary> /// <param name="peer">Person to send the file object</param> /// <param name="moment2distr">File object to send</param> /// <returns>The Sid of the transfer, null if error</returns> public string SendFile(Jid peer, string moment2distr) { if ((moment2distr == null) || !isConnected()) { return(null); } String fileName = System.IO.Path.GetFileName(moment2distr); String tempFilePath = Path.Combine(System.IO.Path.GetTempPath(), fileName); string sid; ///COPY MOMENT TO A TEMP DIR /// try { File.Copy(moment2distr, tempFilePath, true); } catch (DirectoryNotFoundException copyError) { uiDispatcher.multiDebug(copyError.Message); } catch (PathTooLongException copyError) { uiDispatcher.multiDebug(copyError.Message); } catch (UnauthorizedAccessException copyError) { uiDispatcher.multiDebug(copyError.Message); } catch (ArgumentException copyError) { uiDispatcher.multiDebug(copyError.Message); } catch (FileNotFoundException copyError) { uiDispatcher.multiDebug(copyError.Message); } catch (IOException copyError) { uiDispatcher.multiDebug(copyError.Message); } //The sid of the file transfer //Serialize with escaped characters the description of the moment string xdesc = new System.Xml.Linq.XText(moment2distr.ToString()).ToString(); try { sid = xmppClient.InitiateFileTransfer(peer, tempFilePath, xdesc); return(sid); } catch (Exception e) { uiDispatcher.multiDebug("Error in transfering moment" + e.StackTrace + e.ToString()); } return(null); }
/// <summary> /// Create a nice looking header /// </summary> /// <param name="values"></param> /// <param name="targetType"></param> /// <param name="parameter"></param> /// <param name="culture"></param> /// <returns></returns> public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { // Get values string filter = values[0] as string; string headerText = values[1] as string; string filtertype = ""; if (filter.StartsWith("<")) filtertype = "Less Than"; else if (filter.StartsWith(">")) filtertype = "Greater Than"; else if (filter.StartsWith("=")) filtertype = "Exactly"; else if (filter.StartsWith("!")) filtertype = "Not"; else if (filter.StartsWith("~")) filtertype = "Doesn't Contain"; else if (filter.StartsWith(@"""")) filtertype = "Blank"; else if (filter.Equals("*")) filtertype = "Any"; else filtertype = "Contains"; // Generate header text string text = "{0}{3}" + headerText + " {4}"; if (!String.IsNullOrEmpty(filter)) text += "({2}" + filtertype + "{4})"; text += "{1}"; // Escape special XML characters like <>&' text = new System.Xml.Linq.XText(text).ToString(); // Format the text text = String.Format(text, @"<TextBlock xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>", "</TextBlock>", "<Run FontWeight='bold' Text='", "<Run Text='", @"'/>"); // Convert to stream MemoryStream stream = new MemoryStream(ASCIIEncoding.UTF8.GetBytes(text)); // Convert to object TextBlock block = (TextBlock)System.Windows.Markup.XamlReader.Load(stream); return block; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string formatString = value.ToString(); // Escape special XML characters like <>&' formatString = new System.Xml.Linq.XText(formatString).ToString(); string formatted = String.Format(formatString, @"<TextBlock xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>", "</TextBlock>", "<Run FontWeight='bold' Text='", @"'/>", "<Run Text='", @"'/>"); TextBlock block = (TextBlock)System.Windows.Markup.XamlReader.Load(formatted); return(block); }
public XText(System.Xml.Linq.XText other) { }
/// <summary> /// Sends a File Object to the Person /// </summary> /// <param name="peer">Person to send the file object</param> /// <param name="moment2distr">File object to send</param> /// <returns>The Sid of the transfer, null if error</returns> public string SendFile(Jid peer, string moment2distr) { if ((moment2distr == null) || !isConnected()) return null; String fileName = System.IO.Path.GetFileName(moment2distr); String tempFilePath = Path.Combine(System.IO.Path.GetTempPath(), fileName); string sid; ///COPY MOMENT TO A TEMP DIR /// try { File.Copy(moment2distr, tempFilePath, true); } catch (DirectoryNotFoundException copyError) { uiDispatcher.multiDebug(copyError.Message); } catch (PathTooLongException copyError) { uiDispatcher.multiDebug(copyError.Message); } catch (UnauthorizedAccessException copyError) { uiDispatcher.multiDebug(copyError.Message); } catch (ArgumentException copyError) { uiDispatcher.multiDebug(copyError.Message); } catch (FileNotFoundException copyError) { uiDispatcher.multiDebug(copyError.Message); } catch (IOException copyError) { uiDispatcher.multiDebug(copyError.Message); } //The sid of the file transfer //Serialize with escaped characters the description of the moment string xdesc = new System.Xml.Linq.XText(moment2distr.ToString()).ToString(); try { sid = xmppClient.InitiateFileTransfer(peer, tempFilePath, xdesc); return sid; } catch (Exception e) { uiDispatcher.multiDebug("Error in transfering moment" + e.StackTrace + e.ToString()); } return null; }
public XRaw(System.Xml.Linq.XText text) : base(text) { }