Ejemplo n.º 1
0
            public void MoveNext()
            {
                if (state == 0)
                {
                    awaiter = Task.Delay(5000).GetAwaiter();
                    if (awaiter.IsCompleted)
                    {
                        state = 1;
                        goto state1;
                    }
                    else
                    {
                        state = 1;
                        mb.AwaitUnsafeOnCompleted(ref awaiter, ref this);
                    }
                    return;
                }

state1:
                if (state == 1)
                {
                    awaiter.GetResult();
                    mb.SetResult("asdasd");
                    return;

                }
            }
			void IAsyncStateMachine.MoveNext()
			{
				string result = null;
				try
				{
					int num = this.state;
					if (num != -3)
					{
						TaskAwaiter<string> taskAwaiter;
						if (num != 0)
						{
							this.httpClient = new HttpClient();
							this.task = this.httpClient.GetStringAsync("http://web.myresource.org/angular/current/version.txt");
							Console.WriteLine("hello, asynchronous!");
							taskAwaiter = this.task.GetAwaiter();
							if (!taskAwaiter.IsCompleted)
							{
								this.state = 0;
								this.outerAwaiter = taskAwaiter;
                                this.builder.AwaitUnsafeOnCompleted<TaskAwaiter<string>, AsyncAndAwaitImplement.StateMachine>(ref taskAwaiter, ref this);
								return;
							}
						}
						else
						{
							taskAwaiter = this.outerAwaiter;
							this.outerAwaiter = default(TaskAwaiter<string>);
							this.state = -1;
						}
						string arg_B3_0 = taskAwaiter.GetResult();
						taskAwaiter = default(TaskAwaiter<string>);
						string text = arg_B3_0;
						this.result = text;
						Console.WriteLine("{0}", this.result);
						result = this.result;
					}
				}
				catch (Exception exception)
				{
					this.state = -2;
					this.builder.SetException(exception);
					return;
				}
				this.state = -2;
				this.builder.SetResult(result);
			}
