private async Task Populate()
        {
            Items.Clear();
            IsLoadedData = false;


            var findArgs = new FindHyperDocumentsArgs();

            findArgs.SetDocumentType(typeof(Tagonomy));

            if (string.IsNullOrWhiteSpace(Search) == false)
            {
                Guid parsedGuid;
                if (Guid.TryParse(Search, out parsedGuid))
                {
                    findArgs.DocumentConditions.AddCondition("_id", Search);
                }
                else
                {
                    var condition = new MultiScopeCondition();

                    var conditionOr = new MultiScopeCondition()
                    {
                        Mode = AndOr.Or
                    };
                    var regex = $"/{Search}/ig";
                    conditionOr.AddCondition(nameof(Tagonomy.Name), regex, Comparers.Regex);
                    //conditionOr.AddCondition(nameof(Tagonomy.Id), regex, ScopeCondition.Comparators.Regex);
                    conditionOr.AddCondition(nameof(Tagonomy.Group), regex, Comparers.Regex);
                    condition.AddCondition(conditionOr);

                    findArgs.DescriptorConditions.AddCondition(condition);
                }
            }

            var tagonomies = await HyperStore.ExecuteAsync(findArgs);

            if (tagonomies == null || !tagonomies.Any())
            {
                IsLoadedData = true;
                return;
            }

            foreach (var tagonomy in tagonomies)
            {
                var configuration = tagonomy.GetPayload <Tagonomy>();
                if (configuration == null)
                {
                    Console.WriteLine($"Failed to load tagonomy from document: {tagonomy.Id}");
                    continue;
                }

                Items.Add(configuration);
            }

            Items = Items.OrderBy(it => it.Group).ToList();

            IsLoadedData = true;
        }
示例#2
0
        private async Task <string[]> GetWorkflowInstanceIds(
            string missionInstanceId)
        {
            var args = new FindHyperDocumentsArgs(true);

            args.SetDocumentType(typeof(HyperWorkflowInstance));
            args.DescriptorConditions.AddCondition("MissionInstanceId", missionInstanceId);

            var instances = await FindHyperDocumentsArgs.FindAsync <HyperWorkflowInstance>(_netStore, args);

            return(instances.Select(it => it.Id).ToArray());
        }
示例#3
0
        private async Task <string[]> GetWorkflowInstanceIdsAsync(
            bool activeOnly)
        {
            if (_request == null || string.IsNullOrWhiteSpace(_request.MissionId))
            {
                return new string[] { }
            }
            ;

            var args = new FindHyperDocumentsArgs(true);

            args.SetDocumentType(typeof(HyperWorkflowInstance));
            args.DescriptorConditions.AddCondition("MissionId", _request.MissionId);

            var instances = await FindHyperDocumentsArgs.FindAsync <HyperWorkflowInstance>(_netStore, args);

            if (!activeOnly)
            {
                return(instances.Select(it => it.Id).ToArray());
            }

            var statsArgs = new RetrieveHyperWorkflowsStatusesArgs {
                MissionIds = new[] { _request.MissionId }
            };
            var statuses = await _netStore.ExecuteAsync(statsArgs);

            if (statuses == null || !statuses.Any())
            {
                return new string[] { }
            }
            ;

            var data = new List <HyperWorkflowInstance>();

            foreach (var status in statuses)
            {
                var activeInstance = instances.FirstOrDefault(it => it.Id == status.WorkflowInstanceId);

                if (activeInstance == null)
                {
                    continue;
                }

                data.Add(activeInstance);
            }

            return(data.Select(it => it.Id).ToArray());
        }
        public async Task <WorkflowViewModel> GetWorkflowAsync(string workflowId)
        {
            if (string.IsNullOrEmpty(workflowId))
            {
                throw new ArgumentException(nameof(workflowId));
            }

            // Find all data sources stored on this node (and visible by the current user).
            var findArgs = new FindHyperDocumentsArgs();

            findArgs.SetDocumentType(typeof(HyperWorkflow));
            var workflows = await _netStore.ExecuteAsync(findArgs);

            // Pull all working statuses.
            var statsArgs        = new RetrieveHyperWorkflowsStatusesArgs();
            var workflowStatuses = await _netStore.ExecuteAsync(statsArgs);

            var workflowsData = new List <WorkflowViewModel>();

            var model = new WorkflowViewModel();

            foreach (var document in workflows)
            {
                var configuration = document.GetPayload <HyperWorkflow>();

                if (configuration == null)
                {
                    continue;
                }

                if (workflowId != configuration.Id)
                {
                    continue;
                }

                model.WorkflowId       = configuration.Id;
                model.Name             = configuration.Name;
                model.Document         = document;
                model.Source           = configuration;
                model.WorkflowStatuses = workflowStatuses.Where(it => it.Configuration.Id == configuration.Id).ToArray();

                return(model);
            }

            throw new ApplicationException("Missing workflow");
        }
