Exemple #1
0
        internal AufsImpl(MergedVolumeInfo volumeInfo)
        {
            if (volumeInfo == null)
            {
                throw new ArgumentNullException("volumeInfo");
            }

            this.volumeInfo = volumeInfo;
            this.members = volumeInfo.Members;
            this.policy = volumeInfo.Policy;
        }
 private void readConfiguration()
 {
     bool isValid = true;
     XmlReaderSettings settings = new XmlReaderSettings();
     using (StreamReader schemaReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(this.GetType(), "configschema.xsd"))) // load the schema embedded resource to validate the user's config file
     {
         settings.Schemas.Add(null, XmlReader.Create(schemaReader));
         settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
         settings.ValidationType = ValidationType.Schema;
         settings.ValidationEventHandler += (sender, e) => // if there's any validation events (errors), then the configuration file is invalid
         {
             Console.Error.WriteLine(e.Message);
             isValid = false;
         };
         using (XmlReader reader = XmlReader.Create(this.configPath, settings))
         {
             XmlDocument configDoc = new XmlDocument();
             configDoc.Load(reader);
             if (!isValid)
             {
                 throw new InvalidDataException("Configuration file format is invalid");
             }
             List<Member> members = new List<Member>();
             foreach (XmlNode memberNode in configDoc.SelectNodes("//aufsconfig/members/member"))
             {
                 string path = memberNode.Attributes["path"].Value;
                 bool readOnly = false;
                 if (memberNode.Attributes["readonly"] != null)
                 {
                     readOnly = Convert.ToBoolean(memberNode.Attributes["readonly"].Value);
                 }
                 members.Add(new Member(path, readOnly));
             }
             CreationPolicy policy = PolicyLoader.GetPolicy(configDoc.SelectSingleNode("//aufsconfig/volume").Attributes["policy"].Value, members);
             string driveLetter = configDoc.SelectSingleNode("//aufsconfig/volume/letter").InnerText;
             string driveLabel = configDoc.SelectSingleNode("//aufsconfig/volume/label").InnerText;
             this.mergedVolume = new MergedVolumeInfo(members, driveLetter.ToCharArray()[0], driveLabel, policy);
         }
     }
 }