Move uDocumentation
This commit is contained in:
@@ -4730,10 +4730,6 @@
|
||||
<Project>{a625544f-660a-4c01-ba49-1b467d0322d9}</Project>
|
||||
<Name>our.umbraco.org</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\uDocumentation\uDocumentation.csproj">
|
||||
<Project>{2040bdaf-a804-462f-8d5f-ca0df141bf89}</Project>
|
||||
<Name>uDocumentation</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\uEvents\uEvents.csproj">
|
||||
<Project>{f356b339-296a-4594-81b6-cf69a802483e}</Project>
|
||||
<Name>uEvents</Name>
|
||||
|
||||
+30
-30
@@ -1,31 +1,31 @@
|
||||
namespace uDocumentation.Busineslogic
|
||||
{
|
||||
public static class ConventionExtensions
|
||||
{
|
||||
public static string EnsureNoDotsInUrl(this string url)
|
||||
{
|
||||
return url.Replace(".", "_")
|
||||
.Replace("__", "..")
|
||||
.Replace("_md", "")
|
||||
.Replace("_png", ".png")
|
||||
.Replace("_jpg", ".jpg")
|
||||
.Replace("_pdf", ".pdf")
|
||||
.Replace("_gif", ".gif");
|
||||
}
|
||||
|
||||
public static string UnderscoreToDot(this string str)
|
||||
{
|
||||
return str.Replace("_", ".");
|
||||
}
|
||||
|
||||
public static string RemoveDash(this string str)
|
||||
{
|
||||
return str.Replace("-", " ");
|
||||
}
|
||||
|
||||
public static string EnsureCorrectDocumentationText(this string str)
|
||||
{
|
||||
return str.Replace("documentation", "Documentation");
|
||||
}
|
||||
}
|
||||
namespace uDocumentation.Busineslogic
|
||||
{
|
||||
public static class ConventionExtensions
|
||||
{
|
||||
public static string EnsureNoDotsInUrl(this string url)
|
||||
{
|
||||
return url.Replace(".", "_")
|
||||
.Replace("__", "..")
|
||||
.Replace("_md", "")
|
||||
.Replace("_png", ".png")
|
||||
.Replace("_jpg", ".jpg")
|
||||
.Replace("_pdf", ".pdf")
|
||||
.Replace("_gif", ".gif");
|
||||
}
|
||||
|
||||
public static string UnderscoreToDot(this string str)
|
||||
{
|
||||
return str.Replace("_", ".");
|
||||
}
|
||||
|
||||
public static string RemoveDash(this string str)
|
||||
{
|
||||
return str.Replace("-", " ");
|
||||
}
|
||||
|
||||
public static string EnsureCorrectDocumentationText(this string str)
|
||||
{
|
||||
return str.Replace("documentation", "Documentation");
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
-28
@@ -1,29 +1,29 @@
|
||||
namespace uDocumentation.Busineslogic
|
||||
{
|
||||
public class DefaultVersion
|
||||
{
|
||||
private static DefaultVersion _instance;
|
||||
|
||||
private DefaultVersion() { }
|
||||
|
||||
public static DefaultVersion Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DefaultVersion();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public string Number
|
||||
{
|
||||
get
|
||||
{
|
||||
return "master";//Read default version from web.config
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace uDocumentation.Busineslogic
|
||||
{
|
||||
public class DefaultVersion
|
||||
{
|
||||
private static DefaultVersion _instance;
|
||||
|
||||
private DefaultVersion() { }
|
||||
|
||||
public static DefaultVersion Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DefaultVersion();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public string Number
|
||||
{
|
||||
get
|
||||
{
|
||||
return "master";//Read default version from web.config
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+334
-334
@@ -1,336 +1,336 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using System.Diagnostics;
|
||||
using umbraco.BusinessLogic;
|
||||
using System.Dynamic;
|
||||
using Examine;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace uDocumentation.Busineslogic.GithubSourcePull
|
||||
{
|
||||
public class ZipDownloader
|
||||
{
|
||||
private const string rootFolder = @"~\Documentation";
|
||||
private const string config = @"~\config\githubpull.config";
|
||||
private string rootFolderPath = HttpContext.Current.Server.MapPath(rootFolder);
|
||||
private string configPath = HttpContext.Current.Server.MapPath(config);
|
||||
|
||||
|
||||
public string RootFolder { get; set; }
|
||||
public XmlDocument Configuration { get; set; }
|
||||
public bool IsProjectDocumentation { get; set; }
|
||||
|
||||
public ZipDownloader(string rootFolder, XmlDocument configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
RootFolder = rootFolder;
|
||||
IsProjectDocumentation = false;
|
||||
}
|
||||
|
||||
public ZipDownloader()
|
||||
{
|
||||
XmlDocument xd = new XmlDocument();
|
||||
xd.Load(configPath);
|
||||
|
||||
Configuration = xd;
|
||||
RootFolder = rootFolderPath;
|
||||
IsProjectDocumentation = false;
|
||||
}
|
||||
|
||||
public ZipDownloader(string rootFolder, string configurationPath)
|
||||
{
|
||||
XmlDocument xd = new XmlDocument();
|
||||
xd.Load(configurationPath);
|
||||
|
||||
Configuration = xd;
|
||||
RootFolder = rootFolder;
|
||||
IsProjectDocumentation = false;
|
||||
}
|
||||
|
||||
public ZipDownloader(int projectId)
|
||||
{
|
||||
var project = new umbraco.NodeFactory.Node(projectId);
|
||||
var githubRepo = project.GetProperty("documentationGitRepo");
|
||||
var xd = new XmlDocument();
|
||||
|
||||
xd.LoadXml(string.Format(
|
||||
"<?xml version=\"1.0\"?><configuration><sources><add url=\"{0}/zipball/master\" folder=\"\" /></sources></configuration>",
|
||||
githubRepo));
|
||||
|
||||
Configuration = xd;
|
||||
RootFolder = HttpContext.Current.Server.MapPath(@"~" + project.Url.Replace("/",@"\") + @"\Documentation");
|
||||
IsProjectDocumentation = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will ensure that the docs exist, this checks by the existence of the /Documentation/sitemap.js file
|
||||
/// </summary>
|
||||
public static void EnsureGitHubDocs(bool overwrite = false)
|
||||
{
|
||||
var rootFolderPath = HttpContext.Current.Server.MapPath(rootFolder);
|
||||
var configPath = HttpContext.Current.Server.MapPath(config);
|
||||
|
||||
//Check if it exists, if it does then exit
|
||||
if (!overwrite && File.Exists(Path.Combine(rootFolderPath, "sitemap.js"))) return;
|
||||
|
||||
if (!Directory.Exists(rootFolderPath))
|
||||
{
|
||||
Directory.CreateDirectory(rootFolderPath);
|
||||
}
|
||||
|
||||
var unzip = new ZipDownloader(rootFolderPath, configPath)
|
||||
{
|
||||
IsProjectDocumentation = true
|
||||
};
|
||||
unzip.Run();
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
Trace.WriteLine("Started git sync", "Gitsyncer");
|
||||
|
||||
foreach (XmlNode node in Configuration.SelectNodes("//add"))
|
||||
{
|
||||
var url = node.Attributes["url"].Value;
|
||||
var folder = node.Attributes["folder"].Value;
|
||||
var path = Path.Combine(RootFolder, folder);
|
||||
|
||||
Trace.WriteLine("Loading: " + url + " to " + path, "Gitsyncer");
|
||||
|
||||
process(url, folder);
|
||||
}
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using System.Diagnostics;
|
||||
using umbraco.BusinessLogic;
|
||||
using System.Dynamic;
|
||||
using Examine;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace uDocumentation.Busineslogic.GithubSourcePull
|
||||
{
|
||||
public class ZipDownloader
|
||||
{
|
||||
private const string rootFolder = @"~\Documentation";
|
||||
private const string config = @"~\config\githubpull.config";
|
||||
private string rootFolderPath = HttpContext.Current.Server.MapPath(rootFolder);
|
||||
private string configPath = HttpContext.Current.Server.MapPath(config);
|
||||
|
||||
|
||||
public string RootFolder { get; set; }
|
||||
public XmlDocument Configuration { get; set; }
|
||||
public bool IsProjectDocumentation { get; set; }
|
||||
|
||||
public ZipDownloader(string rootFolder, XmlDocument configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
RootFolder = rootFolder;
|
||||
IsProjectDocumentation = false;
|
||||
}
|
||||
|
||||
public ZipDownloader()
|
||||
{
|
||||
XmlDocument xd = new XmlDocument();
|
||||
xd.Load(configPath);
|
||||
|
||||
Configuration = xd;
|
||||
RootFolder = rootFolderPath;
|
||||
IsProjectDocumentation = false;
|
||||
}
|
||||
|
||||
public ZipDownloader(string rootFolder, string configurationPath)
|
||||
{
|
||||
XmlDocument xd = new XmlDocument();
|
||||
xd.Load(configurationPath);
|
||||
|
||||
Configuration = xd;
|
||||
RootFolder = rootFolder;
|
||||
IsProjectDocumentation = false;
|
||||
}
|
||||
|
||||
public ZipDownloader(int projectId)
|
||||
{
|
||||
var project = new umbraco.NodeFactory.Node(projectId);
|
||||
var githubRepo = project.GetProperty("documentationGitRepo");
|
||||
var xd = new XmlDocument();
|
||||
|
||||
xd.LoadXml(string.Format(
|
||||
"<?xml version=\"1.0\"?><configuration><sources><add url=\"{0}/zipball/master\" folder=\"\" /></sources></configuration>",
|
||||
githubRepo));
|
||||
|
||||
Configuration = xd;
|
||||
RootFolder = HttpContext.Current.Server.MapPath(@"~" + project.Url.Replace("/",@"\") + @"\Documentation");
|
||||
IsProjectDocumentation = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will ensure that the docs exist, this checks by the existence of the /Documentation/sitemap.js file
|
||||
/// </summary>
|
||||
public static void EnsureGitHubDocs(bool overwrite = false)
|
||||
{
|
||||
var rootFolderPath = HttpContext.Current.Server.MapPath(rootFolder);
|
||||
var configPath = HttpContext.Current.Server.MapPath(config);
|
||||
|
||||
//Check if it exists, if it does then exit
|
||||
if (!overwrite && File.Exists(Path.Combine(rootFolderPath, "sitemap.js"))) return;
|
||||
|
||||
if (!Directory.Exists(rootFolderPath))
|
||||
{
|
||||
Directory.CreateDirectory(rootFolderPath);
|
||||
}
|
||||
|
||||
var unzip = new ZipDownloader(rootFolderPath, configPath)
|
||||
{
|
||||
IsProjectDocumentation = true
|
||||
};
|
||||
unzip.Run();
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
Trace.WriteLine("Started git sync", "Gitsyncer");
|
||||
|
||||
foreach (XmlNode node in Configuration.SelectNodes("//add"))
|
||||
{
|
||||
var url = node.Attributes["url"].Value;
|
||||
var folder = node.Attributes["folder"].Value;
|
||||
var path = Path.Combine(RootFolder, folder);
|
||||
|
||||
Trace.WriteLine("Loading: " + url + " to " + path, "Gitsyncer");
|
||||
|
||||
process(url, folder);
|
||||
}
|
||||
|
||||
|
||||
FinishEventArgs ev = new FinishEventArgs();
|
||||
FireOnFinish(ev);
|
||||
}
|
||||
|
||||
public dynamic DocumentationSiteMap(string folder = "")
|
||||
{
|
||||
var path = Path.Combine(RootFolder, folder, "sitemap.js");
|
||||
var json = File.ReadAllText(path);
|
||||
dynamic d = JsonConvert.DeserializeObject<dynamic>(json);
|
||||
return d;
|
||||
}
|
||||
|
||||
public void process(string url, string foldername)
|
||||
{
|
||||
var zip = Download(url, foldername);
|
||||
unzip(zip, foldername, RootFolder);
|
||||
BuildSitemap(foldername);
|
||||
|
||||
//YUCK, this is horrible but unfortunately the way that the doc indexes are setup are not with
|
||||
// a consistent integer id per document. I'm sure we can make that happen but I don't have time right now.
|
||||
ExamineManager.Instance.IndexProviderCollection["documentationIndexer"].RebuildIndex();
|
||||
}
|
||||
|
||||
private void BuildSitemap(string foldername)
|
||||
{
|
||||
var folder = new DirectoryInfo(Path.Combine(RootFolder, foldername));
|
||||
dynamic root = GetFolderStructure(folder, folder.FullName, 0);
|
||||
|
||||
var serializedRoot = JsonConvert.SerializeObject(root, Newtonsoft.Json.Formatting.Indented);
|
||||
File.WriteAllText(Path.Combine(folder.FullName, "sitemap.js"), serializedRoot);
|
||||
}
|
||||
|
||||
private dynamic GetFolderStructure(DirectoryInfo dir, string rootPath, int level)
|
||||
{
|
||||
dynamic d = new ExpandoObject();
|
||||
d.name = dir.Name;
|
||||
d.path = dir.FullName.Substring(rootPath.Length).Replace('\\','/');
|
||||
d.level = level;
|
||||
|
||||
if (dir.GetDirectories().Any())
|
||||
{
|
||||
var list = new List<dynamic>();
|
||||
foreach (var child in dir.GetDirectories())
|
||||
list.Add(GetFolderStructure(child, rootPath, level+1));
|
||||
|
||||
|
||||
d.hasChildren = true;
|
||||
d.directories = list;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
private string Download(string url, string foldername)
|
||||
{
|
||||
var dir = new DirectoryInfo(Path.Combine(RootFolder, foldername));
|
||||
var dirsToCreate = new List<DirectoryInfo>();
|
||||
|
||||
while (!dir.Exists)
|
||||
{
|
||||
dirsToCreate.Add(dir);
|
||||
dir = dir.Parent;
|
||||
}
|
||||
|
||||
if (dirsToCreate.Any())
|
||||
{
|
||||
dirsToCreate.Reverse();
|
||||
foreach (var d in dirsToCreate)
|
||||
d.Create();
|
||||
}
|
||||
|
||||
var path = Path.Combine(RootFolder, foldername + "archive.zip");
|
||||
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
|
||||
WebClient Client = new WebClient();
|
||||
Client.DownloadFile(url, path);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
private void unzip(string path, string foldername, string rootFolder)
|
||||
{
|
||||
ZipInputStream s = new ZipInputStream(File.OpenRead(path));
|
||||
ZipEntry theEntry;
|
||||
|
||||
var stopDir = "\\Documentation";
|
||||
string serverFolder = rootFolder + "\\" + foldername;
|
||||
|
||||
List<string> existingFiles = new List<string>();
|
||||
|
||||
if (Directory.Exists(serverFolder))
|
||||
{
|
||||
foreach (var folder in Directory.GetDirectories(serverFolder))
|
||||
Directory.Delete(folder, true);
|
||||
|
||||
foreach (var mdfile in Directory.GetFiles(serverFolder, "*.md"))
|
||||
File.Delete(mdfile);
|
||||
|
||||
// var files = string.Join("|", Directory.GetFiles(serverFolder, "*.md", SearchOption.AllDirectories)).ToLower().Split('|');
|
||||
// existingFiles.AddRange(files);
|
||||
}
|
||||
else
|
||||
Directory.CreateDirectory(serverFolder);
|
||||
|
||||
try
|
||||
{
|
||||
bool stopDirSet = false;
|
||||
|
||||
while ((theEntry = s.GetNextEntry()) != null)
|
||||
{
|
||||
if (IsProjectDocumentation && !stopDirSet)
|
||||
{
|
||||
stopDir = Path.GetDirectoryName(theEntry.Name);
|
||||
stopDirSet = true;
|
||||
}
|
||||
|
||||
string directoryName = Path.GetDirectoryName(theEntry.Name);
|
||||
string fileName = Path.GetFileName(theEntry.Name);
|
||||
|
||||
HttpContext.Current.Trace.Write("git", theEntry.Name + " " + fileName + " - " + directoryName);
|
||||
|
||||
if (directoryName.Contains(stopDir))
|
||||
{
|
||||
var startIndex = directoryName.LastIndexOf(stopDir) + stopDir.Length;
|
||||
directoryName = directoryName.Substring(startIndex);
|
||||
|
||||
// create directory
|
||||
Directory.CreateDirectory(serverFolder + directoryName);
|
||||
|
||||
if (fileName != String.Empty)
|
||||
{
|
||||
bool update = false;
|
||||
var filepath = serverFolder + directoryName + "\\" + fileName;
|
||||
|
||||
|
||||
if (existingFiles.Contains(filepath.ToLower()))
|
||||
{
|
||||
update = true;
|
||||
existingFiles.Remove(filepath.ToLower());
|
||||
}
|
||||
|
||||
FileStream streamWriter = File.Create(filepath);
|
||||
int size = 2048;
|
||||
byte[] data = new byte[2048];
|
||||
while (true)
|
||||
{
|
||||
size = s.Read(data, 0, data.Length);
|
||||
if (size > 0)
|
||||
{
|
||||
streamWriter.Write(data, 0, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
streamWriter.Close();
|
||||
|
||||
if (update)
|
||||
{
|
||||
UpdateEventArgs ev = new UpdateEventArgs();
|
||||
ev.FilePath = filepath;
|
||||
FireOnUpdate(ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateEventArgs ev = new CreateEventArgs();
|
||||
ev.FilePath = filepath;
|
||||
FireOnCreate(ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s.Close();
|
||||
foreach (var file in Directory.GetFiles(rootFolder, "*.zip"))
|
||||
{
|
||||
//File.Delete(file);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Add(LogTypes.Error, -1, ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private Events _e = new Events();
|
||||
|
||||
public static event EventHandler<UpdateEventArgs> OnUpdate;
|
||||
protected virtual void FireOnUpdate(UpdateEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_e.FireCancelableEvent(OnUpdate, this, e);
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
|
||||
|
||||
public static event EventHandler<CreateEventArgs> OnCreate;
|
||||
protected virtual void FireOnCreate(CreateEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_e.FireCancelableEvent(OnCreate, this, e);
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
|
||||
|
||||
public static event EventHandler<DeleteEventArgs> OnDelete;
|
||||
protected virtual void FireOnDelete(DeleteEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_e.FireCancelableEvent(OnDelete, this, e);
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
|
||||
FireOnFinish(ev);
|
||||
}
|
||||
|
||||
public dynamic DocumentationSiteMap(string folder = "")
|
||||
{
|
||||
var path = Path.Combine(RootFolder, folder, "sitemap.js");
|
||||
var json = File.ReadAllText(path);
|
||||
dynamic d = JsonConvert.DeserializeObject<dynamic>(json);
|
||||
return d;
|
||||
}
|
||||
|
||||
public void process(string url, string foldername)
|
||||
{
|
||||
var zip = Download(url, foldername);
|
||||
unzip(zip, foldername, RootFolder);
|
||||
BuildSitemap(foldername);
|
||||
|
||||
//YUCK, this is horrible but unfortunately the way that the doc indexes are setup are not with
|
||||
// a consistent integer id per document. I'm sure we can make that happen but I don't have time right now.
|
||||
ExamineManager.Instance.IndexProviderCollection["documentationIndexer"].RebuildIndex();
|
||||
}
|
||||
|
||||
private void BuildSitemap(string foldername)
|
||||
{
|
||||
var folder = new DirectoryInfo(Path.Combine(RootFolder, foldername));
|
||||
dynamic root = GetFolderStructure(folder, folder.FullName, 0);
|
||||
|
||||
var serializedRoot = JsonConvert.SerializeObject(root, Newtonsoft.Json.Formatting.Indented);
|
||||
File.WriteAllText(Path.Combine(folder.FullName, "sitemap.js"), serializedRoot);
|
||||
}
|
||||
|
||||
private dynamic GetFolderStructure(DirectoryInfo dir, string rootPath, int level)
|
||||
{
|
||||
dynamic d = new ExpandoObject();
|
||||
d.name = dir.Name;
|
||||
d.path = dir.FullName.Substring(rootPath.Length).Replace('\\','/');
|
||||
d.level = level;
|
||||
|
||||
if (dir.GetDirectories().Any())
|
||||
{
|
||||
var list = new List<dynamic>();
|
||||
foreach (var child in dir.GetDirectories())
|
||||
list.Add(GetFolderStructure(child, rootPath, level+1));
|
||||
|
||||
|
||||
d.hasChildren = true;
|
||||
d.directories = list;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
private string Download(string url, string foldername)
|
||||
{
|
||||
var dir = new DirectoryInfo(Path.Combine(RootFolder, foldername));
|
||||
var dirsToCreate = new List<DirectoryInfo>();
|
||||
|
||||
while (!dir.Exists)
|
||||
{
|
||||
dirsToCreate.Add(dir);
|
||||
dir = dir.Parent;
|
||||
}
|
||||
|
||||
if (dirsToCreate.Any())
|
||||
{
|
||||
dirsToCreate.Reverse();
|
||||
foreach (var d in dirsToCreate)
|
||||
d.Create();
|
||||
}
|
||||
|
||||
var path = Path.Combine(RootFolder, foldername + "archive.zip");
|
||||
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
|
||||
WebClient Client = new WebClient();
|
||||
Client.DownloadFile(url, path);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
private void unzip(string path, string foldername, string rootFolder)
|
||||
{
|
||||
ZipInputStream s = new ZipInputStream(File.OpenRead(path));
|
||||
ZipEntry theEntry;
|
||||
|
||||
var stopDir = "\\Documentation";
|
||||
string serverFolder = rootFolder + "\\" + foldername;
|
||||
|
||||
List<string> existingFiles = new List<string>();
|
||||
|
||||
if (Directory.Exists(serverFolder))
|
||||
{
|
||||
foreach (var folder in Directory.GetDirectories(serverFolder))
|
||||
Directory.Delete(folder, true);
|
||||
|
||||
foreach (var mdfile in Directory.GetFiles(serverFolder, "*.md"))
|
||||
File.Delete(mdfile);
|
||||
|
||||
// var files = string.Join("|", Directory.GetFiles(serverFolder, "*.md", SearchOption.AllDirectories)).ToLower().Split('|');
|
||||
// existingFiles.AddRange(files);
|
||||
}
|
||||
else
|
||||
Directory.CreateDirectory(serverFolder);
|
||||
|
||||
try
|
||||
{
|
||||
bool stopDirSet = false;
|
||||
|
||||
while ((theEntry = s.GetNextEntry()) != null)
|
||||
{
|
||||
if (IsProjectDocumentation && !stopDirSet)
|
||||
{
|
||||
stopDir = Path.GetDirectoryName(theEntry.Name);
|
||||
stopDirSet = true;
|
||||
}
|
||||
|
||||
string directoryName = Path.GetDirectoryName(theEntry.Name);
|
||||
string fileName = Path.GetFileName(theEntry.Name);
|
||||
|
||||
HttpContext.Current.Trace.Write("git", theEntry.Name + " " + fileName + " - " + directoryName);
|
||||
|
||||
if (directoryName.Contains(stopDir))
|
||||
{
|
||||
var startIndex = directoryName.LastIndexOf(stopDir) + stopDir.Length;
|
||||
directoryName = directoryName.Substring(startIndex);
|
||||
|
||||
// create directory
|
||||
Directory.CreateDirectory(serverFolder + directoryName);
|
||||
|
||||
if (fileName != String.Empty)
|
||||
{
|
||||
bool update = false;
|
||||
var filepath = serverFolder + directoryName + "\\" + fileName;
|
||||
|
||||
|
||||
if (existingFiles.Contains(filepath.ToLower()))
|
||||
{
|
||||
update = true;
|
||||
existingFiles.Remove(filepath.ToLower());
|
||||
}
|
||||
|
||||
FileStream streamWriter = File.Create(filepath);
|
||||
int size = 2048;
|
||||
byte[] data = new byte[2048];
|
||||
while (true)
|
||||
{
|
||||
size = s.Read(data, 0, data.Length);
|
||||
if (size > 0)
|
||||
{
|
||||
streamWriter.Write(data, 0, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
streamWriter.Close();
|
||||
|
||||
if (update)
|
||||
{
|
||||
UpdateEventArgs ev = new UpdateEventArgs();
|
||||
ev.FilePath = filepath;
|
||||
FireOnUpdate(ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateEventArgs ev = new CreateEventArgs();
|
||||
ev.FilePath = filepath;
|
||||
FireOnCreate(ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s.Close();
|
||||
foreach (var file in Directory.GetFiles(rootFolder, "*.zip"))
|
||||
{
|
||||
//File.Delete(file);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Add(LogTypes.Error, -1, ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private Events _e = new Events();
|
||||
|
||||
public static event EventHandler<UpdateEventArgs> OnUpdate;
|
||||
protected virtual void FireOnUpdate(UpdateEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_e.FireCancelableEvent(OnUpdate, this, e);
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
|
||||
|
||||
public static event EventHandler<CreateEventArgs> OnCreate;
|
||||
protected virtual void FireOnCreate(CreateEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_e.FireCancelableEvent(OnCreate, this, e);
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
|
||||
|
||||
public static event EventHandler<DeleteEventArgs> OnDelete;
|
||||
protected virtual void FireOnDelete(DeleteEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_e.FireCancelableEvent(OnDelete, this, e);
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
|
||||
public static event EventHandler<FinishEventArgs> OnFinish;
|
||||
protected virtual void FireOnFinish(FinishEventArgs e)
|
||||
{
|
||||
@@ -339,7 +339,7 @@ namespace uDocumentation.Busineslogic.GithubSourcePull
|
||||
_e.FireCancelableEvent(OnFinish, this, e);
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+85
-85
@@ -1,86 +1,86 @@
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using MarkdownDeep;
|
||||
|
||||
namespace uDocumentation.Busineslogic
|
||||
{
|
||||
public class MarkdownLogic
|
||||
{
|
||||
private readonly string _filePath;
|
||||
|
||||
public MarkdownLogic(string filePath)
|
||||
{
|
||||
_filePath = filePath;
|
||||
}
|
||||
|
||||
public const string VersionSession = "DocumentationVersion";
|
||||
public const string BaseUrl = "documentation";
|
||||
public const string AlternativeTemplate = "DocumentationSubpage";
|
||||
public const string DocumentTypeAlias = "Wiki";
|
||||
public const string MarkdownBasePath = "Documentation";
|
||||
public const string MarkdownPathKey = "MarkdownPath";
|
||||
public const string RegEx = @"\[([^\]]+)\]\(([^)]+)\)";
|
||||
|
||||
public string GetMarkdownBasePathWithVersion
|
||||
{
|
||||
get { return string.Concat(MarkdownBasePath, "\\"); }
|
||||
}
|
||||
|
||||
public bool PrefixLinks { get; set; }
|
||||
|
||||
public string DoTransformation()
|
||||
{
|
||||
if (File.Exists(_filePath))
|
||||
{
|
||||
string text = File.ReadAllText(_filePath);
|
||||
|
||||
var clean = Regex.Replace(text, MarkdownLogic.RegEx, new MatchEvaluator(match => LinkEvaluator(match, PrefixLinks)),
|
||||
RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
|
||||
|
||||
Markdown md = new Markdown();
|
||||
string transform = md.Transform(clean);
|
||||
return transform;
|
||||
}
|
||||
|
||||
return "<h2>Not Found</h2>";
|
||||
}
|
||||
|
||||
private string LinkEvaluator(Match match, bool prefixLinks)
|
||||
{
|
||||
string mdUrlTag = match.Groups[0].Value;
|
||||
string rawUrl = match.Groups[2].Value;
|
||||
|
||||
//Escpae external URLs
|
||||
if (rawUrl.StartsWith("http") || rawUrl.StartsWith("https") || rawUrl.StartsWith("ftp"))
|
||||
return mdUrlTag;
|
||||
|
||||
//Escape anchor links
|
||||
if (rawUrl.StartsWith("#"))
|
||||
return mdUrlTag;
|
||||
|
||||
//Correct internal image links
|
||||
if (rawUrl.StartsWith("../images/"))
|
||||
return mdUrlTag.Replace("../images/", "images/");
|
||||
|
||||
//Used for main page to correct relative links
|
||||
if (prefixLinks)
|
||||
{
|
||||
var p = "/documentation/";
|
||||
|
||||
if (umbraco.NodeFactory.Node.GetCurrent().Parent.NodeTypeAlias == "Project")
|
||||
p = "documentation/";
|
||||
|
||||
string temp = string.Concat(p, rawUrl);
|
||||
mdUrlTag = mdUrlTag.Replace(rawUrl, temp);
|
||||
}
|
||||
|
||||
if (rawUrl.EndsWith("index.md"))
|
||||
mdUrlTag = mdUrlTag.Replace("/index.md", "/");
|
||||
else
|
||||
mdUrlTag.TrimEnd('/');
|
||||
|
||||
|
||||
return mdUrlTag.Replace(rawUrl, rawUrl.EnsureNoDotsInUrl());
|
||||
}
|
||||
}
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using MarkdownDeep;
|
||||
|
||||
namespace uDocumentation.Busineslogic
|
||||
{
|
||||
public class MarkdownLogic
|
||||
{
|
||||
private readonly string _filePath;
|
||||
|
||||
public MarkdownLogic(string filePath)
|
||||
{
|
||||
_filePath = filePath;
|
||||
}
|
||||
|
||||
public const string VersionSession = "DocumentationVersion";
|
||||
public const string BaseUrl = "documentation";
|
||||
public const string AlternativeTemplate = "DocumentationSubpage";
|
||||
public const string DocumentTypeAlias = "Wiki";
|
||||
public const string MarkdownBasePath = "Documentation";
|
||||
public const string MarkdownPathKey = "MarkdownPath";
|
||||
public const string RegEx = @"\[([^\]]+)\]\(([^)]+)\)";
|
||||
|
||||
public string GetMarkdownBasePathWithVersion
|
||||
{
|
||||
get { return string.Concat(MarkdownBasePath, "\\"); }
|
||||
}
|
||||
|
||||
public bool PrefixLinks { get; set; }
|
||||
|
||||
public string DoTransformation()
|
||||
{
|
||||
if (File.Exists(_filePath))
|
||||
{
|
||||
string text = File.ReadAllText(_filePath);
|
||||
|
||||
var clean = Regex.Replace(text, MarkdownLogic.RegEx, new MatchEvaluator(match => LinkEvaluator(match, PrefixLinks)),
|
||||
RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
|
||||
|
||||
Markdown md = new Markdown();
|
||||
string transform = md.Transform(clean);
|
||||
return transform;
|
||||
}
|
||||
|
||||
return "<h2>Not Found</h2>";
|
||||
}
|
||||
|
||||
private string LinkEvaluator(Match match, bool prefixLinks)
|
||||
{
|
||||
string mdUrlTag = match.Groups[0].Value;
|
||||
string rawUrl = match.Groups[2].Value;
|
||||
|
||||
//Escpae external URLs
|
||||
if (rawUrl.StartsWith("http") || rawUrl.StartsWith("https") || rawUrl.StartsWith("ftp"))
|
||||
return mdUrlTag;
|
||||
|
||||
//Escape anchor links
|
||||
if (rawUrl.StartsWith("#"))
|
||||
return mdUrlTag;
|
||||
|
||||
//Correct internal image links
|
||||
if (rawUrl.StartsWith("../images/"))
|
||||
return mdUrlTag.Replace("../images/", "images/");
|
||||
|
||||
//Used for main page to correct relative links
|
||||
if (prefixLinks)
|
||||
{
|
||||
var p = "/documentation/";
|
||||
|
||||
if (umbraco.NodeFactory.Node.GetCurrent().Parent.NodeTypeAlias == "Project")
|
||||
p = "documentation/";
|
||||
|
||||
string temp = string.Concat(p, rawUrl);
|
||||
mdUrlTag = mdUrlTag.Replace(rawUrl, temp);
|
||||
}
|
||||
|
||||
if (rawUrl.EndsWith("index.md"))
|
||||
mdUrlTag = mdUrlTag.Replace("/index.md", "/");
|
||||
else
|
||||
mdUrlTag.TrimEnd('/');
|
||||
|
||||
|
||||
return mdUrlTag.Replace(rawUrl, rawUrl.EnsureNoDotsInUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,10 @@
|
||||
<HintPath>..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="MarkdownDeep, Version=1.5.4615.26275, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MarkdownDeep.NET.1.5\lib\.NetFramework 3.5\MarkdownDeep.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.ApplicationBlocks.Data, Version=1.0.1559.20655, Culture=neutral">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.2.8-build103\lib\Microsoft.ApplicationBlocks.Data.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@@ -221,6 +225,12 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Documentation\Busineslogic\ConventionExtensions.cs" />
|
||||
<Compile Include="Documentation\Busineslogic\DefaultVersion.cs" />
|
||||
<Compile Include="Documentation\Busineslogic\Events.cs" />
|
||||
<Compile Include="Documentation\Busineslogic\GithubSourcePull\ZipDownloader.cs" />
|
||||
<Compile Include="Documentation\Busineslogic\MarkdownLogic.cs" />
|
||||
<Compile Include="Documentation\DocumentationContentFinder.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Repository\Project.cs" />
|
||||
<Compile Include="Repository\Projects.cs" />
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<package id="ImageProcessor" version="2.2.7.0" targetFramework="net451" />
|
||||
<package id="ImageProcessor.Web" version="4.3.5.0" targetFramework="net451" />
|
||||
<package id="Lucene.Net" version="2.9.4.1" targetFramework="net451" />
|
||||
<package id="MarkdownDeep.NET" version="1.5" targetFramework="net451" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net451" />
|
||||
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.1" targetFramework="net451" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net451" />
|
||||
|
||||
@@ -23,8 +23,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notification", "Notificatio
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotificationsWeb", "NotificationsWeb\NotificationsWeb.csproj", "{6CF53D68-BD81-47BB-8F56-350A1B04F114}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "uDocumentation", "uDocumentation\uDocumentation.csproj", "{2040BDAF-A804-462F-8D5F-CA0DF141BF89}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F3A30EFB-C5EA-460A-A591-8FBD7176B131}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.nuget\NuGet.Config = .nuget\NuGet.Config
|
||||
@@ -118,16 +116,6 @@ Global
|
||||
{6CF53D68-BD81-47BB-8F56-350A1B04F114}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{6CF53D68-BD81-47BB-8F56-350A1B04F114}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{6CF53D68-BD81-47BB-8F56-350A1B04F114}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{2040BDAF-A804-462F-8D5F-CA0DF141BF89}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{C5B74E6A-ABCE-4A9A-896D-89C33FDAFCD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C5B74E6A-ABCE-4A9A-896D-89C33FDAFCD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C5B74E6A-ABCE-4A9A-896D-89C33FDAFCD8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
|
||||
@@ -422,10 +422,6 @@
|
||||
<Project>{a8e5c936-ecab-45b3-bfda-d12f680eb2a6}</Project>
|
||||
<Name>OurUmbraco</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\uDocumentation\uDocumentation.csproj">
|
||||
<Project>{2040BDAF-A804-462F-8D5F-CA0DF141BF89}</Project>
|
||||
<Name>uDocumentation</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\uEvents\uEvents.csproj">
|
||||
<Project>{F356B339-296A-4594-81B6-CF69A802483E}</Project>
|
||||
<Name>uEvents</Name>
|
||||
|
||||
@@ -244,12 +244,6 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Busineslogic\ConventionExtensions.cs" />
|
||||
<Compile Include="Busineslogic\DefaultVersion.cs" />
|
||||
<Compile Include="Busineslogic\Events.cs" />
|
||||
<Compile Include="Busineslogic\GithubSourcePull\ZipDownloader.cs" />
|
||||
<Compile Include="Busineslogic\MarkdownLogic.cs" />
|
||||
<Compile Include="DocumentationContentFinder.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user