public override void GenerateCode(RamlInfo data, Project proj, string targetNamespace, string clientRootClassName,
                                          string apiRefsFolderPath, string ramlDestFile, string destFolderPath, string destFolderName, ProjectItem ramlProjItem)
        {
            //ramlProjItem.Properties.Item("CustomTool").Value = string.Empty; // to cause a refresh when file already exists
            //ramlProjItem.Properties.Item("CustomTool").Value = "RamlClientTool";

            var model          = new ClientGeneratorService(data.RamlDocument, clientRootClassName, targetNamespace, targetNamespace + ".Models").BuildModel();
            var directoryName  = Path.GetDirectoryName(ramlDestFile).TrimEnd(Path.DirectorySeparatorChar);
            var templateFolder = directoryName.Substring(0, directoryName.LastIndexOf(Path.DirectorySeparatorChar)) +
                                 Path.DirectorySeparatorChar + "Templates" + Path.DirectorySeparatorChar;

            var templateFilePath = Path.Combine(templateFolder, ClientT4TemplateName);
            var extensionPath    = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar;

            TemplatesManager.CopyClientTemplateToProjectFolder(apiRefsFolderPath, "Client");

            var t4Service = new T4Service(ServiceProvider);
            var res       = t4Service.TransformText(templateFilePath, model, extensionPath, ramlDestFile, targetNamespace);

            if (res.HasErrors)
            {
                ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, res.Errors);
                MessageBox.Show(res.Errors);
            }
            else
            {
                var content      = TemplatesManager.AddClientMetadataHeader(res.Content);
                var csTargetFile = Path.Combine(destFolderPath, destFolderName + ".cs");
                File.WriteAllText(csTargetFile, content);
                ramlProjItem.ProjectItems.AddFromFile(csTargetFile);
            }
        }
Exemplo n.º 2
0
        public void GenerateCode(RamlInfo data, string targetNamespace, string clientRootClassName, string ramlDestFile, string destFolderPath,
                                 string destFolderName, ProjectItem ramlProjItem)
        {
            //var ramlInfo = await RamlInfoService.GetRamlInfo(ramlDestFile);
            //if (ramlInfo.HasErrors)
            //{
            //    ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, ramlInfo.ErrorMessage);
            //    MessageBox.Show(ramlInfo.ErrorMessage);
            //    return;
            //}

            var model          = new ClientGeneratorService(data.RamlDocument, clientRootClassName, targetNamespace, targetNamespace + ".Models").BuildModel();
            var directoryName  = Path.GetDirectoryName(ramlDestFile).TrimEnd(Path.DirectorySeparatorChar);
            var templateFolder = directoryName.Substring(0, directoryName.LastIndexOf(Path.DirectorySeparatorChar)) +
                                 Path.DirectorySeparatorChar + "Templates" + Path.DirectorySeparatorChar;

            var templateFilePath = Path.Combine(templateFolder, ClientT4TemplateName);
            var extensionPath    = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar;
            var t4Service        = new T4Service(ServiceProvider);
            var res = t4Service.TransformText(templateFilePath, model, extensionPath, ramlDestFile, targetNamespace);

            if (res.HasErrors)
            {
                ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, res.Errors);
                MessageBox.Show(res.Errors);
                return;
            }

            var content      = TemplatesManager.AddClientMetadataHeader(res.Content);
            var csTargetFile = Path.Combine(destFolderPath, destFolderName + ".cs");

            File.WriteAllText(csTargetFile, content);
            ramlProjItem.ProjectItems.AddFromFile(csTargetFile);
        }
