public AmfFormatter() { stream = new MemoryStream(); writer = new FlashorbBinaryWriter(stream); objectSerializer = new ObjectSerializer(); referenceCache = new ReferenceCache(); }
public AmfFormatter() { stream = new MemoryStream(); writer = new FlashorbBinaryWriter( stream ); objectSerializer = new ObjectSerializer(); referenceCache = new ReferenceCache(); }
/// <summary> /// 更新语法树 /// </summary> /// <param name="oldCode">旧代码</param> /// <param name="newCode">新代码</param> /// <param name="sets">新的引用</param> public override void Update(string oldCode, string newCode, HashSet <string> sets = default) { //先移除 if (TreeCache.ContainsKey(oldCode)) { while (!TreeCache.TryRemove(oldCode, out _)) { } ; } if (sets == default) { if (ReferenceCache.ContainsKey(oldCode)) { sets = ReferenceCache[oldCode]; while (!ReferenceCache.TryRemove(oldCode, out _)) { } ; } } //再添加 AddTreeToCache(newCode); ReferenceCache[newCode] = sets; }
/// <summary> /// 初始化必要的构造参数。 /// </summary> public SqlBuilder() { AliasCache = new ReferenceCache <string>(); Builder = new StringBuilder(); XTypeInfo = XTypeInfo.Create(GetType(), XBindingFlags.Default | XBindingFlags.NonPublic); aliasIndex = 0; }
public async Task ResolveReferencesAsync(ISession session, ILogger log, ReferenceCache cache) { foreach (var content in Contents.ToList()) { if (content.References?.Any() == true) { await ResolveContentAsync(content, session, log, cache); } } }
public JsonReferenceSerializer(JsonFormatterOptions options) { if ((options & JsonFormatterOptions.PriorCheckReferences) != 0 && (options & (JsonFormatterOptions.MultiReferencingNull | JsonFormatterOptions.MultiReferencingReference)) == 0) { options ^= JsonFormatterOptions.PriorCheckReferences; } this.options = options; references = new ReferenceCache <TargetPathInfo>(); reference = new TargetPathInfo("#", null); }
public MessagePackSerializer( MessagePackFormatterOptions options, int maxDepth, HGlobalCache <byte> hGCache ) { this.Options = options; this.maxDepth = maxDepth; this.HGCache = hGCache; if (typeof(TMode) == typeof(Reference)) { References = new ReferenceCache <int>(); } }
public JsonRPCFormatter() { objectSerializer = new ObjectSerializer(); referenceCache = new ReferenceCache(); writer = new JsonTextWriter(); JsonNumberWriter numberWriter = new JsonNumberWriter(); customWriters.Add(typeof(int), numberWriter); customWriters.Add(typeof(long), numberWriter); customWriters.Add(typeof(float), numberWriter); customWriters.Add(typeof(double), numberWriter); customWriters.Add(typeof(short), numberWriter); customWriters.Add(typeof(byte), numberWriter); customWriters.Add(typeof(Decimal), numberWriter); }
public async Task ImportAsync(DirectoryInfo directoryInfo, JsonHelper jsonHelper, SyncOptions options, ISession session) { var contentsBySchema = GetContentFiles(directoryInfo) .Select(x => ReadContents(jsonHelper, x)) .SelectMany(x => x.Contents).GroupBy(x => x.Schema) .Select(x => new ContentGroup(x.Key, x)) .ToDictionary(x => x.SchemaName); var edges = new HashSet <(ContentGroup From, ContentGroup To)>(); foreach (var from in contentsBySchema.Values) { foreach (var dependency in from.Dependencies) { if (contentsBySchema.TryGetValue(dependency, out var to)) { edges.Add((to, from)); } } } var sortOrder = TopologicalSort.Sort(new HashSet <ContentGroup>(contentsBySchema.Values), edges); if (sortOrder == null) { throw new SquidexException("Dependencies between content items have a cycle, cannot calculate best sync order."); } var cache = new ReferenceCache(); foreach (var(schema, group) in contentsBySchema) { await log.DoSafeLineAsync($"Schema {schema}: Resolving references", () => { group.ClearLanguages(options); return(group.ResolveReferencesAsync(session, log, cache)); }); await log.DoSafeLineAsync($"Schema {schema}: Inserting", () => { return(group.UpsertAsync(session, log)); }); } }
/// <summary> /// 更新语法树 /// </summary> /// <param name="oldCode">旧代码</param> /// <param name="newCode">新代码</param> /// <param name="usings">新的引用</param> public override void Update(string oldCode, string newCode, HashSet <string> usings = default) { //先移除 TreeCache.Remove(oldCode); if (usings == default) { if (ReferenceCache.ContainsKey(oldCode)) { usings = ReferenceCache[oldCode]; ReferenceCache.Remove(oldCode); } } //再添加 AddTreeToCache(newCode); ReferenceCache[newCode] = usings; }
/// <summary> /// Gets the required non collection references for a type. /// </summary> /// <param name="entityType">The type of the entity to get the references from</param> /// <returns>A list of info on the types</returns> public static IEnumerable <TypeInfo> GetRequiredReferences(Type entityType) { if (ReferenceCache.TryGetValue(entityType, out var types)) { return(types); } var referenceTypes = entityType.GetProperties() .Where(p => p.GetCustomAttributes <EntityForeignKey>().Any(a => a.Required) && p.PropertyType.IsAssignableTo <IAbstractModel>()) .Select(p => new TypeInfo { Name = p.Name, Type = p.PropertyType }) .ToList(); ReferenceCache.TryAdd(entityType, referenceTypes); return(referenceTypes); }
/// <summary> /// Global initialization /// </summary> static RsdnDataCommonProvider() { // load references cache try { if (File.Exists(referencesCacheFilename)) { referenceCache = (ReferenceCache)Deserialize(referencesCacheFilename); } } catch (Exception e) { logger.Error("References cache corrupted", e); } // load message template template = new StringTemplateGroup("format", new EmbeddedResourceTemplateLoader(Assembly.GetExecutingAssembly(), typeof(TemplateArticle).Namespace), null, new TemplateLogger(logger), null); }
public async Task UpsertAsync(ISession session, ILogger log, ReferenceCache cache) { var client = session.Contents(SchemaName); var request = new BulkUpdate { Jobs = Contents.Select(x => new BulkUpdateJob { Query = new { filter = x.Filter }, Data = x.Data }).ToList() }; var results = await client.BulkUpdateAsync(request); var i = 0; foreach (var result in results) { var content = Contents[i]; log.StepStart($"{content.File} / {content.Ref}"); if (result.ContentId != null) { log.StepSuccess(); } else if (result.Error != null) { log.StepFailed(result.Error.ToString()); } else { log.StepSkipped("Unknown Reason"); } i++; } }
public override void Update(string old, string @new, HashSet <string> sets = default) { if (TreeCache.ContainsKey(old)) { while (!TreeCache.TryRemove(old, out _)) { } ; } if (sets == default) { if (ReferenceCache.ContainsKey(old)) { sets = ReferenceCache[old]; while (!ReferenceCache.TryRemove(old, out _)) { } ; } } AddTreeToCache(@new); ReferenceCache[@new] = sets; }
private async Task ResolveContentAsync(ContentModel content, ISession session, ILogger log, ReferenceCache cache) { var resolvedReferences = new Dictionary <string, Guid>(); foreach (var(key, value) in content.References.ToList()) { var schema = value.Schema; var filter = JObject.FromObject(value.Filter); var filterJson = filter.ToString(); if (cache.TryGetValue((schema, filterJson), out var id)) { resolvedReferences[key] = id; continue; } var client = session.Contents(value.Schema); var query = new { filter, take = 1 }; var references = await client.GetAsync(new ContentQuery { JsonQuery = query }, QueryContext.Default.Unpublished(true)); if (references.Total == 1) { id = references.Items[0].Id; resolvedReferences[key] = id; cache[(schema, filterJson)] = id;
public PriorCheckReferenceWriter(ReferenceCache <TargetPathInfo> references, TargetPathInfo parentReference) { References = references; ParentReference = parentReference; }