Esempio n. 1
0
        private void UploadToPoe_Single(string filterId, string accessToken, string descr, string filterContent)
        {
            var url = "https://www.pathofexile.com/api/item-filter/" + filterId + "?access_token=" + accessToken;

            var body = new
            {
                filter      = filterContent,
                filterID    = filterId,
                description = descr,
                version     = FilterAccessFacade.GetInstance().PrimaryFilter.GetHeaderMetaData("VERSION")
            };

            LoggingFacade.LogInfo($"[PoeUpload] Sending request...");

            var resp = FileDownloader.StaticHttpClient.PostAsJsonAsync(url, body);

            resp.Wait();
            if (resp.Result.StatusCode != HttpStatusCode.OK)
            {
                LoggingFacade.LogError($"[PoeUpload] Error: " + resp.Result.StatusCode);
            }
            else
            {
                LoggingFacade.LogInfo($"[PoeUpload] Success");
            }
        }
 public static void Check(bool condition, string message)
 {
     if (condition)
     {
         LoggingFacade.LogError(message);
         Throw(message);
     }
 }
 public static string Run([ActivityTrigger] string req, ILogger log)
 {
     log.LogInformation("C# HTTP trigger function processed a request.");
     try
     {
         FilterGen.Execute(req, log);
         return("finished generation succesfully!");
     }
     catch (Exception e)
     {
         LoggingFacade.LogError("ERROR: " + e.Message);
         return(e.ToString());
     }
 }
Esempio n. 4
0
 public static string ReadFromFile(string adress)
 {
     try
     {   // Open the text file using a stream reader.
         var logFile = File.ReadAllText(adress);
         return(logFile);
     }
     catch (Exception e)
     {
         Console.WriteLine("The file could not be read:");
         Console.WriteLine(e.Message);
         LoggingFacade.LogError("File cound not be read. Path: " + adress + ". Error: " + e.Message);
         return(null);
     }
 }
        public void RequestPoeLeagueInfo()
        {
            this.PoeLeagues.Clear();
            string responseString;

            // Obtaining League Info
            try
            {
                responseString = new RestRequest("http://api.pathofexile.com/leagues").Execute();
            }
            catch (Exception)
            {
                LoggingFacade.LogError($"Error obtaining League Information! PoE Api unresponsive?");
                responseString = null;
            }

            List <PoeLeague> filteredLeagues;

            try
            {
                var leagues = JsonConvert.DeserializeObject <IEnumerable <PoeLeague> >(responseString, new JsonSerializerSettings()
                {
                    CheckAdditionalContent = true
                });

                filteredLeagues = leagues
                                  .Where(x => !x.Id.Contains("Standard"))
                                  .Where(x => !x.Id.Contains("SSF"))
                                  .Where(x => !x.Id.Contains("Event"))
                                  .Where(x => !x.Id.Contains("Race"))
                                  .Where(x => x.Id != "Hardcore")
                                  .ToList();

                filteredLeagues.ForEach(x => this.PoeLeagues.Add(x.Id, x));
                filteredLeagues.ForEach(x => LoggingFacade.LogInfo($"League Detected: {x.Id}"));
            }
            catch (Exception)
            {
                LoggingFacade.LogError($"Error deserializing or filtering league data!");
                responseString = null;
            }
        }
Esempio n. 6
0
        public static string Run([ActivityTrigger] string req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            Logging?.Clean();
            Logging = LoggingFacade.GetInstance();

            Logging.SetCustomLoggingMessage((s) => log.LogInformation(s));

            try
            {
                PerformMainRoutine(req);
                return("finished generation succesfully!");
            }
            catch (Exception e)
            {
                LoggingFacade.LogError("ERRROR: " + e.Message);
                return(e.Message);
            }
        }
