public ICommitContext Fill(IValueSource valueSource, Func <IValueSource, MappedObjectKeys> getKeyFunction, Func <T> createObject) { lock (_cache) { Init(true); CommitContext commitContext = new CommitContext(this); while (valueSource.Next()) { MappedObjectKeys keys = getKeyFunction(valueSource); if (_cache._itemsByKey.ContainsKey(keys)) { IFillAbleObject item = _cache._itemsByKey[keys].Value; if (item == null) { _cache._itemsByKey[keys] = new WeakReference <IFillAbleObject>(item = (IFillAbleObject)createObject()); ((System.ComponentModel.INotifyPropertyChanged)item).PropertyChanged += _cache.EntryValuePropertyChanged; } item.Fill(valueSource); commitContext.AddEntryToCommit((T)item); } else { IFillAbleObject newObject = (IFillAbleObject)createObject(); newObject.Fill(valueSource); _cache._itemsByKey.Add(keys, new WeakReference <IFillAbleObject>(newObject)); commitContext.AddEntryToCommit((T)newObject); ((System.ComponentModel.INotifyPropertyChanged)newObject).PropertyChanged += _cache.EntryValuePropertyChanged; } } return(commitContext); } }
protected override void beforeEach() { MockFor <IAntiForgeryTokenProvider>().Stub(x => x.GetTokenName()).Return("FormName"); MockFor <IAntiForgeryTokenProvider>().Stub(x => x.GetTokenName("String")).IgnoreArguments().Return( "CookieName"); MockFor <IRequestData>().Stub(x => x.Value("ApplicationPath")).Return("Path"); _valueSource = MockFor <IValueSource>(); _headerSource = MockFor <IValueSource>(); MockFor <IRequestData>().Stub(x => x.ValuesFor(RequestDataSource.Request)).Return(_valueSource); MockFor <IRequestData>().Stub(x => x.ValuesFor(RequestDataSource.Header)).Return(_headerSource); _cookies = MockFor <ICookies>(); _formToken = new AntiForgeryData { CreationDate = new DateTime(2010, 12, 12), Salt = "Salty", Username = "******", Value = "12345" }; _cookieToken = new AntiForgeryData { CreationDate = new DateTime(2010, 12, 12), Salt = "Salty", Username = "******", Value = "12345" }; MockFor <IAntiForgerySerializer>().Stub(x => x.Deserialize("CookieValue")).Return(_cookieToken); MockFor <IAntiForgerySerializer>().Stub(x => x.Deserialize("FormValue")).Return(_formToken); }
public void SetUp() { theMapping = new TestCsvMapping(); theRawValues = new[] { "Test", "true", "1" }; theValues = theMapping.ValueSource(new CsvData(theRawValues)); }
public ExpressionMutationVisitor(ExpressionGenerator <T> expressionGenerator, IRandom random, IValueSource <double> mutationRate, IRandom bellWeightedRandom) { _expressionGenerator = expressionGenerator; _random = random; _mutationRate = mutationRate; _bellWeightedRandom = bellWeightedRandom; }
public RequestHeaders(IObjectConverter converter, IObjectResolver resolver, ICurrentHttpRequest request) { _converter = converter; _resolver = resolver; _values = new HeaderValueSource(request); }
public RequestHeaders(IObjectConverter converter, IObjectResolver resolver, IRequestData requestData) { _converter = converter; _resolver = resolver; _values = requestData.ValuesFor(RequestDataSource.Header); }
/// <summary> /// Deserialize JSON content /// </summary> /// <param name="reader">A <c>System.IO.TextReader</c> to read JSON content from</param> /// <param name="additionalInfo">Resolver for special non-value parameters</param> /// <returns>The operation parameters as a collection of atomic values</returns> public AtomCollectionData Deserialize(TextReader reader, IValueSource additionalInfo) { try { _context = new ParseContext(additionalInfo); var text = reader.ReadToEnd(); var rootToken = JToken.Parse(text); switch (rootToken.Type) { case JTokenType.Object: FromObject(rootToken as JObject); break; // Extension point: add capability to read from different structure (array etc.) default: throw new Exception($"Unable to read parameters from a {rootToken.Type}"); } return(_context.Result); } catch (Exception ex) { throw new Exception("JSON deserialization error", ex); } }
public void FillCache(QueryContext context) { if (!context.Load) { return; } IModifyableCommandBuilder commandBuilder = _objectProvider._mappingInfoContainer.FillCommand(_objectProvider._databaseProvider.GetSelectCommandBuilder()); context.PrepareSelectCommand(commandBuilder); using (DbCommand command = commandBuilder.GetDbCommand()) { command.Connection = GetConnection(); try { ICommitContext commitContext; using (IValueSource valueSource = _objectProvider._databaseProvider.GetValueSource(command)) { TypeMapping mappingInfo = _objectProvider._mappingInfoContainer; commitContext = _objectProvider._cache.Fill(valueSource, x => mappingInfo.GetKeyValues(x), () => (T)mappingInfo.CreateObject(), context); } if (commitContext != null) { commitContext.Commit(); } } finally { _objectProvider._databaseProvider.ReleaseConnection(command.Connection); } } context.SetLoaded(); }
public GenomeMutator(IGenomeDescription <T> genomeDescription, IValueSource <double> mutationProbability, IRandom random) : base(genomeDescription, mutationProbability) { _mutationProbability = mutationProbability; _genomeDescription = genomeDescription; _random = random; }
internal bool TryGetValueSource( IValueDescriptor valueDescriptor, out IValueSource valueSource) { foreach (var symbol in ParseResult.ValueDescriptors()) { if (ValueDescriptor.CanBind( from: symbol, to: valueDescriptor)) { valueSource = new SymbolValueSource((ISymbol)symbol); return(true); } } if (ServiceProvider.AvailableServiceTypes.Contains(valueDescriptor.Type)) { valueSource = new ServiceProviderValueSource(); return(true); } valueSource = null; return(false); }
internal bool TryBindToScalarValue( IValueDescriptor valueDescriptor, IValueSource valueSource, out BoundValue boundValue) { if (valueSource.TryGetValue(valueDescriptor, this, out var value)) { if (value == null || valueDescriptor.Type.IsInstanceOfType(value)) { boundValue = new BoundValue(value, valueDescriptor, valueSource); return(true); } else { var parsed = ArgumentConverter.ConvertObject( valueDescriptor as IArgument ?? new Argument(valueDescriptor.ValueName), valueDescriptor.Type, value); if (parsed is SuccessfulArgumentConversionResult successful) { boundValue = new BoundValue(successful.Value, valueDescriptor, valueSource); return(true); } } } boundValue = null; return(false); }
public void SetUp() { theMapping = new TestCsvMapping(); theHeaders = new CsvData(new[] { "Count", "Flag", "Name" }); theRawValues = new CsvData(new[] { "1", "true", "Test" }); theValues = theMapping.ValueSource(theRawValues, theHeaders); }
public void SetUp() { theMapping = new MappingWithAliases(); theHeaders = new CsvData(new[] { "Count", "Flag", "SomethingElse" }); theRawValues = new CsvData(new[] { "1", "true", "Test" }); theValues = theMapping.ValueSource(theRawValues, theHeaders); }
public ConnegOutputBehavior(IValueSource <T> source, IFubuRequest request, IOutputWriter writer, IEnumerable <IMediaWriter <T> > writers) : base(PartialBehavior.Executes) { _source = source; _request = request; _writer = writer; _writers = writers; }
public void StartSource(IValueSource source) { _prefixes.Clear(); _source = source.Provenance; _prefix = string.Empty; startSource(source); }
public void SetSource(IValueSource <T> sourceNode) { if (valueSource != null) { throw new InvalidOperationException(string.Format("{0} already has a source associated with it", FullPath)); } valueSource = sourceNode; }
internal BoundValue( object?value, IValueDescriptor valueDescriptor, IValueSource valueSource) { Value = value; ValueDescriptor = valueDescriptor; ValueSource = valueSource; }
private void BindValueSource(ParameterInfo param, IValueSource valueSource) { var paramDesc = FindParameterDescriptor(param); if (paramDesc is null) { throw new InvalidOperationException("You must bind to a parameter on this handler"); } invokeArgumentBindingSources.Add(paramDesc, valueSource); }
public static async Task <ReadOnlyValue <T> > CreateAsync(string name, IValueSource <T> valueSource) { var cache = await new ReadOnlyCacheBuilder <int, T>(name, new ValueDataSource <T>(valueSource)) .WithLocalCache(new ValueCache <T>()) .WithLoggerFactory(new ConsoleLoggerFactory()) .WithPreload(_ => Task.FromResult <IEnumerable <int> >(new[] { 0 }), null) .BuildAsync(); return(new ReadOnlyValue <T>(cache)); }
public T GetValue <T>() where T : struct { //Make sure output node matches requested type if (_outputNode != null && typeof(IValueSource <T>).IsAssignableFrom(_outputNode.GetType())) { IValueSource <T> outputNode = _outputNode as IValueSource <T>; return(outputNode.GetValue()); } return(default(T)); }
internal bool TryGetValueSource( IValueDescriptor valueDescriptor, [MaybeNullWhen(false)] out IValueSource valueSource) { if (ServiceProvider.AvailableServiceTypes.Contains(valueDescriptor.ValueType)) { valueSource = new ServiceProviderValueSource(); return(true); } valueSource = default !;
public ValueSource(T value = default(T), IValueSource <T> sourceObject = null) { _value = value; _sourceObject = sourceObject as UnityEngine.Object; #if UNITY_EDITOR _editorType = sourceObject != null ? eEdtiorType.Source : eEdtiorType.Static; _editorFoldout = false; _editorHeight = EditorGUIUtility.singleLineHeight * 3; #endif }
public void SetParentNodeGraph(NodeGraph nodeGraph) { _nodeGraph = nodeGraph; switch (_sourceType) { case eSourceType.Node: _sourceObject = _nodeGraph.GetNode(_sourceNodeId) as IValueSource <T>; break; } }
internal bool TryGetValueSource( IValueDescriptor valueDescriptor, out IValueSource valueSource) { if (ServiceProvider.AvailableServiceTypes.Contains(valueDescriptor.Type)) { valueSource = new ServiceProviderValueSource(); return(true); } valueSource = null; return(false); }
/// <summary> /// Adds specified source to list of sources for current input entity. /// </summary> /// <param name="source">Value source entity.</param> public void AddSource(IValueSource source) { lock (_lockGuard) { if (source.ValueType != _type) { throw new ArgumentException(ComponentsResources.InputTypeMismatch); } _sources.Add(source); source.ValueReady += TryCaptureValue; TryCaptureValue(source); } }
public void SetUp() { theDictionary = new Dictionary <string, string>(); theValues = new FlatValueSource(theDictionary, "some name"); theDictionary.Add("ChildProp1", "1"); theDictionary.Add("ChildProp2", "2"); theDictionary.Add("ChildProp3", "3"); theDictionary.Add("ChildProp4", "4"); theDictionary.Add("ChildDescProp1", "123"); child = theValues.GetChild("Child"); }
public void OnValueChanged(IValueSource source, ValueChangedEventArgs e) { var highestSetValueSource = GetHighestPrecedenceSetValueSource(e.Property, 0); if (highestSetValueSource != null && source.Order > highestSetValueSource.Order) { return; } var metadata = GetMetadata(e.Property); if (e.OldValue.HasValue && e.NewValue.HasValue) // value_a -> value_b { effectiveSources[e.Property] = source; RaisePropertyChanged(e.Property, metadata, e.OldValue.Value, e.NewValue.Value); } else { var below = GetHighestPrecedenceSetValueSource(e.Property, source.Order + 1); var belowValue = below?.GetValue(e.Property) ?? Maybe.None <object>(); var previousValue = belowValue.Case(s => s, () => metadata.DefaultValue); if (!e.OldValue.HasValue) // none -> value { effectiveSources[e.Property] = source; if (Helpers.AreDifferent(e.NewValue.Value, previousValue)) { RaisePropertyChanged(e.Property, metadata, previousValue, e.NewValue.Value); } } else if (!e.NewValue.HasValue) // value -> none { if (below == null) { effectiveSources.Remove(e.Property); } else { effectiveSources[e.Property] = below; } if (Helpers.AreDifferent(e.OldValue.Value, previousValue)) { RaisePropertyChanged(e.Property, metadata, e.OldValue.Value, previousValue); } } } }
/// <summary> /// Gets all available values from source and push them to results. /// </summary> /// <param name="source">Node output source.</param> private void TryTakeValue(IValueSource source) { if (source.Pull(out object value)) { lock (_lockGuard) { _results.Add((T)value); DecrementCounters(); TryTakeValue(source); } } }
public void SaveObjects( IEnumerable <IFillAbleObject> items, Func <IFillAbleObject, ICommandBuilder> getBuilder, Action <IFillAbleObject, IValueSource> refill, Action <IFillAbleObject> afterFill) { DbConnection connection = GetConnection(); try { foreach (IFillAbleObject item in items.ToList()) { try { ICommandBuilder commandBuilder = getBuilder(item); if (commandBuilder == null) { continue; } item.FillCommand(commandBuilder); using (DbCommand command = commandBuilder.GetDbCommand()) { command.Connection = connection; using (IValueSource valueSource = _objectProvider._databaseProvider.GetValueSource(command)) { refill(item, valueSource.Next() ? valueSource : null); } } afterFill(item); } catch (Exception ex) { if (ex is EntitySaveException) { throw; } else { throw new EntitySaveException(item, ex); } } } } finally { _objectProvider._databaseProvider.ReleaseConnection(connection); } }
/// <summary> /// Create a totally customized Config instance. /// Generally you will not need this constructor. /// </summary> /// <param name="cache">The <see cref="IValueCache"/> instance to be used by this Config instance.</param> /// <param name="source">The <see cref="IValueSource"/> instance to be used by this Config instance.</param> /// <param name="transformer">The <see cref="IValueTransformer"/> instance to be used by this Config instance.</param> /// <param name="validator">The <see cref="IValueValidator"/> instance to be used by this Config instance.</param> /// <param name="coercer">The <see cref="IValueCoercer"/> instance to be used by this Config instance.</param> protected Config(IValueCache cache, IValueSource source, IValueTransformer transformer, IValueValidator validator, IValueCoercer coercer) { Cache = cache; Source = source; Transformer = transformer; Validator = validator; Coercer = coercer; // Pre-cache all the properties on this instance _properties = GetType() .GetMembers(BindingFlags.Instance | BindingFlags.Public) .OfType <PropertyInfo>() .Where(p => p.CanRead) .ToDictionary(p => p.Name); }
public void AddObject(IValueSource val) { _With.Add(val); }
protected virtual void startSource(IValueSource source) { // no-op; }
public void AddValues(IValueSource source) { _sources.Add(source); }
public RequestData(IValueSource source) { _sources.Add(source); }
public void SetUp() { theDictionary = new Dictionary<string, string>(); theValues = new FlatValueSource(theDictionary, "some name"); theDictionary.Add("ChildProp1", "1"); theDictionary.Add("ChildProp2", "2"); theDictionary.Add("ChildProp3", "3"); theDictionary.Add("ChildProp4", "4"); theDictionary.Add("ChildDescProp1", "123"); child = theValues.GetChild("Child"); }
protected override void startSource(IValueSource source) { _currentReport = new ValueSourceReport(source.Provenance); _reports.Add(_currentReport); }
public void AddValues(IValueSource source) { _inner.AddValues(source); }