public void SaveButton()
        {
            if (Namespace == null || NetNamingMapper.HasIndalidChars(Namespace))
            {
                MessageBox.Show("Error: invalid namespace.");
                return;
            }
            if (clientName != null && NetNamingMapper.HasIndalidChars(ClientName))
            {
                MessageBox.Show("Error: invalid client name.");
                return;
            }
            if (source != null && NetNamingMapper.HasIndalidChars(source))
            {
                MessageBox.Show("Error: invalid source.");
                return;
            }
            if (HasInvalidPath(ModelsFolder))
            {
                MessageBox.Show("Error: invalid path specified for models. Path must be relative.");
                return;
            }

            if (HasInvalidPath(ImplementationControllersFolder))
            {
                MessageBox.Show("Error: invalid path specified for controllers. Path must be relative.");
                return;
            }


            var ramlProperties = new RamlProperties
            {
                Namespace       = Namespace,
                Source          = Source,
                ClientName      = ClientName,
                UseAsyncMethods = UseAsyncMethods,
                IncludeApiVersionInRoutePrefix = IncludeApiVersionInRoutePrefix,
                ModelsFolder       = ModelsFolder,
                AddGeneratedSuffix = AddGeneratedSuffixToFiles,
                ImplementationControllersFolder = ImplementationControllersFolder
            };

            RamlPropertiesManager.Save(ramlProperties, ramlPath);
            WasSaved = true;
            TryClose();
        }
Пример #2
0
        private void AddFilesToProject(string ramlSourceFile, Project proj, string targetNamespace, string ramlOriginalSource, string targetFileName, string clientRootClassName)
        {
            if (!File.Exists(ramlSourceFile))
            {
                throw new FileNotFoundException("RAML file not found " + ramlSourceFile);
            }

            if (Path.GetInvalidFileNameChars().Any(targetFileName.Contains))
            {
                throw new ArgumentException("Specified filename has invalid chars: " + targetFileName);
            }

            var destFolderName    = Path.GetFileNameWithoutExtension(targetFileName);
            var apiRefsFolderPath = Path.GetDirectoryName(proj.FullName) + Path.DirectorySeparatorChar + ApiReferencesFolderName + Path.DirectorySeparatorChar;
            var destFolderPath    = apiRefsFolderPath + destFolderName + Path.DirectorySeparatorChar;
            var apiRefsFolderItem = VisualStudioAutomationHelper.AddFolderIfNotExists(proj, ApiReferencesFolderName);

            var destFolderItem = VisualStudioAutomationHelper.AddFolderIfNotExists(apiRefsFolderItem, destFolderName, destFolderPath);

            var includesManager = new RamlIncludesManager();
            var result          = includesManager.Manage(ramlOriginalSource, destFolderPath, ramlSourceFile);

            var ramlDestFile = Path.Combine(destFolderPath, targetFileName);

            if (File.Exists(ramlDestFile))
            {
                new FileInfo(ramlDestFile).IsReadOnly = false;
            }
            File.WriteAllText(ramlDestFile, result.ModifiedContents);

            var ramlProjItem = InstallerServices.AddOrUpdateRamlFile(ramlDestFile, destFolderPath, destFolderItem, targetFileName);
            var props        = new RamlProperties
            {
                ClientName = clientRootClassName,
                Source     = ramlOriginalSource,
                Namespace  = targetNamespace
            };
            var refFilePath = InstallerServices.AddRefFile(ramlSourceFile, destFolderPath, targetFileName, props);

            ramlProjItem.ProjectItems.AddFromFile(refFilePath);

            ramlProjItem.Properties.Item("CustomTool").Value = string.Empty; // to cause a refresh when file already exists
            ramlProjItem.Properties.Item("CustomTool").Value = "RamlClientTool";
        }
        protected void AddContractFromFile(ProjectItem folderItem, string folderPath, RamlChooserActionParams parameters)
        {
            var includesFolderPath = folderPath + Path.DirectorySeparatorChar + InstallerServices.IncludesFolderName;

            var includesManager = new RamlIncludesManager();
            var result          = includesManager.Manage(parameters.RamlSource, includesFolderPath, confirmOverrite: true, rootRamlPath: folderPath + Path.DirectorySeparatorChar);

            ManageIncludes(folderItem, result);

            var ramlProjItem = AddOrUpdateRamlFile(result.ModifiedContents, folderItem, folderPath, parameters.TargetFileName);

            InstallerServices.RemoveSubItemsAndAssociatedFiles(ramlProjItem);

            var targetFolderPath = GetTargetFolderPath(folderPath, parameters.TargetFileName);

            RamlProperties props       = Map(parameters);
            var            refFilePath = InstallerServices.AddRefFile(parameters.RamlFilePath, targetFolderPath, parameters.TargetFileName, props);

            ramlProjItem.ProjectItems.AddFromFile(refFilePath);

            Scaffold(ramlProjItem.FileNames[0], parameters);
        }
Пример #4
0
        private void AddContractFromFile(ProjectItem folderItem, string folderPath, RamlChooserActionParams parameters)
        {
            var includesFolderPath = folderPath + Path.DirectorySeparatorChar + InstallerServices.IncludesFolderName;

            var includesManager = new RamlIncludesManager();
            var result          = includesManager.Manage(parameters.RamlSource, includesFolderPath, confirmOverrite: true, rootRamlPath: folderPath + Path.DirectorySeparatorChar);

            var includesFolderItem = folderItem.ProjectItems.Cast <ProjectItem>().FirstOrDefault(i => i.Name == InstallerServices.IncludesFolderName);

            if (includesFolderItem == null && !VisualStudioAutomationHelper.IsAVisualStudio2015Project(folderItem.ContainingProject))
            {
                includesFolderItem = folderItem.ProjectItems.AddFolder(InstallerServices.IncludesFolderName);
            }

            foreach (var file in result.IncludedFiles)
            {
                if (!VisualStudioAutomationHelper.IsAVisualStudio2015Project(folderItem.ContainingProject) || !File.Exists(file))
                {
                    includesFolderItem.ProjectItems.AddFromFile(file);
                }
            }

            //var existingIncludeItems = includesFolderItem.ProjectItems.Cast<ProjectItem>();
            //var oldIncludedFiles = existingIncludeItems.Where(item => !result.IncludedFiles.Contains(item.FileNames[0]));
            //InstallerServices.RemoveSubItemsAndAssociatedFiles(oldIncludedFiles);

            var ramlProjItem = AddOrUpdateRamlFile(result.ModifiedContents, folderItem, folderPath, parameters.TargetFileName);

            InstallerServices.RemoveSubItemsAndAssociatedFiles(ramlProjItem);

            var targetFolderPath = GetTargetFolderPath(folderPath, parameters.TargetFileName, folderItem.ContainingProject);

            RamlProperties props       = Map(parameters);
            var            refFilePath = InstallerServices.AddRefFile(parameters.RamlFilePath, targetFolderPath, parameters.TargetFileName, props);

            ramlProjItem.ProjectItems.AddFromFile(refFilePath);

            Scaffold(ramlProjItem.FileNames[0], parameters);
        }