示例#5
0
        public async Task <HyperMissionPhase> GetMissionPhaseAsync(
            string missionId,
            string phaseId,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (_netStore == null)
            {
                throw new ApplicationException("Node does not exist.");
            }
            if (string.IsNullOrWhiteSpace(missionId))
            {
                throw new ArgumentException(nameof(missionId));
            }
            if (string.IsNullOrWhiteSpace(phaseId))
            {
                throw new ArgumentException(nameof(phaseId));
            }

            var retrieveHyperDocumentArgs = new FindHyperDocumentsArgs();

            retrieveHyperDocumentArgs.SetDocumentType(typeof(HyperMission));
            retrieveHyperDocumentArgs.DocumentConditions.AddCondition("_id", missionId);

            await _netStore.ExecuteAsync(retrieveHyperDocumentArgs);

            var hyperDocument = retrieveHyperDocumentArgs.Result.FirstOrDefault();

            if (hyperDocument == null)
            {
                throw new ApplicationException("Missing mission");
            }

            var mission = hyperDocument.GetPayload <HyperMission>();

            foreach (var phase in mission.Phases)
            {
                if (phase?.Id == phaseId)
                {
                    return(phase);
                }
            }

            throw new ApplicationException("Missing mission phase");
        }
        private async Task PopulateWorkflows()
        {
            Items.Clear();
            IsLoadedData = false;

            var findArgs = new FindHyperDocumentsArgs();

            findArgs.SetDocumentType(typeof(HyperWorkflow));
            var workflows = await HyperStore.ExecuteAsync(findArgs);

            if (workflows == null || !workflows.Any())
            {
                return;
            }

            var statsArgs = new RetrieveHyperWorkflowsStatusesArgs();
            var statuses  = await HyperStore.ExecuteAsync(statsArgs);

            if (statuses == null)
            {
                statuses = new HyperWorkflowStatus[] { };
            }

            foreach (var workflow in workflows)
            {
                var configuration = workflow.GetPayload <HyperWorkflow>();
                if (configuration == null)
                {
                    Console.WriteLine($"Failed to load workflow from document: {workflow.Id}");
                    continue;
                }

                var wfVm = new WorkflowConfigurationVm
                {
                    Source           = configuration,
                    WorkflowStatuses = statuses.Where(it => it.Configuration.Id == configuration.Id).ToArray()
                };

                Items.Add(wfVm);
            }

            IsLoadedData = true;
        }
示例#7
0
        private async Task Populate()
        {
            Items.Clear();
            IsLoadedData = false;

            var findArgs = new FindHyperDocumentsArgs();

            findArgs.SetDocumentType(typeof(HyperMission));
            findArgs.DescriptorConditions.Mode = AndOr.Or;
            findArgs.DescriptorConditions.AddCondition(Assist.GetPropertyName((HyperMission i) => i.Archived), false);
            findArgs.DescriptorConditions.AddCondition(Assist.GetPropertyName((HyperMission i) => i.Archived), false, Comparers.DoesNotExist);
            var docs = await HyperStore.ExecuteAsync(findArgs);

            if (docs == null || !docs.Any())
            {
                return;
            }

            foreach (var doc in docs)
            {
                var data = doc.GetPayload <HyperMission>();
                if (data == null)
                {
                    await OnToastMessage.InvokeAsync(new ToastMessage($"Failed to load data from document: {data.Id}", ToastMessageType.Error));

                    continue;
                }

                var model = new MissionItemVm(data, HyperStore);
                await model.UpdateStatus();

                model.OnToastMessage = OnToastMessage;

                Items.Add(model);
            }

            IsLoadedData = true;
        }
