private void Deserialize(XmlTextReader reader) { try { this.ReadStartOfNodeElement(reader, "erccontext"); if (reader.MoveToFirstAttribute()) { for (;;) { if (!StringComparer.OrdinalIgnoreCase.Equals(reader.Name, "t")) { goto IL_88; } if (!string.IsNullOrEmpty(reader.Value)) { try { this.contextType = (RBACContext.RBACContextType) int.Parse(reader.Value); goto IL_E4; } catch (FormatException) { this.ThrowParserException(reader, Strings.InvalidAttributeValue(reader.Value, "t")); goto IL_E4; } catch (OverflowException) { this.ThrowParserException(reader, Strings.InvalidAttributeValue(reader.Value, "t")); goto IL_E4; } goto IL_88; } IL_E4: if (!reader.MoveToNextAttribute()) { break; } continue; IL_88: if (StringComparer.OrdinalIgnoreCase.Equals(reader.Name, "at")) { this.AuthenticationType = reader.Value; goto IL_E4; } if (StringComparer.OrdinalIgnoreCase.Equals(reader.Name, "un")) { this.ExecutingUserName = reader.Value; goto IL_E4; } this.ThrowParserException(reader, Strings.InvalidAttribute(reader.Name)); goto IL_E4; } } if (RBACContext.RBACContextType.Windows != this.contextType && RBACContext.RBACContextType.Delegated != this.contextType) { this.ThrowParserException(reader, Strings.InvalidRBACContextType(this.contextType.ToString())); } if (this.AuthenticationType == null) { this.ThrowParserException(reader, AuthorizationStrings.AuthenticationTypeIsMissing); } if (string.IsNullOrEmpty(this.ExecutingUserName)) { this.ThrowParserException(reader, Strings.ExecutingUserNameIsMissing); } this.ReadExecutingUser(reader); this.ReadImpersonatedUser(reader); } catch (XmlException ex) { this.ThrowParserException(reader, new LocalizedString(AuthorizationStrings.InvalidXml + " : " + ex.Message)); } }
// Token: 0x06000312 RID: 786 RVA: 0x00010354 File Offset: 0x0000E554 internal static AirSyncUserSecurityContext Deserialize(XmlTextReader reader) { AirSyncUserSecurityContext airSyncUserSecurityContext = new AirSyncUserSecurityContext(); airSyncUserSecurityContext.UserSid = null; airSyncUserSecurityContext.GroupSids = null; airSyncUserSecurityContext.RestrictedGroupSids = null; try { List <SidStringAndAttributes> list = new List <SidStringAndAttributes>(); List <SidStringAndAttributes> list2 = new List <SidStringAndAttributes>(); if (!reader.Read() || XmlNodeType.Element != reader.NodeType || StringComparer.OrdinalIgnoreCase.Compare(reader.Name, "r") != 0) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:RootNodeMissing"); } if (reader.MoveToFirstAttribute()) { do { if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, "at") == 0) { if (airSyncUserSecurityContext.authenticationType != null) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:AuthTypeTwice"); } airSyncUserSecurityContext.authenticationType = reader.Value; } else if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, "ln") == 0) { if (airSyncUserSecurityContext.logonName != null) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:UserNameTwice"); } airSyncUserSecurityContext.logonName = reader.Value; } else { string protocolErrorString = "ProxyRequestError:UnknownElement(" + reader.Name + ")"; AirSyncUserSecurityContext.ThrowParserException(protocolErrorString); } }while (reader.MoveToNextAttribute()); } if (airSyncUserSecurityContext.authenticationType == null || airSyncUserSecurityContext.logonName == null) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:AuthTypeLogonNameMissing"); } bool flag = false; int num = 0; while (reader.Read()) { if (XmlNodeType.EndElement == reader.NodeType && StringComparer.OrdinalIgnoreCase.Compare(reader.Name, "r") == 0) { flag = true; break; } if (XmlNodeType.Element != reader.NodeType || StringComparer.OrdinalIgnoreCase.Compare(reader.Name, "s") != 0) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:NoSID"); } AirSyncUserSecurityContext.SidType sidType = AirSyncUserSecurityContext.SidType.User; uint num2 = 0U; if (reader.MoveToFirstAttribute()) { do { if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, "t") == 0) { int num3 = int.Parse(reader.Value, CultureInfo.InvariantCulture); if (num3 == 1) { sidType = AirSyncUserSecurityContext.SidType.Group; } else if (num3 == 2) { sidType = AirSyncUserSecurityContext.SidType.RestrictedGroup; } else { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:InvalidSIDType"); } } else if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, "a") == 0) { num2 = uint.Parse(reader.Value, CultureInfo.InvariantCulture); } else { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:InvalidSIDAttribute"); } }while (reader.MoveToNextAttribute()); } if (sidType == AirSyncUserSecurityContext.SidType.User) { if (num2 != 0U) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:AttributesOnUserSID"); } else if (airSyncUserSecurityContext.UserSid != null) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:MultipleUserSIDs"); } } if (!reader.Read() || XmlNodeType.Text != reader.NodeType || string.IsNullOrEmpty(reader.Value)) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:BadProxyHeader"); } string value = reader.Value; if (sidType == AirSyncUserSecurityContext.SidType.User) { airSyncUserSecurityContext.UserSid = value; } else if (sidType == AirSyncUserSecurityContext.SidType.Group) { SidStringAndAttributes item = new SidStringAndAttributes(value, num2); list.Add(item); } else if (sidType == AirSyncUserSecurityContext.SidType.RestrictedGroup) { SidStringAndAttributes item2 = new SidStringAndAttributes(value, num2); list2.Add(item2); } if (!reader.Read() || XmlNodeType.EndElement != reader.NodeType) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:BadProxyHeader2"); } num++; if (num > 3000) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:TooManySIDs"); } } if (airSyncUserSecurityContext.UserSid == null) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:NoUserSID"); } if (!flag) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:BadParsing"); } if (list.Count > 0) { airSyncUserSecurityContext.GroupSids = list.ToArray(); } if (list2.Count > 0) { airSyncUserSecurityContext.RestrictedGroupSids = list2.ToArray(); } } catch (XmlException) { AirSyncUserSecurityContext.ThrowParserException("ProxyRequestError:XMLParsingException"); } return(airSyncUserSecurityContext); }
public void ReadXML() { if (File.Exists((CONFIG_FILE))) { //Read in XML fields XmlTextReader reader = new XmlTextReader(CONFIG_FILE); string currentRead; DateTime dateValue; int frequencyValue; /*Read LastUpdate*/ reader.ReadToFollowing(XMLFields.LastUpdate.ToString()); reader.MoveToFirstAttribute(); currentRead = reader.ReadElementContentAsString(); if (DateTime.TryParse(currentRead, out dateValue)) { this.PassLastUpdate(dateValue); } /*Read Frequency*/ reader.ReadToFollowing(XMLFields.Frequency.ToString()); reader.MoveToFirstAttribute(); currentRead = reader.ReadElementContentAsString(); if (int.TryParse(currentRead, out frequencyValue)) { this.PassFrequency((UpdateFrequency)frequencyValue); } /*Read DatabaseAddress*/ reader.ReadToFollowing(XMLFields.DatabaseAddress.ToString()); reader.MoveToFirstAttribute(); currentRead = reader.ReadElementContentAsString(); this.PassDbAddress(currentRead); /*Read DatabaseName*/ reader.ReadToFollowing(XMLFields.DatabaseName.ToString()); reader.MoveToFirstAttribute(); currentRead = reader.ReadElementContentAsString(); this.PassDbName(currentRead); /*Read DatabaseUsername*/ reader.ReadToFollowing(XMLFields.DatabaseUsername.ToString()); reader.MoveToFirstAttribute(); currentRead = reader.ReadElementContentAsString(); this.PassDbUsername(currentRead); /*Read DatabasePassword*/ reader.ReadToFollowing(XMLFields.DatabasePassword.ToString()); reader.MoveToFirstAttribute(); currentRead = reader.ReadElementContentAsString(); this.PassDbPassword(currentRead); reader.Close(); } else { //Config file does not exist! Default values will be used and blank config file created. XmlDocument file = new XmlDocument(); file.LoadXml(XML_TEMPLATE); XmlTextWriter writer = new XmlTextWriter(CONFIG_FILE, null); writer.Formatting = Formatting.Indented; file.Save(writer); } }
/// <summary> /// It creates a SVG document reading from a file. /// If a current document exists, it is destroyed. /// </summary> /// <param name="sFilename">The complete path of a valid SVG file.</param> /// <returns> /// true if the file is loaded successfully and it is a valid SVG document, false if the file cannot be open or if it is not /// a valid SVG document. /// </returns> public bool LoadFromFile(XmlTextReader reader) { ErrH err = new ErrH("SvgDoc", "LoadFromFile"); err.LogParameter("sFilename", reader.BaseURI); if (m_root != null) { m_root = null; m_nNextId = 1; m_elements.Clear(); } bool bResult = true; try { // XmlTextReader reader; // reader = new XmlTextReader(sFilename); reader.WhitespaceHandling = WhitespaceHandling.None; reader.Normalization = false; reader.XmlResolver = null; reader.Namespaces = false; string tmp; SvgElement eleParent = null; SvgElement eleLast = null; try { // parse the file and display each of the nodes. while (reader.Read() && bResult) { switch (reader.NodeType) { case XmlNodeType.Attribute: tmp = reader.Name; tmp = reader.Value; break; case XmlNodeType.Element: { SvgElement ele = AddElement(eleParent, reader.Name, ref eleLast); if (ele == null) { err.Log("Svg element cannot be added. Name: " + reader.Name, ErrH._LogPriority.Warning); bResult = false; } else { eleParent = ele; if (reader.IsEmptyElement) { if (eleParent != null) { eleParent = eleParent.getParent(); } } bool bLoop = reader.MoveToFirstAttribute(); while (bLoop) { ele.SetAttributeValue(reader.Name, reader.Value); bLoop = reader.MoveToNextAttribute(); } } } break; case XmlNodeType.Text: if (eleParent != null) { eleParent.setElementValue(reader.Value); } break; case XmlNodeType.CDATA: err.Log("Unexpected item: " + reader.Value, ErrH._LogPriority.Warning); break; case XmlNodeType.ProcessingInstruction: err.Log("Unexpected item: " + reader.Value, ErrH._LogPriority.Warning); break; case XmlNodeType.Comment: err.Log("Unexpected item: " + reader.Value, ErrH._LogPriority.Warning); break; case XmlNodeType.XmlDeclaration: m_sXmlDeclaration = "<?xml " + reader.Value + "?>"; break; case XmlNodeType.Document: err.Log("Unexpected item: " + reader.Value, ErrH._LogPriority.Warning); break; case XmlNodeType.DocumentType: { string sDTD1; string sDTD2; sDTD1 = reader.GetAttribute("PUBLIC"); sDTD2 = reader.GetAttribute("SYSTEM"); m_sXmlDocType = "<!DOCTYPE svg PUBLIC \"" + sDTD1 + "\" \"" + sDTD2 + "\">"; } break; case XmlNodeType.EntityReference: err.Log("Unexpected item: " + reader.Value, ErrH._LogPriority.Warning); break; case XmlNodeType.EndElement: if (eleParent != null) { eleParent = eleParent.getParent(); } break; } // switch } // while } // read try catch (XmlException xmle) { err.LogException(xmle); err.LogParameter("Line Number", xmle.LineNumber.ToString()); err.LogParameter("Line Position", xmle.LinePosition.ToString()); bResult = false; } catch (Exception e) { err.LogException(e); bResult = false; } finally { reader.Close(); } } catch { err.LogUnhandledException(); bResult = false; } err.LogEnd(bResult); return(bResult); }
void CheckXmlDoc(AstNode node) { ResolveResult resolveResult = ctx.Resolve(node); IEntity member = null; if (resolveResult is TypeResolveResult) { member = resolveResult.Type.GetDefinition(); } if (resolveResult is MemberResolveResult) { member = ((MemberResolveResult)resolveResult).Member; } var xml = new StringBuilder(); xml.AppendLine("<root>"); foreach (var cmt in storedXmlComment) { xml.AppendLine(cmt.Content); } xml.AppendLine("</root>"); List <Tuple <string, int> > parameters = new List <Tuple <string, int> >(); using (var reader = new XmlTextReader(new StringReader(xml.ToString()))) { try { while (reader.Read()) { if (member == null) { continue; } if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "param": reader.MoveToFirstAttribute(); var line = reader.LineNumber; var name = reader.GetAttribute("name"); if (name == null) { break; } parameters.Add(Tuple.Create(name, line)); break; } } } } catch (XmlException) { } if (storedXmlComment.Count > 0 && parameters.Count > 0) { var pm = member as IParameterizedMember; if (pm != null) { for (int i = 0; i < pm.Parameters.Count; i++) { var p = pm.Parameters [i]; if (!parameters.Any(tp => tp.Item1 == p.Name)) { AstNode before = i < parameters.Count ? storedXmlComment [parameters [i].Item2 - 2] : null; AstNode afterNode = before == null ? storedXmlComment [storedXmlComment.Count - 1] : null; AddIssue( GetParameterHighlightNode(node, i), string.Format(ctx.TranslateString("Missing xml documentation for Parameter '{0}'"), p.Name), string.Format(ctx.TranslateString("Create xml documentation for Parameter '{0}'"), p.Name), script => { if (before != null) { script.InsertBefore( before, new Comment(string.Format(" <param name = \"{0}\"></param>", p.Name), CommentType.Documentation) ); } else { script.InsertAfter( afterNode, new Comment(string.Format(" <param name = \"{0}\"></param>", p.Name), CommentType.Documentation) ); } }); } } } } storedXmlComment.Clear(); } }
internal static void ParseProxyLanguagePostBody(Stream bodyStream, out CultureInfo culture, out string timeZoneKeyName, out bool isOptimized, out string destination, out SerializedClientSecurityContext serializedContext) { ExTraceGlobals.ProxyCallTracer.TraceDebug(0L, "ProxyLanguagePostRequest.ParseProxyLanguagePostBody"); culture = null; timeZoneKeyName = string.Empty; isOptimized = false; destination = string.Empty; serializedContext = null; XmlTextReader xmlTextReader = null; try { xmlTextReader = SafeXmlFactory.CreateSafeXmlTextReader(bodyStream); xmlTextReader.WhitespaceHandling = WhitespaceHandling.All; if (!xmlTextReader.Read() || XmlNodeType.Element != xmlTextReader.NodeType || StringComparer.OrdinalIgnoreCase.Compare(xmlTextReader.Name, ProxyLanguagePostRequest.rootElementName) != 0) { ProxyLanguagePostRequest.ThrowParserException(xmlTextReader, "Missing or invalid root node"); } if (xmlTextReader.MoveToFirstAttribute()) { do { if (StringComparer.OrdinalIgnoreCase.Compare(xmlTextReader.Name, ProxyLanguagePostRequest.timeZoneKeyNameAttributeName) == 0) { if (DateTimeUtilities.IsValidTimeZoneKeyName(xmlTextReader.Value)) { timeZoneKeyName = xmlTextReader.Value; ExTraceGlobals.ProxyDataTracer.TraceDebug <string>(0L, "Found timeZoneKeyName={0}", timeZoneKeyName); } else { ProxyLanguagePostRequest.ThrowParserException(xmlTextReader, "Invalid time zone id"); } } else if (StringComparer.OrdinalIgnoreCase.Compare(xmlTextReader.Name, ProxyLanguagePostRequest.localeIdAttributeName) == 0) { int num = -1; if (int.TryParse(xmlTextReader.Value, out num) && Culture.IsSupportedCulture(num)) { culture = Culture.GetCultureInfoInstance(num); ExTraceGlobals.ProxyDataTracer.TraceDebug <int>(0L, "Found localeId={0}", num); } else { ProxyLanguagePostRequest.ThrowParserException(xmlTextReader, "Invalid locale id"); } } else if (StringComparer.OrdinalIgnoreCase.Compare(xmlTextReader.Name, ProxyLanguagePostRequest.isOptimizedAttributeName) == 0) { int num2 = -1; if (int.TryParse(xmlTextReader.Value, out num2)) { isOptimized = (num2 == 1); ExTraceGlobals.ProxyDataTracer.TraceDebug <bool>(0L, "Found isOptimized={0}", isOptimized); } else { ProxyLanguagePostRequest.ThrowParserException(xmlTextReader, "Invalid is-optimized value"); } } else if (StringComparer.OrdinalIgnoreCase.Compare(xmlTextReader.Name, ProxyLanguagePostRequest.destinationAttributeName) == 0) { destination = xmlTextReader.Value; } else { ExTraceGlobals.ProxyTracer.TraceDebug(0L, "ProxyLanguagePostRequest.ParseProxyLanguagePostBody - Found invalid attribute, ignoring it."); } }while (xmlTextReader.MoveToNextAttribute()); } ExTraceGlobals.ProxyTracer.TraceDebug(0L, "Deserializing client context..."); serializedContext = SerializedClientSecurityContext.Deserialize(xmlTextReader); if (!xmlTextReader.Read() || XmlNodeType.EndElement != xmlTextReader.NodeType || StringComparer.OrdinalIgnoreCase.Compare(xmlTextReader.Name, ProxyLanguagePostRequest.rootElementName) != 0) { ProxyLanguagePostRequest.ThrowParserException(xmlTextReader, "Missing or invalid root node"); } } catch (XmlException ex) { ProxyLanguagePostRequest.ThrowParserException(xmlTextReader, string.Format("Parser threw an XML exception: {0}", ex.Message)); } finally { xmlTextReader.Close(); } }
private GLocalizeCountry Load_Locs(string _file) { int num = 0; string text = ""; string text2 = ""; GLocalizeCountry gLocalizeCountry = null; try { XmlTextReader xmlTextReader = new XmlTextReader(Path + _file); while (xmlTextReader.Read()) { if (xmlTextReader.NodeType == XmlNodeType.Element) { if (xmlTextReader.Name.ToLower() == "countries") { num = 1; if (xmlTextReader.HasAttributes) { xmlTextReader.MoveToFirstAttribute(); for (int i = 0; i < xmlTextReader.AttributeCount; i++) { xmlTextReader.MoveToAttribute(i); if (xmlTextReader.Name.ToLower() == "iso") { text2 = xmlTextReader.Value.ToString(); } else if (xmlTextReader.Name.ToLower() == "file") { text = xmlTextReader.Value.ToString(); } } } gLocalizeCountry = Localize_Base(text); gLocalizeCountry.BaseFile = text; gLocalizeCountry.BaseLoc = text2; } if (xmlTextReader.Name.ToLower() == "country" && num == 1 && xmlTextReader.HasAttributes) { xmlTextReader.MoveToFirstAttribute(); for (int i = 0; i < xmlTextReader.AttributeCount; i++) { xmlTextReader.MoveToAttribute(i); if (xmlTextReader.Name.ToLower() == "iso") { text2 = xmlTextReader.Value.ToString(); } else if (xmlTextReader.Name.ToLower() == "file") { text = xmlTextReader.Value.ToString(); } else { xmlTextReader.MoveToElement(); } } Array.Resize(ref gLocalizeCountry.Locs, gLocalizeCountry.Locs.Length + 1); gLocalizeCountry.Locs[gLocalizeCountry.Locs.Length - 1] = text2; Array.Resize(ref gLocalizeCountry.LocsFile, gLocalizeCountry.LocsFile.Length + 1); gLocalizeCountry.LocsFile[gLocalizeCountry.LocsFile.Length - 1] = text; } } if (xmlTextReader.NodeType == XmlNodeType.EndElement && xmlTextReader.Name.ToLower() == "countries") { num = 0; } } xmlTextReader.Close(); } catch (Exception ex) { error = ex.Message; return(null); } return(gLocalizeCountry); }
public bool FirstAttribute() { return(_reader.MoveToFirstAttribute()); }
/// <summary> /// Read through the entire XML of a given project file, searching for the element/attribute /// specified by element number and attribute number. Return the line number and column /// number where it was found. /// </summary> /// <param name="projectFile">Path to project file on disk.</param> /// <param name="xmlElementNumberToSearchFor">Which Xml element to search for.</param> /// <param name="xmlAttributeNumberToSearchFor"> /// Which Xml attribute within the above Xml element to search for. Pass in zero /// if you are searching for the Element as a whole and not a particular attribute. /// </param> /// <param name="foundLineNumber">(out) The line number where the given element/attribute begins.</param> /// <param name="foundColumnNumber">The column number where the given element/attribute begins.</param> /// <returns>true if found, false otherwise. Should not throw any exceptions.</returns> /// <owner>RGoel</owner> internal static bool GetLineColumnByNodeNumber ( string projectFile, int xmlElementNumberToSearchFor, int xmlAttributeNumberToSearchFor, out int foundLineNumber, out int foundColumnNumber ) { ErrorUtilities.VerifyThrow(xmlElementNumberToSearchFor != 0, "No element to search for!"); ErrorUtilities.VerifyThrow((projectFile != null) && (projectFile.Length != 0), "No project file!"); // Initialize output parameters. foundLineNumber = 0; foundColumnNumber = 0; try { // We're going to need to re-read the file from disk in order to find // the line/column number of the specified node. using (XmlTextReader reader = new XmlTextReader(projectFile)) { reader.DtdProcessing = DtdProcessing.Ignore; int currentXmlElementNumber = 0; // While we haven't reached the end of the file, and we haven't found the // specified node ... while (reader.Read() && (foundColumnNumber == 0) && (foundLineNumber == 0)) { // Read to the next node. If it is an XML element or Xml text node, then ... if ((reader.NodeType == XmlNodeType.Element) || (reader.NodeType == XmlNodeType.Text)) { // Bump up our current XML element count. currentXmlElementNumber++; // Check to see if this XML element is the one we've been searching for, // based on if the numbers match. if (currentXmlElementNumber == xmlElementNumberToSearchFor) { // We've found the desired XML element. If the caller didn't care // for a particular attribute, then we're done. Return the current // position of the XmlTextReader. if (0 == xmlAttributeNumberToSearchFor) { foundLineNumber = reader.LineNumber; foundColumnNumber = reader.LinePosition; if (reader.NodeType == XmlNodeType.Element) { // Do a minus-one here, because the XmlTextReader points us at the first // letter of the tag name, whereas we would prefer to point at the opening // left-angle-bracket. (Whitespace between the left-angle-bracket and // the tag name is not allowed in XML, so this is safe.) foundColumnNumber = foundColumnNumber - 1; } } else if (reader.MoveToFirstAttribute()) { // Caller wants a particular attribute within the element, // and the element does have 1 or more attributes. So let's // try to find the right one. int currentXmlAttributeNumber = 0; // Loop through all the XML attributes on the current element. do { // Bump the current attribute number and check to see if this // is the one. currentXmlAttributeNumber++; if (currentXmlAttributeNumber == xmlAttributeNumberToSearchFor) { // We found the desired attribute. Return the current // position of the XmlTextReader. foundLineNumber = reader.LineNumber; foundColumnNumber = reader.LinePosition; } } while (reader.MoveToNextAttribute() && (foundColumnNumber == 0) && (foundLineNumber == 0)); } } } } } } catch (XmlException) { // Eat the exception. If anything fails, we simply don't surface the line/column number. } catch (IOException) { // Eat the exception. If anything fails, we simply don't surface the line/column number. } catch (UnauthorizedAccessException) { // Eat the exception. If anything fails, we simply don't surface the line/column number. } return((foundColumnNumber != 0) && (foundLineNumber != 0)); }
public static XTRMObject consumeXML(string XmlFragment, int lVariant = 0, bool bDeep = false) { //XDictionaryLoader myDictionaryLoader = new XDictionaryLoader(); //myDictionaryLoader.Augment(); // // Consume XML to create the XComponent object. // if bDeep is false, then ONLY do this object. // if bDeep is true, then also do recursive objects. XmlTextReader reader = null; XmlParserContext context = null; XTRMConfig thisEntity = null; if (lVariant == 1) { thisEntity = new XTRMConfig(); thisEntity.Initialize(-1); } else { thisEntity = new XTRMConfig(); } thisEntity.variant = lVariant; try { // Load the reader with the data file and ignore all white space nodes. context = new XmlParserContext(null, null, null, XmlSpace.None); reader = new XmlTextReader(XmlFragment, XmlNodeType.Element, context); reader.WhitespaceHandling = WhitespaceHandling.None; // Parse the file and display each of the nodes. bool bResult = reader.Read(); int lElementType = 0; XDictionaryLoader myDictionaryLoader = new XDictionaryLoader(); Dictionary <String, String> elementAttributes; while (bResult) { bool bProcessed = false; switch (reader.NodeType) { case XmlNodeType.Element: string elementName = reader.Name; if (!bProcessed) { // May wish to get all the attributes here for new elements! elementAttributes = new Dictionary <String, String>(); if (reader.HasAttributes) { reader.MoveToFirstAttribute(); for (int i = 0; i < reader.AttributeCount; i++) { //reader.GetAttribute(i); elementAttributes.Add(reader.Name.ToUpper(), reader.Value); reader.MoveToNextAttribute(); } // Check to see if ID is supplied! //if (elementAttributes["ID"] != null) if (elementAttributes.ContainsKey("TAG")) { thisEntity.entityTag = elementAttributes["TAG"]; } if (elementAttributes.ContainsKey("SOURCE")) { thisEntity.entitySource = elementAttributes["SOURCE"]; } if (elementAttributes.ContainsKey("USER")) { thisEntity.entityUser = elementAttributes["USER"]; } if (elementAttributes.ContainsKey("PATH")) { thisEntity.entityPath = elementAttributes["PATH"]; } if (elementAttributes.ContainsKey("PATTERN")) { thisEntity.entityPattern = elementAttributes["PATTERN"]; } if (elementAttributes.ContainsKey("RECURSE")) { thisEntity.entityRecurse = Convert.ToInt16(elementAttributes["RECURSE"]); } if (elementAttributes.ContainsKey("BUFSIZE")) { thisEntity.entityBufsize = Convert.ToInt16(elementAttributes["BUFSIZE"]); } if (elementAttributes.ContainsKey("HOLDTIME")) { thisEntity.entityHoldTime = Convert.ToInt16(elementAttributes["HOLDTIME"]); } if (elementAttributes.ContainsKey("SCHEMA")) { thisEntity.entitySchema = elementAttributes["SCHEMA"]; } reader.MoveToElement(); } // Need to see if we are interested in this element! //string elementName = reader.Name; switch (elementName.ToUpper()) { case "PATH": // Path lElementType = 1; bResult = reader.Read(); break; case "PATTERN": // Pattern lElementType = 2; bResult = reader.Read(); break; case "RECURSE": // Recurse lElementType = 3; bResult = reader.Read(); break; case "BUFSIZE": // Bufsize lElementType = 4; bResult = reader.Read(); break; case "HOLDTIME": // HoldTime lElementType = 5; bResult = reader.Read(); break; default: bResult = reader.Read(); break; } } break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: //writer.WriteProcessingInstruction(reader.Name, reader.Value); bResult = reader.Read(); break; case XmlNodeType.Comment: //writer.WriteComment(reader.Value); bResult = reader.Read(); break; case XmlNodeType.EndElement: //writer.WriteFullEndElement(); bResult = reader.Read(); break; case XmlNodeType.Text: //Console.Write(reader.Value); switch (lElementType) { case 1: // Path thisEntity.entityPath = reader.Value; break; case 2: // Pattern thisEntity.entityPattern = reader.Value; break; case 3: // Recurse thisEntity.entityRecurse = Convert.ToInt16(reader.Value); break; case 4: // Bufsize thisEntity.entityBufsize = Convert.ToInt16(reader.Value); break; case 5: // HoldTime thisEntity.entityHoldTime = Convert.ToInt16(reader.Value); break; default: break; } lElementType = 0; bResult = reader.Read(); break; default: bResult = reader.Read(); break; } } } catch (Exception ex) { exCount_XML++; XLogger(2210, -1, string.Format("XML={0}; Message={1}", XmlFragment, ex.Message)); } finally { if (reader != null) { reader.Close(); } } return(thisEntity); }
public object Deserialize(XmlTextReader reader, Type type, object context) { //If the object has a type converter then just read the attribute string TypeConverter conv = TypeDescriptor.GetConverter(type); if (CanSerialize(conv)) { string strValue = reader.ReadElementString(); object value = conv.ConvertFromInvariantString(strValue); return(value); } //Create an instance of the type Object obj = Activator.CreateInstance(type); //Use the IXmlSerializable implementation if needed IXmlSerializable serializableObject = obj as IXmlSerializable; if (serializableObject != null) { serializableObject.ReadXml(reader); return(obj); } //parse all the attributes as properties PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(type); bool hasChildren = !reader.IsEmptyElement; if (reader.MoveToFirstAttribute()) { do { PropertyDescriptor prop = properties[reader.Name]; if (prop == null) { throw new InvalidOperationException("the property " + reader.Name + " does not exist on the object " + type.Name); } reader.ReadAttributeValue(); TypeConverter converter = prop.Converter; object value = converter.ConvertFromInvariantString(reader.Value); prop.SetValue(obj, value); }while (reader.MoveToNextAttribute()); } reader.Read(); if (hasChildren) { //Parse the children as properties while (true) { if (reader.NodeType == XmlNodeType.Element) { //If the property is read-only and a list then add the children to the list members PropertyDescriptor prop = properties[reader.Name]; if (prop == null) { throw new InvalidOperationException("the property " + reader.Name + " does not exist on the object " + type.Name); } if (prop.IsReadOnly) { IList list = prop.GetValue(obj) as IList; if (list != null) { DefaultListSerializer serializer = new DefaultListSerializer(); serializer.Deserialize(reader, list.GetType(), list); } } else { //parse the value and set the property object value = ObjectSerializer.Deserialize(reader, prop.PropertyType, null); prop.SetValue(obj, value); } } // If end element then we are done parsing children. else if (reader.NodeType == XmlNodeType.EndElement) { reader.Read(); //end element break; } else if (reader.EOF) { break; //end of document } // If we don't explicitly handle this kind of node then ignore it. else { reader.Read(); } } } return(obj); }
// Token: 0x0600038E RID: 910 RVA: 0x000141AC File Offset: 0x000123AC internal static SerializedClientSecurityContext Deserialize(XmlTextReader reader) { SerializedClientSecurityContext serializedClientSecurityContext = new SerializedClientSecurityContext(); serializedClientSecurityContext.UserSid = null; serializedClientSecurityContext.GroupSids = null; serializedClientSecurityContext.RestrictedGroupSids = null; try { List <SidStringAndAttributes> list = new List <SidStringAndAttributes>(); List <SidStringAndAttributes> list2 = new List <SidStringAndAttributes>(); if (!reader.Read() || XmlNodeType.Element != reader.NodeType || StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.RootElementName) != 0) { SerializedClientSecurityContext.ThrowParserException(reader, "Missing or invalid root node"); } if (reader.MoveToFirstAttribute()) { do { if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.AuthenticationTypeAttributeName) == 0) { if (serializedClientSecurityContext.authenticationType != null) { SerializedClientSecurityContext.ThrowParserException(reader, string.Format("Duplicated attribute {0}", SerializedClientSecurityContext.AuthenticationTypeAttributeName)); } serializedClientSecurityContext.authenticationType = reader.Value; } else if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.LogonNameAttributeName) == 0) { if (serializedClientSecurityContext.logonName != null) { SerializedClientSecurityContext.ThrowParserException(reader, string.Format("Duplicated attribute {0}", SerializedClientSecurityContext.LogonNameAttributeName)); } serializedClientSecurityContext.logonName = reader.Value; } else { SerializedClientSecurityContext.ThrowParserException(reader, "Found invalid attribute in root element"); } }while (reader.MoveToNextAttribute()); } if (serializedClientSecurityContext.authenticationType == null || serializedClientSecurityContext.logonName == null) { SerializedClientSecurityContext.ThrowParserException(reader, "Auth type or logon name attributes are missing"); } bool flag = false; int num = 0; while (reader.Read()) { if (XmlNodeType.EndElement == reader.NodeType && StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.RootElementName) == 0) { flag = true; break; } if (XmlNodeType.Element != reader.NodeType || StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.SidElementName) != 0) { SerializedClientSecurityContext.ThrowParserException(reader, "Expecting SID node"); } SerializedClientSecurityContext.SidType sidType = SerializedClientSecurityContext.SidType.User; uint num2 = 0U; if (reader.MoveToFirstAttribute()) { do { if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.SidTypeAttributeName) == 0) { int num3 = int.Parse(reader.Value); if (num3 == 1) { sidType = SerializedClientSecurityContext.SidType.Group; } else if (num3 == 2) { sidType = SerializedClientSecurityContext.SidType.RestrictedGroup; } else { SerializedClientSecurityContext.ThrowParserException(reader, "Invalid SID type"); } } else if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.SidAttributesAttributeName) == 0) { num2 = uint.Parse(reader.Value); } else { SerializedClientSecurityContext.ThrowParserException(reader, "Found invalid attribute in SID element"); } }while (reader.MoveToNextAttribute()); } if (sidType == SerializedClientSecurityContext.SidType.User) { if (num2 != 0U) { SerializedClientSecurityContext.ThrowParserException(reader, "'Attributes' shouldn't be set in an user SID"); } else if (serializedClientSecurityContext.UserSid != null) { SerializedClientSecurityContext.ThrowParserException(reader, "There can only be one user SID in the XML document"); } } if (!reader.Read() || XmlNodeType.Text != reader.NodeType || string.IsNullOrEmpty(reader.Value)) { SerializedClientSecurityContext.ThrowParserException(reader, "Expecting SID value in SDDL format"); } string value = reader.Value; if (sidType == SerializedClientSecurityContext.SidType.User) { serializedClientSecurityContext.UserSid = value; } else if (sidType == SerializedClientSecurityContext.SidType.Group) { SidStringAndAttributes item = new SidStringAndAttributes(value, num2); list.Add(item); } else if (sidType == SerializedClientSecurityContext.SidType.RestrictedGroup) { SidStringAndAttributes item2 = new SidStringAndAttributes(value, num2); list2.Add(item2); } if (!reader.Read() || XmlNodeType.EndElement != reader.NodeType) { SerializedClientSecurityContext.ThrowParserException(reader, "Expected end of SID node"); } num++; if (num > SerializedClientSecurityContext.MaximumSidsPerContext) { throw new Exception(string.Format("Too many SID nodes in the request, maximum is {0}", SerializedClientSecurityContext.MaximumSidsPerContext)); } } if (serializedClientSecurityContext.UserSid == null) { SerializedClientSecurityContext.ThrowParserException(reader, "Serialized context should at least contain an user SID"); } if (!flag) { SerializedClientSecurityContext.ThrowParserException(reader, "Parsing error"); } if (list.Count > 0) { serializedClientSecurityContext.GroupSids = list.ToArray(); } if (list2.Count > 0) { serializedClientSecurityContext.RestrictedGroupSids = list2.ToArray(); } } catch (XmlException ex) { SerializedClientSecurityContext.ThrowParserException(reader, string.Format("Parser threw an XML exception: {0}", ex.Message)); } return(serializedClientSecurityContext); }
public GLocalizeCountry Localize_Base(string _file) { int num = 0; int num2 = 0; string idEnum = ""; string loc = ""; string text = ""; int id = 0; GLocalizeItem.Tipos tipo = GLocalizeItem.Tipos.Desconocido; GLocalizeCountry gLocalizeCountry = new GLocalizeCountry(); try { XmlTextReader xmlTextReader = new XmlTextReader(Path + _file); while (xmlTextReader.Read()) { if (xmlTextReader.NodeType == XmlNodeType.Text && num == 1) { text = xmlTextReader.Value.ToString(); GLocalizeItem gLocalizeItem = new GLocalizeItem(); gLocalizeItem.Translated = true; gLocalizeItem.Tipo = tipo; gLocalizeItem.Loc = loc; gLocalizeItem.Id = id; gLocalizeItem.IdEnum = idEnum; gLocalizeItem.Original = text; gLocalizeItem.Translation = text; gLocalizeCountry.CopyItem(gLocalizeItem); num = 0; } if (xmlTextReader.NodeType == XmlNodeType.Element) { if (xmlTextReader.Name.ToLower() == "localize") { num2 = 1; if (xmlTextReader.HasAttributes) { xmlTextReader.MoveToFirstAttribute(); for (int i = 0; i < xmlTextReader.AttributeCount; i++) { xmlTextReader.MoveToAttribute(i); if (xmlTextReader.Name.ToLower() == "iso") { gLocalizeCountry.BaseLoc = (gLocalizeCountry.Loc = xmlTextReader.Value.ToString()); } } } } if (xmlTextReader.Name.ToLower() == "text" && num2 == 1) { num = 1; if (xmlTextReader.HasAttributes) { xmlTextReader.MoveToFirstAttribute(); for (int i = 0; i < xmlTextReader.AttributeCount; i++) { xmlTextReader.MoveToAttribute(i); if (xmlTextReader.Name.ToLower() == "iso") { loc = xmlTextReader.Value.ToString(); } else if (xmlTextReader.Name.ToLower() == "id") { id = Convert.ToInt32(xmlTextReader.Value.ToString()); } else if (xmlTextReader.Name.ToLower() == "enum") { idEnum = xmlTextReader.Value.ToString(); } else if (xmlTextReader.Name.ToLower() == "type") { string text2 = xmlTextReader.Value.ToString(); switch (text2.ToLower()) { case "imagen": tipo = GLocalizeItem.Tipos.Imagen; break; case "link": tipo = GLocalizeItem.Tipos.Link; break; case "texto": tipo = GLocalizeItem.Tipos.Texto; break; case "video": tipo = GLocalizeItem.Tipos.Video; break; case "datos": tipo = GLocalizeItem.Tipos.Datos; break; case "audio": tipo = GLocalizeItem.Tipos.Audio; break; default: tipo = GLocalizeItem.Tipos.Desconocido; break; } } else { xmlTextReader.MoveToElement(); } } } } if (xmlTextReader.NodeType == XmlNodeType.EndElement && xmlTextReader.Name.ToLower() == "localize") { num2 = 0; } } } xmlTextReader.Close(); } catch (Exception ex) { error = ex.Message; return(null); } return(gLocalizeCountry); }
public bool Localize_Country(ref GLocalizeCountry _l, string _file) { int num = 0; int num2 = 0; string text = ""; string id = "0"; try { XmlTextReader xmlTextReader = new XmlTextReader(Path + _file); while (xmlTextReader.Read()) { if (xmlTextReader.NodeType == XmlNodeType.Text && num == 1) { text = xmlTextReader.Value.ToString(); GLocalizeItem gLocalizeItem = new GLocalizeItem(); _l.EditTranslation(id, text); num = 0; } if (xmlTextReader.NodeType == XmlNodeType.Element) { if (xmlTextReader.Name.ToLower() == "localize") { num2 = 1; if (xmlTextReader.HasAttributes) { xmlTextReader.MoveToFirstAttribute(); for (int i = 0; i < xmlTextReader.AttributeCount; i++) { xmlTextReader.MoveToAttribute(i); if (xmlTextReader.Name.ToLower() == "iso") { _l.Loc = xmlTextReader.Value.ToString(); } } } } if (xmlTextReader.Name.ToLower() == "text" && num2 == 1) { num = 1; if (xmlTextReader.HasAttributes) { xmlTextReader.MoveToFirstAttribute(); for (int i = 0; i < xmlTextReader.AttributeCount; i++) { xmlTextReader.MoveToAttribute(i); if (xmlTextReader.Name.ToLower() == "id") { id = xmlTextReader.Value.ToString(); } else { xmlTextReader.MoveToElement(); } } } } if (xmlTextReader.NodeType == XmlNodeType.EndElement && xmlTextReader.Name.ToLower() == "localize") { num2 = 0; } } } xmlTextReader.Close(); } catch (Exception ex) { error = ex.Message; return(false); } return(true); }
private void ReadImpersonatedUser(XmlTextReader reader) { if (reader.Read() && XmlNodeType.EndElement == reader.NodeType && StringComparer.OrdinalIgnoreCase.Equals(reader.Name, "erccontext")) { return; } if (XmlNodeType.Element != reader.NodeType || !StringComparer.OrdinalIgnoreCase.Equals(reader.Name, "im")) { this.ThrowParserException(reader, Strings.UnExpectedElement("im", reader.Name)); } bool flag = false; if (reader.MoveToFirstAttribute()) { do { if (StringComparer.OrdinalIgnoreCase.Equals(reader.Name, "sddl")) { this.impersonatedUserSddl = reader.Value; } else if (StringComparer.OrdinalIgnoreCase.Equals(reader.Name, "at")) { this.impersonatedAuthenticationType = reader.Value; } else { if (StringComparer.OrdinalIgnoreCase.Equals(reader.Name, "cca")) { if (string.IsNullOrEmpty(reader.Value)) { goto IL_120; } try { this.callerCheckedAccess = bool.Parse(reader.Value); flag = true; goto IL_120; } catch (FormatException) { this.ThrowParserException(reader, Strings.InvalidAttributeValue(reader.Value, "cca")); goto IL_120; } } this.ThrowParserException(reader, Strings.InvalidAttribute(reader.Name)); } IL_120 :; }while (reader.MoveToNextAttribute()); } if (string.IsNullOrEmpty(this.impersonatedUserSddl)) { this.ThrowParserException(reader, Strings.MissingImpersonatedUserSid); } if (this.impersonatedAuthenticationType == null) { this.ThrowParserException(reader, AuthorizationStrings.AuthenticationTypeIsMissing); } if (!flag) { this.ThrowParserException(reader, Strings.MissingAttribute("cca", "im")); } while (reader.Read()) { if (XmlNodeType.Element != reader.NodeType) { return; } string name; if ((name = reader.Name) != null) { if (name == "rtf") { this.roleTypeFilter = this.ReadListElements <RoleType>(reader, "rtf", new Func <XmlTextReader, RoleType>(this.ParseListElementToRoleType)); continue; } if (name == "lrr") { this.logonUserRequiredRoleTypes = this.ReadListElements <RoleType>(reader, "lrr", new Func <XmlTextReader, RoleType>(this.ParseListElementToRoleType)); continue; } if (name == "sref") { this.sortedRoleEntryFilter = this.ReadListElements <RoleEntry>(reader, "sref", new Func <XmlTextReader, RoleEntry>(this.ParseListElementToRoleEntry)); continue; } } this.ThrowParserException(reader, Strings.InvalidElement(reader.Name)); } }
public int ParseConfig(string configFile, bool bDeep = false) { // // Consume XML to create the XFSEntity objects. // if bDeep is false, then ONLY do this object. // if bDeep is true, then also do recursive objects. XmlTextReader reader = null; int rc = -1; string connectString = XTRMObject.getDictionaryEntry("TaskConnectString"); string outerXML; int lElementType = 0; XDictionaryLoader myDictionaryLoader = new XDictionaryLoader(); Dictionary <String, String> elementAttributes; entities.Clear(); try { // Load the reader with the data file and ignore all white space nodes. reader = new XmlTextReader(configFile); reader.WhitespaceHandling = WhitespaceHandling.None; // Parse the file and display each of the nodes. bool bResult = reader.Read(); while (bResult) { bool bProcessed = false; switch (reader.NodeType) { case XmlNodeType.Element: string elementName = reader.Name; switch (elementName.ToUpper()) { case "XFSENTITY": outerXML = reader.ReadOuterXml(); XTRMFSEntity thisEntity = (XTRMFSEntity)XTRMFSEntity.consumeXML(outerXML, 1, true); entities.Add(thisEntity); bProcessed = true; break; } if (!bProcessed) { // May wish to get all the attributes here for new elements! elementAttributes = new Dictionary <String, String>(); if (reader.HasAttributes) { reader.MoveToFirstAttribute(); for (int i = 0; i < reader.AttributeCount; i++) { //reader.GetAttribute(i); elementAttributes.Add(reader.Name, reader.Value); reader.MoveToNextAttribute(); } if (elementAttributes.ContainsKey("Tag")) { agentTag = elementAttributes["Tag"]; } if (elementAttributes.ContainsKey("Source")) { agentSource = elementAttributes["Source"]; } if (elementAttributes.ContainsKey("User")) { agentUser = elementAttributes["User"]; } if (elementAttributes.ContainsKey("EventPath")) { agentEventPath = elementAttributes["EventPath"]; } reader.MoveToElement(); } // Need to see if we are interested in this element! //string elementName = reader.Name; switch (elementName.ToUpper()) { case "XFILEAGENTCONFIG": // Advance into Elements! reader.MoveToContent(); bResult = reader.Read(); break; default: bResult = reader.Read(); break; } } break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: //writer.WriteProcessingInstruction(reader.Name, reader.Value); bResult = reader.Read(); break; case XmlNodeType.Comment: //writer.WriteComment(reader.Value); bResult = reader.Read(); break; case XmlNodeType.EndElement: //writer.WriteFullEndElement(); bResult = reader.Read(); break; case XmlNodeType.Text: //Console.Write(reader.Value); switch (lElementType) { default: break; } bResult = reader.Read(); break; default: bResult = reader.Read(); break; } } } catch (Exception ex) { exCount_XML++; XLogger(2400, -1, string.Format("XTRMFileAgent::parseConfig(); ConfigFile={0}; Message={1}", configFile, ex.Message)); } finally { if (reader != null) { reader.Close(); } } return(rc); }
public List <DrawingObject> Unserialize(string path) { List <DrawingObject> DrawingObject = new List <DrawingObject>(); Edge line = null; string startVertex = null, endVertex = null; int StartPointX = 0, StartPointY = 0, EndPointX = 0, EndPointY = 0; string id = null; string tipe = null, nama = null, jenisRelasiAsal = null, jenisRelasiTujuan = null; XmlTextReader reader = new XmlTextReader(path); reader.MoveToContent(); try { if (reader.Name.Equals("diagram")) { while (reader.Read()) { if (reader.Name.Equals("relation")) { Boolean flag = true; reader.MoveToFirstAttribute(); id = reader.Value; reader.MoveToNextAttribute(); StartPointX = Int32.Parse(reader.Value); reader.MoveToNextAttribute(); StartPointY = Int32.Parse(reader.Value); reader.MoveToNextAttribute(); EndPointX = Int32.Parse(reader.Value); reader.MoveToNextAttribute(); EndPointY = Int32.Parse(reader.Value); reader.MoveToNextAttribute(); startVertex = reader.Value; reader.MoveToNextAttribute(); endVertex = reader.Value; reader.MoveToNextAttribute(); tipe = reader.Value; reader.MoveToElement(); while (reader.Read() && flag) { reader.MoveToContent(); flag = true; if (reader.Name.Equals("nama")) { nama = reader.Value; } else if (reader.Name.Equals("jenisRelasiAsal")) { jenisRelasiAsal = reader.Value; } else if (reader.Name.Equals("jenisRelasiTujuan")) { jenisRelasiTujuan = reader.Value; } else if (reader.Name.Equals("relation")) { flag = false; } } if (id != null && tipe.Equals("Dependency")) { Console.WriteLine("StartVertex: " + startVertex); Console.WriteLine("EndVertex: " + endVertex); Point start = new Point(StartPointX, StartPointY); Point end = new Point(EndPointX, EndPointY); Console.WriteLine("Dependency : " + id); DependencyLine tempLine = new DependencyLine(start, end); tempLine.ID = new Guid(id); tempLine.idStartVertex = startVertex; tempLine.idEndVertex = endVertex; tempLine.relationStart = jenisRelasiAsal; tempLine.relationEnd = jenisRelasiTujuan; DrawingObject.Add(tempLine); } } } } } catch (Exception ex) { Console.WriteLine("Error Unserialize Association: " + ex); } reader.Close(); return(DrawingObject); }
public int ParseConfig(int lVariant = 0, bool bDeep = false) { // // Consume XML to create the XLator object. // if bDeep is false, then ONLY do this object. // if bDeep is true, then also do recursive objects. XmlTextReader reader = null; int rc = -1; string connectString = XTRMObject.getDictionaryEntry("TaskConnectString"); Dictionary <String, String> myConfig = new Dictionary <string, string>(XTRMObject.XDictionary); string outerXML; int lElementType = 0; XDictionaryLoader myDictionaryLoader = new XDictionaryLoader(); Dictionary <String, String> elementAttributes; events.Clear(); try { // Load the reader with the data file and ignore all white space nodes. reader = new XmlTextReader(configFile); reader.WhitespaceHandling = WhitespaceHandling.None; // Parse the file and display each of the nodes. bool bResult = reader.Read(); while (bResult) { bool bProcessed = false; switch (reader.NodeType) { case XmlNodeType.Element: string elementName = reader.Name; switch (elementName.ToUpper()) { case "BASECONFIG": outerXML = reader.ReadOuterXml(); myDictionaryLoader = new XDictionaryLoader(); myConfig = myDictionaryLoader.Augment(myConfig, outerXML); bProcessed = true; break; case "WITHCONFIG": outerXML = reader.ReadOuterXml(); myDictionaryLoader.Augment(myConfig, outerXML); bProcessed = true; break; case "EVENTFILTER": outerXML = reader.ReadOuterXml(); XTRMEvent thisFilter = (XTRMEvent)XTRMEvent.consumeXML(myConfig, outerXML, 2, true); eventFilters.Add(thisFilter); bProcessed = true; break; case "EVENT": case "XTRMEVENT": outerXML = reader.ReadOuterXml(); XTRMEvent thisEvent = (XTRMEvent)XTRMEvent.consumeXML(myConfig, outerXML, 1, true); events.Add(thisEvent); bProcessed = true; break; // Add to the current dictionary! case "WORKFLOW": case "XTRMWORKFLOW": outerXML = reader.ReadOuterXml(); XTRMWorkFlow thisFlow = (XTRMWorkFlow)XTRMWorkFlow.consumeXML(myConfig, outerXML, 1, true); workflows.Add(thisFlow); bProcessed = true; break; } if (!bProcessed) { // May wish to get all the attributes here for new elements! elementAttributes = new Dictionary <String, String>(); if (reader.HasAttributes) { reader.MoveToFirstAttribute(); for (int i = 0; i < reader.AttributeCount; i++) { elementAttributes.Add(reader.Name, reader.Value); reader.MoveToNextAttribute(); } if (elementAttributes.ContainsKey("Name")) { // Try to instantiate the XEvent Object! name = elementAttributes["Name"]; } if (elementAttributes.ContainsKey("File")) { // Try to instantiate the XEvent Object! includeFile = elementAttributes["File"]; } reader.MoveToElement(); } // Need to see if we are interested in this element! switch (elementName.ToUpper()) { case "INCLUDE": if (includeFile != null) { IncludeConfig(ResolveText(includeFile, XDictionary), myConfig, lVariant, bDeep); } else { // Include File Ineffective. XLogger(2401, -1, string.Format("XLator::parseConfig(); ConfigFile={0}; Invalid Include.", configFile)); } bResult = reader.Read(); break; case "EVENTFOLDER": lElementType = 1; bResult = reader.Read(); break; case "XTRM": case "XTRMROOT": // Advance into Elements! reader.MoveToContent(); bResult = reader.Read(); break; default: bResult = reader.Read(); break; } } break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: bResult = reader.Read(); break; case XmlNodeType.Comment: bResult = reader.Read(); break; case XmlNodeType.EndElement: bResult = reader.Read(); break; case XmlNodeType.Text: switch (lElementType) { case 1: // EventFolder eventFolders.Add(ResolveText(reader.Value, XDictionary)); break; default: break; } bResult = reader.Read(); break; default: bResult = reader.Read(); break; } } } catch (Exception ex) { exCount_XML++; XLogger(2400, -1, string.Format("XTRMRoot::parseConfig(); ConfigFile={0}; Message={1}", configFile, ex.Message)); } finally { if (reader != null) { reader.Close(); } } return(rc); }
private string GetAttrValue( XmlTextReader xtr, string strName ) { xtr.MoveToFirstAttribute(); do { if( xtr.LocalName.Equals( strName ) ) return xtr.Value; } while( xtr.MoveToNextAttribute() ); return null; }
/// <summary> /// 設定をファイルから読み込む /// </summary> public static void LoadSetting() { if (File.Exists(SettingPath)) { FileStream fs = null; XmlTextReader reader = null; try { fs = new FileStream(SettingPath, FileMode.Open, FileAccess.Read); reader = new XmlTextReader(fs); ArrayList alStation = new ArrayList(); // StationListタグの中にいるか bool inStationListFlag = false; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName == "StationList") { inStationListFlag = true; } // End of StationList // StationListタグの中にいる場合 else if (inStationListFlag == true) { if (reader.LocalName == "Station") { string id = string.Empty; string name = string.Empty; StationKinds stationKind = StationKinds.Netladio; if (reader.MoveToFirstAttribute()) { id = reader.GetAttribute("id"); name = reader.GetAttribute("name"); string kind = reader.GetAttribute("kind"); if (kind == StationKinds.Netladio.ToString()) { stationKind = StationKinds.Netladio; } else if (kind == StationKinds.RssPodcast.ToString()) { stationKind = StationKinds.RssPodcast; } else if (kind == StationKinds.ShoutCast.ToString()) { stationKind = StationKinds.ShoutCast; } else if (kind == StationKinds.Icecast.ToString()) { stationKind = StationKinds.Icecast; } else { // ここに到達することはあり得ない Trace.Assert(false, "想定外の動作のため、終了します"); } alStation.Add(new Station(id, name, stationKind)); } } // End of Station } // End of StationListタグの中にいる場合 else if (reader.LocalName == "FilterEnable") { string enable; enable = reader.GetAttribute("enable"); if (enable == bool.TrueString) { FilterEnable = true; } else if (enable == bool.FalseString) { FilterEnable = false; } } // End of FilterEnable else if (reader.LocalName.Equals("HeadlineTimer")) { if (reader.MoveToFirstAttribute()) { string check = reader.GetAttribute("check"); if (check == bool.TrueString) { HeadlineTimerCheck = true; } else if (check == bool.FalseString) { HeadlineTimerCheck = false; } try { HeadlineTimerMillSecond = Convert.ToInt32(reader.GetAttribute("millsecond")); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } } } // End of HeadlineTimer else if (reader.LocalName == "MediaPlayerPath") { MediaPlayerPath = reader.GetAttribute("path"); } // End of MediaPlayerPath else if (reader.LocalName == "BrowserPath") { BrowserPath = reader.GetAttribute("path"); } // End of BrowserPath else if (reader.LocalName == "PlayListSave") { string save; save = reader.GetAttribute("save"); if (save == bool.TrueString) { PlayListSave = true; } else if (save == bool.FalseString) { PlayListSave = false; } } // End of PlayListSave else if (reader.LocalName.Equals("HeadlineListBoxFont")) { if (reader.MoveToFirstAttribute()) { string check = reader.GetAttribute("change"); if (check == bool.TrueString) { HeadlineListBoxFontSizeChange = true; } else if (check == bool.FalseString) { HeadlineListBoxFontSizeChange = false; } try { HeadlineListBoxFontSize = Convert.ToInt32(reader.GetAttribute("size")); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } } } // End of HeadlineListBoxFont else if (reader.LocalName == "Proxy") { if (reader.MoveToFirstAttribute()) { string use = reader.GetAttribute("use"); if (use == ProxyConnect.Unuse.ToString()) { ProxyUse = ProxyConnect.Unuse; } else if (use == ProxyConnect.OsSetting.ToString()) { ProxyUse = ProxyConnect.OsSetting; } else if (use == ProxyConnect.OriginalSetting.ToString()) { ProxyUse = ProxyConnect.OriginalSetting; } ProxyServer = reader.GetAttribute("server"); try { string port = reader.GetAttribute("port"); ProxyPort = int.Parse(port); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } } } // End of Proxy } else if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName == "StationList") { inStationListFlag = false; StationList.SetStationList((Station[])alStation.ToArray(typeof(Station))); } } } } finally { reader.Close(); fs.Close(); } } }