Skip to content

Commit

Permalink
Added credential inputs, cleaned up the code, and added ui to edit ba…
Browse files Browse the repository at this point in the history
…se class
ewelsh committed Jul 18, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 8e83354 commit ebc977b
Showing 15 changed files with 322 additions and 171 deletions.
4 changes: 2 additions & 2 deletions EpicorRESTGenerator.WPFGUI/App.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Application x:Class="EpicorRESTGenerator.WPFGUI.App"
<Application x:Class="EpicorSwaggerRESTGenerator.WPFGUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:EpicorRESTGenerator.WPFGUI"
xmlns:local="clr-namespace:EpicorSwaggerRESTGenerator.WPFGUI"
StartupUri="generator.xaml">
<Application.Resources>

2 changes: 1 addition & 1 deletion EpicorRESTGenerator.WPFGUI/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
using System.Threading.Tasks;
using System.Windows;

namespace EpicorRESTGenerator
namespace EpicorSwaggerRESTGenerator
{
/// <summary>
/// Interaction logic for App.xaml
4 changes: 2 additions & 2 deletions EpicorRESTGenerator.WPFGUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EpicorRESTGenerator.WPFGUI")]
[assembly: AssemblyTitle("EpicorSwaggerRESTGenerator.WPFGUI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EpicorRESTGenerator.WPFGUI")]
[assembly: AssemblyProduct("EpicorSwaggerRESTGenerator.WPFGUI")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
4 changes: 2 additions & 2 deletions EpicorRESTGenerator.WPFGUI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion EpicorRESTGenerator.WPFGUI/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 31 additions & 7 deletions EpicorRESTGenerator.WPFGUI/generator.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Window x:Class="EpicorRESTGenerator.WPFGUI.generator"
<Window x:Class="EpicorSwaggerRESTGenerator.WPFGUI.generator"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:EpicorRESTGenerator.WPFGUI"
xmlns:local="clr-namespace:EpicorSwaggerRESTGenerator.WPFGUI"
mc:Ignorable="d"
Title="Epicor Client Generator" Height="516.224" Width="584.444">
Title="Epicor Client Generator" Height="547.724" Width="584.444">
<Grid Margin="0,0,2,0">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
@@ -16,9 +16,9 @@
<Label x:Name="ERPProjectDirLabel_Copy2" Content="Namespace:" HorizontalAlignment="Left" Margin="10,36,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.542,2.237" Height="26" Width="74"/>
<TextBox x:Name="NamespaceTextBox" HorizontalAlignment="Left" Height="23" Margin="89,36,0,0" TextWrapping="Wrap" Text="E10RestClient" VerticalAlignment="Top" Width="475"/>
<Label x:Name="ERPProjectDirLabel_Copy3" Content="Base Class:" HorizontalAlignment="Left" Margin="17,64,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.542,2.237" Height="26" Width="67"/>
<TextBox x:Name="BaseClassTextBox" HorizontalAlignment="Left" Height="23" Margin="89,64,0,0" TextWrapping="Wrap" Text="TMIBaseClass" VerticalAlignment="Top" Width="475"/>
<CheckBox x:Name="UseBaseClassCheckBox" Content="Use Base Class" HorizontalAlignment="Right" Margin="0,92,130,0" VerticalAlignment="Top" IsChecked="True" Height="15" Width="97"/>
<TabControl x:Name="tabControl" HorizontalAlignment="Left" Height="360" Margin="10,117,0,0" VerticalAlignment="Top" Width="554" IsEnabled="False" SelectionChanged="OnTabItemChanged">
<TextBox x:Name="BaseClassTextBox" HorizontalAlignment="Left" Height="23" Margin="89,64,0,0" TextWrapping="Wrap" Text="TMIBaseClass" VerticalAlignment="Top" Width="355"/>
<CheckBox x:Name="UseBaseClassCheckBox" Content="Use Base Class" HorizontalAlignment="Right" Margin="0,64,10,0" VerticalAlignment="Top" IsChecked="True" Height="15" Width="97"/>
<TabControl x:Name="tabControl" Margin="10,147,10,10" IsEnabled="False" SelectionChanged="OnTabItemChanged">
<TabItem Header="ERP">
<Grid Background="#FFE5E5E5">
<Grid.ColumnDefinitions>
@@ -75,7 +75,31 @@
<Button x:Name="GeneratBAQButton" Content="Generate BAQ" HorizontalAlignment="Left" Margin="343.38,306,0,0" VerticalAlignment="Top" Width="100" RenderTransformOrigin="1.144,0.117" Grid.Column="3" Click="GeneratBAQButton_Click"/>
</Grid>
</TabItem>
<TabItem Header="ClientBase">
<Grid Background="#FFE5E5E5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="35*"/>
<ColumnDefinition Width="43*"/>
<ColumnDefinition Width="428*"/>
</Grid.ColumnDefinitions>
<Button x:Name="button" Content="Save" Grid.Column="3" HorizontalAlignment="Left" Margin="369.543,10,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
<Button x:Name="button1" Content="Load" Grid.Column="3" HorizontalAlignment="Left" Margin="289.543,10,0,0" VerticalAlignment="Top" Width="75" Click="button1_Click"/>
<RichTextBox x:Name="richTextBox" Grid.ColumnSpan="3" Margin="0.38,40,9,10" RenderTransformOrigin="0.36,0.31" IsDocumentEnabled="True" Grid.Column="1" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible">
<FlowDocument>
<Paragraph>
<Run Text="RichTextBox"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</Grid>
</TabItem>
</TabControl>
<Button x:Name="CheckService" Content="Check" HorizontalAlignment="Left" Margin="489,92,0,0" VerticalAlignment="Top" Width="75" Click="CheckService_Click"/>
<Button x:Name="CheckService" Content="Check" HorizontalAlignment="Left" Margin="489,122,0,0" VerticalAlignment="Top" Width="75" Click="CheckService_Click"/>
<Label x:Name="usernameLabel" Content="Username:" HorizontalAlignment="Left" Margin="18,90,0,0" VerticalAlignment="Top"/>
<Label x:Name="passwordlabel" Content="Password:" HorizontalAlignment="Left" Margin="22,116,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="usernameTextBox" HorizontalAlignment="Left" Height="23" Margin="89,92,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="355" IsEnabled="False"/>
<TextBox x:Name="passwordTextBox" HorizontalAlignment="Left" Height="23" Margin="89,119,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="355" IsEnabled="False"/>
<CheckBox x:Name="useCredentialsCheckBox" Content="Use Credentials" HorizontalAlignment="Left" Margin="467,90,0,0" VerticalAlignment="Top" Checked="useCredentialsCheckBox_Checked" Unchecked="useCredentialsCheckBox_UnChecked"/>
</Grid>
</Window>
73 changes: 70 additions & 3 deletions EpicorRESTGenerator.WPFGUI/generator.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using EpicorRESTGenerator.Models;
using EpicorSwaggerRESTGenerator.Models;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -13,7 +15,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace EpicorRESTGenerator.WPFGUI
namespace EpicorSwaggerRESTGenerator.WPFGUI
{
/// <summary>
/// Interaction logic for generator.xaml
@@ -33,6 +35,19 @@ private void CheckService_Click(object sender, RoutedEventArgs e)
MessageBox.Show("Epicor API URL is Required");
return;
}
if((bool)useCredentialsCheckBox.IsChecked)
{
if(string.IsNullOrEmpty(usernameTextBox.Text))
{
MessageBox.Show("Username is required");
return;
}
if(string.IsNullOrEmpty(passwordTextBox.Text))
{
MessageBox.Show("Password is required");
return;
}
}

MessageBoxResult result = MessageBox.Show("Do you want to generate a client for oData? Selecting No will default to custom methods", "", MessageBoxButton.YesNo);
switch (result)
@@ -113,7 +128,15 @@ private void PopulateService(TextBox textBox, ListBox listBox, string type)
{
MessageBox.Show("Services URL is Required");
}
services = service.getServices(textBox.Text);

EpicorDetails details = new EpicorDetails();
if((bool)useCredentialsCheckBox.IsChecked)
{
details.Username = usernameTextBox.Text;
details.Password = passwordTextBox.Text;
}

services = service.getServices(textBox.Text, details);
services.workspace.collection = services.workspace.collection.Where(o => o.href.ToUpper().StartsWith(type)).ToArray<serviceWorkspaceCollection>();
listBox.ItemsSource = services.workspace.collection.Select(o => o.href);
}
@@ -149,5 +172,49 @@ private void ServiceListBox_SelectionChanged(object sender, SelectionChangedEven
{
e.Handled = true;
}

private void useCredentialsCheckBox_Checked(object sender, RoutedEventArgs e)
{
usernameTextBox.IsEnabled = true;
passwordTextBox.IsEnabled = true;
}
private void useCredentialsCheckBox_UnChecked(object sender, RoutedEventArgs e)
{
usernameTextBox.IsEnabled = false;
passwordTextBox.IsEnabled = false;
}

private void button1_Click(object sender, RoutedEventArgs e)
{
richTextBox.Document = new FlowDocument();

OpenFileDialog openFile1 = new OpenFileDialog();
openFile1.DefaultExt = "*.cs";
openFile1.Filter = "CS Files|*.cs";

var hasValue = openFile1.ShowDialog().HasValue;
if (hasValue)
{
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(System.IO.File.ReadAllText(openFile1.FileName));
FlowDocument document = new FlowDocument(paragraph);
richTextBox.Document = document;
}
}
private void button_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.DefaultExt = "*.cs";
dialog.Filter = "CS Files|*.cs";

if (dialog.ShowDialog() == true)
{
TextRange t = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
FileStream file = new FileStream(dialog.FileName, FileMode.Create);
t.Save(file, System.Windows.DataFormats.Text);
file.Close();
//File.WriteAllText(dialog.FileName, richTextBox.Document.);
}
}
}
}
3 changes: 2 additions & 1 deletion EpicorSwaggerRESTGenerator/ClientBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
@@ -54,3 +54,4 @@ protected HttpClient CreateHttpClientAsync(CancellationToken cancellationToken)
}
}
}

