private void OnObjectSignaled(ISynchronizable obj) { if (ObjectSignaled != null) { ObjectSignaled(obj); } }
protected override void Arrange() { _suppliedSourceEntityExtension = Stub <ISynchronizable>(); A.CallTo(() => _suppliedSourceEntityExtension.Synchronize(A <object> ._)).Returns(true); // Source extension entry, mapped from the resource object, will be an ArrayList of "transient" entities var sourceExtensions = new Dictionary <string, object> { { "Extension1", new ArrayList { _suppliedSourceEntityExtension } } }; _suppliedSourceEntity = new FakeEntityWithExtensions(sourceExtensions); // Target extension entries during synchronization are "persistent" entities loaded through NHibernate, and due to the NHibernate mapping approach for extensions, will be a list with a single "persistent" entity _suppliedTargetEntityExtension = Stub <ISynchronizable>(); var targetExtensions = new Dictionary <string, object> { { "Extension1", new List <ISynchronizable> { _suppliedTargetEntityExtension } } }; _suppliedTargetEntity = new FakeEntityWithExtensions(targetExtensions); }
protected override void Arrange() { _suppliedSourceEntityExtension1 = Stub <ISynchronizable>(); _suppliedSourceEntityExtension1 .Expect(x => x.Synchronize(Arg <object> .Is.Anything)) .Return(true); // Source extension entry, mapped from the resource object, will be a "transient" entity var sourceExtensions = new Dictionary <string, object>(); _suppliedSourceEntity = new FakeEntityWithExtensions(sourceExtensions); // Target extension entries during synchronization are "persistent" entities loaded through NHibernate, and due to the NHibernate mapping approach for extensions, will be a list with a single "persistent" entity _suppliedTargetEntityExtension1 = Stub <ISynchronizable>(); var targetExtensions = new Dictionary <string, object> { { "Extension1", new List <ISynchronizable> { _suppliedTargetEntityExtension1 } } }; _suppliedTargetEntity = new FakeEntityWithExtensions(targetExtensions); }
public static ISynchronizable Or(this ISynchronizable lhs, ISynchronizable rhs) { if (lhs == null) { throw new ArgumentNullException(nameof(lhs)); } if (rhs == null) { throw new ArgumentNullException(nameof(rhs)); } if (lhs is EmptySynchronizable && rhs is EmptySynchronizable) { return(Empty()); } else if (lhs is EmptySynchronizable) { return(rhs); } else if (rhs is EmptySynchronizable) { return(lhs); } else { return(new OrSynchronizable(lhs, rhs)); } }
public static TValue FindOrCreate <TKey, TValue>(this ISynchronizable <IDictionary <TKey, TValue> > items, TKey key, Func <TValue> factory) { TValue value = default(TValue); items.Lock.Write(d => d.TryGetValue(key, out value), d => d.Add(key, value = factory())); return(value); }
private static ISynchronizable[] ObjectsToISync(NativeObject[] objects) { ISynchronizable[] newArray = new ISynchronizable[objects.Length]; for (int i = 0; i < newArray.Length; i++) newArray[i] = objects[i].Handle; return newArray; }
protected override void Arrange() { _suppliedSourceEntityExtension1 = Stub <ISynchronizable>(); _suppliedSourceEntityExtension2 = Stub <ISynchronizable>(); // First extension has modifications _suppliedSourceEntityExtension1 .Expect(x => x.Synchronize(Arg <object> .Is.Anything)) .Return(true); // Second extension has no modifications, but should not overwrite state _suppliedSourceEntityExtension2 .Expect(x => x.Synchronize(Arg <object> .Is.Anything)) .Return(false); // Source extension entry, mapped from the resource object, will be a ArrayList of "transient" entities var sourceExtensions = new Dictionary <string, object> { { "Extension1", new ArrayList { _suppliedSourceEntityExtension1 } }, { "Extension2", new ArrayList { _suppliedSourceEntityExtension2 } } }; _suppliedSourceEntity = new FakeEntityWithExtensions(sourceExtensions); // Target extension entries during synchronization are "persistent" entities loaded through NHibernate, and due to the NHibernate mapping approach for extensions, will be a list with a single "persistent" entity _suppliedTargetEntityExtension1 = Stub <ISynchronizable>(); _suppliedTargetEntityExtension2 = Stub <ISynchronizable>(); var targetExtensions = new Dictionary <string, object> { { "Extension1", new List <ISynchronizable> { _suppliedTargetEntityExtension1 } }, { "Extension2", new List <ISynchronizable> { _suppliedTargetEntityExtension2 } } }; _suppliedTargetEntity = new FakeEntityWithExtensions(targetExtensions); }
public PauseSynchronizable(ISynchronizable operand, int millisecondsPause) : base(operand) { if (millisecondsPause < -1) { throw new ArgumentOutOfRangeException(nameof(millisecondsPause), Resources.GetString("Synchronizable_Pause_InvalidMillisecondsPause")); } m_millisecondsPause = millisecondsPause; }
public DelaySynchronizable(ISynchronizable operand, int millisecondsDelay) : base(operand) { if (millisecondsDelay < -1) { throw new ArgumentOutOfRangeException(nameof(millisecondsDelay), Resources.GetString("Synchronizable_Delay_InvalidMillisecondsDelay")); } m_millisecondsDelay = millisecondsDelay; }
public static ISynchronizable Delay(this ISynchronizable source, TimeSpan delay) { var totalMilliseconds = (long)delay.TotalMilliseconds; if (totalMilliseconds < -1 || int.MaxValue < totalMilliseconds) { throw new ArgumentOutOfRangeException(nameof(delay), Resources.GetString("Synchronizable_Delay_InvalidDelay")); } return(source.Delay((int)totalMilliseconds)); }
/// <summary> /// Signals the object and waits for another. /// </summary> public virtual NtStatus SignalAndWait(ISynchronizable waitObject, bool alertable, long timeout, bool relative) { long realTimeout = relative ? -timeout : timeout; return(Win32.NtSignalAndWaitForSingleObject( this, waitObject.Handle, alertable, ref realTimeout )); }
private static ISynchronizable[] ObjectsToISync(NativeObject[] objects) { ISynchronizable[] newArray = new ISynchronizable[objects.Length]; for (int i = 0; i < newArray.Length; i++) { newArray[i] = objects[i].Handle; } return(newArray); }
private void CreateWaiterThread(ISynchronizable obj = null) { WaiterThread waiterThread = new WaiterThread(this); waiterThread.ObjectSignaled += this.OnObjectSignaled; if (obj != null) { waiterThread.Add(obj); } lock (_waiterThreads) _waiterThreads.Add(waiterThread); }
public bool Remove(ISynchronizable obj) { lock (_waitObjects) { if (!_waitObjects.Contains(obj)) { return(false); } _waitObjects.Remove(obj); this.NotifyChange(); return(true); } }
public bool Add(ISynchronizable obj) { lock (_waitObjects) { // Check if we already have the maximum number of wait objects. if (_waitObjects.Count >= Win32.MaximumWaitObjects) { return(false); } _waitObjects.Add(obj); this.NotifyChange(); return(true); } }
public Whisper.WhisperResult GetWhisperResult(ISynchronizable syncObj) { AsyncResultSync asyncResultSync = syncObj as AsyncResultSync; if (asyncResultSync == null || this.RelayClient == null) { Log <TalkService> .Logger.Error("RelayClient is not connected"); return(Whisper.WhisperResult.LogicalFail); } if (!this.RelayClient.EndWhisper(asyncResultSync.AsyncResult)) { return(Whisper.WhisperResult.OffLine); } return(Whisper.WhisperResult.Success); }
/// <summary> /// Removes an object the waiter is waiting on. /// </summary> /// <param name="obj">An object which is currently being waited on.</param> /// <returns>Whether the object was successfully removed.</returns> public bool Remove(ISynchronizable obj) { foreach (var waiterThread in this.GetWaiterThreads()) { if (waiterThread.Remove(obj)) { lock (_waitObjects) _waitObjects.Remove(obj); this.BalanceWaiterThreads(); return(true); } } // We couldn't remove the object. return(false); }
/// <summary> /// Signals the object and waits for another. /// </summary> public virtual NtStatus SignalAndWait(ISynchronizable waitObject, bool alertable, long timeout, bool relative) { NtStatus status; long realTimeout = relative ? -timeout : timeout; if ((status = Win32.NtSignalAndWaitForSingleObject( this, waitObject.Handle, alertable, ref timeout )) >= NtStatus.Error) { Win32.ThrowLastError(status); } return(status); }
/// <summary> /// Adds an object for the waiter to wait on. /// </summary> /// <param name="obj">The object to wait for.</param> public void Add(ISynchronizable obj) { lock (_waitObjects) _waitObjects.Add(obj); foreach (var waiterThread in this.GetWaiterThreads()) { if (waiterThread.Add(obj)) { return; } } // We couldn't add the object to any existing waiter thread. // Create a new waiter thread and add the object to that. this.CreateWaiterThread(obj); }
public static void Initialize(IServiceProvider serviceProvider) { ApplicationDbContext context = serviceProvider.GetRequiredService <ApplicationDbContext>(); context.Database.EnsureCreated(); CreateProgrammerUserAsync(context, serviceProvider).GetAwaiter().GetResult(); Type type = typeof(ISynchronizable); IEnumerable <Type> types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => type.IsAssignableFrom(p) && !p.IsInterface); foreach (Type t in types) { ISynchronizable temp = (ISynchronizable)ActivatorUtilities.CreateInstance(serviceProvider, t); temp.AddEntitiesAsync().GetAwaiter().GetResult(); } }
public static ISynchronizable Delay(this ISynchronizable source, int millisecondsDelay) { if (millisecondsDelay < -1) { throw new ArgumentOutOfRangeException(nameof(millisecondsDelay), Resources.GetString("Synchronizable_Delay_InvalidMillisecondsDelay")); } if (millisecondsDelay == 0) { return(Empty()); } else if (source is EmptySynchronizable) { return(source); } else { return(new DelaySynchronizable(source, millisecondsDelay)); } }
public static ISynchronizable Pause(this ISynchronizable source, int millisecondsPause) { if (millisecondsPause < -1) { throw new ArgumentOutOfRangeException(nameof(millisecondsPause), Resources.GetString("Synchronizable_Pause_InvalidMillisecondsPause")); } if (millisecondsPause == 0) { return(Empty()); } else if (source is EmptySynchronizable) { return(source); } else { return(new PauseSynchronizable(source, millisecondsPause)); } }
public bool Add(ISynchronizable obj) { lock (_waitObjects) { // Check if we already have the maximum number of wait objects. if (_waitObjects.Count >= Win32.MaximumWaitObjects) return false; _waitObjects.Add(obj); this.NotifyChange(); return true; } }
/// <summary> /// Removes an object the waiter is waiting on. /// </summary> /// <param name="obj">An object which is currently being waited on.</param> /// <returns>Whether the object was successfully removed.</returns> public bool Remove(ISynchronizable obj) { foreach (var waiterThread in this.GetWaiterThreads()) { if (waiterThread.Remove(obj)) { lock (_waitObjects) _waitObjects.Remove(obj); this.BalanceWaiterThreads(); return true; } } // We couldn't remove the object. return false; }
public Property(ISynchronizable sync, V value) { this.s = sync; this.v = value; }
protected UnarySynchronizable(ISynchronizable operand) { m_operand = operand ?? throw new ArgumentNullException(nameof(operand)); }
private void OnObjectSignaled(ISynchronizable obj) { if (ObjectSignaled != null) ObjectSignaled(obj); }
public Property(ISynchronizable sync) : this(sync, default(V)) { }
/// <summary> /// Signals the object and waits for another. /// </summary> public virtual NtStatus SignalAndWait(ISynchronizable waitObject, bool alertable) { return(this.SignalAndWait(waitObject, alertable, long.MinValue, false)); }
public bool Remove(ISynchronizable obj) { lock (_waitObjects) { if (!_waitObjects.Contains(obj)) return false; _waitObjects.Remove(obj); this.NotifyChange(); return true; } }
private void SharedWaiter_ObjectSignaled(ISynchronizable obj) { if (obj == _processHandle) { if (this.IsHandleCreated) { this.BeginInvoke(new MethodInvoker(() => { NtStatus exitStatus = _processHandle.GetExitStatus(); string exitString = exitStatus.ToString(); long exitLong; if (exitString == "Wait0") exitString = "Success"; if (!long.TryParse(exitString, out exitLong)) { this.Text += " (exited with status " + exitString + ")"; } else { this.Text += " (exited with status 0x" + exitLong.ToString("x8") + ")"; } })); } } }
/// <summary> /// Signals the object and waits for another. /// </summary> public virtual NtStatus SignalAndWait(ISynchronizable waitObject) { return(this.SignalAndWait(waitObject, false)); }
public SyncItem(ISynchronizable <TId> change) { Id = change.Id; Stamp = change.Stamp; }
private void SharedWaiter_ObjectSignaled(ISynchronizable obj) { // Check if the object is our process handle. if (obj == _processHandle) { if (this.IsHandleCreated) { this.BeginInvoke(new MethodInvoker(() => { NtStatus exitStatus = _processHandle.GetExitStatus(); string exitString = exitStatus.ToString(); long exitLong; // We want "Success" instead of "Wait0" (both are 0x0). if (exitString == "Wait0") exitString = "Success"; // If we have a NT status string, display it. // Otherwise, display the NT status value in hex. if (!long.TryParse(exitString, out exitLong)) { this.Text += " (exited with status " + exitString + ")"; } else { this.Text += " (exited with status 0x" + exitLong.ToString("x8") + ")"; } })); } } }
private void CreateWaiterThread(ISynchronizable obj = null) { WaiterThread waiterThread = new WaiterThread(this); waiterThread.ObjectSignaled += this.OnObjectSignaled; if (obj != null) waiterThread.Add(obj); lock (_waiterThreads) _waiterThreads.Add(waiterThread); }
public static KeyValuePair <TKey, TValue>[] ToArrayLocked <TKey, TValue>(this ISynchronizable <IDictionary <TKey, TValue> > items) { return(items.Lock.Read(d => d.ToArray())); }
/// <summary> /// Signals the object and waits for another. /// </summary> public virtual NtStatus SignalAndWait(ISynchronizable waitObject, bool alertable, long timeout) { return(this.SignalAndWait(waitObject, alertable, timeout, true)); }
public ThenSynchronizable(ISynchronizable lhs, ISynchronizable rhs) : base(lhs, rhs) { }
/// <summary> /// Adds an object for the waiter to wait on. /// </summary> /// <param name="obj">The object to wait for.</param> public void Add(ISynchronizable obj) { lock (_waitObjects) _waitObjects.Add(obj); foreach (var waiterThread in this.GetWaiterThreads()) { if (waiterThread.Add(obj)) return; } // We couldn't add the object to any existing waiter thread. // Create a new waiter thread and add the object to that. this.CreateWaiterThread(obj); }