public void Init(int id, string name) { try { var input = File.ReadAllText(name); var ms = new MemoryStream(Encoding.UTF8.GetBytes(input)); var lexer = new NinjaLexer(new AntlrInputStream(ms)); var tokens = new CommonTokenStream(lexer); IList <IToken> tokenList = tokens.GetTokens(); Main.Log("Lexems of the program:"); Main.Log(tokenList.Count + " lexems"); foreach (var elem in tokenList) { Main.Log("Lexem: " + elem.Text); } parser = new NinjaParser(tokens); parser.owner = this; parser.id = id; var tree = parser.program(); } catch (Exception exc) { //Main.Log("Error in " + exc.StackTrace + ": " + exc.Message); //messages.Enqueue(Main.FormMessage("Программа ниндзя " + ninjaName + " завершилась с ошибкой.")); } }
public Dictionary <string, ItemList <FilterEconomy.Model.NinjaItem> > PerformRequest(string league, string variation, string branchKey, string url, string prefix, RequestType requestType, string baseStoragePath, string ninjaUrl) { var economySegmentBranch = url; var directoryPath = $"{baseStoragePath}/{variation}/{league}/{StringWork.GetDateString()}"; var fileName = $"{branchKey}.txt"; var fileFullPath = $"{directoryPath}/{fileName}"; string responseString; try { if (File.Exists(fileFullPath) && requestType != RequestType.ForceOnline) { // Load existing file responseString = FileWork.ReadFromFile(fileFullPath); } else { // Request online file var urlRequest = $"{ninjaUrl}{economySegmentBranch}{prefix}league={variation}"; responseString = new RestRequest(urlRequest).Execute(); // poeNinja down -> use most recent local file if (responseString == null || responseString.Length < 400) { var recentFile = Directory.EnumerateDirectories(directoryPath.Replace(StringWork.GetDateString(), "")).OrderByDescending(Directory.GetCreationTime).FirstOrDefault(); if (recentFile != null) { responseString = FileWork.ReadFromFile(recentFile + "/" + fileName); if (responseString != null && responseString.Length >= 400) { if (!didShowNinjaOfflineMessage) { InfoPopUpMessageDisplay.ShowInfoMessageBox("Could not connect to poeNinja. used recent local file instead: " + recentFile + "/" + fileName); this.didShowNinjaOfflineMessage = true; } } } } // Store locally Task.Run(() => FileWork.WriteTextAsync(fileFullPath, responseString)); } if (responseString == null || responseString.Length < 400) { InfoPopUpMessageDisplay.ShowError("poeNinja web request or file content is null/short:\n\n\n" + responseString); responseString = ""; } } catch { throw new Exception("Failed to load economy file: " + branchKey); } var result = NinjaParser.CreateOverviewDictionary(NinjaParser.ParseNinjaString(responseString).ToList()); return(result); }
public void Init() { var input = File.ReadAllText("..\\..\\nnj.npr"); var ms = new MemoryStream(Encoding.UTF8.GetBytes(input)); var lexer = new NinjaLexer(new AntlrInputStream(ms)); var tokens = new CommonTokenStream(lexer); parser = new NinjaParser(tokens); var tree = parser.program(); }
// public class ParamList // { // private ArrayList<NinjaParser.ParamData> _list = new ArrayList<NinjaParser.ParamData>(); // // public void Add(NinjaParser.ParamData data) // { // _list.Add(data); // } // // public override string ToString() // { // if (_list.Count == 0) // { // return "<no params>"; // } // // string s = "{"; // foreach (var data in _list) // { // s += $"{data.type} ,"; // } // // s = s.Substring(0, s.Length - 1) + "}"; // return s; // } // } private static void Initialize() { try { Process proc = new Process { StartInfo = { FileName = "CMD.exe", Arguments = @"/c ..\..\..\Interpreter\antlr.bat ..\..\..\Interpreter\Ninja.g4", WindowStyle = ProcessWindowStyle.Hidden } }; proc.Start(); proc.WaitForExit(); var input = File.ReadAllText("..\\..\\nnj.npr"); var ms = new MemoryStream(Encoding.UTF8.GetBytes(input)); var lexer = new NinjaLexer(new AntlrInputStream(ms)); var tokens = new CommonTokenStream(lexer); // tokens.Fill(); /* foreach(var tok in tokens.GetTokens()) * { * Console.WriteLine(tok); * }*/ var parser = new NinjaParser(tokens); var tree = parser.program(); var pastwk = new ParseTreeWalker(); pastwk.Walk(new NinjaAdvancedListener(), tree); } catch (Exception e) { Console.WriteLine(e.Message); } initialized = true; }
public Dictionary <string, ItemList <FilterEconomy.Model.NinjaItem> > PerformRequest(string league, string leagueType, string branchKey, string url, string baseStoragePath) { var economySegmentBranch = url; var directoryPath = $"{baseStoragePath}/{leagueType}/{league}/{StringWork.GetDateString()}"; var fileName = $"{branchKey}.txt"; var fileFullPath = $"{directoryPath}/{fileName}"; string responseString; try { if (FilterPolishConfig.ActiveRequestMode != RequestType.ForceOnline && File.Exists(fileFullPath)) { // Load existing file LoggingFacade.LogInfo($"Loading Economy: Loading Cached File {fileFullPath}"); responseString = FileWork.ReadFromFile(fileFullPath); } else { // Request online file string variation = this.CreateNinjaLeagueParameter(league, leagueType); var urlRequest = $"{economySegmentBranch}&league={variation}"; try { responseString = new RestRequest(urlRequest).Execute(); } catch (Exception) { LoggingFacade.LogError($"Loading Economy: Requesting From Ninja {urlRequest}"); responseString = null; } // poeNinja down -> use most recent local file if ((responseString == null || responseString.Length < 400) && FilterPolishConfig.ActiveRequestMode == RequestType.Dynamic) { var recentFile = Directory .EnumerateDirectories(directoryPath.Replace(StringWork.GetDateString(), "")) .Where(x => File.Exists(x + "/" + fileName)) .OrderByDescending(Directory.GetCreationTime) .FirstOrDefault(); if (recentFile != null && File.Exists(recentFile + "/" + fileName)) { responseString = FileWork.ReadFromFile(recentFile + "/" + fileName); if (responseString != null && responseString.Length >= 400) { if (!didShowNinjaOfflineMessage) { LoggingFacade.LogWarning("Could not connect to poeNinja. used recent local file instead: " + recentFile + "/" + fileName); this.didShowNinjaOfflineMessage = true; } } } else { throw new Exception("did not find any old ninja files"); } } if (!string.IsNullOrEmpty(responseString) && FilterPolishConfig.ActiveRequestMode == RequestType.Dynamic) { // Store locally FileWork.WriteText(fileFullPath, responseString); } } if (responseString == null || responseString.Length < 400) { LoggingFacade.LogError("poeNinja web request or file content is null/short:\n\n\n" + responseString); throw new Exception("poeNinja web request or file content is null/short:\n\n\n" + responseString); } } catch (Exception e) { LoggingFacade.LogError("Failed to load economy file: " + branchKey + ": " + e); return(null); } var result = NinjaParser.CreateOverviewDictionary(NinjaParser.ParseNinjaString(responseString, branchKey).ToList()); return(result); }