public IObservable <StatisticsUploadStatus> uploadStatistics() { return(Observable.Create <StatisticsUploadStatus>(o => { Guid updateId = Guid.NewGuid(); IEnumerable <StatisticItem> stats = GetStatisticsForSending(LoggedUser.LoggedUser, updateId); if (stats.Count() == 0) { o.OnNext(StatisticsUploadStatus.NothingToUpload); o.OnCompleted(); } else { o.OnNext(StatisticsUploadStatus.UploadStarted); Transport.UploadStaticstics(stats) .ObserveOnDispatcher() .Subscribe <int>( responseContent => { RemoveQueuedStatistics(true, updateId); NedStatUploadConsts responseCode = (NedStatUploadConsts)responseContent; if (responseCode == NedStatUploadConsts.NEWSTATS || responseCode == NedStatUploadConsts.STATSUPDATED) { o.OnNext(StatisticsUploadStatus.Success); } else { o.OnNext(StatisticsUploadStatus.Error); } }, error => { RemoveQueuedStatistics(false, updateId); o.OnError(new Exception()); }, () => { o.OnCompleted(); } ); } return () => { }; } )); }