Exemple #1
0
        public bool CheckMergedDocumentationFreshness(AppleDocInformation infos, Product product)
        {
            var statusFile = Path.Combine(baseApplicationPath, "macdoc");

            if (!Directory.Exists(statusFile))
            {
                try {
                    Directory.CreateDirectory(statusFile);
                } catch {}
                return(true);
            }
            statusFile = Path.Combine(statusFile, product == Product.MonoMac ? "merge.mac.status" : "merge.status");
            if (!File.Exists(statusFile))
            {
                return(true);
            }
            if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPLEDOCWIZARD_FORCE_MERGE")))
            {
                return(true);
            }

            var mergedVersion = CloneFillWithZeros(new Version(File.ReadAllText(statusFile)));

            Logger.Log("Comparing merged {0} with downloaded {1}", mergedVersion.ToString(), infos.Version.ToString());
            return(mergedVersion != infos.Version);
        }
Exemple #2
0
        public bool CheckMergedDocumentationFreshness(AppleDocInformation infos)
        {
            var statusFile = Path.Combine(baseApplicationPath, "macdoc");

            if (!Directory.Exists(statusFile))
            {
                try {
                    Directory.CreateDirectory(statusFile);
                } catch {}
                return(true);
            }
            statusFile = Path.Combine(statusFile, "merge.status");
            if (!File.Exists(statusFile))
            {
                return(true);
            }
            if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPLEDOCWIZARD_FORCE_MERGE")))
            {
                return(true);
            }

            var mergedVersion = CloneFillWithZeros(new Version(File.ReadAllText(statusFile)));

            return(mergedVersion != infos.Version);
        }
Exemple #3
0
        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();
        }
Exemple #4
0
        // atom feed is one of the Apple documentation feed, iOS and Lion are given in const form above
        // returns true if the documentation was updated, false otherwise. The progressDelegate parameter
        // is given the completion percentage
        public bool CheckAppleDocFreshness(string atomFeed, out AppleDocInformation infos)
        {
            var feed = LoadAppleFeed(atomFeed);

            infos = GetLatestAppleDocInformation(feed);
            var needRefresh = !CheckAppleDocAvailabilityAndFreshness(infos);

            return(needRefresh);
        }
Exemple #5
0
        // atom feed is one of the Apple documentation feed, iOS and Lion are given in const form above
        // returns true if the documentation was updated, false otherwise. The progressDelegate parameter
        // is given the completion percentage
        public bool CheckAppleDocFreshness(string atomFeed, out AppleDocInformation infos)
        {
            FireAppleDocEvent(new AppleDocEventArgs()
            {
                Stage = ProcessStage.GettingManifest
            });
            var feed = LoadAppleFeed(atomFeed);

            infos = GetLatestAppleDocInformation(feed);
            var needRefresh = !CheckAppleDocAvailabilityAndFreshness(infos);

            return(needRefresh);
        }
Exemple #6
0
		// This method transforms the Atom XML data into a POCO for the the most recent item of the feed
		AppleDocInformation GetLatestAppleDocInformation (XDocument feed)
		{
			var latestEntry = feed.Descendants (atomNamespace + "entry").LastOrDefault ();
			if (latestEntry == null)
				return null;
			
			var infos = new AppleDocInformation () {
				Version = CloneFillWithZeros (new Version (latestEntry.Element (docsetNamespace + "version").Value)),
				ID = latestEntry.Element (docsetNamespace + "identifier").Value,
				UpdateDate = DateTime.Parse (latestEntry.Element (atomNamespace + "updated").Value),
				DownloadUrl = latestEntry.Element (atomNamespace + "link").Attribute ("href").Value
			};

			return infos;
		}
Exemple #7
0
        // This method checks that an iOS documentation set is installed on the user machine
        // and also checks if it's the latest available
        bool CheckAppleDocAvailabilityAndFreshness(AppleDocInformation infos)
        {
            var path = searchPaths
                       .Select(p => Path.Combine(p, infos.ID + ".docset"))
                       .FirstOrDefault(p => Directory.Exists(p));

            if (path == null)
            {
                return(false);
            }

            var installedVersion = GetAppleDocVersion(path);

            return(installedVersion >= infos.Version);
        }
Exemple #8
0
        // This method checks that an iOS documentation set is installed on the user machine
        // and also checks if it's the latest available
        bool CheckAppleDocAvailabilityAndFreshness(AppleDocInformation infos)
        {
            var path = searchPaths
                       .Select(p => Path.Combine(p, infos.ID + ".docset"))
                       .FirstOrDefault(p => Directory.Exists(p));

            if (path == null)
            {
                return(false);
            }

            var installedVersion = GetAppleDocVersion(path);

            Logger.Log("Installed doc version {0}, compared to remote {1}", installedVersion.ToString(), infos.Version.ToString());
            return(installedVersion >= infos.Version);
        }
Exemple #9
0
        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
            });
        }
Exemple #10
0
        // This method transforms the Atom XML data into a POCO for the the most recent item of the feed
        AppleDocInformation GetLatestAppleDocInformation(XDocument feed)
        {
            var latestEntry = feed.Descendants(atomNamespace + "entry").LastOrDefault();

            if (latestEntry == null)
            {
                return(null);
            }

            var infos = new AppleDocInformation()
            {
                Version     = CloneFillWithZeros(new Version(latestEntry.Element(docsetNamespace + "version").Value)),
                ID          = latestEntry.Element(docsetNamespace + "identifier").Value,
                UpdateDate  = DateTime.Parse(latestEntry.Element(atomNamespace + "updated").Value),
                DownloadUrl = latestEntry.Element(atomNamespace + "link").Attribute("href").Value
            };

            return(infos);
        }
