void HandleAppleDocDownloadFinished(System.ComponentModel.AsyncCompletedEventArgs e, AppleDocInformation infos, string path, ManualResetEvent evt, CancellationToken token) { try { if (e.Cancelled || token.IsCancellationRequested) { return; } FireAppleDocEvent(new AppleDocEventArgs() { Stage = ProcessStage.Extracting, CurrentFile = null }); var evtArgs = new AppleDocEventArgs() { Stage = ProcessStage.Extracting }; XarApi.ExtractXar(path, searchPaths.First(), token, (filepath) => { evtArgs.CurrentFile = filepath; FireAppleDocEvent(evtArgs); }); if (token.IsCancellationRequested) { var extractedDocDir = Path.Combine(searchPaths.First(), infos.ID + ".docset"); if (Directory.Exists(extractedDocDir)) { Directory.Delete(extractedDocDir, true); } } } finally { evt.Set(); // Delete the .xar file if (File.Exists(path)) { File.Delete(path); } } }
public void DownloadAppleDocs(AppleDocInformation infos, CancellationToken token) { if (token.IsCancellationRequested) { return; } var tempPath = Path.GetTempFileName(); var evt = new ManualResetEvent(false); var evtArgs = new AppleDocEventArgs() { Stage = ProcessStage.Downloading }; WebClient client = new WebClient(); client.DownloadFileCompleted += (sender, e) => HandleAppleDocDownloadFinished(e, infos, tempPath, evt, token); client.DownloadProgressChanged += (sender, e) => { if (e.ProgressPercentage - evtArgs.Percentage < 1.0) { return; } evtArgs.Percentage = e.ProgressPercentage; FireAppleDocEvent(evtArgs); }; FireAppleDocEvent(new AppleDocEventArgs() { Stage = ProcessStage.Downloading, Percentage = -1 }); client.DownloadFileAsync(new Uri(infos.DownloadUrl), tempPath); token.Register(() => client.CancelAsync()); evt.WaitOne(); }
void HandleAppleDocProgress(object sender, AppleDocEventArgs e) { InvokeOnMainThread(delegate { Window.UpdateProgress(e); }); }
void FireAppleDocEvent(AppleDocEventArgs e) { var temp = AppleDocProgress; if (temp != null) { temp(this, e); } }
public void UpdateProgress (AppleDocEventArgs e) { switch (e.Stage) { case ProcessStage.GettingManifest: currentStage = ProcessStage.GettingManifest; progressIndicator.Indeterminate = true; progressIndicator.StartAnimation (this); stageLabel.StringValue = "Getting Apple Documentation feed"; extraStageInfoLabel.Hidden = true; break; case ProcessStage.Downloading: if (currentStage == ProcessStage.Downloading) progressIndicator.DoubleValue = e.Percentage; else { currentStage = ProcessStage.Downloading; progressIndicator.Indeterminate = false; progressIndicator.StartAnimation (this); stageLabel.StringValue = "Downloading Apple documentation"; extraStageInfoLabel.Hidden = true; } break; case ProcessStage.Extracting: if (currentStage == ProcessStage.Extracting) extraStageInfoLabel.StringValue = e.CurrentFile; else { currentStage = ProcessStage.Extracting; progressIndicator.Indeterminate = true; progressIndicator.StartAnimation (this); stageLabel.StringValue = "Extracting Apple documentation"; extraStageInfoLabel.Hidden = false; } break; case ProcessStage.Merging: if (currentStage == ProcessStage.Merging) extraStageInfoLabel.StringValue = e.CurrentFile; else { currentStage = ProcessStage.Merging; stageLabel.StringValue = "Merging MonoTouch documentation with Apple documentation"; progressIndicator.Indeterminate = true; progressIndicator.StartAnimation (this); extraStageInfoLabel.Hidden = false; extraStageInfoLabel.StringValue = "Preparing merge"; } break; case ProcessStage.Finished: currentStage = ProcessStage.Finished; stageLabel.StringValue = "Operation(s) ran successfully"; progressIndicator.Hidden = true; extraStageInfoLabel.Hidden = true; break; default: break; } }
public void LaunchMergeProcess(AppleDocInformation infos, string resourcePath, CancellationToken token) { if (token.IsCancellationRequested) { return; } var evtArgs = new AppleDocEventArgs() { Stage = ProcessStage.Merging }; FireAppleDocEvent(evtArgs); var mdocArchive = MDocZipArchive.ExtractAndLoad(Path.Combine(MonodocLibPath, "MonoTouch-lib.zip")); var merger = new AppleDocMerger(new AppleDocMerger.Options() { DocBase = Path.Combine(searchPaths.First(), infos.ID + ".docset", "Contents/Resources/Documents/documentation"), Assembly = Mono.Cecil.AssemblyDefinition.ReadAssembly(MonoTouchLibPath), BaseAssemblyNamespace = "MonoTouch", ImportSamples = true, MonodocArchive = mdocArchive, SamplesRepositoryPath = Path.Combine(resourcePath, "samples.zip"), MergingPathCallback = path => { evtArgs.CurrentFile = path; FireAppleDocEvent(evtArgs); }, CancellationToken = token }); merger.MergeDocumentation(); if (!token.IsCancellationRequested) { mdocArchive.CommitChanges(); var statusDirectory = Path.Combine(baseApplicationPath, "macdoc"); if (!Directory.Exists(statusDirectory)) { Directory.CreateDirectory(statusDirectory); } var statusFile = Path.Combine(statusDirectory, "merge.status"); File.WriteAllText(statusFile, infos.Version.ToString()); } FireAppleDocEvent(new AppleDocEventArgs() { Stage = ProcessStage.Finished }); }
void FireAppleDocEvent (AppleDocEventArgs e) { var temp = AppleDocProgress; if (temp != null) temp (this, e); }
public void LaunchMergeProcess (AppleDocInformation infos, string resourcePath, CancellationToken token) { // TODO: take token into account inside merging if (token.IsCancellationRequested) return; var evtArgs = new AppleDocEventArgs () { Stage = ProcessStage.Merging }; FireAppleDocEvent (evtArgs); var merger = new AppleDocMerger (new AppleDocMerger.Options () { DocBase = Path.Combine (searchPaths.First (), infos.ID + ".docset", "Contents/Resources/Documents/documentation"), Assembly = System.Reflection.Assembly.ReflectionOnlyLoadFrom (MonoTouchLibPath), BaseAssemblyNamespace = "MonoTouch", ImportSamples = true, //SamplesRepositoryPath = Path.Combine (resourcePath, "samples.zip"), MonoDocBaseDir = Path.Combine (MonodocLibPath, "en"), SamplesRepositoryPath = Path.Combine (MonodocLibPath, "samples.zip"), MergingPathCallback = path => { evtArgs.CurrentFile = path; FireAppleDocEvent (evtArgs); } }); merger.MergeDocumentation (); var statusFile = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), "macdoc", "merge.status"); File.WriteAllText (statusFile, infos.Version.ToString ()); FireAppleDocEvent (new AppleDocEventArgs () { Stage = ProcessStage.Finished }); }
void HandleAppleDocDownloadFinished (System.ComponentModel.AsyncCompletedEventArgs e, string path, ManualResetEvent evt, CancellationToken token) { try { if (e.Cancelled || token.IsCancellationRequested) { return; } FireAppleDocEvent (new AppleDocEventArgs () { Stage = ProcessStage.Extracting, CurrentFile = null }); var evtArgs = new AppleDocEventArgs () { Stage = ProcessStage.Extracting }; XarApi.ExtractXar (path, searchPaths.First (), token, (filepath) => { evtArgs.CurrentFile = filepath; FireAppleDocEvent (evtArgs); }); } finally { evt.Set (); } }
public void DownloadAppleDocs (AppleDocInformation infos, CancellationToken token) { if (token.IsCancellationRequested) return; var tempPath = Path.GetTempFileName (); var evt = new ManualResetEvent (false); var evtArgs = new AppleDocEventArgs () { Stage = ProcessStage.Downloading }; WebClient client = new WebClient (); client.DownloadFileCompleted += (sender, e) => HandleAppleDocDownloadFinished (e, tempPath, evt, token); client.DownloadProgressChanged += (sender, e) => { evtArgs.Percentage = e.ProgressPercentage; FireAppleDocEvent (evtArgs); }; FireAppleDocEvent (new AppleDocEventArgs () { Stage = ProcessStage.Downloading, Percentage = -1 }); client.DownloadFileAsync (new Uri (infos.DownloadUrl), tempPath); token.Register (() => client.CancelAsync ()); evt.WaitOne (); }
public void LaunchMergeProcess (AppleDocInformation infos, string resourcePath, CancellationToken token) { if (token.IsCancellationRequested) return; var evtArgs = new AppleDocEventArgs () { Stage = ProcessStage.Merging }; FireAppleDocEvent (evtArgs); var mdocArchive = MDocZipArchive.ExtractAndLoad (Path.Combine (MonodocLibPath, "MonoTouch-lib.zip")); var merger = new AppleDocMerger (new AppleDocMerger.Options () { DocBase = Path.Combine (searchPaths.First (), infos.ID + ".docset", "Contents/Resources/Documents/documentation"), Assembly = Mono.Cecil.AssemblyDefinition.ReadAssembly (MonoTouchLibPath), BaseAssemblyNamespace = "MonoTouch", ImportSamples = true, MonodocArchive = mdocArchive, SamplesRepositoryPath = Path.Combine (resourcePath, "samples.zip"), MergingPathCallback = path => { evtArgs.CurrentFile = path; FireAppleDocEvent (evtArgs); }, CancellationToken = token }); merger.MergeDocumentation (); if (!token.IsCancellationRequested) { mdocArchive.CommitChanges (); var statusDirectory = Path.Combine (baseApplicationPath, "macdoc"); if (!Directory.Exists (statusDirectory)) Directory.CreateDirectory (statusDirectory); var statusFile = Path.Combine (statusDirectory, "merge.status"); File.WriteAllText (statusFile, infos.Version.ToString ()); } FireAppleDocEvent (new AppleDocEventArgs () { Stage = ProcessStage.Finished }); }
void HandleAppleDocDownloadFinished (System.ComponentModel.AsyncCompletedEventArgs e, AppleDocInformation infos, string path, ManualResetEvent evt, CancellationToken token) { try { if (e.Cancelled || token.IsCancellationRequested) { return; } FireAppleDocEvent (new AppleDocEventArgs () { Stage = ProcessStage.Extracting, CurrentFile = null }); var evtArgs = new AppleDocEventArgs () { Stage = ProcessStage.Extracting }; XarApi.ExtractXar (path, searchPaths.First (), token, (filepath) => { evtArgs.CurrentFile = filepath; FireAppleDocEvent (evtArgs); }); if (token.IsCancellationRequested) { var extractedDocDir = Path.Combine (searchPaths.First (), infos.ID + ".docset"); if (Directory.Exists (extractedDocDir)) Directory.Delete (extractedDocDir, true); } } finally { evt.Set (); // Delete the .xar file if (File.Exists (path)) File.Delete (path); } }
public void UpdateProgress(AppleDocEventArgs e) { switch (e.Stage) { case ProcessStage.GettingManifest: currentStage = ProcessStage.GettingManifest; progressIndicator.Indeterminate = true; progressIndicator.StartAnimation(this); stageLabel.StringValue = "Getting Apple Documentation feed"; extraStageInfoLabel.Hidden = true; break; case ProcessStage.Downloading: if (currentStage == ProcessStage.Downloading) { progressIndicator.DoubleValue = e.Percentage; extraStageInfoLabel.StringValue = e.Percentage + " %"; } else { currentStage = ProcessStage.Downloading; progressIndicator.Indeterminate = false; progressIndicator.StartAnimation(this); stageLabel.StringValue = "Downloading Apple documentation"; extraStageInfoLabel.Hidden = false; } break; case ProcessStage.Extracting: if (currentStage == ProcessStage.Extracting) { extraStageInfoLabel.StringValue = e.CurrentFile ?? "(none)"; } else { currentStage = ProcessStage.Extracting; progressIndicator.Indeterminate = true; progressIndicator.StartAnimation(this); stageLabel.StringValue = "Extracting Apple documentation"; extraStageInfoLabel.Hidden = false; extraStageInfoLabel.StringValue = string.Empty; } break; case ProcessStage.Merging: if (currentStage == ProcessStage.Merging) { extraStageInfoLabel.StringValue = e.CurrentFile; } else { currentStage = ProcessStage.Merging; stageLabel.StringValue = "Merging MonoTouch documentation with Apple documentation"; progressIndicator.Indeterminate = true; progressIndicator.StartAnimation(this); extraStageInfoLabel.Hidden = false; extraStageInfoLabel.StringValue = "Preparing merge"; } break; case ProcessStage.Finished: currentStage = ProcessStage.Finished; progressIndicator.StopAnimation(this); break; default: break; } }
void HandleAppleDocProgress (object sender, AppleDocEventArgs e) { InvokeOnMainThread (delegate { Window.UpdateProgress (e); }); }