diff options
author | Jeremie Laval <jeremie.laval@gmail.com> | 2012-03-05 20:34:31 +0400 |
---|---|---|
committer | Jeremie Laval <jeremie.laval@gmail.com> | 2012-03-05 21:33:29 +0400 |
commit | dc2de7cd0948d1b7e026dc26d4c23a32b570b03e (patch) | |
tree | 55def669f854109a5b4cff9dbec757bd89931999 /AppleDocWizard | |
parent | 5feb94b335f30ab32bf94da91533e878a7c1a7c3 (diff) |
[appledocwizard] Report error occuring during processing
Diffstat (limited to 'AppleDocWizard')
-rw-r--r-- | AppleDocWizard/AppleDocWizardController.cs | 16 | ||||
-rw-r--r-- | AppleDocWizard/MDocArchive.cs | 97 |
2 files changed, 110 insertions, 3 deletions
diff --git a/AppleDocWizard/AppleDocWizardController.cs b/AppleDocWizard/AppleDocWizardController.cs index 53150ba..e1d47d7 100644 --- a/AppleDocWizard/AppleDocWizardController.cs +++ b/AppleDocWizard/AppleDocWizardController.cs @@ -13,7 +13,8 @@ namespace macdoc enum FinishState { NothingToDo, Processed, - Canceled + Canceled, + Error } CancellationTokenSource source = new CancellationTokenSource (); @@ -54,7 +55,12 @@ namespace macdoc handler.AdvertiseEarlyFinish (); ShowAlert (FinishState.NothingToDo); } - }); + }).ContinueWith (t => { + Console.WriteLine ("Exception occured during doc process"); + Console.WriteLine (); + Console.WriteLine (t.Exception.ToString ()); + ShowAlert (FinishState.Error); + }, TaskContinuationOptions.OnlyOnFaulted); } void ShowAlert (FinishState finishState) @@ -72,7 +78,11 @@ namespace macdoc break; case FinishState.Canceled: alert.MessageText = "Canceled"; - alert.MessageText = "The update operation was canceled"; + alert.InformativeText = "The update operation was canceled"; + break; + case FinishState.Error: + alert.MessageText = "An error occured"; + alert.InformativeText = "A fatal error occured during one of the documentation installer step"; break; } diff --git a/AppleDocWizard/MDocArchive.cs b/AppleDocWizard/MDocArchive.cs new file mode 100644 index 0000000..23fd293 --- /dev/null +++ b/AppleDocWizard/MDocArchive.cs @@ -0,0 +1,97 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Xml; +using Ionic.Zip; + +namespace macdoc +{ + public interface IMonodocArchive + { + string GetPathForType (Type t); + } + + // This is an uncompiled 'en' directory of ECMA documentation + public class DirectoryDocArchive : IMonodocArchive + { + string baseDir; + + public DirectoryDocArchive (string baseDir) + { + this.baseDir = baseDir; + } + + public string GetPathForType (Type t) + { + + } + } + + // This represent a .zip archive of a ECMA API doc set + public class EcmaDocArchive : IMonodocArchive + { + string baseDir; + string originalArchivePath; + // Provide a mapping between a type full name (e.g. System.String) and the file name of its documentation (in ecma doc case, a number) + Dictionary<string, string> typeMapping = new Dictionary<string, string> (); + + private EcmaDocArchive (string originalArchivePath, string baseDir) + { + this.baseDir = baseDir; + this.originalArchivePath = originalArchivePath; + BuildTypeMapping (); + } + + void BuildTypeMapping () + { + int id; + foreach (var file in Directory.EnumerateFiles (baseDir)) { + var name = Path.GetFileName (file); + if (!int.TryParse (name, out id)) + continue; + var reader = XmlReader.Create (file); + if (!reader.Read ()) + continue; + if (!reader.MoveToAttribute ("FullName")) + continue; + var typeFullName = reader.ReadContentAsString (); + if (string.IsNullOrEmpty (typeFullName)) + continue; + typeMapping[typeFullName] = id.ToString (); + } + } + + public string GetPathForType (Type t) + { + string path; + bool result = typeMapping.TryGetValue (t.FullName, out path); + return result ? path : null; + } + + public static EcmaDocArchive ExtractAndLoad (string archivePath) + { + if (!File.Exists (archivePath)) + throw new ArgumentException ("Archive file doesn't exists", "archivePath"); + + var extractionDir = Path.Combine (Path.GetTempPath (), Path.GetFileNameWithoutExtension (archivePath)); + if (Directory.Exists (extractionDir)) + Directory.Delete (extractionDir, true); + Directory.CreateDirectory (extractionDir); + using (var zip = ZipFile.Read (archivePath)) + zip.ExtractAll (extractionDir); + + return new EcmaDocArchive (archivePath, extractionDir); + } + + public void SaveBack () + { + File.Copy (originalArchivePath, originalArchivePath + ".origin"); + File.Delete (originalArchivePath); + using (var zip = new ZipArchive (originalArchivePath)) { + zip.AddDirectory (baseDir); + zip.Save (); + } + } + } +} + |