Esempio n. 7
0
        private void SelectSeedFilterFile(object sender, RoutedEventArgs e)
        {
            var fd = new OpenFileDialog();

            if (fd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            var filePath = fd.FileName;
            var lineList = FileWork.ReadLinesFromFile(filePath);

            if (lineList == null || lineList.Count < 4500)
            {
                LoggingFacade.LogError("Warning: (seed) filter result line count: " + lineList?.Count);
            }
            this.FilterAccessFacade.PrimaryFilter = new Filter(lineList);

            this.ResetAllComponents();
            this.LoadAllComponents();
            this.EventGrid.Publish();
        }
        public void LoadFromSaveFile(string branchKey)
        {
            var filePath = this.GetItemInfoSaveFilePath(branchKey);

            if (File.Exists(filePath))
            {
                var fileText = File.ReadAllText(filePath);
                if (fileText.Length < 2)
                {
                    LoggingFacade.LogWarning("ItemAspect saveFile empty for: " + branchKey);
                }
                this.Deserialize(branchKey, fileText);
            }
            else
            {
                LoggingFacade.LogError("no ItemAspect saveFile for: " + branchKey);
            }

            var economyData = EconomyRequestFacade.GetInstance();

            this.MigrateAspectDataToEcoData(economyData, branchKey);
        }
Esempio n. 9
0
        public static async Task WriteFilter(Filter baseFilter, bool isGeneratingStylesAndSeed, string outputFolder, string styleSheetFolderPath)
        {
            var isStopping = VerifyFilter(baseFilter);

            if (isStopping)
            {
                return;
            }

            new FilterTableOfContentsCreator(baseFilter).Run();

            const string filterName       = "NeverSink's";
            var          generationTasks  = new List <Task>();
            var          seedFilterString = baseFilter.Serialize();

            if (isGeneratingStylesAndSeed)
            {
                var seedPath = outputFolder + "ADDITIONAL-FILES\\SeedFilter\\";
                if (!Directory.Exists(seedPath))
                {
                    Directory.CreateDirectory(seedPath);
                }
                seedPath += filterName + " filter - SEED (SeedFilter) .filter";
                generationTasks.Add(FileWork.WriteTextAsync(seedPath, seedFilterString));
            }

            baseFilter = new Filter(seedFilterString); // we do not want to edit the seedFilter directly and execute its tag commands
            baseFilter.ExecuteCommandTags();
            var baseFilterString = baseFilter.Serialize();

            if (baseFilterString == null || baseFilterString.Count < 4500)
            {
                LoggingFacade.LogError("Warning: (seed) filter result line count: " + baseFilterString?.Count);
            }

            for (var strictnessIndex = 0; strictnessIndex < FilterGenerationConfig.FilterStrictnessLevels.Count; strictnessIndex++)
            {
                if (isGeneratingStylesAndSeed)
                {
                    foreach (var style in FilterGenerationConfig.FilterStyles)
                    {
                        if (style.ToLower() == "default" || style.ToLower() == "backup" || style.ToLower() == "streamsound")
                        {
                            continue;
                        }
                        generationTasks.Add(GenerateFilter_Inner(style, strictnessIndex));
                    }
                }

                // default style
                generationTasks.Add(GenerateFilter_Inner("", strictnessIndex));
            }

            if (isGeneratingStylesAndSeed)
            {
                generationTasks.Add(GenerateFilter_Inner("", 3, 2, explicitName: "NeverSink's filter - 1X-ConStrict"));
                generationTasks.Add(GenerateFilter_Inner("", 4, 2, explicitName: "NeverSink's filter - 2X-ConStrict"));
                generationTasks.Add(GenerateFilter_Inner("", 4, 3, explicitName: "NeverSink's filter - 3X-ConStrict"));
                generationTasks.Add(GenerateFilter_Inner("", 5, 3, explicitName: "NeverSink's filter - 4X-ConStrict"));
                generationTasks.Add(GenerateFilter_Inner("", 6, 3, explicitName: "NeverSink's filter - 5X-ConStrict"));
            }

            await Task.WhenAll(generationTasks);

            LoggingFacade.LogInfo("Filter generation successfully done!", true);

            // local func
            async Task GenerateFilter_Inner(string style, int strictnessIndex, int?consoleStrictness = null, string explicitName = null)
            {
                var filePath = outputFolder;
                var fileName = filterName + " filter - " + strictnessIndex + "-" + FilterGenerationConfig.FilterStrictnessLevels[strictnessIndex].ToUpper();
                var filter   = new Filter(baseFilterString);

                LoggingFacade.LogDebug($"GENERATING: {fileName}");

                new FilterTableOfContentsCreator(filter).Run();
                filter.ExecuteStrictnessCommands(strictnessIndex, consoleStrictness);

                if (style != "")
                {
                    new StyleGenerator(filter, styleSheetFolderPath + style + ".fsty", style).Apply();
                    filePath += "(STYLE) " + style.ToUpper() + "\\";
                    fileName += " (" + style + ") ";
                }

                if (consoleStrictness.HasValue)
                {
                    // little dirty fix
                    filePath += "(Console-Strictness)\\";
                    fileName += " Console-Strictness ";
                }

                if (explicitName != null)
                {
                    fileName = explicitName;
                }

                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }

                var result = filter.Serialize();

                if (result.Count <= seedFilterString?.Count)
                {
                    LoggingFacade.LogError("Error: style/strictness variant is smaller size than seed");
                }

                await FileWork.WriteTextAsync(filePath + "\\" + fileName + ".filter", result);

                LoggingFacade.LogInfo($"DONE GENERATING: {fileName}");
            }
        }
        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);
        }
 public static void Throw(string message)
 {
     LoggingFacade.LogError(message);
     throw new Exception(message);
 }