Ejemplo n.º 3
0
            public void MoveNext()
            {
                int result;
                try
                {
#pragma warning disable 0219 // doFinallyBodies is never used
                    bool doFinallyBodies = true;
#pragma warning restore
                    if (state != 1)
                    {
                        if (state != -1)
                        {
                            task = Task<int>.Factory.StartNew(() => 5);
                            awaiter = task.GetAwaiter();
                            if (awaiter.IsCompleted)
                            {
                                goto Label_GetResult;
                            }
                            state = 1;
                            doFinallyBodies = false;
                            awaiter.OnCompleted(moveNextDelegate);
                        }
                        return;
                    }
                    state = 0;
                  Label_GetResult: // target of state=1
                    int awaitResult = awaiter.GetResult();
                    awaiter = default(TaskAwaiter<int>);
                    result = awaitResult;
                }
                catch (Exception e)
                {
                    state = -1;
                    builder.SetException(e);
                    return;
                }
                state = -1;
                builder.SetResult(result);
            }
 public async Task RunLoop()
 {
   await Task.Delay(WintermintUpdateDaemon.InitialUpdateDelay);
   TaskAwaiter awaiter;
   while (true)
   {
     LaunchData.TryLaunch("wintermint-update", (string) null);
     awaiter = Task.Delay(WintermintUpdateDaemon.UpdateDelay).GetAwaiter();
     if (awaiter.IsCompleted)
     {
       awaiter.GetResult();
       awaiter = new TaskAwaiter();
     }
     else
       break;
   }
   // ISSUE: explicit reference operation
   // ISSUE: reference to a compiler-generated field
   (^this).\u003C\u003E1__state = 1;
   TaskAwaiter taskAwaiter = awaiter;
   // ISSUE: explicit reference operation
   // ISSUE: reference to a compiler-generated field
   (^this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted<TaskAwaiter, WintermintUpdateDaemon.\u003CRunLoop\u003Ed__0>(ref awaiter, this);
 }
Ejemplo n.º 5
0
            public void MoveNext()
            {
                string str;
                int    num = this._state;

                try
                {
                    ConfiguredTaskAwaitable <Stream> .ConfiguredTaskAwaiter awaiter;
                    switch (num)
                    {
                    case 0:
                        break;

                    case 1:
                        goto Label_00C3;

                    default:
                        this._path = null;
                        this._streamVideoSource = this.source as StreamVideoSource;
                        if (this._streamVideoSource?.Stream == null)
                        {
                            goto Label_01FB;
                        }
                        awaiter = this._streamVideoSource.GetStreamAsync(this.cancellationToken).ConfigureAwait(false).GetAwaiter();
                        if (awaiter.IsCompleted)
                        {
                            goto Label_00AC;
                        }
                        this._state             = num = 0;
                        this._configuredAwaiter = awaiter;
                        this._builder.AwaitUnsafeOnCompleted(ref awaiter, ref this);
                        return;
                    }
                    awaiter = this._configuredAwaiter;
                    this._configuredAwaiter = new ConfiguredTaskAwaitable <Stream> .ConfiguredTaskAwaiter();

                    this._state = num = -1;
Label_00AC:
                    Stream introduced9 = awaiter.GetResult();
                    awaiter            = new ConfiguredTaskAwaitable <Stream> .ConfiguredTaskAwaiter();

                    Stream stream = introduced9;
                    this._stream = stream;
                    Label_00C3 :;
                    try
                    {
                        if (num != 1)
                        {
                            if (this._stream == null)
                            {
                                goto Label_01F4;
                            }
                            string fileName = this._this.GetFileName(this._stream, this._streamVideoSource.Format);
                            string str3     = Path.Combine(Path.GetTempPath(), "MediaCache");
                            this._path = Path.Combine(str3, fileName);
                            if (File.Exists(this._path))
                            {
                                goto Label_01F4;
                            }
                            if (!Directory.Exists(str3))
                            {
                                Directory.CreateDirectory(str3);
                            }
                            this._tempFile = File.Create(this._path);
                        }
                        try
                        {
                            TaskAwaiter awaiter2;
                            if (num != 1)
                            {
                                awaiter2 = this._stream.CopyToAsync(this._tempFile).GetAwaiter();
                                if (!awaiter2.IsCompleted)
                                {
                                    this._state   = num = 1;
                                    this._awaiter = awaiter2;
                                    this._builder.AwaitUnsafeOnCompleted(ref awaiter2, ref this);
                                    return;
                                }
                            }
                            else
                            {
                                awaiter2      = this._awaiter;
                                this._awaiter = new TaskAwaiter();
                                this._state   = num = -1;
                            }
                            awaiter2.GetResult();
                            awaiter2 = new TaskAwaiter();
                        }
                        finally
                        {
                            if ((num < 0) && (this._tempFile != null))
                            {
                                this._tempFile.Dispose();
                            }
                        }
                        this._tempFile = null;
                    }
                    finally
                    {
                        if ((num < 0) && (this._stream != null))
                        {
                            this._stream.Dispose();
                        }
                    }
Label_01F4:
                    this._stream = null;
Label_01FB:
                    str = this._path;
                }
                catch (Exception exception)
                {
                    this._state = -2;
                    this._builder.SetException(exception);
                    return;
                }
                this._state = -2;
                this._builder.SetResult(str);
            }
Ejemplo n.º 6
0
 public TaskOperation(Task <T> task)
 {
     Task        = task;
     TaskAwaiter = Task.GetAwaiter();
 }
Ejemplo n.º 7
0
 public WcfContextAwaiter(Task task)
 {
     Validate(task);
     m_Awaiter = task.GetAwaiter();
 }
Ejemplo n.º 8
0
            void IAsyncStateMachine.MoveNext()
            {
                int num = this.state;

                try
                {
                    TaskAwaiter awaiter1;
                    switch (num)
                    {
                    default:
                        goto MethodStart;

                    case 0:
                        goto FirstAwaitContinuation;

                    case 1:
                        goto SecondAwaitContinuation;
                    }
MethodStart:
                    Console.WriteLine("Before first delay");
                    awaiter1 = Task.Delay(this.delay).GetAwaiter();
                    if (awaiter1.IsCompleted)
                    {
                        goto GetFirstAwaitResult;
                    }
                    this.state   = num = 0;
                    this.awaiter = awaiter1;
                    this.builder.AwaitUnsafeOnCompleted(ref awaiter1, ref this);
                    return;

FirstAwaitContinuation:
                    awaiter1     = this.awaiter;
                    this.awaiter = default(TaskAwaiter);
                    this.state   = num = -1;
GetFirstAwaitResult:
                    awaiter1.GetResult();
                    for (int i = 0; i < 3; i++)
                    {
                        Console.WriteLine("Between delays");
                    }
                    TaskAwaiter awaiter2 = Task.Delay(this.delay).GetAwaiter();
                    if (awaiter2.IsCompleted)
                    {
                        goto GetSecondAwaitResult;
                    }
                    this.state   = num = 1;
                    this.awaiter = awaiter2;
                    this.builder.AwaitUnsafeOnCompleted(ref awaiter2, ref this);
                    return;

SecondAwaitContinuation:
                    awaiter2     = this.awaiter;
                    this.awaiter = default(TaskAwaiter);
                    this.state   = num = -1;
GetSecondAwaitResult:
                    awaiter2.GetResult();
                    Console.WriteLine("After second delay");
                }
                catch (Exception exception)
                {
                    this.state = -2;
                    this.builder.SetException(exception);
                    return;
                }
                this.state = -2;
                this.builder.SetResult();
            }
    private async Task RunLoop()
    {
      await Task.Delay(RiotUpdateDaemon.InitialUpdateDelay);
      TaskAwaiter awaiter1;
      TaskAwaiter awaiter2;
      while (true)
      {
        awaiter1 = this.TryUpdate().GetAwaiter();
        if (awaiter1.IsCompleted)
        {
          awaiter1.GetResult();
          awaiter1 = new TaskAwaiter();
          awaiter2 = Task.Delay(RiotUpdateDaemon.UpdateDelay).GetAwaiter();
          if (awaiter2.IsCompleted)
          {
            awaiter2.GetResult();
            awaiter2 = new TaskAwaiter();
          }
          else
            goto label_6;
        }
        else
          break;
      }
      // ISSUE: explicit reference operation
      // ISSUE: reference to a compiler-generated field
      state = 1;
      TaskAwaiter taskAwaiter = awaiter1;
      // ISSUE: explicit reference operation
      // ISSUE: reference to a compiler-generated field
      (^this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted<TaskAwaiter, RiotUpdateDaemon.\u003CRunLoop\u003Ed__1f>(ref awaiter1, this);
      return;
label_6:
      // ISSUE: explicit reference operation
      // ISSUE: reference to a compiler-generated field
      (^this).\u003C\u003E1__state = 2;
      taskAwaiter = awaiter2;
      // ISSUE: explicit reference operation
      // ISSUE: reference to a compiler-generated field
      (^this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted<TaskAwaiter, RiotUpdateDaemon.\u003CRunLoop\u003Ed__1f>(ref awaiter2, this);
    }
Ejemplo n.º 10
0
            private void MoveNextSingleYield()
            {
                int num = state;
                int result;

                try
                {
                    TaskAwaiter <int>           awaiter;
                    YieldAwaitable.YieldAwaiter awaiter2;
                    if (num != 0)
                    {
                        if (num == 1)
                        {
                            awaiter = u__2;
                            u__2    = default(TaskAwaiter <int>);
                            num     = (state = -1);
                            goto IL_00fb;
                        }
                        awaiter2 = Task.Yield().GetAwaiter();
                        if (!awaiter2.IsCompleted)
                        {
                            num  = (state = 0);
                            u__1 = awaiter2;
                            //CountRecursivelyAsyncd__1 stateMachine = this;
                            t__builder.AwaitUnsafeOnCompleted(ref awaiter2, ref this);
                            return;
                        }
                    }
                    else
                    {
                        awaiter2 = u__1;
                        u__1     = default(YieldAwaitable.YieldAwaiter);
                        num      = (state = -1);
                    }
                    awaiter2.GetResult();
                    if (count > 0)
                    {
                        awaiter = CountRecursivelyAsync(count - 1).GetAwaiter();
                        if (!awaiter.IsCompleted)
                        {
                            num  = (state = 1);
                            u__2 = awaiter;
                            //CountRecursivelyAsyncd__1 stateMachine = this;
                            t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref this);
                            return;
                        }
                        goto IL_00fb;
                    }
                    result = count;
                    goto end_IL_0007;
IL_00fb:
                    s__1   = awaiter.GetResult();
                    result = 1 + s__1;
                    end_IL_0007 :;
                }
                catch (Exception exception)
                {
                    state = -2;
                    t__builder.SetException(exception);
                    return;
                }
                state = -2;
                t__builder.SetResult(result);
            }
Ejemplo n.º 11
0
            public void MoveNext()
            {
                int result;
                try
                {
                    bool doFinallyBodies = true;
                    int tmpState = state;

                    // Effectively a three way switch: 1, -1, 0
                    if (tmpState != 1)
                    {
                        if (state == -1)
                        {
                            return;
                        }
                        this.writer = File.CreateText("output.txt");
                    }
                    try
                    {
                        tmpState = state;
                        if (tmpState == 1)
                        {
                            goto Label_ResumePoint;
                        }
                        sum = 0;
                        i = 0;
                      Label_ResumePoint: // This shouldn't quite be here... see below
                        while (i < loopCount)
                        {
                            // Not in generated code:
                            if (state == 1)
                            {
                                goto Label_ResumePoint2;
                            }
                            // Back to generated code

                            valueFetcher = Task.Factory.StartNew(() => 1);
                            j = 0;

                            // Still not in the generated code, and still not quite right... we don't want the j test here
                          Label_ResumePoint2:
                            // Back to generated code again...
                            while (j < 3)
                            {
                                try
                                {
                                    // We want Label_ResumePoint to be here really
                                    tmpState = state;
                                    if (tmpState != 1)
                                    {
                                        Console.WriteLine("Awaiting...");
                                        awaiter = valueFetcher.GetAwaiter();
                                        if (!awaiter.IsCompleted)
                                        {
                                            state = 1;
                                            doFinallyBodies = false;
                                            awaiter.OnCompleted(moveNextDelegate);
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        state = 0;
                                    }
                                    int awaitResult = awaiter.GetResult();
                                    awaiter = new TaskAwaiter<int>();
                                    value = awaitResult;
                                    writer.WriteLine("Got value {0}", value);
                                    sum += value;
                                    break;
                                }
                                catch (Exception)
                                {
                                    Console.WriteLine("Oops... retrying");
                                }
                                j++;
                            }
                            i++;
                        }
                        result = sum;
                    }
                    finally
                    {
                        if (doFinallyBodies && writer != null)
                        {
                            writer.Dispose();
                        }
                    }
                }
                catch (Exception e)
                {
                    state = -1;
                    builder.SetException(e);
                    return;
                }
                state = -1;
                builder.SetResult(result);
            }
Ejemplo n.º 12
0
        public void Toggle(bool open, int durationMs)
        {
            var animationFn = AnimationFunction(Settings.Instance.ToggleAnimationType);
            var frameTimeMs = Settings.Instance.ToggleAnimationFrameTimeMs;

            Log.Information(open?"Open":"Close");
            if (open)
            {
                FocusTracker.FocusGained(_process);
            }
            var screen = GetScreenWithCursor();

            User32.ShowWindow(_process.MainWindowHandle, NCmdShow.RESTORE);
            User32.SetForegroundWindow(_process.MainWindowHandle);

            // Used to accurately measure how far we are in the animation
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            TimeSpan ts    = stopWatch.Elapsed;
            var      curMs = ts.TotalMilliseconds;

            // Run the open/close animation
            while (curMs < durationMs)
            {
                // Asynchronously start the timer for this frame (unless frameTimeMs is 0)
                TaskAwaiter frameTimer = (frameTimeMs == 0)? new TaskAwaiter(): Task.Delay(TimeSpan.FromMilliseconds(frameTimeMs)).GetAwaiter();

                // Render the next frame of animation
                var animationX = open ? (curMs / durationMs) : (1.0 - (curMs / durationMs));
                var bounds     = GetBounds(screen, animationFn(animationX));
                User32.MoveWindow(_process.MainWindowHandle, bounds.X, bounds.Y, bounds.Width, bounds.Height, true);
                User32.ThrowIfError();

                ts    = stopWatch.Elapsed;
                curMs = (double)ts.TotalMilliseconds;
                if (frameTimeMs != 0)
                {
                    frameTimer.GetResult();                     // Wait for the timer to end
                }
            }
            stopWatch.Stop();

            // To ensure sure we end up in exactly the correct final position
            var finalBounds = GetBounds(screen, open?1.0:0.0);

            User32.MoveWindow(_process.MainWindowHandle, finalBounds.X, finalBounds.Y, finalBounds.Width, finalBounds.Height, true);
            User32.ThrowIfError();


            if (open)
            {
                if (Settings.Instance.VerticalScreenCoverage >= 100 && Settings.Instance.HorizontalScreenCoverage >= 100)
                {
                    User32.ShowWindow(_process.MainWindowHandle, NCmdShow.MAXIMIZE);
                }
            }
            else
            {
                // Minimize, so the last window gets focus
                User32.ShowWindow(_process.MainWindowHandle, NCmdShow.MINIMIZE);

                // Hide, so the terminal windows doesn't linger on the desktop
                User32.ShowWindow(_process.MainWindowHandle, NCmdShow.HIDE);
            }
        }
 public TaskAwaiterWrapper(TaskAwaiter taskAwaiter)
 {
     this.taskAwaiter = taskAwaiter;
 }
Ejemplo n.º 14
0
 internal GremlinQueryAwaiter(TaskAwaiter <TElement[]> valueTaskAwaiter)
 {
     _valueTaskAwaiter = valueTaskAwaiter;
 }
Ejemplo n.º 15
0
 public ContextAwaiter(Task task, Control control, bool alwaysAsync)
 {
     _awaiter     = task.GetAwaiter();
     _control     = control;
     _alwaysAsync = alwaysAsync;
 }
 public ClientesRepository()
 {
     getAwaiter = new TaskAwaiter();
 }
      private async Task TrackProgressAsync()
      {
        StreamReader stream = this.Process.StandardError;
        TaskAwaiter<string> awaiter;
        while (true)
        {
          awaiter = stream.ReadLineAsync().GetAwaiter();
          if (awaiter.IsCompleted)
          {
            string result = awaiter.GetResult();
            awaiter = new TaskAwaiter<string>();
            string line;
            if ((line = result) != null)
            {
              GroupCollection groups = RiotUpdateDaemon.RiotUpdaterProgressParser.Match(line).Groups;
              string s1 = groups["position"].Value;
              string s2 = groups["length"].Value;
              this.Status = groups["status"].Value;
              long.TryParse(s1, out this.Position);
              long.TryParse(s2, out this.Length);
              this.notifyChange();
            }
            else
              break;
          }
          else
            goto label_5;
        }
        this.SetCompleted();
label_5:
        // ISSUE: explicit reference operation
        // ISSUE: reference to a compiler-generated field
        (^this).\u003C\u003E1__state = 0;
        TaskAwaiter<string> taskAwaiter = awaiter;
        // ISSUE: explicit reference operation
        // ISSUE: reference to a compiler-generated field
        (^this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted<TaskAwaiter<string>, RiotUpdateDaemon.UpdaterState.\u003CTrackProgressAsync\u003Ed__27>(ref awaiter, this);
      }
Ejemplo n.º 18
0
		static void CreateFaultedAwaiter (out TaskAwaiter<object> awaiter)
		{
			var faultedSource = new TaskCompletionSource<object>();
			faultedSource.SetException(new Exception());
			awaiter = faultedSource.Task.GetAwaiter ();
			try {
				awaiter.GetResult ();
			} catch {
			}

			try {
				awaiter.GetResult ();
			} catch {
			}
		}
Ejemplo n.º 19
0
        public async Task HomeWorkDoneChanged(bool done)
        {
            HomeWorkDetailViewModel workDetailViewModel = this;

            try
            {
                TaskAwaiter taskAwaiter;
                int         num;
                if (done != workDetailViewModel.HomeWorkDone)
                {
                    try
                    {
                        if (workDetailViewModel.ActiveProfile.IsTutelary)
                        {
                            TaskAwaiter awaiter = ((MvxNotifyPropertyChanged)workDetailViewModel).RaisePropertyChanged("HomeWorkDone").GetAwaiter();
                            if (!awaiter.IsCompleted)
                            {
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003E1__state = num = 0;
                                taskAwaiter = awaiter;
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter, HomeWorkDetailViewModel.\u003CHomeWorkDoneChanged\u003Ed__39>(ref awaiter, this);
                                return;
                            }
                            awaiter.GetResult();
                            awaiter = workDetailViewModel._modalDialog.DisplayAlertByResourceKeysAsync("HomeWorkDetail_Update_IsTutelary", "Common_NoInternet_Title").GetAwaiter();
                            if (!awaiter.IsCompleted)
                            {
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003E1__state = num = 1;
                                taskAwaiter = awaiter;
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter, HomeWorkDetailViewModel.\u003CHomeWorkDoneChanged\u003Ed__39>(ref awaiter, this);
                                return;
                            }
                            awaiter.GetResult();
                        }
                        else if (!workDetailViewModel.HasInternetConnection)
                        {
                            TaskAwaiter awaiter = ((MvxNotifyPropertyChanged)workDetailViewModel).RaisePropertyChanged("HomeWorkDone").GetAwaiter();
                            if (!awaiter.IsCompleted)
                            {
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003E1__state = num = 2;
                                taskAwaiter = awaiter;
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter, HomeWorkDetailViewModel.\u003CHomeWorkDoneChanged\u003Ed__39>(ref awaiter, this);
                                return;
                            }
                            awaiter.GetResult();
                            awaiter = workDetailViewModel._modalDialog.DisplayAlertByResourceKeysAsync("HomeWorkStudentDetail_Update_NoInternet", "Common_NoInternet_Title").GetAwaiter();
                            if (!awaiter.IsCompleted)
                            {
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003E1__state = num = 3;
                                taskAwaiter = awaiter;
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter, HomeWorkDetailViewModel.\u003CHomeWorkDoneChanged\u003Ed__39>(ref awaiter, this);
                                return;
                            }
                            awaiter.GetResult();
                        }
                        else
                        {
                            TaskAwaiter awaiter1 = workDetailViewModel._mobileApi.SaveTeacherHomeWorkDoneStatusAsync(workDetailViewModel.ActiveProfile, workDetailViewModel._teacherHomeWork.Id, done).GetAwaiter();
                            if (!awaiter1.IsCompleted)
                            {
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003E1__state = num = 4;
                                taskAwaiter = awaiter1;
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter, HomeWorkDetailViewModel.\u003CHomeWorkDoneChanged\u003Ed__39>(ref awaiter1, this);
                                return;
                            }
                            awaiter1.GetResult();
                            workDetailViewModel._teacherHomeWorkDbDataService.AddOrUpdate(workDetailViewModel.TeacherHomeWork, (Action <TeacherHomeWorkRealm>)(_teacherHomeWork => _teacherHomeWork.Done = done));
                            workDetailViewModel._lessonDataService.AddOrUpdate(workDetailViewModel.Lesson, (Action <LessonRealm>)(lesson => lesson.IsHomeworkDone = done));
                            TaskAwaiter awaiter2 = ((MvxNotifyPropertyChanged)workDetailViewModel).RaisePropertyChanged("HomeWorkDone").GetAwaiter();
                            if (!awaiter2.IsCompleted)
                            {
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003E1__state = num = 5;
                                taskAwaiter = awaiter2;
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter, HomeWorkDetailViewModel.\u003CHomeWorkDoneChanged\u003Ed__39>(ref awaiter2, this);
                                return;
                            }
                            awaiter2.GetResult();
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorHandler.Current.HandleError(ex);
                        TaskAwaiter awaiter = ((MvxNotifyPropertyChanged)workDetailViewModel).RaisePropertyChanged("HomeWorkDone").GetAwaiter();
                        if (!awaiter.IsCompleted)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003E1__state = num = 6;
                            taskAwaiter = awaiter;
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter, HomeWorkDetailViewModel.\u003CHomeWorkDoneChanged\u003Ed__39>(ref awaiter, this);
                            return;
                        }
                        awaiter.GetResult();
                    }
                }
            }
            catch (Exception ex)
            {
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003E1__state = -2;
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003Et__builder.SetException(ex);
                return;
            }
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003E1__state = -2;
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003Et__builder.SetResult();
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskDynamicListAwaiter"/> struct.
 /// </summary>
 /// <param name="awaiter">Awaiter for <see cref="TaskDynamicListAwaitable.Wait"/> method result.</param>
 internal TaskDynamicListAwaiter(TaskAwaiter awaiter)
 {
     _awaiter = awaiter;
 }
            void IAsyncStateMachine.MoveNext()
            {
                int result = default(int);
                try
                {
                    bool doFinallyBodies = true;
                    switch (state)
                    {
                        case -3:
                            goto Done;
                        case 0:
                            goto FirstAwaitContinuation;
                        case 1:
                            goto SecondAwaitContinuation;
                    }
                    // Default case - first call (state is -1)
                    total = 0;
                    iterator = text.GetEnumerator();

                // We really want to jump straight to FirstAwaitRealContinuation, but we can't
                // goto a label inside a try block...
                FirstAwaitContinuation:
                    // foreach loop
                    try
                    {
                        // for/foreach loops typically have the condition at the end of the generated code.
                        // We want to go there *unless* we're trying to reach the first continuation.
                        if (state != 0)
                        {
                            goto LoopCondition;
                        }
                        goto FirstAwaitRealContinuation;
                    LoopBody:
                        ch = iterator.Current;
                        unicode = ch;
                        TaskAwaiter localTaskAwaiter = Task.Delay(unicode).GetAwaiter();
                        if (localTaskAwaiter.IsCompleted)
                        {
                            goto FirstAwaitCompletion;
                        }
                        state = 0;
                        taskAwaiter = localTaskAwaiter;
                        builder.AwaitUnsafeOnCompleted(ref localTaskAwaiter, ref this);
                        doFinallyBodies = false;
                        return;
                    FirstAwaitRealContinuation:
                        localTaskAwaiter = taskAwaiter;
                        taskAwaiter = default(TaskAwaiter);
                        state = -1;
                    FirstAwaitCompletion:
                        localTaskAwaiter.GetResult();
                        localTaskAwaiter = default(TaskAwaiter);
                        total += unicode;
                    LoopCondition:
                        if (iterator.MoveNext())
                        {
                            goto LoopBody;
                        }
                    }
                    finally
                    {
                        if (doFinallyBodies && iterator != null)
                        {
                            iterator.Dispose();
                        }
                    }

                    // After the loop
                    YieldAwaitable.YieldAwaiter localYieldAwaiter = Task.Yield().GetAwaiter();
                    if (localYieldAwaiter.IsCompleted)
                    {
                        goto SecondAwaitCompletion;
                    }
                    state = 1;
                    yieldAwaiter = localYieldAwaiter;
                    builder.AwaitUnsafeOnCompleted(ref localYieldAwaiter, ref this);
                    doFinallyBodies = false;
                    return;

                SecondAwaitContinuation:
                    localYieldAwaiter = yieldAwaiter;
                    yieldAwaiter = default(YieldAwaitable.YieldAwaiter);
                    state = -1;
                    SecondAwaitCompletion:
                    localYieldAwaiter.GetResult();
                    localYieldAwaiter = default(YieldAwaitable.YieldAwaiter);
                    result = total;
                }
                catch (Exception ex)
                {
                    state = -2;
                    builder.SetException(ex);
                    return;
                }
                Done:
                state = -2;
                builder.SetResult(result);
            }
Ejemplo n.º 22
0
 public EventReceiverAwaiter(TaskAwaiter <T> task)
 {
     this.task = task;
 }
        private async Task <HttpRequestMessage> CloneRequest(
            HttpRequestMessage request,
            TokenData tokenData = null)
        {
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            int num1 = (^ this).\u003C\u003E1__state;
            HttpRequestMessage result;
            HttpRequestMessage result1;

            try
            {
                result = new HttpRequestMessage(request.Method, request.RequestUri);
                IEnumerator <KeyValuePair <string, IEnumerable <string> > > enumerator1 = request.Headers.GetEnumerator();
                try
                {
                    while (enumerator1.MoveNext())
                    {
                        KeyValuePair <string, IEnumerable <string> > current = enumerator1.Current;
                        if (tokenData != null && current.Key == "Authorization")
                        {
                            result.Headers.Add(current.Key, string.Format("Bearer " + tokenData.AccessToken));
                        }
                        else
                        {
                            result.Headers.Add(current.Key, current.Value);
                        }
                    }
                }
                finally
                {
                    if (num1 < 0 && enumerator1 != null)
                    {
                        enumerator1.Dispose();
                    }
                }
                if (request.Content?.Headers.ContentType != null)
                {
                    TaskAwaiter <string> awaiter = request.Content.ReadAsStringAsync().GetAwaiter();
                    if (!awaiter.IsCompleted)
                    {
                        int num2;
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003E1__state = num2 = 0;
                        TaskAwaiter <string> taskAwaiter = awaiter;
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <string>, AuthDbMessageHandler.\u003CCloneRequest\u003Ed__7>(ref awaiter, this);
                        return;
                    }
                    result.Content = (HttpContent) new StringContent(awaiter.GetResult(), Encoding.UTF8, request.Content.Headers.ContentType.MediaType);
                    IEnumerator <KeyValuePair <string, IEnumerable <string> > > enumerator2 = request.Content.Headers.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            KeyValuePair <string, IEnumerable <string> > current = enumerator2.Current;
                            if (!current.Key.Equals("Content-Type", StringComparison.OrdinalIgnoreCase))
                            {
                                result.Content.Headers.Add(current.Key, current.Value);
                            }
                        }
                    }
                    finally
                    {
                        if (num1 < 0 && enumerator2 != null)
                        {
                            enumerator2.Dispose();
                        }
                    }
                }
                result1 = result;
            }
            catch (Exception ex)
            {
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003E1__state = -2;
                result = (HttpRequestMessage)null;
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003Et__builder.SetException(ex);
                return;
            }
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003E1__state = -2;
            result = (HttpRequestMessage)null;
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003Et__builder.SetResult(result1);
        }
 public WithinCancellableCallbackTaskAwaitable(HttpContext context, TaskAwaiter innerAwaiter) {
     _awaiter = new WithinCancellableCallbackTaskAwaiter(context, innerAwaiter);
 }
Ejemplo n.º 25
0
            void IAsyncStateMachine.MoveNext()
            {
                string result = null;

                try
                {
                    bool executeFinally = true;
                    if (m_state == -1)
                    {
                        m_local = m_argument;
                    }
                    try
                    {
                        TaskAwaiter <Type1> awaiterType1;
                        TaskAwaiter <Type2> awaiterType2;
                        switch (m_state)
                        {
                        case -1:
                            awaiterType1 = Method1Async().GetAwaiter();
                            if (!awaiterType1.IsCompleted)
                            {
                                m_state        = 0;
                                m_awaiterType1 = awaiterType1;
                                //把Method1Async的continue方法设置为调用this.movenext
                                m_builder.AwaitUnsafeOnCompleted(ref awaiterType1, ref this);
                                executeFinally = false;
                                return;
                            }
                            break;

                        case 0:
                            awaiterType1 = m_awaiterType1;
                            break;

                        case 1:
                            awaiterType2 = m_awaiterType2;
                            goto ForLoopEpilog;
                        }

                        m_result1 = awaiterType1.GetResult();

                        m_i = 0;
                        goto ForLoopBody;

ForLoopEpilog:
                        m_result2 = awaiterType2.GetResult();
                        m_i++;

ForLoopBody:
                        if (m_i < 3)
                        {
                            awaiterType2 = Method2Async().GetAwaiter();
                            if (!awaiterType2.IsCompleted)
                            {
                                m_state        = 1;
                                m_awaiterType2 = awaiterType2;
                                m_builder.AwaitUnsafeOnCompleted(ref awaiterType2, ref this);
                                executeFinally = false;
                                return;
                            }
                            goto ForLoopEpilog;
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Catch");
                    }
                    finally
                    {
                        if (executeFinally)
                        {
                            Console.WriteLine("Finally");
                        }
                    }
                }
                catch (Exception exception)
                {
                    // Unhandled exception: complete state machine's Task with exception
                    m_builder.SetException(exception);
                    return;
                }

                m_builder.SetResult(result);
            }
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            int num = (^ this).\u003C\u003E1__state;
            HttpResponseMessage response;
            HttpResponseMessage result1;

            try
            {
                response = (HttpResponseMessage)null;
                try
                {
                    TaskAwaiter awaiter1 = this._semaphore.WaitAsync().GetAwaiter();
                    if (!awaiter1.IsCompleted)
                    {
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003E1__state = num = 0;
                        TaskAwaiter taskAwaiter = awaiter1;
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter, AuthDbMessageHandler.\u003CSendAsync\u003Ed__6>(ref awaiter1, this);
                        return;
                    }
                    awaiter1.GetResult();
                    TaskAwaiter <HttpRequestMessage> taskAwaiter1;
                    HttpRequestMessage result2;
                    if (this._secureStore.GetTokenData(this._profile.Id).ExpiresAt <= DateTime.Now)
                    {
                        TaskAwaiter <TokenData> awaiter2 = ((IAuthDbDataService)Mvx.get_IoCProvider().Resolve <IAuthDbDataService>()).RefreshToken(this._profile).GetAwaiter();
                        if (!awaiter2.IsCompleted)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003E1__state = num = 1;
                            TaskAwaiter <TokenData> taskAwaiter2 = awaiter2;
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <TokenData>, AuthDbMessageHandler.\u003CSendAsync\u003Ed__6>(ref awaiter2, this);
                            return;
                        }
                        TokenData result3 = awaiter2.GetResult();
                        if (result3 == null)
                        {
                            result1 = (HttpResponseMessage)null;
                            goto label_26;
                        }
                        else
                        {
                            this._tokenInfoRepository.AddOrUpdate(new TokenInfoRealmMapper().To((Ekreta.Mobile.Core.Models.TokenInfo)JsonConvert.DeserializeObject <Ekreta.Mobile.Core.Models.TokenInfo>(TokenDecoder.Decode(result3.AccessToken))), (Action <TokenInfoRealm>)null);
                            TaskAwaiter <HttpRequestMessage> awaiter3 = this.CloneRequest(request, result3).GetAwaiter();
                            if (!awaiter3.IsCompleted)
                            {
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003E1__state = num = 2;
                                taskAwaiter1 = awaiter3;
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <HttpRequestMessage>, AuthDbMessageHandler.\u003CSendAsync\u003Ed__6>(ref awaiter3, this);
                                return;
                            }
                            result2 = awaiter3.GetResult();
                        }
                    }
                    else
                    {
                        TaskAwaiter <HttpRequestMessage> awaiter2 = this.CloneRequest(request, (TokenData)null).GetAwaiter();
                        if (!awaiter2.IsCompleted)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003E1__state = num = 3;
                            taskAwaiter1 = awaiter2;
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <HttpRequestMessage>, AuthDbMessageHandler.\u003CSendAsync\u003Ed__6>(ref awaiter2, this);
                            return;
                        }
                        result2 = awaiter2.GetResult();
                    }
                    TaskAwaiter <HttpResponseMessage> awaiter4 = base.SendAsync(result2, cancellationToken).GetAwaiter();
                    if (!awaiter4.IsCompleted)
                    {
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003E1__state = num = 4;
                        TaskAwaiter <HttpResponseMessage> taskAwaiter2 = awaiter4;
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <HttpResponseMessage>, AuthDbMessageHandler.\u003CSendAsync\u003Ed__6>(ref awaiter4, this);
                        return;
                    }
                    response = awaiter4.GetResult();
                    result1  = response;
                }
                catch (InvalidOperationException ex)
                {
                    result1 = response;
                }
                catch (HttpRequestException ex)
                {
                    if (!((IConnectivity)Mvx.get_IoCProvider().Resolve <IConnectivity>()).get_IsConnected())
                    {
                        throw new NoInternetConnectionException().SetErrorCode <NoInternetConnectionException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Services/Handlers/AuthDbMessageHandler.cs", 99);
                    }
                    throw;
                }
                finally
                {
                    if (num < 0)
                    {
                        this._semaphore.Release();
                    }
                }
            }
            catch (Exception ex)
            {
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003E1__state = -2;
                response = (HttpResponseMessage)null;
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003Et__builder.SetException(ex);
                return;
            }
label_26:
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003E1__state = -2;
            response = (HttpResponseMessage)null;
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003Et__builder.SetResult(result1);
        }
 internal WithinCancellableCallbackTaskAwaiter(HttpContext context, TaskAwaiter innerAwaiter) {
     _context = context;
     _innerAwaiter = innerAwaiter;
 }
 public SilentAwaiter(Task <T> task)
 {
     _task  = task;
     _inner = task.GetAwaiter();
 }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            //Tasks erzeugen, grundsätzlich Threads aus dem Threadpool, somit Background-Tasks
            Task t1 = new Task(() => { Console.WriteLine("Hallo aus neuem Task"); });

            t1.Start();
            Task t2 = Task.Factory.StartNew(() => { Console.WriteLine("Hallo über Factory!"); }, TaskCreationOptions.LongRunning); //Kein Threadpool Thread

            Task t3 = Task.Run(() => { Console.WriteLine("Hallo über Task.Run!"); Thread.Sleep(3000); });                          // ab .NET 4.5

            Console.WriteLine("Task 3 läuft!");
            t3.Wait(); //Blockiert weitere Ausführung bis Task 3 beendet ist.
            Console.WriteLine("Task 3 beendet!");

            //Wertrückgabe
            Task <string> t4 = Task.Run(() => { Console.WriteLine("Methode mit Rückgabe"); Thread.Sleep(3000); return("drei"); });

            //t4.Wait(); //Bei Zugriff auf Result-Property wird auf das Beenden des Tasks gewartet! Somit ist Wait() nicht notwendig
            Console.WriteLine("Ergebnis ist: " + t4.Result);

            Task <int> t5 = Task.Run <int>(Berechne);

            Console.WriteLine("t5 Ergebnis: " + t5.Result);

            goto weiter; // nur Demonstration
            //Ausnahme im Task abfangen
            Task <int> t6 = Task.Run(MethodeMitException);

            try
            {
                t6.Wait();
            }catch (AggregateException ex)
            {
                Console.WriteLine("Fehler: " + ex.Message + "\n" + ex.GetType());
                Console.WriteLine("InnerException: " + ex.InnerException.Message);
                if (ex.InnerException is NullReferenceException)
                {
                    Console.WriteLine("Erwartete Null Reference Exception");
                }
            }catch (Exception)
            {
                Console.WriteLine("Exception aufgetreten!! (nicht im Task)");
            }

weiter:     //Goto Sprungmarke (nur zur Demonstration!!!)
            // Methoden mit Übergabeparameter in neuem Task aufrufen
            Task <int> t7 = Task.Factory.StartNew(BerechneSinn, 13);

            Console.WriteLine("t7: " + t7.Result);

            Task <int> t8 = Task.Run(() => { return(BerechneMitIntUebergabe(100)); });

            Console.WriteLine("t8: " + t8.Result);

            Task t9 = Task.Run(() => MethodeMitVielenParametern(12, 2.3, "Hallo", 'c'));

            //Task abbrechen
            cts = new CancellationTokenSource(); //Instanz erstellen
            Task t10 = Task.Factory.StartNew(SchreibeX, cts.Token);

            Thread.Sleep(1500);
            cts.Cancel();

            //Continuations
            //Nach Fertigstellung eines Task, eine weitere Aufgabe ausführen
            // 1. Möglichkeit
            Console.WriteLine("Starte t11");
            Task <int> t11 = Task.Run(() => { Thread.Sleep(2000); return(42); });

            TaskAwaiter <int> awaiter = t11.GetAwaiter();

            awaiter.OnCompleted(() =>
            {
                int ergebnis = awaiter.GetResult();
                Console.WriteLine("Ergebnis von t11: " + ergebnis);
            });
            Console.WriteLine("Nach Aufruf der OnCompleted-Methode.");

            //2. Möglichkeit
            Console.WriteLine("Starte t12");
            Task <int> t12 = Task.Run(() => { Thread.Sleep(2000); return(42); });

            t12.ContinueWith(vorrigerTask =>
            {
                int ergebnis = vorrigerTask.Result;
                Console.WriteLine("Ergebnis von t12: {0}", ergebnis);
            });
            Console.WriteLine("Nach Aufruf der ContinueWith-Methode");

            //Erzeugen eines Task aus einem Abhandlungstrangs
            var tcs = new TaskCompletionSource <int>();

            new Thread(() => { Thread.Sleep(2000); tcs.SetResult(42); })
            {
                IsBackground = true
            }.Start();

            Task <int> t13 = tcs.Task;

            Console.WriteLine("Ergebnis von t13: " + t13.Result);

            Task <int> t14 = Run <int>(() => { Thread.Sleep(1000); return(42); });

            Console.WriteLine("Starten des Delays");
            Task.Delay(5000).GetAwaiter().OnCompleted(() => Console.WriteLine("5 Sekunden abgelaufen!!!!"));
            Console.WriteLine("Ende des Delays");
            Task.Delay(1000).ContinueWith(delay => Console.WriteLine("1 Sekunde abgelaufen"));

            Console.ReadLine();
        }
