private bool IsServiceValid(string url)
        {
            GeneratorOptions details = new GeneratorOptions();

            if ((bool)UseCredentialsCheckBox.IsChecked)
            {
                details.Username = UsernameTextBox.Text;
                details.Password = passwordTextBox.Password;
            }
            try
            {
                var valid = GeneratorService.GetEpicorServices(url, details);
                if (valid.Workspace != null && valid.Workspace.Collection != null && valid.Workspace.Collection.Count() == 0)
                {
                    MessageBox.Show("Service is invalid");
                    return(false);
                }
            }
            catch (WebException ex)
            {
                if (ex.Response != null)
                {
                    using (WebResponse response = ex.Response)
                    {
                        HttpWebResponse httpResponse = (HttpWebResponse)response;
                        MessageBox.Show(string.Format("Error code: {0}", httpResponse.StatusDescription));
                        string text = "";
                        using (Stream data = response.GetResponseStream())
                            using (var reader = new StreamReader(data))
                            {
                                // text is the response body
                                text = reader.ReadToEnd();
                            }
                        MessageBox.Show(text);
                        return(false);
                    }
                }
                else
                {
                    MessageBox.Show(ex.Message);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
            return(true);
        }
        private void PopulateService(TextBox textBox, ListBox listBox, string type)
        {
            if (string.IsNullOrWhiteSpace(textBox.Text))
            {
                MessageBox.Show("Services URL is Required");
            }
            if (!IsServiceValid(textBox.Text))
            {
                return;
            }

            GeneratorOptions details = new GeneratorOptions();

            if ((bool)UseCredentialsCheckBox.IsChecked)
            {
                details.Username = UsernameTextBox.Text;
                details.Password = passwordTextBox.Password;
            }

            generatorService = GeneratorService.GetEpicorServices(textBox.Text, details);
            generatorService.Workspace.Collection = generatorService.Workspace.Collection
                                                    .Where(o => o.Href.ToUpper().StartsWith(type)).ToArray <ServiceWorkspaceCollection>();
            listBox.ItemsSource = generatorService.Workspace.Collection.Select(o => o.Href);

            try
            {
                var files = Directory.EnumerateFiles(Path.GetDirectoryName(ERPProjectTextBox.Text), "*.cs");
                foreach (var file in files)
                {
                    var filename = System.IO.Path.GetFileNameWithoutExtension(file);
                    if (listBox.Items.Contains(filename))
                    {
                        listBox.SelectedItems.Add(listBox.Items[listBox.Items.IndexOf(filename)]);
                    }
                }
            }
            catch (Exception ex)
            {
                var error = ex;
                // TODO Log this exception instead of throwing it away
            }
        }