using OpenMetaverse; using OpenMetaverse.ImportExport.Collada14; using RestSharp.Extensions; using SecondBotEvents.Services; using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Net; using System.Reflection; using System.Resources; using System.Security.Policy; using System.Text; using System.Threading.Tasks; using static log4net.Appender.RollingFileAppender; namespace SecondBotEvents { public class WikiMake { protected SimpleIO IO = new(); protected string version = ""; protected string htmltemplate = ""; public WikiMake() { IO.ChangeRoot("Static"); htmltemplate = IO.ReadFile("template.html"); version = AssemblyInfo.GetGitHash(); LogFormater.Info("Creating wiki files"); IO.ChangeRoot("wiki"); makehome(); } protected void makehome() { Dictionary commandmodules = http_commands_helper.getCommandModules(); string content = "
"; foreach (KeyValuePair entry in commandmodules) { Type endpointtype = entry.Value; string namespaceworker = entry.Key.ToLower(); string url = namespaceworker + ".html"; int commandcount = 0; foreach (MethodInfo M in endpointtype.GetMethods()) { foreach (CustomAttributeData At in M.CustomAttributes) { if (At.AttributeType.Name == "About") { commandcount++; break; } } } string about = entry.Value.GetAttribute().classinfo; string card = "
" + "
" + "
" + namespaceworker.FirstCharToUpper() + "
" + "

" + about.Split("" + "View " + commandcount.ToString() + " commands" + "

" + "
"; content = content + card; makecommandlist(endpointtype, namespaceworker, about); } makefile("index", content, "Index"); } protected string makeCommandList(string namespaceworker, List commands) { commands = commands.OrderBy(x => x.Name).ToList(); string reply = "
"; foreach (MethodInfo M in commands) { string about = ""; foreach (CustomAttributeData At in M.CustomAttributes) { if (At.AttributeType.Name == "About") { about = M.GetAttribute().about; break; } } if(about == "") { about = "No description"; } if(about.Contains("
") == true) { about = about.Split("
")[0]; } if (about.Contains("\n") == true) { about = about.Split("\n")[0]; } string url = "command" + M.Name.ToLower() + ".html"; reply = reply + ""; reply = reply + "
"; reply = reply + "" + M.Name+""; reply = reply + "
"; reply = reply + "

" + about + "

"; reply = reply + "
"; makecommandfile(namespaceworker, M, about); } reply = reply + "
"; return reply; } protected void makecommandlist(Type endpoint, string namespaceworker, string aboutnamespace) { List getCommands = []; List setCommands = []; List doCommands = []; foreach (MethodInfo M in endpoint.GetMethods()) { foreach (CustomAttributeData At in M.CustomAttributes) { if (typeof(CmdType).IsAssignableFrom(At.AttributeType)) { if (At.AttributeType.Name == "CmdTypeGet") { getCommands.Add(M); } else if (At.AttributeType.Name == "CmdTypeSet") { setCommands.Add(M); } else if (At.AttributeType.Name == "CmdTypeDo") { doCommands.Add(M); } break; } } } string content = ""; if (((getCommands.Count > 0) || (setCommands.Count > 0)) && (doCommands.Count == 0)) { // get set only (no do commands) content = "
<- Back to command sections
" + "

" + namespaceworker.FirstCharToUpper() + "

" + aboutnamespace + "

" + "
" + "
" + "" + "" + ""; content = content + "" + "" + "
Get (" + getCommands.Count.ToString() + ") / Set (" + setCommands.Count.ToString() + ")
" + makeCommandList(namespaceworker, getCommands) + "" + makeCommandList(namespaceworker, setCommands) + "
"; } else if (((getCommands.Count == 0) && (setCommands.Count == 0)) && (doCommands.Count > 0)) { // Do only (no get/set commands) content = "
<- Back to command sections
" + "

" + namespaceworker.FirstCharToUpper() + "

" + aboutnamespace + "

" + "
" + "
" + "" + "" + ""; content = content + "" + "" + "
Do (" + doCommands.Count.ToString() + ")
" + makeCommandList(namespaceworker, doCommands) + "
"; } else if ((getCommands.Count > 4) && (setCommands.Count > 4)) { // mix of both content = "
<- Back to command sections
" + "

" + namespaceworker.FirstCharToUpper() + "

" + aboutnamespace + "

" + "
" + "
" + "" + "" + "" + "" + ""; content = content + "" + "" + "" + "" + "
Get (" + getCommands.Count.ToString() + ")Set (" + setCommands.Count.ToString() + ")Do (" + doCommands.Count.ToString() + ")
" + makeCommandList(namespaceworker, getCommands) + "" + makeCommandList(namespaceworker, setCommands) + "" + makeCommandList(namespaceworker, doCommands) + "
"; } else { // mix of both content = "
<- Back to command sections
" + "

" + namespaceworker.FirstCharToUpper() + "

" + aboutnamespace + "

" + "
" + "
" + "" + "" + "" + ""; content = content + "" + "" + "" + "
Get (" + getCommands.Count.ToString() + ") / Set (" + setCommands.Count.ToString() + ")Do (" + doCommands.Count.ToString() + ")
" + makeCommandList(namespaceworker, getCommands) + "" + makeCommandList(namespaceworker, setCommands) + "" + makeCommandList(namespaceworker, doCommands) + "
"; } makefile(namespaceworker, content, "Command list for "+ namespaceworker.FirstCharToUpper()); } protected void makecommandfile(string namespaceworker, MethodInfo method, string methodabout) { string content = "
<- Back to "+namespaceworker.FirstCharToUpper()+"
" + "

" + method.Name + "

" + methodabout + "

" + "
"; Dictionary hints = []; Dictionary hinttypes = []; Dictionary hintexamplevalue = []; Dictionary hintacceptvalues = []; string examplecall = method.Name; foreach (ArgHints At in method.GetCustomAttributes()) { hints.Add(At.name, At.about); hinttypes.Add(At.name, At.defaultValueType); hintexamplevalue.Add(At.name, At.exampleValue); hintacceptvalues.Add(At.name, At.acceptedValues); } if (method.GetParameters().Length > 0) { content = content + "
Args
"; content = content + ""; content = content + ""; bool hadStartSplit = false; string addon = ""; foreach (ParameterInfo pram in method.GetParameters()) { if(hadStartSplit == false) { hadStartSplit = true; examplecall = examplecall + "###"; } content = content + ""; content = content + ""; string hinttext = ""; string hinttype = ""; string hintexample = ""; string hintexamplecmd = ""; string hinttextsuggested = ""; if(hintacceptvalues.ContainsKey(pram.Name) == true) { if (hintacceptvalues[pram.Name] != null) { hinttextsuggested = ""; string addoncsv = ""; int loop = 0; foreach(string a in hintacceptvalues[pram.Name]) { if (loop == 3) { hinttextsuggested = hinttextsuggested + "
"; addoncsv = ""; loop = 0; } hinttextsuggested = hinttextsuggested + addoncsv; hinttextsuggested = hinttextsuggested + a; addoncsv = ", "; loop++; } } } if (hintexamplevalue.ContainsKey(pram.Name) == true) { if (hintexamplevalue[pram.Name] != null) { hintexample = hintexamplevalue[pram.Name]; hintexamplecmd = hintexamplevalue[pram.Name]; } } if (hinttypes.ContainsKey(pram.Name) == true) { hinttype = hinttypes[pram.Name]; if (hinttype == "UUID") { hintexample = UUID.Random().ToString(); hintexamplecmd = hintexample; } else if (hinttype == "AVATAR") { hintexample = "Firstname Lastname or UUID"; hintexamplecmd = "Madpeter Zond"; } else if(hinttype == "BOOL") { hintexample = "false"; hintexamplecmd = "true"; } else if(hinttype == "SMART") { hintexample = "HTTP URL, Avatar UUID or chat chanel"; hintexamplecmd = "1234"; } } if (hints.ContainsKey(pram.Name) == true) { if (hints[pram.Name] != null) { hinttext = hints[pram.Name]; } } examplecall = examplecall + addon + "" + hintexamplecmd; addon = "~#~"; content = content + "" + "" + "" + "" + "" + ""; } content = content + "
NameHintTypeExample valueSupported values
" + pram.Name + "" + hinttext + ""+ hinttype+""+ hintexample +"" + hinttextsuggested + "
"; } content = content + "
Return hints
    "; foreach (ReturnHints At in method.GetCustomAttributes()) { content = content + "
  • ☑ "+At.hint+"
  • "; } foreach (ReturnHintsFailure At in method.GetCustomAttributes()) { content = content + "
  • ❌ "+ At.hint+"
  • "; } content = content + "

Example call

"+examplecall+"

"; makefile("command"+method.Name.ToLower(), content, "Command info for " + method.Name); } protected void makefile(string file, string content, string title) { string pagecontent = htmltemplate; pagecontent = pagecontent.Replace("[[PAGETITLE]]", "Secondbot [Events] command wiki / "+title); pagecontent = pagecontent.Replace("[[BUILDVERSION]]", version); pagecontent = pagecontent.Replace("[[BUILDDATE]]", "Wiki created:"+DateTime.Now.ToString("dd/MM/yyyy")); pagecontent = pagecontent.Replace("[[CONTENT]]", content); IO.WriteFile(file+".html", pagecontent); } } }