public string GetSampleFromID(string id, out SampleDesc desc) { desc = new SampleDesc(); string source; if (updates.TryGetValue(id, out source)) { return(source); } var entry = archive.FirstOrDefault(e => e.FullName == id); if (entry == null) { return(null); } desc = index[id]; using (var stream = new MemoryStream()) { entry.Extract(stream); stream.Position = 0; return(new StreamReader(stream).ReadToEnd()); } }
object ConvertPre(XElement e, bool insideFormat) { string content = e.Value; XElement result = null; SampleDesc desc; string snippet; if (!Application.ProcessingContext.ImportSamples) { return(null); } if ((snippet = Application.Samples.GetSampleFromContent(content, out desc)) != null) { result = new XElement("example", new XElement("code", new XAttribute("lang", desc.Language ?? "java"), // new XAttribute (XNamespace.Xml + "space", "preserve"), snippet)); } else { string language = content.TrimStart(); language = (string.IsNullOrEmpty(language) || language [0] != '<') ? "java" : "xml"; SampleDesc d = new SampleDesc { Language = language, FullTypeName = Application.ProcessingContext.CurrentType.FullName, DocumentationFilePath = Application.ProcessingContext.CurrentFilePath }; var id = Application.Samples.RegisterSample(content, d); result = new XElement("sample", new XAttribute("external-id", id)); } return(result); }
public void OverwriteSample(string hash, string content, SampleDesc newDesc) { if (!archive.ContainsEntry(hash)) { return; } UpdateEntry(archive, hash, content); index[hash] = newDesc; }
public static void Main(string[] args) { string samplesPath = args[0]; string inDir = args[1]; if (!File.Exists(samplesPath)) { Console.WriteLine("Couldn't find samples repository at {0}"); return; } if (!Directory.Exists(inDir)) { Console.WriteLine("Couldn't find input snippet directory"); return; } var langExtensions = new Dictionary <string, string> () { { ".xml", "XML" }, { ".cs", "C#" } }; SampleRepository samples = SampleRepository.LoadFrom(samplesPath); foreach (var file in Directory.EnumerateFiles(inDir, "*", SearchOption.AllDirectories)) { var extension = Path.GetExtension(file); var id = Path.GetFileNameWithoutExtension(file); if (string.IsNullOrEmpty(extension) || string.IsNullOrEmpty(id)) { continue; } string lang; if (!langExtensions.TryGetValue(extension, out lang) || !samples.IsValidID(id)) { Console.WriteLine("Not processed: {0}", Path.GetFileName(file)); continue; } SampleDesc oldDesc = samples.GetSampleDescFromID(id); samples.OverwriteSample(id, File.ReadAllText(file), new SampleDesc { ID = id, Language = lang, DocumentationFilePath = oldDesc.DocumentationFilePath, FullTypeName = oldDesc.FullTypeName }); Console.WriteLine("Done: {0}", id); } samples.Close(false); }
// Returns an id that can be used to register the sample position in the documentation flow public string RegisterSample(string source, SampleDesc desc) { var hash = StringHash(source); validFiles.Add(hash); desc.ID = hash; if (!archive.ContainsEntry(hash)) { updates.Add(hash, source); archive.AddEntry(hash, source, Encoding.UTF8); index[hash] = desc; } return(hash); }
public string GetSampleFromContent(string content, out SampleDesc desc) { return(GetSampleFromID(StringHash(content), out desc)); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SampleDesc obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }
public SampleDesc GetSampleInfo() { SampleDesc ret = new SampleDesc(ITexturePINVOKE.Texture_GetSampleInfo(swigCPtr), true); return(ret); }