Example #1
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;
        }
        private async Task PopulateData()
        {
            Items.Clear();
            IsLoadedData = false;

            if (HyperStore == null || string.IsNullOrWhiteSpace(WorkflowId))
            {
                return;
            }

            var historyArgs = new FindHyperDocumentsArgs(true);

            historyArgs.DescriptorConditions.AddCondition(Assist.GetPropertyName((HyperWorkflowInstance i) => i.WorkflowId), WorkflowId);
            var instances = await FindHyperDocumentsArgs.FindAsync <HyperWorkflowInstance>(HyperStore, historyArgs);

            if (instances != null)
            {
                var wfInstances = instances.OrderBy(it => it.ToString());
                Items.AddRange(wfInstances);
            }

            IsLoadedData = true;
        }
Example #3
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);
        }
Example #4
0
        public async Task <long> CountTag(
            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 findHyperTagsArgs = new CountHyperDocumentsArgs
            {
                DescriptorConditions = new MultiScopeCondition(AndOr.And),
            };

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

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

            if (!filter.Children)
            {
                findHyperTagsArgs.DescriptorConditions.AddCondition(elementType, nameof(HyperTagReference), Comparers.DoesNotEqual);
            }
            else
            {
                findHyperTagsArgs.DescriptorConditions.AddCondition(elementType, nameof(HyperTagReference), Comparers.Equals);
                var elementRefrenceId = Assist.GetPropertyName((HyperTag t) => t.Elements) + ".ReferenceId";
                findHyperTagsArgs.DescriptorConditions.AddCondition(elementRefrenceId, filter.ParentId, Comparers.Equals);
            }

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

            findHyperTagsArgs.SetDocumentType(nameof(HyperTag));

            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 key =
                    Assist.GetPropertyName((HyperTag t) => t.Elements) + $".{nameof(HyperId)}." +
                    Assist.GetPropertyName((HyperId m) => m.AssetId);

                findHyperTagsArgs.DocumentConditions.AddCondition(key, filter.AssetIds, Comparers.In);
            }

            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);
                }
            }

            var documents = await _store.ExecuteAsync(findHyperTagsArgs);

            return(documents);
        }