public void UpdateProjectConfiguration(IProjectConfiguraiton projectConfiguration, IProjectManager projectManager)
        {
            ProjectItems serverMethods = projectManager.ServerMethodFolderItems;

            if (serverMethods.Count == 0)
            {
                projectConfiguration.MethodInfos.Clear();
                return;
            }

            var updatedMethodInfos = new List <MethodInfo>();

            foreach (MethodInfo methodInfo in projectConfiguration.MethodInfos)
            {
                if (!projectManager.IsMethodExist(methodInfo.Package.MethodFolderPath, methodInfo.MethodName))
                {
                    continue;
                }

                MethodInfo updatedMethodInfo;
                if (methodInfo is PackageMethodInfo)
                {
                    updatedMethodInfo = new PackageMethodInfo((PackageMethodInfo)methodInfo);
                }
                else
                {
                    updatedMethodInfo = new MethodInfo(methodInfo);
                }

                updatedMethodInfos.Add(updatedMethodInfo);
            }

            projectConfiguration.MethodInfos = updatedMethodInfos;
        }
        public override void ExecuteCommandImpl(object sender, EventArgs args)
        {
            TemplateLoader templateLoader = new TemplateLoader();

            templateLoader.Load(projectManager.MethodConfigPath);

            var packageManager = new PackageManager(authManager, this.messageManager);

            string     selectedMethodPath = projectManager.MethodPath;
            string     selectedMethodName = Path.GetFileNameWithoutExtension(selectedMethodPath);
            MethodInfo methodInformation  = projectConfigurationManager.CurrentProjectConfiguraiton.MethodInfos.FirstOrDefault(m => m.MethodName == selectedMethodName);

            if (methodInformation == null)
            {
                throw new Exception();
            }

            string manifastFileName;

            if (methodInformation is PackageMethodInfo)
            {
                PackageMethodInfo packageMethodInfo = (PackageMethodInfo)methodInformation;
                manifastFileName = packageMethodInfo.ManifestFileName;
            }
            else
            {
                manifastFileName = "imports.mf";
            }

            string packageMethodFolderPath = this.projectConfigurationManager.CurrentProjectConfiguraiton.UseCommonProjectStructure ? methodInformation.Package.MethodFolderPath : string.Empty;
            string methodWorkingFolder     = Path.Combine(projectManager.ServerMethodFolderPath, packageMethodFolderPath, methodInformation.MethodName);

            ICodeProvider codeProvider = codeProviderFactory.GetCodeProvider(projectManager.Language);

            string   sourceCode   = File.ReadAllText(selectedMethodPath, new UTF8Encoding(true));
            CodeInfo codeItemInfo = codeProvider.UpdateSourceCodeToInsertExternalItems(methodWorkingFolder, sourceCode, methodInformation, projectConfigurationManager.CurrentProjectConfiguraiton.UseVSFormatting);

            if (codeItemInfo != null)
            {
                var dialogResult = dialogFactory.GetMessageBoxWindow().ShowDialog(messageManager.GetMessage("CouldNotInsertExternalItemsInsideOfMethodCodeSection"),
                                                                                  messageManager.GetMessage("ArasVSMethodPlugin"),
                                                                                  MessageButtons.OKCancel,
                                                                                  MessageIcon.Question);
                if (dialogResult == MessageDialogResult.Cancel)
                {
                    return;
                }

                projectManager.AddItemTemplateToProjectNew(codeItemInfo, packageMethodFolderPath, true, 0);
                sourceCode = codeItemInfo.Code;
            }

            var saveView       = dialogFactory.GetSaveToPackageView(projectConfigurationManager.CurrentProjectConfiguraiton, templateLoader, packageManager, codeProvider, projectManager, methodInformation, sourceCode);
            var saveViewResult = saveView.ShowDialog();

            if (saveViewResult?.DialogOperationResult != true)
            {
                return;
            }

            string pathPackageToSaveMethod;
            string rootPath       = saveViewResult.PackagePath;
            string importFilePath = Path.Combine(rootPath, manifastFileName);

            if (File.Exists(importFilePath))
            {
                var xmlDocument = new XmlDocument();
                xmlDocument.Load(importFilePath);
                XmlNode importsXmlNode = xmlDocument.SelectSingleNode("imports");
                XmlNode packageXmlNode = importsXmlNode.SelectSingleNode($"package[@name='{saveViewResult.SelectedPackage}']");

                if (packageXmlNode == null)
                {
                    XmlElement packageXmlElement = xmlDocument.CreateElement("package");
                    packageXmlElement.SetAttribute("name", saveViewResult.SelectedPackage.Name);
                    packageXmlElement.SetAttribute("path", saveViewResult.SelectedPackage.Path);
                    importsXmlNode.AppendChild(packageXmlElement);

                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Encoding           = new UTF8Encoding(true);
                    settings.Indent             = true;
                    settings.IndentChars        = "\t";
                    settings.OmitXmlDeclaration = true;
                    using (XmlWriter xmlWriter = XmlWriter.Create(importFilePath, settings))
                    {
                        xmlDocument.Save(xmlWriter);
                    }
                }
                else
                {
                    pathPackageToSaveMethod = packageXmlNode.Attributes["path"].Value;
                }
            }
            else
            {
                var        xmlDocument       = new XmlDocument();
                XmlElement importsXmlNode    = xmlDocument.CreateElement("imports");
                XmlElement packageXmlElement = xmlDocument.CreateElement("package");
                packageXmlElement.SetAttribute("name", saveViewResult.SelectedPackage.Name);
                packageXmlElement.SetAttribute("path", saveViewResult.SelectedPackage.Path);
                importsXmlNode.AppendChild(packageXmlElement);
                xmlDocument.AppendChild(importsXmlNode);

                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent             = true;
                settings.IndentChars        = "\t";
                settings.OmitXmlDeclaration = true;
                settings.Encoding           = new UTF8Encoding(true);
                using (XmlWriter xmlWriter = XmlWriter.Create(importFilePath, settings))
                {
                    xmlDocument.Save(xmlWriter);
                }
            }

            string methodPath = Path.Combine(rootPath, saveViewResult.SelectedPackage.MethodFolderPath);

            Directory.CreateDirectory(methodPath);

            string methodId       = null;
            string methodFilePath = Path.Combine(methodPath, $"{saveViewResult.MethodName}.xml");

            if (File.Exists(methodFilePath))
            {
                var methodXmlDocument = new XmlDocument();
                methodXmlDocument.Load(methodFilePath);
                methodId = methodXmlDocument.SelectSingleNode("/AML/Item/@id").InnerText;
            }
            else
            {
                methodId = saveViewResult.MethodInformation.InnovatorMethodConfigId;
            }

            string updateMethodCodeForSavingToAmlPackage = saveViewResult.MethodCode.Replace("]]>", "]]]]><![CDATA[>");
            string methodTemplate = $@"<AML>
 <Item type=""Method"" id=""{methodId}"" action=""add"">" +
                                    (!string.IsNullOrWhiteSpace(saveViewResult.MethodComment) ? $"<comments>{saveViewResult.MethodComment}</comments>" : "") +
                                    $@"<execution_allowed_to keyed_name=""{saveViewResult.SelectedIdentityKeyedName}"" type=""Identity"">{saveViewResult.SelectedIdentityId}</execution_allowed_to>
  <method_code><![CDATA[{updateMethodCodeForSavingToAmlPackage}]]></method_code>
  <method_type>{saveViewResult.MethodInformation.MethodLanguage}</method_type>
  <name>{saveViewResult.MethodName}</name>
 </Item>
</AML>";

            XmlDocument resultXmlDoc = new XmlDocument();

            resultXmlDoc.LoadXml(methodTemplate);
            SaveToFile(methodFilePath, resultXmlDoc);

            if (methodInformation.MethodName == saveViewResult.MethodName &&
                methodInformation.Package.Name == saveViewResult.SelectedPackage.Name)
            {
                methodInformation.Package = saveViewResult.SelectedPackage;
                methodInformation.ExecutionAllowedToKeyedName = saveViewResult.SelectedIdentityKeyedName;
                methodInformation.ExecutionAllowedToId        = saveViewResult.SelectedIdentityId;
                methodInformation.MethodComment = saveViewResult.MethodComment;
            }

            projectConfigurationManager.CurrentProjectConfiguraiton.LastSelectedDir = rootPath;
            projectConfigurationManager.Save(projectManager.ProjectConfigPath);

            // Show a message box to prove we were here
            var messageWindow = dialogFactory.GetMessageBoxWindow();

            messageWindow.ShowDialog(this.messageManager.GetMessage("MethodSavedToPackage", saveViewResult.MethodName, saveViewResult.SelectedPackage.Name),
                                     string.Empty,
                                     MessageButtons.OK,
                                     MessageIcon.Information);
        }
