Пример #1
0
        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
        public async Task LoadDashboarList()
        {
            DataList.Clear();
            IsLoadedDataResult = false;

            if (string.IsNullOrWhiteSpace(SearchInput))
            {
                // We are only going to pull the basic info on the Dashboards, as they are becoming large objects.
                var datas = await HyperStore.FindAllAsync <DashboardData>(null, 0, 500, true);

                DataList = datas.ToList();
            }
            else
            {
                var findDocArgs = new FindHyperDocumentsArgs(typeof(DashboardData), true);

                var regexText = $"/.*{SearchInput}.*/i";

                var conditions = new MultiScopeCondition(AndOr.Or);
                conditions.AddCondition(nameof(DashboardData.Name), regexText, Comparers.Regex);
                conditions.AddCondition(nameof(DashboardData.Group), regexText, Comparers.Regex);
                conditions.AddCondition(nameof(DashboardData.Tag), regexText, Comparers.Regex);

                findDocArgs.DescriptorConditions = conditions;

                var documents = await HyperStore.ExecuteAsync(findDocArgs);

                DataList = documents.Select(x => x.GetPayload <DashboardData>()).ToList();

                if (!findDocArgs.ExecutionResult.IsNotSuccess || documents != null)
                {
                    DataList = documents.Select(x => x.GetPayload <DashboardData>()).ToList();
                }
            }

            IsLoadedDataResult = true;

            this.RaiseNotify(nameof(DataList));
        }
Пример #3
0
        private async Task ApplyFilterConditions <T>(ScopeHyperDocumentsArgs <T> mainArgs)
        {
            var conditions = await MetaDataSetHelper.GenerateFilterFromMetaDataSetAsync(_hyperStore, _metadataSet);

            mainArgs.DescriptorConditions.AddCondition(conditions.Result);

            //hyper tag ids condition
            var hyperTagIdscondition = new MultiScopeCondition(AndOr.Or);

            foreach (var id in _metadataSet.HyperTagIds ?? new HyperDocumentId[] { })
            {
                hyperTagIdscondition.AddCondition("_id", id.Id);
            }
            if (hyperTagIdscondition.ConditionsCount > 0)
            {
                mainArgs.DocumentConditions.AddCondition(hyperTagIdscondition);
            }
            //if (tagFilterConditions != null)
            //{
            //	mainArgs.DocumentConditions.AddCondition(tagFilterConditions);
            //}
        }
Пример #4
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);
        }
