/// <summary> /// Open zip package that contains course's files /// </summary> /// <param name="fileName">If course is opened return true</param> public static bool OpenZipPackage([NotNull] string fileName) { FFDebug.EnterMethod(Cattegory.Course, string.Format("fileName:'{0}'", fileName)); var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Zipper.ExtractZipFile(fileName, path); bool res = Open(path); if (res) { var lc = Settings.Default.LastCoursesXml; if (!lc.Contains(fileName)) { lc.Add(fileName); if (lc.Count > 9) { lc.RemoveAt(0); } Settings.Default.LastCoursesXml = lc; } } FFDebug.LeaveMethod(Cattegory.Course, MethodBase.GetCurrentMethod()); return(res); }
/// <summary> /// Creates new course and opens it. /// </summary> public static void CreateNew() { FFDebug.EnterMethod(Cattegory.Course, State.ToString()); if ((State & CourseStates.Opened) > 0 && !Close()) { return; } __FullPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(__FullPath); __Manifest = new ManifestType("New Course") { version = CourseUpgradeManager.LastVersion }; __Manifest.ResolveTree(__Manifest); __Organization = __Manifest.organizations.Organizations[0]; __Manifest.organizations.@default = __Organization.identifier; Answers = new Answers(); Save(); if (Open(__FullPath)) { State = CourseStates.Opened; } FFDebug.LeaveMethod(Cattegory.Course, MethodBase.GetCurrentMethod()); }
///<summary> /// Parses html file as sub-tree of this control ///</summary> ///<param name="htmlFilePath">Path to file should be parsed</param> ///<param name="onControlParsed">Delegate should be invoked for all control after parsing</param> public void ParseHtmlFile([NotNull] string htmlFilePath, [NotNull] Action <HtmlControl, HtmlControl> onControlParsed) { FFDebug.EnterMethod(Cattegory.HtmlControl, string.Format("HtmlFile:'{0}'", htmlFilePath)); using (var f = new StreamReader(htmlFilePath)) { ParseStream(f, onControlParsed); } FFDebug.LeaveMethod(Cattegory.HtmlControl, MethodBase.GetCurrentMethod()); }
///<summary> /// ///</summary> ///<param name="source">Instance of <see cref="Stream"/> content of which should be parsed</param> ///<param name="onControlParsed">Delegate should be invoked for all control after parsing</param> public void ParseStream([NotNull] TextReader source, [NotNull] Action <HtmlControl, HtmlControl> onControlParsed) { FFDebug.EnterMethod(Cattegory.HtmlControl, "Parsing stream"); var doc = new XmlDocument(); doc.Load(source); Debug.Assert(doc.DocumentElement != null); Parse(doc.DocumentElement, onControlParsed); OnParsed(); ReValidate(); FFDebug.LeaveMethod(Cattegory.HtmlControl, "Parsing stream"); }
/// <summary> /// Save all changes of current course to folder that represents is /// </summary> public static bool Save() { FFDebug.EnterMethod(Cattegory.Course, State.ToString()); State |= CourseStates.Saving; #if CHECKERS if (__Manifest == null) { throw new FireFlyException("Course is not assigned"); } if (__Manifest.organizations.Organizations.Count == 0) { throw new FireFlyException("No organization assigned"); } #endif if (CourseSaving != null) { CourseSaving(); } HtmlPageBase.StorePages(); State &= ~CourseStates.Saving; var cv = new CourseValidator(); if (!cv.Validate()) { ErrorDialog.ShowError("THIS COURSE IS INVALID!!! It cannot be played. Errors:" + Environment.NewLine + cv.GetErrorMessages()); State &= ~CourseStates.Modified; return(false); } using (var f = new FileStream(MapPath(MANIFEST_FILE_NAME), FileMode.Create)) { ManifestType.Serializer.Serialize(f, __Manifest, ManifestNamespaces.SerializerNamespaces); } Answers.SaveToFile(MapPath(ANSWERS_FILE_NAME)); State &= ~CourseStates.Modified; if (CourseSaved != null) { CourseSaved(); } FFDebug.LeaveMethod(Cattegory.Course, MethodBase.GetCurrentMethod()); return(true); }
/// <summary> /// Save current course to zip package /// </summary> /// <param name="fileName">File name of zip package. If file not exists it will be created</param> public static bool SaveToZipPackage([NotNull] string fileName) { FFDebug.EnterMethod(Cattegory.Course, string.Format("fileName:'{0}'", fileName)); if (Save() != true) { return(false); } Zipper.CreateZip(fileName, __FullPath); var lc = Settings.Default.LastCoursesXml; if (!lc.Contains(fileName)) { lc.Add(fileName); if (lc.Count > 9) { lc.RemoveAt(0); } Settings.Default.LastCoursesXml = lc; } FFDebug.LeaveMethod(Cattegory.Course, MethodBase.GetCurrentMethod()); return(true); }
/// <summary> /// Open course represented as folder. /// </summary> /// <param name="courseFileName">Path to directory contains the course's files</param> /// <returns>If this course was opened return true</returns> public static bool Open([NotNull] string courseFileName) { #if DEBUG try { FFDebug.EnterMethod(Cattegory.Course, string.Format("Path:{0}", courseFileName)); #endif if ((State & CourseStates.Opened) > 0 && !Close()) { return(false); } State |= CourseStates.Opening; __FullPath = courseFileName; __Manifest = null; __Organization = null; __ContainedFileResource.Clear(); string manifestFile = MapPath(MANIFEST_FILE_NAME); if (!File.Exists(manifestFile)) { ErrorDialog.ShowError("File you are trying to open is not a FireFly-compatible course. If you are sure it has been create using FireFly Course Editor, please send it to support of the Editor", courseFileName); return(false); } else { using (var f = new FileStream(manifestFile, FileMode.Open)) { #if LOGGER using (Logger.Scope("Deserializing manifest")) { #endif __Manifest = (ManifestType)ManifestType.Serializer.Deserialize(f); #if LOGGER } using (Logger.Scope("Resolving tree")) { #endif __Manifest.ResolveTree(__Manifest); #if LOGGER } #endif } __Organization = __Manifest.organizations.Organizations[0]; Answers = CourseEditor.Course.Answers.FromFile(MapPath(ANSWERS_FILE_NAME)); if (__Manifest.version > CourseUpgradeManager.LastVersion) { State = CourseStates.OpenFailed; Close(); State = CourseStates.None; ErrorDialog.ShowError ("Cannot open course because it was created by highest version of FireFly Course Editor than this one. Please, update program"); } State = CourseStates.Opened; string updRes; if (CourseUpgradeManager.UpgradeCourse(out updRes)) { if (CourseOpened != null) { CourseOpened(); } return(true); } else { State = CourseStates.UpgradeFailed; Close(); State = CourseStates.None; ErrorDialog.ShowError ("Failed to convert course to actual version. Please sent it to our support." + Environment.NewLine + "Upgrading details: " + Environment.NewLine + updRes); return(false); } } #if DEBUG } finally { FFDebug.LeaveMethod(Cattegory.Course, MethodBase.GetCurrentMethod()); } #endif }