-
-
Save bielawb/f6b41130a04b5c0cf07f3bab39d75004 to your computer and use it in GitHub Desktop.
Podpowiedzi - przykłady pomocy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// do konstruktora dodajemy _examples pobrane z pliku, by nie czytać ich za każdym razem... | |
internal HelpExamplePredictor(string guid) | |
{ | |
_guid = new Guid(guid); | |
string moduleFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | |
string ewsHelpPath = Path.Combine(moduleFolder, "EWS-help.xml"); | |
XmlDocument xmlDoc = new XmlDocument(); | |
xmlDoc.Load(ewsHelpPath); | |
XmlNamespaceManager manager = new XmlNamespaceManager(xmlDoc.NameTable); | |
manager.AddNamespace("dev", "http://schemas.microsoft.com/maml/dev/2004/10"); | |
_examples = new List<string>{}; | |
foreach (XmlNode node in xmlDoc.SelectNodes("*//dev:code", manager)) | |
{ | |
_examples.Add(node.InnerText.Replace(@"PS C:\> ", "")); | |
} | |
} | |
public SuggestionPackage GetSuggestion(PredictionClient client, PredictionContext context, CancellationToken cancellationToken) | |
{ | |
if (context.TokenAtCursor.TokenFlags == TokenFlags.CommandName) | |
{ | |
string command = context.TokenAtCursor.Text; | |
List<PredictiveSuggestion> suggestions = new List<PredictiveSuggestion>{}; | |
foreach (string example in _examples) | |
{ | |
if (example.ToLower().StartsWith(command.ToLower())) | |
{ | |
suggestions.Add(new PredictiveSuggestion(example)); | |
} | |
} | |
if (suggestions.Count == 0) | |
{ | |
return default; | |
} | |
else | |
{ | |
return new SuggestionPackage(suggestions); | |
} | |
} | |
else | |
{ | |
return default; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment