private void SetNamespace(string fileName)
        {
            var ns = VisualStudioAutomationHelper.GetDefaultNamespace(ServiceProvider) + "." +
                     NetNamingMapper.GetObjectName(Path.GetFileNameWithoutExtension(fileName));

            txtNamespace.Text = ns;
        }
        private static string GetFileName(string ramlSource)
        {
            var filename = Path.GetFileName(ramlSource);

            if (string.IsNullOrWhiteSpace(filename))
            {
                filename = NetNamingMapper.GetObjectName(ramlSource) + ".raml";
            }
            return(filename);
        }
        private void SetDefaultClientRootClassName()
        {
            var rootName = NetNamingMapper.GetObjectName(Path.GetFileNameWithoutExtension(RamlTempFilePath));

            if (!rootName.ToLower().Contains("client"))
            {
                rootName += "Client";
            }
            txtClientName.Text = rootName;
        }
Exemple #4
0
        private async void GoButton_Click(object sender, RoutedEventArgs e)
        {
            StartProgress();
            DoEvents();

            try
            {
                var includesManager = new RamlIncludesManager();
                var url             = addressText.Text;
                var result          = includesManager.Manage(url, Path.GetTempPath());

                var raml   = result.ModifiedContents;
                var parser = new RamlParser();

                var ramlDocument = await parser.LoadRamlAsync(raml, Path.GetTempPath());

                var filename = Path.GetFileName(url);

                if (string.IsNullOrEmpty(filename))
                {
                    filename = "reference.raml";
                }

                if (!filename.ToLowerInvariant().EndsWith(RamlFileExtension))
                {
                    filename += RamlFileExtension;
                }

                txtFileName.Text = NetNamingMapper.RemoveIndalidChars(Path.GetFileNameWithoutExtension(filename)) + RamlFileExtension;

                var path = Path.Combine(Path.GetTempPath(), filename);
                File.WriteAllText(path, raml);
                RamlTempFilePath   = path;
                RamlOriginalSource = url;

                SetPreview(ramlDocument);

                btnOk.IsEnabled = true;
                StopProgress();
            }
            catch (UriFormatException uex)
            {
                ShowErrorAndStopProgress(uex.Message);
            }
            catch (HttpRequestException rex)
            {
                ShowErrorAndStopProgress(GetFriendlyMessage(rex));
                ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(rex));
            }
            catch (Exception ex)
            {
                ShowErrorAndStopProgress(ex.Message);
                ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex));
            }
        }
Exemple #5
0
        private void Title_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            btnOk.IsEnabled = false;
            if (string.IsNullOrWhiteSpace(txtTitle.Text))
            {
                return;
            }

            SelectNewRamlOption();
            txtFileName.Text = NetNamingMapper.RemoveIndalidChars(txtTitle.Text) + RamlFileExtension;
            SetNamespace(txtFileName.Text);
            btnOk.IsEnabled = true;
        }
        public static string GetPropertyName(string name)
        {
            var propName = name.Replace(":", string.Empty);

            propName = propName.Replace("/", string.Empty);
            propName = propName.Replace("-", string.Empty);
            propName = NetNamingMapper.Capitalize(propName);

            if (StartsWithNumber(propName))
            {
                propName = "P" + propName;
            }

            return(propName);
        }
        private static string GetFilename(string url)
        {
            var filename = Path.GetFileName(url);

            if (string.IsNullOrEmpty(filename))
            {
                filename = "reference.raml";
            }

            if (!filename.ToLowerInvariant().EndsWith(RamlFileExtension))
            {
                filename += RamlFileExtension;
            }

            filename = NetNamingMapper.RemoveIndalidChars(Path.GetFileNameWithoutExtension(filename)) +
                       RamlFileExtension;
            return(filename);
        }
        private void SetPreview(RamlDocument document)
        {
            Dispatcher.Invoke(() =>
            {
                try
                {
                    ResourcesLabel.Text = GetResourcesPreview(document);
                    StopProgress();
                    btnOk.IsEnabled = true;
                    SetNamespace(RamlTempFilePath);

                    if (NetNamingMapper.HasIndalidChars(txtFileName.Text))
                    {
                        ShowErrorStopProgressAndDisableOk("The specied file name has invalid chars");
                        txtFileName.Focus();
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorStopProgressAndDisableOk("Error while parsing raml file. " + ex.Message);
                    ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex));
                }
            });
        }
 public static string GetNamespace(string title)
 {
     return(NetNamingMapper.Capitalize(NetNamingMapper.RemoveIndalidChars(title)));
 }
 private string GetNamespace(string fileName)
 {
     return(VisualStudioAutomationHelper.GetDefaultNamespace(ServiceProvider) + "." +
            NetNamingMapper.GetObjectName(Path.GetFileNameWithoutExtension(fileName)));
 }