Пример #5
0
        public async Task RunGenerationAsync(DateTime?from, DateTime?to)
        {
            _keepWorking = true;
            _ctSource    = new CancellationTokenSource();

            var source = new TaskCompletionSource <bool>();

            _completionTask = source.Task;

            try
            {
                _frames = new ConcurrentFixedSizeQueue <List <HeatPoint> >(int.MaxValue);

                ProtectOriginalMetadataSet();

                if (from.HasValue)
                {
                    _metadataSet.FromDate = from;
                }
                if (to.HasValue)
                {
                    _metadataSet.ToDate = to;
                }

                await CountTagsTotalAsync();

                if (this.TotalCountProp.Value == 0)
                {
                    _lastImage = await GetFirstImageForMetadatasetAssetAsync(from);

                    ImageProp.Value = _lastImage.Data;
                    PertcantageProcessedUpdated?.Invoke(100);
                }

                var batchSize  = 100;
                var batchesNum = Math.Ceiling((double)TotalCountProp.Value / batchSize);
                batchesNum = Math.Min(batchesNum, _settings.NumberOfBatchesToProcess);

                var hyperIds = new List <HyperId>();

                for (int i = 0; i < batchesNum; i++)
                {
                    StatusProp.Value = $"Processing batch {(i + 1)} out of {batchesNum}...";

                    if (!_keepWorking || _ct.IsCancellationRequested)
                    {
                        return;
                    }

                    var skip = batchSize * i;

                    var findArgs = new FindHyperDocumentsArgs(typeof(HyperTag))
                    {
                        Skip  = skip,
                        Limit = batchSize
                    };

                    var conditions = await MetaDataSetHelper.GenerateFilterFromMetaDataSetAsync(_hyperStore, _metadataSet);

                    findArgs.DescriptorConditions.AddCondition(conditions.Result);

                    //hyper tag ids condition
                    var hyperTagIdscondition = new MultiScopeCondition(AndOr.Or);
                    foreach (var id in _metadataSet.HyperTagIds ?? new HyperDocumentId[] { })
                    {
                        hyperTagIdscondition.AddCondition("_id", id.Id);
                    }
                    if (hyperTagIdscondition.ConditionsCount > 0)
                    {
                        findArgs.DocumentConditions.AddCondition(hyperTagIdscondition);
                    }

                    var tagDocs = await _hyperStore.ExecuteAsync(findArgs) ?? new HyperDocument[0];

                    if (!_keepWorking || _ct.IsCancellationRequested)
                    {
                        return;
                    }

                    var tags            = tagDocs.Select(it => it.GetPayload <HyperTag>()).ToArray();
                    var grouppedBySlice = tags.GroupBy(it =>
                    {
                        var item = it.GetElement <IHyperTagHyperIds>();
                        return(item.HyperId);
                    }).ToArray();

                    if (!_keepWorking || _ct.IsCancellationRequested)
                    {
                        return;
                    }

                    if (_width == 0 || _height == 0)
                    {
                        var hyperId = grouppedBySlice.First().Key;

                        await UpdateImageDataAsync(hyperId);

                        _globalMatrix = new uint[_height, _width];

                        ImageProp.Value = _lastImage.Data;

                        if (!_keepWorking || _ct.IsCancellationRequested)
                        {
                            return;
                        }
                    }

                    grouppedBySlice = grouppedBySlice.OrderBy(x => x.Key).ToArray();

                    // Group by asset first?

                    var groupedByFragment = grouppedBySlice.GroupBy(x => x.Key.FragmentId.Value).ToArray();

                    foreach (var group in groupedByFragment)
                    {
                        var sliceGroupsOfFragment = group.ToArray();

                        foreach (var sliceTags in sliceGroupsOfFragment)
                        {
                            await _pauseResetEvent.WaitAsync();

                            var framePoints = new List <HeatPoint>();

                            foreach (var tag in sliceTags)
                            {
                                // TODO: Reintegrate RealImage processing logic
                                if (_settings.RenderingMode == RenderingMode.Masks || _settings.RenderingMode == RenderingMode.RealImage)
                                {
                                    var tagExtraction = ProcessMaskedTag(tag);
                                    if (tagExtraction != null)
                                    {
                                        ProcessMaskOverlapsIntoMatrix(tagExtraction.Image, tagExtraction.Rect);
                                    }
                                }
                                else if (_settings.RenderingMode == RenderingMode.LowerPointOfGeometry)
                                {
                                    ProcessGeometryTag(tag, framePoints);
                                }
                            }

                            _frames.Enqueue(framePoints);
                        }

                        if (!_keepWorking || _ct.IsCancellationRequested)
                        {
                            return;
                        }
                    }

                    _lastHyperId = grouppedBySlice.Last().Key;

                    await RerenderAsync();

                    var tagDocsCount = tagDocs.Count();
                    ItemsProcessed.Value  += tagDocsCount;
                    PertcantageLabel.Value = ((double)100 * ItemsProcessed.Value / TotalCountProp.Value).ToString("0.00", System.Globalization.CultureInfo.InvariantCulture) + "%";
                    PertcantageProcessedUpdated?.Invoke(100 * tagDocsCount / (double)TotalCountProp.Value);
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error(this.GetType(), nameof(RunGenerationAsync), ex.Message);
            }
            finally
            {
                source.SetResult(true);
            }
        }