public static DataTable LoadXsdText(string xsd) { DataTable table = null; try { table = new DataTable(); if (!String.IsNullOrEmpty(xsd)) { MemoryStream s = new MemoryStream(UStr.ToBytes(xsd)); s.Position = 0; DataSet ds = new DataSet(); ds.ReadXmlSchema(s); table = ds.Tables[0]; s.Close(); } } catch (Exception ex) { throw ex; } return(table); }
public static string ToString(XmlNodeList nodes) { StringBuilder sb = new StringBuilder(); try { foreach (XmlNode node in nodes) { sb.AppendLine(node.OuterXml); } string s = "<Root>" + sb.ToString() + "</Root>"; s = Indent(s); s = UStr.TrimStart(s, "<Root>"); s = UStr.TrimEnd(s, "</Root>"); return(s); } catch { return(""); } }
public static string FilterAnd(params object[] pv) { string filter = ""; if (pv == null || pv.Length == 0) { return(""); } if (pv.Length % 2 != 0) { throw new Exception("Length of parameter-value collection should be an even number. Incorrect parameter-value collection [" + UStr.GetString(pv) + "]"); } for (int i = 0; i < pv.Length; i += 2) { if (pv.GetValue(i) != null) { string val = ""; if (pv.GetValue(i + 1) != null) { val = pv.GetValue(i + 1).ToString(); } filter = BaseItem.FilterAnd(filter, UStr.FilterExact(pv.GetValue(i).ToString(), val)); } } filter = BaseItem.TrimAnd(filter); return(filter); }
public static DataSet LoadXsdText2(string xsd) { DataSet dataset = null; try { if (!String.IsNullOrEmpty(xsd)) { MemoryStream s = new MemoryStream(UStr.ToBytes(xsd)); s.Position = 0; dataset = new DataSet(); dataset.ReadXmlSchema(s); s.Close(); } } catch (Exception ex) { throw ex; } return(dataset); }
protected virtual void OnExtract(string text) { if (TextExtracted != null && !UStr.IsSpaces(text)) { TextExtracted(this, text.Trim()); } }
public static void TrimNewLine(string filePath) { if (!File.Exists(filePath)) { return; } File.WriteAllText(filePath, UStr.TrimNewLine(File.ReadAllText(filePath))); }
public static bool Contains(DataTable table, string columnName, string value) { table.DefaultView.RowFilter = UStr.FilterExact(columnName, value); bool contains = table.DefaultView.Count != 0; table.DefaultView.RowFilter = ""; return(contains); }
public static string More(string s, int maxChar, string readMoreUrl) { int len = s.Length; if (len <= maxChar) { return(s); } return(s.Substring(0, maxChar) + " <a href=" + UStr.DQuote(readMoreUrl) + ">Read More...</a>"); }
public static DialogResult Show(Form owner, string text, MessageBoxButtons buttons, MessageBoxIcon icon) { if (UStr.LineCount(text) <= 15) { return(MessageBox.Show(owner, text, Config.ProductName, buttons, icon)); } else { return(MessageForm.Open(owner, text)); } }
public static string Delimited(string delimiter, params object[] vals) { string s = ""; foreach (object val in vals) { s += val.ToString() + delimiter; } return(UStr.TrimEnd(s, delimiter)); }
public static string ToString(SqlCommand cmd) { StringBuilder s = new StringBuilder(); s.AppendLine(cmd.CommandText); foreach (SqlParameter p in cmd.Parameters) { s.AppendLine(UStr.Bracket(p.ParameterName) + " = " + UStr.Bracket(p.Value)); } return(s.ToString()); }
public virtual bool Parse(string pageUrls) { bool result = true; string[] urls = UStr.Split(pageUrls, Environment.NewLine); foreach (string urlx in urls) { result = ParseUrl(urlx); } return(result); }
public Move GetBySNo(int sNo) { try { DataRow[] rows = base.DataTable.Select("sno=" + UStr.Quote(sNo)); if (rows.Length > 0) { Move m = new Move(rows[0]); m.Game = this.Game; return(m); } } catch { } return(null); }
private void InitWaterMarkText() { if (!ShowWaterMarkText) { return; } Page.ClientScript.RegisterClientScriptInclude(this.GetType().ToString(), UWeb.ResUrl(this, "Script.js")); Text = WaterMarkText; CssClass = CssClassWaterMarkTextBlur; Attributes.Add("onfocus", "RsTextBox_onfocus(this, " + UStr.Quote(CssClassWaterMarkTextFocus) + ", " + UStr.Quote(WaterMarkText) + ");"); Attributes.Add("onblur", "RsTextBox_onblur(this, " + UStr.Quote(CssClassWaterMarkTextBlur) + ", " + UStr.Quote(WaterMarkText) + ");"); Attributes.Add("onkeypress", "return RsTextBox_onkeypress(event, " + UStr.Quote(ClickOnEnterButtonClientID) + ")"); }
private Move Get(int id, string op, string sort) { try { DataRow[] rows = base.DataTable.Select(Id + op + UStr.Quote(id), Id + " " + sort); if (rows.Length > 0) { Move m = new Move(rows[0]); m.Game = this.Game; return(m); } } catch { } return(null); }
public static string ToString(DataRow row) { if (row == null) { return(""); } StringBuilder s = new StringBuilder(); s.AppendLine("Table Name = " + UStr.Bracket(row.Table.TableName)); foreach (DataColumn col in row.Table.Columns) { s.AppendLine(UStr.Bracket(col.ColumnName) + " = " + UStr.Bracket(row[col.ColumnName])); } return(s.ToString()); }
public static void CopyFolder(string source, string destination) { string param = @"/E /H /R /Y"; string XCopyArguments = UStr.DQuote(source) + " " + UStr.DQuote(destination) + " " + param; Process XCopyProcess = new Process(); ProcessStartInfo XCopyStartInfo = new ProcessStartInfo(); XCopyStartInfo.FileName = "CMD.exe "; //do not write error output to standard stream XCopyStartInfo.RedirectStandardError = false; //do not write output to Process.StandardOutput Stream XCopyStartInfo.RedirectStandardOutput = false; //do not read input from Process.StandardInput (i/e; the keyboard) XCopyStartInfo.RedirectStandardInput = false; XCopyStartInfo.UseShellExecute = false; //Dont show a command window XCopyStartInfo.CreateNoWindow = true; XCopyStartInfo.Arguments = "/D /c XCOPY " + XCopyArguments; XCopyProcess.EnableRaisingEvents = true; XCopyProcess.StartInfo = XCopyStartInfo; //start cmd.exe & the XCOPY process XCopyProcess.Start(); //set the wait period for exiting the process XCopyProcess.WaitForExit(5 * 60000); //or the wait time you want int ExitCode = XCopyProcess.ExitCode; //Now we need to see if the process was successful if (ExitCode > 0 & !XCopyProcess.HasExited) { XCopyProcess.Kill(); } //now clean up after ourselves XCopyProcess.Dispose(); }
public static DataRow GetSettingRow(DataTable table, string key) { DataRow row = null; DataRow[] rows = table.Select(Kv.KeyName + "=" + UStr.Quote(key)); if (rows.Length > 0) { row = rows[0]; } else { row = table.NewRow(); row[Kv.KeyName] = key; table.Rows.Add(row); table.AcceptChanges(); } return(row); }
public static DataSet LoadDataSet(DataSet dataset, string xml) { try { if (IsValidXml(xml)) { MemoryStream s = new MemoryStream(UStr.ToBytes(xml)); s.Position = 0; dataset.ReadXml(s); s.Close(); } } catch (Exception ex) { throw ex; } return(dataset); }
public static string Join(string sep1, string sep2, params object[] s) { string ret = ""; bool s1 = false; if (s == null) { return(""); } foreach (object v in s) { s1 = !s1; if (v != null) { ret += v.ToString() + (s1 ? sep1 : sep2); } } return(UStr.TrimEnd(ret, s1 ? sep1 : sep2)); }
public static DataTable LoadDataTable(DataTable table, string xml) { try { if (IsValidXml(xml)) { MemoryStream s = new MemoryStream(UStr.ToBytes(xml)); s.Position = 0; table.ReadXml(s); s.Close(); } } catch (Exception ex) { throw ex; } return(table); }
private StringBuilder FilterData(UserSession us) { string[] strs = UStr.Split(us.AsyncData.ToString(), "\0", StringSplitOptions.RemoveEmptyEntries); string str = ""; int i = 0; us.AsyncData = new StringBuilder(); bool isValid = true; if (strs.Length > 0) { str = strs[strs.Length - 1]; if (!UData.IsValidXml(str)) { us.AsyncData.Append(str); isValid = false; } if (isValid) { for (i = 0; i < strs.Length; i++) { str = strs[i]; ProcessData(str, us); } } else { for (i = 0; i < strs.Length - 1; i++) { str = strs[i]; ProcessData(str, us); } } } return(us.AsyncData); }
public void LoadXml(string xsdPath, string xml) { try { LoadXsd(xsdPath); if (!String.IsNullOrEmpty(xml)) { MemoryStream s = new MemoryStream(UStr.ToBytes(xml)); s.Position = 0; DataTable.ReadXml(s); s.Close(); } } catch (Exception ex) { throw ex; } }
public virtual bool ParseUrl(string pageUrl) { try { if (UStr.IsSpaces(pageUrl)) { return(true); } if (DoParse(pageUrl)) { Extract(); } return(true); } catch (Exception ex) { error = ex; return(false); } }
public static string FilterInt32(string columnName, object value) { return(UStr.Bracket(columnName) + "=" + value); }
public static string Substring(string s, int maxChar, bool removeNewLine) { return(UStr.Substring(removeNewLine ? s.Replace(Environment.NewLine, "") : s, maxChar)); }
public static int LineCount(string text) { string [] lines = UStr.Split(text, Environment.NewLine); return(lines.Length); }
public static string TrimOr(string filter) { filter = UStr.TrimEnd(filter, " OR "); return(filter); }
public static string TrimAnd(string filter) { filter = UStr.TrimEnd(filter, " AND "); return(filter); }
private static string ToAnd(params object[] whereColVals) { return(UStr.Join(" = ", " AND ", whereColVals)); }