コード例 #1
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 ramlProjItem = InstallerServices.AddOrUpdateRamlFile(ramlSourceFile, destFolderPath, destFolderItem, targetFileName);
            var refFilePath  = InstallerServices.AddRefFile(ramlSourceFile, targetNamespace, ramlOriginalSource, destFolderPath, targetFileName, null, clientRootClassName);

            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";
        }
コード例 #2
0
        private void AddContractFromFile(string ramlFilePath, string targetNamespace, string ramlSource, bool?doNotScaffold, ProjectItem folderItem, string folderPath, string targetFilename)
        {
            InstallerServices.AddRefFile(ramlFilePath, targetNamespace, ramlSource, folderPath, targetFilename);

            var includesFolderPath = folderPath + Path.DirectorySeparatorChar + InstallerServices.IncludesFolderName;

            var includesManager = new RamlIncludesManager();
            var result          = includesManager.Manage(ramlSource, includesFolderPath, confirmOverrite: true);

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

            if (includesFolderItem == null)
            {
                includesFolderItem = folderItem.ProjectItems.AddFolder(InstallerServices.IncludesFolderName);
            }

            foreach (var file in result.IncludedFiles)
            {
                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, Path.GetFileName(ramlFilePath));

            InstallerServices.RemoveSubItemsAndAssociatedFiles(ramlProjItem);

            if (doNotScaffold == null || !doNotScaffold.Value)
            {
                Scaffold(ramlSource, targetNamespace, Path.GetFileName(ramlFilePath));
            }
        }
コード例 #3
0
        private void AddEmptyContract(string filename, string title, ProjectItem folderItem, string folderPath, string targetNamespace, string targetFilename)
        {
            var newContractFile = Path.Combine(folderPath, filename);
            var contents        = CreateNewRamlContents(title);

            InstallerServices.AddRefFile(newContractFile, targetNamespace, newContractFile, folderPath, targetFilename);

            if (File.Exists(newContractFile))
            {
                var dialogResult = InstallerServices.ShowConfirmationDialog(filename);
                if (dialogResult == MessageBoxResult.Yes)
                {
                    File.WriteAllText(newContractFile, contents);
                    folderItem.ProjectItems.AddFromFile(newContractFile);
                }
                else
                {
                    var item = folderItem.ProjectItems.Cast <ProjectItem>().FirstOrDefault(i => i.Name == newContractFile);
                    if (item == null)
                    {
                        folderItem.ProjectItems.AddFromFile(newContractFile);
                    }
                }
            }
            else
            {
                File.WriteAllText(newContractFile, contents);
                folderItem.ProjectItems.AddFromFile(newContractFile);
            }
        }
コード例 #4
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";
        }
コード例 #5
0
        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);
        }
コード例 #6
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);
        }
コード例 #7
0
        protected void AddEmptyContract(ProjectItem folderItem, string folderPath, RamlChooserActionParams parameters)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var newContractFile = Path.Combine(folderPath, parameters.TargetFileName);
            var contents        = CreateNewRamlContents(parameters.RamlTitle);

            ProjectItem ramlProjItem;

            if (File.Exists(newContractFile))
            {
                var dialogResult = InstallerServices.ShowConfirmationDialog(parameters.TargetFileName);
                if (dialogResult == MessageBoxResult.Yes)
                {
                    File.WriteAllText(newContractFile, contents);
                    ramlProjItem = folderItem.ProjectItems.AddFromFile(newContractFile);
                }
                else
                {
#pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
                    ramlProjItem = folderItem.ProjectItems.Cast <ProjectItem>().FirstOrDefault(i => i.Name == newContractFile);
#pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread
                    if (ramlProjItem == null)
                    {
                        ramlProjItem = folderItem.ProjectItems.AddFromFile(newContractFile);
                    }
                }
            }
            else
            {
                File.WriteAllText(newContractFile, contents);
                ramlProjItem = folderItem.ProjectItems.AddFromFile(newContractFile);
            }

            var props            = Map(parameters);
            var targetFolderPath = GetTargetFolderPath(folderPath, parameters.TargetFileName);
            var refFilePath      = InstallerServices.AddRefFile(newContractFile, targetFolderPath, parameters.TargetFileName, props);
            ramlProjItem.ProjectItems.AddFromFile(refFilePath);
        }
コード例 #8
0
        protected void AddEmptyContract(ProjectItem folderItem, string folderPath, RamlChooserActionParams parameters)
        {
            var newContractFile = Path.Combine(folderPath, parameters.TargetFileName);
            var contents        = CreateNewRamlContents(parameters.RamlTitle);

            ProjectItem ramlProjItem;

            if (File.Exists(newContractFile))
            {
                var dialogResult = InstallerServices.ShowConfirmationDialog(parameters.TargetFileName);
                if (dialogResult == MessageBoxResult.Yes)
                {
                    File.WriteAllText(newContractFile, contents);
                    ramlProjItem = folderItem.ProjectItems.AddFromFile(newContractFile);
                }
                else
                {
                    ramlProjItem = folderItem.ProjectItems.Cast <ProjectItem>().FirstOrDefault(i => i.Name == newContractFile);
                    if (ramlProjItem == null)
                    {
                        ramlProjItem = folderItem.ProjectItems.AddFromFile(newContractFile);
                    }
                }
            }
            else
            {
                File.WriteAllText(newContractFile, contents);
                ramlProjItem = folderItem.ProjectItems.AddFromFile(newContractFile);
            }

            var props            = Map(parameters);
            var targetFolderPath = GetTargetFolderPath(folderPath, parameters.TargetFileName);
            var refFilePath      = InstallerServices.AddRefFile(newContractFile, targetFolderPath, parameters.TargetFileName, props);

            ramlProjItem.ProjectItems.AddFromFile(refFilePath);
        }