barely works

parent 9df2f501
......@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2011
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShoptimizaSalesFileExporter", "ShoptimizaSalesFileExporter\ShoptimizaSalesFileExporter.csproj", "{162E241E-3C61-4401-9CFD-A2FB0B726CC2}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShoptimizaSalesFileExporter", "src\ShoptimizaSalesFileExporter.csproj", "{162E241E-3C61-4401-9CFD-A2FB0B726CC2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ShoptimizaSalesFileExporter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
This diff is collapsed.
using System;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Windows.Forms;
namespace ShoptimizaSalesFileExporter
{
public partial class ConfigurationWizard : Form
{
Configuration newConf = new Configuration();
public ConfigurationWizard()
{
InitializeComponent();
testDBWorker.RunWorkerCompleted += TestDBWorker_RunWorkerCompleted;
}
private void credentials_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
{
string apiKey = txtAPIKey.Text;
string secret = txtSharedSecret.Text;
if (apiKey == "")
{
errorProvider1.SetError(txtAPIKey, "API Key is mandatory");
e.Cancel = true;
return;
}
else
{
errorProvider1.SetError(txtAPIKey, null);
}
if (secret == "")
{
errorProvider1.SetError(txtSharedSecret, "Shared Secret is mandatory");
e.Cancel = true;
return;
}
else
{
errorProvider1.SetError(txtSharedSecret, null);
}
// we want to prevent to move to next wizard page until we validate credentials
e.Cancel = true;
//this.Enabled = false;
wizardControl1.Enabled = false;
var args = new Tuple<string, string, string>(apiKey, secret, "http://localhost:3000/login");
testCredentialsWorker.DoWork += TestCredentials;
testCredentialsWorker.RunWorkerCompleted += TestCredentials_Complete;
testCredentialsWorker.RunWorkerAsync(args);
}
private void TestCredentials_Complete(object sender, RunWorkerCompletedEventArgs e)
{
Application.UseWaitCursor = false;
if (e.Error != null)
{
switch (e.Error)
{
case ShoptimizaInvalidAPIKeyException ex:
errorProvider1.SetError(txtAPIKey, MessageBox.Show("Invalid API Key").ToString());
wizardControl1.Enabled = true;
return;
default:
MessageBox.Show("We were not able to perform the request " + e.Error.StackTrace);
wizardControl1.Enabled = true;
return;
}
}
if (e.Cancelled)
{
// nothing
MessageBox.Show("cancelled");
wizardControl1.Enabled = true;
wizardControl1.NextPage(database, true);
return;
}
//this.Enabled = true;
newConf.APIKey = this.txtAPIKey.Text;
newConf.Secret = this.txtSharedSecret.Text;
wizardControl1.Enabled = true;
wizardControl1.NextPage(database, true);
}
private void welcome_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
{
}
private void database_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
{
string connectionString = this.txtMySqlConnection.Text;
// cancel commit always
e.Cancel = true;
if (connectionString == "")
{
errorProvider1.SetError(this.txtMySqlConnection, "Connection string is mandatory");
e.Cancel = true;
return;
}
else
{
errorProvider1.SetError(this.txtMySqlConnection, null);
}
wizardControl1.Enabled = false;
Application.UseWaitCursor = true;
testDBWorker.RunWorkerAsync(connectionString);
}
private void TestDBWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Application.UseWaitCursor = false;
wizardControl1.Enabled = true;
if (e.Error != null)
{
errorProvider1.SetError(this.txtMySqlConnection, "Unable to connect to MySql Server");
MessageBox.Show("There was an error trying to connect to MySql:" + e.Error.Message);
return;
}
bool success = (bool)e.Result;
if (!success)
{
MessageBox.Show("Unable to connect to MySql server. Please double check your connection string");
errorProvider1.SetError(this.txtMySqlConnection, "Unable to connect to MySql Server. Please double check your connection");
return;
}
newConf.MySqlConnStr = this.txtMySqlConnection.Text;
wizardControl1.NextPage(this.databaseQuery,true);
return;
}
private void TestCredentials(object sender, System.ComponentModel.DoWorkEventArgs e)
{
Application.UseWaitCursor = true;
var bw = sender as BackgroundWorker;
var args = e.Argument as Tuple<string, string, string>;
if (bw.CancellationPending)
{
e.Cancel = true;
}
var client = new ShoptimizaWebClient(args.Item1, args.Item2);
e.Result = client.DoGetRequest(args.Item3);
}
private void testDBWorker_DoWork(object sender, DoWorkEventArgs e)
{
var bw = sender as BackgroundWorker;
string connStr = (string)e.Argument;
MySqlConnection conn = new MySqlConnection(connStr);
{
conn.Open();
e.Result = true;
}
conn.Close();
}
private void testDBQueryWorker_DoWork(object sender, DoWorkEventArgs e)
{
var bw = sender as BackgroundWorker;
var args = e.Argument as Tuple<string, string>;
var connStr = args.Item1;
var query = args.Item2;
MySqlConnection conn = new MySqlConnection(connStr);
{
conn.Open();
MySqlCommand cmd = new MySqlCommand(query, conn);
MySqlDataReader reader = cmd.ExecuteReader();
reader.Read();
if (!reader.HasRows)
{
throw new Exception("No records found!");
}
//TODO: do something?
reader.Close();
}
conn.Close();
e.Result = true;
}
private void testDBQueryWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Application.UseWaitCursor = false;
wizardControl1.Enabled = true;
if (e.Error != null)
{
errorProvider1.SetError(this.txtMySqlConnection, "Unable to execute query");
MessageBox.Show("There was an error while running your query:" + e.Error.Message);
return;
}
bool success = (bool)e.Result;
if (!success)
{
MessageBox.Show("Unable to run query.");
errorProvider1.SetError(this.txtMySqlConnection, "Unable to run query");
return;
}
newConf.MySqlQuery = this.txtMysqlQuery.Text;
wizardControl1.NextPage(this.wpDone ,true);
return;
}
private void wizardControl1_Finished(object sender, EventArgs e)
{
Configuration conf = Configuration.Instance;
conf.APIKey = newConf.APIKey;
conf.Secret = newConf.Secret;
conf.MySqlConnStr = newConf.MySqlConnStr;
conf.MySqlQuery = newConf.MySqlQuery;
conf.Save();
this.Close();
}
private void databaseQuery_Commit(object sender, AeroWizard.WizardPageConfirmEventArgs e)
{
string query = this.txtMysqlQuery.Text;
// cancel commit always
e.Cancel = true;
if (query == "")
{
errorProvider1.SetError(this.txtMySqlConnection, "Query string is mandatory");
return;
}
else
{
errorProvider1.SetError(this.txtMySqlConnection, null);
}
wizardControl1.Enabled = false;
Application.UseWaitCursor = true;
var args = new Tuple<string, string>(this.newConf.MySqlConnStr, query);
testDBQueryWorker.RunWorkerAsync(args);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="bindingSource1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="errorProvider1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>154, 17</value>
</metadata>
<metadata name="testCredentialsWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>284, 17</value>
</metadata>
<metadata name="testDBWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>456, 17</value>
</metadata>
<metadata name="testDBQueryWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>583, 17</value>
</metadata>
</root>
\ No newline at end of file
namespace ShoptimizaSalesFileExporter
{
partial class Form1
partial class MainForm
{
/// <summary>
/// Required designer variable.
......@@ -28,13 +28,35 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(64, 245);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
this.Controls.Add(this.button1);
this.Name = "MainForm";
this.Text = "Shoptimiza Sales File Exporter";
this.Load += new System.EventHandler(this.MainForm_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ShoptimizaSalesFileExporter
{
public partial class MainForm : Form
{
private ConfigurationWizard configurationWizard;
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
}
private void bindingSource1_CurrentChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
configurationWizard = new ConfigurationWizard();
configurationWizard.FormClosed += ConfigurationWizard_FormClosed;
configurationWizard.Show();
}
private void ConfigurationWizard_FormClosed(object sender, FormClosedEventArgs e)
{
configurationWizard = null;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
namespace ShoptimizaSalesFileExporter
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
bool confExists = Configuration.Instance.Load();
Debug.WriteLine("Conf exists {0}",confExists);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 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("ShoptimizaSalesFileExporter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("ShoptimizaSalesFileExporter")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("162e241e-3c61-4401-9cfd-a2fb0b726cc2")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ShoptimizaSalesFileExporter.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;