Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22266: NotesXMLDataImport #95

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Samples/XMLDataToGenerateDiagram/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Custom Userhandle as a SpeedDial component

This sample demonstrates how to convert XML data into JSON format and how to generate a diagram using this JSON value.

## Prerequisites

* Visual Studio 2022

## How to run the project

* Checkout this project to a location in your disk.
* Open the solution file using the Visual Studio 2022.
* Restore the NuGet packages by rebuilding the solution.
* Run the project.
13 changes: 13 additions & 0 deletions Samples/XMLDataToGenerateDiagram/XMLData/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>

29 changes: 29 additions & 0 deletions Samples/XMLDataToGenerateDiagram/XMLData/FileUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.JSInterop;

namespace XMLData.Pages
{

#pragma warning disable CA1052 // Static holder types should be Static or NotInheritable
public class FileUtil
#pragma warning restore CA1052 // Static holder types should be Static or NotInheritable
{
public async static Task SaveAs(IJSRuntime js, string data, string fileName)
{
await js.InvokeAsync<object>(
"saveDiagram",
#pragma warning disable CA1305 // Specify IFormatProvider
Convert.ToString(data), fileName).ConfigureAwait(true);
#pragma warning restore CA1305 // Specify IFormatProvider
}
public async static Task Click(IJSRuntime js)
{
await js.InvokeAsync<object>(
"click").ConfigureAwait(true);
}
public async static Task<string> LoadFile(IJSRuntime js, object data)
{
return await js.InvokeAsync<string>(
"loadFile", data).ConfigureAwait(true);
}
}
}
190 changes: 190 additions & 0 deletions Samples/XMLDataToGenerateDiagram/XMLData/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
@page "/"

@using Syncfusion.Blazor.Diagram
@using Syncfusion.Blazor.Buttons
@using Microsoft.JSInterop
@using Syncfusion.Blazor.Navigations
@using Syncfusion.Blazor.Inputs
@inject IJSRuntime jsRuntime
@using Newtonsoft.Json
@using System.Xml.Linq
@using System;
@using System.Collections.Generic;
@using System.Linq;

@inject XmlFileService XmlFileService
<style>
.e-file-select-wrap {
display: none;
}

.e-orgchart-template-div-style {
position: absolute;
width: 170px;
height: 120px;
border: 1px solid #6495ED;
background: #6495ED;
box-sizing: border-box;
border-radius: 5px;
}
</style>

<div>

<SfDiagramComponent Height="700px" @ref="@diagram" @bind-Nodes="@nodes" NodeCreating="@OnNodeCreating" ConnectorCreating="@OnConnectorCreating">
<DataSourceSettings ID="EmployeeID" ParentID="ManagerID" DataSource="@dataSourceDetails"></DataSourceSettings>
<Layout Type="LayoutType.HierarchicalTree" @bind-HorizontalSpacing="@HorizontalSpacing" @bind-VerticalSpacing="@VerticalSpacing" @bind-HorizontalAlignment="@horizontalAlignment" @bind-VerticalAlignment="@verticalAlignment">
<LayoutMargin Left="50" Top="50"></LayoutMargin>
</Layout>
<DiagramTemplates>
<NodeTemplate>
@{
Node node1 = (context as Node);
string Name = (node1.Data as OrgChartDetails).Name;
string Designation = (node1.Data as OrgChartDetails).Designation;
<div class="e-orgchart-template-div-style">
<div style="height:75%; float:right; margin-right:20px;">
<div>
<b>Name:</b> @Name
</div>
<div>
<b>Role:</b> @Designation
</div>
</div>
</div>
}
</NodeTemplate>
</DiagramTemplates>
</SfDiagramComponent>
<SfButton OnClick="@XMLDiagram">ImportToXML</SfButton>
</div>



