public async Task LoadHyperTags() { if (this.HyperStore == null) { return; } TagsAreBeingLoaded = true; var findArgs = new FindHyperDocumentsArgs(typeof(HyperTag)); var conditions = await MetaDataSetHelper.GenerateFilterFromMetaDataSetAsync(HyperStore, _metadataSet); findArgs.DescriptorConditions.AddCondition(conditions.Result); findArgs.Skip = PageSize * (PageNumber - 1); findArgs.Limit = PageSize; var docs = await HyperStore.ExecuteAsync(findArgs); var hyperTags = new List <HyperTag>(); foreach (var doc in docs) { hyperTags.Add(doc.GetPayload <HyperTag>()); } HyperTags.Value = hyperTags; TagsAreBeingLoaded = false; RaiseNotify(nameof(HyperTags)); }
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; }
private async Task ApplyFilterConditions(FindHyperDocumentsArgs mainArgs, HyperMetadataSet id) { var conditions = await MetaDataSetHelper.GenerateFilterFromMetaDataSetAsync(_netStore, id); if (conditions.Value != null) { mainArgs.DescriptorConditions.AddCondition(conditions.Value); } }
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()); }
public async Task <byte[]> ExtractAllDashboards() { var dashboards = new List <DashboardData>(); var findDocArgs = new FindHyperDocumentsArgs(typeof(DashboardData), true); var documents = await HyperStore.ExecuteAsync(findDocArgs); if (!findDocArgs.ExecutionResult.IsNotSuccess || documents != null) { foreach (var doc in documents) { var dashboard = doc?.GetPayload <DashboardData>(); if (dashboard != null) { dashboards.Add(dashboard); } } } var compressedFileStream = new MemoryStream(); using (compressedFileStream) { //compressedFileStream.Seek(0, SeekOrigin.Begin); using (var zipArchive = new ZipArchive(compressedFileStream, ZipArchiveMode.Create, false)) { foreach (var data in dashboards) { var projectJson = JsonHelper.Serialize(data); var fileName = $"{data?.Name}.json"; //Create a zip entry for each attachment var zipEntry = zipArchive.CreateEntry(fileName); //Get the stream of the attachment using (var originalFileStream = new MemoryStream(Encoding.UTF8.GetBytes(projectJson))) { using (var zipEntryStream = zipEntry.Open()) { //Copy the attachment stream to the zip entry stream originalFileStream.CopyTo(zipEntryStream); } } } } } var result = compressedFileStream.ToArray(); return(result); }
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"); }
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; }
private async Task PopulateData() { if (HyperStore == null || string.IsNullOrWhiteSpace(TagonomyId)) { return; } var documentId = HyperDocumentId.Create <Tagonomy>(TagonomyId); var argTagonomy = new RetrieveHyperDocumentArgs(documentId); var doc = await HyperStore.ExecuteAsync(argTagonomy); if (argTagonomy.ExecutionResult.IsNotSuccess) { return; } _rootTagonomy = doc?.GetPayload <Tagonomy>(); _unprocessedSourceTagonomies.Clear(); _processedSourceTagonomies.Clear(); var args = new FindHyperDocumentsArgs(typeof(Tagonomy), true); _allTagonomies = ((await this.HyperStore.ExecuteAsyncThrows(args)) ?? new Node.Common.HyperDocument[0]) .Select(x => x.GetPayload <Tagonomy>()) .ToArray(); _unprocessedSourceTagonomies.Add(_rootTagonomy.Id, _rootTagonomy); while (_unprocessedSourceTagonomies.Any()) { foreach (var unprocTagonomie in _unprocessedSourceTagonomies.Select(x => x.Value).ToArray()) { var linkingNodesInner = GetLinkingNodes(unprocTagonomie); ProcessLinkingNodes(linkingNodesInner, unprocTagonomie, true); } } GoBackwards(); }
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)); }
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; }
public async Task InitDataAsync(CrossModuleVisualizationRequest crossModuleVisualizationRequest = null) { if (_netStore != null) { var findArgs = new FindHyperDocumentsArgs(typeof(HyperTag)) { Skip = 0, Limit = 5000 // TODO: This is limited for faster testing. Consider to increase the value }; if (crossModuleVisualizationRequest != null && crossModuleVisualizationRequest.MetadataSetDocIds != null && crossModuleVisualizationRequest.MetadataSetDocIds.Any()) { var metadataSetId = crossModuleVisualizationRequest.MetadataSetDocIds.FirstOrDefault(); Logger.Instance.PriorityInfo($"Meta data set id retrieved: {metadataSetId}"); MetadataSet = await RetrieveHyperDocumentArgs.RetrieveAsync <HyperMetadataSet>(_netStore, metadataSetId); await ApplyFilterConditions(findArgs, MetadataSet); Mission = await LoadMission(MetadataSet); } var docs = await _netStore.ExecuteAsync(findArgs) ?? new HyperDocument[0]; _allTags = docs.Select(x => x.GetPayload <HyperTag>()).ToList(); PopulateCharts(); IsLoadedData = true; } else { Logger.Instance.Error("NetStore is null"); } }
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); }
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); } }
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()); }
private async Task InitializeMetadatasetEdgeDates() { FilterState.Value.HeatMapMinDate.Value = this.FilterState.Value.MetadataSetMinDate; FilterState.Value.HeatMapMaxDate.Value = this.FilterState.Value.MetadataSetMaxDate; if (_metadataSet != null) { var findArgs = new FindHyperDocumentsArgs(typeof(HyperTag)); var conditions = await MetaDataSetHelper.GenerateFilterFromMetaDataSetAsync(HyperStore, _metadataSet); findArgs.DescriptorConditions.AddCondition(conditions.Result); findArgs.Limit = 1; findArgs.OrderByFields = new OrderByField[] { new OrderByField() { Ascending = true, DescriptorField = true, FieldName = "Elements.UniversalTime" } }; var results = await HyperStore.ExecuteAsync(findArgs); if (results?.Length > 0 == false) { return; } var earliestTag = results[0].GetPayload <HyperTag>(); var earliestDate = earliestTag.GetUniversalDateTimeFromElements(); var lastTagFindArgs = new FindHyperDocumentsArgs(typeof(HyperTag)); lastTagFindArgs.DescriptorConditions.AddCondition(conditions.Result); lastTagFindArgs.OrderByFields = new OrderByField[] { new OrderByField() { Ascending = false, DescriptorField = true, FieldName = "Elements.UniversalTime" } }; lastTagFindArgs.Limit = 1; var latestTag = (await HyperStore.ExecuteAsync(lastTagFindArgs))[0].GetPayload <HyperTag>(); var latestDate = latestTag.GetUniversalDateTimeFromElements(); this.FilterState.Value.MetadataSetMinDate.Value = earliestDate.Value; if (this.FilterState.Value.FilterMinDate.Value == null) { this.FilterState.Value.HeatMapMinDate.Value = earliestDate.Value; } this.FilterState.Value.MetadataSetMaxDate.Value = latestDate.Value; if (FilterState.Value.FilterMaxDate.Value == null) { this.FilterState.Value.HeatMapMaxDate.Value = latestDate.Value; } this.OnMetadatasetEdgeDatesUpdated?.Invoke(earliestDate.Value, latestDate.Value); } }
public async Task RunUpdatesAsync() { var store = _netStore; if (store == null) { return; } Interlocked.Increment(ref _refreshCycle); { try { RetrieveConfigurationArgs.ConfigurationData[] configs = await store.ExecuteAsync(new RetrieveConfigurationArgs()); Configs = configs; } catch (Exception ex) { } } { try { var loginsArgs = new FindHyperDocumentsArgs(typeof(HyperUserLoginAttempt)); loginsArgs.Limit = 20; loginsArgs.DescriptorConditions.AddCondition(nameof(HyperUserLoginAttempt.DateTimeUTC), DateTime.UtcNow - TimeSpan.FromMinutes(120), Comparers.GreaterThanOrEqual); var docs = await store.ExecuteAsync(loginsArgs); Logins = docs?.Select(it => it.GetPayload <HyperUserLoginAttempt>()).Where(it => it != null).ToArray() ?? new HyperUserLoginAttempt[] { }; Logins = Logins?.GroupBy(x => x.UserName).Select(x => x.FirstOrDefault()).ToArray(); // Distincts by UserName } catch (Exception ex) { } } { try { var countArgs = new CountHyperDocumentsArgs(typeof(HyperMission)); _missionsCount = await store.ExecuteAsync(countArgs); } catch (Exception ex) { } } { try { var countArgs = new CountHyperDocumentsArgs(typeof(HyperWorkflow)); _workflowsCount = await store.ExecuteAsync(countArgs); } catch (Exception ex) { } } { try { var logsArgs = new CountLogsArgs() { Age = TimeSpan.FromSeconds(10) }; var logsCount = await store.ExecuteAsync(logsArgs); if (_refreshCycle % 2 == 0) { lock (_syncRoot) { _activityHistory.Enqueue(logsCount); while (_activityHistory.Count > _refreshCount) { _activityHistory.Dequeue(); } } } } catch (Exception ex) { } } { try { var countArgs = new CountHyperDocumentsArgs(typeof(HyperAsset)); _assetsCount = await store.ExecuteAsync(countArgs); } catch (Exception ex) { } } { try { var fullStatus = await store.ExecuteAsync(new RetrieveHardwareStatusArgs() { RetrieveDetailedDrivesInfo = true, RetrieveOSInfo = true, RetrieveProcessorsInfo = true }); _fullStatus = fullStatus; SetRAMNotification(false); SetCPUNotification(false); SetDiskNotification(false); if (fullStatus != null) { _status = $"CPU {fullStatus.ProcessorsInfo?.Average(it => it.PercentProcessorTime):#0.0}% RAM {fullStatus.OSInfo?.PercentageUsedRAM:##.0}% "; var cpuTime = fullStatus.ProcessorsInfo.Average(it => it.PercentProcessorTime); if (cpuTime.HasValue && _refreshCycle % 2 == 0) { lock (_syncRoot) { _cpuHistory.Enqueue(cpuTime.Value); while (_cpuHistory.Count > _refreshCount) { _cpuHistory.Dequeue(); } } } var ram = fullStatus.OSInfo?.PercentageUsedRAM; if (ram.HasValue && _refreshCycle % 2 == 0) { lock (_syncRoot) { _ramHistory.Enqueue(ram.Value); while (_ramHistory.Count > _refreshCount) { _ramHistory.Dequeue(); } } } SetCPUNotification(cpuTime > 50); SetRAMNotification(ram > 50); SetDiskNotification(fullStatus.DetailedDrivesInfo.Any(it => it.Progress > 0.9)); // 80% disk drive. Notify(nameof(Status)); } } catch (Exception ex) { } } Notify(nameof(Configs)); Notify(nameof(FullStatus)); }
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); }