Exemplo n.º 1
0
 private void SaveState(IAsyncStateMachine stateMachine)
 {
     using (var stream = new MemoryStream())
     {
         stateMachine.SaveTo(stream);
         savedState = stream.ToArray();
     }
 }
Exemplo n.º 2
0
 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();
 }
Exemplo n.º 3
0
 public void SetStateMachine(IAsyncStateMachine stateMachine)
 {
 }
Exemplo n.º 4
0
 //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);
 }
Exemplo n.º 6
0
 public void SetStateMachine(IAsyncStateMachine stateMachine)
 {
     this.m_coreState.SetStateMachine(stateMachine);
 }
Exemplo n.º 7
0
 public AwaiterSerializableCallback(Action continuation, IAsyncStateMachine stateMachine, string awaiterResultType, bool isUiThread, IAsyncOperation asyncOperation)
 {
     IsUiThread        = isUiThread;
     AwaiterResultType = awaiterResultType;
     Initialize(continuation, stateMachine, asyncOperation);
 }
Exemplo n.º 8
0
 void IAsyncStateMachineAware.SetStateMachine(IAsyncStateMachine stateMachine)
 {
     _stateMachine = stateMachine;
 }
Exemplo n.º 9
0
 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();
 }
Exemplo n.º 11
0
 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();
 }
Exemplo n.º 12
0
 /// <summary>
 /// Associates the builder with the specified state machine.
 /// </summary>
 /// <param name="stateMachine"></param>
 public void SetStateMachine(IAsyncStateMachine stateMachine)
 {
     Debug.WriteLine($"AsyncTaskMethodBuilder:SetStateMachine");
 }
Exemplo n.º 13
0
 private static FieldInfo BuilderField(this IAsyncStateMachine sm) => sm.GetType().GetField("<>t__builder") ?? sm.GetType().GetField("$Builder");
Exemplo n.º 14
0
 public void SetStateMachine(IAsyncStateMachine stateMachine) => SetStateMachineDelegate?.Invoke(stateMachine);
Exemplo n.º 15
0
 void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
 {
     /* Данный метод не играет важной роли в этом примере. */
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 17
0
 /// <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;
 }
Exemplo n.º 19
0
 public void SetStateMachine(IAsyncStateMachine stateMachine)
 {
     this.asyncStateMachineImplementation.SetStateMachine(stateMachine);
 }
Exemplo n.º 20
0
 void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
 {
 }
Exemplo n.º 21
0
 public void SetStateMachine(IAsyncStateMachine stateMachine)
 {
     Log();
     methodBuilder.SetStateMachine(stateMachine);
 }
Exemplo n.º 22
0
 public extern void SetStateMachine(IAsyncStateMachine stateMachine);
Exemplo n.º 23
0
 public void SetStateMachine(IAsyncStateMachine stateMachine)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 24
0
            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;
                    }
                }
            }
Exemplo n.º 25
0
 private void SetStateMachine(IAsyncStateMachine stateMachine)
 {
 }
Exemplo n.º 26
0
 /// <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
 }
Exemplo n.º 27
0
 void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
 {
     //ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
     this.SetStateMachine(stateMachine);
 }
Exemplo n.º 28
0
 public void SetStateMachine(IAsyncStateMachine _) => Counters.SetStateMachine.Increment();
Exemplo n.º 29
0
 private AsyncTaskMethodBuilder(Task <TResult> task)
 {
     this.task         = task;
     this.stateMachine = null;
 }
Exemplo n.º 30
0
        /// <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&lt;T&gt;.
        /// 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&lt;VoidTaskResult&gt;.
        /// </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);
                }
            }
        }
Exemplo n.º 31
0
 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)
 {
 }
Exemplo n.º 33
0
 private void SetStateMachine(IAsyncStateMachine stateMachine)
 {
     this.asyncTaskMethodBuilder_0.SetStateMachine(stateMachine);
 }
Exemplo n.º 34
0
 public void SetStateMachine(IAsyncStateMachine stateMachine)
 {
     mb.SetStateMachine(stateMachine);
 }
Exemplo n.º 35
0
        _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);
 }
Exemplo n.º 37
0
 private AsyncVoidMethodBuilder(SynchronizationContext context)
 {
     this.context      = context;
     this.stateMachine = null;
 }
 void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine machine)
 {
     builder.SetStateMachine(machine);
 }
			void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine param0)
			{
				this.builder.SetStateMachine(param0);
			}