public void ReplaceCurrent(PeerInfo betterPeer) { if (betterPeer == null) { throw new ArgumentNullException(nameof(betterPeer)); } AllocationChangeEventArgs args; lock (_allocationLock) { PeerInfo current = Current; if (current != null && !CanBeReplaced) { return; } if (betterPeer.IsAllocated) { return; } betterPeer.IsAllocated = true; if (current != null) { current.IsAllocated = false; } args = new AllocationChangeEventArgs(current, betterPeer); Current = betterPeer; } Replaced?.Invoke(this, args); }
public void AllocateBestPeer(IEnumerable <PeerInfo> peers, INodeStatsManager nodeStatsManager, IBlockTree blockTree, string reason) { PeerInfo current = Current; PeerInfo selected = _peerSelectionStrategy.Select(Current, peers, nodeStatsManager, blockTree); if (selected == current) { return; } AllocationChangeEventArgs args = null; lock (_allocationLock) { if (selected.IsAllocated) { throw new InvalidAsynchronousStateException("Selected an already allocated peer"); } selected.IsAllocated = true; Current = selected; args = new AllocationChangeEventArgs(current, selected); if (current != null) { current.IsAllocated = false; } } Replaced?.Invoke(this, args); }
private IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && (wParam == (IntPtr)WM.KEYDOWN || wParam == (IntPtr)WM.KEYUP) && (IgnoreHwnd != IntPtr.Zero && GetForegroundWindow() != IgnoreHwnd)) { KBDLLHOOKSTRUCT kbd = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)); bool shift = IsKeyDown(Keys.Shift) || IsKeyDown(Keys.ShiftKey); bool alt = IsKeyDown(Keys.Menu); bool ctrl = IsKeyDown(Keys.Control) || IsKeyDown(Keys.ControlKey); var replacement = GetReplacement((Keys)kbd.vkCode, shift, alt, ctrl); if (replacement == null) { return(CallNextHookEx(hHook, nCode, wParam, lParam)); } var stats = statistics[replacement]; stats.Hits++; Hit?.Invoke(this, new KeyStatsEventArgs(replacement, stats)); if (replacement.Replacement != Keys.None) { var input = new INPUT(); input.type = INPUT_TYPE.INPUT_KEYBOARD; input.ki.wVk = (short)replacement.Replacement; input.ki.wScan = (short)MapVirtualKeyA((uint)replacement.Replacement, MapVirtualKeyMapTypes.MAPVK_VK_TO_VSC); if (wParam == (IntPtr)WM.KEYUP) { input.ki.dwFlags = KEYEVENTF.KEYUP; } SendInput(1, new INPUT[] { input }, Marshal.SizeOf(input)); stats.Replacements++; Replaced?.Invoke(this, new KeyStatsEventArgs(replacement, stats)); } return((IntPtr)1); } return(CallNextHookEx(hHook, nCode, wParam, lParam)); }
protected void OnCollectionChangedReplace(object oldValue, object newValue, int index) { var eventArgs = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newValue, oldValue, index); using (BlockReentrancy()) { CollectionChanged?.Invoke(this, eventArgs); Replaced?.Invoke(this, eventArgs); } }
public T this[int index] { get { return(_list[index]); } set { var replaced = _list[index]; var success = EventsEnabled ? BeforeReplacing.Call(this, index, replaced, value, true) : true; if (success) { _list[index] = value; if (EventsEnabled && !EqualityComparer <T> .Default.Equals(replaced, value)) { Replaced.Call(this, index, replaced, value); } } } }
public override Expression Visit(Expression node) { if (node == null) { return(null); } node = base.Visit(node); if (Predicate(node)) { var par = node.Type == typeof(void) ? Expression.Parameter(typeof(object), ""): Expression.Parameter(node.Type, "r_" + Replaced.Count); Replaced.Add(par, node); ParameterOrder.Add(par); return(par); } else { return(node); } }
/// <summary> /// 使用 Replaced 之前调用这个方法把 Map 中不是增删,而是直接改变 value 的数据合并到 Replaced 之中。 /// </summary> public void MergeChangedToReplaced(Collections.PMap2 <K, V> map) { if (null == ChangedValue || ChangedValue.Count == 0) { return; } foreach (var e in map) { if (ChangedValue.ContainsKey(e.Value)) { if (!Replaced.ContainsKey(e.Key)) { Replaced.Add(e.Key, e.Value); } } } ChangedValue.Clear(); }
public static String ReplaceTextInString(String S, String Replace, String NewString) { String Replaced = ""; foreach (String s in S.Split(' ')) { if (s.Equals(Replace)) { Replaced += NewString; } else { Replaced += s; } Replaced += " "; } Replaced.Trim(); return(Replaced); }
public override Expression Visit(Expression node) { if (node == null) { return(null); } node = base.Visit(node); var annotator = Predicate(node); if (annotator != null) { var par = Expression.Parameter(node.Type == typeof(void) ? typeof(object) : node.Type, "r_" + Replaced.Count); annotator(par)?.Apply(par.AddParameterAnnotation); Replaced.Add(par, node); ParameterOrder.Add(par); return(par); } else { return(node); } }
public void AllocateBestPeer(IEnumerable <PeerInfo> peers, INodeStatsManager nodeStatsManager, IBlockTree blockTree) { PeerInfo current = Current; PeerInfo selected = _peerAllocationStrategy.Allocate(Current, peers, nodeStatsManager, blockTree); if (selected == current) { return; } AllocationChangeEventArgs args; lock (_allocationLock) { if (selected != null && selected.TryAllocate(Contexts)) { Current = selected; args = new AllocationChangeEventArgs(current, selected); current?.Free(Contexts); Replaced?.Invoke(this, args); } } }
protected virtual void OnReplaced(ContentControl e) { Replaced?.Invoke(this, e); }
void Given(Replaced e) => Value = e.Value;
protected virtual void OnReplaced(ItemChangeEventArgs <T> e) { Replaced?.Invoke(this, e); ItemChanged?.Invoke(this, new ItemUpdateEventArgs <T>(e.Index, e.Original, e.Current, ItemAction.Replace)); }
/* ----------------------------------------------------------------- */ /// /// OnReplaced /// /// <summary> /// Replaced イベントを発生させます。 /// </summary> /// /* ----------------------------------------------------------------- */ protected virtual void OnReplaced(ValueEventArgs <int> e) => Replaced?.Invoke(this, e);
/// 由于不需要 Note 来支持回滚,这里只保留最新的改变即可。 internal void LogRemove(K key) { Removed.Add(key); Replaced.Remove(key); }