protected StateBoundComputed( ComputedOptions options, State <T> input, Result <T> output, LTag version, bool isConsistent) : base(options, input, output, version, isConsistent) { }
//todo: come back to this, setting up for single-unit negation public bool Matches(LTag e) { if (IsComposite) { if (LeftCondition.Matches(e)) LeftMatched = true; if (RightCondition.Matches(e)) RightMatched = true; if (Operator == LOGIC_OP.AND && (CheckNeg() && CheckNeg(false))) { Matched = true; } else if (CheckNeg() || CheckNeg(false)) //must be OR op { Matched = true; } } else { if (Tag.Tag == e.Tag && Negation == false) { Matched = true; } else if (Tag.Tag != e.Tag && Negation == true) { Matched = true; } } return Matched; }
public override object ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer) { var value = (string)reader.Value !; // ReSharper disable once HeapView.BoxingAllocation return(LTag.Parse(value)); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string s) { // ReSharper disable once HeapView.BoxingAllocation return(LTag.Parse(s)); } return(base.ConvertFrom(context, culture, value)); }
public virtual IReplica <T> GetOrAdd <T>( Symbol publisherId, Symbol publicationId, Result <T> output, LTag version, bool isConsistent = true, bool requestUpdate = false) { var(replica, isNew) = Registry.GetOrAdd(publicationId, () => new Replica <T>(this, publisherId, publicationId, output, version, isConsistent, requestUpdate)); if (isNew) { Subscribe(replica); } return((IReplica <T>)replica); }
protected Computed(ComputedOptions options, ComputeMethodInput input, Result <T> output, LTag version, bool isConsistent = true) : base(options, input, output, version, isConsistent) { }
public Computed(ComputedOptions options, ComputeMethodInput input, LTag version) : base(options, input, version) { }
protected internal SimpleComputed(ComputedOptions options, SimpleComputedInput input, LTag version) : base(options, input, version) { }
protected SwappingComputed(ComputedOptions options, InterceptedInput input, ResultBox <T> maybeOutput, LTag version, bool isConsistent) : base(options, input, default, version, isConsistent) => _maybeOutput = maybeOutput;
protected abstract IComputed <T> CreateComputed(ComputeMethodInput input, LTag tag);
public SimpleComputed(ComputedOptions options, SimpleComputedInput input, LTag version) : base(options, input, version) { }
public ReplicaClientComputed(ComputedOptions options, InterceptedInput input, Exception error, LTag version) : this(options, null, input, new Result <T>(default !, error), version, false)
protected override IComputed <T> CreateComputed(InterceptedInput input, LTag tag) => new Computed <T>(Options, input, tag);
public ReplicaServiceComputed(ComputedOptions options, InterceptedInput input, Exception error, LTag lTag) : this(options, null, input, new Result <T>(default !, error), lTag, false)
public SimpleComputed(ComputedOptions options, SimpleComputedInput input, LTag lTag) : base(options, input, lTag) { }
public ReplicaMethodComputed(ComputedOptions options, ComputeMethodInput input, Exception error, LTag version) : this(null, options, input, new Result <T>(default !, error), version, false)
public ReplicaComputed(ComputedOptions options, ReplicaInput input, LTag lTag) : base(options, input, lTag) { }
protected override IComputed <T> CreateComputed(ComputeMethodInput input, LTag tag) => new Computed <T>(Options, input, tag);
public ReplicaComputed(ComputedOptions options, ReplicaInput input, Result <T> output, LTag lTag, bool isConsistent = true) : base(options, input, output, lTag, isConsistent) { }
public SimpleComputed(ComputedOptions options, SimpleComputedInput input, Result <T> output, LTag version, bool isConsistent = true) : base(options, input, output, version, isConsistent) { }
public StateBoundComputed( ComputedOptions options, State <T> input, LTag version) : base(options, input, version) { }
public SwappingComputed(ComputedOptions options, InterceptedInput input, LTag version) : base(options, input, version) { }
public IComputed?TryGetCachedComputed(LTag lTag, IComputed?usedBy = null) { var computed = TryGetCachedComputed(usedBy); return(computed == null ? computed : computed.LTag == lTag ? computed : null); }
protected ReplicaComputed(ComputedOptions options, ReplicaInput input, LTag version) : base(options, input, version) { }
protected override async ValueTask <IComputed <T> > ComputeAsync( InterceptedInput input, IComputed <T>?cached, CancellationToken cancellationToken) { var method = input.Method; // 1. Trying to update the Replica first if (cached is IReplicaServiceComputed <T> rsc && rsc.Replica != null) { try { var replica = rsc.Replica; var computed = await replica.Computed .UpdateAsync(true, cancellationToken).ConfigureAwait(false); var replicaComputed = (IReplicaComputed <T>)computed; var output = new ReplicaServiceComputed <T>( method.Options, replicaComputed, input); return(output); } catch (OperationCanceledException) { if (_isLogDebugEnabled) { _log.LogDebug($"{nameof(ComputeAsync)}: Cancelled (1)."); } throw; } catch (Exception e) { if (_isLogDebugEnabled) { _log.LogError(e, $"{nameof(ComputeAsync)}: Error on Replica update."); } } } // 2. Replica update failed, let's refresh it try { using var replicaCapture = new ReplicaCapture(); var result = input.InvokeOriginalFunction(cancellationToken); if (method.ReturnsComputed) { if (method.ReturnsValueTask) { var task = (ValueTask <IComputed <T> >)result; await task.ConfigureAwait(false); } else { var task = (Task <IComputed <T> >)result; await task.ConfigureAwait(false); } } else { if (method.ReturnsValueTask) { var task = (ValueTask <T>)result; await task.ConfigureAwait(false); } else { var task = (Task <T>)result; await task.ConfigureAwait(false); } } var replica = replicaCapture.GetCapturedReplica <T>(); var computed = await replica.Computed .UpdateAsync(true, cancellationToken).ConfigureAwait(false); var replicaComputed = (IReplicaComputed <T>)computed; var output = new ReplicaServiceComputed <T>( method.Options, replicaComputed, input); return(output); } catch (OperationCanceledException) { if (_isLogDebugEnabled) { _log.LogDebug($"{nameof(ComputeAsync)}: Cancelled (2)."); } throw; } catch (Exception e) { if (_isLogDebugEnabled) { _log.LogError(e, $"{nameof(ComputeAsync)}: Error on update."); } // We need a unique LTag here, so we use a range that's supposed // to be unused by LTagGenerators. var lTag = new LTag(LTagGenerator.Next().Value ^ (1L << 62)); var output = new ReplicaServiceComputed <T>( method.Options, null, input, new Result <T>(default !, e), lTag);
public ReplicaComputed(ComputedOptions options, ReplicaInput input, Result <T> output, LTag version, bool isConsistent) : base(options, input, output, version, isConsistent) { }
protected abstract IComputed <T> CreateComputed(InterceptedInput input, LTag tag);