public object Clone() { AdaptationProfile ap = (AdaptationProfile)this.MemberwiseClone(); ap.flags = new List <string>(); foreach (string s in flags) { ap.flags.Add((s != null ? s : null)); } ap.initialState = (AdaptedState)initialState.Clone(); ap.name = (name != null ? name : null); ap.rules = new List <AdaptationRule>(); foreach (AdaptationRule ar in rules) { ap.rules.Add((AdaptationRule)ar.Clone()); } ap.vars = new List <string>(); foreach (string s in vars) { ap.vars.Add((s != null ? s : null)); } ap.scorm12 = scorm12; ap.scorm2004 = scorm2004; return(ap); }
/** * Load the assessment and adaptation profiles from xml. * */ //This method must be called after all chapter data is parse, because is a past functionality, and must be preserved in order // to bring the possibility to load game of past versions. Now the adaptation and assessment profiles are into chapter.xml, and not // in separate files. public void loadProfiles() { //check if in chapter.xml there was any assessment or adaptation data if (!adventureData.hasAdapOrAssesData()) { // Load all the assessment files in each chapter foreach (string assessmentPath in assessmentPaths) { bool added = false; AssessmentProfile assessProfile = Loader.loadAssessmentProfile(isCreator, assessmentPath, incidences); if (assessProfile != null) { foreach (Chapter chapter in adventureData.getChapters()) { if (chapter.getAssessmentName().Equals(assessProfile.getName())) { chapter.addAssessmentProfile(assessProfile); added = true; } } if (!added) { foreach (Chapter chapter in adventureData.getChapters()) { chapter.addAssessmentProfile(assessProfile); } } } } // Load all the adaptation files in each chapter foreach (string adaptationPath in adaptationPaths) { bool added = false; AdaptationProfile adaptProfile = Loader.loadAdaptationProfile(isCreator, adaptationPath, incidences); if (adaptProfile != null) { foreach (Chapter chapter in adventureData.getChapters()) { if (chapter.getAdaptationName().Equals(adaptProfile.getName())) { chapter.addAdaptationProfile(adaptProfile); added = true; } } if (!added) { foreach (Chapter chapter in adventureData.getChapters()) { chapter.addAdaptationProfile(adaptProfile); } } } } } }
public static XmlElement writeAdaptationData(AdaptationProfile profile, bool valid, XmlDocument doc) { /** * ******************* STORE ASSESSMENT DATA WHEN PRESENT * ****************** */ XmlElement adpNode = null; // take the name of the profile string name = profile.getName(); if (name != null && !profile.getName().Equals("") /*&& new File(zipFilename, controller.getPath( )).exists()*/) { List <AdaptationRule> rules = profile.getRules(); AdaptedState initialState = profile.getInitialState(); // check if it is an scorm profile bool scorm2004 = profile.isScorm2004(); bool scorm12 = profile.isScorm12(); adpNode = AdaptationDOMWriter.buildDOM(rules, initialState, scorm12, scorm2004, name, doc); } return(adpNode); }
/** * Default constructor */ public AdaptationSubParser(Chapter chapter) : base(chapter) { profile = new AdaptationProfile(); currentstring = string.Empty; }
/** * Adds new adaptation profile * * @param adaptProfile * the new assessment profile to add */ public void addAdaptationProfile(AdaptationProfile adaptProfile) { adaptationProfiles.Add(adaptProfile); }
/** * Loads the adaptation profile (set of adaptation rules + initial state) * stored in file with path xmlFile in zipFile * * @param zipFile * @param xmlFile * @param incidences * @return */ public static AdaptationProfile loadAdaptationProfile(InputStreamCreator isCreator, string xmlFile, List<Incidence> incidences) { AdaptationProfile newProfile = null; if (Loader.adventureData != null) { foreach (Chapter chapter in Loader.adventureData.getChapters()) { if (chapter.getAssessmentProfiles().Count != 0) { foreach (AdaptationProfile profile in chapter.getAdaptationProfiles()) if (profile.getName().Equals(xmlFile)) { newProfile = profile; break; } } } } else { // Open the file and load the data try { // Set the chapter handler List<AdaptationRule> rules = new List<AdaptationRule>(); AdaptedState initialState = new AdaptedState(); AdaptationHandler adpParser = new AdaptationHandler(isCreator, rules, initialState); //factory.setValidating(true); //SAXParser saxParser = factory.newSAXParser(); // Parse the data and close the data string adaptationIS = isCreator.buildInputStream(xmlFile); //saxParser.parse(adaptationIS, adpParser); //adaptationIS.close(); adpParser.Parse(adaptationIS); // Finally add the new controller to the list // Create the new profile string name = xmlFile; name = name.Substring(name.IndexOf("/") + 1); name = name.Substring(0, name.IndexOf(".")); newProfile = new AdaptationProfile(adpParser.getAdaptationRules(), adpParser.getInitialState(), name, adpParser.isScorm12(), adpParser.isScorm2004()); newProfile.setFlags(adpParser.getFlags()); newProfile.setVars(adpParser.getVars()); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.SAX"), xmlFile, e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.SAX"), xmlFile, e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.IO"), xmlFile, e)); //} } return newProfile; }
/** * Loads the adaptation profile (set of adaptation rules + initial state) * stored in file with path xmlFile in zipFile * * @param zipFile * @param xmlFile * @param incidences * @return */ public static AdaptationProfile loadAdaptationProfile(InputStreamCreator isCreator, string xmlFile, List <Incidence> incidences) { AdaptationProfile newProfile = null; if (Loader.adventureData != null) { foreach (Chapter chapter in Loader.adventureData.getChapters()) { if (chapter.getAssessmentProfiles().Count != 0) { foreach (AdaptationProfile profile in chapter.getAdaptationProfiles()) { if (profile.getName().Equals(xmlFile)) { newProfile = profile; break; } } } } } else { // Open the file and load the data try { // Set the chapter handler List <AdaptationRule> rules = new List <AdaptationRule>(); AdaptedState initialState = new AdaptedState(); AdaptationHandler adpParser = new AdaptationHandler(isCreator, rules, initialState); //factory.setValidating(true); //SAXParser saxParser = factory.newSAXParser(); // Parse the data and close the data string adaptationIS = isCreator.buildInputStream(xmlFile); //saxParser.parse(adaptationIS, adpParser); //adaptationIS.close(); adpParser.Parse(adaptationIS); // Finally add the new controller to the list // Create the new profile string name = xmlFile; name = name.Substring(name.IndexOf("/") + 1); name = name.Substring(0, name.IndexOf(".")); newProfile = new AdaptationProfile(adpParser.getAdaptationRules(), adpParser.getInitialState(), name, adpParser.isScorm12(), adpParser.isScorm2004()); newProfile.setFlags(adpParser.getFlags()); newProfile.setVars(adpParser.getVars()); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.SAX"), xmlFile, e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.SAX"), xmlFile, e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.IO"), xmlFile, e)); //} } return(newProfile); }
public AdaptationSubParser_(Chapter chapter) : base(chapter) { profile = new AdaptationProfile(); }