public async Task Add(T value) { var oldVals = _items.ToArray(); _items.Add(value); await Changed.Invoke(Changes.Add(_items.Count - 1, value).Collect(oldVals, _items)); }
protected virtual bool TryParse(JsonReader reader) { switch (reader.Path) { case "": case "Changes[].": // Ignore these items. break; case "Changes[].Type": switch (reader.AsString("")) { case "Clear": Changes.Add(new OvercastCondition(reader)); break; case "Precipitation": Changes.Add(new PrecipitationCondition(reader)); break; case "Fog": Changes.Add(new FogCondition(reader)); break; default: return(false); } break; default: return(false); } return(true); }
protected void brightnessSlider_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs <double> e) { Debug.WriteLine("Changing brightness to " + (1.0 - e.NewValue)); Changes.Add(() => { _lomoFilter.Brightness = 1.0 - e.NewValue; }); Apply(); Control.NotifyManipulated(); }
internal WorkItemWrapper(EngineContext context, WorkItem item) { _context = context; _item = item; _originalValues = new Dictionary <string, object>(item.Fields); Relations = new WorkItemRelationWrapperCollection(this, _item.Relations); if (item.Id.HasValue) { Id = new PermanentWorkItemId(item.Id.Value); AddRevisionCheck(item, context); //for simplify testing: item.Url can be null IsDeleted = item.Url?.EndsWith($"/recyclebin/{item.Id.Value}", StringComparison.OrdinalIgnoreCase) ?? false; IsReadOnly = false; _context.Tracker.TrackExisting(this); } else { Id = new TemporaryWorkItemId(_context.Tracker); Changes.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/id", Value = Id.Value }); _context.Tracker.TrackNew(this); } }
public VersionedList <T> Insert(int index, T item) { return(new VersionedList <T>( Items.Insert(index, item), Version + 1, Changes.Add(ListChange.Added(Version, index, item)))); }
protected void AddChange(Control control) { if (!Changes.Contains(control)) { Changes.Add(control); } }
/// <inheritdoc/> public override void Dispose() { GC.SuppressFinalize(this); var tags = Repository.Tags .ToDictionary(r => r.CanonicalName); foreach (var tag in tags.Values) { if (OldTags.TryGetValue(tag.CanonicalName, out var oldTag)) { if (oldTag.Target.Sha != tag.Target.Sha) { Changes.Add(new TagChange(ChangeType.Updated, tag)); } } else { Changes.Add(new TagChange(ChangeType.Created, tag)); } } foreach (var deletedTag in OldTags.Values.Where(t => !tags.ContainsKey(t.CanonicalName))) { Changes.Add(new TagChange(ChangeType.Deleted, deletedTag)); } }
public async Task DecrementCounterAsync(ISocketMessageChannel channel) { if (channel is IPrivateChannel) { return; } lock (Locker) { if (!Counters.ContainsKey(channel.Id)) { return; } var counter = Counters[channel.Id]; counter.Count--; if (counter.Count < 0) { counter.Count = 0; } Changes.Add(channel.Id); } }
public void ApplyChange(int pairIndex, TriviaData data) { Contract.ThrowIfNull(data); Contract.ThrowIfFalse(0 <= pairIndex && pairIndex < this.TokenCount - 1); // do reference equality check var sameAsOriginal = GetOriginalTriviaData(pairIndex) == data; if (_changes.Contains(pairIndex)) { if (sameAsOriginal) { _changes.Remove(pairIndex); return; } // okay it already exist. // replace existing one _changes.Replace(pairIndex, data); return; } // triviaInfo is same as original, nothing to do here. if (sameAsOriginal) { return; } _changes.Add(pairIndex, data); }
public void AddValue(double value, DateTime?dt = null) { if (Equity.Count == 0) { Returns.Add(0); Changes.Add(0); } else { Returns.Add(Equity.Last() != 0 ? value / Equity.Last() - 1 : 0); Changes.Add(value - Equity[Equity.Count - 1]); } Equity.Add(value); _maxEquity = Math.Max(_maxEquity, value); DrawdownPct.Add(_maxEquity == 0 ? 0 : value / _maxEquity - 1); DrawdownAmt.Add(Equity.Last() - _maxEquity); if (dt != null) { AddDrawdownLengths(dt.Value); } Dates.Add(dt); }
public async Task IncrementCounterAsync(ISocketMessageChannel channel) { if (channel is IPrivateChannel) { return; } lock (Locker) { if (!Counters.ContainsKey(channel.Id)) { Counters.Add(channel.Id, new ChannelStat() { SnowflakeID = channel.Id }); } var counterForChannel = Counters[channel.Id]; counterForChannel.Count++; counterForChannel.LastMessageAt = DateTime.Now; Changes.Add(channel.Id); } }
public void AddChange(double change, DateTime?dt = null) { if (Equity.Count == 0) { Returns.Add(0); Equity.Add(change); } else { Returns.Add(Equity.Last() != 0 ? change / Equity.Last() : 0); Equity.Add(Equity[Equity.Count - 1] + change); } Changes.Add(change); _maxEquity = Math.Max(_maxEquity, Equity.Last()); DrawdownPct.Add(_maxEquity == 0 ? 0 : Equity.Last() / _maxEquity - 1); DrawdownAmt.Add(Equity.Last() - _maxEquity); if (dt != null) { AddDrawdownLengths(dt.Value); } Dates.Add(dt); }
/// <summary> /// /// </summary> /// <param name="ret">Net Return</param> public void AddReturn(double ret, DateTime?dt = null) { if (Equity.Count == 0) { Equity.Add(1); Changes.Add(0); } else { Equity.Add(Equity.Last() * (1 + ret)); Changes.Add(Equity[Equity.Count - 1] - Equity[Equity.Count - 2]); } _maxEquity = Math.Max(_maxEquity, Equity.Last()); Returns.Add(ret); DrawdownPct.Add(_maxEquity == 0 ? 0 : Equity.Last() / _maxEquity - 1); DrawdownAmt.Add(Equity.Last() - _maxEquity); if (dt != null) { AddDrawdownLengths(dt.Value); } Dates.Add(dt); }
public async Task MergeEmotesAsync(SocketGuild guild) { lock (Locker) { using (var repository = new GrillBotRepository(Config)) { foreach (var item in GetMergeList(guild)) { if (!Counter.ContainsKey(item.MergeTo)) { Counter.Add(item.MergeTo, new EmoteStat() { EmoteID = item.MergeTo, LastOccuredAt = DateTime.Now }); } var emote = Counter[item.MergeTo]; foreach (var source in item.Emotes) { emote.Count += source.Value; repository.EmoteStats.RemoveEmote(source.Key); Counter.Remove(source.Key); } Changes.Add(emote.EmoteID); } } } }
/// <summary> /// Remove the specified <see cref="EMiscFlag"/> from the device/feature /// </summary> /// <param name="misc">The <see cref="EMiscFlag"/> to remove</param> public void RemoveMiscFlag(EMiscFlag misc) { var currentMisc = _misc; if (Changes.ContainsKey(EProperty.Misc)) { currentMisc = (uint)Changes[EProperty.Misc]; } var tempMisc = currentMisc ^ (uint)misc; if (Changes.ContainsKey(EProperty.Misc)) { Changes[EProperty.Misc] = tempMisc; } else { Changes.Add(EProperty.Misc, tempMisc); } if (_cacheChanges) { return; } _misc = tempMisc; }
protected void brightnessSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) { Debug.WriteLine("Changing brightness to " + (1.0 - e.NewValue)); Changes.Add(() => { Filter.Brightness = 1.0 - e.NewValue; }); Apply(); NotifyManipulated(); }
internal WorkItemWrapper(EngineContext context, WorkItem item) { _context = context.Track(this); if (item.Id.HasValue) { Id = new PermanentWorkItemId(item.Id.Value); Changes.Add(new JsonPatchOperation() { Operation = Operation.Test, Path = "/rev", Value = item.Rev }); } else { Id = new TemporaryWorkItemId(); Changes.Add(new JsonPatchOperation() { Operation = Operation.Test, Path = "/id", Value = Id }); } _item = item; }
protected void saturationSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) { Debug.WriteLine("Changing saturation changed to " + e.NewValue); Changes.Add(() => { Filter.Saturation = e.NewValue; }); Apply(); NotifyManipulated(); }
/// <summary> /// Sets current state of the object to be Changed (i.e. from now on the object will know it had some changes since last <see cref="Accept"/> call); /// </summary> public void InvokeChanged() { if (!HasChanges) { Changes.Add("External change invoke"); } }
/// <summary> /// Adds an element with the provided key and value to the <see cref="IDictionary{TKey,TValue}" />. /// </summary> /// <param name="key">The object to use as the key of the element to add.</param> /// <param name="value">The object to use as the value of the element to add.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="key"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if an element with the same key already exists in the <see cref="IDictionary{TKey,TValue}" />. /// </exception> public void Add(TKey key, TExternal value) { var storageItem = m_ExternalToStorage(value); Current.Add(key, storageItem); Changes.Add(new AddToDictionaryChange(key, storageItem)); }
public virtual void Change(User user) { Changes.Add(new Change() { CreatedAt = DateTime.Now, User = user, Issue = this }); }
internal void RemoveStatusControl(StatusControl statusControl) { var currentStatusControls = _statusControls ?? new StatusControlCollection(); if (Changes.ContainsKey(EProperty.StatusControls)) { currentStatusControls = Changes[EProperty.StatusControls] as StatusControlCollection ?? new StatusControlCollection(); } currentStatusControls.Remove(statusControl); if (Changes.ContainsKey(EProperty.StatusControls)) { Changes[EProperty.StatusControls] = currentStatusControls; } else { Changes.Add(EProperty.StatusControls, currentStatusControls); } if (_cacheChanges) { return; } _statusControls = currentStatusControls; }
internal WorkItemWrapper(EngineContext context, WorkItem item) { _context = context; _item = item; _relationCollection = new WorkItemRelationWrapperCollection(this, _item.Relations); if (item.Id.HasValue) { Id = new PermanentWorkItemId(item.Id.Value); Changes.Add(new JsonPatchOperation() { Operation = Operation.Test, Path = "/rev", Value = item.Rev }); _context.Tracker.TrackExisting(this); } else { Id = new TemporaryWorkItemId(_context.Tracker); Changes.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/id", Value = Id.Value }); _context.Tracker.TrackNew(this); } }
internal void RemoveStatusGraphic(StatusGraphic statusGraphic) { var currentStatusGraphics = _statusGraphics ?? new StatusGraphicCollection(); if (Changes.ContainsKey(EProperty.StatusGraphics)) { currentStatusGraphics = Changes[EProperty.StatusGraphics] as StatusGraphicCollection ?? new StatusGraphicCollection(); } currentStatusGraphics.Remove(statusGraphic); if (Changes.ContainsKey(EProperty.StatusGraphics)) { Changes[EProperty.StatusGraphics] = currentStatusGraphics; } else { Changes.Add(EProperty.StatusGraphics, currentStatusGraphics); } if (_cacheChanges) { return; } _statusGraphics = currentStatusGraphics; }
public VersionedList <T> Add(T item) { return(new VersionedList <T>( Items.Add(item), Version + 1, Changes.Add(ListChange.Added(Version, Items.Count, item)))); }
/// <summary> /// Adds an item to the <see cref="IList{T}"/>. /// </summary> /// <param name="item">The object to add to the <see cref="IList{T}"/>.</param> public void Add(TExternal item) { var storageItem = m_ExternalToStorage(item); Current.Add(storageItem); Changes.Add(new InsertIntoListChange(Current.Count - 1, storageItem)); }
public CustomerAggregate(string firstName, string lastName, string nationalCode) { FirstName = firstName; LastName = lastName; NationalCode = new NationalCode(nationalCode); Changes.Add(new CustomerRegisteredEvent(Id, FirstName, LastName, NationalCode.Code)); }
/// <summary> /// Inserts an item to the <see cref="IList{T}"/> at the specified index. /// </summary> /// <param name="index">The zero-based index at which item should be inserted.</param> /// <param name="item">The object to insert into the <see cref="IList{T}"/>.</param> /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is not a valid index in the <see cref="IList{T}"/>.</exception> public void Insert(int index, TExternal item) { var storageItem = m_ExternalToStorage(item); Current.Insert(index, storageItem); Changes.Add(new InsertIntoListChange(index, storageItem)); }
protected void saturationSlider_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs <double> e) { Debug.WriteLine("Changing saturation changed to " + e.NewValue); Changes.Add(() => { _lomoFilter.Saturation = e.NewValue; }); Apply(); Control.NotifyManipulated(); }
public async Task Insert(int index, T item) { var oldVals = _items.ToArray(); _items.Insert(index, item); await Changed.Invoke(Changes.Add(index, item).Collect(oldVals, _items)); }