示例#8
0
        private async Task <List <Option> > GetMissionInstanceOptionsAsync(
            string selectedOption = null)
        {
            var options = new List <Option>
            {
                new Option {
                    Text = "All Instances", Value = "0"
                },
                new Option {
                    Text = "Active Instances", Value = "1"
                }
            };

            if (_request == null || string.IsNullOrWhiteSpace(_request.MissionId))
            {
                return(options);
            }

            var args = new FindHyperDocumentsArgs(true);

            args.SetDocumentType(typeof(HyperMissionInstance));
            args.DescriptorConditions.AddCondition("MissionId", _request.MissionId);

            var documents = await _netStore.ExecuteAsync(args);

            options.AddRange(GetMissionInstanceOptions(documents));

            var option = options.FirstOrDefault(it => it.Value == selectedOption);

            if (option != null)
            {
                option.Selected = true;
            }

            return(options);
        }
示例#9
0
        public async Task <List <DynamicHyperTagViewModel> > GetTag(
            TagPageFilterModel filter,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (filter == null)
            {
                throw new ArgumentException(nameof(filter));
            }
            if (string.IsNullOrWhiteSpace(filter.ServerUri))
            {
                throw new ArgumentException(nameof(filter.ServerUri));
            }

            var hyperNodeUtility = new HyperStoreUtility(filter.ServerUri, _store);

            var serverHost    = HyperStoreConnectionStringUtility.GetHost(filter.ServerUri);
            var serverPort    = HyperStoreConnectionStringUtility.GetPort(filter.ServerUri);
            var hlsServerHost = await hyperNodeUtility.GetHlsServerUriAsync(filter.ServerUri);

            var missionTags = new List <DynamicHyperTagViewModel>();

            var findHyperTagsArgs = new FindHyperDocumentsArgs
            {
                DescriptorConditions = new MultiScopeCondition(AndOr.And),
            };

            findHyperTagsArgs.SetDocumentType(nameof(HyperTag));

            var elementType = Assist.GetPropertyName((HyperTag t) => t.Elements) + ".TYPE";

            //findHyperTagsArgs.DescriptorConditions.AddCondition(elementType, nameof(TagonomyExecutionResultHyperTagElement));

            findHyperTagsArgs.OrderByFields = new OrderByField[]
            {
                new OrderByField()
                {
                    Ascending       = true,
                    DescriptorField = true,
                    FieldName       = "Elements.UniversalTime"
                },
                new OrderByField()
                {
                    Ascending       = true,
                    DescriptorField = true,
                    FieldName       = "Elements.StreamTime"
                },
                //new OrderByField()
                //{
                //	Ascending = true,
                //	DescriptorField = true,
                //	FieldName = "Elements.HyperId.FragmentId"
                //},
                //new OrderByField()
                //{
                //	Ascending = true,
                //	DescriptorField = true,
                //	FieldName = "Elements.HyperId.SliceId"
                //}
            };

            if (filter.PageNumber.HasValue && filter.PageSize.HasValue)
            {
                findHyperTagsArgs.Skip  = filter.PageNumber.Value * filter.PageSize.Value;
                findHyperTagsArgs.Limit = filter.PageSize.Value;
            }

            if (filter.WorkflowInstanceId != null)
            {
                var workflowInstanceKey =
                    Assist.GetPropertyName((HyperTag t) => t.Elements) + "." +
                    Assist.GetPropertyName((HyperTagMission m) => m.WorkflowInstanceId);

                findHyperTagsArgs.DescriptorConditions.AddCondition(workflowInstanceKey, filter.WorkflowInstanceId);
            }

            if (filter.Ids != null && filter.Ids.Any())
            {
                findHyperTagsArgs.DocumentConditions.AddCondition("_id", filter.Ids, Comparers.In);
            }

            if (filter.AssetIds != null && filter.AssetIds.Any())
            {
                var assetDescriptorConditions = new MultiScopeCondition(AndOr.Or);
                foreach (var assetId in filter.AssetIds)
                {
                    var regexText = $"/^{assetId}.*/i";

                    var key =
                        Assist.GetPropertyName((HyperTag t) => t.Elements) + $".{nameof(HyperId)}." +
                        Assist.GetPropertyName((HyperId m) => m.AssetId);

                    assetDescriptorConditions.AddCondition(key, regexText, Comparers.Regex);
                }
                findHyperTagsArgs.DescriptorConditions.AddCondition(assetDescriptorConditions);
            }

            if (filter.Start.HasValue || filter.End.HasValue)
            {
                var field = Assist.GetPropertyName((HyperTag t) => t.Elements)
                            + "."
                            + Assist.GetPropertyName((HyperTagTime t) => t.UniversalTime);

                if (filter.Start.HasValue)
                {
                    findHyperTagsArgs.DescriptorConditions.AddCondition(
                        field,
                        new DateTime(filter.Start.Value.Ticks, DateTimeKind.Utc),
                        Comparers.GreaterThanOrEqual);
                }

                if (filter.End.HasValue)
                {
                    findHyperTagsArgs.DescriptorConditions.AddCondition(
                        field,
                        new DateTime(filter.End.Value.Ticks, DateTimeKind.Utc),
                        Comparers.LessThanOrEqual);
                }
            }

            if (filter.Range != null && filter.AssetIds != null && filter.AssetIds.Any())
            {
                var assetId = filter.AssetIds.FirstOrDefault();

                var hyperAssetId = HyperAssetId.TryParse(assetId);

                // TODO: Enable cache
                // var hyperTrack = _tagsCache.Get<HyperTrack>(assetId);
                HyperTrack hyperTrack = null;

                if (hyperTrack == null)
                {
                    var retrieveAssetArgs = new RetrieveAssetArgs()
                    {
                        AssetId = hyperAssetId.Value,
                    };

                    var hyperAsset = await _store.ExecuteAsync(retrieveAssetArgs);

                    var retrieveTrackArgs = new RetrieveTrackArgs()
                    {
                        AssetId = hyperAssetId.Value,
                        TrackId = hyperAsset.DefaultVideoTrackId.Value
                    };

                    hyperTrack = await _store.ExecuteAsync(retrieveTrackArgs);

                    // TODO: Enable cache
                    //_tagsCache.Set(assetId, hyperTrack, TimeSpan.FromSeconds(Settings.Instance.CacheExpiratonTagIntervalInSeconds));
                }

                var fromExtended = await hyperTrack.FindAtAsync(_store, hyperAssetId.Value, filter.Range.FromSeconds * 1000, HyperSeek.SeekModes.Estimated);

                var toExtended = await hyperTrack.FindAtAsync(_store, hyperAssetId.Value, filter.Range.ToSeconds * 1000, HyperSeek.SeekModes.Estimated);

                var field = Assist.GetPropertyName((HyperTag t) => t.Elements)
                            + $".{nameof(HyperId)}."
                            + Assist.GetPropertyName((HyperId t) => t.FragmentId);

                findHyperTagsArgs.DescriptorConditions.AddCondition(
                    field,
                    fromExtended.Value.FragmentId.Index,
                    Comparers.GreaterThanOrEqual);

                findHyperTagsArgs.DescriptorConditions.AddCondition(
                    field,
                    toExtended.Value.FragmentId.Index,
                    Comparers.LessThanOrEqual);
            }
            ;

            var documents = await _store.ExecuteAsync(findHyperTagsArgs);

            if (documents == null)
            {
                return(missionTags);
            }

            var parallel = documents
                           .Select(it => it.GetPayload <HyperTag>())
                           .Where(it => it.GetElement <HyperTagMission>() != null)
                           .ToDictionary(k => k, v => new DynamicHyperTagViewModel());

            if (!parallel.Any())
            {
                return(missionTags);
            }

            foreach (var item in parallel.AsParallel().WithDegreeOfParallelism(100))
            {
                try
                {
                    // TODO: Enable cache
                    //var cacheElement = _tagsCache.Get<TagCacheElement>(item.Key.Id);
                    TagCacheElement cacheElement = null;

                    if (cacheElement != null)
                    {
                        var cacheTag = cacheElement.Tag;

                        item.Value.ServerUri     = cacheTag.ServerUri;
                        item.Value.ServerHost    = cacheTag.ServerHost;
                        item.Value.ServerPort    = cacheTag.ServerPort;
                        item.Value.HlsServerHost = cacheTag.HlsServerHost;
                        item.Value.DynamicData   = cacheTag.DynamicData;
                        item.Value.TagView       = cacheTag.TagView;
                        item.Value.HyperTag      = cacheTag.HyperTag;
                    }
                    else
                    {
                        var view = await HyperTagHelper.GenerateTagView(_store, new DummyLogger(), item.Key);

                        var json    = JsonConvert.SerializeObject(view);
                        var @object = JsonConvert.DeserializeObject <JObject>(json);

                        item.Value.ServerUri     = filter.ServerUri;
                        item.Value.ServerHost    = serverHost;
                        item.Value.ServerPort    = serverPort;
                        item.Value.HlsServerHost = hlsServerHost;
                        item.Value.DynamicData   = @object;
                        item.Value.TagView       = view;
                        item.Value.HyperTag      = item.Key;

                        cacheElement = new TagCacheElement()
                        {
                            Tag = item.Value,
                        };

                        // TODO: Enable cache
                        //_tagsCache.Set(item.Key.Id, cacheElement, TimeSpan.FromSeconds(Settings.Instance.CacheExpiratonTagIntervalInSeconds));
                    }
                }
                catch (Exception)
                {
                }
            }

            missionTags.AddRange(parallel.Where(it => it.Value.DynamicData != null).Select(it => it.Value));

            if (!string.IsNullOrWhiteSpace(filter.FilterValue))
            {
                missionTags = missionTags.Where(it => it.TagView.TaggingTitle != null &&
                                                it.TagView.TaggingTitle.ToLower().Contains(filter.FilterValue.ToLower())).ToList();
            }

            return(missionTags);
        }
        public async Task <IEnumerable <WorkflowViewModel> > GetWorkflowsAsync(
            int pageNumber = 0,
            int pageSize   = 100)
        {
            // Find all data sources stored on this node (and visible by the current user).
            var findArgs = new FindHyperDocumentsArgs();

            findArgs.SetDocumentType(typeof(HyperWorkflow));


            var docs = await _netStore.ExecuteAsync(findArgs);

            if (!docs.Any())
            {
                new List <WorkflowViewModel>();
            }

            var workflowsIds = new List <string>();

            foreach (var document in docs)
            {
                var configuration = document.GetPayload <HyperWorkflow>();
                if (configuration == null)
                {
                    continue;
                }
                workflowsIds.Add(configuration.Id);
            }

            HyperWorkflowStatus[] statuses = await _netStore.ExecuteAsync(new RetrieveHyperWorkflowsStatusesArgs()
            {
                WorkflowConfigurationIds = workflowsIds.ToArray()
            });


            var workflowsData = new List <WorkflowViewModel>();

            foreach (var document in docs)
            {
                var configuration = document.GetPayload <HyperWorkflow>();

                if (configuration == null)
                {
                    continue;
                }

                var model = new WorkflowViewModel()
                {
                    WorkflowId = configuration.Id,
                    Name       = configuration.Name,
                    Document   = document,
                    Source     = configuration,
                };


                if (statuses != null)
                {
                    model.WorkflowStatuses = statuses.Where(it => it.Configuration.Id == configuration.Id).ToArray();
                }
                else
                {
                    model.WorkflowStatuses = new HyperWorkflowStatus[] { };
                }

                workflowsData.Add(model);
            }

            return(workflowsData.OrderByDescending(it => it.HasInstances).ToList());
        }
示例#11
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);
        }