@code{

SfDiagramComponent diagram;

//Creates connectors with some default values.
private void OnNodeCreating(IDiagramObject obj)
{
Node node = obj as Node;
node.Height = 120;
node.Width = 170;
node.Style.Fill = "#88C65C";
node.Style.StrokeColor = "#88C65C";
node.Shape = new Shape()
{
Type = Syncfusion.Blazor.Diagram.NodeShapes.HTML,
};

}
//Creates node with some default values.
private void OnConnectorCreating(IDiagramObject connector)
{
Connector connectors = connector as Connector;
connectors.Type = ConnectorSegmentType.Orthogonal;
connectors.Style = new TextStyle() { StrokeColor = "#6495ED", StrokeWidth = 2 };
connectors.TargetDecorator = new DecoratorSettings
{
Shape = DecoratorShape.None,
};
}
/// <summary>
/// Specifies the vertical spacing between diagram elements.
/// </summary>
int VerticalSpacing = 50;

/// <summary>
/// Specifies the horizontal spacing between diagram elements.
/// </summary>
int HorizontalSpacing = 100;
/// <summary>
/// Specifies the horizontal alignment of the diagram elements.
/// </summary>
private HorizontalAlignment horizontalAlignment = HorizontalAlignment.Auto;

/// <summary>
/// Specifies the vertical alignment of the diagram elements.
/// </summary>
private VerticalAlignment verticalAlignment = VerticalAlignment.Auto;
DiagramObjectCollection<Node> nodes = new DiagramObjectCollection<Node>();
protected override void OnInitialized()
{
Node node = new Node()
{
// Position of the node
OffsetX = 250,
OffsetY = 250,
// Size of the node
Width = 100,
Height = 100,
Style = new ShapeStyle() { Fill = "#6495ED", StrokeColor = "white" }
};
// nodes.Add(node);
}

/// <summary>
/// List to store data source details.
/// </summary>
private List<OrgChartDetails> dataSourceDetails = new List<OrgChartDetails>();
//Method to save the diagram
public async Task XMLDiagram()
{
XDocument xmlDoc = await XmlFileService.GetXmlDocumentAsync("people.xml");
var employeesList = new List<Dictionary<string, string>>();
if (xmlDoc != null)
{
foreach (var employee in xmlDoc.Descendants("Employees"))
{
var empDict = new Dictionary<string, string>
{
{ "EmployeeID", employee.Attribute("EmployeeID").Value },
{ "Name", employee.Element("Name").Value },
{ "Designation", employee.Element("Designation").Value }
};

// Optional ManagerID
var managerId = employee.Element("ManagerID");
if (managerId != null)
{
empDict.Add("ManagerID", managerId.Value);
}

employeesList.Add(empDict);
}
// Convert the list of employees to JSON format
string jsonData = JsonConvert.SerializeObject(employeesList, Formatting.Indented);
dataSourceDetails = JsonConvert.DeserializeObject<List<OrgChartDetails>>(jsonData);
await diagram.RefreshDataSource();
}
}

public partial class OrgChartDetails
{
/// <summary>
/// Gets or sets the employee ID.
/// </summary>

public string EmployeeID { get; set; }

/// <summary>
/// Gets or sets the name of the employee.
/// </summary>
public string Name { get; set; }

/// <summary>
/// Gets or sets the role of the employee.
/// </summary>
public string Designation { get; set; }

/// <summary>
/// Gets or sets the Manager of the employee.
/// </summary>
public string ManagerID { get; set; }

}

}


8 changes: 8 additions & 0 deletions Samples/XMLDataToGenerateDiagram/XMLData/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page "/"
@namespace XMLData.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = "_Layout";
}

<component type="typeof(App)" render-mode="ServerPrerendered" />
25 changes: 25 additions & 0 deletions Samples/XMLDataToGenerateDiagram/XMLData/Pages/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@using Microsoft.AspNetCore.Components.Web
@namespace XMLData.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
<script src="_content/Syncfusion.Blazor/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
<link href="XMLData.styles.css" rel="stylesheet" />
<script src="~/interop.js"></script>
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
<body>
@RenderBody()



<script src="_framework/blazor.server.js"></script>
</body>
</html>
30 changes: 30 additions & 0 deletions Samples/XMLDataToGenerateDiagram/XMLData/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Syncfusion.Blazor;
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSyncfusionBlazor();
builder.Services.AddSingleton<XmlFileService>();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:11920",
"sslPort": 44341
}
},
"profiles": {
"XMLData": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7204;http://localhost:5236",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
17 changes: 17 additions & 0 deletions Samples/XMLDataToGenerateDiagram/XMLData/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@inherits LayoutComponentBase

<PageTitle>XMLData</PageTitle>

<div class="page">
<div class="sidebar">
<NavMenu />
</div>


<main>

<article class="content px-4">
@Body
</article>
</main>
</div>
Loading
Loading