Exemplo n.º 1
0
        public void AddPackageElementToPackageDefinition()
        {
            //Arrange
            string name        = null;
            string id          = null;
            string packageName = null;

            //Act
            var testDelegate = new TestDelegate(() => packageManager.AddPackageElementToPackageDefinition(id, name, packageName));

            //Assert
            Assert.DoesNotThrow(testDelegate);
        }
Exemplo n.º 2
0
        public override void ExecuteCommandImpl(object sender, EventArgs args)
        {
            var project = projectManager.SelectedProject;

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

            var projectConfiguration = projectConfigurationManager.Load(projectConfigPath);

            string selectedMethodPath = projectManager.MethodPath;
            string sourceCode         = File.ReadAllText(selectedMethodPath, new UTF8Encoding(true));
            string selectedMethodName = Path.GetFileNameWithoutExtension(selectedMethodPath);

            MethodInfo methodInformation = projectConfiguration.MethodInfos.FirstOrDefault(m => m.MethodName == selectedMethodName);

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

            ICodeProvider codeProvider = codeProviderFactory.GetCodeProvider(project.CodeModel.Language, projectConfiguration);
            string        methodCode   = codeProvider.LoadMethodCode(sourceCode, methodInformation, projectManager.ServerMethodFolderPath);

            var packageManager = new PackageManager(authManager);
            var saveView       = dialogFactory.GetSaveToArasView(projectConfigurationManager, projectConfiguration, packageManager, methodInformation, methodCode, projectConfigPath, project.Name, project.FullName);
            var saveViewResult = saveView.ShowDialog();

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

            var templateLoader = new TemplateLoader(this.dialogFactory);

            templateLoader.Load(methodConfigPath);

            dynamic currentMethodItem = saveViewResult.MethodItem;

            if (!currentMethodItem.isError())
            {
                methodCode = saveViewResult.MethodCode;
                var template = templateLoader.Templates.FirstOrDefault(t => t.TemplateName == saveViewResult.TemplateName);
                if (template != null && !template.IsSupported)
                {
                    methodCode = methodCode.Insert(0, string.Format("//MethodTemplateName={0}\r\n", template.TemplateName));
                }

                currentMethodItem.setProperty("comments", saveViewResult.MethodComment);
                currentMethodItem.setProperty("method_code", methodCode);
                currentMethodItem.setProperty("name", saveViewResult.MethodName);
                currentMethodItem.setProperty("method_type", saveViewResult.MethodLanguage);
                currentMethodItem.setProperty("execution_allowed_to", saveViewResult.SelectedIdentityId);

                var action = GetUpdateAction(currentMethodItem.getLockStatus());
                currentMethodItem = currentMethodItem.apply(action);
            }
            else
            {
                methodCode = saveViewResult.MethodCode;
                var template = templateLoader.Templates.FirstOrDefault(t => t.TemplateName == saveViewResult.TemplateName);
                if (template != null && !template.IsSupported)
                {
                    methodCode = methodCode.Insert(0, string.Format("//MethodTemplateName={0}\r\n", template.TemplateName));
                }

                currentMethodItem = authManager.InnovatorInstance.newItem("Method", "add");
                currentMethodItem.setProperty("comments", saveViewResult.MethodComment);
                currentMethodItem.setProperty("method_code", methodCode);
                currentMethodItem.setProperty("name", saveViewResult.MethodName);
                currentMethodItem.setProperty("method_type", saveViewResult.MethodLanguage);
                currentMethodItem.setProperty("execution_allowed_to", saveViewResult.SelectedIdentityId);
                currentMethodItem = currentMethodItem.apply();
            }

            if (currentMethodItem.isError())
            {
                throw new Exception(currentMethodItem.getErrorString());
            }

            var newId = currentMethodItem.getID();

            if (string.IsNullOrEmpty(saveViewResult.CurrentMethodPackage))
            {
                packageManager.AddPackageElementToPackageDefinition(newId, saveViewResult.MethodName, saveViewResult.SelectedPackage);
            }
            else
            {
                if (!string.Equals(saveViewResult.CurrentMethodPackage, saveViewResult.SelectedPackage))
                {
                    packageManager.DeletePackageElementByNameFromPackageDefinition(saveViewResult.MethodName);
                    packageManager.AddPackageElementToPackageDefinition(newId, saveViewResult.MethodName, saveViewResult.SelectedPackage);
                }
            }

            if (methodInformation.MethodName == saveViewResult.MethodName)
            {
                methodInformation.InnovatorMethodConfigId     = currentMethodItem.getProperty("config_id");
                methodInformation.InnovatorMethodId           = newId;
                methodInformation.PackageName                 = saveViewResult.SelectedPackage;
                methodInformation.ExecutionAllowedToKeyedName = saveViewResult.SelectedIdentityKeyedName;
                methodInformation.ExecutionAllowedToId        = saveViewResult.SelectedIdentityId;
                methodInformation.MethodComment               = saveViewResult.MethodComment;

                projectConfigurationManager.Save(projectConfigPath, projectConfiguration);
            }

            string message          = string.Format("Method \"{0}\" saved", saveViewResult.MethodName);
            var    messageBoxWindow = dialogFactory.GetMessageBoxWindow();

            messageBoxWindow.ShowDialog(message,
                                        string.Empty,
                                        MessageButtons.OK,
                                        MessageIcon.Information);
        }