Exemple #3
0
 public PackageMethodInfo(PackageMethodInfo packageMethodInfo) : base(packageMethodInfo)
 {
     this.ManifestFileName = packageMethodInfo.ManifestFileName;
 }
Exemple #4
0
        public override void ExecuteCommandImpl(object sender, EventArgs args)
        {
            var project = projectManager.SelectedProject;

            string projectConfigPath = projectManager.ProjectConfigPath;
            string methodConfigPath  = projectManager.MethodConfigPath;

            var           projectConfiguration = projectConfigurationManager.Load(projectConfigPath);
            ICodeProvider codeProvider         = codeProviderFactory.GetCodeProvider(project.CodeModel.Language, projectConfiguration);

            var templateLoader = new TemplateLoader(this.dialogFactory);

            templateLoader.Load(methodConfigPath);

            var openView = dialogFactory.GetOpenFromPackageView(templateLoader, codeProvider.Language, projectConfiguration);

            var openViewResult = openView.ShowDialog();

            if (openViewResult?.DialogOperationResult != true)
            {
                return;
            }

            MethodInfo methodInformation = projectConfiguration.MethodInfos.FirstOrDefault(m => m.MethodName == openViewResult.MethodName);
            bool       isMethodExist     = projectManager.IsMethodExist(openViewResult.MethodName);

            if (projectManager.IsMethodExist(openViewResult.MethodName))
            {
                var messageWindow = this.dialogFactory.GetMessageBoxWindow();
                var dialogReuslt  = messageWindow.ShowDialog("Method already added to project. Do you want replace method?",
                                                             "Warning",
                                                             MessageButtons.YesNo,
                                                             MessageIcon.None);

                if (dialogReuslt == MessageDialogResult.Yes)
                {
                    projectManager.RemoveMethod(methodInformation);
                    projectConfiguration.MethodInfos.Remove(methodInformation);
                }
                else
                {
                    return;
                }
            }

            GeneratedCodeInfo codeInfo = codeProvider.GenerateCodeInfo(openViewResult.SelectedTemplate, openViewResult.SelectedEventSpecificData, openViewResult.MethodName, false, openViewResult.MethodCode, openViewResult.IsUseVSFormattingCode);

            projectManager.CreateMethodTree(codeInfo);

            var methodInfo = new PackageMethodInfo()
            {
                InnovatorMethodConfigId = openViewResult.MethodConfigId,
                InnovatorMethodId       = openViewResult.MethodId,
                MethodLanguage          = openViewResult.MethodLanguage,
                MethodName                  = openViewResult.MethodName,
                MethodType                  = openViewResult.MethodType,
                MethodComment               = openViewResult.MethodComment,
                PackageName                 = openViewResult.Package,
                TemplateName                = openViewResult.SelectedTemplate.TemplateName,
                EventData                   = openViewResult.SelectedEventSpecificData.EventSpecificData,
                ExecutionAllowedToId        = openViewResult.IdentityId,
                ExecutionAllowedToKeyedName = openViewResult.IdentityKeyedName,
                PartialClasses              = codeInfo.PartialCodeInfoList.Select(pci => pci.Path).ToList(),
                ExternalItems               = codeInfo.ExternalItemsInfoList.Select(pci => pci.Path).ToList(),
                ManifestFileName            = openViewResult.SelectedManifestFileName
            };

            projectConfiguration.LastSelectedDir    = openViewResult.SelectedFolderPath;
            projectConfiguration.LastSelectedMfFile = openViewResult.SelectedManifestFullPath;
            projectConfiguration.UseVSFormatting    = openViewResult.IsUseVSFormattingCode;
            projectConfiguration.LastSelectedSearchTypeInOpenFromPackage = openViewResult.SelectedSearchType;
            projectConfiguration.AddMethodInfo(methodInfo);
            projectConfigurationManager.Save(projectConfigPath, projectConfiguration);
        }
        public override void ExecuteCommandImpl(object sender, EventArgs args)
        {
            ICodeProvider codeProvider = codeProviderFactory.GetCodeProvider(projectManager.Language);

            TemplateLoader templateLoader = new TemplateLoader();

            templateLoader.Load(projectManager.MethodConfigPath);

            var openView       = dialogFactory.GetOpenFromPackageView(templateLoader, codeProvider.Language, projectConfigurationManager.CurrentProjectConfiguraiton);
            var openViewResult = openView.ShowDialog();

            if (openViewResult?.DialogOperationResult != true)
            {
                return;
            }

            MethodInfo methodInformation = projectConfigurationManager.CurrentProjectConfiguraiton.MethodInfos.FirstOrDefault(m => m.MethodName == openViewResult.MethodName);

            if (projectManager.IsMethodExist(openViewResult.Package.MethodFolderPath, openViewResult.MethodName))
            {
                var messageWindow = this.dialogFactory.GetMessageBoxWindow();
                var dialogReuslt  = messageWindow.ShowDialog(this.messageManager.GetMessage("MethodAlreadyAddedToProjectDoYouWantReplaceMethod"),
                                                             this.messageManager.GetMessage("Warning"),
                                                             MessageButtons.YesNo,
                                                             MessageIcon.None);

                if (dialogReuslt == MessageDialogResult.Yes)
                {
                    projectManager.RemoveMethod(methodInformation);
                    projectConfigurationManager.CurrentProjectConfiguraiton.MethodInfos.Remove(methodInformation);
                }
                else
                {
                    return;
                }
            }

            GeneratedCodeInfo codeInfo = codeProvider.GenerateCodeInfo(openViewResult.SelectedTemplate, openViewResult.SelectedEventSpecificData, openViewResult.MethodName, openViewResult.MethodCode, openViewResult.IsUseVSFormattingCode);

            projectManager.CreateMethodTree(codeInfo, openViewResult.Package);

            var methodInfo = new PackageMethodInfo()
            {
                InnovatorMethodConfigId = openViewResult.MethodConfigId,
                InnovatorMethodId       = openViewResult.MethodId,
                MethodLanguage          = openViewResult.MethodLanguage,
                MethodName                  = openViewResult.MethodName,
                MethodType                  = openViewResult.MethodType,
                MethodComment               = openViewResult.MethodComment,
                Package                     = openViewResult.Package,
                TemplateName                = openViewResult.SelectedTemplate.TemplateName,
                EventData                   = openViewResult.SelectedEventSpecificData.EventSpecificData,
                ExecutionAllowedToId        = openViewResult.IdentityId,
                ExecutionAllowedToKeyedName = openViewResult.IdentityKeyedName,
                ManifestFileName            = openViewResult.SelectedManifestFileName
            };

            projectManager.AddSuppression("assembly: System.Diagnostics.CodeAnalysis.SuppressMessage", "Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", "namespace", codeInfo.Namespace);

            projectConfigurationManager.CurrentProjectConfiguraiton.LastSelectedDir    = openViewResult.SelectedFolderPath;
            projectConfigurationManager.CurrentProjectConfiguraiton.LastSelectedMfFile = openViewResult.SelectedManifestFullPath;
            projectConfigurationManager.CurrentProjectConfiguraiton.UseVSFormatting    = openViewResult.IsUseVSFormattingCode;
            projectConfigurationManager.CurrentProjectConfiguraiton.LastSelectedSearchTypeInOpenFromPackage = openViewResult.SelectedSearchType;
            projectConfigurationManager.CurrentProjectConfiguraiton.AddMethodInfo(methodInfo);
            projectConfigurationManager.Save(projectManager.ProjectConfigPath);
        }
        public override void ExecuteCommandImpl(object sender, EventArgs args, IVsUIShell uiShell)
        {
            var    project           = projectManager.SelectedProject;
            string projectConfigPath = projectManager.ProjectConfigPath;
            string methodConfigPath  = projectManager.MethodConfigPath;

            var projectConfiguration = projectConfigurationManager.Load(projectConfigPath);

            var templateLoader = new TemplateLoader();

            templateLoader.Load(methodConfigPath);

            var packageManager = new PackageManager(authManager);

            string     selectedMethodPath = projectManager.MethodPath;
            string     selectedMethodName = Path.GetFileNameWithoutExtension(selectedMethodPath);
            MethodInfo methodInformation  = projectConfiguration.MethodInfos.FirstOrDefault(m => m.MethodName == selectedMethodName);

            if (methodInformation == null)
            {
                throw new Exception();
            }

            string manifastFileName;

            if (methodInformation is PackageMethodInfo)
            {
                PackageMethodInfo packageMethodInfo = (PackageMethodInfo)methodInformation;
                manifastFileName = packageMethodInfo.ManifestFileName;
            }
            else
            {
                manifastFileName = "imports.mf";
            }

            ICodeProvider codeProvider   = codeProviderFactory.GetCodeProvider(project.CodeModel.Language, projectConfiguration);
            var           saveView       = dialogFactory.GetSaveToPackageView(uiShell, projectConfiguration, templateLoader, packageManager, codeProvider, projectManager, methodInformation, selectedMethodPath);
            var           saveViewResult = saveView.ShowDialog();

            if (saveViewResult?.DialogOperationResult != true)
            {
                return;
            }

            string pathPackageToSaveMethod;
            string rootPath       = saveViewResult.PackagePath;
            string importFilePath = Path.Combine(rootPath, manifastFileName);

            if (File.Exists(importFilePath))
            {
                var xmlDocument = new XmlDocument();
                xmlDocument.Load(importFilePath);
                XmlNode importsXmlNode = xmlDocument.SelectSingleNode("imports");
                XmlNode packageXmlNode = importsXmlNode.SelectSingleNode($"package[@name='{saveViewResult.SelectedPackage}']");

                if (packageXmlNode == null)
                {
                    pathPackageToSaveMethod = $"{saveViewResult.SelectedPackage}\\Import";
                    XmlElement packageXmlElement = xmlDocument.CreateElement("package");
                    packageXmlElement.SetAttribute("name", saveViewResult.SelectedPackage);
                    packageXmlElement.SetAttribute("path", pathPackageToSaveMethod);
                    importsXmlNode.AppendChild(packageXmlElement);

                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Encoding           = new UTF8Encoding(true);
                    settings.Indent             = true;
                    settings.IndentChars        = "\t";
                    settings.OmitXmlDeclaration = true;
                    using (XmlWriter xmlWriter = XmlWriter.Create(importFilePath, settings))
                    {
                        xmlDocument.Save(xmlWriter);
                    }
                }
                else
                {
                    pathPackageToSaveMethod = packageXmlNode.Attributes["path"].Value;
                }
            }
            else
            {
                pathPackageToSaveMethod = $"{saveViewResult.SelectedPackage}\\Import";
                var        xmlDocument       = new XmlDocument();
                XmlElement importsXmlNode    = xmlDocument.CreateElement("imports");
                XmlElement packageXmlElement = xmlDocument.CreateElement("package");
                packageXmlElement.SetAttribute("name", saveViewResult.SelectedPackage);
                packageXmlElement.SetAttribute("path", pathPackageToSaveMethod);
                importsXmlNode.AppendChild(packageXmlElement);
                xmlDocument.AppendChild(importsXmlNode);

                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent             = true;
                settings.IndentChars        = "\t";
                settings.OmitXmlDeclaration = true;
                settings.Encoding           = new UTF8Encoding(true);
                using (XmlWriter xmlWriter = XmlWriter.Create(importFilePath, settings))
                {
                    xmlDocument.Save(xmlWriter);
                }
            }

            string methodPath = Path.Combine(rootPath, $"{pathPackageToSaveMethod}\\Method\\");

            Directory.CreateDirectory(methodPath);

            string methodId       = null;
            string methodFilePath = Path.Combine(methodPath, $"{saveViewResult.MethodName}.xml");

            if (File.Exists(methodFilePath))
            {
                var methodXmlDocument = new XmlDocument();
                methodXmlDocument.Load(methodFilePath);
                methodId = methodXmlDocument.SelectSingleNode("/AML/Item/@id").InnerText;
            }
            else
            {
                methodId = saveViewResult.MethodInformation.InnovatorMethodConfigId;
            }

            string updateMethodCodeForSavingToAmlPackage = saveViewResult.MethodCode.Replace("]]", "]]]]><![CDATA[");
            string methodTemplate = $@"<AML>
 <Item type=""Method"" id=""{methodId}"" action=""add"">" +
                                    (!string.IsNullOrWhiteSpace(saveViewResult.MethodComment) ? $"<comments>{saveViewResult.MethodComment}</comments>" : "") +
                                    $@"<execution_allowed_to keyed_name=""{saveViewResult.SelectedIdentityKeyedName}"" type=""Identity"">{saveViewResult.SelectedIdentityId}</execution_allowed_to>
  <method_code><![CDATA[{updateMethodCodeForSavingToAmlPackage}]]></method_code>
  <method_type>{saveViewResult.MethodInformation.MethodLanguage}</method_type>
  <name>{saveViewResult.MethodName}</name>
 </Item>
</AML>";

            XmlDocument resultXmlDoc = new XmlDocument();

            resultXmlDoc.LoadXml(methodTemplate);
            SaveToFile(methodFilePath, resultXmlDoc);

            if (methodInformation.MethodName == saveViewResult.MethodName)
            {
                methodInformation.PackageName = saveViewResult.SelectedPackage;
                methodInformation.ExecutionAllowedToKeyedName = saveViewResult.SelectedIdentityKeyedName;
                methodInformation.ExecutionAllowedToId        = saveViewResult.SelectedIdentityId;
                methodInformation.MethodComment = saveViewResult.MethodComment;
            }

            projectConfiguration.LastSelectedDir = rootPath;
            projectConfigurationManager.Save(projectConfigPath, projectConfiguration);

            string message = string.Format("Method \"{0}\" saved to package \"{1}\"", saveViewResult.MethodName, saveViewResult.SelectedPackage);

            // Show a message box to prove we were here
            var messageWindow = dialogFactory.GetMessageBoxWindow(uiShell);

            messageWindow.ShowDialog(null,
                                     message,
                                     string.Empty,
                                     MessageButtons.OK,
                                     MessageIcon.Information);
        }