Пример #1
0
        private async Task UpdateModelStatusAsync()
        {
            string missionId = Mission.Id;

            if (HyperStore == null || missionId == null || _callPending)
            {
                return;
            }

            var args = new GetHyperMissionStatusArgs()
            {
                MissionId = missionId
            };

            _callPending = true;
            try
            {
                InstanceStatus = await HyperStore.ExecuteAsync(args);
            }
            finally
            {
                _callPending = false;
            }
        }
Пример #2
0
        public async Task <IEnumerable <MissionViewModel> > GetMissionsAsync(
            int pageNumber  = 0,
            int pageSize    = 100,
            bool onlyActive = false)
        {
            var retrieveHyperDocumentArgs = new FindHyperDocumentsArgs()
            {
                Skip  = pageNumber * pageSize,
                Limit = pageSize,
            };

            retrieveHyperDocumentArgs.SetDocumentType(typeof(HyperMission));

            var condition = new MultiScopeCondition();

            if (onlyActive)
            {
                //var conditionOr = new MultiScopeCondition()
                //{
                //	Mode = AndOr.Or
                //};
                //conditionOr.AddCondition(Assist.GetPropertyName((HyperMission i) => i.Archived), false);
                //conditionOr.AddCondition(Assist.GetPropertyName((HyperMission i) => i.Archived), false, ScopeCondition.Comparators.DoesNotExist);
                //condition.AddCondition(conditionOr);
            }

            retrieveHyperDocumentArgs.DescriptorConditions.AddCondition(condition);

            var results = await _netStore.ExecuteAsync(retrieveHyperDocumentArgs);

            var missionVms = new List <MissionViewModel>();

            foreach (var hyperDocument in results)
            {
                var mission = hyperDocument.GetPayload <HyperMission>();

                var missionVM = new MissionViewModel
                {
                    MissionId = mission.Id,
                    Mission   = mission,
                    Name      = mission.Name,
                    Document  = hyperDocument,
                    IsActive  = !mission.Archived,
                };

                missionVms.Add(missionVM);
            }


            var getMissionStatusTasks = new List <IHyperArgs <HyperMissionInstanceStatus> >();

            var listRetrieveMissionStatusArgs = new List <Tuple <string, GetHyperMissionStatusArgs> >();

            foreach (var mission in missionVms)
            {
                var args = new GetHyperMissionStatusArgs()
                {
                    MissionId = mission.Mission.Id
                };


                var getMissionStatusTask = _netStore.ExecuteAsync(args);

                getMissionStatusTasks.Add(getMissionStatusTask);
                listRetrieveMissionStatusArgs.Add(
                    new Tuple <string, GetHyperMissionStatusArgs>(
                        mission.MissionId,
                        args
                        ));
            }

            await Task.WhenAll(getMissionStatusTasks.Select(x => x.AsTask()).ToList());

            foreach (var missionStatusArgs in listRetrieveMissionStatusArgs)
            {
                // TODO - better error handling
                if (missionStatusArgs.Item2.ExecutionResult.IsFailure)
                {
                    continue;
                }
                //throw new InvalidOperationException(retrieveAssetsArgs.ExecutionResult.ToString());

                HyperMissionInstanceStatus instance = missionStatusArgs.Item2.Result;

                var item = missionVms.FirstOrDefault(it => it.MissionId == missionStatusArgs.Item1);
                item.InstanceStatus      = instance;
                item.InstanceDescription = instance.ToString();

                item.Status = ManageMissionInstanseStatusStyle(instance);
            }

            missionVms = missionVms.OrderBy(it => it.Status).ToList();


            return(missionVms);
        }