/// <summary> /// Build a POCO from an ITypedElement. /// </summary> /// <param name="source"></param> /// <returns></returns> public Base BuildFrom(ITypedElement source) { if (source == null) { throw Error.ArgumentNull(nameof(source)); } if (source is IExceptionSource) { using (source.Catch((o, a) => ExceptionHandler.NotifyOrThrow(o, a))) { return(build()); } } else { return(build()); } Base build() { var typeToBuild = ModelInfo.GetTypeForFhirType(source.InstanceType); if (typeToBuild == null) { ExceptionHandler.NotifyOrThrow(this, ExceptionNotification.Error( new StructuralTypeException($"While building a POCO: There is no .NET type representing the FHIR type '{source.InstanceType}'."))); return(null); } var settings = new ParserSettings { AcceptUnknownMembers = _settings.IgnoreUnknownMembers, AllowUnrecognizedEnums = _settings.AllowUnrecognizedEnums }; return(typeToBuild.CanBeTreatedAsType(typeof(Resource)) ? new ResourceReader(source, settings).Deserialize() : new ComplexTypeReader(source, settings).Deserialize()); } }
public Base BuildFrom(ISourceNode source, string dataType) { if (dataType == null) { throw Error.ArgumentNull(nameof(dataType)); } var typeFound = ModelInfo.GetTypeForFhirType(dataType); if (typeFound == null) { ExceptionNotification.Error( new StructuralTypeException($"There is no .NET type representing the FHIR type '{dataType}'.")); return(null); } else { return(buildInternal(source, typeFound)); } }
/// <summary> /// Build a POCO from an ISourceNode. /// </summary> /// <param name="source"></param> /// <param name="dataType">Optional. Type of POCO to build. Should be one of the generated POCO classes.</param> /// <returns></returns> /// <remarks>If <paramref name="dataType"/> is not supplied, or is <code>Resource</code> or <code>DomainResource</code>, /// the builder will try to determine the actual type to create from the <paramref name="source"/>. </remarks> public Base BuildFrom(ISourceNode source, Type dataType = null) { if (source == null) { throw Error.ArgumentNull(nameof(source)); } string typeFound = null; if (dataType != null) { typeFound = ModelInfo.GetFhirTypeNameForType(dataType); if (typeFound == null) { ExceptionNotification.Error( new StructuralTypeException($"While building a POCO: The .NET type '{dataType.Name}' does not represent a FHIR type.")); return(null); } } return(BuildFrom(source, typeFound)); }
internal bool MustSerializeMember(ITypedElement source, out IElementDefinitionSummary info) { info = source.Definition; if (info == null && !_roundtripMode) { var message = $"Element '{source.Location}' is missing type information."; if (_settings.IgnoreUnknownElements) { ExceptionHandler.NotifyOrThrow(source, ExceptionNotification.Warning( new MissingTypeInformationException(message))); } else { ExceptionHandler.NotifyOrThrow(source, ExceptionNotification.Error( new MissingTypeInformationException(message))); } return(false); } return(true); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.Parameter is Sample sample) { CurrentSample = sample; } if (CurrentSample != null) { // UNO TODO // The controls may be loaded when set directly to their parent // so the datacontext of the renderer needs to be set early. await SetSampleDataContext(); if (CurrentSample.HasType) { try { SamplePage = Activator.CreateInstance(CurrentSample.PageType) as Page; SampleContent.Content = SamplePage; // Some samples use the OnNavigatedTo and OnNavigatedFrom // Can't use Frame here because some samples depend on the current Frame MethodInfo method = CurrentSample.PageType.GetMethod( "OnNavigatedTo", BindingFlags.Instance | BindingFlags.NonPublic); if (method != null) { method.Invoke(SamplePage, new object[] { e }); } } catch (Exception ex) { ExceptionNotification.Show("Sample Page failed to load: " + ex.Message); } if (SamplePage != null) { SamplePage.Loaded += SamplePage_Loaded; // UNO TODO if (SamplePage.IsLoaded) { SamplePage_Loaded(SamplePage, new RoutedEventArgs()); } } } else if (!CurrentSample.HasXAMLCode) { _onlyDocumentation = true; } async Task SetSampleDataContext() { InfoAreaPivot.Items.Clear(); // Load Sample Properties before we load sample (if we haven't before) await CurrentSample.PreparePropertyDescriptorAsync(); // We only have properties on examples with live XAML var propertyDesc = CurrentSample.PropertyDescriptor; DataContext = CurrentSample; if (propertyDesc != null) { _xamlRenderer.DataContext = propertyDesc.Expando; } if (propertyDesc?.Options.Count > 0) { InfoAreaPivot.Items.Add(PropertiesPivotItem); } // Uno todo (Adding a pivot item does not refresh SelectedItem) UpdateXamlRender(CurrentSample.BindedXamlCode); } if (CurrentSample.HasXAMLCode) { #if !HAS_UNO if (AnalyticsInfo.VersionInfo.GetDeviceFormFactor() != DeviceFormFactor.Desktop || CurrentSample.DisableXamlEditorRendering) #endif { // Only makes sense (and works) for now to show Live Xaml on Desktop, so fallback to old system here otherwise. XamlReadOnlyCodeRenderer.SetCode(CurrentSample.UpdatedXamlCode, "xaml"); InfoAreaPivot.Items.Add(XamlReadOnlyPivotItem); } #if !HAS_UNO else { XamlCodeEditor.Text = CurrentSample.UpdatedXamlCode; InfoAreaPivot.Items.Add(XamlPivotItem); _xamlCodeRendererSupported = true; } #endif InfoAreaPivot.SelectedIndex = 0; } if (CurrentSample.HasCSharpCode) { var code = await CurrentSample.GetCSharpSourceAsync(); CSharpCodeRenderer.SetCode(code, "c#"); InfoAreaPivot.Items.Add(CSharpPivotItem); } if (CurrentSample.HasDocumentation) { var contents = await CurrentSample.GetDocumentationAsync(); if (!string.IsNullOrWhiteSpace(contents)) { DocumentationTextBlock.Text = contents; InfoAreaPivot.Items.Add(DocumentationPivotItem); } } // Hide the GitHub button if there isn't a CodeUrl. if (string.IsNullOrEmpty(CurrentSample.CodeUrl)) { GithubButton.Visibility = Visibility.Collapsed; } else { GithubButton.Visibility = Visibility.Visible; } if (InfoAreaPivot.Items.Count == 0) { SidePaneState = PaneState.None; } else { SidePaneState = _onlyDocumentation ? PaneState.Full : PaneState.Normal; } Shell.Current.SetAppTitle($"{CurrentSample.CategoryName} > {CurrentSample.Name}"); } else { ExceptionNotification.Show("Sample does not exist"); } if (!CanChangePaneState) { SampleTitleBar.Children.Remove(NarrowInfoButton); } if (e.NavigationMode != NavigationMode.Back) { var nop = Samples.PushRecentSample(CurrentSample); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.Parameter is Sample sample) { CurrentSample = sample; } if (CurrentSample != null) { if (!string.IsNullOrWhiteSpace(CurrentSample.Type)) { try { var pageInstance = Activator.CreateInstance(CurrentSample.PageType); SampleContent.Content = pageInstance; } catch { ExceptionNotification.Show("Sample Page failed to load."); } if (SamplePage != null) { SamplePage.Loaded += SamplePage_Loaded; } } else { _onlyDocumentation = true; } DataContext = CurrentSample; await Samples.PushRecentSample(CurrentSample); var propertyDesc = CurrentSample.PropertyDescriptor; InfoAreaPivot.Items.Clear(); if (propertyDesc != null) { _xamlRenderer.DataContext = propertyDesc.Expando; } if (propertyDesc != null && propertyDesc.Options.Count > 0) { InfoAreaPivot.Items.Add(PropertiesPivotItem); } if (CurrentSample.HasXAMLCode) { if (AnalyticsInfo.VersionInfo.GetDeviceFormFactor() != DeviceFormFactor.Desktop || CurrentSample.DisableXamlEditorRendering) { // Only makes sense (and works) for now to show Live Xaml on Desktop, so fallback to old system here otherwise. XamlReadOnlyCodeRenderer.SetCode(CurrentSample.UpdatedXamlCode, "xaml"); InfoAreaPivot.Items.Add(XamlReadOnlyPivotItem); } else { XamlCodeEditor.Text = CurrentSample.UpdatedXamlCode; InfoAreaPivot.Items.Add(XamlPivotItem); _xamlCodeRendererSupported = true; } InfoAreaPivot.SelectedIndex = 0; } if (CurrentSample.HasCSharpCode) { var code = await CurrentSample.GetCSharpSourceAsync(); CSharpCodeRenderer.SetCode(code, "c#"); InfoAreaPivot.Items.Add(CSharpPivotItem); } if (CurrentSample.HasJavaScriptCode) { var code = await CurrentSample.GetJavaScriptSourceAsync(); JavaScriptCodeRenderer.SetCode(code, "js"); InfoAreaPivot.Items.Add(JavaScriptPivotItem); } if (CurrentSample.HasDocumentation) { #pragma warning disable SA1008 // Opening parenthesis must be spaced correctly var(contents, path) = await CurrentSample.GetDocumentationAsync(); #pragma warning restore SA1008 // Opening parenthesis must be spaced correctly documentationPath = path; if (!string.IsNullOrWhiteSpace(contents)) { DocumentationTextblock.Text = contents; InfoAreaPivot.Items.Add(DocumentationPivotItem); } } // Hide the Github button if there isn't a CodeUrl. if (string.IsNullOrEmpty(CurrentSample.CodeUrl)) { GithubButton.Visibility = Visibility.Collapsed; } if (InfoAreaPivot.Items.Count == 0) { SidePaneState = PaneState.None; _hasDocumentation = false; } else { SidePaneState = _onlyDocumentation ? PaneState.Full : PaneState.Normal; } Shell.Current.SetAppTitle($"{CurrentSample.CategoryName} > {CurrentSample.Name}"); } else { ExceptionNotification.Show("Sample does not exist"); } if (!CanChangePaneState) { SampleTitleBar.Children.Remove(NarrowInfoButton); PaneStates.States.Clear(); WindowStates.States.Clear(); } }
private async Task UpdateXamlRenderAsync(string text) { // Hide any Previous Errors XamlCodeRenderer.Decorations.Clear(); XamlCodeRenderer.Options.GlyphMargin = false; // Try and Render Xaml to a UIElement UIElement element = null; try { element = _xamlRenderer.Render(text); } catch (Exception ex) { ExceptionNotification.Show(ex.Message, 3000); } if (element != null) { // Add element to main panel var content = NavigationFrame.Content as Page; var root = content.FindDescendantByName("XamlRoot"); if (root is Panel) { // If we've defined a 'XamlRoot' element to host us as a panel, use that. (root as Panel).Children.Clear(); (root as Panel).Children.Add(element); } else { // Otherwise, just replace the entire page's content content.Content = element; } // Tell the page we've finished with an update to the XAML contents, after the control has rendered. await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { (content as IXamlRenderListener)?.OnXamlRendered(element as FrameworkElement); }); } else if (_xamlRenderer.Errors.Count > 0) { var error = _xamlRenderer.Errors.First(); XamlCodeRenderer.Options.GlyphMargin = true; var range = new Range(error.StartLine, 1, error.EndLine, await XamlCodeRenderer.GetModel().GetLineMaxColumnAsync(error.EndLine)); // Highlight Error Line XamlCodeRenderer.Decorations.Add(new IModelDeltaDecoration( range, new IModelDecorationOptions() { IsWholeLine = true, ClassName = _errorStyle, HoverMessage = new string[] { error.Message } })); // Show Glyph Icon XamlCodeRenderer.Decorations.Add(new IModelDeltaDecoration( range, new IModelDecorationOptions() { IsWholeLine = true, GlyphMarginClassName = _errorIconStyle, GlyphMarginHoverMessage = new string[] { error.Message } })); } }
public void SingleDataFormControlCollectionManagerInstance_OnNotifyExceptionOccurence(ExceptionNotification ex) { NotifierControl.Text = ex.Message; NotifierControl.Show(); }
private void raiseFormatError(string message, JToken node) { var(lineNumber, linePosition) = getPosition(node); ExceptionHandler.NotifyOrThrow(this, ExceptionNotification.Error(Error.Format("Parser: " + message, lineNumber, linePosition))); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.Parameter is Sample sample) { CurrentSample = sample; } if (CurrentSample != null) { if (!string.IsNullOrWhiteSpace(CurrentSample.Type)) { try { var pageInstance = Activator.CreateInstance(CurrentSample.PageType); SampleContent.Content = pageInstance; // Some samples use the OnNavigatedTo and OnNavigatedFrom // Can't use Frame here because some samples depend on the current Frame MethodInfo method = CurrentSample.PageType.GetMethod( "OnNavigatedTo", BindingFlags.Instance | BindingFlags.NonPublic); if (method != null) { method.Invoke(pageInstance, new object[] { e }); } } catch { ExceptionNotification.Show("Sample Page failed to load."); } if (SamplePage != null) { SamplePage.Loaded += SamplePage_Loaded; } } else { _onlyDocumentation = true; } InfoAreaPivot.Items.Clear(); if (CurrentSample.HasXAMLCode) { // Load Sample Properties before we load sample (if we haven't before) await CurrentSample.PreparePropertyDescriptorAsync(); // We only have properties on examples with live XAML var propertyDesc = CurrentSample.PropertyDescriptor; if (propertyDesc != null) { _xamlRenderer.DataContext = propertyDesc.Expando; } if (propertyDesc?.Options.Count > 0) { InfoAreaPivot.Items.Add(PropertiesPivotItem); } if (AnalyticsInfo.VersionInfo.GetDeviceFormFactor() != DeviceFormFactor.Desktop || CurrentSample.DisableXamlEditorRendering) { // Only makes sense (and works) for now to show Live Xaml on Desktop, so fallback to old system here otherwise. XamlReadOnlyCodeRenderer.SetCode(CurrentSample.UpdatedXamlCode, "xaml"); InfoAreaPivot.Items.Add(XamlReadOnlyPivotItem); } else { XamlCodeEditor.Text = CurrentSample.UpdatedXamlCode; InfoAreaPivot.Items.Add(XamlPivotItem); _xamlCodeRendererSupported = true; } InfoAreaPivot.SelectedIndex = 0; } if (CurrentSample.HasCSharpCode) { var code = await CurrentSample.GetCSharpSourceAsync(); CSharpCodeRenderer.SetCode(code, "c#"); InfoAreaPivot.Items.Add(CSharpPivotItem); } if (CurrentSample.HasDocumentation) { #pragma warning disable SA1008 // Opening parenthesis must be spaced correctly var(contents, path) = await CurrentSample.GetDocumentationAsync(); #pragma warning restore SA1008 // Opening parenthesis must be spaced correctly documentationPath = path; if (!string.IsNullOrWhiteSpace(contents)) { DocumentationTextBlock.Text = contents; InfoAreaPivot.Items.Add(DocumentationPivotItem); } } // Hide the GitHub button if there isn't a CodeUrl. if (string.IsNullOrEmpty(CurrentSample.CodeUrl)) { GithubButton.Visibility = Visibility.Collapsed; } else { GithubButton.Visibility = Visibility.Visible; } DataContext = CurrentSample; if (InfoAreaPivot.Items.Count == 0) { SidePaneState = PaneState.None; } else { SidePaneState = _onlyDocumentation ? PaneState.Full : PaneState.Normal; } Shell.Current.SetAppTitle($"{CurrentSample.CategoryName} > {CurrentSample.Name}"); } else { ExceptionNotification.Show("Sample does not exist"); } if (!CanChangePaneState) { SampleTitleBar.Children.Remove(NarrowInfoButton); } if (e.NavigationMode != NavigationMode.Back) { var nop = Samples.PushRecentSample(CurrentSample); } }
public void Test(string message) { ExceptionHandler.NotifyOrThrow(this, ExceptionNotification.Error(new FormatException(message))); }