public void TestAppend() { StringBuilder buf = new StringBuilder(); buf.Append('a'); StringUtil.Append(buf, "abc", 1, 1); StringUtil.Append(buf, (byte)12, 16); StringUtil.Append(buf, (byte)16, 16); StringUtil.Append(buf, unchecked ((byte)-1), 16); StringUtil.Append(buf, unchecked ((byte)-16), 16); Assert.AreEqual("ab0c10fff0", buf.ToString()); }
/// <summary> /// Get any <see cref="CommentFlags"/> and <see cref="AnnotationFlags"/> as a comma separated string. /// </summary> public string FlagsAsText() { string result = ""; if (_commentFlags != CommentFlags.None) { result += _commentFlags; } if (_annotationFlags != AnnotationFlags.None || string.IsNullOrEmpty(result)) { result = StringUtil.Append(result, ", ", _annotationFlags.ToString()); } return(result); }
public int PrepareMarcFilter( string strFilterFileName, out LoanFilterDocument filter, out string strError) { strError = ""; // 看看是否有现成可用的对象 filter = (LoanFilterDocument)this.Filters.GetFilter(strFilterFileName); if (filter != null) { return(1); } // 新创建 filter = new LoanFilterDocument(); filter.strOtherDef = "FilterHost Host = null;"; filter.strPreInitial = " LoanFilterDocument doc = (LoanFilterDocument)this.Document;\r\n"; filter.strPreInitial += " Host = (" + "FilterHost" + ")doc.FilterHost;\r\n"; try { filter.Load(strFilterFileName); } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); return(-1); } string strCode = ""; // c#代码 int nRet = filter.BuildScriptFile(out strCode, out strError); if (nRet == -1) { return(-1); } try { string[] saRef2 = filter.GetRefs(); filter.Assembly = this.AssemblyCache.GetObject(strFilterFileName, () => { string strError1 = ""; string[] saAddRef1 = { // 2011/9/3 增加 "system.dll", "system.drawing.dll", "system.web.dll", "system.xml.dll", "System.Runtime.Serialization.dll", this.BinDir + "\\digitalplatform.marcdom.dll", this.BinDir + "\\digitalplatform.marckernel.dll", this.BinDir + "\\digitalplatform.libraryserver.dll", this.BinDir + "\\digitalplatform.dll", this.BinDir + "\\digitalplatform.Text.dll", this.BinDir + "\\digitalplatform.IO.dll", this.BinDir + "\\digitalplatform.Xml.dll", this.BinDir + "\\digitalplatform.script.dll", this.BinDir + "\\digitalplatform.marcquery.dll", }; string strWarning = ""; // string strLibPaths = ""; string[] saRef = StringUtil.Append(saRef2, saAddRef1); #if NO string[] saRef = new string[saRef2.Length + saAddRef1.Length]; Array.Copy(saRef2, saRef, saRef2.Length); Array.Copy(saAddRef1, 0, saRef, saRef2.Length, saAddRef1.Length); #endif Assembly assembly1 = null; // 创建Script的Assembly // 本函数内对saRef不再进行宏替换 nRet = ScriptManager.CreateAssembly_1(strCode, saRef, "", // strLibPaths, out assembly1, out strError1, out strWarning); if (nRet == -2) { throw new Exception(strError1); } if (nRet == -1) { if (strWarning == "") { throw new Exception(strError1); } } return(assembly1); }); } catch (Exception ex) { strError = ex.Message; return(-1); } return(0); }
// 根据源代码文件获得Xml到Html转换的Assembly对象 public int GetXml2HtmlAssembly( string strCodeFileName, string strRefFileName, string strBinDir, out Assembly assembly, out string strError) { strError = ""; try { assembly = this.AssemblyCache.GetObject(strCodeFileName, () => { int nRet = 0; string strError1 = ""; string strCode = ""; // c#代码 try { using (StreamReader sr = new StreamReader(strCodeFileName, true)) { strCode = sr.ReadToEnd(); } } catch (Exception ex) { strError1 = ExceptionUtil.GetAutoText(ex); throw new Exception(strError1); } string[] saAddRef1 = { // 2011/9/3 增加 "system.dll", "system.drawing.dll", "system.web.dll", "system.xml.dll", "System.Runtime.Serialization.dll", strBinDir + "\\digitalplatform.marcdom.dll", strBinDir + "\\digitalplatform.marckernel.dll", strBinDir + "\\digitalplatform.rms.client.dll", strBinDir + "\\digitalplatform.libraryserver.dll", strBinDir + "\\digitalplatform.dll", strBinDir + "\\digitalplatform.Text.dll", strBinDir + "\\digitalplatform.IO.dll", strBinDir + "\\digitalplatform.Xml.dll", // strBinDir + "\\dp2rms.exe", }; string strWarning = ""; // string strLibPaths = ""; string[] saRef2 = null; if (String.IsNullOrEmpty(strRefFileName) == false) { // 从references.xml文件中得到refs字符串数组 // return: // -1 error // 0 not found file // 1 found file nRet = ScriptManager.GetRefs(strRefFileName, out saRef2, out strError1); if (nRet == -1) { strError1 = "ref文件 '" + strRefFileName + "' 出错: " + strError1; throw new Exception(strError1); } } string[] saRef = StringUtil.Append(saRef2, saAddRef1); Assembly assembly1 = null; // 创建Script的Assembly // 本函数内对saRef不再进行宏替换 nRet = ScriptManager.CreateAssembly_1(strCode, saRef, "", // strLibPaths, out assembly1, out strError1, out strWarning); if (nRet == -2) { throw new Exception(strError1); } if (nRet == -1) { strError1 = "文件 '" + strCodeFileName + "' 编译出错: " + strError1; if (string.IsNullOrEmpty(strWarning) == true) { throw new Exception(strError1); } } return(assembly1); }); } catch (Exception ex) { strError = ex.Message; assembly = null; return(-1); } if (assembly != null) { return(1); } return(0); }
// 根据源代码文件获得Xml到Html转换的Assembly对象 public int GetXml2HtmlAssembly( string strCodeFileName, string strRefFileName, string strBinDir, out Assembly assembly, out string strError) { strError = ""; try { assembly = this.AssemblyCache.GetObject(strCodeFileName.ToLower(), () => { int nRet = 0; string strError1 = ""; string strCode = ""; // c#代码 // 装入code? try { using (StreamReader sr = new StreamReader(strCodeFileName, true)) { strCode = sr.ReadToEnd(); } } catch (Exception ex) { strError1 = ExceptionUtil.GetAutoText(ex); throw new Exception(strError1); } string[] saAddRef1 = { strBinDir + "\\digitalplatform.core.dll", strBinDir + "\\digitalplatform.marcdom.dll", strBinDir + "\\digitalplatform.marckernel.dll", // strBinDir + "\\digitalplatform.rms.client.dll", strBinDir + "\\digitalplatform.OPAC.Server.dll", strBinDir + "\\digitalplatform.dll", strBinDir + "\\digitalplatform.Text.dll", strBinDir + "\\digitalplatform.IO.dll", strBinDir + "\\digitalplatform.Xml.dll", // strBinDir + "\\dp2rms.exe", }; string strWarning = ""; // string strLibPaths = ""; string[] saRef2 = null; if (String.IsNullOrEmpty(strRefFileName) == false) { // 从references.xml文件中得到refs字符串数组 // return: // -1 error // 0 not found file // 1 found file nRet = ScriptManager.GetRefs(strRefFileName, out saRef2, out strError1); if (nRet == -1) { strError1 = "ref文件 '" + strRefFileName + "' 出错: " + strError1; throw new Exception(strError1); } } string[] saRef = StringUtil.Append(saRef2, saAddRef1); #if NO if (saRef2 != null) { saRef = new string[saRef2.Length + saAddRef1.Length]; Array.Copy(saRef2, saRef, saRef2.Length); Array.Copy(saAddRef1, 0, saRef, saRef2.Length, saAddRef1.Length); } else { saRef = saAddRef1; } #endif Assembly assembly1 = null; // 创建Script的Assembly // 本函数内对saRef不再进行宏替换 nRet = ScriptManager.CreateAssembly_1(strCode, saRef, "", // strLibPaths, out assembly1, out strError1, out strWarning); if (nRet == -2) { throw new Exception(strError1); } if (nRet == -1) { strError1 = "文件 '" + strCodeFileName + "' 编译出错: " + strError1; if (string.IsNullOrEmpty(strWarning) == true) { throw new Exception(strError1); } } return(assembly1); }); } catch (Exception ex) { strError = ex.Message; assembly = null; return(-1); } // 优化 if (assembly != null) { return(1); } return(0); }