Ejemplo n.º 30
0
        private async Task LoadMessages()
        {
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            int num1 = (^ this).\u003C\u003E1__state;
            MessagesViewModel           messagesViewModel1 = this;
            IEnumerable <PostaladaElem> tempPostaladaElemek;

            try
            {
                tempPostaladaElemek          = (IEnumerable <PostaladaElem>)null;
                messagesViewModel1.IsLoading = true;
                TaskAwaiter <IEnumerable <PostaladaElem> > taskAwaiter;
                try
                {
                    if (messagesViewModel1.ActiveProfile == null)
                    {
                        messagesViewModel1.ActiveProfile = messagesViewModel1._profileDataService.GetActiveProfile();
                    }
                    IEnumerable <PostaladaElem>        postaladaElemek = messagesViewModel1._uzenetDataService.GetPostaladaElemek(messagesViewModel1.ActiveProfile);
                    IOrderedEnumerable <PostaladaElem> orderedEnumerable;
                    if (postaladaElemek == null)
                    {
                        orderedEnumerable = (IOrderedEnumerable <PostaladaElem>)null;
                    }
                    else
                    {
                        IEnumerable <PostaladaElem> source = postaladaElemek.Where <PostaladaElem>((Func <PostaladaElem, bool>)(x => x.Uzenet != null));
                        orderedEnumerable = source != null?source.OrderByDescending <PostaladaElem, DateTimeOffset>((Func <PostaladaElem, DateTimeOffset>)(x => x.Uzenet.KuldesDatum)) : (IOrderedEnumerable <PostaladaElem>)null;
                    }
                    IEnumerable <PostaladaElem> postaladaElems = (IEnumerable <PostaladaElem>)orderedEnumerable;
                    tempPostaladaElemek = postaladaElems;
                    if (!messagesViewModel1.HasInternetConnection)
                    {
                        if (postaladaElems == null)
                        {
                            messagesViewModel1.ShowError();
                        }
                    }
                    else
                    {
                        TaskAwaiter <IEnumerable <PostaladaElem> > awaiter = messagesViewModel1._uzenetDataService.FetchPostaladaElemek(messagesViewModel1.ActiveProfile).GetAwaiter();
                        if (!awaiter.IsCompleted)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003E1__state = num1 = 0;
                            taskAwaiter = awaiter;
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <IEnumerable <PostaladaElem> >, MessagesViewModel.\u003CLoadMessages\u003Ed__32>(ref awaiter, this);
                            return;
                        }
                        IEnumerable <PostaladaElem> result = awaiter.GetResult();
                        tempPostaladaElemek = (IEnumerable <PostaladaElem>)messagesViewModel1._uzenetDataService.OverridePostaladaElemek(messagesViewModel1.ActiveProfile, result).OrderByDescending <PostaladaElem, DateTimeOffset>((Func <PostaladaElem, DateTimeOffset>)(x => x.Uzenet.KuldesDatum));
                        messagesViewModel1._messenger.Publish <ActiveProfileChangedMessage>((M0) new ActiveProfileChangedMessage((object)messagesViewModel1, messagesViewModel1.ActiveProfile));
                    }
                }
                catch (Exception ex1)
                {
                    IEnumerable <PostaladaElem> postaladaElemek = messagesViewModel1._uzenetDataService.GetPostaladaElemek(messagesViewModel1.ActiveProfile);
                    if (postaladaElemek == null)
                    {
                        messagesViewModel1.ShowError();
                    }
                    else if (!postaladaElemek.Any <PostaladaElem>())
                    {
                        try
                        {
                            TaskAwaiter <IEnumerable <PostaladaElem> > awaiter = messagesViewModel1._uzenetDataService.FetchPostaladaElemek(messagesViewModel1.ActiveProfile).GetAwaiter();
                            if (!awaiter.IsCompleted)
                            {
                                int num2;
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003E1__state = num2 = 1;
                                taskAwaiter = awaiter;
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <IEnumerable <PostaladaElem> >, MessagesViewModel.\u003CLoadMessages\u003Ed__32>(ref awaiter, this);
                                return;
                            }
                            IEnumerable <PostaladaElem> result = awaiter.GetResult();
                            tempPostaladaElemek = (IEnumerable <PostaladaElem>)messagesViewModel1._uzenetDataService.OverridePostaladaElemek(messagesViewModel1.ActiveProfile, result).OrderByDescending <PostaladaElem, DateTimeOffset>((Func <PostaladaElem, DateTimeOffset>)(x => x.Uzenet.KuldesDatum));
                            messagesViewModel1._messenger.Publish <ActiveProfileChangedMessage>((M0) new ActiveProfileChangedMessage((object)messagesViewModel1, messagesViewModel1.ActiveProfile));
                        }
                        catch (Exception ex2)
                        {
                            CrossMobileAnalytics.Current.TrackException(ex2, (IDictionary <string, string>)null, nameof(LoadMessages), "/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/ViewModels/MessagesViewModel.cs", 151);
                        }
                    }
                    else
                    {
                        messagesViewModel1.PostaladaElemek = tempPostaladaElemek;
                    }
                    CrossMobileAnalytics.Current.TrackException(ex1, (IDictionary <string, string>)null, nameof(LoadMessages), "/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/ViewModels/MessagesViewModel.cs", 161);
                }
                MessagesViewModel           messagesViewModel2 = messagesViewModel1;
                IEnumerable <PostaladaElem> source1            = tempPostaladaElemek;
                List <PostaladaElem>        postaladaElemList  = source1 != null?source1.OrderByDescending <PostaladaElem, DateTimeOffset>((Func <PostaladaElem, DateTimeOffset>)(x => x.Uzenet.KuldesDatum)).ToList <PostaladaElem>() : (List <PostaladaElem>)null;

                messagesViewModel2.PostaladaElemek = (IEnumerable <PostaladaElem>)postaladaElemList;
                messagesViewModel1.IsLoading       = false;
            }
            catch (Exception ex)
            {
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003E1__state = -2;
                tempPostaladaElemek           = (IEnumerable <PostaladaElem>)null;
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003Et__builder.SetException(ex);
                return;
            }
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003E1__state = -2;
            tempPostaladaElemek           = (IEnumerable <PostaladaElem>)null;
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003Et__builder.SetResult();
        }
