private void UpdateRamlRefCallback(object sender, EventArgs e)
        {
            ChangeCommandStatus(updateReferenceCmdId, 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 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;
            }

            RegenerateClientCode(ramlFilePath);

            ChangeCommandStatus(updateReferenceCmdId, true);
        }
Esempio n. 2
0
        private void GenerateCode(string targetNamespace, string clientRootClassName, string ramlDestFile, string destFolderPath,
                                  string destFolderName)
        {
            var ramlInfo = RamlInfoService.GetRamlInfo(ramlDestFile);

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

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

            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);
        }
        private void EditRamlPropertiesCallback(object sender, EventArgs e)
        {
            ChangeCommandStatus(editRamlPropertiesCmdId, 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, Settings.Default.ContractsFolderName, Settings.Default.ApiReferencesFolderName);
            windowManager.ShowDialog(editorModel);

            //var frm = new RamlPropertiesEditor();
            //frm.Load(refFilePath, Settings.Default.ContractsFolderName, Settings.Default.ApiReferencesFolderName);
            //var result = frm.ShowDialog();
            if (editorModel.WasSaved)
            {
                if (IsServerSide(ramlFilePath))
                {
                    var ramlScaffoldUpdater = new RamlScaffoldService(new T4Service(ServiceProvider.GlobalProvider), 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;
                    }

                    var dte = (DTE2)GetService(typeof(SDTE));
                    dte.ExecuteCommand("Project.RunCustomTool");
                }
            }

            ChangeCommandStatus(editRamlPropertiesCmdId, true);
        }
        private void UpdateRamlRefCallback(object sender, EventArgs e)
        {
            ChangeCommandStatus(updateReferenceCmdId, 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 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;
            }

            //if (Unauthorized(ramlFilePath))
            //{
            //    var generationServices = new RamlReferenceService(ServiceProvider.GlobalProvider);
            //    var ramlChooser = new RamlChooser(this, generationServices.AddRamlReference, "Update RAML Reference", false,
            //        Settings.Default.RAMLExchangeUrl);
            //    ramlChooser.ShowDialog();
            //}
            //else
            //{
            var dte = (DTE2)GetService(typeof(SDTE));

            dte.ExecuteCommand("Project.RunCustomTool");
            //}

            ChangeCommandStatus(updateReferenceCmdId, true);
        }
Esempio n. 5
0
 protected override void GenerateCode(Project proj, string targetNamespace, string clientRootClassName, string apiRefsFolderPath,
                                      string ramlDestFile, string destFolderPath, string destFolderName, ProjectItem ramlProjItem)
 {
     TemplatesManager.CopyClientTemplateToProjectFolder(apiRefsFolderPath);
     GenerateCode(targetNamespace, clientRootClassName, ramlDestFile, destFolderPath, destFolderName);
 }
        private void UpdateRamlRefCallback(object sender, EventArgs e)
        {
            ChangeCommandStatus(updateReferenceCmdId, 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 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;

            //if (Unauthorized(ramlFilePath))
            //{
            //    var generationServices = new RamlReferenceService(ServiceProvider.GlobalProvider);
            //    var ramlChooser = new RamlChooser(this, generationServices.AddRamlReference, "Update RAML Reference", false,
            //        Settings.Default.RAMLExchangeUrl);
            //    ramlChooser.ShowDialog();
            //}
            //else
            //{
            var dte = (DTE2)GetService(typeof(SDTE));
            dte.ExecuteCommand("Project.RunCustomTool");
            //}

            ChangeCommandStatus(updateReferenceCmdId, true);
        }
        private void EditRamlPropertiesCallback(object sender, EventArgs e)
        {
            ChangeCommandStatus(editRamlPropertiesCmdId, 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 frm = new RamlPropertiesEditor();
            frm.Load(refFilePath, Settings.Default.ContractsFolderName, Settings.Default.ApiReferencesFolderName);
            var result = frm.ShowDialog();
            if (result != null && result.Value)
            {

                if (IsServerSide(ramlFilePath))
                {
                    var ramlScaffoldUpdater = new RamlScaffoldService(new T4Service(ServiceProvider.GlobalProvider), 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;

                    var dte = (DTE2)GetService(typeof(SDTE));
                    dte.ExecuteCommand("Project.RunCustomTool");
                }
            }

            ChangeCommandStatus(editRamlPropertiesCmdId, true);
        }