Exemplo n.º 3
0
        public override void ExecuteCommandImpl(object sender, EventArgs args)
        {
            var project = projectManager.SelectedProject;

            string selectedMethodPath = projectManager.MethodPath;
            string sourceCode         = File.ReadAllText(selectedMethodPath, new UTF8Encoding(true));
            string selectedMethodName = Path.GetFileNameWithoutExtension(selectedMethodPath);

            string projectConfigPath = projectManager.ProjectConfigPath;

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

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

            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);

            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;
            }

            string methodCode = codeProvider.LoadMethodCode(methodWorkingFolder, sourceCode);

            var packageManager = new PackageManager(authManager, this.messageManager);
            var saveView       = dialogFactory.GetSaveToArasView(projectConfigurationManager, packageManager, methodInformation, methodCode, projectConfigPath, project.Name, project.FullName);
            var saveViewResult = saveView.ShowDialog();

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

            TemplateLoader templateLoader = new TemplateLoader();

            templateLoader.Load(projectManager.MethodConfigPath);

            dynamic currentMethodItem = saveViewResult.MethodItem;

            if (!currentMethodItem.isError())
            {
                methodCode = saveViewResult.MethodCode;
                var template = templateLoader.Templates.FirstOrDefault(t => t.TemplateName == saveViewResult.TemplateName);
                if (template != null && !template.IsSupported)
                {
                    methodCode = methodCode.Insert(0, string.Format("//MethodTemplateName={0}\r\n", template.TemplateName));
                }

                currentMethodItem.setProperty("comments", saveViewResult.MethodComment);
                currentMethodItem.setProperty("method_code", methodCode);
                currentMethodItem.setProperty("name", saveViewResult.MethodName);
                currentMethodItem.setProperty("method_type", saveViewResult.MethodLanguage);
                currentMethodItem.setProperty("execution_allowed_to", saveViewResult.SelectedIdentityId);

                var action = GetUpdateAction(currentMethodItem.getLockStatus());
                currentMethodItem = currentMethodItem.apply(action);
            }
            else
            {
                methodCode = saveViewResult.MethodCode;
                var template = templateLoader.Templates.FirstOrDefault(t => t.TemplateName == saveViewResult.TemplateName);
                if (template != null && !template.IsSupported)
                {
                    methodCode = methodCode.Insert(0, string.Format("//MethodTemplateName={0}\r\n", template.TemplateName));
                }

                currentMethodItem = authManager.InnovatorInstance.newItem("Method", "add");
                currentMethodItem.setProperty("comments", saveViewResult.MethodComment);
                currentMethodItem.setProperty("method_code", methodCode);
                currentMethodItem.setProperty("name", saveViewResult.MethodName);
                currentMethodItem.setProperty("method_type", saveViewResult.MethodLanguage);
                currentMethodItem.setProperty("execution_allowed_to", saveViewResult.SelectedIdentityId);
                currentMethodItem = currentMethodItem.apply();
            }

            if (currentMethodItem.isError())
            {
                throw new Exception(currentMethodItem.getErrorString());
            }

            string newId    = currentMethodItem.getID();
            string configId = currentMethodItem.getProperty("config_id");

            if (string.IsNullOrEmpty(saveViewResult.CurrentMethodPackage))
            {
                packageManager.AddPackageElementToPackageDefinition(configId, saveViewResult.MethodName, saveViewResult.SelectedPackageInfo.Name);
            }
            else
            {
                if (!string.Equals(saveViewResult.CurrentMethodPackage, saveViewResult.SelectedPackageInfo.ToString()))
                {
                    packageManager.DeletePackageByElementIdFromPackageDefinition(configId);
                    packageManager.AddPackageElementToPackageDefinition(configId, saveViewResult.MethodName, saveViewResult.SelectedPackageInfo.Name);
                }
            }

            if (methodInformation.MethodName == saveViewResult.MethodName &&
                methodInformation.Package.Name == saveViewResult.SelectedPackageInfo.Name)
            {
                methodInformation.InnovatorMethodConfigId = configId;
                methodInformation.InnovatorMethodId       = newId;
                methodInformation.Package = saveViewResult.SelectedPackageInfo;
                methodInformation.ExecutionAllowedToKeyedName = saveViewResult.SelectedIdentityKeyedName;
                methodInformation.ExecutionAllowedToId        = saveViewResult.SelectedIdentityId;
                methodInformation.MethodComment = saveViewResult.MethodComment;

                projectConfigurationManager.Save(projectConfigPath);
            }

            var messageBoxWindow = dialogFactory.GetMessageBoxWindow();

            messageBoxWindow.ShowDialog(this.messageManager.GetMessage("MethodSaved", saveViewResult.MethodName),
                                        string.Empty,
                                        MessageButtons.OK,
                                        MessageIcon.Information);
        }