Exemple #1
0
 private void cboConnections_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cboConnections.SelectedIndex != ListBox.NoMatches)
     {
         try
         {
             string conn    = cboConnections.SelectedItem.ToString();
             string tenant  = Settings.Get(IniSection.Connection, conn, IniKey.Tenant);
             string service = cboWWS2.ReturnValue();
             string version = Settings.Get(IniSection.WDWebServices, IniKey.Version);
             txtTenant.Text   = tenant;
             txtUsername.Text = Settings.Get(IniSection.Connection, conn, IniKey.Username);
             lnkApiUrl.Text   = WDWebService.BuildApiUrl(conn, service, version);
             Settings.Set(IniSection.State, cboConnections.Name, conn);
             lblPassword.Text = "";
             string password = Settings.Get(IniSection.Connection, conn, IniKey.Password);
             if (!String.IsNullOrEmpty(password))
             {
                 lblPassword.Text = password;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error selecting a connection. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Exemple #2
0
 private void btnGetSOAP_Click(object sender, EventArgs e)
 {
     try
     {
         string xmlData = editor.GetAllText();
         notepad.FileNew();
         editor.SetXML(WDWebService.WrapSOAP("username", "password", xmlData) + Environment.NewLine);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "SOAP Generator Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemple #3
0
 private void cboWWS2_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cboWWS2.SelectedIndex != ListBox.NoMatches && cboConnections.SelectedIndex != ListBox.NoMatches)
     {
         try
         {
             Settings.Set(IniSection.State, cboWWS2.Name, cboWWS2.ReturnValue());
             string conn    = cboConnections.SelectedItem.ToString();
             string service = cboWWS2.ReturnValue();
             lnkApiUrl.Text = WDWebService.BuildApiUrl(conn, service, txtVersion2.Text);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Web Service Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Exemple #4
0
        public static string CallAPI(string username, string password, string url, string xmlData)
        {
            try
            {
                using (var webClient = new WebClient())
                {
                    webClient.Headers.Add("Content-Type", "text/xml; charset=utf-8");
                    ServicePointManager.Expect100Continue = true;
                    ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
                    ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
                    webClient.Credentials = new NetworkCredential(username, password);
                    byte[] data  = Encoding.UTF8.GetBytes(WDWebService.WrapSOAP(username, password, xmlData));
                    byte[] rData = webClient.UploadData(url, data);

                    return(new XDeclaration("1.0", "UTF-8", null).ToString() + Environment.NewLine + XDocument.Parse(Encoding.UTF8.GetString(rData)).ToString() + Environment.NewLine);
                }
            }
            catch (WebException webEx)
            {
                String responseFromServer = webEx.Message.ToString() + Environment.NewLine;
                if (webEx.Response != null)
                {
                    using (WebResponse response = webEx.Response)
                    {
                        Stream dataRs = response.GetResponseStream();
                        using (StreamReader reader = new StreamReader(dataRs))
                        {
                            try
                            {
                                responseFromServer += XDocument.Parse(reader.ReadToEnd());
                            }
                            catch
                            {
                                // ignore exception
                            }
                        }
                    }
                }
                return(responseFromServer);
            }
        }
Exemple #5
0
 private void txtVersion2_TextChanged(object sender, EventArgs e)
 {
     try
     {
         if (String.IsNullOrEmpty(txtVersion2.Text))
         {
             txtVersion2.Text = verDefault;
         }
         Settings.Set(IniSection.WDWebServices, IniKey.Version, txtVersion2.Text);
         if (cboConnections.SelectedIndex != ListBox.NoMatches)
         {
             string conn    = cboConnections.SelectedItem.ToString();
             string service = cboWWS2.ReturnValue();
             lnkApiUrl.Text = WDWebService.BuildApiUrl(conn, service, txtVersion2.Text);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error saving version. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemple #6
0
        private void CallAPI(string data)
        {
            string tenant     = "";
            string username   = "";
            string password   = "";
            string token      = "";
            string serviceURL = "";

            try
            {
                if (radSoap.Checked || radRaaS.Checked)
                {
                    if (String.IsNullOrEmpty(lblPassword.Text))
                    {
                        using (PasswordForm passwordForm = new PasswordForm())
                        {
                            if (passwordForm.ShowDialog() == DialogResult.OK)
                            {
                                lblPassword.Text = Crypto.Protect(passwordForm.Password);
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                }

                tenant     = txtTenant.Text;
                username   = txtUsername.Text + "@" + tenant;
                password   = Crypto.Unprotect(lblPassword.Text);
                token      = txtAccessToken.Text;
                serviceURL = lnkApiUrl.Text;

                try
                {
                    Cursor = Cursors.WaitCursor;
                    notepad.FileNew();
                    if (radSoap.Checked)
                    {
                        editor.SetXML(WDWebService.CallAPI(username, password, lnkApiUrl.Text, data));
                    }
                    else
                    {
                        username = txtUsername.Text;
                        string method = radGet.Text.ToUpper();
                        if (radRaaS.Checked)
                        {
                            token = "";
                        }
                        if (radREST.Checked)
                        {
                            username = "";
                            foreach (RadioButton r in flwRestActions.Controls)
                            {
                                if (r.Checked)
                                {
                                    method = r.Text.ToUpper();
                                }
                            }
                        }
                        if (radGetNoAuth.Checked)
                        {
                            username = "";
                            token    = "";
                        }
                        string result = WDWebService.CallRest(username, password, token, txtRest.Text, method, data);
                        if (!String.IsNullOrEmpty(result))
                        {
                            editor.SetXML(result);
                        }
                    }
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
            }
            catch (Exception ex)
            {
                string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                MessageBox.Show(message, "Web API Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #7
0
        public WDMainForm()
        {
            InitializeComponent();

            try
            {
                Cursor          = Cursors.WaitCursor;
                lblWarning.Text = "";
                // Tool Tips
                toolTip1.SetToolTip(lnkXFormInst, Properties.Resources.Instructions_XForm);
                toolTip1.SetToolTip(lnkInstCallAPI, Properties.Resources.Instructions_CallAPI);
                toolTip1.SetToolTip(lnkApiUrl, Properties.Resources.Instructions_Click2Copy2Clipboard);
                toolTip1.SetToolTip(lnkInstAddlActions, Properties.Resources.Instructions_AdditionalActions);
                tabControl.DrawItem += new DrawItemEventHandler(tabControl_DrawItem);
                // Web Services Download
                string wdWebServicesURL = Settings.Get(IniSection.WDWebServices, IniKey.URL);
                string iniFolder        = Path.GetDirectoryName(Settings.iniFilePath);

                if (!File.Exists(iniFolder + "\\" + wwsFile))
                {
                    try
                    {
                        // Clear any older versions
                        foreach (string file in Directory.GetFiles(iniFolder, wwsFilePart + "*.*"))
                        {
                            File.Delete(file);
                        }
                        wdWebServices = WDWebService.Download(WWSURL);
                        File.WriteAllText(iniFolder + "\\" + wwsFile, JsonSerializer.Serialize(wdWebServices));
                    }
                    finally
                    {
                        Settings.Set(IniSection.WDWebServices, IniKey.URL, WWSURL);
                    }
                }
                else
                {
                    try
                    {
                        wdWebServices = WDWebService.Load(File.ReadAllText(iniFolder + "\\" + wwsFile));
                    }
                    catch (Exception ex)
                    {
                        Settings.Set(IniSection.WDWebServices, IniKey.URL, "");
                    }
                }
                foreach (KeyValuePair <string, string> service in wdWebServices)
                {
                    try
                    {
                        Uri uri = new Uri(service.Key);
                        verDefault = uri.Segments[uri.Segments.Length - 2].Replace("/", "");
                    }
                    catch
                    {
                        // ignore exception
                    }
                    break;
                }

                // Turn Off Event Handling During Init
                this.cboWWS1.SelectedIndexChanged -= new System.EventHandler(this.cboWWS1_SelectedIndexChanged);
                this.cboWWS2.SelectedIndexChanged -= new System.EventHandler(this.cboWWS2_SelectedIndexChanged);
                this.cboXSD.SelectedIndexChanged  -= new System.EventHandler(this.cboXSD_SelectedIndexChanged);
                this.txtVersion1.TextChanged      -= new System.EventHandler(this.txtVersion1_TextChanged);
                this.txtVersion2.TextChanged      -= new System.EventHandler(this.txtVersion2_TextChanged);

                // Web Services
                cboWWS1.DisplayMember = "Value";
                cboWWS1.ValueMember   = "Key";
                cboWWS1.DataSource    = new BindingSource(wdWebServices, null);

                cboWWS2.DisplayMember = "Value";
                cboWWS2.ValueMember   = "Key";
                cboWWS2.DataSource    = new BindingSource(wdWebServices, null);

                // Connections
                ConnectionsLoad();

                // Init
                // Workday Studio Files
                string dir = Settings.Get(IniSection.WDStudio, IniKey.Workspace);
                if (!String.IsNullOrEmpty(dir) && Directory.Exists(dir))
                {
                    txtWDStudioFolder.Text = dir;
                    string filter = Settings.Get(IniSection.WDStudio, IniKey.WorkspaceFilter);
                    if (!String.IsNullOrEmpty(filter))
                    {
                        txtFilter.Text = filter;
                        TreeViewUpdate(txtWDStudioFolder.Text, txtFilter.Text);
                    }
                }
                pnlTreeView.Size = new Size(450, 609);

                // Web Services
                cboWWS1.SelectedIndex = cboWWS1.FindStringExact(Settings.Get(IniSection.State, cboWWS1.Name));
                cboXSD_Load(cboWWS1.ReturnKey());
                cboXSD.SelectedIndex = cboXSD.FindStringExact(Settings.Get(IniSection.State, cboXSD.Name));
                txtVersion1.Text     = Settings.Get(IniSection.WDWebServices, IniKey.Version);
                if (String.IsNullOrEmpty(txtVersion1.Text))
                {
                    txtVersion1.Text = verDefault;
                }

                // API
                cboConnections.SelectedIndex = cboConnections.FindStringExact(Settings.Get(IniSection.State, cboConnections.Name));
                cboWWS2.SelectedIndex        = cboWWS2.FindStringExact(Settings.Get(IniSection.State, cboWWS2.Name));
                txtVersion2.Text             = Settings.Get(IniSection.WDWebServices, IniKey.Version);
                if (cboConnections.SelectedIndex != ListBox.NoMatches && cboWWS2.SelectedIndex != ListBox.NoMatches)
                {
                    string conn    = cboConnections.SelectedItem.ToString();
                    string service = cboWWS2.ReturnValue();
                    lnkApiUrl.Text = WDWebService.BuildApiUrl(conn, service, txtVersion2.Text);
                }
                if (String.IsNullOrEmpty(txtVersion2.Text))
                {
                    txtVersion2.Text = verDefault;
                }

                // Hide Update Tab
                Octokit release           = new Octokit();
                Task <GitHubRelease> task = Task.Run(() => release.GetLatest());
                task.Wait();
                if (task.Result != null & task.Result.Version != null & task.Result.Description != null)
                {
                    txtVersionDescr.Text = task.Result.Version + Environment.NewLine + task.Result.Description;
                }
                if (!task.Result.UpdateAvailable)
                {
                    tabControl.Controls.Remove(tabUpdate);
                }

                // Init as Soap
                radSoap.Checked = true;
                radGet.Checked  = true;

                // Init IntSyst Tab
                txtConnection.Text = cboConnections.SelectedItem.ToString();
                txtTenant2.Text    = txtTenant.Text;
                txtUsername2.Text  = txtUsername.Text;

                // Initial Tab
                string tab = Settings.Get(IniSection.State, tabControl.Name);
                if (!String.IsNullOrEmpty(tab))
                {
                    try
                    {
                        tabControl.SelectTab(tab);
                    }
                    catch
                    {
                        // ignore exception
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "ERP Helper Start", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                // Turn On Event Handling
                this.cboWWS1.SelectedIndexChanged += new System.EventHandler(this.cboWWS1_SelectedIndexChanged);
                this.cboWWS2.SelectedIndexChanged += new System.EventHandler(this.cboWWS2_SelectedIndexChanged);
                this.cboXSD.SelectedIndexChanged  += new System.EventHandler(this.cboXSD_SelectedIndexChanged);
                this.txtVersion1.TextChanged      += new System.EventHandler(this.txtVersion1_TextChanged);
                this.txtVersion2.TextChanged      += new System.EventHandler(this.txtVersion2_TextChanged);
                Cursor = Cursors.Default;
            }
        }