public static Settings LoadFromXml( XmlReader xmlReader ) { Settings settings = new Settings(); xmlReader.MoveToAttribute( 0 ); do { switch ( xmlReader.Name.ToLower() ) { case "paddingwidth": { int pw = 0; if ( !int.TryParse( xmlReader.Value, out pw ) ) throw new Exception( "Failed to parse paddingwidth" ); settings.Padding.Width = pw; } break; case "paddingheight": { int ph = 0; if ( !int.TryParse( xmlReader.Value, out ph ) ) throw new Exception( "Failed to parse paddingheight" ); settings.Padding.Height = ph; } break; case "outputwidth": { int ow = 0; if ( !int.TryParse( xmlReader.Value, out ow ) ) throw new Exception( "Failed to parse outputwidth" ); settings.OutputBitmapSize.Width = ow; } break; case "outputheight": { int oh = 0; if ( !int.TryParse( xmlReader.Value, out oh ) ) throw new Exception( "Failed to parse outputheight" ); settings.OutputBitmapSize.Height = oh; } break; case "allowrotation": { bool ar = false; if ( !bool.TryParse( xmlReader.Value, out ar ) ) throw new Exception( "Failed to parse allowrotation" ); settings.AllowRotation = ar; } break; } } while ( xmlReader.MoveToNextAttribute() ); return settings; }
public void MergeSettings( Settings settingsFromXml ) { if ( !AllowRotationForced ) AllowRotation = settingsFromXml.AllowRotation; if ( !PaddingForced ) Padding = settingsFromXml.Padding; if ( !OutputBitmapSizeForced ) OutputBitmapSize = settingsFromXml.OutputBitmapSize; }
public bool VerifySameSettings( Settings otherSettings ) { if ( !Padding.Equals( otherSettings.Padding ) ) return false; if ( !OutputBitmapSize.Equals( otherSettings.OutputBitmapSize ) ) return false; if ( AllowRotation != otherSettings.AllowRotation ) return false; return true; }
InputFileStore( string xmlFile ) { System.IO.FileStream fs = null; XmlTextReader xmlReader = null; CheckXmlFileSignature( xmlFile ); try { fs = new System.IO.FileStream( xmlFile, System.IO.FileMode.Open ); xmlReader = new XmlTextReader( fs ); if ( !xmlReader.ReadToFollowing( "Settings" ) ) throw new Exception( "Settings xml not found" ); mSettings = Settings.LoadFromXml( xmlReader ); if ( !xmlReader.ReadToFollowing( "Image" ) ) return; do { if ( !xmlReader.ReadToFollowing( "SubImage" ) ) return; do { string filename = ""; long lastModified = 0; do { string lowerName = xmlReader.Name.ToLower(); switch ( lowerName ) { case "name": filename = xmlReader.Value; break; case "lastmodified": long.TryParse( xmlReader.Value, out lastModified ); break; } } while ( xmlReader.MoveToNextAttribute() ); if ( filename.Length > 0 && lastModified > 0 ) mModificationTimes.Add( filename, new DateTime( lastModified ) ); } while ( xmlReader.ReadToNextSibling( "SubImage" ) ); } while ( xmlReader.ReadToFollowing( "Image" ) ); } catch ( System.Exception ) { } finally { if ( xmlReader != null ) xmlReader.Close(); if ( fs != null ) fs.Close(); } }