コード例 #1
0
        public async Task RetrieveMonthAsync(DateTime monthDate, TrainingDaysHolder holder)
        {
            DateTime monthTOShow             = monthDate;
            WorkoutDaysSearchCriteria search = new WorkoutDaysSearchCriteria();

            search.UserId     = holder.User != null ? (Guid?)holder.User.GlobalId : null;
            search.CustomerId = holder.CustomerId;
            search.EndDate    = monthDate.AddMonths(1);
            if (Settings.NumberOfMonthToRetrieve > 1)
            {//-1 because we need to subtract months
                monthDate = monthDate.AddMonths(-1 * (Settings.NumberOfMonthToRetrieve - 1));
            }
            search.StartDate = monthDate;
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 0;//we want to download all entries in selected period of time

            try
            {
                var result = await BAService.GetTrainingDaysAsync(search, pageInfo);

                RetrievedDays(monthDate, Settings.NumberOfMonthToRetrieve, result.Items, holder);
            }
            catch (NetworkException)
            {
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowWarning(ApplicationStrings.EntryObjectPageBase_SavedLocallyOnly);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
            catch (Exception)
            {
                BAMessageBox.ShowError(ApplicationStrings.ApplicationState_ErrRetrieveTrainingDays);
            }



            //var m = new ServiceManager<GetTrainingDaysCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler<GetTrainingDaysCompletedEventArgs> operationCompleted)
            //{
            //    client1.GetTrainingDaysCompleted -= operationCompleted;
            //    client1.GetTrainingDaysCompleted += operationCompleted;
            //    client1.GetTrainingDaysAsync(ApplicationState.Current.SessionData.Token, search, pageInfo);
            //});
            //m.OperationCompleted += (s, a) =>
            //   {

            //    if (a.Error != null)
            //    {
            //        onTrainingDaysRetrieved(monthTOShow);
            //        BAMessageBox.ShowError(ApplicationStrings.ApplicationState_ErrRetrieveTrainingDays);
            //        return;
            //    }
            //    if (a.Result != null && a.Result.Result!=null )
            //    {
            //        RetrievedDays(monthDate, Settings.NumberOfMonthToRetrieve, a.Result.Result.Items, holder);
            //        onTrainingDaysRetrieved(monthTOShow);
            //    }
            //};

            //if(!m.Run())
            //{
            //    if(ApplicationState.Current.IsOffline)
            //    {
            //        BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
            //    }
            //    else
            //    {
            //        BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
            //    }
            //    onTrainingDaysRetrieved(monthTOShow);
            //}
        }