private ResourceViewModel ToResourceViewModel(EtpUri uri, string name, Action <ResourceViewModel, string> action, int children = -1, IndicatorViewModel indicator = null) { var resource = new Resource() { Uri = uri, Name = name, ContentType = uri.ContentType, HasChildren = children }; var viewModel = new ResourceViewModel(resource); if (indicator != null) { viewModel.Indicator = indicator; } if (children != 0 && action != null) { viewModel.LoadChildren = x => { action(viewModel, x); return(_messageId++); }; } return(viewModel); }
private void LoadWellboreFolders(ResourceViewModel parent, string uri) { var etpUri = new EtpUri(uri); DataObjects .Select(x => ToResourceViewModel(etpUri.Append(x), x, LoadWellboreObjects)) .ForEach(parent.Children.Add); }
/// <summary> /// Called when the GetResources response is received. /// </summary> /// <param name="header">The header.</param> /// <param name="message">The message.</param> /// <param name="resource">The resource.</param> /// <param name="uri">The URI.</param> private void OnGetResourcesResponse(IMessageHeader header, ISpecificRecord message, IResource resource, string uri) { //int id = Thread.CurrentThread.ManagedThreadId; var viewModel = ResourceViewModel.NoData; // Handle case when "No Data" Acknowledge message was received if (resource != null) { viewModel = new ResourceViewModel(Runtime, resource) { LoadChildren = GetResources }; resource.FormatLastChanged(); } // Handle when message is received from JSON Message tab if (string.IsNullOrWhiteSpace(uri)) { return; } // If the message URI equals "/" or the current base URI then treat // it as a root object. if (EtpUri.IsRoot(uri)) { Resources.ForEach(x => x.IsSelected = false); viewModel.IsSelected = true; Resources.Add(viewModel); if (header.MessageFlags == 3) { _messageRespondedEvent.Set(); } return; } var parent = Resources.FindByMessageId(header.CorrelationId); if (parent == null) { return; } viewModel.Parent = parent; parent.Children.Add(viewModel); viewModel.IsChecked = CheckedUris.Contains(viewModel.Resource.Uri); viewModel.PropertyChanged += ResourcePropertyChanged; if (header.MessageFlags == 3) { _messageRespondedEvent.Set(); } }
private void LoadWellbores(ResourceViewModel parent, string uri) { Runtime.ShowBusy(); Task.Run(async() => { var wellbores = Context.GetWellbores(new EtpUri(uri)); await LoadDataItems(wellbores, parent.Children, LoadWellboreFolders, x => x.GetUri()); Runtime.ShowBusy(false); }); }
private void LoadLogObjects(ResourceViewModel parent, string uri) { Runtime.ShowBusy(); Task.Run(async() => { var etpUri = new EtpUri(uri); var indexType = ObjectFolders.All.EqualsIgnoreCase(etpUri.ObjectType) ? null : etpUri.ObjectType; var dataObjects = Context.GetGrowingObjectsWithStatus(ObjectTypes.Log, etpUri.Parent, indexType); await LoadDataItems(dataObjects, parent.Children, LoadGrowingObjectChildren, x => x.GetUri()); Runtime.ShowBusy(false); }); }
private void LoadGrowingObjectChildren(ResourceViewModel parent, string uri) { Runtime.ShowBusy(); Task.Run(async() => { var etpUri = new EtpUri(uri); var dataObject = Context.GetGrowingObjectHeaderOnly(etpUri.ObjectType, etpUri); if (ObjectTypes.Log.EqualsIgnoreCase(etpUri.ObjectType)) { LoadLogCurveInfo(parent.Children, dataObject); } await Task.Yield(); Runtime.ShowBusy(false); }); }
private void LoadWellboreObjects(ResourceViewModel parent, string uri) { Runtime.ShowBusy(); Task.Run(async() => { var etpUri = new EtpUri(uri); if (ObjectTypes.Log.EqualsIgnoreCase(etpUri.ObjectType)) { var logFolders = new Dictionary <string, string> { { ObjectFolders.Time, Enum.GetName(typeof(Witsml141ReferenceData.LogIndexType), Witsml141ReferenceData.LogIndexType.datetime) }, { ObjectFolders.Depth, Enum.GetName(typeof(Witsml141ReferenceData.LogIndexType), Witsml141ReferenceData.LogIndexType.measureddepth) }, { ObjectFolders.All, ObjectFolders.All } }; logFolders .Select(x => ToResourceViewModel(etpUri.Append(x.Value), x.Key, LoadLogObjects)) .ForEach(parent.Children.Add); } else { var dataObjects = ObjectTypes.IsGrowingDataObject(etpUri.ObjectType) ? Context.GetGrowingObjectsWithStatus(etpUri.ObjectType, etpUri) : Context.GetWellboreObjects(etpUri.ObjectType, etpUri); await LoadDataItems(dataObjects, parent.Children, LoadGrowingObjectChildren, x => x.GetUri(), 0); } Runtime.ShowBusy(false); }); }
/// <summary> /// Expands the specified resource. /// </summary> /// <param name="resource">The resource.</param> public bool Expand(ResourceViewModel resource) { resource.IsExpanded = true; int index = WaitHandle.WaitAny(new[] { _messageRespondedEvent, _cancellationTokenSource.Token.WaitHandle }, 10000); if (_cancellationTokenSource.Token.IsCancellationRequested) { Runtime.Invoke(() => StatusBarText = "Expanding All Cancelled."); ExpandAllInProcess = false; return(false); } else if (index == WaitHandle.WaitTimeout) { Runtime.Invoke(() => StatusBarText = "Expanding All Timed Out."); ExpandAllInProcess = false; return(false); } var children = resource.Children.ToList(); foreach (var child in children) { if (!child.IsExpanded && child.HasPlaceholder && child.Resource.TargetCount > 0) { bool succeeded = Expand(child); if (!succeeded) { ExpandAllInProcess = false; return(false); } } } return(true); }
/// <summary> /// Gets the resources using the Discovery protocol. /// </summary> /// <param name="uri">The URI.</param> /// <param name="parent">The parent.</param> /// <returns>The message identifier.</returns> public Task <long> GetResources(string uri, ResourceViewModel parent = null) { var result = EtpExtender.GetResources(uri); return(Task.FromResult(result)); }