Ejemplo n.º 31
0
 public Awaiter(TaskAwaiter awaiter)
 {
     this.awaiter = awaiter;
 }
Ejemplo n.º 32
0
        protected async Task <string> DownloadFile(
            string relativeUri,
            Profile profile,
            string accessToken,
            Csatolmany csatolmany)
        {
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            int    num = (^ this).\u003C\u003E1__state;
            string filePath;
            string name;

            try
            {
                Uri requestUri = new Uri(new Uri(ConfigurationRepository.EnvironmentSetting.EugyintezesAPIUrl ?? ""), "/integration-kretamobile-api/v1" + relativeUri);
                filePath = this._dataViewer.FilePath(csatolmany.FajlNev);
                HttpClient httpClient = this.BuildHttpClient(profile);
                try
                {
                    HttpRequestMessage httpMessage = new HttpRequestMessage(HttpMethod.Get, requestUri);
                    try
                    {
                        httpMessage.Headers.Add("Accept", "application/json");
                        httpMessage.Headers.Add(this._deviceSpecification.AgentName, this._userAgentData.UserAgentText);
                        httpMessage.Headers.Add("Authorization", string.Format("Bearer " + accessToken));
                        TaskAwaiter <HttpResponseMessage> awaiter1 = httpClient.SendAsync(httpMessage, HttpCompletionOption.ResponseHeadersRead).GetAwaiter();
                        if (!awaiter1.IsCompleted)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003E1__state = num = 0;
                            TaskAwaiter <HttpResponseMessage> taskAwaiter = awaiter1;
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <HttpResponseMessage>, EugyintezesApi.\u003CDownloadFile\u003Ed__12>(ref awaiter1, this);
                            return;
                        }
                        HttpResponseMessage response = awaiter1.GetResult();
                        try
                        {
                            FileStream fs = new FileStream(filePath, FileMode.CreateNew);
                            try
                            {
                                TaskAwaiter awaiter2 = response.Content.CopyToAsync((Stream)fs).GetAwaiter();
                                if (!awaiter2.IsCompleted)
                                {
                                    // ISSUE: explicit reference operation
                                    // ISSUE: reference to a compiler-generated field
                                    (^ this).\u003C\u003E1__state = num = 1;
                                    TaskAwaiter taskAwaiter = awaiter2;
                                    // ISSUE: explicit reference operation
                                    // ISSUE: reference to a compiler-generated field
                                    (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter, EugyintezesApi.\u003CDownloadFile\u003Ed__12>(ref awaiter2, this);
                                    return;
                                }
                                awaiter2.GetResult();
                                name = fs.Name;
                            }
                            finally
                            {
                                if (num < 0 && fs != null)
                                {
                                    fs.Dispose();
                                }
                            }
                        }
                        finally
                        {
                            if (num < 0 && response != null)
                            {
                                response.Dispose();
                            }
                        }
                    }
                    finally
                    {
                        if (num < 0 && httpMessage != null)
                        {
                            httpMessage.Dispose();
                        }
                    }
                }
                finally
                {
                    if (num < 0 && httpClient != null)
                    {
                        httpClient.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003E1__state = -2;
                filePath = (string)null;
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003Et__builder.SetException(ex);
                return;
            }
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003E1__state = -2;
            filePath = (string)null;
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003Et__builder.SetResult(name);
        }
Ejemplo n.º 33
0
 public TaskAwaiterAdapter(TaskAwaiter <object[]> awaiter, string description) : base(description)
 {
     this.awaiter = awaiter;
 }
Ejemplo n.º 34
0
   // This is the state machine method itself
   void IAsyncStateMachine.MoveNext() {
      String result = null;   // Task's result value

      // Compiler-inserted try block ensures the state machine's task completes
      try {
         Boolean executeFinally = true;   // Assume we're logically leaving the 'try' block
         if (m_state == -1) {             // If 1st time in state machine method,
            m_local = m_argument;         // execute start of original method
         }

         // Try block that we had in our original code
         try {
            TaskAwaiter<Type1> awaiterType1;
            TaskAwaiter<Type2> awaiterType2;

            switch (m_state) {
               case -1: // Start execution of code in 'try'
                  // Call Method1Async and get its awaiter
                  awaiterType1 = Method1Async().GetAwaiter();
                  if (!awaiterType1.IsCompleted) {
                     m_state = 0;                   // 'Method1Async' is completing
                                                    // asynchronously
                     m_awaiterType1 = awaiterType1; // Save the awaiter for when we come back

                     // Tell awaiter to call MoveNext when operation completes
                     m_builder.AwaitUnsafeOnCompleted(ref awaiterType1, ref this);
                     // The line above invokes awaiterType1's OnCompleted which approximately
                     // calls ContinueWith(t => MoveNext()) on the Task being awaited.
                     // When the Task completes, the ContinueWith task calls MoveNext

                     executeFinally = false;        // We're not logically leaving the 'try'
                                                    // block
                     return;                        // Thread returns to caller
                  }
                  // 'Method1Async' completed synchronously
                  break;

               case 0:  // 'Method1Async' completed asynchronously
                  awaiterType1 = m_awaiterType1;  // Restore most-recent awaiter
                  break;

               case 1:  // 'Method2Async' completed asynchronously
                  awaiterType2 = m_awaiterType2;  // Restore most-recent awaiter
                  goto ForLoopEpilog;
            }

            // After the first await, we capture the result & start the 'for' loop
            m_resultType1 = awaiterType1.GetResult(); // Get awaiter's result

         ForLoopPrologue:
            m_x = 0;          // 'for' loop initialization
            goto ForLoopBody; // Skip to 'for' loop body

         ForLoopEpilog:
            m_resultType2 = awaiterType2.GetResult();
            m_x++;            // Increment x after each loop iteration
            // Fall into the 'for' loop's body

         ForLoopBody:
            if (m_x < 3) {  // 'for' loop test
               // Call Method2Async and get its awaiter
               awaiterType2 = Method2Async().GetAwaiter();
               if (!awaiterType2.IsCompleted) {
                  m_state = 1;                   // 'Method2Async' is completing asynchronously
                  m_awaiterType2 = awaiterType2; // Save the awaiter for when we come back

                  // Tell awaiter to call MoveNext when operation completes
                  m_builder.AwaitUnsafeOnCompleted(ref awaiterType2, ref this);
                  executeFinally = false;        // We're not logically leaving the 'try' block
                  return;                        // Thread returns to caller
               }
               // 'Method2Async' completed synchronously
               goto ForLoopEpilog;  // Completed synchronously, loop around
            }
         }
         catch (Exception) {
            Console.WriteLine("Catch");
         }
         finally {
            // Whenever a thread physically leaves a 'try', the 'finally' executes
            // We only want to execute this code when the thread logically leaves the 'try
'
            if (executeFinally) {
               Console.WriteLine("Finally");
            }
         }
         result = "Done"; // What we ultimately want to return from the async function
      }
      catch (Exception exception) {
         // Unhandled exception: complete state machine's Task with exception
         m_builder.SetException(exception);
         return;
      }
      // No exception: complete state machine's Task with result
      m_builder.SetResult(result);
   }
Ejemplo n.º 35
0
        public async Task <Institute> GetInstituteAsync(Institute savedInstitute)
        {
            Institute downloadedInstitute;
            Institute result;

            try
            {
                downloadedInstitute = (Institute)null;
                int num;
                try
                {
                    TaskAwaiter <Institute> awaiter = this.SendAsync <Institute>(HttpMethod.Get, "Institute/" + savedInstitute.InstituteId, (Dictionary <string, string>)null, false, (string)null).GetAwaiter();
                    if (!awaiter.IsCompleted)
                    {
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003E1__state = num = 0;
                        TaskAwaiter <Institute> taskAwaiter = awaiter;
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <Institute>, GlobalMobileApi.\u003CGetInstituteAsync\u003Ed__8>(ref awaiter, this);
                        return;
                    }
                    downloadedInstitute = awaiter.GetResult();
                }
                catch (KeyNotFoundException ex)
                {
                    CrossMobileAnalytics.Current.TrackException((Exception)ex, (IDictionary <string, string>)null, nameof(GetInstituteAsync), "/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Services/GlobalMobileApi.cs", 70);
                }
                finally
                {
                    if (downloadedInstitute == null || downloadedInstitute.InstituteCode != savedInstitute.InstituteCode || downloadedInstitute.InstituteId != savedInstitute.InstituteId)
                    {
                        TaskAwaiter <IEnumerable <Institute> > awaiter = this.GetInstitutesAsync().GetAwaiter();
                        if (!awaiter.IsCompleted)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003E1__state = num = 1;
                            TaskAwaiter <IEnumerable <Institute> > taskAwaiter = awaiter;
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <IEnumerable <Institute> >, GlobalMobileApi.\u003CGetInstituteAsync\u003Ed__8>(ref awaiter, this);
                            return;
                        }
                        downloadedInstitute = awaiter.GetResult().Where <Institute>((Func <Institute, bool>)(i => i.InstituteCode == savedInstitute.InstituteCode)).FirstOrDefault <Institute>();
                    }
                }
                result = downloadedInstitute ?? savedInstitute;
            }
            catch (Exception ex)
            {
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003E1__state = -2;
                downloadedInstitute           = (Institute)null;
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003Et__builder.SetException(ex);
                return;
            }
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003E1__state = -2;
            downloadedInstitute           = (Institute)null;
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003Et__builder.SetResult(result);
        }
Ejemplo n.º 36
0
 internal Awaiter(TaskAwaiter <TResult> awaiter)
 {
     _awaiter = awaiter;
 }
Ejemplo n.º 37
0
        private async Task <TeacherHomeWorkRealm> FetchTeacherHomeWork()
        {
            HomeWorkDetailViewModel workDetailViewModel = this;
            TeacherHomeWorkRealm    teacherHomeWork;
            TeacherHomeWorkRealm    result;

            try
            {
                teacherHomeWork = (TeacherHomeWorkRealm)null;
                try
                {
                    workDetailViewModel.IsOffline = false;
                    if (!workDetailViewModel._connectivity.get_IsConnected())
                    {
                        throw new NoInternetConnectionException().SetErrorCode <NoInternetConnectionException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/ViewModels/HomeWorkDetailViewModel.cs", 155);
                    }
                    if (workDetailViewModel.Lesson.TeacherHomeWorkId.HasValue)
                    {
                        TaskAwaiter <TeacherHomeWorkRealm> awaiter = workDetailViewModel._teacherHomeWorkDbDataService.FetchTeacherHomeWorkAsync(workDetailViewModel.ActiveProfileRealm, workDetailViewModel.Lesson.TeacherHomeWorkId.Value, true).GetAwaiter();
                        if (!awaiter.IsCompleted)
                        {
                            int num;
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003E1__state = num = 0;
                            TaskAwaiter <TeacherHomeWorkRealm> taskAwaiter = awaiter;
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <TeacherHomeWorkRealm>, HomeWorkDetailViewModel.\u003CFetchTeacherHomeWork\u003Ed__36>(ref awaiter, this);
                            return;
                        }
                        teacherHomeWork = awaiter.GetResult();
                        workDetailViewModel._teacherHomeWorkDbDataService.SaveTeacherHomeWork(workDetailViewModel.ActiveProfileRealm.RolelessId, teacherHomeWork);
                    }
                    if (teacherHomeWork == null)
                    {
                        workDetailViewModel.CreateTanarHaziFeladatFromLesson();
                    }
                }
                catch (Exception ex)
                {
                    ex.SetErrorCode <Exception>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/ViewModels/HomeWorkDetailViewModel.cs", 171);
                    switch (ex)
                    {
                    case NoInternetConnectionException _:
                    case ServerUnreachableException _:
                        workDetailViewModel.IsOffline = true;
                        result = workDetailViewModel._teacherHomeWorkDbDataService.GetTeacherHomeWork(workDetailViewModel.Lesson);
                        goto label_14;
                    }
                }
                result = teacherHomeWork;
            }
            catch (Exception ex)
            {
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003E1__state = -2;
                teacherHomeWork = (TeacherHomeWorkRealm)null;
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003Et__builder.SetException(ex);
                return;
            }
label_14:
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003E1__state = -2;
            teacherHomeWork = (TeacherHomeWorkRealm)null;
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003Et__builder.SetResult(result);
        }
Ejemplo n.º 38
0
 // Token: 0x060004FD RID: 1277
 public async void method_7(object sender, EventArgs e)
 {
     for (;;)
     {
         try
         {
             string a;
             if (this.string_1 == null)
             {
                 if (GClass0.string_2 != null && GClass0.string_2.Length > 5)
                 {
                     this.method_5("Authenticating license", "white");
                     TaskAwaiter <string> taskAwaiter = Licenser.smethod_11(GClass0.string_2, true, false).GetAwaiter();
                     bool isCompleted = taskAwaiter.IsCompleted;
                     a = taskAwaiter.GetResult();
                 }
                 else
                 {
                     this.method_5("Starting", "white");
                     a = "none";
                 }
             }
             else
             {
                 a = this.string_1;
             }
             if (a == "valid")
             {
                 this.method_6();
                 Thread.Sleep(500);
                 this.method_5(string.Format("Welcome back {0}", Licenser.string_0.Split(new char[]
                 {
                     '#'
                 })[0]), "white");
                 MainWindow.smethod_0(new EventHandler(this.method_3));
                 new MainWindow().Show();
             }
             else
             {
                 if (a == "error")
                 {
                     this.method_5(string.Format("Retrying in {0} seconds", Array.Empty <object>()), "white");
                     Thread.Sleep(1000);
                     continue;
                 }
                 MainWindow.smethod_0(new EventHandler(this.method_3));
                 new MainWindow().Show();
             }
         }
         catch
         {
             for (int i = 10; i > 0; i--)
             {
                 this.method_5(string.Format("Retrying in {0} seconds", i), "white");
                 Thread.Sleep(1000);
             }
             continue;
         }
         break;
     }
 }
Ejemplo n.º 39
0
 public override async Task Handle<TResult>(TaskAwaiter<TResult> effect)
 {            
     var result = await effect.Task;
     effect.SetResult(result);
     await Log(result, effect);
 }
Ejemplo n.º 40
0
 public NonGenericAdapter(Task task)
 {
     _awaiter = task.GetAwaiter();
 }
Ejemplo n.º 41
0
 public Awaiter(TaskAwaiter<bool> taskAwaiter)
 {
     this._taskAwaiter = taskAwaiter;
 }
Ejemplo n.º 42
0
 public GenericAdapter(Task <T> task)
 {
     _awaiter = task.GetAwaiter();
 }
Ejemplo n.º 43
0
 public RecursiveLockAwaitable(Task<IDisposable> key, RecursiveAsyncLock mutex)
 {
     _key = key;
     _awaiter = key.GetAwaiter();
     _mutex = mutex;
 }
            void IAsyncStateMachine.MoveNext()
            {
                try
                {
                    bool doFinallyBodies = true;
                    TaskAwaiter<int> localAwaiter;
                    int localLhs;

                    switch (state)
                    {
                        case -3:
                            goto Done;
                        case 0:
                            goto FirstAwaitContinuation;
                        case 1:
                            goto SecondAwaitContinuation;
                    }
                    // Default case - first call (state = -1)
                    y = 10;
                    z = Task.FromResult(10);
                    localAwaiter = z.GetAwaiter();
                    localLhs = y;
                    if (localAwaiter.IsCompleted)
                    {
                        goto FirstAwaitCompletion;
                    }
                    stack = localLhs;
                    state = 0;
                    awaiter = localAwaiter;
                    builder.AwaitUnsafeOnCompleted(ref awaiter, ref this);
                    doFinallyBodies = false;
                    return;
                FirstAwaitContinuation:
                    localLhs = (int) stack;
                    stack = null;
                    localAwaiter = awaiter;
                    awaiter = default(TaskAwaiter<int>);
                    state = -1;
                FirstAwaitCompletion:
                    int localRhs = localAwaiter.GetResult();
                    x = localLhs * localRhs;

                    // Second section of code...
                    task = Task.FromResult(20);

                    string localArg0 = "{0} {1}";
                    int localArg1 = x;
                    localAwaiter = task.GetAwaiter();
                    if (localAwaiter.IsCompleted)
                    {
                        goto SecondAwaitCompletion;
                    }
                    var localTuple = new Tuple<string, int>(localArg0, localArg1);
                    stack = localTuple;
                    state = 1;
                    awaiter = localAwaiter;
                    builder.AwaitUnsafeOnCompleted(ref awaiter, ref this);
                    doFinallyBodies = false;
                    return;
                SecondAwaitContinuation:
                    localTuple = (Tuple<string, int>) stack;
                    localArg0 = localTuple.Item1;
                    localArg1 = localTuple.Item2;
                    stack = null;
                    localAwaiter = awaiter;
                    awaiter = default(TaskAwaiter<int>);
                    state = -1;
                SecondAwaitCompletion:
                    int localArg2 = localAwaiter.GetResult();
                    Console.WriteLine(localArg0, localArg1, localArg2);
                }
                catch (Exception ex)
                {
                    state = -2;
                    builder.SetException(ex);
                    return;
                }
            Done:
                state = -2;
                builder.SetResult();
            }
        /// <summary>
        /// Submits the http put request to the specified uri.
        /// </summary>
        /// <param name="uri">The uri to which the put request will be issued.</param>
        /// <param name="body">The HTTP content comprising the body of the request.</param>
        /// <param name="allowRetry">Allow the Post to be retried after issuing a Get call. Currently used for CSRF failures.</param>
        /// <returns>Task tracking the PUT completion.</returns>
#pragma warning disable 1998
        private async Task <Stream> Put(
            Uri uri,
            IHttpContent body = null,
            bool allowRetry   = true)
        {
            IBuffer dataBuffer = null;

            HttpBaseProtocolFilter httpFilter = new HttpBaseProtocolFilter();

            httpFilter.AllowUI = false;

            if (this.deviceConnection.Credentials != null)
            {
                httpFilter.ServerCredential          = new PasswordCredential();
                httpFilter.ServerCredential.UserName = this.deviceConnection.Credentials.UserName;
                httpFilter.ServerCredential.Password = this.deviceConnection.Credentials.Password;
            }

            using (HttpClient client = new HttpClient(httpFilter))
            {
                this.ApplyHttpHeaders(client, HttpMethods.Put);

                // Send the request
                IAsyncOperationWithProgress <HttpResponseMessage, HttpProgress> responseOperation = client.PutAsync(uri, null);
                TaskAwaiter <HttpResponseMessage> responseAwaiter = responseOperation.GetAwaiter();
                while (!responseAwaiter.IsCompleted)
                {
                }

                using (HttpResponseMessage response = responseOperation.GetResults())
                {
                    if (!response.IsSuccessStatusCode)
                    {
                        // If this isn't a retry and it failed due to a bad CSRF
                        // token, issue a GET to refresh the token and then retry.
                        if (allowRetry && this.IsBadCsrfToken(response))
                        {
                            await this.RefreshCsrfToken();

                            return(await this.Put(uri, body, false));
                        }

                        throw new DevicePortalException(response);
                    }

                    this.RetrieveCsrfToken(response);

                    if (response.Content != null)
                    {
                        using (IHttpContent messageContent = response.Content)
                        {
                            IAsyncOperationWithProgress <IBuffer, ulong> bufferOperation = messageContent.ReadAsBufferAsync();
                            while (bufferOperation.Status != AsyncStatus.Completed)
                            {
                            }

                            dataBuffer = bufferOperation.GetResults();
                        }
                    }
                }
            }

            return((dataBuffer != null) ? dataBuffer.AsStream() : null);
        }
Ejemplo n.º 46
-1
            public void MoveNext()
            {
                int result;
                try
                {
#pragma warning disable 0219 // doFinallyBodies is never used
                    bool doFinallyBodies = true;
#pragma warning restore
                    switch (state)
                    {
                        case 1:
                            break;

                        case 2:
                            goto Label_Awaiter2Continuation;

                        case 3:
                            goto Label_Awaiter3Continuation;

                        default:
                            if (state != -1)
                            {
                                task1 = Task.Factory.StartNew(() => 1);
                                task2 = Task.Factory.StartNew(() => 2);
                                task3 = Task.Factory.StartNew(() => 3);

                                awaiter1 = task1.GetAwaiter();
                                if (awaiter1.IsCompleted)
                                {
                                    goto Label_GetAwaiter1Result;
                                }
                                state = 1;
                                doFinallyBodies = false;
                                awaiter1.OnCompleted(moveNextDelegate);
                            }
                            return;
                    }
                    state = 0;
                Label_GetAwaiter1Result:
                    int awaitResult1 = awaiter1.GetResult();
                    awaiter1 = new TaskAwaiter<int>();
                    value1 = awaitResult1;

                    awaiter2 = task2.GetAwaiter();
                    if (awaiter2.IsCompleted)
                    {
                        goto Label_GetAwaiter2Result;
                    }
                    state = 2;
                    doFinallyBodies = false;
                    awaiter2.OnCompleted(moveNextDelegate);
                    return;
                Label_Awaiter2Continuation:
                    state = 0;
                Label_GetAwaiter2Result:
                    int awaitResult2 = awaiter2.GetResult();
                    awaiter2 = new TaskAwaiter<int>();
                    value2 = awaitResult2;

                    awaiter3 = task3.GetAwaiter();
                    if (awaiter3.IsCompleted)
                    {
                        goto Label_GetAwaiter3Result;
                    }
                    state = 3;
                    doFinallyBodies = false;
                    awaiter3.OnCompleted(moveNextDelegate);
                    return;
                Label_Awaiter3Continuation:
                    state = 0;
                Label_GetAwaiter3Result:
                    int awaitResult3 = awaiter3.GetResult();
                    awaiter3 = new TaskAwaiter<int>();
                    value3 = awaitResult3;

                    result = value1 + value2 + value3;
                }
                catch (Exception e)
                {
                    state = -1;
                    builder.SetException(e);
                    return;
                }
                state = -1;
                builder.SetResult(result);
            }