Exemple #11
0
		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 ();
		}
Exemple #12
0
		public bool CheckMergedDocumentationFreshness (AppleDocInformation infos)
		{
			var statusFile = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), "macdoc");
			if (!Directory.Exists (statusFile)) {
				Directory.CreateDirectory (statusFile);
				return true;
			}
			statusFile = Path.Combine (statusFile, "merge.status");
			if (!File.Exists (statusFile))
				return true;
			
			var mergedVersion = CloneFillWithZeros (new Version (File.ReadAllText (statusFile)));
			
			return mergedVersion != infos.Version;
		}
Exemple #13
0
		// atom feed is one of the Apple documentation feed, iOS and Lion are given in const form above
		// returns true if the documentation was updated, false otherwise. The progressDelegate parameter
		// is given the completion percentage
		public bool CheckAppleDocFreshness (string atomFeed, out AppleDocInformation infos)
		{
			FireAppleDocEvent (new AppleDocEventArgs () { Stage = ProcessStage.GettingManifest });
			var feed = LoadAppleFeed (atomFeed);
			infos = GetLatestAppleDocInformation (feed);
			var needRefresh = !CheckAppleDocAvailabilityAndFreshness (infos);
			
			return needRefresh;
		}
Exemple #14
0
		// This method checks that an iOS documentation set is installed on the user machine
		// and also checks if it's the latest available
		bool CheckAppleDocAvailabilityAndFreshness (AppleDocInformation infos)
		{
			var path = searchPaths
				.Select (p => Path.Combine (p, infos.ID + ".docset"))
				.FirstOrDefault (p => Directory.Exists (p));

			if (path == null)
				return false;

			var installedVersion = GetAppleDocVersion (path);
			return installedVersion >= infos.Version;
		}
		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 bool CheckMergedDocumentationFreshness (AppleDocInformation infos)
		{
			var statusFile = Path.Combine (baseApplicationPath, "macdoc");
			if (!Directory.Exists (statusFile)) {
				try {
					Directory.CreateDirectory (statusFile);
				} catch {}
				return true;
			}
			statusFile = Path.Combine (statusFile, "merge.status");
			if (!File.Exists (statusFile))
				return true;
			if (!string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("APPLEDOCWIZARD_FORCE_MERGE")))
				return true;
			
			var mergedVersion = CloneFillWithZeros (new Version (File.ReadAllText (statusFile)));
			
			return mergedVersion != infos.Version;
		}
		// atom feed is one of the Apple documentation feed, iOS and Lion are given in const form above
		// returns true if the documentation was updated, false otherwise. The progressDelegate parameter
		// is given the completion percentage
		public bool CheckAppleDocFreshness (string atomFeed, out AppleDocInformation infos)
		{
			Logger.Log ("Downloading Apple feed at {0}", atomFeed);
			var feed = LoadAppleFeed (atomFeed);
			infos = GetLatestAppleDocInformation (feed);
			var needRefresh = !CheckAppleDocAvailabilityAndFreshness (infos);
			
			return needRefresh;
		}
Exemple #19
0
		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 });
		}
		public bool CheckMergedDocumentationFreshness (AppleDocInformation infos, Product product)
		{
			var statusFile = Path.Combine (baseApplicationPath, "macdoc");
			if (!Directory.Exists (statusFile)) {
				try {
					Directory.CreateDirectory (statusFile);
				} catch {}
				return true;
			}
			statusFile = Path.Combine (statusFile, product == Product.MonoMac ? "merge.mac.status" : "merge.status");
			if (!File.Exists (statusFile))
				return true;
			if (!string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("APPLEDOCWIZARD_FORCE_MERGE")))
				return true;
			
			var mergedVersion = CloneFillWithZeros (new Version (File.ReadAllText (statusFile)));
			Logger.Log ("Comparing merged {0} with downloaded {1}", mergedVersion.ToString (), infos.Version.ToString ());
			return mergedVersion != infos.Version;
		}
		// This method checks that an iOS documentation set is installed on the user machine
		// and also checks if it's the latest available
		bool CheckAppleDocAvailabilityAndFreshness (AppleDocInformation infos)
		{
			var path = searchPaths
				.Select (p => Path.Combine (p, infos.ID + ".docset"))
				.FirstOrDefault (p => Directory.Exists (p));

			if (path == null)
				return false;

			var installedVersion = GetAppleDocVersion (path);
			Logger.Log ("Installed doc version {0}, compared to remote {1}", installedVersion.ToString (), infos.Version.ToString ());
			return installedVersion >= infos.Version;
		}
Exemple #22
0
 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 LaunchMergeProcess (AppleDocInformation infos, CancellationToken token)
		{
			// TODO: take token into account inside merging
			if (token.IsCancellationRequested)
				return;
			
			FireAppleDocEvent (new AppleDocEventArgs () { Stage = ProcessStage.Merging });
			DocGenerator.Main (new [] { "--import-samples",  });
			//Thread.Sleep (5000);
			var statusFile = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), "macdoc", "merge.status");
			File.WriteAllText (statusFile, infos.Version.ToString ());
			FireAppleDocEvent (new AppleDocEventArgs () { Stage = ProcessStage.Finished });
		}