예제 #1
0
		static void CreateSitemap(FileItem files)
		{
			var sm = "";

			foreach (var file in files.GetFiles())
			{
				var s = file.Name.Replace(destPath, "http://www.bltoolkit.net/").Replace("\\", "/");

				if (s == "http://www.bltoolkit.net/index.htm")
					continue;

				sm += string.Format(@"
	<url>
		<loc>{0}</loc>
		<lastmod>{1:yyyy-MM-dd}</lastmod>
		<changefreq>weekly</changefreq>
	</url>",
					s, DateTime.Now);
			}

			using (var sw = File.CreateText(destPath + "sitemap.xml"))
			{
				sw.WriteLine(string.Format(@"<?xml version=""1.0"" encoding=""UTF-8""?>
<urlset xmlns=""http://www.google.com/schemas/sitemap/0.84"">
	<url>
		<loc>http://www.bltoolkit.net/</loc>
		<lastmod>{0:yyyy-MM-dd}</lastmod>
		<changefreq>weekly</changefreq>
	</url>{1}
</urlset>",
					DateTime.Now, sm));
			}
		}
예제 #2
0
		public void Add(FileItem item)
		{
			item.Parent = this;

			if (Items == null)
				Items = new List<FileItem>();

			Items.Add(item);
		}
예제 #3
0
		static void CreateTarget(FileItem root)
		{
			CreateProjectFile(root);
			CreateIndexFile  ();
			CreateContentFile(root);

			var hcc = ProgramFilesx86() + @"\HTML Help Workshop\hhc.exe";

			Process.Start(hcc, destPath + "BLToolkit.hhp").WaitForExit();
			Process.Start(Path.GetFullPath(@"..\..\..\..\Source\Doc\") + "BLToolkit.chm");
		}
예제 #4
0
		static void Main()
		{
			var root = new FileItem();

			new Generator().Generate(
				root,
				_template, new string[] {}, destPath, @"..\..\content", true, false,
				fileName =>
				{
					var name = Path.GetFileName(fileName).ToLower();

					switch (name)
					{
						case "rss.xml"         : return FileAction.Copy;
						case "chmtemplate.html": return FileAction.Skip;
						case "webtemplate.html": return FileAction.Skip;
					}

					var fileAction = FilterFile(fileName);

					if (fileAction != FileAction.Process)
						return fileAction;

					var ext = Path.GetExtension(fileName).ToLower();

					switch (ext)
					{
						case ".cs":
						case ".config":
						case ".xml":
						case ".sql": return FileAction.Skip;
						case ".htm": return FileAction.Process;
						default    : return FileAction.Copy;
					}
				});

			root.Prepare();

			CreateTarget(root);
		}
예제 #5
0
		static void CreateTarget(FileItem files)
		{
			new Generator().Generate(
				new FileItem(),
				_template, new[] { "Source" }, destPath, @"..\..\..\..\", false, true,
				fileName =>
				{
					var name = Path.GetFileName(fileName).ToLower();

					if (name == "assemblyinfo.cs")
						return FileAction.Skip;

					var ext = Path.GetExtension(fileName).ToLower();

					switch (ext)
					{
						case ".cs": return FileAction.Process;
						default   : return FileAction.Skip;
					}
				});

			CreateSitemap(files);
		}
예제 #6
0
		public void Generate(
			FileItem          createdFiles,
			string            templateFileName,
			string[]          path,
			string            destFolder,
			string            sourcePath,
			bool              cleanUp,
			bool              createIndex,
			FileActionHandler fileAction)
		{
			_sourcePath = Path.GetFullPath(sourcePath);
			_destFolder = Path.GetFullPath(destFolder);
			_fileAction = fileAction;

			if (cleanUp)
				CleanUp();

			CreateDestFolder();

			var template = File.ReadAllText(templateFileName);

			GenerateContent(createdFiles, template, path, createIndex);
		}
예제 #7
0
		static void CreateProjectFile(FileItem root)
		{
			using (var sw = File.CreateText(destPath + "BLToolkit.hhp"))
			{
				sw.WriteLine("[FILES]");

				foreach (var file in root.GetFiles())
				{
					var s = file.Path;
					sw.WriteLine(s);
				}

				var path = Path.GetFullPath(@"..\..\..\..\Source\Doc\");

				sw.WriteLine(@"
[OPTIONS]
Title=BLToolkit
Auto Index=Yes
Compatibility=1.1 or later
Compiled file={0}BLToolkit.chm
Default Window=MsdnHelp
Default topic=Home.htm
Display compile progress=No
Error log file=BLToolkit.log
Full-text search=Yes
Index file=BLToolkit.hhk
Language=0x409 English (United States)
Contents file=BLToolkit.hhc

[WINDOWS]
MsdnHelp=""Business Logic Toolkit for .NET Help"",""BLToolkit.hhc"",""BLToolkit.hhk"",""Home.htm"",""Home.htm"",,,,,0x63520,250,0x387e,[50,25,850,625],0x1020000,,,,,,0

[INFOTYPES]
",
					path);
			}
		}
예제 #8
0
		private static void CreateContentFile(FileItem root)
		{
			using (var sw = File.CreateText(destPath + "BLToolkit.hhc"))
			{
				sw.WriteLine(@"
<HTML>
<HEAD>
</HEAD><BODY>
<UL>
	<LI> <OBJECT type=""text/sitemap"">
		<param name=""Name"" value=""Home"">
		<param name=""Local"" value=""Home.htm"">
		</OBJECT>
	<LI> <OBJECT type=""text/sitemap"">
		<param name=""Name"" value=""License"">
		<param name=""Local"" value=""License.htm"">
		</OBJECT>");

				foreach (var file in root.Items)
				{
					if (!file.IsFile && file.Name == "Doc")
					{
						file.Title = "Documentation";
						CreateContent(file, sw);
						break;
					}
				}

				sw.WriteLine(@"
</UL>
</BODY></HTML>
");
			}
		}
예제 #9
0
		private static void CreateContent(FileItem dir, TextWriter sw)
		{
			if (dir.Items == null)
				return;

			var index = dir.Items.Find(i => i.Name.ToLower().EndsWith("index.htm"));

			if (index == null)
			{
				sw.WriteLine(
					@"
<LI><OBJECT type=""text/sitemap"">
	<param name=""Name"" value=""{0}"">
	</OBJECT>
<UL>",
					dir.Title);
			}
			else
			{
				sw.WriteLine(
					@"
<LI><OBJECT type=""text/sitemap"">
	<param name=""Name"" value=""{0}"">
	<param name=""Local"" value=""{1}"">
	</OBJECT>
<UL>",
					index.Title, index.Name);
			}

			foreach (var file in dir.Items)
			{
				if (file.Name.ToLower().EndsWith("index.htm"))
					continue;

				if (file.IsFile)
				{
					sw.WriteLine(@"
<LI><OBJECT type=""text/sitemap"">
	<param name=""Name"" value=""{0}"">
	<param name=""Local"" value=""{1}"">
	</OBJECT>",
					             file.Title, file.Name);

				}
				else
					CreateContent(file, sw);
			}

			sw.WriteLine("</UL>");
		}
예제 #10
0
		public void Prepare()
		{
			if (Items != null)
			{
				var groups = new List<FileItem>();

				for (var i = 0; i < Items.Count; i++)
				{
					var item = Items[i];

					if (item.Group != null && item.Group != Name)
					{
						var group = groups.Find(file => file.Name == item.Group);

						if (group == null)
							groups.Add(group = new FileItem { Name = item.Group, SortOrder = item.SortOrder });

						group.Add(item);
						Items.RemoveAt(i);

						i--;
					}
				}

				Items.AddRange(groups);

				foreach (var item in Items)
					item.Prepare();

				Items.Sort((x, y) =>
				{
					var xname = x.Title.ToLower();
					var yname = y.Title.ToLower();

					if (xname == yname)                         return  0;
					if (x.Name.ToLower().EndsWith("index.htm")) return -1;
					if (y.Name.ToLower().EndsWith("index.htm")) return  1;

					if (x.SortOrder != 0 && y.SortOrder != 0)
						return x.SortOrder - y.SortOrder;

					if (x.SortOrder != 0) return -1;
					if (y.SortOrder != 0) return  1;

					return string.Compare(xname, yname);
				});
			}
		}
예제 #11
0
		private bool GenerateContent(
			FileItem createdFiles, string template, string[] path, bool createIndex)
		{
			var folder     = string.Join("/", path);
			var destFolder = Path.Combine(_destFolder, folder);
			var backPath   = "";

			for (var i = 0; i < path.Length; i++)
				backPath += "../";

			var sourcePath  = Path.Combine(_sourcePath, folder);
			var sourceFiles = Directory.GetFiles(sourcePath);

			var files   = new List<string>();
			var folders = new List<string>();

			foreach (var fileName in sourceFiles)
			{
				var backLinks = GeneratePath(path, backPath, fileName);

				var destName  = Path.Combine(destFolder, Path.GetFileName(fileName));
				var ext       = Path.GetExtension(destName).ToLower();

				Console.WriteLine(destName);

				switch (_fileAction(fileName))
				{
					case FileAction.Skip:
						break;

					case FileAction.Copy:
						File.Copy(fileName, destName, true);
						break;

					case FileAction.Process:
						if (Directory.Exists(destFolder) == false)
							Directory.CreateDirectory(destFolder);

						switch (ext)
						{
							case ".htm":
							case ".html":
								using (var sw = File.CreateText(destName))
								using (var sr = File.OpenText(fileName))
								{
									var item = new FileItem { IsFile = true, Name = destName };
									createdFiles.Add(item);

									var source = sr.ReadToEnd();

									source = source
										.Replace("<ct_table>",  "<table border='0' cellpadding='0' cellspacing='0'>")
										.Replace("<ct_hr>",     "<ct_mg><tr><td colspan='5' class='hr'><img width='1' height='1' alt=''/></td></tr><ct_mg>")
										.Replace("<ct_text>",   "<tr><td colspan='5'>")
										.Replace("</ct_text>",  "</td></tr><ct_mg>")
										.Replace("<ct_mg>",     "<tr><td colspan='5' class='sp'><img width='1' height='1' alt=''/></td></tr>")
										.Replace("</ct_table>", "</table>")
										;

									source = ct_item1.Replace(source, @"<tr><td nowrap colspan='5'>&#8226; <a href=${link}>${label}</a></td></tr>");
									source = ct_item2.Replace(source, @"<tr><td nowrap>&#8226; <a href=${link}>${label}</a></td><td>&nbsp;&nbsp;&nbsp;</td><td class='j' colspan='3'>${text}</td></tr>");
									source = ct_item3.Replace(source, @"<tr><td nowrap class='p'>&#8226; <a href=${link}>${label}</a></td><td></td><td class='pj' colspan='3'>${text}</td></tr>");
									source = ct_item4.Replace(source, @"<tr><td nowrap>&#8226; <a href=${link1}>${label1}</a></td><td>&nbsp;&nbsp;&nbsp;</td><td nowrap colspan='3'>&#8226; <a href=${link2}>${label2}</a></td></tr>");
									source = ct_item5.Replace(source, @"<tr><td nowrap>&#8226; <a href=${link1}>${label1}</a></td><td>&nbsp;&nbsp;&nbsp;</td><td nowrap>&#8226; <a href=${link2}>${label2}</a></td><td>&nbsp;&nbsp;&nbsp;</td><td nowrap>&#8226; <a href=${link3}>${label3}</a></td></tr>");

									if (_modifySourceLinks)
									{
										source = source
											.Replace("href=\"..\\..\\..\\Source\\", "target=_blank href=\"/Source/")
											.Replace("href='..\\..\\..\\Source\\",  "target=_blank href='/Source/")
											.Replace("<a href=\"http://", "<a target=_blank href=\"http://")
											.Replace("<a href='http://",  "<a target=_blank href='http://")
											;
									}

									var title  = item.Title;

									if (title == "index")
									{
										title = Path.GetFileName(Path.GetDirectoryName(fileName));

										if (title != "content")
											item.Title = title;
									}

									source = GenerateSource(source, item);
									title  = item.Title;

									if (title.Length > 0 && _addDashToTitle)
										title += " - ";

									sw.WriteLine(string.Format(
										template,
										source,
										backPath,
										backLinks,
										title));

									if (item.NoIndex == false)
									{
										source = source
											.Replace("<span class='a'>", "")
											.Replace("</span>", "")
											.Replace("&lt;", "<")
											.Replace("&gt;", ">")
											;

										foreach (var index in IndexItem.Index)
											if (!item.NoIndexes.Contains(index.Name))
												foreach (var s in index.Text)
													if (source.IndexOf(s) >= 0)
													{
														index.Files.Add(item);
														break;
													}

										foreach (var s in item.Indexes)
										{
											var index = IndexItem.Index.Find(i => i.Name == s);

											if (index == null)
												IndexItem.Index.Add(new IndexItem(s));

											if (index.Files.Contains(item) == false)
												index.Files.Add(item);
										}
									}
								}

								break;

							case ".cs":
								using (var sw = File.CreateText(destName + ".htm"))
								{
									createdFiles.Add(new FileItem { IsFile = true, Name = destName + ".htm" });

									var source = GenerateSource("<% " + fileName + " %>", null);

									sw.WriteLine(string.Format(
										template,
										source,
										backPath,
										backLinks,
										Path.GetFileNameWithoutExtension(fileName) + " - "));
								}
								break;
						}

						files.Add(fileName);

						break;
				}
			}

			var dirs    = Directory.GetDirectories(sourcePath);
			var newPath = new string[path.Length + 1];

			path.CopyTo(newPath, 0);

			foreach (var dir in dirs)
			{
				var dirList = dir.Split('/', '\\');
				var dirName = dirList[dirList.Length - 1];

				// Skip Subversion folders.
				//
				if (dirName == "_svn" || dirName == ".svn")
					continue;

				newPath[path.Length] = dirName;

				var item = new FileItem { IsFile = false, Name = dirName};

				createdFiles.Add(item);

				if (GenerateContent(item, template, newPath, createIndex))
					folders.Add(dir);
			}

			if (files.Count > 0 || folders.Count > 0)
			{
				var indexName = destFolder + "/index.htm";

				if (createIndex && File.Exists(indexName) == false)
				{
					var str = "";

					folders.Sort();

					foreach (var s in folders)
						str += string.Format("&#8226; <a href='{0}/index.htm'>{0}</a><br>\n",
							Path.GetFileName(s));

					if (str.Length > 0)
						str += "<br>";

					files.Sort();

					foreach (var s in files)
						str += string.Format(
							s.EndsWith(".htm",  true, CultureInfo.CurrentCulture) ||
							s.EndsWith(".html", true, CultureInfo.CurrentCulture)?
								"&#8226; <a href='{0}'>{0}</a><br>":
								"&#8226; <a href='{0}.htm'>{0}</a><br>\n",
							Path.GetFileName(s));

					_fileAction(indexName);

					using (var sw = File.CreateText(indexName))
					{
						createdFiles.Add(new FileItem { IsFile = true, Name = indexName });

						sw.WriteLine(string.Format(
							template,
							str,
							backPath,
							GeneratePath(path, backPath, "@@@").Replace(".@@@", ""),
							Path.GetFileNameWithoutExtension(destFolder) + " - "));
					}
				}

				return true;
			}

			return false;
		}
예제 #12
0
		private string GenerateSource(string text, FileItem item)
		{
			for (int
				 idx = text.IndexOf("<%"),
				 end = text.IndexOf("%>", idx + 2);
				 idx >= 0 &&
				 end >= 0;
				 idx = text.IndexOf("<%", idx + 2),
				 end = text.IndexOf("%>", idx + 2))
			{
				var startSource = text.Substring(0, idx);
				var source      = text.Substring(idx + 2, end - idx - 2).Trim();
				var command     = "source";

				var cmdIdx = source.IndexOf('#');

				if (cmdIdx >= 0)
				{
					command = source.Substring(0, cmdIdx).Trim().ToLower();
					source  = source.Substring(cmdIdx+1).Trim();
				}

				switch (command)
				{
					case "source"  : source = GetSourceCodeFromPath(Path.Combine(_sourcePath, source), text); break;
					case "rss"     : source = GetNews              (Path.Combine(_sourcePath, source));       break;
					case "txt"     :
					case "cs"      :
					case "sql"     : source = GetSourceCode(source, "." + command, text);                     break;
					case "title"   : item.Title     = source;            source = "";                         break;
					case "order"   : item.SortOrder = int.Parse(source); source = "";                         break;
					case "group"   : item.Group     = source;            source = "";                         break;
					case "index"   : item.Indexes.Add(source);           source = "";                         break;
					case "table"   : source = GetTable(Path.Combine(_sourcePath, source));                    break;
					case "noindex" :
						if (source.Length == 0)
							item.NoIndex = true;
						else
							item.NoIndexes.Add(source);
							
						source = "";
						break;

					default        : throw new InvalidOperationException();
				}

				text = startSource + source + text.Substring(end + 2);
			}

			return text
				.Replace(@"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DBHost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));User Id=TestUser;Password=TestPassword;", "...");
		}