private void SaveState(IAsyncStateMachine stateMachine) { using (var stream = new MemoryStream()) { stateMachine.SaveTo(stream); savedState = stream.ToArray(); } }
public IAwaitable Setup() { var awaiter = new YieldingAwaiter(continuation => { stateMachine = AsyncUtil.GetStateMachine(continuation); machineContinuation = continuation; if (savedState == null) { SaveState(stateMachine); } else { stateMachine.LoadFrom(new MemoryStream(savedState)); } }); return awaiter.NewAwaitable(); }
public void SetStateMachine(IAsyncStateMachine stateMachine) { }
//przekazanie referencji do siebie samej: case heap vs stack public void SetStateMachine(IAsyncStateMachine stateMachine) { //tutaj znajdujemy się w momencie ewakuacji }
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) { this.builder.SetStateMachine(stateMachine); }
public void SetStateMachine(IAsyncStateMachine stateMachine) { this.m_coreState.SetStateMachine(stateMachine); }
public AwaiterSerializableCallback(Action continuation, IAsyncStateMachine stateMachine, string awaiterResultType, bool isUiThread, IAsyncOperation asyncOperation) { IsUiThread = isUiThread; AwaiterResultType = awaiterResultType; Initialize(continuation, stateMachine, asyncOperation); }
void IAsyncStateMachineAware.SetStateMachine(IAsyncStateMachine stateMachine) { _stateMachine = stateMachine; }
public void SetStateMachine(IAsyncStateMachine stateMachine) { //set state machine }
public void SetStateMachine(IAsyncStateMachine stateMachine) { // Method is not implemented as it is not needed for our purpose. throw new NotImplementedException(); }
public void SetStateMachine(IAsyncStateMachine stateMachine) { // Should not get called as we don't implement the optimization that this method is used for. throw new NotImplementedException(); }
/// <summary> /// Associates the builder with the specified state machine. /// </summary> /// <param name="stateMachine"></param> public void SetStateMachine(IAsyncStateMachine stateMachine) { Debug.WriteLine($"AsyncTaskMethodBuilder:SetStateMachine"); }
private static FieldInfo BuilderField(this IAsyncStateMachine sm) => sm.GetType().GetField("<>t__builder") ?? sm.GetType().GetField("$Builder");
public void SetStateMachine(IAsyncStateMachine stateMachine) => SetStateMachineDelegate?.Invoke(stateMachine);
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) { /* Данный метод не играет важной роли в этом примере. */ throw new NotImplementedException(); }
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) { throw new NotImplementedException(); }
/// <summary>Associates the builder with the specified state machine.</summary> /// <param name="stateMachine">The state machine instance to associate with the builder.</param> public void SetStateMachine(IAsyncStateMachine stateMachine) => AsyncMethodBuilderCore.SetStateMachine(stateMachine, task: null);
public void SetStateMachine(IAsyncStateMachine stateMachine) { _asyncStateMachine = stateMachine; }
public void SetStateMachine(IAsyncStateMachine stateMachine) { this.asyncStateMachineImplementation.SetStateMachine(stateMachine); }
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) { }
public void SetStateMachine(IAsyncStateMachine stateMachine) { Log(); methodBuilder.SetStateMachine(stateMachine); }
public extern void SetStateMachine(IAsyncStateMachine stateMachine);
public void SetStateMachine(IAsyncStateMachine stateMachine) { throw new NotImplementedException(); }
private void InvokeInternal(IOperationResult result) { if (StateMachineType == null || FieldSnapshots == null) { Tracer.Error("The await callback cannot be executed empty serialization state property " + (StateMachineType == null ? "StateMachineType" : "FieldSnapshots")); return; } var type = Type.GetType(StateMachineType, true); IAsyncStateMachine stateMachine = null; #if WINDOWSCOMMON || XAMARIN_FORMS if (type.GetTypeInfo().IsValueType) #else if (type.IsValueType) #endif { try { #if WINDOWSCOMMON stateMachine = (IAsyncStateMachine)Activator.CreateInstance(type); #else stateMachine = (IAsyncStateMachine)GetDefault(type); #endif } catch { ; } } else { try { var constructor = type.GetConstructor(Empty.Array <Type>()); if (constructor != null) { stateMachine = (IAsyncStateMachine)constructor.InvokeEx(); } } catch { ; } } if (stateMachine == null) { Exception e = null; try { #if WINDOWSCOMMON if (type.GetTypeInfo().IsValueType) { stateMachine = (IAsyncStateMachine)GetDefault(type); } else { stateMachine = (IAsyncStateMachine)Activator.CreateInstance(type); } #else stateMachine = (IAsyncStateMachine)Activator.CreateInstance(type); #endif } catch (Exception ex) { e = ex; } if (e != null) { Tracer.Error("The await callback cannot be executed missing constructor, state machine " + type + " " + e.Flatten(true)); return; } } var viewModels = CollectViewModels(result); var items = new Dictionary <Type, object>(); if (result.Source != null) { items[result.Source.GetType()] = result.Source; } //we need to sort fields, to restore builder as last operation. FieldSnapshots.Sort((x1, x2) => x1.FieldType.CompareTo(x2.FieldType)); for (int index = 0; index < FieldSnapshots.Count; index++) { var fieldSnapshot = FieldSnapshots[index]; if (!fieldSnapshot.Restore(type, stateMachine, items, viewModels, AwaiterResultType, result)) { object fieldInfo = (object)type.GetFieldEx(fieldSnapshot.Name, MemberFlags.NonPublic | MemberFlags.Public | MemberFlags.Instance) ?? fieldSnapshot.Name; Tracer.Error("The await callback cannot be executed, field ({0}) cannot be restored source {1}", fieldInfo, result.Source); break; } } }
private void SetStateMachine(IAsyncStateMachine stateMachine) { }
/// <summary>Associates the builder with the state machine it represents.</summary> /// <param name="stateMachine">The heap-allocated state machine object.</param> /// <exception cref="System.ArgumentNullException">The <paramref name="stateMachine"/> argument was null (Nothing in Visual Basic).</exception> /// <exception cref="System.InvalidOperationException">The builder is incorrectly initialized.</exception> public void SetStateMachine(IAsyncStateMachine stateMachine) { AsyncMethodBuilderCore.SetStateMachine(stateMachine, m_moveNextAction); // argument validation handled by AsyncMethodBuilderCore }
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) { //ILSpy generated this explicit interface implementation from .override directive in SetStateMachine this.SetStateMachine(stateMachine); }
public void SetStateMachine(IAsyncStateMachine _) => Counters.SetStateMachine.Increment();
private AsyncTaskMethodBuilder(Task <TResult> task) { this.task = task; this.stateMachine = null; }
/// <summary> /// This is the core to find the continuation delegate(s) inside the given async state machine. /// The chain of objects is like this: async state machine -> async method builder -> task -> continuation object -> action. /// </summary> /// <remarks> /// There are 3 types of "async method builder": AsyncVoidMethodBuilder, AsyncTaskMethodBuilder, AsyncTaskMethodBuilder<T>. /// We don't cover AsyncVoidMethodBuilder as it is used rarely and it can't be awaited either; /// AsyncTaskMethodBuilder is a wrapper on top of AsyncTaskMethodBuilder<VoidTaskResult>. /// </remarks> private static IEnumerable <Delegate> FindContinuationDelegates(IAsyncStateMachine stateMachine) { Requires.NotNull(stateMachine, nameof(stateMachine)); var builder = GetStateMachineFieldValueOnSuffix(stateMachine, "__builder"); if (builder == null) { yield break; } var task = GetFieldValue(builder, "m_task"); if (task == null) { // Probably this builder is an instance of "AsyncTaskMethodBuilder", so we need to get its inner "AsyncTaskMethodBuilder<VoidTaskResult>" builder = GetFieldValue(builder, "m_builder"); if (builder != null) { task = GetFieldValue(builder, "m_task"); } } if (task == null) { yield break; } // "task" might be an instance of the type deriving from "Task", but "m_continuationObject" is a private field in "Task", // so we need to use "typeof(Task)" to access "m_continuationObject". var continuationField = typeof(Task).GetTypeInfo().GetDeclaredField("m_continuationObject"); if (continuationField == null) { yield break; } var continuationObject = continuationField.GetValue(task); if (continuationObject == null) { yield break; } if (continuationObject is IEnumerable items) { foreach (var item in items) { var action = item as Delegate ?? GetFieldValue(item, "m_action") as Delegate; if (action != null) { yield return(action); } } } else { var action = continuationObject as Delegate ?? GetFieldValue(continuationObject, "m_action") as Delegate; if (action != null) { yield return(action); } } }
public void SetStateMachine(IAsyncStateMachine stateMachine) { builder.SetStateMachine(stateMachine); }
/// <summary> /// Set the state machine. /// </summary> /// <param name="stateMachine">State machine.</param> public void SetStateMachine(IAsyncStateMachine stateMachine) { }
private void SetStateMachine(IAsyncStateMachine stateMachine) { this.asyncTaskMethodBuilder_0.SetStateMachine(stateMachine); }
public void SetStateMachine(IAsyncStateMachine stateMachine) { mb.SetStateMachine(stateMachine); }
_methodBuilder.Start(ref stateMachine); // will provide the right ExecutionContext semantics /// <summary>Associates the builder with the specified state machine.</summary> /// <param name="stateMachine">The state machine instance to associate with the builder.</param> public void SetStateMachine(IAsyncStateMachine stateMachine) => _methodBuilder.SetStateMachine(stateMachine);
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine machine) { builder.SetStateMachine(machine); }
private AsyncVoidMethodBuilder(SynchronizationContext context) { this.context = context; this.stateMachine = null; }
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine param0) { this.builder.SetStateMachine(param0); }