Exemplo n.º 3
0
 public override void GenerateCode(RamlInfo data, Project proj, string targetNamespace, string clientRootClassName, string apiRefsFolderPath,
                                   string ramlDestFile, string destFolderPath, string destFolderName, ProjectItem ramlProjItem)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     TemplatesManager.CopyClientTemplateToProjectFolder(apiRefsFolderPath, "ClientCore");
     GenerateCode(data, targetNamespace, clientRootClassName, ramlDestFile, destFolderPath, destFolderName, ramlProjItem);
 }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private async void Execute(object sender, EventArgs e)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            await ChangeCommandStatusAsync(menuCommandID, false);

            // Get the file path
            uint         itemid;
            IVsHierarchy hierarchy;

            if (!IsSingleProjectItemSelection(out hierarchy, out itemid))
            {
                return;
            }
            string ramlFilePath;

            ((IVsProject)hierarchy).GetMkDocument(itemid, out ramlFilePath);

            var refFilePath = InstallerServices.GetRefFilePath(ramlFilePath);


            var editorModel = new RamlPropertiesEditorViewModel();

            editorModel.Load(refFilePath, RAML.Tools.Properties.Settings.Default.ContractsFolderName, RAML.Tools.Properties.Settings.Default.ApiReferencesFolderName);
            AMFToolsPackage.WindowManager.ShowDialog(editorModel);

            //var frm = new RamlPropertiesEditor();
            //frm.Load(refFilePath, RAML.Tools.Properties.Settings.Default.ContractsFolderName, RAML.Tools.Properties.Settings.Default.ApiReferencesFolderName);
            //var result = frm.ShowDialog();
            if (editorModel.WasSaved)
            {
                if (IsServerSide(ramlFilePath))
                {
                    var ramlScaffoldUpdater = RamlScaffoldServiceBase.GetRamlScaffoldService(Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider);
                    ramlScaffoldUpdater.UpdateRaml(ramlFilePath);
                }
                else
                {
                    var templatesManager    = new TemplatesManager();
                    var ramlFolder          = Path.GetDirectoryName(ramlFilePath).TrimEnd(Path.DirectorySeparatorChar);
                    var generatedFolderPath = ramlFolder.Substring(0, ramlFolder.LastIndexOf(Path.DirectorySeparatorChar) + 1);
                    if (!templatesManager.ConfirmWhenIncompatibleClientTemplate(generatedFolderPath))
                    {
                        return;
                    }

                    await RegenerateClientCodeAsync(ramlFilePath);
                }
            }

            await ChangeCommandStatusAsync(menuCommandID, true);
        }
Exemplo n.º 5
0
        public void GenerateCode(RamlInfo data, string targetNamespace, string clientRootClassName, string ramlDestFile, string destFolderPath,
                                 string destFolderName, ProjectItem ramlProjItem)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            //var ramlInfo = await RamlInfoService.GetRamlInfo(ramlDestFile);
            //if (ramlInfo.HasErrors)
            //{
            //    ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, ramlInfo.ErrorMessage);
            //    MessageBox.Show(ramlInfo.ErrorMessage);
            //    return;
            //}

            var model          = new ClientGeneratorService(data.RamlDocument, clientRootClassName, targetNamespace, targetNamespace + ".Models").BuildModel();
            var directoryName  = Path.GetDirectoryName(ramlDestFile).TrimEnd(Path.DirectorySeparatorChar);
            var templateFolder = directoryName.Substring(0, directoryName.LastIndexOf(Path.DirectorySeparatorChar)) +
                                 Path.DirectorySeparatorChar + "Templates" + Path.DirectorySeparatorChar;

            var templateFilePath = Path.Combine(templateFolder, ClientT4TemplateName);
            var extensionPath    = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar;

            // when array has no properties, set it collection on base type
            foreach (var arrayModel in model.Objects.Where(o => o.IsArray && o.Properties.Count == 0 && o.Type != null &&
                                                           CollectionTypeHelper.IsCollection(o.Type) && !NewNetTypeMapper.IsPrimitiveType(CollectionTypeHelper.GetBaseType(o.Type))))
            {
                arrayModel.BaseClass = arrayModel.Type.Substring(1); // remove the initil "I" to make it a concrete class
            }

            var t4Service = new T4Service(ServiceProvider);
            var res       = t4Service.TransformText(templateFilePath, model, extensionPath, ramlDestFile, targetNamespace);

            if (res.HasErrors)
            {
                ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, res.Errors);
                MessageBox.Show(res.Errors);
                return;
            }

            var content      = TemplatesManager.AddClientMetadataHeader(res.Content);
            var csTargetFile = Path.Combine(destFolderPath, destFolderName + ".cs");

            File.WriteAllText(csTargetFile, content);
            ramlProjItem.ProjectItems.AddFromFile(csTargetFile);
        }