//removePath将要删除的路径 static public string GetFileListXMLString(List <string> fileList, string removePath) { var root = new System.Security.SecurityElement("root"); foreach (var item in fileList) { string fileName = Path.GetFileName(item); string ext = Path.GetExtension(item); if (string.Compare(ext, ".meta", true) == 0) { continue; } string filePath = null; if (IsUseAssetBundle) { filePath = item.Replace(removePath, ""); root.AddChild(new System.Security.SecurityElement("k", fileName.ToLower())); root.AddChild(new System.Security.SecurityElement("v", filePath.ToLower())); } else { filePath = item.Replace(removePath, ""); root.AddChild(new System.Security.SecurityElement("k", fileName)); root.AddChild(new System.Security.SecurityElement("v", filePath)); } } return(root.ToString()); }
//在生成资源包时使用 static public string SerializeInEditor(List <ResInfo> listResInfo) { string innerText = MyFileUtil.ReadConfigDataInStreamingAssets(VersionManager.VersionInfoFilePath); VersionInfo innerVersionInfo = VersionInfo.ParseData(innerText); var root = new System.Security.SecurityElement("root"); root.AddChild(new System.Security.SecurityElement("ProgramVersion", innerVersionInfo.ProgramVersion.ToString())); root.AddChild(new System.Security.SecurityElement("ApkUrl", innerVersionInfo.ApkUrl)); root.AddChild(new System.Security.SecurityElement("ApkMd5")); root.AddChild(new System.Security.SecurityElement("IOSAppUrl", innerVersionInfo.IOSAppUrl)); root.AddChild(new System.Security.SecurityElement("IOSAppStoreUrl", innerVersionInfo.IOSAppStoreUrl)); root.AddChild(new System.Security.SecurityElement("IsAppleAppStore", innerVersionInfo.IsAppleAppStore.ToString())); root.AddChild(new System.Security.SecurityElement("IsOpenAutoUpdateInAppStore", innerVersionInfo.IsOpenAutoUpdateInAppStore.ToString())); root.AddChild(new System.Security.SecurityElement("IsForceToUpdate", innerVersionInfo.IsForceToUpdate.ToString())); var resInfoNode = new System.Security.SecurityElement("ResInfo"); root.AddChild(resInfoNode); foreach (var item in listResInfo) { var recordNode = new System.Security.SecurityElement("Record"); resInfoNode.AddChild(recordNode); recordNode.AddChild(new System.Security.SecurityElement("ResName", item.resName)); recordNode.AddChild(new System.Security.SecurityElement("ResMD5", item.resMD5)); recordNode.AddChild(new System.Security.SecurityElement("ResURL", item.resURL)); recordNode.AddChild(new System.Security.SecurityElement("ResSize", item.resSize.ToString())); recordNode.AddChild(new System.Security.SecurityElement("ResRequire", "true")); recordNode.AddChild(new System.Security.SecurityElement("resRequireID", item.resRequireID.ToString())); } return(root.ToString()); }
internal static void EncodeLevel (PolicyLevel level) { Contract.Assert(level != null, "No policy level to encode."); // We cannot encode a policy level without a backing file if (level.Path == null) { string errorMessage = Environment.GetResourceString("Policy_UnableToSave", level.Label, Environment.GetResourceString("Policy_SaveNotFileBased")); throw new PolicyException(errorMessage); } SecurityElement elConf = new SecurityElement("configuration"); SecurityElement elMscorlib = new SecurityElement("mscorlib"); SecurityElement elSecurity = new SecurityElement("security"); SecurityElement elPolicy = new SecurityElement("policy"); elConf.AddChild(elMscorlib); elMscorlib.AddChild(elSecurity); elSecurity.AddChild(elPolicy); elPolicy.AddChild(level.ToXml()); try { StringBuilder sb = new StringBuilder(); Encoding encoding = Encoding.UTF8; SecurityElement format = new SecurityElement("xml"); format.m_type = SecurityElementType.Format; format.AddAttribute("version", "1.0"); format.AddAttribute("encoding", encoding.WebName); sb.Append(format.ToString()); sb.Append(elConf.ToString()); byte[] data = encoding.GetBytes(sb.ToString()); // Write out the new config. int hrSave = Config.SaveDataByte(level.Path, data, data.Length); Exception extendedError = Marshal.GetExceptionForHR(hrSave); if (extendedError != null) { string extendedInformation = extendedError != null ? extendedError.Message : String.Empty; throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", level.Label, extendedInformation), extendedError); } } catch (Exception e) { if (e is PolicyException) throw e; else throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", level.Label, e.Message), e); } Config.ResetCacheData(level.ConfigId); if (CanUseQuickCache(level.RootCodeGroup)) Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level)); }
private void SaveVersion(VersionManagerInfo version) { var props = typeof(VersionManagerInfo).GetProperties(); var root = new System.Security.SecurityElement("root"); foreach (var item in props) { root.AddChild(new System.Security.SecurityElement(item.Name, item.GetGetMethod().Invoke(version, null) as String)); } XMLParser.SaveText(SystemConfig.VersionPath, root.ToString()); }
private void BuildPathFile() { var root = new System.Security.SecurityElement("root"); foreach (var item in m_instance.m_filesDic) { root.AddChild(new System.Security.SecurityElement("k", item.Key)); root.AddChild(new System.Security.SecurityElement("v", item.Value)); } XMLParser.SaveText(m_instance.m_resourcePath + "resourceInfo.xml", root.ToString()); }
internal static void EncodeLevel(PolicyLevel level) { SecurityElement elConf = new SecurityElement("configuration"); SecurityElement elMscorlib = new SecurityElement("mscorlib"); SecurityElement elSecurity = new SecurityElement("security"); SecurityElement elPolicy = new SecurityElement("policy"); elConf.AddChild(elMscorlib); elMscorlib.AddChild(elSecurity); elSecurity.AddChild(elPolicy); elPolicy.AddChild(level.ToXml()); try { StringBuilder sb = new StringBuilder(); Encoding encoding = Encoding.UTF8; SecurityElement format = new SecurityElement("xml"); format.m_type = SecurityElementType.Format; format.AddAttribute("version", "1.0"); format.AddAttribute("encoding", encoding.WebName); sb.Append(format.ToString()); sb.Append(elConf.ToString()); byte[] data = encoding.GetBytes(sb.ToString()); // Write out the new config. if (level.Path == null || !Config.SaveDataByte(level.Path, data, 0, data.Length)) { throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label)); } } catch (Exception e) { if (e is PolicyException) { throw e; } else { throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label), e); } } catch { throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label)); } Config.ResetCacheData(level.ConfigId); if (CanUseQuickCache(level.RootCodeGroup)) { Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level)); } }
internal static void EncodeLevel(PolicyLevel level) { if (level.Path == null) { throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", (object)level.Label, (object)Environment.GetResourceString("Policy_SaveNotFileBased"))); } SecurityElement securityElement1 = new SecurityElement("configuration"); SecurityElement child1 = new SecurityElement("mscorlib"); SecurityElement child2 = new SecurityElement("security"); SecurityElement child3 = new SecurityElement("policy"); securityElement1.AddChild(child1); child1.AddChild(child2); child2.AddChild(child3); child3.AddChild(level.ToXml()); try { StringBuilder stringBuilder = new StringBuilder(); Encoding utF8 = Encoding.UTF8; SecurityElement securityElement2 = new SecurityElement("xml"); securityElement2.m_type = SecurityElementType.Format; securityElement2.AddAttribute("version", "1.0"); securityElement2.AddAttribute("encoding", utF8.WebName); stringBuilder.Append(securityElement2.ToString()); stringBuilder.Append(securityElement1.ToString()); byte[] bytes = utF8.GetBytes(stringBuilder.ToString()); string path = level.Path; byte[] data = bytes; int length = data.Length; Exception exceptionForHr = Marshal.GetExceptionForHR(Config.SaveDataByte(path, data, length)); if (exceptionForHr != null) { string str = exceptionForHr != null ? exceptionForHr.Message : string.Empty; throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", (object)level.Label, (object)str), exceptionForHr); } } catch (Exception ex) { if (ex is PolicyException) { throw ex; } throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", (object)level.Label, (object)ex.Message), ex); } Config.ResetCacheData(level.ConfigId); if (!PolicyManager.CanUseQuickCache(level.RootCodeGroup)) { return; } Config.SetQuickCache(level.ConfigId, PolicyManager.GenerateQuickCache(level)); }
internal static void EncodeLevel(PolicyLevel level) { if (level.Path == null) { throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, Environment.GetResourceString("Policy_SaveNotFileBased") })); } SecurityElement element = new SecurityElement("configuration"); SecurityElement child = new SecurityElement("mscorlib"); SecurityElement element3 = new SecurityElement("security"); SecurityElement element4 = new SecurityElement("policy"); element.AddChild(child); child.AddChild(element3); element3.AddChild(element4); element4.AddChild(level.ToXml()); try { StringBuilder builder = new StringBuilder(); Encoding encoding = Encoding.UTF8; SecurityElement element5 = new SecurityElement("xml") { m_type = SecurityElementType.Format }; element5.AddAttribute("version", "1.0"); element5.AddAttribute("encoding", encoding.WebName); builder.Append(element5.ToString()); builder.Append(element.ToString()); byte[] bytes = encoding.GetBytes(builder.ToString()); Exception exceptionForHR = Marshal.GetExceptionForHR(Config.SaveDataByte(level.Path, bytes, bytes.Length)); if (exceptionForHR != null) { string str2 = (exceptionForHR != null) ? exceptionForHR.Message : string.Empty; throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, str2 }), exceptionForHR); } } catch (Exception exception2) { if (exception2 is PolicyException) { throw exception2; } throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, exception2.Message }), exception2); } Config.ResetCacheData(level.ConfigId); if (CanUseQuickCache(level.RootCodeGroup)) { Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level)); } }
//序列化为字符串 static public string Serialize(VersionInfo versionInfo) { var root = new System.Security.SecurityElement("root"); root.AddChild(new System.Security.SecurityElement("ProgramVersion", versionInfo.ProgramVersion.ToString())); var resInfoNode = new System.Security.SecurityElement("ResInfo"); root.AddChild(resInfoNode); foreach (var item in versionInfo.dictRes) { var recordNode = new System.Security.SecurityElement("Record"); resInfoNode.AddChild(recordNode); recordNode.AddChild(new System.Security.SecurityElement("ResName", item.Value.resName)); recordNode.AddChild(new System.Security.SecurityElement("ResMD5", item.Value.resMD5)); } return(root.ToString()); }
public static string GetXMLListContent <T>(string path, List <T> data, string attrName = "record") { try { var root = new System.Security.SecurityElement("root"); var props = typeof(T).GetProperties(); foreach (var item in data) { if (item == null) { LoggerHelper.Error("null item: " + path); continue; } var xml = new System.Security.SecurityElement(attrName); foreach (var prop in props) { var type = prop.PropertyType; String result = String.Empty; object obj = prop.GetGetMethod().Invoke(item, null); if (obj == null) { LoggerHelper.Error("null obj: " + prop.Name); continue; } //var obj = prop.GetValue(item, null); if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <,>)) { var o = typeof(Utils).GetMethod("PackMap") .MakeGenericMethod(type.GetGenericArguments()) .Invoke(null, new object[] { obj, ':', ',' }); if (o != null) { result = o.ToString(); } else { LoggerHelper.Error("null obj: " + prop.Name); } } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>)) { var o = typeof(Utils).GetMethod("PackList") .MakeGenericMethod(type.GetGenericArguments()) .Invoke(null, new object[] { obj, ',' }); if (o != null) { result = o.ToString(); } else { LoggerHelper.Error("null obj: " + prop.Name); } } else { result = obj.ToString(); } xml.AddChild(new System.Security.SecurityElement(prop.Name, result)); } root.AddChild(xml); } return(root.ToString()); } catch (Exception ex) { LoggerHelper.Except(ex); return(""); } }
[Test] // bug #333699 (ugh, mostly a dup) public void TestToString () { SecurityElement values = new SecurityElement ("values"); SecurityElement infoValue = new SecurityElement ("value"); infoValue.AddAttribute ("name", "string"); infoValue.Text = SecurityElement.Escape ("<'Suds' & \"Soda\">!"); values.AddChild (infoValue); Assert.AreEqual ("<value name=\"string\"><'Suds' & "Soda">!</value>" + Environment.NewLine, infoValue.ToString (), "#1"); Assert.AreEqual ("<'Suds' & \"Soda\">!", infoValue.Text, "#2"); Assert.IsNull (values.Text, "#3"); #if NET_2_0 Assert.AreEqual (String.Format ("<values>{0}<value name=\"string\"><'Suds' & "Soda">!</value>{0}</values>{0}", Environment.NewLine), values.ToString (), "#4"); #else Assert.AreEqual (String.Format ("<values>{0} <value name=\"string\"><'Suds' & "Soda">!</value>{0}</values>{0}", Environment.NewLine), values.ToString (), "#4"); #endif #if NET_2_0 SecurityElement sec = SecurityElement.FromString (values.ToString ()); Assert.AreEqual (1, sec.Children.Count, "#5"); Assert.AreEqual ("<'Suds' & \"Soda\">!", ((SecurityElement) sec.Children [0]).Text, "#6"); #endif }
public void MultipleAttributes () { SecurityElement se = new SecurityElement ("Multiple"); se.AddAttribute ("Attribute1", "One"); se.AddAttribute ("Attribute2", "Two"); #if NET_2_0 string expected = String.Format ("<Multiple Attribute1=\"One\"{0}Attribute2=\"Two\"/>{0}", Environment.NewLine); #else string expected = String.Format ("<Multiple Attribute1=\"One\"{0} Attribute2=\"Two\"/>{0}", Environment.NewLine); #endif Assert.AreEqual (expected, se.ToString (), "ToString()"); }
public void Tag () { SecurityElement se = new SecurityElement ("Values"); Assert.AreEqual ("Values", se.Tag, "#A1"); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "<Values/>{0}", Environment.NewLine), se.ToString (), "#A2"); se.Tag = "abc:Name"; Assert.AreEqual ("abc:Name", se.Tag, "#B1"); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "<abc:Name/>{0}", Environment.NewLine), se.ToString (), "#B2"); se.Tag = "Name&Address"; Assert.AreEqual ("Name&Address", se.Tag, "#C1"); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "<Name&Address/>{0}", Environment.NewLine), se.ToString (), "#C2"); se.Tag = string.Empty; Assert.AreEqual (string.Empty, se.Tag, "#D1"); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "</>{0}", Environment.NewLine), se.ToString (), "#D2"); }
static bool ProcessAssemblyXml (TextWriter tw, AssemblyDefinition ad) { SecurityElement se = new SecurityElement ("Assembly"); se.AddAttribute ("Name", ad.Name.FullName); if (ad.SecurityDeclarations.Count > 0) { se.AddChild (AddSecurityXml (ad.SecurityDeclarations)); } ArrayList tlist = new ArrayList (); ArrayList mlist = new ArrayList (); foreach (ModuleDefinition module in ad.Modules) { foreach (TypeDefinition type in module.Types) { SecurityElement klass = new SecurityElement ("Class"); SecurityElement methods = new SecurityElement ("Methods"); SecurityElement typelem = null; if (type.SecurityDeclarations.Count > 0) { typelem = AddSecurityXml (type.SecurityDeclarations); } if (mlist.Count > 0) mlist.Clear (); foreach (MethodDefinition method in type.Methods) { if (method.SecurityDeclarations.Count > 0) { SecurityElement meth = new SecurityElement ("Method"); AddAttribute (meth, "Name", method.ToString ()); meth.AddChild (AddSecurityXml (method.SecurityDeclarations)); mlist.Add (meth); } } // sort methods mlist.Sort (Comparer); foreach (SecurityElement method in mlist) { methods.AddChild (method); } if ((typelem != null) || ((methods.Children != null) && (methods.Children.Count > 0))) { AddAttribute (klass, "Name", type.ToString ()); if (typelem != null) klass.AddChild (typelem); if ((methods.Children != null) && (methods.Children.Count > 0)) klass.AddChild (methods); tlist.Add (klass); } } // sort types tlist.Sort (Comparer); foreach (SecurityElement type in tlist) { se.AddChild (type); } } tw.WriteLine (se.ToString ()); return true; }
internal static void EncodeLevel( PolicyLevel level ) { SecurityElement elConf = new SecurityElement( "configuration" ); SecurityElement elMscorlib = new SecurityElement( "mscorlib" ); SecurityElement elSecurity = new SecurityElement( "security" ); SecurityElement elPolicy = new SecurityElement( "policy" ); elConf.AddChild( elMscorlib ); elMscorlib.AddChild( elSecurity ); elSecurity.AddChild( elPolicy ); elPolicy.AddChild( level.ToXml() ); try { MemoryStream stream = new MemoryStream( 24576 ); StreamWriter writer = new StreamWriter( stream, new UTF8Encoding(false) ); Encoding encoding = level.Encoding; if (encoding == null) encoding = writer.Encoding; SecurityElement format = new SecurityElement( "xml" ); format.m_type = SecurityElementType.Format; format.AddAttribute( "version", "1.0" ); format.AddAttribute( "encoding", encoding.WebName ); writer.Write( format.ToString() ); writer.Flush(); writer = new StreamWriter( stream, encoding ); writer.Write( elConf.ToString() ); writer.Flush(); // Write out the new config. if (!Config.SaveData( level.ConfigId, stream.GetBuffer(), 0, (int)stream.Length )) { throw new PolicyException( String.Format( Environment.GetResourceString( "Policy_UnableToSave" ), level.Label ) ); } } catch (Exception e) { if (e is PolicyException) throw e; else throw new PolicyException( String.Format( Environment.GetResourceString( "Policy_UnableToSave" ), level.Label ), e ); } Config.ResetCacheData( level.ConfigId ); try { if (CanUseQuickCache( level.RootCodeGroup )) { Config.SetQuickCache( level.ConfigId, GenerateQuickCache( level ) ); } } catch (Exception) { } }
public override string ToString() { SecurityElement elem = ToXml(); return(elem.ToString()); }
internal static void EncodeLevel (PolicyLevel level) { SecurityElement elConf = new SecurityElement("configuration"); SecurityElement elMscorlib = new SecurityElement("mscorlib"); SecurityElement elSecurity = new SecurityElement("security"); SecurityElement elPolicy = new SecurityElement("policy"); elConf.AddChild(elMscorlib); elMscorlib.AddChild(elSecurity); elSecurity.AddChild(elPolicy); elPolicy.AddChild(level.ToXml()); try { StringBuilder sb = new StringBuilder(); Encoding encoding = Encoding.UTF8; SecurityElement format = new SecurityElement("xml"); format.m_type = SecurityElementType.Format; format.AddAttribute("version", "1.0"); format.AddAttribute("encoding", encoding.WebName); sb.Append(format.ToString()); sb.Append(elConf.ToString()); byte[] data = encoding.GetBytes(sb.ToString()); // Write out the new config. if (level.Path == null || !Config.SaveDataByte(level.Path, data, 0, data.Length)) throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label)); } catch (Exception e) { if (e is PolicyException) throw e; else throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label), e); } catch { throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label)); } Config.ResetCacheData(level.ConfigId); if (CanUseQuickCache(level.RootCodeGroup)) Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level)); }
internal static void EncodeLevel(PolicyLevel level) { if (level.Path == null) { string resourceString = Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, Environment.GetResourceString("Policy_SaveNotFileBased") }); throw new PolicyException(resourceString); } SecurityElement securityElement = new SecurityElement("configuration"); SecurityElement securityElement2 = new SecurityElement("mscorlib"); SecurityElement securityElement3 = new SecurityElement("security"); SecurityElement securityElement4 = new SecurityElement("policy"); securityElement.AddChild(securityElement2); securityElement2.AddChild(securityElement3); securityElement3.AddChild(securityElement4); securityElement4.AddChild(level.ToXml()); try { StringBuilder stringBuilder = new StringBuilder(); Encoding utf = Encoding.UTF8; SecurityElement securityElement5 = new SecurityElement("xml"); securityElement5.m_type = SecurityElementType.Format; securityElement5.AddAttribute("version", "1.0"); securityElement5.AddAttribute("encoding", utf.WebName); stringBuilder.Append(securityElement5.ToString()); stringBuilder.Append(securityElement.ToString()); byte[] bytes = utf.GetBytes(stringBuilder.ToString()); int errorCode = Config.SaveDataByte(level.Path, bytes, bytes.Length); Exception exceptionForHR = Marshal.GetExceptionForHR(errorCode); if (exceptionForHR != null) { string text = (exceptionForHR != null) ? exceptionForHR.Message : string.Empty; throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, text }), exceptionForHR); } } catch (Exception ex) { if (ex is PolicyException) { throw ex; } throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, ex.Message }), ex); } Config.ResetCacheData(level.ConfigId); if (PolicyManager.CanUseQuickCache(level.RootCodeGroup)) { Config.SetQuickCache(level.ConfigId, PolicyManager.GenerateQuickCache(level)); } }
internal static void EncodeLevel(PolicyLevel level) { SecurityElement elConf = new SecurityElement("configuration"); SecurityElement elMscorlib = new SecurityElement("mscorlib"); SecurityElement elSecurity = new SecurityElement("security"); SecurityElement elPolicy = new SecurityElement("policy"); elConf.AddChild(elMscorlib); elMscorlib.AddChild(elSecurity); elSecurity.AddChild(elPolicy); elPolicy.AddChild(level.ToXml()); try { MemoryStream stream = new MemoryStream(24576); StreamWriter writer = new StreamWriter(stream, new UTF8Encoding(false)); Encoding encoding = level.Encoding; if (encoding == null) { encoding = writer.Encoding; } SecurityElement format = new SecurityElement("xml"); format.m_type = SecurityElementType.Format; format.AddAttribute("version", "1.0"); format.AddAttribute("encoding", encoding.WebName); writer.Write(format.ToString()); writer.Flush(); writer = new StreamWriter(stream, encoding); writer.Write(elConf.ToString()); writer.Flush(); // Write out the new config. if (!Config.SaveData(level.ConfigId, stream.GetBuffer(), 0, (int)stream.Length)) { throw new PolicyException(String.Format(Environment.GetResourceString("Policy_UnableToSave"), level.Label)); } } catch (Exception e) { if (e is PolicyException) { throw e; } else { throw new PolicyException(String.Format(Environment.GetResourceString("Policy_UnableToSave"), level.Label), e); } } Config.ResetCacheData(level.ConfigId); try { if (CanUseQuickCache(level.RootCodeGroup)) { Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level)); } } catch (Exception) { } }
private static void SaveFingerPrint(String destFileName, FingerPrint fingerPrint) { String fingerPrintFileName = FileDownloader.MakeFingerPrintFilePath(destFileName); SecurityElement finger_print = new SecurityElement("finger_print"); finger_print.AddAttribute("time_stamp", fingerPrint.timeStamp); finger_print.AddAttribute("file_size", fingerPrint.fileSize.ToString()); File.WriteAllText(fingerPrintFileName, finger_print.ToString()); }
/// <summary>Creates and returns a string representation of the current permission object.</summary> /// <returns>A string representation of the current permission object.</returns> public override string ToString() { SecurityElement securityElement = this.ToXml(); return(securityElement.ToString()); }
CreatePermissionFromElement( SecurityElement el, bool safeLoad, bool policyLoad, out bool assemblyIsLoading ) { #if _DEBUG if (debug) DEBUG_WRITE( "ip element = " + el.ToString() ); #endif IPermission ip = XMLUtil.CreatePermission( el, safeLoad, policyLoad, out assemblyIsLoading ); #if _DEBUG if (debug) DEBUG_WRITE( "ip after create = " + (ip == null ? "<null>" : ip.ToString()) ); #endif if (ip == null) return null ; ip.FromXml( el ); #if _DEBUG if (debug) DEBUG_WRITE( "ip after decode = " + (ip == null ? "<null>" : ip.ToString()) ); #endif return ip; }
void Save () { if (IsMarkedForDeletion) return; if (!File.Exists (file) && values.Count == 0) return; SecurityElement se = new SecurityElement ("values"); // With SecurityElement.Text = value, and SecurityElement.AddAttribute(key, value) // the values must be escaped prior to being assigned. foreach (DictionaryEntry de in values){ object val = de.Value; SecurityElement value = new SecurityElement ("value"); value.AddAttribute ("name", SecurityElement.Escape ((string) de.Key)); if (val is string){ value.AddAttribute ("type", "string"); value.Text = SecurityElement.Escape ((string) val); } else if (val is int){ value.AddAttribute ("type", "int"); value.Text = val.ToString (); } else if (val is long) { value.AddAttribute ("type", "qword"); value.Text = val.ToString (); } else if (val is byte []){ value.AddAttribute ("type", "bytearray"); value.Text = Convert.ToBase64String ((byte[]) val); } else if (val is ExpandString){ value.AddAttribute ("type", "expand"); value.Text = SecurityElement.Escape (val.ToString ()); } else if (val is string []){ value.AddAttribute ("type", "string-array"); foreach (string ss in (string[]) val){ SecurityElement str = new SecurityElement ("string"); str.Text = SecurityElement.Escape (ss); value.AddChild (str); } } se.AddChild (value); } using (FileStream fs = File.Create (file)){ StreamWriter sw = new StreamWriter (fs); sw.Write (se.ToString ()); sw.Flush (); } }
private void BuildPathFile() { LoggerHelper.Debug("BuildPathFile"); var root = new System.Security.SecurityElement("root"); foreach (var item in m_instance.m_filesDic) { root.AddChild(new System.Security.SecurityElement("k", item.Key)); root.AddChild(new System.Security.SecurityElement("v", item.Value)); } XMLParser.SaveText(m_instance.m_resourcePath + "resourceInfo.xml", root.ToString()); }
/// <summary> /// 从指定的 XML 文档加载 map 数据。 /// </summary> /// <param name="xml">XML 文档</param> /// <returns>map 数据</returns> public static Dictionary<String, Dictionary<String, String>> LoadMap(SecurityElement xml) { var result = new Dictionary<String, Dictionary<String, String>>(); foreach (SecurityElement subMap in xml.Children) { String key = (subMap.Children[0] as SecurityElement).Text.Trim(); if (result.ContainsKey(key)) { LoggerHelper.Warning(String.Format("Key {0} already exist, in {1}.", key, xml.ToString())); continue; } var children = new Dictionary<string, string>(); result.Add(key, children); for (int i = 1; i < subMap.Children.Count; i++) { var node = subMap.Children[i] as SecurityElement; if (node != null && !children.ContainsKey(node.Tag)) { if (String.IsNullOrEmpty(node.Text)) children.Add(node.Tag, ""); else children.Add(node.Tag, node.Text.Trim()); } else LoggerHelper.Warning(String.Format("Key {0} already exist, index {1} of {2}.", node.Tag, i, node.ToString())); } } return result; }