private Task OnPreCompile(ISite site) { m_Site = site; AssetsHelper.AddTextAsset(Resources.code_snippet_css, site.MainPage, CSS_FILE_PATH); AssetsHelper.AddTextAsset(Resources.code_snippet_js, site.MainPage, JS_FILE_PATH); m_SnippetFileIds = new List <string>(); m_UsedTabIds = new Dictionary <IPage, List <string> >(); m_UsedSnippetIds = new Dictionary <IPage, List <string> >(); if (!string.IsNullOrEmpty(m_Settings.SnippetsFolder)) { try { m_SnippetsFolder = site.MainPage.FindFolder(PluginLocation.FromPath(m_Settings.SnippetsFolder)); } catch (AssetNotFoundException) { throw new PluginUserMessageException($"Failed to find the folder for snippets: '{m_Settings.SnippetsFolder}'"); } foreach (var snipAsset in m_SnippetsFolder.GetAllAssets()) { m_SnippetFileIds.Add(snipAsset.Id); } } return(Task.CompletedTask); }
public static IAsset FindAsset(ISite site, IAssetsFolder page, string path) { var loc = PluginLocation.FromPath(path); var folder = GetBaseFolder(site, page, loc); return(folder.FindAsset(loc)); }
public void Init(IDocifyApplication app, FilesPromoterPluginSettings setts) { m_App = app; m_Setts = setts; m_App.Loader.PreLoadFile += OnPreLoadFile; m_PromoteLocations = setts.Folders?.Select(f => PluginLocation.FromPath(f)).ToArray(); }
private IAssetsFolder FindSnippetFolder(ISite site, IPage page, ref string snipLoc) { IAssetsFolder snippetsBaseFolder = null; if (snipLoc.StartsWith(SNIPPETS_FOLDER_PATH)) { if (m_SnippetsFolder == null) { throw new PluginUserMessageException("Snippets folder is not set"); } snipLoc = snipLoc.TrimStart(SNIPPETS_FOLDER_PATH); snippetsBaseFolder = m_SnippetsFolder; } else { snippetsBaseFolder = AssetsHelper.GetBaseFolder(site, page, PluginLocation.FromPath(snipLoc)); } return(snippetsBaseFolder.FindFolder(PluginLocation.FromPath(snipLoc))); }
private void TestPluginLocation(PluginLocation originalLocation, PluginLocation savedLocation) { var testedProperties = new HashSet <string>(); foreach (var x in PluginLocationPropertiesWhichShouldBePersisted) { var loadedValue = PropertyHelper.GetPropertyValue(savedLocation, x.Key); var originalValue = PropertyHelper.GetPropertyValue(originalLocation, x.Key); loadedValue.Should().BeEquivalentTo(originalValue, $"Loading the property {x.Key} should be the same as the saved one"); testedProperties.Add(x.Key); } testedProperties.AddRange(PluginLocationPropertiesWhichShouldBeIgnored); var allProperties = (from prop in typeof(PluginLocation).GetProperties() where !prop.GetType().IsEnum select prop.Name) .ToList(); allProperties.Except(testedProperties).Should().BeEmpty("We want to test ALL TEH PROPERTIEZ"); }
private void MigratePluginLocation(Plugin oldPlugin, PluginLocation oldLocation, NewModels.PluginLocation newLocation) { var propertiesToMigrate = new HashSet <string> { nameof(PluginLocation.DllHash), nameof(PluginLocation.DllPath), nameof(PluginLocation.PluginName), nameof(PluginLocation.PluginName), nameof(PluginLocation.PluginVendor), nameof(PluginLocation.PluginProduct), nameof(PluginLocation.VstPluginId), nameof(PluginLocation.VendorVersion), nameof(PluginLocation.LastModifiedDateTime), }; foreach (var propertyName in propertiesToMigrate) { var oldValue = PropertyHelper.GetPropertyValue(oldLocation, propertyName); PropertyHelper.SetPropertyValue(newLocation, propertyName, oldValue); } newLocation.HasMetadata = oldPlugin.HasMetadata; }
public static void Main(string[] args) { FrontendInitializer.RegisterTypes(ServiceLocator.Default); FrontendInitializer.Initialize(ServiceLocator.Default); var vendorPresetParserService = ServiceLocator.Default.ResolveType <VendorPresetParserService>(); var logger = new RollingInMemoryLogListener(); LogManager.AddListener(logger); var pluginTestDirectory = @"C:\Program Files\VSTPlugins"; var testResults = new List <PluginTestResult>(); var presetParserDictionary = vendorPresetParserService.GetPresetHandlerListByPlugin(); var testData = ReadTestData(); var ignoredPlugins = ReadIgnoredPlugins(); List <string> IgnoredPresetParsers = new List <string>(); IgnoredPresetParsers.Add("VoidPresetParser"); var localLogger = new MiniConsoleLogger(); var hasIgnored = false; localLogger.SetConsoleLogLevelFilter(new HashSet <LogLevel> { LogLevel.Error, LogLevel.Warning }); if (args.Length > 0) { foreach (var key in presetParserDictionary.Keys.ToList()) { if (!presetParserDictionary[key].PresetParserType.ToLower().Contains(args[0].ToLower())) { presetParserDictionary.Remove(key); hasIgnored = true; } } } foreach (var presetParserKeyValue in presetParserDictionary) { var presetParser = presetParserKeyValue.Value; var pluginId = presetParserKeyValue.Key; if (IgnoredPresetParsers.Contains(presetParser.PresetParserType)) { continue; } if (IsIgnored(ignoredPlugins, presetParser.PresetParserType, pluginId)) { continue; } Console.Write(presetParser.PresetParserType + ": "); var start = DateTime.Now; var pluginLocation = new PluginLocation { DllPath = @"C:\Program Files\VstPlugins\Foobar.dll", IsPresent = true }; var plugin = new Plugin { VstPluginId = pluginId, PluginLocation = pluginLocation, PluginInfo = new VstPluginInfoSurrogate { ProgramCount = 1, Flags = VstPluginFlags.ProgramChunks, PluginID = pluginId } }; var stubProcess = new StubVstHostProcess(); stubProcess.PluginId = pluginId; var remoteInstance = new RemotePluginInstance(stubProcess, plugin); presetParser.DataPersistence = new NullPresetPersistence(); presetParser.PluginInstance = remoteInstance; presetParser.RootBank = plugin.RootBank.First(); presetParser.Logger.Clear(); presetParser.Logger.MirrorTo(localLogger); var testResult = new PluginTestResult { VendorPresetParser = presetParser.PresetParserType, PluginId = plugin.VstPluginId }; double timeForNumPresets = 0; double timeForDoScan = 0; double totalTime = 0; try { presetParser.Init(); testResult.ReportedPresets = presetParser.GetNumPresets(); timeForNumPresets = (DateTime.Now - start).TotalSeconds; start = DateTime.Now; presetParser.DoScan().GetAwaiter().GetResult(); timeForDoScan = (DateTime.Now - start).TotalSeconds; totalTime = timeForNumPresets + timeForDoScan; } catch (Exception e) { testResult.Error = "Errored"; Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } testResult.Presets = plugin.Presets.Count; var timePerPreset = (totalTime / testResult.Presets) * 1000; // ReSharper disable once LocalizableElement Console.WriteLine( $"{testResult.Presets} parsed in {totalTime:F3}s (avg {timePerPreset:F3}ms / Preset, DoScan {timeForDoScan:F3}s, NumPresets {timeForNumPresets:F3}s"); var testDataEntries = GetTestDataEntries(testData, presetParser.PresetParserType, pluginId); var hasTestDataEntries = testDataEntries.Count > 0; var testDataOk = true; foreach (var preset in plugin.Presets) { if (preset.Metadata.BankPath == "") { testResult.BankMissing++; } foreach (var testDataEntry in testDataEntries.ToList()) { if (preset.Metadata.PresetName == testDataEntry.ProgramName && preset.Metadata.BankPath == testDataEntry.BankPath) { var testFilename = PathUtils.SanitizeFilename( testDataEntry.PresetParser + "." + preset.OriginalMetadata.PresetName + ".testdata"); var myDocumentsTestDataFile = Path.Combine(GetPatchFilesDirectory(), testFilename); var localTestDataFile = Path.Combine("TestData", testFilename); var presetHash = testDataEntry.Hash.TrimEnd(); if (preset.PresetHash != presetHash) { var fileMessage = ""; var wrongPresetData = myDocumentsTestDataFile + ".wrong"; testDataOk = false; if (File.Exists(myDocumentsTestDataFile)) { fileMessage = $"Original preset data in {myDocumentsTestDataFile}" + Environment.NewLine + $"Current (wrong) preset data in {wrongPresetData}"; } else { fileMessage = $"Original preset data not found (expected in {myDocumentsTestDataFile})" + Environment.NewLine + $"Current (wrong) preset data in {wrongPresetData}"; } File.WriteAllBytes(wrongPresetData, LZ4Pickler.Unpickle( NullPresetPersistence.PresetData[preset.OriginalMetadata.SourceFile])); testResult.DetailedErrors.Add( $"Found preset {testDataEntry.ProgramName} with bank path " + $"{testDataEntry.BankPath} but the preset hashes were different. " + $"Expected hash {presetHash} but found hash {preset.PresetHash}" + Environment.NewLine + Environment.NewLine + $"{fileMessage}"); } else { // Check if the file exists in the output directory if (!File.Exists(myDocumentsTestDataFile)) { if (File.Exists(localTestDataFile)) { File.Copy(localTestDataFile, myDocumentsTestDataFile); } else { File.WriteAllBytes(myDocumentsTestDataFile, LZ4Pickler.Unpickle( NullPresetPersistence.PresetData[preset.OriginalMetadata.SourceFile])); } } else { if (!File.Exists(localTestDataFile)) { testResult.DetailedErrors.Add( $"Warning: The preset data file {testFilename} exists in the documents " + "folder but not in the source folder. Copy from documents to git folder. " + "If already done, remember to clean the presetparsertest project."); } } var hash = HashUtils.getIxxHash(File.ReadAllBytes(myDocumentsTestDataFile)); if (hash != presetHash) { testResult.DetailedErrors.Add( $"Warning: The preset data file {myDocumentsTestDataFile} exists but does not match the " + $"preset hash from the reference presets. Expected: {testDataEntry.Hash} found {hash}"); } } testDataEntries.Remove(testDataEntry); } } } if (testDataEntries.Count > 0) { foreach (var missingTestDataEntry in testDataEntries) { var presetHash = missingTestDataEntry.Hash.TrimEnd(); testResult.DetailedErrors.Add( $"Did not find preset {missingTestDataEntry.ProgramName} with bank path " + $"{missingTestDataEntry.BankPath} and hash {presetHash}"); } testResult.IsOK = false; } if (plugin.Presets.Count > 0) { var randomPreset = plugin.Presets.OrderBy(qu => Guid.NewGuid()).First(); testResult.RndHash = randomPreset.PresetHash; testResult.RndPresetName = randomPreset.Metadata.PresetName; testResult.RndBankPath = randomPreset.Metadata.BankPath; } var mockFxp = Path.Combine(Directory.GetCurrentDirectory(), "mock.fxp"); var fxp = new FXP(); fxp.ReadFile(Path.Combine(Directory.GetCurrentDirectory(), "test.fxp")); fxp.FxID = VstUtils.PluginIdNumberToIdString(pluginId); fxp.WriteFile(mockFxp); // Test additional banks var bankFile = new BankFile(); bankFile.Path = mockFxp; bankFile.BankName = "Default"; plugin.AdditionalBankFiles.Clear(); plugin.AdditionalBankFiles.Add(bankFile); bool additionalBankFileCountOk = false; if (presetParser.GetNumPresets() == testResult.ReportedPresets + 1) { additionalBankFileCountOk = true; } else { testResult.Error += " additionalBankFileCount failed"; } plugin.Presets.Clear(); NullPresetPersistence.PresetData.Clear(); presetParser.DoScan().GetAwaiter().GetResult(); var additionalBankFileScanOk = false; if (plugin.Presets.Count == testResult.Presets + 1) { additionalBankFileScanOk = true; } else { testResult.Error += " additionalBankFileScan failed"; } bool bankMissingOk = false; if (NumBankMissingsOk.ContainsKey(testResult.PluginId)) { if (testResult.BankMissing <= NumBankMissingsOk[testResult.PluginId]) { bankMissingOk = true; } } else { if (testResult.BankMissing < 2) { bankMissingOk = true; } } if (hasTestDataEntries && testDataOk && testResult.Presets > 5 && bankMissingOk && testResult.Presets == testResult.ReportedPresets && additionalBankFileCountOk && additionalBankFileScanOk) { testResult.IsOK = true; } testResults.Add(testResult); NullPresetPersistence.PresetData.Clear(); } var consoleTable = ConsoleTable.From(from testRes in testResults where testRes.IsOK == false orderby testRes.Presets select testRes); Console.WriteLine(consoleTable.ToMinimalString()); foreach (var testRes in (from testRes in testResults where testRes.DetailedErrors.Count > 0 orderby testRes.Presets select testRes)) { Console.WriteLine(Environment.NewLine); Console.WriteLine($"Detailed Errors for {testRes.VendorPresetParser}"); Console.WriteLine($"------------------------------------------------------------"); foreach (var detailedError in testRes.DetailedErrors) { Console.WriteLine($"Error #{testRes.DetailedErrors.IndexOf(detailedError)}: {detailedError}"); } } Console.WriteLine($"Stuff left: {consoleTable.Rows.Count} / {presetParserDictionary.Count}"); foreach (var data in GlobalMethodTimeLogger.GetTopMethods()) { Console.WriteLine($"{data.Name}: {data.Duration.TotalSeconds.ToString()}ms"); } if (hasIgnored) { Console.WriteLine("Warning: Filter active!!"); Console.WriteLine("Warning: Filter active!!"); Console.WriteLine("Warning: Filter active!!"); Console.WriteLine("Warning: Filter active!!"); Console.WriteLine("Warning: Filter active!!"); Console.WriteLine("Warning: Filter active!!"); Console.WriteLine("Warning: Filter active!!"); } }
private async Task WriteCodeSnippet(StringBuilder html, IPage page, string filePath, string lang, string[] exclRegs, bool leftAlign, string[] regs) { IAsset snipAsset; try { var searchFolder = FindSnippetFolder(m_Site, page, ref filePath); var fileName = new PluginLocation("", Path.GetFileName(filePath), Enumerable.Empty <string>()); snipAsset = searchFolder.FindAsset(fileName); } catch (Exception ex) { throw new NullReferenceException($"Failed to find code snippet: '{filePath}'", ex); } if (snipAsset != null) { if (!m_SnippetFileIds.Contains(snipAsset.Id)) { m_SnippetFileIds.Add(snipAsset.Id); } var rawCode = snipAsset.AsTextContent(); if (string.IsNullOrEmpty(lang)) { lang = Path.GetExtension(snipAsset.FileName).TrimStart('.').ToLower(); } var snips = CodeSnippetHelper.Select(rawCode, lang, new CodeSelectorOptions() { ExcludeRegions = exclRegs, LeftAlign = leftAlign, Regions = regs }); foreach (var snip in snips) { var snipClass = ""; switch (snip.Location) { case SnippetLocation_e.Full: snipClass = ""; break; case SnippetLocation_e.Start: snipClass = "jagged-bottom"; break; case SnippetLocation_e.End: snipClass = "jagged-top"; break; case SnippetLocation_e.Middle: snipClass = "jagged"; break; } var code = $"~~~{lang} {snipClass}\r\n{snip.Code}\r\n~~~"; html.AppendLine(await m_App.Compiler.StaticContentTransformer.Transform(code)); } } else { throw new InvalidCastException($"Failed to find an asset at '{filePath}'"); } }