Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
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)
            {
                InfoPopUpMessageDisplay.ShowError("Warning: (seed) filter result line count: " + lineList?.Count);
            }
            this.FilterAccessFacade.PrimaryFilter = new Filter(lineList);

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

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

            var economyData = EconomyRequestFacade.GetInstance();

            this.MigrateAspectDataToEcoData(economyData, branchKey);
        }
Exemplo n.º 4
0
        private Filter PerformFilterWork()
        {
            var    outputFolder = Configuration.AppSettings["Output Folder"];
            var    defaultPath  = outputFolder + "\\Unnamed filter - SEED (SeedFilter) .filter";
            string filePath;

            if (System.IO.File.Exists(defaultPath))
            {
//                InfoPopUpMessageDisplay.ShowInfoMessageBox("unnamed seed used");
                filePath = defaultPath;
            }
            else
            {
                this.SelectSeedFilterFile(null, null);
                return(this.FilterAccessFacade.PrimaryFilter);
            }

            this.FilterRawString = FileWork.ReadLinesFromFile(filePath);
            if (this.FilterRawString == null || this.FilterRawString.Count < 4500)
            {
                InfoPopUpMessageDisplay.ShowError("Warning: (seed) filter result line count: " + this.FilterRawString?.Count);
            }
            return(new Filter(this.FilterRawString));
        }
Exemplo n.º 5
0
        public static async Task WriteFilter(Filter baseFilter, bool isGeneratingStylesAndSeed, string outputFolder = null)
        {
            var isStopping = VerifyFilter(baseFilter);

            if (isStopping)
            {
                return;
            }

            new FilterTableOfContentsCreator(baseFilter).Run();

            const string filterName = "NeverSink's";

            if (outputFolder == null)
            {
                outputFolder = Configuration.AppSettings["Output Folder"];
            }
            var styleSheetFolderPath = Configuration.AppSettings["StyleSheet Folder"];
            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)
            {
                InfoPopUpMessageDisplay.ShowError("Warning: (seed) filter result line count: " + baseFilterString?.Count);
            }

            for (var strictnessIndex = 0; strictnessIndex < FilterConstants.FilterStrictnessLevels.Count; strictnessIndex++)
            {
                if (isGeneratingStylesAndSeed)
                {
                    foreach (var style in FilterConstants.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);

            InfoPopUpMessageDisplay.ShowInfoMessageBox("Filter generation successfully done!");

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

                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)
                {
                    InfoPopUpMessageDisplay.ShowError("Error: style/strictness variant is smaller size than seed");
                }

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