internal override IContentSource Crawl(IContentSource content, bool asList) { if (content == null) return GetDefault(string.Format("Null content")); return asList ? CrawlList(content) : CrawlObject(content); }
private static void acceptVisitorForSource(IContentPlanVisitor visitor, IContentSource source) { visitor.Push(source); source.InnerSources.Each(s => acceptVisitorForSource(visitor, s)); visitor.Pop(); }
public bool IsNextPolicy(IContentSource source, ITransformerPolicy policy) { return source.Files.All(x => { var policies = _policies[x]; return policies.Any() && ReferenceEquals(policies.Peek(), policy); }); }
IContentSource CrawlObject(IContentSource content) { var match = Regex.Match(content.ToString(), Pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase); if (match == null || match.Groups.Count <= MatchGroup) return GetDefault(string.Format("Could not match pattern {0}", Pattern)); var plainContent = new PlainContent(); plainContent.ContentList.Add(match.Groups[MatchGroup].Value); return plainContent; }
public IContentSource ApplyTransform(IContentSource source, Type transformerType) { int index = findIndexOfSource(source); _sources.Remove(source); var transformer = typeof (Transform<>).CloseAndBuildAs<IContentSource>(source, transformerType); _sources.Insert(index, transformer); return transformer; }
public void DequeueTransformer(IContentSource source, ITransformerPolicy policy) { source.Files.Each(x => { var policies = _policies[x]; if (policies.FirstOrDefault() == policy) { policies.Dequeue(); } }); }
public void AddDependency(IContentSource source) { _lock.EnterWriteLock(); try { _dependencies.Add(source); } finally { _lock.ExitWriteLock(); } }
public TModel ReadJson <TModel>(string path, IContentSource source, Action <JsonSerializerSettings> settings) where TModel : class { string fullPath = Path.Combine(source.Path, path); // Validate path if (string.IsNullOrWhiteSpace(fullPath)) { throw new ArgumentException("The file path is empty or invalid.", nameof(fullPath)); } if (!File.Exists(fullPath)) { return(null); } // Read from file stream directly using (FileStream stream = File.OpenRead(fullPath)) { return(this.Deserialze <TModel>(stream, settings)); } }
private void LoadWeapons(IContentPack contentPack, IContentSource contentSource, ICoreTranslationHelper translationHelper, IEnumerable <ContentPackDataInfo> sources) { var weapons = (from source in sources from entry in source.Content.Weapons select new { Source = source, Name = entry.Key, Data = entry.Value }).ToArray(); // Create exceptions for conflicting item names Exception[] exceptions = (from itemGroup in this.GetDuplicateGroups(weapons, item => item.Name) select new Exception($"Weapon '{itemGroup.Key}' is being registered by multiple content files: {string.Join(", ", itemGroup.Select(item => $"'{item.Source.FullPath}'"))}")).ToArray(); // Throw the exceptions if (exceptions.Any()) { if (exceptions.Length > 1) { throw new AggregateException(exceptions); } throw exceptions.First(); } // Create each weapon foreach (var weapon in weapons) { ItemKey key = new ItemKey(contentPack.Manifest, weapon.Name); // Create the sprite for the object ISprite sprite = this.CreateSprite(contentSource, weapon.Source, weapon.Name, weapon.Data); if (weapon.Data.Tint != Color.White) { sprite = new TintedSprite(sprite, weapon.Data.Tint); } // Create the weapon's manager ModWeapon manager = new ModWeapon(translationHelper, key.LocalKey, sprite, weapon.Data.Type, weapon.Data.MinDamage, weapon.Data.MaxDamage, weapon.Data.Knockback, weapon.Data.Speed, weapon.Data.Accuracy, weapon.Data.Defense, weapon.Data.AreaOfEffect, weapon.Data.CritChance, weapon.Data.CritMultiplier); // Register the object this._api.Items.CommonRegistry.Weapons.Register(key, manager); this._api.Owner.Monitor.Log($" - {key} registered (weapon)", LogLevel.Trace); } }
public IContentSource GetContentSource() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown if (_needsReload) { if (_isCompressed) { _contentSource = (IContentSource)(object)new ZipContentSource(FullPath, "Content"); } else { _contentSource = (IContentSource)(object)new FileSystemContentSource(Path.Combine(FullPath, "Content")); } _contentSource.set_ContentValidator((IContentValidator)(object)VanillaContentValidator.Instance); _needsReload = false; } return(_contentSource); }
public byte[] ReadToByte(string path) { byte[] _dataArray = null; IContentSource _foundSource = null; foreach (IContentSource provider in _sources.Values) { if (provider.Containes(path.ToLower())) { _foundSource = provider; } } if (_foundSource != null) { _dataArray = _foundSource.ReadToByte(path); return(_dataArray); } else { throw new FileNotFoundException("File " + path + " not found in any of the providers"); } }
public async Task GenerateAndSaveIfChangedAsync(ContentVersion version, IContentSource contentSource) { if (contentSource is null) { throw new ArgumentNullException(nameof(contentSource)); } var existing = await GetExistingVersionAsync() .ConfigureAwait(false); if (existing?.Version != version?.Version || existing?.ReleaseDate?.ToString(CultureInfo.InvariantCulture) != version?.ReleaseDate?.ToString(CultureInfo.InvariantCulture)) { if (!Directory.Exists(_options.Location)) { Directory.CreateDirectory(_options.Location); } File.WriteAllText(GetFullFileName(), Generate(version, await contentSource.GetAllContentItemsAsync(_options.DefaultCultureCode, null) .ConfigureAwait(false))); } }
internal override IContentSource Crawl(IContentSource content, bool asList) { if (content == null) return GetDefault(string.Format("Null content")); if (content.GetType() != typeof(XmlContent) && content.GetType() != typeof(XHtmlContent)) { // convert to XHTML var strContent = content.ToString(); content = new XHtmlContent(); content.LoadRaw(strContent); } if (content.GetType() == typeof(XHtmlContent)) { content = asList ? (content as XHtmlContent).CrawlList(XPath) : (content as XHtmlContent).Crawl(XPath); } else { //if (content.GetType() == typeof(XmlContent)) // last case content = asList ? (content as XmlContent).CrawlList(XPath) : (content as XmlContent).Crawl(XPath); } if (content == null) return GetDefault(string.Format("Null content")); return content; }
private IEnumerable <ContentPackDataInfo> LoadData(IContentSource contentSource, ISet <string> loadedPaths, string configDir, string configName) { // Combine the directory and file name string fullPath = Path.Combine(configDir, configName); // Check if this data has already been loaded if (!loadedPaths.Add(fullPath)) { return(Enumerable.Empty <ContentPackDataInfo>()); } // Set up all the custom converters void SetSerializerSettings(JsonSerializerSettings settings) { settings.Converters.Add(new PossibleConfigValuesDataJsonConverter()); // settings.Converters.Add(new ContentPackValueJsonConverter()); settings.Converters.Add(new SColorJsonConverter()); settings.Converters.Add(new RecipeData.PartJsonConverter()); } // Check if this path points to proper content pack data if (!(this._api.Json.ReadJson <ContentPackData>(fullPath, contentSource, SetSerializerSettings) is ContentPackData curData)) { throw new Exception($"Invalid content file: {fullPath}"); } // Get all child include paths IEnumerable <ContentPackDataInfo> childIncludes = from relativeChildPath in curData.Include let fullChildPath = Path.Combine(configDir, relativeChildPath) let childDir = Path.GetDirectoryName(fullChildPath) let childName = Path.GetFileName(fullChildPath) from child in this.LoadData(contentSource, loadedPaths, childDir, childName) select child; // Return all the paths return(new ContentPackDataInfo(configDir, configName, curData).Yield().Concat(childIncludes)); }
public ITransformerStoreModel AddOrGetTransformer(IContentTransformer transformer, IContentSource source) { ITransformerStoreModel currentTransformer = _transformers.Find(model => model.TransformerType == transformer.GetType().FullName&& model.SourceIdentity == source.Identity); if (currentTransformer != null) { return(currentTransformer); } _dbConnection.Execute($"INSERT INTO Transformers (Created, Name, TransformerType, SourceIdentity) VALUES ('{DateTime.Now:yyyy-MM-dd hh:mm:ss}', '{transformer.GetType().Assembly.GetName().Name}', '{transformer.GetType().FullName}', '{source.Identity}')"); TransformerStoreModel transformerStoreModel = (TransformerStoreModel)GetTransformer(transformer, source); Directory.CreateDirectory(Path.Combine(_storeContentDirectoryName, transformerStoreModel.Id.ToString())); _transformers.Add(transformerStoreModel); return(transformerStoreModel); }
private ITransformerStoreModel GetTransformer(IContentTransformer transformer, IContentSource source) { TransformerStoreModel currentTransformer = _transformers.FirstOrDefault(x => x.TransformerType == transformer.GetType().FullName&& x.SourceIdentity == source.Identity); return(currentTransformer ?? _dbConnection.QueryFirst <TransformerStoreModel>($"SELECT * FROM Transformers WHERE TransformerType='{transformer.GetType().FullName}' AND SourceIdentity='{source.Identity}'")); }
private bool ExistTransformer(IContentTransformer transformer, IContentSource source) { return(_dbConnection.QuerySingleOrDefault <bool>($"SELECT 1 FROM Transformers WHERE TransformerType='{transformer.GetType().FullName}' AND SourceIdentity='{source.Identity}'")); }
public void Push(IContentSource node) { _descriptions.Add("".PadRight(_level * 2, ' ') + node.ToString()); _level++; }
public ContentSourceViewModel(IContentSource source) { this.source = source; }
private void TestStrategy(IContentSource source, IDiscoveryStrategy strategy) { if (!Global.IsReadyRedlineEnabled) return; RedemptionLoader.DllLocation32Bit = Path.Combine(Workshare.Interop.Options.OptionApi.GetString("ProgramLocation"), "Redemption.dll"); IStrategyResult result = source.ApplyStrategy(strategy); Assert.AreEqual(1, result.Count); IMail sentMail = result.First() as IMail; Assert.IsNotNull(sentMail); Assert.AreEqual(1, sentMail.Attachments.Count); Assert.IsTrue(sentMail.Attachments.First().IsModified == false); Assert.IsNotNull(sentMail.Attachments.First().TrackingId); Assert.IsTrue("ReadyRedlineDocumentTrackingTest.doc" == sentMail.Attachments.First().DisplayName); }
public CachingContentSource(IFileSystem cache, IContentSource source) { _cache = cache; _source = source; }
public void SetUp() { files = new AssetFile[]{ new AssetFile("something.js"){FullPath = "something.js"}, new AssetFile("something2.js"){FullPath = "something2.js"}, new AssetFile("something3.js"){FullPath = "something3.js"}, new AssetFile("something4.js"){FullPath = "something4.js"}, }; thePlan = new ContentPlan("a plan", files); theReadFileSource = thePlan.GetAllSources().ElementAt(2); theTransformerNode = thePlan.ApplyTransform(theReadFileSource, typeof(StubTransformer)); }
public static void SetContentSource(IContentSource source) { if(source == null) throw new ArgumentNullException("source"); _source = source; }
public TransformerProcessor(IContentTransformerStorage storage, IContentTransformer transformer, IContentSource source) { _storage = storage; _transformer = transformer; _source = source; _source.SourceChanged += SourceChanged; _source.Start(); }
private int findIndexOfSource(IContentSource source) { var index = _sources.IndexOf(source); if (index < 0) { throw new ArgumentOutOfRangeException("Source {0} is not in the top level of this plan".ToFormat(source)); } return index; }
public ContentItem(IContentSource source, string type, IReadOnlyFile file) { Type = type; File = file; _source = source; }
public TModel ReadOrCreate <TModel>(string path, IContentSource source, Action <JsonSerializerSettings> settings, bool minify = false) where TModel : class, new() => this.ReadOrCreate(path, source, settings, () => new TModel(), minify);
/// <summary> /// Registers the content source. /// </summary> /// <param name="src">The source.</param> void RegisterContentSource(IContentSource src) { this._contentSrcMap[src.Id] = src; }
private IEnumerable <ContentPackDataInfo> LoadData(IContentSource contentSource) => this.LoadData(contentSource, new HashSet <string>(), "", "content.json");
internal abstract IContentSource Crawl(IContentSource content, bool asList);
public ContentPackTranslationHelper(ICoreApi api, IContentSource contentSource) { this._api = api; this._contentSource = contentSource; this._defaultTranslations = this._api.Json.ReadJson <Dictionary <string, string> >("i18n/default.json", this._contentSource, settings => { }) ?? new Dictionary <string, string>(); }
public Transform(IContentSource inner) { _inner = inner; }
public ContentSyncer(IContentSource source, IContentDestination destination, ILogger <ContentSyncer> logger) { _destination = destination; _source = source; _logger = logger; }