5 changes: 5 additions & 0 deletions EpicorSwaggerRESTGenerator/EpicorSwaggerRESTGenerator.csproj
Original file line number Diff line number Diff line change
@@ -70,7 +70,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ClientBase.cs" />
<Compile Include="Models\Client.cs" />
<Compile Include="Models\EpicorDetails.cs" />
<Compile Include="Models\Service.cs" />
<Compile Include="Models\serviceWorkspace.cs" />
<Compile Include="Models\serviceWorkspaceCollection.cs" />
<Compile Include="Models\title.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
26 changes: 26 additions & 0 deletions EpicorSwaggerRESTGenerator/Models/Client.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace EpicorSwaggerRESTGenerator.Models
{
public static class Client
{
public static WebClient getWebClient(string username = "", string password = "")
{
WebClient client = new WebClient();
ServicePointManager.ServerCertificateValidationCallback += (senderC, cert, chain, sslPolicyErrors) => true;
if (!string.IsNullOrEmpty(username))
{
client.Credentials = new NetworkCredential() { UserName = username, Password = password };
}else
{
client.UseDefaultCredentials = true;
}
return client;
}
}
}
19 changes: 19 additions & 0 deletions EpicorSwaggerRESTGenerator/Models/EpicorDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EpicorSwaggerRESTGenerator.Models
{
public class EpicorDetails
{
public string Namespace { get; set; }
public bool useBaseClass { get; set; }
public string BaseClass { get; set; }
public string APIURL { get; set; }
public string Project { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
}
156 changes: 4 additions & 152 deletions EpicorSwaggerRESTGenerator/Models/Service.cs
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
using System.Text;
using System.Threading.Tasks;

namespace EpicorRESTGenerator.Models
namespace EpicorSwaggerRESTGenerator.Models
{
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2007/app")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.w3.org/2007/app", IsNullable = false)]
@@ -47,9 +47,9 @@ public string @base
}
}

public static service getServices(string serviceURL)
public static service getServices(string serviceURL, EpicorDetails details)
{
using (WebClient client = getWebClient())
using (WebClient client = Client.getWebClient(string.IsNullOrEmpty(details.Username)?"":details.Username, string.IsNullOrEmpty(details.Password) ? "" : details.Password))
{
service services = new service();
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(service));
@@ -64,7 +64,7 @@ public static service getServices(string serviceURL)

public static async Task<bool> generateCode(service services, EpicorDetails details)
{
using (WebClient client = getWebClient())
using (WebClient client = Client.getWebClient(string.IsNullOrEmpty(details.Username) ? "" : details.Username, string.IsNullOrEmpty(details.Password) ? "" : details.Password))
{
foreach (var service in services.workspace.collection)
{
@@ -129,14 +129,6 @@ public static async Task<bool> generateCode(service services, EpicorDetails deta
}
return true;
}

private static WebClient getWebClient()
{
WebClient client = new WebClient();
ServicePointManager.ServerCertificateValidationCallback += (senderC, cert, chain, sslPolicyErrors) => true;
client.UseDefaultCredentials = true;
return client;
}
private static void addReference(string projectFile, string filename)
{
using (var collection = new Microsoft.Build.Evaluation.ProjectCollection())
@@ -154,144 +146,4 @@ private static void addReference(string projectFile, string filename)
}
}
}

/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2007/app")]
public partial class serviceWorkspace
{

private title titleField;

private serviceWorkspaceCollection[] collectionField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://www.w3.org/2005/Atom")]
public title title
{
get
{
return this.titleField;
}
set
{
this.titleField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("collection")]
public serviceWorkspaceCollection[] collection
{
get
{
return this.collectionField;
}
set
{
this.collectionField = value;
}
}
}

/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2005/Atom")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.w3.org/2005/Atom", IsNullable = false)]
public partial class title
{

private string typeField;

private string valueField;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string type
{
get
{
return this.typeField;
}
set
{
this.typeField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}

/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2007/app")]
public partial class serviceWorkspaceCollection
{

private title titleField;

private string[] textField;

private string hrefField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://www.w3.org/2005/Atom")]
public title title
{
get
{
return this.titleField;
}
set
{
this.titleField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string[] Text
{
get
{
return this.textField;
}
set
{
this.textField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string href
{
get
{
return this.hrefField;
}
set
{
this.hrefField = value;
}
}
}

public class EpicorDetails
{
public string Namespace { get; set; }
public bool useBaseClass { get; set; }
public string BaseClass { get; set; }
public string APIURL { get; set; }
public string Project { get; set; }
}
}
47 changes: 47 additions & 0 deletions EpicorSwaggerRESTGenerator/Models/serviceWorkspace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using EpicorSwaggerRESTGenerator.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EpicorSwaggerRESTGenerator.Models
{
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2007/app")]
public partial class serviceWorkspace
{

private title titleField;

private serviceWorkspaceCollection[] collectionField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://www.w3.org/2005/Atom")]
public title title
{
get
{
return this.titleField;
}
set
{
this.titleField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("collection")]
public serviceWorkspaceCollection[] collection
{
get
{
return this.collectionField;
}
set
{
this.collectionField = value;
}
}
}
}
63 changes: 63 additions & 0 deletions EpicorSwaggerRESTGenerator/Models/serviceWorkspaceCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EpicorSwaggerRESTGenerator.Models
{

/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2007/app")]
public partial class serviceWorkspaceCollection
{

private title titleField;

private string[] textField;

private string hrefField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://www.w3.org/2005/Atom")]
public title title
{
get
{
return this.titleField;
}
set
{
this.titleField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string[] Text
{
get
{
return this.textField;
}
set
{
this.textField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string href
{
get
{
return this.hrefField;
}
set
{
this.hrefField = value;
}
}
}
}
47 changes: 47 additions & 0 deletions EpicorSwaggerRESTGenerator/Models/title.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EpicorSwaggerRESTGenerator.Models
{
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2005/Atom")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.w3.org/2005/Atom", IsNullable = false)]
public partial class title
{

private string typeField;

private string valueField;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string type
{
get
{
return this.typeField;
}
set
{
this.typeField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}
}

0 comments on commit ebc977b

Please sign in to comment.